Advertisement
AvengersAssemble

Datecheck + Print In Various Options

Sep 29th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication25
  8. {
  9.     public delegate void isDateValid(int falseInfo, string falseType);
  10.     enum Months : byte { January, February, March, April, May, June, July, August, September, October, November, December, False };
  11.     public class Date
  12.     {
  13.         private int year;
  14.         private Months month;
  15.         private int day;
  16.         private bool isFalse = false;
  17.         public isDateValid dateCheck;
  18.         public Date(int year, int month, int day)
  19.         {
  20.             this.year = year;
  21.             if (month > 0 && month < 13)
  22.             {
  23.                 this.month = (Months)month-1;
  24.             }
  25.             else
  26.             {
  27.                 this.month = (Months)13;
  28.                 isFalse = true;
  29.             }
  30.                 this.day = day;
  31.         }
  32.         public void DayMonthCheck()
  33.         {
  34.             if (month != (Months) 13)
  35.             {
  36.                 if ((int)month > 2 && (int)month < 8)
  37.                 {
  38.                     if ((int)month % 2 == 0)
  39.                     {
  40.                         if (day > 30)
  41.                         {
  42.                             dateCheck(day, "day");
  43.                             isFalse = true;
  44.                         }
  45.                     }
  46.                     else
  47.                     {
  48.                         if (day > 31)
  49.                         {
  50.                             dateCheck(day, "day");
  51.                             isFalse = true;
  52.                         }
  53.                     }
  54.                 }
  55.                 else if ((int)month >= 8)
  56.                 {
  57.                     if( (int) month % 2 == 0)
  58.                     {
  59.                         if (day > 31)
  60.                         {
  61.                             dateCheck(day, "day");
  62.                             isFalse = true;
  63.                         }
  64.                     }
  65.                     else
  66.                     {
  67.                         if (day > 30)
  68.                         {
  69.                             dateCheck(day, "day");
  70.                             isFalse = true;
  71.                         }
  72.                     }
  73.                 }
  74.                 else if ((int)month == 1)
  75.                 {
  76.                     if (day > 31)
  77.                     {
  78.                         dateCheck(day, "day");
  79.                         isFalse = true;
  80.                     }
  81.                 }
  82.                 else if ((int)month == 2)
  83.                 {
  84.                     if (day > 28)
  85.                     {
  86.                         dateCheck(day, "day");
  87.                         isFalse = true;
  88.                     }
  89.                 }
  90.             }
  91.             else
  92.                 dateCheck((int)month, "month");
  93.             if (day < 1)
  94.             {
  95.                 dateCheck(day, "day");
  96.                 isFalse = true;
  97.             }
  98.         }
  99.         public static void Sub()
  100.         {
  101.         }
  102.         public void Print(int selectedOutput)
  103.         {
  104.             if (!isFalse)
  105.             {
  106.                 if (selectedOutput == 1)
  107.                     Console.WriteLine("{0}/{1}/{2}", day, (int)month+1, year);
  108.                 else if (selectedOutput == 2)
  109.                     Console.WriteLine("{0} {1}, {2}", day, month, year);
  110.                 else if (selectedOutput == 3)
  111.                     Console.WriteLine("{0} - {1} - {2}", day, (int)month+1, year);
  112.                 else
  113.                     Console.WriteLine("{0}/{1}/{2}", (int)month+1, day, year);
  114.             }
  115.         }
  116.     }
  117.     class Program
  118.     {
  119.         static void Main(string[] args)
  120.         {
  121.             Console.Write("Year: ");
  122.             int year = int.Parse(Console.ReadLine());
  123.             Console.Write("Month: ");
  124.             int month = int.Parse(Console.ReadLine());
  125.             Console.Write("Day: ");
  126.             int day = int.Parse(Console.ReadLine());
  127.             Date today = new Date(year, month, day);
  128.             today.dateCheck = new isDateValid(DateValidation);
  129.             today.DayMonthCheck();
  130.             Console.WriteLine("Choose printing method:");
  131.             Console.WriteLine("1. dd/mm/yy\n2. dd Month, yy\n3. dd-mm-yy\n4. mm/dd/yy");
  132.             int selectedOutput = int.Parse(Console.ReadLine());
  133.             today.Print(selectedOutput);
  134.         }
  135.         static void DateValidation(int date, string type)
  136.         {
  137.             Console.WriteLine("Invalid date! {0} {1} doesn't exist.", type, date);
  138.         }
  139.     }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement