GamerSK

počítadlo

Feb 26th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace pocitadlo
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         int day; int month; int year; int aday; int amonth; int ayear;
  16.         byte[] months = new byte[13] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  17.  
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void checkDatum_CheckedChanged(object sender, EventArgs e)
  24.         {
  25.             if (checkDatum.Checked == false)
  26.             {
  27.                 txtADay.Visible = true;
  28.                 txtAMonth.Visible = true;
  29.                 txtAYear.Visible = true;
  30.                 labelDatum.Visible = true;
  31.                 btnSend.Location = new Point(265, 104);
  32.             }
  33.             else
  34.             {
  35.                 txtADay.Visible = false;
  36.                 txtAMonth.Visible = false;
  37.                 txtAYear.Visible = false;
  38.                 labelDatum.Visible = false;
  39.                 btnSend.Location = new Point(162, 104);
  40.             }
  41.         }
  42.  
  43.         private void btnSend_Click(object sender, EventArgs e)
  44.         {
  45.             int s1 = 0; int s2 = 0; int v = 0; int age = 0;
  46.             if (checkDatum.Checked == true)
  47.             {
  48.                 aday = DateTime.Now.Day;
  49.                 amonth = DateTime.Now.Month;
  50.                 ayear = DateTime.Now.Year;
  51.             }
  52.             else
  53.             {
  54.                 aday = int.Parse(txtADay.Text);
  55.                 amonth = int.Parse(txtAMonth.Text);
  56.                 ayear = int.Parse(txtAYear.Text);
  57.             }
  58.             day = int.Parse(txtDay.Text);
  59.             month = int.Parse(txtMonth.Text);
  60.             year = int.Parse(txtYear.Text);
  61.             if (year % 4 == 0 && ayear % 4 == 0)
  62.                 months[2] = 29;
  63.             else months[2] = 28;
  64.             for (int i = 1; i <= month; i++)
  65.                 s1 += months[i];
  66.             for (int i = 1; i <= amonth; i++)
  67.                 s2 += months[i];
  68.             v = (s1 + day) - (s2 + aday);
  69.             if (day == aday && month == amonth)
  70.             {
  71.                 age = ayear - year;
  72.                 if (year % 4 == 0 && ayear % 4 == 0)
  73.                     v = v + 366;
  74.                 else v = v + 365;
  75.             }
  76.             else age = (ayear - year) - 1;
  77.             if (v < 0)
  78.             {
  79.                 age++;
  80.                 if (year % 4 == 0 && ayear % 4 == 0)
  81.                     v = v + 366;
  82.                 else v = v + 365;
  83.             }
  84.             Output1.Text = "Máš "+ age +" rokov";
  85.             Output2.Text = "Za "+ v + " dní budeš mať narodeniny";
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment