private void Del() { tblphieunhapkhoBL ctr = new tblphieunhapkhoBL(); string kq = ""; string sidhd = ""; try { sidhd = txtID.Text.Trim(); } catch { } string stientttemp = "N/A"; try { stientttemp = ctr.GetByID(sidhd).tienthanhtoan.ToString(); } catch { } if (MessageBox.Show("Xác nhận xóa dữ liệu?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { UpdateSoLuongMatHang(sidhd); kq = ctr.Delete(sidhd); if (kq.Trim().Equals("") == true) { _ctrlog.Append(Data.use, "Xóa phiếu nhập hàng của nhà cung cấp: " + cbNhaCC.Text.Trim() + " xuất ngày: " + dpkNgayNhap.Value.ToString("dd/MM/yyyy").Trim() + "; id: " + txtID.Text.Trim() + ";\nChi tiết: Tổng tiền hàng: " + txtTongTien.Text + " - Nợ cũ: " + txtNoToaTruoc.Text + " - Tiền thanh toán: " + stientttemp + " - Tổng nợ mới: " + txtConNo.Text); Add(); HienThiDSMatHang(); } else { MessageBox.Show("Xóa phiếu nhập hàng không thành công.\nChi tiết lỗi: " + kq, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } }
private void Save() { string kq = ""; tienthanhtoanphieunhapBL ctrtientt = new tienthanhtoanphieunhapBL(); tblmathangBL ctrmathang = new tblmathangBL(); tblphieunhapkhoBL ctrphieu = new tblphieunhapkhoBL(); tblphieunhapkho objphieu = new tblphieunhapkho(); objphieu = GetDataPhieuNhap(); tblhangnhapkhoBL ctrmathangnhap = new tblhangnhapkhoBL(); List<tblhangnhapkho> lstmathang = new List<tblhangnhapkho>(); lstmathang = GetListMatHang(); if (objphieu != null && lstmathang != null) { if (txtID.Text.Trim().Equals("-1") == true) { kq = ctrphieu.Insert(objphieu); if (kq.Trim().Equals("") == true) { tienthanhtoanphieunhap objtientt = new tienthanhtoanphieunhap(); objtientt.id = Guid.NewGuid().ToString().Trim(); objtientt.idpn = objphieu.id; objtientt.ngaytt = objphieu.ngaytao; objtientt.tientt = objphieu.tienthanhtoan; ctrtientt.Insert(objtientt); } } else { kq = ctrphieu.Update(objphieu); tienthanhtoanphieunhap objtientt = new tienthanhtoanphieunhap(); objtientt = ctrtientt.GetByIDPNvsNgayTT(objphieu.id, objphieu.ngaytao); if (objtientt != null) { objtientt.tientt = objphieu.tienthanhtoan; ctrtientt.Update(objtientt); } else { objtientt = new tienthanhtoanphieunhap(); objtientt.id = Guid.NewGuid().ToString().Trim(); objtientt.idpn = objphieu.id; objtientt.ngaytt = objphieu.ngaytao; objtientt.tientt = objphieu.tienthanhtoan; ctrtientt.Insert(objtientt); } _ctrlog.Append(Data.use, "Sửa phiếu nhập kho của nhà cung cấp: " + cbNhaCC.Text.Trim() + " xuất ngày: " + dpkNgayNhap.Value.ToString("dd/MM/yyyy").Trim() + "; id: " + objphieu.id + ";\nChi tiết: Tổng tiền hàng: " + txtTongTien.Text + " - Nợ cũ: " + txtNoToaTruoc.Text + " - Tiền thanh toán: " + txtTienThanhToan.Text + " - Tổng nợ mới: " + txtConNo.Text); } if (kq.Trim().Equals("") == true) { if (lstmathang != null) { if (objphieu != null && lstmathang.Count > 0) { for (int i = 0; i < lstmathang.Count; i++) { tblhangnhapkho temp = new tblhangnhapkho(); temp = ctrmathangnhap.GetByID(lstmathang[i].id); if (temp == null) { lstmathang[i].id_phieunhapkho = objphieu.id; kq = ctrmathangnhap.Insert(lstmathang[i]); if (kq.Trim().Equals("") == false) { ctrphieu.Delete(objphieu.id); break; } else //Thêm số lượng vào trong kho { tblmathang objmathang = new tblmathang(); objmathang = ctrmathang.GetByID(lstmathang[i].id_mathang.Trim()); objmathang.soluong = objmathang.soluong + lstmathang[i].soluong; objmathang.gianhap = lstmathang[i].gianhap; ctrmathang.Update(objmathang); } } else { lstmathang[i].id_phieunhapkho = objphieu.id; kq = ctrmathangnhap.Update(lstmathang[i]); if (kq.Trim().Equals("") == false) { break; } else //Cập nhật lại số lượng còn trong kho { tblmathang objmathang = new tblmathang(); objmathang = ctrmathang.GetByID(lstmathang[i].id_mathang.Trim()); objmathang.soluong = (objmathang.soluong - temp.soluong) + lstmathang[i].soluong; objmathang.gianhap = lstmathang[i].gianhap; ctrmathang.Update(objmathang); } } } if (kq.Trim().Equals("") == false) { MessageBox.Show("Lỗi cập nhật phiếu nhập hàng.\nChi tiết lỗi: " + kq, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (txtID.Text.Trim().Equals("-1") == true) { txtID.Text = objphieu.id.Trim(); _ctrlog.Append(Data.use, "Thêm mới phiếu nhập hàng của nhà cung cấp: " + cbNhaCC.Text.Trim() + " xuất ngày: " + dpkNgayNhap.Value.ToString("dd/MM/yyyy").Trim() + "; id: " + objphieu.id + ";\nChi tiết: Tổng tiền hàng: " + txtTongTien.Text + " - Nợ cũ: " + txtNoToaTruoc.Text + " - Tiền thanh toán: " + txtTienThanhToan.Text + " - Tổng nợ mới: " + txtConNo.Text); } } } } } else { MessageBox.Show("Lỗi cập nhật phiếu nhập hàng.\nChi tiết lỗi: " + kq, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (kq.Trim().Equals("") == true && lstmathang != null) { MessageBox.Show("Cập nhật phiếu nhập hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); HienThiTT(); HienThiDSMatHang(); ultraToolbarsManager1.Tools["btn_Del"].SharedProps.Visible = true; } }