Beispiel #1
0
        //InsertData()
        public static List <Staff> InsertData(List <Staff> L, string file)
        {
            Staff  s;
            string line;

            string[]     stringArray = new string[6];
            char[]       charArray   = new char[] { ',' };
            StreamWriter sw;

            sw = File.AppendText(file);

            Console.WriteLine(@"input your information as the famart:\\nPwId,StaffName,SeatNo,RoomId,Department,CostCenter\\nClose with # in next line");
            line = Console.ReadLine();

            while (line != "#")
            {
                stringArray = line.Split(charArray);

                s = new Staff(stringArray);

                L.Add(s);

                sw.WriteLine(s.ToString());
                line = Console.ReadLine();
            }
            CodeControl.PrintFinish();

            sw.Close();
            return(L);
        }
Beispiel #2
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);
        }