private void btnDel_Click(object sender, EventArgs e) { try { int rowindex = dgvHoaDon.CurrentCell.RowIndex; string rs = dgvHoaDon.Rows[rowindex].Cells[0].Value.ToString(); try { string sHD = rs; DialogResult result = MessageBox.Show("Chắn chắn xóa?!!!", "Cảnh Báo!", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign, false); if (result == DialogResult.Yes) { bool kq1; try { kq1 = HoaDonBLL.XoaHDTheoMa(sHD); if (kq1 == true) { MessageBox.Show("Xóa thành công!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); DataTable _dshd = HoaDonBLL.LayDSHD(); dgvHoaDon.DataSource = _dshd; dgvHHTT.DataSource = null; dgvHHTT.Rows.Clear(); tbCTH.Text = ""; tbTTGTGT.Text = ""; tbTCTTT.Text = "0"; } else { MessageBox.Show("Xóa thất bại!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Không thể xóa!!!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch { MessageBox.Show("Chưa chọn hóa đơn cần xóa!", "Lỗi!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Chưa chọn hóa đơn cần xóa!", "Lỗi!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Nhap_Hoa_Don_control_Load(object sender, EventArgs e) { DataTable _dshd = HoaDonBLL.LayDSHD(); dgvHoaDon.DataSource = _dshd; List <String> dshh = HangHoaBLL.LayListHH(); comboBox2.DataSource = dshh; comboBox2.DisplayMember = "MaHang"; comboBox2.SelectedIndex = -1; DataTable listHTTT = HinhThucTTBLL.LayListHTTT(); comboBox1.DataSource = listHTTT; comboBox1.DisplayMember = "TenHTTT"; comboBox1.ValueMember = "MaHTTT"; DataTable listDVMH = DVMHBLL.LayDSDVMH(); comboBoxDVM.Properties.DataSource = listDVMH; comboBoxDVM.Properties.DisplayMember = "TenDonViMuaHang"; }
private void btnAdd_Click(object sender, EventArgs e) { dgvHHTT.DataSource = null; dgvHHTT.Rows.Clear(); tbCTH.Text = ""; tbTTGTGT.Text = ""; tbTCTTT.Text = "0"; HoaDon hd = new HoaDon(); try { hd.SHD = int.Parse(tbSHD.Text); hd.KyHieu = tbKHHD.Text; hd.TenDonViMuaHang = comboBoxDVM.Text; hd.MDVMH = tbMDVMH.Text; hd.NguoiMuaHang = tbNMH.Text; hd.MaSoThueMua = tbMST.Text; hd.DiaChiMua = tbDC.Text; hd.STKMua = tbSTK.Text; hd.NgayHD = dtpNgayBan.Value.ToString("dd/MM/yyyy"); hd.HinhThucThanhToan = Convert.ToInt32(comboBox1.SelectedValue); hd.ThueSuat = int.Parse(TGTGT.Text); hd.TongTien = 0; bool kq1 = HoaDonBLL.ThemHD(hd); if (kq1 == true) { MessageBox.Show("Thêm Đơn thành công!", "Thông báo!!!", MessageBoxButtons.OK, MessageBoxIcon.Information); DataTable _dshd = HoaDonBLL.LayDSHD(); dgvHoaDon.DataSource = _dshd; } else { MessageBox.Show("Hóa Đơn này đã có!", "Thông báo!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Nhập sai định dạng", "Thông báo!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnUpdate_Click(object sender, EventArgs e) { try { int rowindex = dgvHoaDon.CurrentCell.RowIndex; HoaDon hd = new HoaDon(); int icountSelectedRow = dgvHoaDon.SelectedRows.Count; if (icountSelectedRow == 0) { MessageBox.Show("Bạn hãy chọn dòng cần cập nhật lại dữ liệu!"); } else if (icountSelectedRow == 1) { hd.SHD = int.Parse(dgvHoaDon.Rows[rowindex].Cells[0].Value.ToString()); hd.ThueSuat = int.Parse(TGTGT.Value.ToString()); hd.TongTien = float.Parse(tbTCTTT.Text); bool kq1 = HoaDonBLL.UpdateHD(hd); if (kq1 == true) { MessageBox.Show("Cập nhật hóa đơn thành công!", "Thông báo!!!", MessageBoxButtons.OK, MessageBoxIcon.Information); DataTable _dshd = HoaDonBLL.LayDSHD(); dgvHoaDon.DataSource = _dshd; } else { MessageBox.Show("hàng hóa này đã có!", "Thông báo!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Bạn chỉ có thể chọn 1 dòng để cập nhật lại dữ liệu!"); } } catch { MessageBox.Show("Nhập Sai Định Dạng!"); } }
private void btnRefresh_Click(object sender, EventArgs e) { DataTable _dshd = HoaDonBLL.LayDSHD(); dgvHoaDon.DataSource = _dshd; }
void LoadDSHD() { dtgvThongKe.DataSource = HoaDonBLL.LayDSHD(); }