private void btnXoaCTHD_Click(object sender, EventArgs e) { DialogResult rs = DialogResult.Yes; if (rs == MessageBox.Show("Bạn có chắc muốn xóa nguyên liệu này!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { if (cthd != null) { hd.TongTien = HDXuatBUS.LayTongTienHDXuat(hd.MaHDXuat) - (Convert.ToInt32(txtDonGia.Text) * Convert.ToInt32(txtSoLuongConLai.Text)); if (CTHDXuatBUS.XoaCTHDXuat(cthd.MaHDXuat, cthd.MaNL)) { LoadDSCTHDXuat(hd.MaHDXuat); hd.MaHDXuat = Convert.ToInt32(txtMaHD_CTHD.Text); if (HDXuatBUS.CapNhatHDXuat(hd.MaHDXuat, hd.TongTien)) { LoadDSHDXuat(); AddStatus(-2); //MessageBox.Show("Xóa CTHD xuất thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); LamMoiCTHD(); } SettingText(); } else { MessageBox.Show("Xóa CTHD xuất thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
void SetForm() { frmMain frm = new frmMain(); txtMaHD.Text = HDXuatBUS.LayMaHDXuatLonNhat().ToString(); txtTenTaiKhoan.Text = ((frmMain)this.ParentForm).getTenTK(); dtpNgayXuat.Value = DateTime.Now; }
private void btnCapNhatCTHD_Click(object sender, EventArgs e) { if (txtMaHD_CTHD.Text == "" || txtSoLuongConLai.Text == "" || txtDonGia.Text == "") { MessageBox.Show("Mời bạn nhập đầy đủ thông tin CTHD xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else if (Convert.ToInt32(txtSoLuongConLai.Text) > Convert.ToInt32(lblSLTK.Text)) { MessageBox.Show("Số lượng xuất không được vượt quá số lượng tồn kho!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (cthd != null) { GetInfoResultCTHDXuat(); int slHienTai = cthd.SoLuong; int slBanDau = CTHDXuatBUS.LaySoLuongHienTai(cthd.MaHDXuat, cthd.MaNL); if (slHienTai > 0) { int slThayDoi = slHienTai - slBanDau; if (slThayDoi < 0) { hd.TongTien = HDXuatBUS.LayTongTienHDXuat(cthd.MaHDXuat) - (Math.Abs(slThayDoi) * Convert.ToInt32(txtDonGia.Text)); } else { hd.TongTien = HDXuatBUS.LayTongTienHDXuat(cthd.MaHDXuat) + (Math.Abs(slThayDoi) * Convert.ToInt32(txtDonGia.Text)); } if (CTHDXuatBUS.CapNhatCTHDXuat(cthd)) { if (HDXuatBUS.CapNhatHDXuat(hd.MaHDXuat, hd.TongTien)) { //MessageBox.Show("Cập nhật CTHD xuất thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); LoadDSCTHDXuat(cthd.MaHDXuat); LoadDSHDXuat(); AddStatus(-2); txtTongTien.Text = HDXuatBUS.LayTongTienHDXuat(hd.MaHDXuat).ToString(); LamMoiCTHD(); } } else { MessageBox.Show("Cập nhật CTHD xuất thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Số lượng không được dưới 1", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } }
void LoadDSHDXuat() { if (!chkTrangThaiHDHuy.Checked)//DS HD chưa thanh toán và đã thanh toán { dgvDSHDXuat.DataSource = HDXuatBUS.LayDSHDXuat(_tenTK); } else//DS HD bị xóa { dgvDSHDXuat.DataSource = HDXuatBUS.LayDSHDXuatBiXoa(_tenTK); dgvDSHDXuat.CurrentCell = null; AddStatus(3); } }
private void btnHoanTat_Click(object sender, EventArgs e) { if (dgvDSCTHDXuat.Rows.Count == 0) { MessageBox.Show("Bạn chưa thêm thông CTHD xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { if (hd != null) { hd.NgayXuat = dtpNgayXuat.Value; if (HDXuatBUS.CapNhatTrangThaiHD(hd.MaHDXuat, 1) && HDXuatBUS.HoanTatHD(hd)) { LoadDSHDXuat(); //MessageBox.Show("Tạo hóa đơn thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); // Cập nhật nguyên liệu số lượng tồn kho - giảm for (int i = 0; i < dgvDSCTHDXuat.Rows.Count; i++) { DataTable dt = NguyenLieuBUS.LayDSMaNL(); foreach (DataRow dr in dt.Rows) { NguyenLieuDTO nl = new NguyenLieuDTO(); nl.MaNL = dr["MaNL"].ToString(); if (dgvDSCTHDXuat.Rows[i].Cells["colMaNL_CTHD"].Value.ToString() == nl.MaNL) { cthd = new CTHDXuatDTO(); cthd.MaHDXuat = Convert.ToInt32(dgvDSCTHDXuat.Rows[i].Cells["colMaHDXuat_CTHD"].Value); cthd.MaNL = dgvDSCTHDXuat.Rows[i].Cells["colMaNL_CTHD"].Value.ToString(); int sltk = NguyenLieuBUS.LaySoLuongTKNL(cthd.MaNL) - CTHDXuatBUS.LaySoLuongHienTai(cthd.MaHDXuat, cthd.MaNL); if (NguyenLieuBUS.CapNhatSoLuongTonKhoGiam(cthd.MaHDXuat, cthd.MaNL, sltk)) { //MessageBox.Show("Cập nhật số lượng tồn kho thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); } else { MessageBox.Show("Cập nhật số lượng tồn kho thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } else { MessageBox.Show("Tạo hóa đơn thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void btnTaoHD_Click(object sender, EventArgs e) { if (hd == null) { GetInfoResultHDXuat(); if (HDXuatBUS.ThemHDXuat(hd)) { //MessageBox.Show("Thêm hóa đơn thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); LoadDSHDXuat(); AddStatus(1); } else { MessageBox.Show("Thêm hóa đơn thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnKhoiPhuc_Click(object sender, EventArgs e) { if (chkTrangThaiHDHuy.Checked == true) { if (hd != null) { if (HDXuatBUS.CapNhatTrangThaiHuy(hd.MaHDXuat, 1)) { LoadDSHDXuat(); //MessageBox.Show("Khôi phục hóa đơn thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); } else { MessageBox.Show("Khôi phục hóa đơn thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void dgvDSHDXuat_SelectionChanged(object sender, EventArgs e) { if (dgvDSHDXuat.SelectedRows.Count > 0) { DataGridViewRow dgvRow = dgvDSHDXuat.CurrentRow; hd = new HDXuatDTO(); hd.MaHDXuat = Convert.ToInt32(dgvRow.Cells["colMaHDXuat"].Value.ToString()); //hd.TongTien = Convert.ToInt32(dgvRow.Cells["colTongTien"].Value.ToString()); hd.TongTien = HDXuatBUS.LayTongTienHDXuat(hd.MaHDXuat); hd.TenTaiKhoan = dgvRow.Cells["colTenTK"].Value.ToString(); hd.NgayXuat = Convert.ToDateTime(dgvRow.Cells["colNgayXuat"].Value.ToString()); hd.TrangThai = Convert.ToInt32(dgvRow.Cells["colTrangThai"].Value); SetInfoHD(); if (chkTrangThaiHDHuy.Checked) { AddStatus(3); } else { AddStatus(1); } } }
private void btnXoaHD_Click(object sender, EventArgs e) { //TrangThai: 0: chưa thanh toán || 1: đã thanh toán //TonTai: 0: đã hủy || 1: chưa hủy if (hd != null) { DialogResult ds = DialogResult.Yes; if (ds == MessageBox.Show("Bạn có chắc muốn xóa hóa đơn này không!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { if (HDXuatBUS.CapNhatTrangThaiHuy(hd.MaHDXuat, 0)) { LoadDSHDXuat(); //MessageBox.Show("Xóa hóa đơn thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); LamMoi(); AddStatus(-1); } else { MessageBox.Show("Xóa hóa đơn thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void btnThemCTHD_Click(object sender, EventArgs e) { if (txtMaHD_CTHD.Text == "" || txtSoLuongConLai.Text == "" || txtDonGia.Text == "") { MessageBox.Show("Mời bạn nhập đầy đủ thông tin CTHD xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else if (Convert.ToInt32(txtSoLuongConLai.Text) >= NguyenLieuBUS.LaySoLuongTKNL(cboMaNL.SelectedValue.ToString()) || Convert.ToInt32(txtSoLuongConLai.Text) >= Convert.ToInt32(lblSLTK.Text)) { MessageBox.Show("Số lượng còn lại không được bằng hoặc vượt quá số lượng tồn kho!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (cthd == null) { GetInfoResultCTHDXuat(); cthd.SoLuong = NguyenLieuBUS.LaySoLuongTKNL(cthd.MaNL) - Convert.ToInt32(txtSoLuongConLai.Text); if (!CTHDXuatBUS.KiemTraMaNLTonTai(cthd.MaHDXuat, cthd.MaNL)) { if (CTHDXuatBUS.ThemCTHDHDXuat(cthd)) { if (hd != null) { hd.MaHDXuat = Convert.ToInt32(txtMaHD_CTHD.Text); //Tổng tiền = tổng tiền HD + vs Tiền mới của 1 món ăn mói thêm vào hd.TongTien = HDXuatBUS.LayTongTienHDXuat(hd.MaHDXuat) + (Convert.ToInt32(Convert.ToInt32(txtDonGia.Text) * cthd.SoLuong)); if (HDXuatBUS.CapNhatHDXuat(hd.MaHDXuat, hd.TongTien)) { //MessageBox.Show("Thêm thông tin CTHD xuất thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); LoadDSCTHDXuat(hd.MaHDXuat); txtTongTien.Text = HDXuatBUS.LayTongTienHDXuat(cthd.MaHDXuat).ToString(); } } cthd = null; } else { MessageBox.Show("Thêm thông tin CTHD xuất thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { int sltk = NguyenLieuBUS.LaySoLuongTKNL(cthd.MaNL) - CTHDXuatBUS.LaySoLuongHienTai(cthd.MaHDXuat, cthd.MaNL); cthd.SoLuong = (CTHDXuatBUS.LaySoLuongHienTai(cthd.MaHDXuat, cthd.MaNL) + (sltk - Convert.ToInt32(txtSoLuongConLai.Text))); if (CTHDXuatBUS.CapNhatSoLuong(cthd.SoLuong, cthd.MaHDXuat, cthd.MaNL)) { hd.TongTien = HDXuatBUS.LayTongTienHDXuat(hd.MaHDXuat) + (Convert.ToInt32(Convert.ToInt32(txtDonGia.Text) * (sltk - Convert.ToInt32(txtSoLuongConLai.Text)))); if (HDXuatBUS.CapNhatHDXuat(hd.MaHDXuat, hd.TongTien)) { LoadDSCTHDXuat(hd.MaHDXuat); txtTongTien.Text = HDXuatBUS.LayTongTienHDXuat(cthd.MaHDXuat).ToString(); //MessageBox.Show("Thêm số lượng thông tin CTHD xuất thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None); } } cthd = null; } AddStatus(-2); } } }