Ejemplo n.º 1
0
        public void Nhap(int x, int y, ConsoleColor background_color, ConsoleColor text_color)
        {
            do
            {
                Console.BackgroundColor = background_color;
                Console.ForegroundColor = text_color;
                IMayTinhBLL maytinh  = new MayTinhBLL();
                HDNhapBLL   hdnBLL   = new HDNhapBLL();
                MayTinhBLL  mtBLL    = new MayTinhBLL();
                FormHDNhap  fcthdn   = new FormHDNhap();
                CTHDNhapBLL cthdnBLL = new CTHDNhapBLL();
                MayTinh     mt       = new MayTinh();

                Console.Clear();
                IO.Box(0, 0, 28, 114, ConsoleColor.Black, ConsoleColor.White);
                IO.BoxTitle("                                          THÊM GIÁ BÁN MÁY TÍNH", x, y, 10, 110);
                IO.Writexy("Mã MT:", x + 2, y + 3);
                IO.Writexy("Tên máy:", x + 43, y + 3);
                IO.Writexy("Mã nhà CC:", x + 2, y + 5);
                IO.Writexy("Số lượng còn:", x + 37, y + 5);
                IO.Writexy("Giá bán:", x + 74, y + 5);
                IO.Writexy("------------------------------------------------------------------------------------------------------------", x + 1, y + 6);
                IO.Writexy("Nhập ! để thoát...", x + 4, y + 8);

                fcthdn.HienCT_N(x - 1, y + 10, cthdnBLL.LayDS_CTHDNhap(), 5, 0);
                do
                {
                    Console.SetCursorPosition(x + 9, y + 3);
                    mt.maMT = Console.ReadLine();
                    if (mt.maMT == null)
                    {
                        IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                        IO.Writexy("Nhập lại mã máy tính...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                    }
                    else if (mt.maMT == "!")
                    {
                        return;
                    }
                    else
                    {
                        if (cthdnBLL.KT_MaMT(CongCu.ChuanHoaMa(mt.maMT)) == false)
                        {
                            IO.Writexy("Không tồn tại mã máy tính này...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                            IO.Clear(x + 8, y + 3, 10, ConsoleColor.Black);
                        }
                        else if (mtBLL.KT_MaMayTinh(CongCu.ChuanHoaMa(mt.maMT)) == true)
                        {
                            IO.Writexy("Mã máy tính này đã tồn tại...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                            IO.Clear(x + 8, y + 3, 10, ConsoleColor.Black);
                        }
                        else
                        {
                            mt.maMT = CongCu.ChuanHoaMa(mt.maMT);
                        }
                    }
                } while (mt.maMT == null || cthdnBLL.KT_MaMT(CongCu.ChuanHoaMa(mt.maMT)) == false || mtBLL.KT_MaMayTinh(CongCu.ChuanHoaMa(mt.maMT)) == true);
                IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black);

                CTHDNhap ctn = cthdnBLL.LayMT(CongCu.ChuanHoaMa(mt.maMT));
                IO.Writexy(ctn.tenMT, x + 52, y + 3);
                mt.tenMT = ctn.tenMT;

                IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                mt.maNCC = hdnBLL.LayMaNCC(CongCu.ChuanHoaMa(mt.maMT));
                IO.Writexy(mt.maNCC, x + 13, y + 5);

                IO.Writexy(ctn.soLuong.ToString(), x + 51, y + 5);
                mt.sLCon = ctn.soLuong;

                fcthdn.HienCT_N(x - 1, y + 10, cthdnBLL.LayDS_CTHDNhap(), 5, 0);
                IO.Clear(x + 13, y + 7, 60, ConsoleColor.Black);
                do
                {
                    mt.giaBan = double.Parse(IO.ReadNumber(x + 83, y + 5));
                    if (mt.giaBan <= 0)
                    {
                        IO.Writexy("Nhập lại giá bán...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                        IO.Clear(x + 82, y + 5, 20, ConsoleColor.Black);
                    }
                    else if (mt.giaBan <= ctn.donGia)
                    {
                        IO.Writexy("Nhập lại giá bán lớn hơn giá nhập...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                        IO.Clear(x + 82, y + 5, 20, ConsoleColor.Black);
                    }
                } while (mt.giaBan < 0 || mt.giaBan <= ctn.donGia);

                IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                IO.Writexy("Enter để nhập, Esc để thoát...", x + 4, y + 7);
                Console.SetCursorPosition(x + 34, y + 7);
                ConsoleKeyInfo kt = Console.ReadKey();
                if (kt.Key == ConsoleKey.Escape)
                {
                    break;
                }
                else if (kt.Key == ConsoleKey.Enter)
                {
                    IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                    IO.Writexy("Giá bán đã được thêm...", x + 4, y + 7);
                    maytinh.ThemMayTinh(mt);
                    Hien(x + 9, y + 10, maytinh.LayDSMayTinh(), 5, 1);
                }
            } while (true);
        }