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); } } } }
private void frmHoaDonXuat_Load(object sender, EventArgs e) { gridControl1.DataSource = hdxbus.DanhSachHoaDonXuat(); txtMHDX.EditValue = hdxbus.TangHD(); bthIHD.Enabled = false; CTHDXuatBUS chitiet = new CTHDXuatBUS(); }
private void cboMaNL_SelectedIndexChanged(object sender, EventArgs e) { if (cboMaNL.SelectedIndex == 0) { txtDonGia.Text = NguyenLieuBUS.LayDonGiaTuMaNL("NL001").ToString(); if (dgvDSCTHDXuat.Rows.Count > 0) { bool result = false; for (int i = 0; i < dgvDSCTHDXuat.Rows.Count; i++) { if (dgvDSCTHDXuat.Rows[i].Cells["colMaNL_CTHD"].Value.ToString() == "NL001") { result = true; break; } } if (result) { lblSLTK.Text = (NguyenLieuBUS.LaySoLuongTKNL("NL001") - CTHDXuatBUS.LaySoLuongHienTai(hd.MaHDXuat, "NL001")).ToString(); } } else { lblSLTK.Text = NguyenLieuBUS.LaySoLuongTKNL("NL001").ToString(); } lblDonViTinh.Text = NguyenLieuBUS.LayDonViTinhTuMaNL("NL001").ToString() + ")"; } else if (cboMaNL.SelectedIndex > 0) { string maNL = cboMaNL.SelectedValue.ToString(); txtDonGia.Text = NguyenLieuBUS.LayDonGiaTuMaNL(maNL).ToString(); lblSLTK.Text = NguyenLieuBUS.LaySoLuongTKNL(maNL).ToString(); if (dgvDSCTHDXuat.Rows.Count > 0) { bool result = false; for (int i = 0; i < dgvDSCTHDXuat.Rows.Count; i++) { if (dgvDSCTHDXuat.Rows[i].Cells["colMaNL_CTHD"].Value.ToString() == maNL) { result = true; break; } } if (result) { lblSLTK.Text = (NguyenLieuBUS.LaySoLuongTKNL(maNL) - CTHDXuatBUS.LaySoLuongHienTai(hd.MaHDXuat, maNL)).ToString(); } } else { lblSLTK.Text = NguyenLieuBUS.LaySoLuongTKNL(maNL).ToString(); } lblDonViTinh.Text = NguyenLieuBUS.LayDonViTinhTuMaNL(maNL).ToString() + ")"; } }
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); } } } }
private void simpleButton4_Click(object sender, EventArgs e) { GetDuLieu(); if (gridView2.RowCount > 0 || gridView2.RowCount != 0) { try { int tien = 0; foreach (CTHDXuatDTO ct in cthdxDTO) { tien += ct.GiaBan * ct.SoLuong; } HoaDonXuatDTO hdb = new HoaDonXuatDTO(); frmSanPham sp = new frmSanPham(); Form1 frm = (Form1)this.MdiParent; hdb.MaHDX = hdxbus.TangHD(); hdb.MaNV = frm.NhanVienDN.MaNV; hdb.MaKH = lueKH.EditValue.ToString(); hdb.NgayXuat = System.DateTime.Now; hdb.TongTien = tien; int mhd = hdxbus.themHoaDon(hdb); CTHDXuatBUS ctbus = new CTHDXuatBUS(); int kq = 0; foreach (CTHDXuatDTO ct in cthdxDTO) { ct.MaCTHoaDonXuat = hdb.MaHDX; if (ctbus.ThemCTHoaDonXuat(ct)) { kq++; } if (sanphambus.TimSP(ct.MaSP)) { SanPhamDTO hh = new SanPhamDTO(); hh.MaSP = ct.MaSP; hh.SoLuong = ct.SoLuong; sanphambus.TruSL(hh); } } if (kq == cthdxDTO.Count) { XtraMessageBox.Show("Thanh toán thành công", "Thông báo", MessageBoxButtons.OK); frmHoaDonBanHang frm1 = new frmHoaDonBanHang(); frm1.MaHD = txtMHD.Text; frm1.ShowDialog(); txtMHD.Text = hdxbus.TangHD(); } else { XtraMessageBox.Show("Thanh toán thất bại", "Thông báo"); } } catch (Exception) { XtraMessageBox.Show("Bạn chưa mua hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } gctSP.DataSource = sanphambus.DanhSachSanPham(); for (int i = 0; i < gridView2.RowCount;) { gridView2.DeleteRow(i); } } else { XtraMessageBox.Show("Bạn chưa mua hàng", "Thông báo"); } txtSL.Text = ""; lblThanhTien.Text = ""; lblTongTien.Text = ""; lueKH.Enabled = true; btnT.Enabled = true; }
void LoadDSCTHDXuat(int maHD) { dgvDSCTHDXuat.DataSource = CTHDXuatBUS.LayDSCTHDXuat(maHD); dgvDSCTHDXuat.CurrentCell = null; }
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); } } }
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); } } } }