Пример #1
0
        public void Sua(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();
                NCC_BLL  nccBLL = new NCC_BLL();

                Console.Clear();
                IO.Box(0, 0, 28, 114, ConsoleColor.Black, ConsoleColor.White);
                IO.BoxTitle("                                 CẬP NHẬT THÔNG TIN NHÀ CUNG CẤP", x, y, 10, 101);
                IO.Writexy("Mã NCC:", x + 4, y + 3);
                IO.Writexy("Tên nhà cung cấp:", x + 39, 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);

                string mancc;
                string tenncc;
                string diachi;
                string sdt;

                do
                {
                    Console.SetCursorPosition(x + 12, y + 3);
                    mancc = Console.ReadLine();
                    if (mancc == "")
                    {
                        IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                        IO.Writexy("Nhập lại mã nhà cung cấp...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                    }
                    else if (mancc == "!")
                    {
                        return;
                    }
                    else
                    {
                        if (nccBLL.KT_MaNCC(CongCu.ChuanHoaMa(mancc)) == false)
                        {
                            IO.Writexy("Không tồn tại mã nhà cung cấp này...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                            IO.Clear(x + 11, y + 3, 27, ConsoleColor.Black);
                        }
                        else
                        {
                            mancc = CongCu.ChuanHoaMa(mancc);
                        }
                    }
                } while (mancc == "" || nccBLL.KT_MaNCC(CongCu.ChuanHoaMa(mancc)) == false);
                NCC ncc = nhacc.LayNCC(mancc);

                IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black);
                IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                do
                {
                    Console.SetCursorPosition(x + 57, y + 3);
                    tenncc = Console.ReadLine();
                    if (tenncc == "")
                    {
                        IO.Writexy("Nhập lại tên nhà cung cấp...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                    }
                    else if (tenncc != ncc.tenNCC && tenncc != "")
                    {
                        ncc.tenNCC = CongCu.ChuanHoaXau(tenncc);
                    }
                } while (tenncc == "");
                IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                do
                {
                    Console.SetCursorPosition(x + 13, y + 5);
                    diachi = Console.ReadLine();
                    if (diachi == "")
                    {
                        IO.Writexy("Nhập lại địa chỉ...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White);
                    }
                    else if (diachi != ncc.diaChi && diachi != "")
                    {
                        ncc.diaChi = CongCu.ChuanHoaXau(diachi);
                    }
                } while (diachi == "");
                IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                do
                {
                    sdt = IO.ReadNumber(x + 54, y + 5);
                    if (sdt == null || sdt.Length < 10 || sdt.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);
                    }
                    else if (sdt != ncc.soDT && sdt != null)
                    {
                        ncc.soDT = CongCu.ChuanHoaMa(sdt);
                    }
                } while (sdt == null || sdt.Length < 10 || sdt.Length > 10);

                IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black);
                IO.Writexy("Enter để cập nhật, Esc để thoát...", x + 4, y + 7);
                Console.SetCursorPosition(x + 38, 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 cập nhật...", x + 4, y + 7);
                    nhacc.SuaNCC(ncc);
                    Hien(x + 11, y + 10, nhacc.LayDSNCC(), 5, 1);
                }
            } while (true);
        }
Пример #2
0
        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);
            }
        }