Ejemplo n.º 1
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     try
     {
         DialogResult rs = MessageBox.Show("Bạn có muốn xóa chứ ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
         if (rs == DialogResult.Yes)
         {
             if (txtMa.Text == "")
             {
                 MessageBox.Show("Mã NCC không được để trống!!");
                 txtMa.Focus();
                 return;
             }
             if (ncc.KTraKhoaNgoai(txtMa.Text) == false)
             {
                 ncc.XoaNCC(txtMa.Text);
                 MessageBox.Show("Xóa thành công");
                 dgvNCC.DataSource = ncc.getDSNCC();
                 blockButtonTextbox();
             }
             else
             {
                 MessageBox.Show("Dữ liệu này đang được sử dụng không thể xóa!!");
                 blockButtonTextbox();
             }
         }
     }
     catch
     {
         MessageBox.Show("Lỗi!! ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Ejemplo n.º 2
0
        public void Xoa(int x, int y, ConsoleColor background_color, ConsoleColor text_color)
        {
            do
            {
                Console.BackgroundColor = background_color;
                Console.ForegroundColor = text_color;
                string   mancc  = "";
                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("                                        XÓA NHÀ CUNG CẤP", x, y, 8, 101);
                IO.Writexy("Nhập mã nhà cung cấp cần xóa:", x + 4, y + 3);
                IO.Writexy("---------------------------------------------------------------------------------------------------", x + 1, y + 4);
                IO.Writexy("Nhập ! để thoát...", x + 4, y + 6);
                Hien(x + 11, y + 8, nhacc.LayDSNCC(), 5, 0);
                do
                {
                    Console.SetCursorPosition(x + 34, y + 3);
                    mancc = Console.ReadLine();
                    if (mancc == "")
                    {
                        IO.Clear(x + 3, y + 5, 60, ConsoleColor.Black);
                        IO.Writexy("Nhập lại mã nhà cung cấp...", x + 4, y + 5, ConsoleColor.Black, ConsoleColor.White);
                    }
                    else if (mancc == "!")
                    {
                        return;
                    }
                    else
                    {
                        if (nccBLL.KT_MaNCC(CongCu.ChuanHoaMa(mancc)) == false)
                        {
                            IO.Clear(x + 3, y + 5, 60, ConsoleColor.Black);
                            IO.Writexy("Không tồn tại mã nhà cung cấp này...", x + 4, y + 5, ConsoleColor.Black, ConsoleColor.White);
                            IO.Clear(x + 33, y + 3, 60, ConsoleColor.Black);
                        }
                        else
                        {
                            mancc = CongCu.ChuanHoaMa(mancc);
                            nhacc.XoaNCC(mancc);
                            IO.Clear(x + 3, y + 5, 60, ConsoleColor.Black);
                            IO.Clear(x + 33, y + 3, 60, ConsoleColor.Black);
                            IO.Writexy("Nhà cung cấp đã được xóa...", x + 4, y + 5);
                            Hien(x + 11, y + 8, nhacc.LayDSNCC(), 5, 1);
                        }
                    }
                } while (mancc == "" || nccBLL.KT_MaNCC(CongCu.ChuanHoaMa(mancc)) == false);

                IO.Clear(x + 3, y + 5, 60, ConsoleColor.Black);
                Console.SetCursorPosition(x + 33, y + 5);
                IO.Writexy("E", x + 4, y + 5);
                IO.Writexy("Enter để xóa, Esc để thoát...", x + 4, y + 5);
                ConsoleKeyInfo ktr = Console.ReadKey();
                if (ktr.Key == ConsoleKey.Escape)
                {
                    break;
                }
            } while (true);
        }