From ce3ec2381ec85a51e7c15281315b1ecf9c510d5a Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Mon, 10 Dec 2018 16:09:46 -0600 Subject: [PATCH 1/7] Projects --- Today/Today.cs | 26 ++++++++++++++++++++++++++ Today/Today.csproj | 8 ++++++++ Today/test.txt | 1 + Week9.cs | 12 ++++++++++++ Week9/Program.cs | 12 ++++++++++++ Week9/Week7.csproj | 8 ++++++++ Week9/Week9.csproj | 8 ++++++++ csharp-workbook.csproj | 9 +++++++++ 8 files changed, 84 insertions(+) create mode 100644 Today/Today.cs create mode 100644 Today/Today.csproj create mode 100644 Today/test.txt create mode 100644 Week9.cs create mode 100644 Week9/Program.cs create mode 100644 Week9/Week7.csproj create mode 100644 Week9/Week9.csproj create mode 100644 csharp-workbook.csproj diff --git a/Today/Today.cs b/Today/Today.cs new file mode 100644 index 00000000..cb0eec76 --- /dev/null +++ b/Today/Today.cs @@ -0,0 +1,26 @@ +using System; +using System.IO; + +namespace Today +{ + class Today + { + static void Main(string[] args) + { + String file = @"/Users/jasonconnolly/Desktop/words.txt"; + String[] lines = File.ReadAllLines(file); + //reading all lines and putting in an array + + int lineNo =0; + foreach(String line in lines){ + lineNo +=1; + Console.WriteLine(lineNo+"+line"); + //reading each line and then writing to the console + } + + String copy= @"/Users/jasonconnolly/Desktop/.txt"; + File.WriteAllLines(copy, lines); + //creates new file and puts into new file + } + } +} diff --git a/Today/Today.csproj b/Today/Today.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/Today/Today.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/Today/test.txt b/Today/test.txt new file mode 100644 index 00000000..b6cb3c87 --- /dev/null +++ b/Today/test.txt @@ -0,0 +1 @@ +Hello Yousif \ No newline at end of file diff --git a/Week9.cs b/Week9.cs new file mode 100644 index 00000000..d879ba8f --- /dev/null +++ b/Week9.cs @@ -0,0 +1,12 @@ +using System; + +namespace csharp_workbook +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/Week9/Program.cs b/Week9/Program.cs new file mode 100644 index 00000000..0ce3e294 --- /dev/null +++ b/Week9/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace Week7 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/Week9/Week7.csproj b/Week9/Week7.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/Week9/Week7.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/Week9/Week9.csproj b/Week9/Week9.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/Week9/Week9.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/csharp-workbook.csproj b/csharp-workbook.csproj new file mode 100644 index 00000000..d06178dc --- /dev/null +++ b/csharp-workbook.csproj @@ -0,0 +1,9 @@ + + + + Exe + netcoreapp2.1 + csharp_workbook + + + From efba78262750754c50e9d1116c24a322d45851eb Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Mon, 10 Dec 2018 16:42:33 -0600 Subject: [PATCH 2/7] Projects --- PigLatin/PigLatin.cs | 73 ++++- Week9.cs | 638 ++++++++++++++++++++++++++++++++++++++++++- Week9/Program.cs | 2 +- 3 files changed, 692 insertions(+), 21 deletions(-) diff --git a/PigLatin/PigLatin.cs b/PigLatin/PigLatin.cs index 702647dd..255c149d 100644 --- a/PigLatin/PigLatin.cs +++ b/PigLatin/PigLatin.cs @@ -1,21 +1,78 @@ using System; +using System.Collections.Generic; namespace PigLatin { class Program { - public static void Main() + public static void Main(string[] args) { - // your code goes here + // run tests and print out if tests passed or not + if(tests()){ + Console.WriteLine("Tests passed."); + } else { + Console.WriteLine("Tests failed."); + } - // leave this command at the end so your program does not close automatically - Console.ReadLine(); + //your code to get user input and call TranslateWord method here + + string word = ""; + + + Console.WriteLine("Translate to Pig Latin, Enter a word {0}", word); + word = Console.ReadLine(); + string pigLatin = ToPigLatin(word); + Console.WriteLine(pigLatin); + } - - public static string TranslateWord(string word) + + public static string ToPigLatin(string word) { - // your code goes here - return word; + string vowels = "AEIOUaeio"; + string PigWorded = ""; + + + string firstLetter = word.Substring(0,1); + + Console.WriteLine(firstLetter); + + string restOfWord = word.Substring(1, word.Length -1); + Console.WriteLine(restOfWord); + + int currentLetter = vowels.IndexOf(firstLetter); + Console.WriteLine(currentLetter); + if (currentLetter == -1) + { + PigWorded += (restOfWord + firstLetter + "ay"); + } + else + { + PigWorded += (word + "yay"); + } + + + return PigWorded; + + } + /** + This method tests some examples against the 5 following rules, + and returns true if all tests pass, otherwise returns false. + + rule 1: if it starts with a vowel add "yay" to the end + rule 2: move all letter before the first vowel to the end, then add "ay" to the end + rule 3: if it starts with a "y", treat the "y" as a consonant + rule 4: if it does not start with a "y", treat the "y" as a vowel + rule 5: if there are no vowels, add "ay" to the end (this is the same as rule 2) + */ + public static bool tests(){ + return + ToPigLatin("elephant") == "elephantyay" && + ToPigLatin("fox") == "oxfay" && + ToPigLatin("choice") == "oicechay" && + ToPigLatin("dye") == "yeday" && + ToPigLatin("bystander") == "ystanderbay" && + ToPigLatin("yellow") == "ellowyay" && + ToPigLatin("tsktsk") == "tsktskay"; } } } diff --git a/Week9.cs b/Week9.cs index d879ba8f..43c125e0 100644 --- a/Week9.cs +++ b/Week9.cs @@ -1,12 +1,626 @@ -using System; - -namespace csharp_workbook -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("Hello World!"); - } - } -} +using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Globalization; + using System.Security.Permissions; + using System.Threading; + + namespace To_Do_List_Tuhin + { + public class To_do : IComparable + { + public int Todo_ID { get; set; } + public DateTime date { get; set; } + public string Task { get; set; } + public int Lvl_Imp { get; set; } + + public To_do(int Todo_ID, DateTime date, string Task, int Lvl_Imp) + { + this.Todo_ID = Todo_ID; + this.date = date; + this.Task = Task; + this.Lvl_Imp = Lvl_Imp; + } + public int CompareTo(To_do other) + { + return this.Todo_ID.CompareTo(other.Todo_ID); + } + + } + + + class Program + { + public static string mt = "\t\t\t"; + public static string st = "\t\t "; + public static string xst = "\t\t"; + + //UI + public static void header() + { + Console.Clear(); + DateTime dtu = DateTime.Now; + + Console.WriteLine("\n\n\n\t\t\t\t\t" + dtu.ToString("dd-MM-yyyy")); + Console.WriteLine("\t\t===================================="); + Console.WriteLine("\t\t\t TO-DO List"); + Console.WriteLine("\t\t===================================="); + } + + public static void footer() + { + Console.WriteLine("\t\t===================================="); + } + + + + public static void UI_msg(String msg) + { + header(); + Console.WriteLine("\n\n" + st + msg + "\n\n"); + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + } + + + public static bool chk_date(String daaat) + { + string[] formats = { "d-M-yyyy" }; + DateTime parsedDateTime; + if (DateTime.TryParseExact(daaat, formats, new CultureInfo("en-US"), + DateTimeStyles.None, out parsedDateTime)) + { + return true; + } + else + { + return false; + } + } + + public static void Main() + { + Random rnd = new Random(); + int ID = rnd.Next(89); + + List TD_Task = new List(); + bool check = true; ; + + SUDO_MAIN: + + while (true) + { + + + header(); + Console.WriteLine(xst + "1.New Task.\t\t6.Update Task.\n"); + Console.WriteLine(xst + "2.View Al.\t\t7.Delete Task.\n"); + Console.WriteLine(xst + "3.View b/w Dates.\t8.Sort.\n"); + Console.WriteLine(xst + "4.Find Task.\t\t9.Exit\n"); + Console.WriteLine(xst + "5.Find Duplicates."); + footer(); + + Console.Write(st + "Enter your choice: "); + int ch = 0; + try + { + ch = int.Parse(Console.ReadLine()); + } + catch (Exception) + { + + UI_msg("ERROR: Insert Only Intergers!"); + } + + + switch (ch) + { + case 1: + header(); + Console.Write("\t\tEnter the Date.\t[dd-MM-yyyy]\n\t\t"); + try + { + string dat = Console.ReadLine(); + string daat = dat; + + DateTime cur_time = DateTime.Now; + cur_time.ToString("d-M-yyyy"); + try + { + TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dat.ToString())); + + + int day = (int)Math.Round(duration.TotalDays); + + int x=0 ; + if (day % 2 != 0) + { + x = 2; + } + else + { + x = 1; + } + + + if (day >= x) // if date less than todays + { + DateTime dtu = DateTime.Now; + string msg = "Plz select date from\n\t\t" + dtu.ToString("d-M-yyyy") + " onwards!"; + UI_msg("ERROR: " + msg); + goto SUDO_MAIN; + } + + } + catch (FormatException) + { + UI_msg("ERROR: Invalid Date!"); + goto SUDO_MAIN; + + } + + + + if (chk_date(daat)) // check validity of date + { + Console.Write("\n\t\tEnter Task.\n\t\t"); + string msg = Console.ReadLine(); + + Console.Write("\n\t\tEnter Level of Importance.\t[1-5]\n\t\t"); + int lvl = int.Parse(Console.ReadLine()); + if (lvl >= 1 && lvl <= 5) + { + ID++; + + TD_Task.Add(new To_do(ID, DateTime.Parse(dat), msg, lvl)); + UI_msg("New Task created with Task ID = " + ID.ToString()); + TD_Task.Sort(); // Sort db + } + else + { + UI_msg("ERROR: Only between [1-5]!"); + } + } + else + { + UI_msg("ERROR: Invalid Date!"); + } + + + } + catch (Exception) + { + UI_msg("ERROR: Enter Integer Only!!"); + } + break; + + case 2: + header(); + Console.WriteLine("\t\tID \tDate\tTask\t\tLevel"); + + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 3: + + header(); + + string cmp_date1, mon1, day1, S_d, E_d, S_m, E_m, S_da, E_da; + int SD, ED, cmp_date, mon, SM, EM, dayx, SDA, EDA; + + Console.Write("\t\tEnter starting Date.\t[dd-MM-yyyy]\n\t\t"); + string Sdat3 = Console.ReadLine(); + + if (chk_date(Sdat3)) // check validity of date + { + Console.Write("\n\t\tEnter ending Date.\t[dd-MM-yyyy]\n\t\t"); + string Edat3 = Console.ReadLine(); + Console.WriteLine("\t\t------------------------------------"); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + + if (chk_date(Edat3)) // check validity of date + { + + DateTime s = DateTime.Parse(Sdat3); + DateTime e = DateTime.Parse(Edat3); + + + for (int i = 0; i < TD_Task.Count; i++) + { + //year + cmp_date1 = TD_Task[i].date.ToString("yyyy"); + cmp_date = int.Parse(cmp_date1); + S_d = s.ToString("yyyy"); + E_d = e.ToString("yyyy"); + SD = int.Parse(S_d); + ED = int.Parse(E_d); + + //month + mon1 = TD_Task[i].date.ToString("MM"); + mon = int.Parse(mon1); + S_m = s.ToString("MM"); + E_m = e.ToString("MM"); + SM = int.Parse(S_m); + EM = int.Parse(E_m); + + //day + day1 = TD_Task[i].date.ToString("dd"); + dayx = int.Parse(day1); + S_da = s.ToString("dd"); + E_da = e.ToString("dd"); + SDA = int.Parse(S_da); + EDA = int.Parse(E_da); + + if (cmp_date >= SD && cmp_date <= ED) // Range of Years + { + if (mon >= SM && mon <= EM) // Range of Months + { + if (dayx >= SDA && dayx <= EDA) // Range of Days + { + check = false; + Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("dd-MM-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); + } + } + } + } + + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + } + else + { + UI_msg("ERROR: Invalid Ending Date!"); + } + } + else + { + UI_msg("ERROR: Invalid Starting Date!"); + } + + break; + + case 4: + header(); + Console.Write("\t\tEnter the String.\n\t\t"); + try + { + string str1; + string str = Console.ReadLine(); + str.ToLower(); + Console.WriteLine("\t\t------------------------------------"); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + for (int i = 0; i < TD_Task.Count; i++) + { + str1 = TD_Task[i].Task; + str1.ToLower(); + if (str1.Contains(str)) + { + check = false; + Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("dd-MM-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); + } + + + } + + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + } + catch (Exception) + { + + UI_msg("Error in Find string"); + } + + + break; + + case 5: + header(); + Console.WriteLine("\t\t------------------------------------"); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + string a; + int z=0; + foreach (To_do y in TD_Task) + { + a = y.Task; + + + z = 0; + foreach (To_do x in TD_Task) + { + + if (a.Equals(x.Task)) + { + z++; + + } + + + } + if (z >= 2) + { + check = false; + Console.WriteLine("\t\t" + y.Todo_ID + " " + y.date.ToString("dd-MM-yyyy") + "\t" + y.Task + "\t" + y.Lvl_Imp); + } + } + + if (check) + { + Console.WriteLine("\n\n\t\t No Duplicate Records Found!\n\n"); + } + + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 6: + header(); + Console.Write("\t\tEnter the Task_ID.\n\t\t"); + try + { + int T_ID = int.Parse(Console.ReadLine()); + Console.WriteLine("\t\t------------------------------------"); + for (int i = 0; i < TD_Task.Count; i++) + { + if (TD_Task[i].Todo_ID == T_ID) + { + check = false; + Console.Write("\t\tEnter the Date.\t[dd-MM-yyyy]\n\t\t"); + try + { + string dat = Console.ReadLine(); + string daat = dat; + + DateTime cur_time = DateTime.Now; + cur_time.ToString("d-M-yyyy"); + try + { + TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dat.ToString())); + + + int day = (int)Math.Round(duration.TotalDays); + + if (day >= 2) // if date less than todays + { + DateTime dtu = DateTime.Now; + string msg = "Plz select date from\n\t\t" + dtu.ToString("d-M-yyyy") + " onwards!"; + UI_msg("ERROR: " + msg); + goto SUDO_MAIN; + } + + } + catch (FormatException) + { + UI_msg("ERROR: Invalid Date!"); + goto SUDO_MAIN; + + } + + + + if (chk_date(daat)) // check validity of date + { + Console.Write("\n\t\tEnter Task.\n\t\t"); + string msg = Console.ReadLine(); + + Console.Write("\n\t\tEnter Level of Importance.\t[1-5]\n\t\t"); + int lvl = int.Parse(Console.ReadLine()); + if (lvl >= 1 && lvl <= 5) + { + + + TD_Task[i].date = DateTime.Parse(dat); + TD_Task[i].Task = msg; + TD_Task[i].Lvl_Imp = lvl; + + Console.WriteLine("\t\tTask Updated!"); + TD_Task.Sort(); // Sort db + } + else + { + UI_msg("ERROR: Only between [1-5]!"); + } + } + else + { + UI_msg("ERROR: Invalid Date!"); + } + + + } + catch (Exception) + { + UI_msg("ERROR: Enter Integer Only!!"); + } + + } + } + if (check) + { + Console.WriteLine("\n\n\t\t\t No Record Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + } + catch (Exception) + { + + UI_msg("ERROR: Insert Only Intergers!"); + } + break; + + case 7: + header(); + Console.Write("\t\tEnter the Task_ID.\n\t\t"); + try + { + int T_ID = int.Parse(Console.ReadLine()); + Console.WriteLine("\t\t------------------------------------"); + for (int i = 0; i < TD_Task.Count; i++) + { + if (TD_Task[i].Todo_ID == T_ID) + { + check = false; + TD_Task.RemoveAll(e => e.Todo_ID == T_ID); + } + } + if (check) + { + Console.WriteLine("\n\n\t\t\t No Record Found!\n\n"); + } + else + { + Console.WriteLine("\n\n\t\t\t Record Deleted!\n\n"); + + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + } + catch (Exception) + { + + UI_msg("ERROR: Insert Only Intergers!"); + } + break; + + + case 8: + + while (true) + { + header(); + Console.WriteLine("\t\t\t1.Sort By ID."); + Console.WriteLine("\t\t\t2.Sort By DATE."); + Console.WriteLine("\t\t\t3.Sort By Level Of Importance."); + Console.WriteLine("\t\t\t4.Exit."); + footer(); + Console.Write(st + "Enter your choice: "); + ch = int.Parse(Console.ReadLine()); + + switch (ch) + { + + case 1: + + header(); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + Console.WriteLine("\t\t------------------------------------"); + TD_Task = TD_Task.OrderBy(x => x.Todo_ID).ToList(); + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 2: + + header(); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + Console.WriteLine("\t\t------------------------------------"); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 3: + + header(); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + Console.WriteLine("\t\t------------------------------------"); + TD_Task = TD_Task.OrderBy(x => x.Lvl_Imp).ToList(); + TD_Task.Reverse(); + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + case 4: + goto SUDO_MAIN; + + + default: + UI_msg("Invalid choice!"); + break; + } + + } + + case 9: + Environment.Exit(0); + break; + + default: + UI_msg("Invalid choice!"); + break; + + } + } + } + } + } \ No newline at end of file diff --git a/Week9/Program.cs b/Week9/Program.cs index 0ce3e294..2ab31d63 100644 --- a/Week9/Program.cs +++ b/Week9/Program.cs @@ -1,6 +1,6 @@ using System; -namespace Week7 +namespace Week9 { class Program { From cbf06aa6e2685cbff79c4968588a10c64d81c6ee Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Mon, 10 Dec 2018 18:53:04 -0600 Subject: [PATCH 3/7] Todo --- Todo/Todo.cs | 626 +++++++++++++++++++++++++++++++++++++++++++++++ Todo/Todo.csproj | 8 + 2 files changed, 634 insertions(+) create mode 100644 Todo/Todo.cs create mode 100644 Todo/Todo.csproj diff --git a/Todo/Todo.cs b/Todo/Todo.cs new file mode 100644 index 00000000..43c125e0 --- /dev/null +++ b/Todo/Todo.cs @@ -0,0 +1,626 @@ +using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Globalization; + using System.Security.Permissions; + using System.Threading; + + namespace To_Do_List_Tuhin + { + public class To_do : IComparable + { + public int Todo_ID { get; set; } + public DateTime date { get; set; } + public string Task { get; set; } + public int Lvl_Imp { get; set; } + + public To_do(int Todo_ID, DateTime date, string Task, int Lvl_Imp) + { + this.Todo_ID = Todo_ID; + this.date = date; + this.Task = Task; + this.Lvl_Imp = Lvl_Imp; + } + public int CompareTo(To_do other) + { + return this.Todo_ID.CompareTo(other.Todo_ID); + } + + } + + + class Program + { + public static string mt = "\t\t\t"; + public static string st = "\t\t "; + public static string xst = "\t\t"; + + //UI + public static void header() + { + Console.Clear(); + DateTime dtu = DateTime.Now; + + Console.WriteLine("\n\n\n\t\t\t\t\t" + dtu.ToString("dd-MM-yyyy")); + Console.WriteLine("\t\t===================================="); + Console.WriteLine("\t\t\t TO-DO List"); + Console.WriteLine("\t\t===================================="); + } + + public static void footer() + { + Console.WriteLine("\t\t===================================="); + } + + + + public static void UI_msg(String msg) + { + header(); + Console.WriteLine("\n\n" + st + msg + "\n\n"); + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + } + + + public static bool chk_date(String daaat) + { + string[] formats = { "d-M-yyyy" }; + DateTime parsedDateTime; + if (DateTime.TryParseExact(daaat, formats, new CultureInfo("en-US"), + DateTimeStyles.None, out parsedDateTime)) + { + return true; + } + else + { + return false; + } + } + + public static void Main() + { + Random rnd = new Random(); + int ID = rnd.Next(89); + + List TD_Task = new List(); + bool check = true; ; + + SUDO_MAIN: + + while (true) + { + + + header(); + Console.WriteLine(xst + "1.New Task.\t\t6.Update Task.\n"); + Console.WriteLine(xst + "2.View Al.\t\t7.Delete Task.\n"); + Console.WriteLine(xst + "3.View b/w Dates.\t8.Sort.\n"); + Console.WriteLine(xst + "4.Find Task.\t\t9.Exit\n"); + Console.WriteLine(xst + "5.Find Duplicates."); + footer(); + + Console.Write(st + "Enter your choice: "); + int ch = 0; + try + { + ch = int.Parse(Console.ReadLine()); + } + catch (Exception) + { + + UI_msg("ERROR: Insert Only Intergers!"); + } + + + switch (ch) + { + case 1: + header(); + Console.Write("\t\tEnter the Date.\t[dd-MM-yyyy]\n\t\t"); + try + { + string dat = Console.ReadLine(); + string daat = dat; + + DateTime cur_time = DateTime.Now; + cur_time.ToString("d-M-yyyy"); + try + { + TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dat.ToString())); + + + int day = (int)Math.Round(duration.TotalDays); + + int x=0 ; + if (day % 2 != 0) + { + x = 2; + } + else + { + x = 1; + } + + + if (day >= x) // if date less than todays + { + DateTime dtu = DateTime.Now; + string msg = "Plz select date from\n\t\t" + dtu.ToString("d-M-yyyy") + " onwards!"; + UI_msg("ERROR: " + msg); + goto SUDO_MAIN; + } + + } + catch (FormatException) + { + UI_msg("ERROR: Invalid Date!"); + goto SUDO_MAIN; + + } + + + + if (chk_date(daat)) // check validity of date + { + Console.Write("\n\t\tEnter Task.\n\t\t"); + string msg = Console.ReadLine(); + + Console.Write("\n\t\tEnter Level of Importance.\t[1-5]\n\t\t"); + int lvl = int.Parse(Console.ReadLine()); + if (lvl >= 1 && lvl <= 5) + { + ID++; + + TD_Task.Add(new To_do(ID, DateTime.Parse(dat), msg, lvl)); + UI_msg("New Task created with Task ID = " + ID.ToString()); + TD_Task.Sort(); // Sort db + } + else + { + UI_msg("ERROR: Only between [1-5]!"); + } + } + else + { + UI_msg("ERROR: Invalid Date!"); + } + + + } + catch (Exception) + { + UI_msg("ERROR: Enter Integer Only!!"); + } + break; + + case 2: + header(); + Console.WriteLine("\t\tID \tDate\tTask\t\tLevel"); + + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 3: + + header(); + + string cmp_date1, mon1, day1, S_d, E_d, S_m, E_m, S_da, E_da; + int SD, ED, cmp_date, mon, SM, EM, dayx, SDA, EDA; + + Console.Write("\t\tEnter starting Date.\t[dd-MM-yyyy]\n\t\t"); + string Sdat3 = Console.ReadLine(); + + if (chk_date(Sdat3)) // check validity of date + { + Console.Write("\n\t\tEnter ending Date.\t[dd-MM-yyyy]\n\t\t"); + string Edat3 = Console.ReadLine(); + Console.WriteLine("\t\t------------------------------------"); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + + if (chk_date(Edat3)) // check validity of date + { + + DateTime s = DateTime.Parse(Sdat3); + DateTime e = DateTime.Parse(Edat3); + + + for (int i = 0; i < TD_Task.Count; i++) + { + //year + cmp_date1 = TD_Task[i].date.ToString("yyyy"); + cmp_date = int.Parse(cmp_date1); + S_d = s.ToString("yyyy"); + E_d = e.ToString("yyyy"); + SD = int.Parse(S_d); + ED = int.Parse(E_d); + + //month + mon1 = TD_Task[i].date.ToString("MM"); + mon = int.Parse(mon1); + S_m = s.ToString("MM"); + E_m = e.ToString("MM"); + SM = int.Parse(S_m); + EM = int.Parse(E_m); + + //day + day1 = TD_Task[i].date.ToString("dd"); + dayx = int.Parse(day1); + S_da = s.ToString("dd"); + E_da = e.ToString("dd"); + SDA = int.Parse(S_da); + EDA = int.Parse(E_da); + + if (cmp_date >= SD && cmp_date <= ED) // Range of Years + { + if (mon >= SM && mon <= EM) // Range of Months + { + if (dayx >= SDA && dayx <= EDA) // Range of Days + { + check = false; + Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("dd-MM-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); + } + } + } + } + + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + } + else + { + UI_msg("ERROR: Invalid Ending Date!"); + } + } + else + { + UI_msg("ERROR: Invalid Starting Date!"); + } + + break; + + case 4: + header(); + Console.Write("\t\tEnter the String.\n\t\t"); + try + { + string str1; + string str = Console.ReadLine(); + str.ToLower(); + Console.WriteLine("\t\t------------------------------------"); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + for (int i = 0; i < TD_Task.Count; i++) + { + str1 = TD_Task[i].Task; + str1.ToLower(); + if (str1.Contains(str)) + { + check = false; + Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("dd-MM-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); + } + + + } + + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + } + catch (Exception) + { + + UI_msg("Error in Find string"); + } + + + break; + + case 5: + header(); + Console.WriteLine("\t\t------------------------------------"); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + string a; + int z=0; + foreach (To_do y in TD_Task) + { + a = y.Task; + + + z = 0; + foreach (To_do x in TD_Task) + { + + if (a.Equals(x.Task)) + { + z++; + + } + + + } + if (z >= 2) + { + check = false; + Console.WriteLine("\t\t" + y.Todo_ID + " " + y.date.ToString("dd-MM-yyyy") + "\t" + y.Task + "\t" + y.Lvl_Imp); + } + } + + if (check) + { + Console.WriteLine("\n\n\t\t No Duplicate Records Found!\n\n"); + } + + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 6: + header(); + Console.Write("\t\tEnter the Task_ID.\n\t\t"); + try + { + int T_ID = int.Parse(Console.ReadLine()); + Console.WriteLine("\t\t------------------------------------"); + for (int i = 0; i < TD_Task.Count; i++) + { + if (TD_Task[i].Todo_ID == T_ID) + { + check = false; + Console.Write("\t\tEnter the Date.\t[dd-MM-yyyy]\n\t\t"); + try + { + string dat = Console.ReadLine(); + string daat = dat; + + DateTime cur_time = DateTime.Now; + cur_time.ToString("d-M-yyyy"); + try + { + TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dat.ToString())); + + + int day = (int)Math.Round(duration.TotalDays); + + if (day >= 2) // if date less than todays + { + DateTime dtu = DateTime.Now; + string msg = "Plz select date from\n\t\t" + dtu.ToString("d-M-yyyy") + " onwards!"; + UI_msg("ERROR: " + msg); + goto SUDO_MAIN; + } + + } + catch (FormatException) + { + UI_msg("ERROR: Invalid Date!"); + goto SUDO_MAIN; + + } + + + + if (chk_date(daat)) // check validity of date + { + Console.Write("\n\t\tEnter Task.\n\t\t"); + string msg = Console.ReadLine(); + + Console.Write("\n\t\tEnter Level of Importance.\t[1-5]\n\t\t"); + int lvl = int.Parse(Console.ReadLine()); + if (lvl >= 1 && lvl <= 5) + { + + + TD_Task[i].date = DateTime.Parse(dat); + TD_Task[i].Task = msg; + TD_Task[i].Lvl_Imp = lvl; + + Console.WriteLine("\t\tTask Updated!"); + TD_Task.Sort(); // Sort db + } + else + { + UI_msg("ERROR: Only between [1-5]!"); + } + } + else + { + UI_msg("ERROR: Invalid Date!"); + } + + + } + catch (Exception) + { + UI_msg("ERROR: Enter Integer Only!!"); + } + + } + } + if (check) + { + Console.WriteLine("\n\n\t\t\t No Record Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + } + catch (Exception) + { + + UI_msg("ERROR: Insert Only Intergers!"); + } + break; + + case 7: + header(); + Console.Write("\t\tEnter the Task_ID.\n\t\t"); + try + { + int T_ID = int.Parse(Console.ReadLine()); + Console.WriteLine("\t\t------------------------------------"); + for (int i = 0; i < TD_Task.Count; i++) + { + if (TD_Task[i].Todo_ID == T_ID) + { + check = false; + TD_Task.RemoveAll(e => e.Todo_ID == T_ID); + } + } + if (check) + { + Console.WriteLine("\n\n\t\t\t No Record Found!\n\n"); + } + else + { + Console.WriteLine("\n\n\t\t\t Record Deleted!\n\n"); + + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + } + catch (Exception) + { + + UI_msg("ERROR: Insert Only Intergers!"); + } + break; + + + case 8: + + while (true) + { + header(); + Console.WriteLine("\t\t\t1.Sort By ID."); + Console.WriteLine("\t\t\t2.Sort By DATE."); + Console.WriteLine("\t\t\t3.Sort By Level Of Importance."); + Console.WriteLine("\t\t\t4.Exit."); + footer(); + Console.Write(st + "Enter your choice: "); + ch = int.Parse(Console.ReadLine()); + + switch (ch) + { + + case 1: + + header(); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + Console.WriteLine("\t\t------------------------------------"); + TD_Task = TD_Task.OrderBy(x => x.Todo_ID).ToList(); + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 2: + + header(); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + Console.WriteLine("\t\t------------------------------------"); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 3: + + header(); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + Console.WriteLine("\t\t------------------------------------"); + TD_Task = TD_Task.OrderBy(x => x.Lvl_Imp).ToList(); + TD_Task.Reverse(); + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + case 4: + goto SUDO_MAIN; + + + default: + UI_msg("Invalid choice!"); + break; + } + + } + + case 9: + Environment.Exit(0); + break; + + default: + UI_msg("Invalid choice!"); + break; + + } + } + } + } + } \ No newline at end of file diff --git a/Todo/Todo.csproj b/Todo/Todo.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/Todo/Todo.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + From 6921519664f6a59e26500a7f1113d0d771d16cf8 Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Mon, 17 Dec 2018 16:33:22 -0600 Subject: [PATCH 4/7] Todo.cs --- Todo/Todo.cs | 125 ++++++++++++++++++++++--------------------- week10/week10.cs | 46 ++++++++++++++++ week10/week10.csproj | 12 +++++ 3 files changed, 121 insertions(+), 62 deletions(-) create mode 100644 week10/week10.cs create mode 100644 week10/week10.csproj diff --git a/Todo/Todo.cs b/Todo/Todo.cs index 43c125e0..c691c63b 100644 --- a/Todo/Todo.cs +++ b/Todo/Todo.cs @@ -32,30 +32,31 @@ public int CompareTo(To_do other) class Program { + //commonly used string tabbing public static string mt = "\t\t\t"; public static string st = "\t\t "; public static string xst = "\t\t"; //UI - public static void header() + public static void header() //Draw the main Menu Header { Console.Clear(); DateTime dtu = DateTime.Now; - Console.WriteLine("\n\n\n\t\t\t\t\t" + dtu.ToString("dd-MM-yyyy")); + Console.WriteLine("\n\n\n\t\t\t\t\t" + dtu.ToString("MM-dd-yyyy")); Console.WriteLine("\t\t===================================="); Console.WriteLine("\t\t\t TO-DO List"); Console.WriteLine("\t\t===================================="); } - public static void footer() + public static void footer() //Draw the main Menu Footer { Console.WriteLine("\t\t===================================="); } - public static void UI_msg(String msg) + public static void Prompt(String msg) //Deliver common error messages and instructions { header(); Console.WriteLine("\n\n" + st + msg + "\n\n"); @@ -66,11 +67,11 @@ public static void UI_msg(String msg) } - public static bool chk_date(String daaat) + public static bool chk_date(String dateChk) //checking for a valid date entry { - string[] formats = { "d-M-yyyy" }; + string[] formats = { "M-d-yyyy" }; DateTime parsedDateTime; - if (DateTime.TryParseExact(daaat, formats, new CultureInfo("en-US"), + if (DateTime.TryParseExact(dateChk, formats, new CultureInfo("en-US"), DateTimeStyles.None, out parsedDateTime)) { return true; @@ -84,20 +85,20 @@ public static bool chk_date(String daaat) public static void Main() { Random rnd = new Random(); - int ID = rnd.Next(89); + int ID = rnd.Next(89); //generate random ID - List TD_Task = new List(); + List TD_Task = new List(); //setup the list container bool check = true; ; - SUDO_MAIN: + MAIN: //main menu while (true) { - header(); + header(); //Todo Menu Console.WriteLine(xst + "1.New Task.\t\t6.Update Task.\n"); - Console.WriteLine(xst + "2.View Al.\t\t7.Delete Task.\n"); + Console.WriteLine(xst + "2.View All.\t\t7.Delete Task.\n"); Console.WriteLine(xst + "3.View b/w Dates.\t8.Sort.\n"); Console.WriteLine(xst + "4.Find Task.\t\t9.Exit\n"); Console.WriteLine(xst + "5.Find Duplicates."); @@ -112,25 +113,25 @@ public static void Main() catch (Exception) { - UI_msg("ERROR: Insert Only Intergers!"); + Prompt("ERROR: Insert Only Intergers!"); } - + //Menu options and Error Catching based on selection (ch) switch (ch) { case 1: header(); - Console.Write("\t\tEnter the Date.\t[dd-MM-yyyy]\n\t\t"); + Console.Write("\t\tEnter the Date.\t[MM-dd-yyyy]\n\t\t"); try { - string dat = Console.ReadLine(); - string daat = dat; + string dateEntry = Console.ReadLine(); + string storedDateEntry = dateEntry; DateTime cur_time = DateTime.Now; - cur_time.ToString("d-M-yyyy"); + cur_time.ToString("M-d-yyyy"); try { - TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dat.ToString())); + TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dateEntry.ToString())); int day = (int)Math.Round(duration.TotalDays); @@ -149,22 +150,22 @@ public static void Main() if (day >= x) // if date less than todays { DateTime dtu = DateTime.Now; - string msg = "Plz select date from\n\t\t" + dtu.ToString("d-M-yyyy") + " onwards!"; - UI_msg("ERROR: " + msg); - goto SUDO_MAIN; + string msg = "Please select date from\n\t\t" + dtu.ToString("M-d-yyyy") + " onwards!"; + Prompt("ERROR: " + msg); + goto MAIN; } } catch (FormatException) { - UI_msg("ERROR: Invalid Date!"); - goto SUDO_MAIN; + Prompt("ERROR: Invalid Date!"); + goto MAIN; } - if (chk_date(daat)) // check validity of date + if (chk_date(storedDateEntry)) // check validity of date { Console.Write("\n\t\tEnter Task.\n\t\t"); string msg = Console.ReadLine(); @@ -175,25 +176,25 @@ public static void Main() { ID++; - TD_Task.Add(new To_do(ID, DateTime.Parse(dat), msg, lvl)); - UI_msg("New Task created with Task ID = " + ID.ToString()); + TD_Task.Add(new To_do(ID, DateTime.Parse(dateEntry), msg, lvl)); + Prompt("New Task created with Task ID = " + ID.ToString()); TD_Task.Sort(); // Sort db } else { - UI_msg("ERROR: Only between [1-5]!"); + Prompt("ERROR: Only between [1-5]!"); } } else { - UI_msg("ERROR: Invalid Date!"); + Prompt("ERROR: Invalid Date!"); } } catch (Exception) { - UI_msg("ERROR: Enter Integer Only!!"); + Prompt("ERROR: Enter Integer Only!!"); } break; @@ -204,7 +205,7 @@ public static void Main() foreach (To_do x in TD_Task) { check = false; - Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t\t" + x.Lvl_Imp); + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t\t" + x.Lvl_Imp); } if (check) { @@ -223,12 +224,12 @@ public static void Main() string cmp_date1, mon1, day1, S_d, E_d, S_m, E_m, S_da, E_da; int SD, ED, cmp_date, mon, SM, EM, dayx, SDA, EDA; - Console.Write("\t\tEnter starting Date.\t[dd-MM-yyyy]\n\t\t"); + Console.Write("\t\tEnter starting Date.\t[MM-dd-yyyy]\n\t\t"); string Sdat3 = Console.ReadLine(); if (chk_date(Sdat3)) // check validity of date { - Console.Write("\n\t\tEnter ending Date.\t[dd-MM-yyyy]\n\t\t"); + Console.Write("\n\t\tEnter ending Date.\t[MM-dd-yyyy]\n\t\t"); string Edat3 = Console.ReadLine(); Console.WriteLine("\t\t------------------------------------"); Console.WriteLine("\t\tID \tDate\tTask\tLevel"); @@ -273,7 +274,7 @@ public static void Main() if (dayx >= SDA && dayx <= EDA) // Range of Days { check = false; - Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("dd-MM-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); + Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("MM-dd-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); } } } @@ -289,12 +290,12 @@ public static void Main() } else { - UI_msg("ERROR: Invalid Ending Date!"); + Prompt("ERROR: Invalid Ending Date!"); } } else { - UI_msg("ERROR: Invalid Starting Date!"); + Prompt("ERROR: Invalid Starting Date!"); } break; @@ -316,7 +317,7 @@ public static void Main() if (str1.Contains(str)) { check = false; - Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("dd-MM-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); + Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("MM-dd-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); } @@ -333,7 +334,7 @@ public static void Main() catch (Exception) { - UI_msg("Error in Find string"); + Prompt("Error in Find string"); } @@ -365,7 +366,7 @@ public static void Main() if (z >= 2) { check = false; - Console.WriteLine("\t\t" + y.Todo_ID + " " + y.date.ToString("dd-MM-yyyy") + "\t" + y.Task + "\t" + y.Lvl_Imp); + Console.WriteLine("\t\t" + y.Todo_ID + " " + y.date.ToString("MM-dd-yyyy") + "\t" + y.Task + "\t" + y.Lvl_Imp); } } @@ -392,17 +393,17 @@ public static void Main() if (TD_Task[i].Todo_ID == T_ID) { check = false; - Console.Write("\t\tEnter the Date.\t[dd-MM-yyyy]\n\t\t"); + Console.Write("\t\tEnter the Date.\t[MM-dd-yyyy]\n\t\t"); try { - string dat = Console.ReadLine(); - string daat = dat; + string dateEntry = Console.ReadLine(); + string storedDateEntry = dateEntry; DateTime cur_time = DateTime.Now; - cur_time.ToString("d-M-yyyy"); + cur_time.ToString("M-d-yyyy"); try { - TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dat.ToString())); + TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dateEntry.ToString())); int day = (int)Math.Round(duration.TotalDays); @@ -410,22 +411,22 @@ public static void Main() if (day >= 2) // if date less than todays { DateTime dtu = DateTime.Now; - string msg = "Plz select date from\n\t\t" + dtu.ToString("d-M-yyyy") + " onwards!"; - UI_msg("ERROR: " + msg); - goto SUDO_MAIN; + string msg = "Plz select date from\n\t\t" + dtu.ToString("M-d-yyyy") + " onwards!"; + Prompt("ERROR: " + msg); + goto MAIN; } } catch (FormatException) { - UI_msg("ERROR: Invalid Date!"); - goto SUDO_MAIN; + Prompt("ERROR: Invalid Date!"); + goto MAIN; } - if (chk_date(daat)) // check validity of date + if (chk_date(storedDateEntry)) // check validity of date { Console.Write("\n\t\tEnter Task.\n\t\t"); string msg = Console.ReadLine(); @@ -436,7 +437,7 @@ public static void Main() { - TD_Task[i].date = DateTime.Parse(dat); + TD_Task[i].date = DateTime.Parse(dateEntry); TD_Task[i].Task = msg; TD_Task[i].Lvl_Imp = lvl; @@ -445,19 +446,19 @@ public static void Main() } else { - UI_msg("ERROR: Only between [1-5]!"); + Prompt("ERROR: Only between [1-5]!"); } } else { - UI_msg("ERROR: Invalid Date!"); + Prompt("ERROR: Invalid Date!"); } } catch (Exception) { - UI_msg("ERROR: Enter Integer Only!!"); + Prompt("ERROR: Enter Integer Only!!"); } } @@ -474,7 +475,7 @@ public static void Main() catch (Exception) { - UI_msg("ERROR: Insert Only Intergers!"); + Prompt("ERROR: Insert Only Intergers!"); } break; @@ -510,7 +511,7 @@ public static void Main() catch (Exception) { - UI_msg("ERROR: Insert Only Intergers!"); + Prompt("ERROR: Insert Only Intergers!"); } break; @@ -540,7 +541,7 @@ public static void Main() foreach (To_do x in TD_Task) { check = false; - Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); } if (check) { @@ -563,7 +564,7 @@ public static void Main() foreach (To_do x in TD_Task) { check = false; - Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); } if (check) { @@ -587,7 +588,7 @@ public static void Main() foreach (To_do x in TD_Task) { check = false; - Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("dd-MM-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); } if (check) { @@ -601,11 +602,11 @@ public static void Main() break; case 4: - goto SUDO_MAIN; + goto MAIN; default: - UI_msg("Invalid choice!"); + Prompt("Invalid choice!"); break; } @@ -616,7 +617,7 @@ public static void Main() break; default: - UI_msg("Invalid choice!"); + Prompt("Invalid choice!"); break; } diff --git a/week10/week10.cs b/week10/week10.cs new file mode 100644 index 00000000..8f1b1aed --- /dev/null +++ b/week10/week10.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; + +namespace week10 +{ + class Program + { + static void Main(string[] args) + { + Student john = new Student(1, "John Doe"); + Student jane = new Student(2, "Jane Doe"); + + Console.WriteLine(jane); + Console.WriteLine(john); + } + } + public class Student + { + public int id { get; set; } + public String name { get; set; } + + public Student(int id, String name) + { + this.id = id; + this.name = name; + } + override + public string ToString() + { + return id + ":" + name; + } + } + public class Context : DbContext + { + public DbSet myStudents { get; set; } + override + protected void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlite("Filename=./students.db"); + + } + + + } +} diff --git a/week10/week10.csproj b/week10/week10.csproj new file mode 100644 index 00000000..56f6f2cf --- /dev/null +++ b/week10/week10.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp2.1 + + + + + + + From ef75f874beae9f3271a0d3442ae5f6a38a6489a1 Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Mon, 17 Dec 2018 16:43:01 -0600 Subject: [PATCH 5/7] Todo.cs --- Todo/Todo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Todo/Todo.cs b/Todo/Todo.cs index c691c63b..d86c55b0 100644 --- a/Todo/Todo.cs +++ b/Todo/Todo.cs @@ -227,7 +227,7 @@ public static void Main() Console.Write("\t\tEnter starting Date.\t[MM-dd-yyyy]\n\t\t"); string Sdat3 = Console.ReadLine(); - if (chk_date(Sdat3)) // check validity of date + if (chk_date(Sdat3)) // enter validity of date { Console.Write("\n\t\tEnter ending Date.\t[MM-dd-yyyy]\n\t\t"); string Edat3 = Console.ReadLine(); From ee14a163ab8b87f4a685733e37df9ab12d2975b2 Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Mon, 17 Dec 2018 18:36:06 -0600 Subject: [PATCH 6/7] Todo.cs --- Todo/Todo.cs | 1254 +++++++++++++++++++++++++------------------------- 1 file changed, 627 insertions(+), 627 deletions(-) diff --git a/Todo/Todo.cs b/Todo/Todo.cs index d86c55b0..f1bbb135 100644 --- a/Todo/Todo.cs +++ b/Todo/Todo.cs @@ -1,627 +1,627 @@ -using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Globalization; - using System.Security.Permissions; - using System.Threading; - - namespace To_Do_List_Tuhin - { - public class To_do : IComparable - { - public int Todo_ID { get; set; } - public DateTime date { get; set; } - public string Task { get; set; } - public int Lvl_Imp { get; set; } - - public To_do(int Todo_ID, DateTime date, string Task, int Lvl_Imp) - { - this.Todo_ID = Todo_ID; - this.date = date; - this.Task = Task; - this.Lvl_Imp = Lvl_Imp; - } - public int CompareTo(To_do other) - { - return this.Todo_ID.CompareTo(other.Todo_ID); - } - - } - - - class Program - { - //commonly used string tabbing - public static string mt = "\t\t\t"; - public static string st = "\t\t "; - public static string xst = "\t\t"; - - //UI - public static void header() //Draw the main Menu Header - { - Console.Clear(); - DateTime dtu = DateTime.Now; - - Console.WriteLine("\n\n\n\t\t\t\t\t" + dtu.ToString("MM-dd-yyyy")); - Console.WriteLine("\t\t===================================="); - Console.WriteLine("\t\t\t TO-DO List"); - Console.WriteLine("\t\t===================================="); - } - - public static void footer() //Draw the main Menu Footer - { - Console.WriteLine("\t\t===================================="); - } - - - - public static void Prompt(String msg) //Deliver common error messages and instructions - { - header(); - Console.WriteLine("\n\n" + st + msg + "\n\n"); - footer(); - Console.Write(st + "Press key to continue:"); - Console.ReadKey(); - - } - - - public static bool chk_date(String dateChk) //checking for a valid date entry - { - string[] formats = { "M-d-yyyy" }; - DateTime parsedDateTime; - if (DateTime.TryParseExact(dateChk, formats, new CultureInfo("en-US"), - DateTimeStyles.None, out parsedDateTime)) - { - return true; - } - else - { - return false; - } - } - - public static void Main() - { - Random rnd = new Random(); - int ID = rnd.Next(89); //generate random ID - - List TD_Task = new List(); //setup the list container - bool check = true; ; - - MAIN: //main menu - - while (true) - { - - - header(); //Todo Menu - Console.WriteLine(xst + "1.New Task.\t\t6.Update Task.\n"); - Console.WriteLine(xst + "2.View All.\t\t7.Delete Task.\n"); - Console.WriteLine(xst + "3.View b/w Dates.\t8.Sort.\n"); - Console.WriteLine(xst + "4.Find Task.\t\t9.Exit\n"); - Console.WriteLine(xst + "5.Find Duplicates."); - footer(); - - Console.Write(st + "Enter your choice: "); - int ch = 0; - try - { - ch = int.Parse(Console.ReadLine()); - } - catch (Exception) - { - - Prompt("ERROR: Insert Only Intergers!"); - } - - //Menu options and Error Catching based on selection (ch) - switch (ch) - { - case 1: - header(); - Console.Write("\t\tEnter the Date.\t[MM-dd-yyyy]\n\t\t"); - try - { - string dateEntry = Console.ReadLine(); - string storedDateEntry = dateEntry; - - DateTime cur_time = DateTime.Now; - cur_time.ToString("M-d-yyyy"); - try - { - TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dateEntry.ToString())); - - - int day = (int)Math.Round(duration.TotalDays); - - int x=0 ; - if (day % 2 != 0) - { - x = 2; - } - else - { - x = 1; - } - - - if (day >= x) // if date less than todays - { - DateTime dtu = DateTime.Now; - string msg = "Please select date from\n\t\t" + dtu.ToString("M-d-yyyy") + " onwards!"; - Prompt("ERROR: " + msg); - goto MAIN; - } - - } - catch (FormatException) - { - Prompt("ERROR: Invalid Date!"); - goto MAIN; - - } - - - - if (chk_date(storedDateEntry)) // check validity of date - { - Console.Write("\n\t\tEnter Task.\n\t\t"); - string msg = Console.ReadLine(); - - Console.Write("\n\t\tEnter Level of Importance.\t[1-5]\n\t\t"); - int lvl = int.Parse(Console.ReadLine()); - if (lvl >= 1 && lvl <= 5) - { - ID++; - - TD_Task.Add(new To_do(ID, DateTime.Parse(dateEntry), msg, lvl)); - Prompt("New Task created with Task ID = " + ID.ToString()); - TD_Task.Sort(); // Sort db - } - else - { - Prompt("ERROR: Only between [1-5]!"); - } - } - else - { - Prompt("ERROR: Invalid Date!"); - } - - - } - catch (Exception) - { - Prompt("ERROR: Enter Integer Only!!"); - } - break; - - case 2: - header(); - Console.WriteLine("\t\tID \tDate\tTask\t\tLevel"); - - foreach (To_do x in TD_Task) - { - check = false; - Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t\t" + x.Lvl_Imp); - } - if (check) - { - Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); - } - footer(); - Console.Write(st + "Press key to continue:"); - Console.ReadKey(); - - break; - - case 3: - - header(); - - string cmp_date1, mon1, day1, S_d, E_d, S_m, E_m, S_da, E_da; - int SD, ED, cmp_date, mon, SM, EM, dayx, SDA, EDA; - - Console.Write("\t\tEnter starting Date.\t[MM-dd-yyyy]\n\t\t"); - string Sdat3 = Console.ReadLine(); - - if (chk_date(Sdat3)) // enter validity of date - { - Console.Write("\n\t\tEnter ending Date.\t[MM-dd-yyyy]\n\t\t"); - string Edat3 = Console.ReadLine(); - Console.WriteLine("\t\t------------------------------------"); - Console.WriteLine("\t\tID \tDate\tTask\tLevel"); - - if (chk_date(Edat3)) // check validity of date - { - - DateTime s = DateTime.Parse(Sdat3); - DateTime e = DateTime.Parse(Edat3); - - - for (int i = 0; i < TD_Task.Count; i++) - { - //year - cmp_date1 = TD_Task[i].date.ToString("yyyy"); - cmp_date = int.Parse(cmp_date1); - S_d = s.ToString("yyyy"); - E_d = e.ToString("yyyy"); - SD = int.Parse(S_d); - ED = int.Parse(E_d); - - //month - mon1 = TD_Task[i].date.ToString("MM"); - mon = int.Parse(mon1); - S_m = s.ToString("MM"); - E_m = e.ToString("MM"); - SM = int.Parse(S_m); - EM = int.Parse(E_m); - - //day - day1 = TD_Task[i].date.ToString("dd"); - dayx = int.Parse(day1); - S_da = s.ToString("dd"); - E_da = e.ToString("dd"); - SDA = int.Parse(S_da); - EDA = int.Parse(E_da); - - if (cmp_date >= SD && cmp_date <= ED) // Range of Years - { - if (mon >= SM && mon <= EM) // Range of Months - { - if (dayx >= SDA && dayx <= EDA) // Range of Days - { - check = false; - Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("MM-dd-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); - } - } - } - } - - if (check) - { - Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); - } - footer(); - Console.Write(st + "Press key to continue:"); - Console.ReadKey(); - } - else - { - Prompt("ERROR: Invalid Ending Date!"); - } - } - else - { - Prompt("ERROR: Invalid Starting Date!"); - } - - break; - - case 4: - header(); - Console.Write("\t\tEnter the String.\n\t\t"); - try - { - string str1; - string str = Console.ReadLine(); - str.ToLower(); - Console.WriteLine("\t\t------------------------------------"); - Console.WriteLine("\t\tID \tDate\tTask\tLevel"); - for (int i = 0; i < TD_Task.Count; i++) - { - str1 = TD_Task[i].Task; - str1.ToLower(); - if (str1.Contains(str)) - { - check = false; - Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("MM-dd-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); - } - - - } - - if (check) - { - Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); - } - footer(); - Console.Write(st + "Press key to continue:"); - Console.ReadKey(); - } - catch (Exception) - { - - Prompt("Error in Find string"); - } - - - break; - - case 5: - header(); - Console.WriteLine("\t\t------------------------------------"); - Console.WriteLine("\t\tID \tDate\tTask\tLevel"); - string a; - int z=0; - foreach (To_do y in TD_Task) - { - a = y.Task; - - - z = 0; - foreach (To_do x in TD_Task) - { - - if (a.Equals(x.Task)) - { - z++; - - } - - - } - if (z >= 2) - { - check = false; - Console.WriteLine("\t\t" + y.Todo_ID + " " + y.date.ToString("MM-dd-yyyy") + "\t" + y.Task + "\t" + y.Lvl_Imp); - } - } - - if (check) - { - Console.WriteLine("\n\n\t\t No Duplicate Records Found!\n\n"); - } - - footer(); - Console.Write(st + "Press key to continue:"); - Console.ReadKey(); - - break; - - case 6: - header(); - Console.Write("\t\tEnter the Task_ID.\n\t\t"); - try - { - int T_ID = int.Parse(Console.ReadLine()); - Console.WriteLine("\t\t------------------------------------"); - for (int i = 0; i < TD_Task.Count; i++) - { - if (TD_Task[i].Todo_ID == T_ID) - { - check = false; - Console.Write("\t\tEnter the Date.\t[MM-dd-yyyy]\n\t\t"); - try - { - string dateEntry = Console.ReadLine(); - string storedDateEntry = dateEntry; - - DateTime cur_time = DateTime.Now; - cur_time.ToString("M-d-yyyy"); - try - { - TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dateEntry.ToString())); - - - int day = (int)Math.Round(duration.TotalDays); - - if (day >= 2) // if date less than todays - { - DateTime dtu = DateTime.Now; - string msg = "Plz select date from\n\t\t" + dtu.ToString("M-d-yyyy") + " onwards!"; - Prompt("ERROR: " + msg); - goto MAIN; - } - - } - catch (FormatException) - { - Prompt("ERROR: Invalid Date!"); - goto MAIN; - - } - - - - if (chk_date(storedDateEntry)) // check validity of date - { - Console.Write("\n\t\tEnter Task.\n\t\t"); - string msg = Console.ReadLine(); - - Console.Write("\n\t\tEnter Level of Importance.\t[1-5]\n\t\t"); - int lvl = int.Parse(Console.ReadLine()); - if (lvl >= 1 && lvl <= 5) - { - - - TD_Task[i].date = DateTime.Parse(dateEntry); - TD_Task[i].Task = msg; - TD_Task[i].Lvl_Imp = lvl; - - Console.WriteLine("\t\tTask Updated!"); - TD_Task.Sort(); // Sort db - } - else - { - Prompt("ERROR: Only between [1-5]!"); - } - } - else - { - Prompt("ERROR: Invalid Date!"); - } - - - } - catch (Exception) - { - Prompt("ERROR: Enter Integer Only!!"); - } - - } - } - if (check) - { - Console.WriteLine("\n\n\t\t\t No Record Found!\n\n"); - } - footer(); - Console.Write(st + "Press key to continue:"); - Console.ReadKey(); - - } - catch (Exception) - { - - Prompt("ERROR: Insert Only Intergers!"); - } - break; - - case 7: - header(); - Console.Write("\t\tEnter the Task_ID.\n\t\t"); - try - { - int T_ID = int.Parse(Console.ReadLine()); - Console.WriteLine("\t\t------------------------------------"); - for (int i = 0; i < TD_Task.Count; i++) - { - if (TD_Task[i].Todo_ID == T_ID) - { - check = false; - TD_Task.RemoveAll(e => e.Todo_ID == T_ID); - } - } - if (check) - { - Console.WriteLine("\n\n\t\t\t No Record Found!\n\n"); - } - else - { - Console.WriteLine("\n\n\t\t\t Record Deleted!\n\n"); - - } - footer(); - Console.Write(st + "Press key to continue:"); - Console.ReadKey(); - - } - catch (Exception) - { - - Prompt("ERROR: Insert Only Intergers!"); - } - break; - - - case 8: - - while (true) - { - header(); - Console.WriteLine("\t\t\t1.Sort By ID."); - Console.WriteLine("\t\t\t2.Sort By DATE."); - Console.WriteLine("\t\t\t3.Sort By Level Of Importance."); - Console.WriteLine("\t\t\t4.Exit."); - footer(); - Console.Write(st + "Enter your choice: "); - ch = int.Parse(Console.ReadLine()); - - switch (ch) - { - - case 1: - - header(); - Console.WriteLine("\t\tID \tDate\tTask\tLevel"); - Console.WriteLine("\t\t------------------------------------"); - TD_Task = TD_Task.OrderBy(x => x.Todo_ID).ToList(); - foreach (To_do x in TD_Task) - { - check = false; - Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); - } - if (check) - { - Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); - } - footer(); - TD_Task = TD_Task.OrderBy(x => x.date).ToList(); - - Console.Write(st + "Press key to continue:"); - Console.ReadKey(); - - break; - - case 2: - - header(); - Console.WriteLine("\t\tID \tDate\tTask\tLevel"); - Console.WriteLine("\t\t------------------------------------"); - TD_Task = TD_Task.OrderBy(x => x.date).ToList(); - foreach (To_do x in TD_Task) - { - check = false; - Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); - } - if (check) - { - Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); - } - footer(); - TD_Task = TD_Task.OrderBy(x => x.date).ToList(); - - Console.Write(st + "Press key to continue:"); - Console.ReadKey(); - - break; - - case 3: - - header(); - Console.WriteLine("\t\tID \tDate\tTask\tLevel"); - Console.WriteLine("\t\t------------------------------------"); - TD_Task = TD_Task.OrderBy(x => x.Lvl_Imp).ToList(); - TD_Task.Reverse(); - foreach (To_do x in TD_Task) - { - check = false; - Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); - } - if (check) - { - Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); - } - footer(); - TD_Task = TD_Task.OrderBy(x => x.date).ToList(); - - Console.Write(st + "Press key to continue:"); - Console.ReadKey(); - - break; - case 4: - goto MAIN; - - - default: - Prompt("Invalid choice!"); - break; - } - - } - - case 9: - Environment.Exit(0); - break; - - default: - Prompt("Invalid choice!"); - break; - - } - } - } - } - } \ No newline at end of file +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Globalization; +using System.Security.Permissions; +using System.Threading; + +namespace To_Do_List +{ + public class To_do : IComparable + { + public int Todo_ID { get; set; } + public DateTime date { get; set; } + public string Task { get; set; } + public int Lvl_Imp { get; set; } + + public To_do(int Todo_ID, DateTime date, string Task, int Lvl_Imp) + { + this.Todo_ID = Todo_ID; + this.date = date; + this.Task = Task; + this.Lvl_Imp = Lvl_Imp; + } + public int CompareTo(To_do other) + { + return this.Todo_ID.CompareTo(other.Todo_ID); + } + + } + + + class Program + { + //commonly used string tabbing + public static string mt = "\t\t\t"; + public static string st = "\t\t "; + public static string xst = "\t\t"; + + //UI + public static void header() //Draw the main Menu Header + { + Console.Clear(); + DateTime dtu = DateTime.Now; + + Console.WriteLine("\n\n\n\t\t\t\t\t" + dtu.ToString("MM-dd-yyyy")); + Console.WriteLine("\t\t===================================="); + Console.WriteLine("\t\t\t TO-DO List"); + Console.WriteLine("\t\t===================================="); + } + + public static void footer() //Draw the main Menu Footer + { + Console.WriteLine("\t\t===================================="); + } + + + + public static void Prompt(String msg) //Deliver common error messages and instructions + { + header(); + Console.WriteLine("\n\n" + st + msg + "\n\n"); + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + } + + + public static bool chk_date(String dateChk) //checking for a valid date entry + { + string[] formats = { "M-d-yyyy" }; + DateTime parsedDateTime; + if (DateTime.TryParseExact(dateChk, formats, new CultureInfo("en-US"), + DateTimeStyles.None, out parsedDateTime)) + { + return true; + } + else + { + return false; + } + } + + public static void Main() + { + Random rnd = new Random(); + int ID = rnd.Next(89); //generate random ID + + List TD_Task = new List(); //setup the list container + bool check = true; ; + + MAIN: //main menu + + while (true) + { + + + header(); //Todo Menu + Console.WriteLine(xst + "1.New Task.\t\t6.Update Task.\n"); + Console.WriteLine(xst + "2.View All.\t\t7.Delete Task.\n"); + Console.WriteLine(xst + "3.View b/w Dates.\t8.Sort.\n"); + Console.WriteLine(xst + "4.Find Task.\t\t9.Exit\n"); + Console.WriteLine(xst + "5.Find Duplicates."); + footer(); + + Console.Write(st + "Enter your choice: "); + int ch = 0; + try + { + ch = int.Parse(Console.ReadLine()); + } + catch (Exception) + { + + Prompt("ERROR: Insert Only Intergers!"); + } + + //Menu options and Error Catching based on selection (ch) + switch (ch) + { + case 1: + header(); + Console.Write("\t\tEnter the Date.\t[MM-dd-yyyy]\n\t\t"); + try + { + string dateEntry = Console.ReadLine(); + string storedDateEntry = dateEntry; + + DateTime cur_time = DateTime.Now; + cur_time.ToString("M-d-yyyy"); + try + { + TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dateEntry.ToString())); + + + int day = (int)Math.Round(duration.TotalDays); + + int x = 0; + if (day % 2 != 0) + { + x = 2; + } + else + { + x = 1; + } + + + if (day >= x) // if date less than todays + { + DateTime dtu = DateTime.Now; + string msg = "Please select date from\n\t\t" + dtu.ToString("M-d-yyyy") + " onwards!"; + Prompt("ERROR: " + msg); + goto MAIN; + } + + } + catch (FormatException) + { + Prompt("ERROR: Invalid Date!"); + goto MAIN; + + } + + + + if (chk_date(storedDateEntry)) // check validity of date + { + Console.Write("\n\t\tEnter Task.\n\t\t"); + string msg = Console.ReadLine(); + + Console.Write("\n\t\tEnter Level of Importance.\t[1-5]\n\t\t"); + int lvl = int.Parse(Console.ReadLine()); + if (lvl >= 1 && lvl <= 5) + { + ID++; + + TD_Task.Add(new To_do(ID, DateTime.Parse(dateEntry), msg, lvl)); + Prompt("New Task created with Task ID = " + ID.ToString()); + TD_Task.Sort(); // Sort db + } + else + { + Prompt("ERROR: Only between [1-5]!"); + } + } + else + { + Prompt("ERROR: Invalid Date!"); + } + + + } + catch (Exception) + { + Prompt("ERROR: Enter Integer Only!!"); + } + break; + + case 2: + header(); + Console.WriteLine("\t\tID \tDate\tTask\t\tLevel"); + + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 3: + + header(); + + string cmp_date1, mon1, day1, S_d, E_d, S_m, E_m, S_da, E_da; + int SD, ED, cmp_date, mon, SM, EM, dayx, SDA, EDA; + + Console.Write("\t\tEnter starting Date.\t[MM-dd-yyyy]\n\t\t"); + string Sdat3 = Console.ReadLine(); + + if (chk_date(Sdat3)) // enter validity of date + { + Console.Write("\n\t\tEnter ending Date.\t[MM-dd-yyyy]\n\t\t"); + string Edat3 = Console.ReadLine(); + Console.WriteLine("\t\t------------------------------------"); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + + if (chk_date(Edat3)) // check validity of date + { + + DateTime s = DateTime.Parse(Sdat3); + DateTime e = DateTime.Parse(Edat3); + + + for (int i = 0; i < TD_Task.Count; i++) + { + //year + cmp_date1 = TD_Task[i].date.ToString("yyyy"); + cmp_date = int.Parse(cmp_date1); + S_d = s.ToString("yyyy"); + E_d = e.ToString("yyyy"); + SD = int.Parse(S_d); + ED = int.Parse(E_d); + + //month + mon1 = TD_Task[i].date.ToString("MM"); + mon = int.Parse(mon1); + S_m = s.ToString("MM"); + E_m = e.ToString("MM"); + SM = int.Parse(S_m); + EM = int.Parse(E_m); + + //day + day1 = TD_Task[i].date.ToString("dd"); + dayx = int.Parse(day1); + S_da = s.ToString("dd"); + E_da = e.ToString("dd"); + SDA = int.Parse(S_da); + EDA = int.Parse(E_da); + + if (cmp_date >= SD && cmp_date <= ED) // Range of Years + { + if (mon >= SM && mon <= EM) // Range of Months + { + if (dayx >= SDA && dayx <= EDA) // Range of Days + { + check = false; + Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("MM-dd-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); + } + } + } + } + + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + } + else + { + Prompt("ERROR: Invalid Ending Date!"); + } + } + else + { + Prompt("ERROR: Invalid Starting Date!"); + } + + break; + + case 4: + header(); + Console.Write("\t\tEnter the String.\n\t\t"); + try + { + string str1; + string str = Console.ReadLine(); + str.ToLower(); + Console.WriteLine("\t\t------------------------------------"); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + for (int i = 0; i < TD_Task.Count; i++) + { + str1 = TD_Task[i].Task; + str1.ToLower(); + if (str1.Contains(str)) + { + check = false; + Console.WriteLine("\t\t" + TD_Task[i].Todo_ID + " " + TD_Task[i].date.ToString("MM-dd-yyyy") + "\t " + TD_Task[i].Task + "\t " + TD_Task[i].Lvl_Imp); + } + + + } + + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + } + catch (Exception) + { + + Prompt("Error in Find string"); + } + + + break; + + case 5: + header(); + Console.WriteLine("\t\t------------------------------------"); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + string a; + int z = 0; + foreach (To_do y in TD_Task) + { + a = y.Task; + + + z = 0; + foreach (To_do x in TD_Task) + { + + if (a.Equals(x.Task)) + { + z++; + + } + + + } + if (z >= 2) + { + check = false; + Console.WriteLine("\t\t" + y.Todo_ID + " " + y.date.ToString("MM-dd-yyyy") + "\t" + y.Task + "\t" + y.Lvl_Imp); + } + } + + if (check) + { + Console.WriteLine("\n\n\t\t No Duplicate Records Found!\n\n"); + } + + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 6: + header(); + Console.Write("\t\tEnter the Task_ID.\n\t\t"); + try + { + int T_ID = int.Parse(Console.ReadLine()); + Console.WriteLine("\t\t------------------------------------"); + for (int i = 0; i < TD_Task.Count; i++) + { + if (TD_Task[i].Todo_ID == T_ID) + { + check = false; + Console.Write("\t\tEnter the Date.\t[MM-dd-yyyy]\n\t\t"); + try + { + string dateEntry = Console.ReadLine(); + string storedDateEntry = dateEntry; + + DateTime cur_time = DateTime.Now; + cur_time.ToString("M-d-yyyy"); + try + { + TimeSpan duration = DateTime.Parse(cur_time.ToString()) - (DateTime.Parse(dateEntry.ToString())); + + + int day = (int)Math.Round(duration.TotalDays); + + if (day >= 2) // if date less than todays + { + DateTime dtu = DateTime.Now; + string msg = "Plz select date from\n\t\t" + dtu.ToString("M-d-yyyy") + " onwards!"; + Prompt("ERROR: " + msg); + goto MAIN; + } + + } + catch (FormatException) + { + Prompt("ERROR: Invalid Date!"); + goto MAIN; + + } + + + + if (chk_date(storedDateEntry)) // check validity of date + { + Console.Write("\n\t\tEnter Task.\n\t\t"); + string msg = Console.ReadLine(); + + Console.Write("\n\t\tEnter Level of Importance.\t[1-5]\n\t\t"); + int lvl = int.Parse(Console.ReadLine()); + if (lvl >= 1 && lvl <= 5) + { + + + TD_Task[i].date = DateTime.Parse(dateEntry); + TD_Task[i].Task = msg; + TD_Task[i].Lvl_Imp = lvl; + + Console.WriteLine("\t\tTask Updated!"); + TD_Task.Sort(); // Sort db + } + else + { + Prompt("ERROR: Only between [1-5]!"); + } + } + else + { + Prompt("ERROR: Invalid Date!"); + } + + + } + catch (Exception) + { + Prompt("ERROR: Enter Integer Only!!"); + } + + } + } + if (check) + { + Console.WriteLine("\n\n\t\t\t No Record Found!\n\n"); + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + } + catch (Exception) + { + + Prompt("ERROR: Insert Only Intergers!"); + } + break; + + case 7: + header(); + Console.Write("\t\tEnter the Task_ID.\n\t\t"); + try + { + int T_ID = int.Parse(Console.ReadLine()); + Console.WriteLine("\t\t------------------------------------"); + for (int i = 0; i < TD_Task.Count; i++) + { + if (TD_Task[i].Todo_ID == T_ID) + { + check = false; + TD_Task.RemoveAll(e => e.Todo_ID == T_ID); + } + } + if (check) + { + Console.WriteLine("\n\n\t\t\t No Record Found!\n\n"); + } + else + { + Console.WriteLine("\n\n\t\t\t Record Deleted!\n\n"); + + } + footer(); + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + } + catch (Exception) + { + + Prompt("ERROR: Insert Only Intergers!"); + } + break; + + + case 8: + + while (true) + { + header(); + Console.WriteLine("\t\t\t1.Sort By ID."); + Console.WriteLine("\t\t\t2.Sort By DATE."); + Console.WriteLine("\t\t\t3.Sort By Level Of Importance."); + Console.WriteLine("\t\t\t4.Exit."); + footer(); + Console.Write(st + "Enter your choice: "); + ch = int.Parse(Console.ReadLine()); + + switch (ch) + { + + case 1: + + header(); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + Console.WriteLine("\t\t------------------------------------"); + TD_Task = TD_Task.OrderBy(x => x.Todo_ID).ToList(); + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 2: + + header(); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + Console.WriteLine("\t\t------------------------------------"); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + + case 3: + + header(); + Console.WriteLine("\t\tID \tDate\tTask\tLevel"); + Console.WriteLine("\t\t------------------------------------"); + TD_Task = TD_Task.OrderBy(x => x.Lvl_Imp).ToList(); + TD_Task.Reverse(); + foreach (To_do x in TD_Task) + { + check = false; + Console.WriteLine("\t\t" + x.Todo_ID + " " + x.date.ToString("MM-dd-yyyy") + "\t" + x.Task + "\t" + x.Lvl_Imp); + } + if (check) + { + Console.WriteLine("\n\n\t\t\tNo Records Found!\n\n"); + } + footer(); + TD_Task = TD_Task.OrderBy(x => x.date).ToList(); + + Console.Write(st + "Press key to continue:"); + Console.ReadKey(); + + break; + case 4: + goto MAIN; + + + default: + Prompt("Invalid choice!"); + break; + } + + } + + case 9: + Environment.Exit(0); + break; + + default: + Prompt("Invalid choice!"); + break; + + } + } + } + } +} \ No newline at end of file From c0caabff26bf7bdbe11939cd6d788b9a19fc44bf Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Mon, 17 Dec 2018 20:08:23 -0600 Subject: [PATCH 7/7] Todo.cs --- Todo/Todo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Todo/Todo.cs b/Todo/Todo.cs index f1bbb135..59e64d2c 100644 --- a/Todo/Todo.cs +++ b/Todo/Todo.cs @@ -87,7 +87,7 @@ public static void Main() Random rnd = new Random(); int ID = rnd.Next(89); //generate random ID - List TD_Task = new List(); //setup the list container + List TD_Task = new List(); //setup the list container, just storing to memory fix this bool check = true; ; MAIN: //main menu