Beispiel #1
0
        public void Nhap(int x, int y, ConsoleColor background_color, ConsoleColor text_color)
        {
            do
            {
                Console.BackgroundColor = background_color;
                Console.ForegroundColor = text_color;
                INCC_BLL nhacc = new NCC_BLL();

                Console.Clear();
                IO.Box(0, 0, 28, 114, ConsoleColor.Black, ConsoleColor.White);
                IO.BoxTitle("                                   NHẬP THÔNG TIN NHÀ CUNG CẤP", x, y, 10, 101);
                IO.Writexy("Tên nhà cung cấp:", x + 4, y + 3);
                IO.Writexy("Địa chỉ:", x + 4, y + 5);
                IO.Writexy("Số điện thoại:", x + 39, y + 5);
                IO.Writexy("---------------------------------------------------------------------------------------------------", x + 1, y + 6);
                IO.Writexy("Nhập ! để thoát...", x + 4, y + 8);
                Hien(x + 11, y + 10, nhacc.LayDSNCC(), 5, 0);
                NCC ncc = new NCC();

                do
                {
                    Console.SetCursorPosition(x + 22, y + 3);
                    ncc.tenNCC = Console.ReadLine();
                    if (ncc.tenNCC == null)
                    {
                        IO.Writexy("Nhập lại tên nhà cung cấp...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                    }
                    else if (ncc.tenNCC == "!")
                    {
                        return;
                    }
                } while (ncc.tenNCC == null);
                IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black);
                do
                {
                    Console.SetCursorPosition(x + 13, y + 5);
                    ncc.diaChi = Console.ReadLine();
                    if (ncc.diaChi == null)
                    {
                        IO.Writexy("Nhập lại địa chỉ...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                    }
                } while (ncc.diaChi == null);
                IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                do
                {
                    ncc.soDT = IO.ReadNumber(x + 54, y + 5);
                    if (ncc.soDT == null || ncc.soDT.Length < 10 || ncc.soDT.Length > 10)
                    {
                        IO.Writexy("Nhập lại số điện thoại...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                        IO.Clear(x + 53, y + 5, 46, ConsoleColor.Black);
                    }
                } while (ncc.soDT == null || ncc.soDT.Length < 10 || ncc.soDT.Length > 10);

                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("Nhà cung cấp đã được thêm...", x + 4, y + 7);
                    nhacc.ThemNCC(ncc);
                    Hien(x + 11, y + 10, nhacc.LayDSNCC(), 5, 1);
                }
            } while (true);
        }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtMa.Enabled == true)
                {
                    if (txtMa.Text == "")
                    {
                        MessageBox.Show("Mã NCC không được để trống!!");
                        txtMa.Focus();
                        return;
                    }
                    if (txtTen.Text == "")
                    {
                        MessageBox.Show("Tên NCC không được để trống!!");
                        txtTen.Focus();
                        return;
                    }
                    if (txtDiaChi.Text == "")
                    {
                        MessageBox.Show("Địa chỉ không được để trống!!");
                        txtDiaChi.Focus();
                        return;
                    }

                    if (txtDT.Text == "")
                    {
                        MessageBox.Show("Điện thoại không được để trống!!");
                        txtDT.Focus();
                        return;
                    }
                    if (IsValidPhone(txtDT.Text) == false)
                    {
                        MessageBox.Show("Số ĐT không hợp lệ!!");
                        txtDT.Focus();
                        return;
                    }
                    if (ncc.KTraNCCTonTai(txtMa.Text) == true)
                    {
                        ncc.ThemNCC(txtMa.Text, txtTen.Text, txtDiaChi.Text, txtDT.Text);
                        dgvNCC.DataSource = ncc.getDSNCC();
                        blockButtonTextbox();
                    }
                    else
                    {
                        MessageBox.Show("Nhà cung cấp " + txtTen.Text + "đã tồn tại rồi!!");
                        return;
                    }
                }
                else
                {
                    ncc.SuaNCC(txtMa.Text, txtTen.Text, txtDiaChi.Text, txtDT.Text);
                    dgvNCC.DataSource = ncc.getDSNCC();
                    blockButtonTextbox();
                    MessageBox.Show("Sửa thành công ");
                }
            }
            catch
            {
                MessageBox.Show("Lỗi!! ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }