Пример #1
0
        void OnClicked(object sender, System.EventArgs e)
        {
            DateTime birthday = bday.Date;
            int      legalAge = 21;

            switch (Location.SelectedItem)
            {
            case "USA":
                legalAge = 21;
                break;

            case "Mexico":
                legalAge = 18;
                break;

            case "Brazil":
                legalAge = 21;
                break;

            case "Australia":
                legalAge = 18;
                break;
            }
            DateTime.Compare(birthday, birthday.AddYears(legalAge));
            int    daysTill21 = (birthday.AddYears(legalAge) - DateTime.Now).Days;
            var    dateSpan   = DateTimeSpan.CompareDates(birthday.AddYears(legalAge), DateTime.Now);
            string message    = "";

            if (daysTill21 > 0)
            {
                message = $"In {Location.SelectedItem}, You will be able to drink in {dateSpan.Years} years {dateSpan.Months} months {dateSpan.Days} days.";
            }
            else if (daysTill21 == 0)
            {
                message = $"Congratulations! In {Location.SelectedItem}, You can drink today!";
            }
            else
            {
                message = $"In {Location.SelectedItem}, You have been able to drink for {dateSpan.Years} years {dateSpan.Months} months {dateSpan.Days} days.";
            }

            output.Text = $"{message}";
        }