예제 #1
0
        private void Save()
        {
            string kq = "";
            tienthanhtoanphieunhapBL      ctr = new tienthanhtoanphieunhapBL();
            List <tienthanhtoanphieunhap> lst = new List <tienthanhtoanphieunhap>();

            lst = GetListTienThanhToan();
            for (int i = 0; i < lst.Count; i++)
            {
                tienthanhtoanphieunhap temp = new tienthanhtoanphieunhap();
                temp = ctr.GetByID(lst[i].id);
                if (temp == null)
                {
                    try
                    {
                        kq = ctr.Insert(lst[i]);
                    }
                    catch { break; }
                    _ctrlog.Append(Data.use, "Thêm mới tiền thanh toán ngày: " + lst[i].ngaytt.ToString("dd/MM/yyyy HH:mm:ss")
                                   + " số tiền: " + lst[i].tientt.ToString("N0", CultureInfo.InvariantCulture)
                                   + " cho phiếu nhập hàng của nhà cung cấp: " + lbTenKH.Text
                                   + " xuất ngày: " + lbNgayXuat.Text);
                }
                else
                {
                    try
                    {
                        kq = ctr.Update(lst[i]);
                    }
                    catch { break; }
                    _ctrlog.Append(Data.use, "Cập nhật tiền thanh toán ngày: " + lst[i].ngaytt.ToString("dd/MM/yyyy HH:mm:ss")
                                   + " từ số tiền: " + temp.tientt.ToString("N0", CultureInfo.InvariantCulture)
                                   + " thành số tiền: " + lst[i].tientt.ToString("N0", CultureInfo.InvariantCulture)
                                   + " cho phiếu nhập hàng của nhà cung cấp: " + lbTenKH.Text
                                   + " xuất ngày: " + lbNgayXuat.Text);
                }
            }
            if (kq.Trim().Equals("") == true)
            {
                MessageBox.Show("Cập nhật tiền thanh toán cho phiếu nhập hàng thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                HienThiDS();
            }
        }
예제 #2
0
 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;
     }
 }