Beispiel #1
0
 static void mTen(List <HocSinh> Input, Ten T)
 {
     foreach (HocSinh HS in Input)
     {
         if (!T.Name.Contains(HS.Ten.ToLower()))
         {
             T.Name.Add(HS.Ten.ToLower());
         }
     }
 }
Beispiel #2
0
        static List <HocSinh> SName(List <HocSinh> Input, Ten T, string str)//Tim ten co chua thanh phan tim kiem
        {
            List <HocSinh> Output = new List <HocSinh>();

            if (T.Name.Contains(str.ToLower()))
            {
                Console.WriteLine("\n=>Tìm kiếm HS có tên : " + str);
                Output = Input.FindAll(delegate(HocSinh HS)
                {
                    return(HS.Ten.ToLower() == str.ToLower());
                });
            }
            else
            {
                Console.WriteLine("\n=>Tìm kiếm HS có tên chứa chuỗi kí tự: " + str);
                Output = Input.FindAll(delegate(HocSinh HS)
                {
                    return(HS.HoTen.ToLower().Contains(str.ToLower()));
                });
            }
            InDanhSach(Output);
            return(Output);
        }
Beispiel #3
0
        static void Thuc_hien(List <HocSinh> Input)
        {
            List <HocSinh> Output = new List <HocSinh>();

            Console.Write("\n\n***Nhập vào giá trị tìm kiếm: ");
            string str = Console.ReadLine();

            foreach (char i in str)
            {
                if (str.Contains("/"))
                {
                    DateTime namsinh;
                    try
                    {
                        namsinh = DateTime.ParseExact(str, "dd/MM/yyyy", null);
                    }
                    catch
                    {
                        Console.WriteLine("\n!!!Định dạng ngày tháng năm không đúng!!!");
                        break;
                    }
                    Output = SNamSinh(Input, namsinh);
                    break;
                }

                if (!Char.IsLetterOrDigit(i) || str.Contains("-"))
                {
                    Output = STuoi2(Input, str);
                    break;
                }
                else
                {
                    if (Int32.TryParse(str, out int t))
                    {
                        Output = STuoi1(Input, t);
                        break;
                    }
                    else
                    {
                        Ten T = new Ten();
                        mTen(Input, T);

                        if (str.ToLower() == "nam" || str.ToLower() == "nu")
                        {
                            Console.Write("Bạn muốn tìm: \n +)HS có giới tính {0} (Nhấn phím A). \n +)HS tên '{1}'(Nhấn phím bất kì trong các phím còn lại):  ", str.ToLower(), str);
                            var key = Console.ReadKey().Key;
                            if (key == ConsoleKey.A)
                            {
                                Console.WriteLine("\n=>Tìm kiếm HS có giới tính : " + str.ToLower());
                                Output = SGioiTinh(Input, str.ToLower());
                                break;
                            }
                        }
                        Output = SName(Input, T, str);
                        break;
                    }
                }
            }

            if (Output.Count > 1)
            {
                Console.Write("\nBạn muốn tiếp tục tìm kiếm trong danh sách trên: (y/n)?  ");
                var yn = Console.ReadKey().Key;
                do
                {
                    if (yn != ConsoleKey.Y)
                    {
                        if (yn == ConsoleKey.N)
                        {
                            Console.WriteLine("\n###Kết thúc chương trình###");
                            break;
                        }
                        Console.WriteLine("\n!!!Bạn nhập chưa đúng!!! ");
                        Console.Write("\nBạn muốn tiếp tục tìm kiếm trong danh sách trên: (y/n)?  ");
                        yn = Console.ReadKey().Key;
                    }

                    if (yn == ConsoleKey.Y)
                    {
                        Thuc_hien(Output);
                    }
                }while (yn != ConsoleKey.Y);
            }

            if (Output.Count == 1)
            {
                Console.WriteLine("\n===>Đã ra kết quả cần tìm.");
            }

            if (Output.Count == 0)
            {
                Console.WriteLine("\n\n=>Thực hiện lại tìm kiếm với danh sách ban đầu.");
                Thuc_hien(Input);
            }
        }