private void btn2_Click_1(object sender, EventArgs e)
 {
     dataGridView1.BeginEdit(true);
     if (tbx_makh.Text == "" || tbx_tenkh.Text == "" || tbx_diachi.Text == "" || tbx_gioitinh.Text == "" || tbx_dienthoai.Text == "" || tbx_email.Text == "" || tbx_fax.Text == "")
     {
         MessageBox.Show("Chọn Dòng Bạn Muốn Sửa", "Thông Báo!");
         tbx_makh.Focus();
     }
     else
     {
         if (tbx_makh.Text != dataGridView1.CurrentRow.Cells["MAKH"].Value.ToString().Trim() || tbx_makh.Text == "")
         {
             MessageBox.Show("Mã Kho chưa được nhập hoặc đã bị thay đổi!", "Lỗi");
         }
         else
         {
             if (tbx_tenkh.Text == dataGridView1.CurrentRow.Cells["TENKH"].Value.ToString().Trim() && tbx_makh.Text == dataGridView1.CurrentRow.Cells["MAKH"].Value.ToString().Trim() && tbx_diachi.Text == dataGridView1.CurrentRow.Cells["DIACHI"].Value.ToString().Trim() && tbx_gioitinh.Text == dataGridView1.CurrentRow.Cells["GIOITINH"].Value.ToString().Trim() && tbx_dienthoai.Text == dataGridView1.CurrentRow.Cells["DIENTHOAI"].Value.ToString().Trim() && tbx_email.Text == dataGridView1.CurrentRow.Cells["EMAIL"].Value.ToString().Trim() && tbx_fax.Text == dataGridView1.CurrentRow.Cells["FAX"].Value.ToString().Trim())
             {
                 MessageBox.Show("Toàn Bộ Thông Tin Kho Hàng Đã Tồn Tại. Vui Lòng Sủa Lại!", "Thông Báo!");
             }
             else
             {
                 acc.CapNhat_KhachHang(tbx_makh.Text, tbx_tenkh.Text, tbx_diachi.Text, tbx_gioitinh.Text, tbx_dienthoai.Text, tbx_email.Text, tbx_fax.Text);
                 KhachHang_Load(sender, e);
             }
         }
     }
     dataGridView1.EndEdit();
 }
示例#2
0
        private void btn_ghinhan_Click(object sender, EventArgs e)
        {
            if (key == 1)
            {
                if (tbx_tenkh.Text.Trim() == "" || tbx_diachi.Text.Trim() == "" || tbx_dienthoai.Text.Trim() == "")
                {
                    MessageBox.Show("Hãy Nhập Đầy Đủ Thông Tin!,", "Thông Báo!");
                    tbx_makh.Focus();
                }
                else
                {
                    DataTable dtkho = new DataTable();
                    dtkho = acc.CheckSql("select * from KHACHHANG where MAKH ='" + tbx_makh.Text + "'");
                    if (dtkho.Rows.Count > 0)
                    {
                        MessageBox.Show("Mã Khách Hàng đã tồn tại!", "Lỗi");
                        ClearText();
                    }
                    else
                    {
                        if (MessageBox.Show("Bạn Chắc Chắn Muốn Thêm Khách Hàng Này?", "Xác Nhận!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            acc.Them_KhachHang(tbx_makh.Text, tbx_tenkh.Text, tbx_diachi.Text, tbx_gioitinh.Text, tbx_dienthoai.Text, tbx_email.Text, tbx_fax.Text);
                            KhachHang_Load(sender, e);
                            MessageBox.Show("Thêm Thành Công!", "Thông Báo!");
                        }
                        else
                        {
                        }
                    }
                }
            }
            if (key == 2)
            {
                dataGridView1.BeginEdit(true);
                if (tbx_tenkh.Text == "" || tbx_diachi.Text == "" || tbx_gioitinh.Text == "" || tbx_dienthoai.Text == "" || tbx_email.Text == "" || tbx_fax.Text == "")
                {
                    MessageBox.Show("Chọn Dòng Bạn Muốn Sửa", "Thông Báo!");
                    tbx_makh.Focus();
                }
                else
                {
                    if (tbx_makh.Text != dataGridView1.CurrentRow.Cells["MAKH"].Value.ToString().Trim() || tbx_makh.Text == "")
                    {
                        MessageBox.Show("Mã Khách Hàng chưa được nhập hoặc đã bị thay đổi!", "Lỗi");
                    }
                    else
                    {
                        if (tbx_tenkh.Text == dataGridView1.CurrentRow.Cells["TENKH"].Value.ToString().Trim() && tbx_makh.Text == dataGridView1.CurrentRow.Cells["MAKH"].Value.ToString().Trim() && tbx_diachi.Text == dataGridView1.CurrentRow.Cells["DIACHI"].Value.ToString().Trim() && tbx_gioitinh.Text == dataGridView1.CurrentRow.Cells["GIOITINH"].Value.ToString().Trim() && tbx_dienthoai.Text == dataGridView1.CurrentRow.Cells["DIENTHOAI"].Value.ToString().Trim() && tbx_email.Text == dataGridView1.CurrentRow.Cells["EMAIL"].Value.ToString().Trim() && tbx_fax.Text == dataGridView1.CurrentRow.Cells["FAX"].Value.ToString().Trim())
                        {
                            MessageBox.Show("Toàn Bộ Thông Tin Khách Hàng Đã Tồn Tại. Vui Lòng Sủa Lại!", "Thông Báo!");
                        }
                        else
                        {
                            if (MessageBox.Show("Bạn Chắc Chắn Muốn Sửa Khách Hàng Này?", "Xác Nhận!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                acc.CapNhat_KhachHang(tbx_makh.Text, tbx_tenkh.Text, tbx_diachi.Text, tbx_gioitinh.Text, tbx_dienthoai.Text, tbx_email.Text, tbx_fax.Text);
                                KhachHang_Load(sender, e);
                                MessageBox.Show("Sửa Thành Công!", "Thông Báo!");
                            }
                            else
                            {
                            }
                        }
                    }
                }
                dataGridView1.EndEdit();
            }
            if (key == 3)
            {
                if (tbx_makh.Text.Trim() == "" || dataGridView1.SelectedRows == null)
                {
                    MessageBox.Show("Hãy Nhập Mã Khách Hàng Muốn Xóa Hoặc Chọn Dòng Muốm Xóa!,", "Cảnh Báo!");
                    btn_mo_Click_1(sender, e);
                }
                else
                {
                    DataTable dtpx = new DataTable();
                    dtpx = acc.CheckSql("select * from PHIEUXUAT where MAKH ='" + tbx_makh.Text + "'");

                    if (dtpx.Rows.Count > 0)
                    {
                        if (MessageBox.Show("Khách Hàng  Đang Tốn Tại Ơ Bảng PHIEUXUAT, PHIEUNHAP! Bạn Có Muốn Xóa Thông Tin KH Này!", "Xác Nhận!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            acc.CheckSql("Update PHIEUXUAT SET MAKH = null WHERE MAKH = '" + tbx_makh.Text + "'");
                        }
                    }
                    else
                    {
                        if (MessageBox.Show("Bạn Chắc Chắn Muốn Xóa Khách Hàng Này?", "Xác Nhận!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            acc.Xoa_KhachHang(tbx_makh.Text);
                            KhachHang_Load(sender, e);
                            MessageBox.Show("XÓa Thành Công!", "Thông Báo!");
                        }
                        else
                        {
                        }
                    }
                }
            }
        }