//Retrieve() public static List <Staff> Retrieve(List <Staff> L, string file) { Console.WriteLine("choose the index number\n1:PwId;\n2:StaffName;\n3:SeatNo;\n4:for firstname"); string f = Console.ReadLine(); Console.WriteLine("input the index data:"); string str = Console.ReadLine(); List <Staff> result = null; switch (f) { case "1": result = (from s in L where s.GetPwId() == str select s).ToList <Staff>(); break; case "2": result = (from s in L where s.GetStaffName() == str select s).ToList <Staff>(); break; case "3": result = (from s in L where s.GetSeatNo() == str select s).ToList <Staff>(); break; case "4": result = (from s in L where (s.GetStaffName().StartsWith(str)) select s).ToList <Staff>(); break; default: CodeControl.PrintError(); break; } foreach (Staff s in result) { Console.WriteLine(s.ToString()); } Console.WriteLine("there are(is) {0} records matched.", result.Count); return(result); }
static int Main(string[] args) { //List-Object List <Staff> L = new List <Staff>(); Console.WriteLine("Welcome."); ConsoleApplication1.CodeControl.PrintLine(); //DefaultFile const string DefaultFile = @"D:\project"; string path = DefaultFile; //DirInfo FileSystem.DirInfo(DefaultFile); while (true) { //Instruction() Console.WriteLine("Input the instruction:\n1:go into a cataloge;\n2:go back the cataloge;\n3:open a file;\n*:exit"); string F = Console.ReadLine(); //switch switch (F) { case "1": Console.WriteLine("please input the foldername:"); string folder = Console.ReadLine(); path = FileSystem.GoInto(path, folder); break; case "2": path = FileSystem.GoBack(path); break; case "3": Console.WriteLine("please input the filename:"); string file = Console.ReadLine(); file = DefaultFile + "\\" + file; file = FileSystem.FileExists(file); if (File.Exists(file)) { L = FileSystem.GetData(file); FileCRUD.CRUD(L, file); } else { CodeControl.PrintLine(); return(0); } break; case "*": CodeControl.PrintLine(); return(0); default: CodeControl.PrintError(); break; } } Console.ReadKey(); return(0); }
//Delete() public static List <Staff> Delete(List <Staff> L, string file) { Console.WriteLine("input the instruction\n1:rows;\n2;Retrieve"); string f = Console.ReadLine(); string stringArray = "PwId,StaffName,SeatNo,RoomId,Department,CostCenter\n"; switch (f) { case "1": Console.WriteLine("the begining row:"); int br = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("the ending row:"); int er = Convert.ToInt32(Console.ReadLine()); File.Delete(file); File.AppendAllText(file, stringArray); for (int i = 0; i < L.Count; i++) { if ((i >= 0 && i < br - 1) || (i > er - 1 && i <= L.Count - 1)) { File.AppendAllText(file, L[i].ToString()); } } break; case "2": Console.WriteLine("Let's do the Retrieve first."); List <Staff> result = Retrieve(L, file); for (int i = 0; i < L.Count; i++) { for (int j = 0; j < result.Count; j++) { if (L[i] == result[j]) { L.Remove(L[i]); } } } File.Delete(file); File.AppendAllText(file, stringArray); for (int k = 0; k < L.Count; k++) { File.AppendAllText(file, L[k].ToString()); } CodeControl.PrintFinish(); break; default: CodeControl.PrintError(); break; } return(L); }
//FileExists() public static string FileExists(string file) { while (!File.Exists(file)) { Console.WriteLine("File do not exists. Try again."); Console.WriteLine("input the instructon:\n1;continue;\n2:exit"); string f = Console.ReadLine(); switch (f) { case "1": Console.WriteLine("File do not exists. Try again."); file = Console.ReadLine(); file = @"D:\project" + "\\" + file; break; case "2": return(null); default: CodeControl.PrintError(); break; } } Console.WriteLine("File do exist."); Console.WriteLine(); return(file); }
//Update() public static List <Staff> Update(List <Staff> L, string file) { Console.WriteLine("choose the index number you want to update\n1:PwId;\n2:StaffName;\n3:SeatNo"); string f = Console.ReadLine(); switch (f) { case "1": Set(L, file, "1"); break; case "2": Set(L, file, "2"); break; case "3": Set(L, file, "3"); break; default: CodeControl.PrintError(); break; } return(L); }