private List <tienthanhtoanphieunhap> GetListTienThanhToan()
        {
            tblphieunhapkhoBL ctrphieunhap = new tblphieunhapkhoBL();
            tblphieunhapkho   objphieunhap = new tblphieunhapkho();

            objphieunhap = ctrphieunhap.GetByID(sidpn);
            try
            {
                List <tienthanhtoanphieunhap> lst = new List <tienthanhtoanphieunhap>();
                for (int i = 1; i < c1FlexGrid1.Rows.Count; i++)
                {
                    tienthanhtoanphieunhap obj = new tienthanhtoanphieunhap();
                    if (c1FlexGrid1[i, "tt"].ToString().Trim().Equals("0") == false)
                    {
                        if (c1FlexGrid1[i, "tt"].ToString().Trim().Equals("1") == true)
                        {
                            obj.id = Guid.NewGuid().ToString();
                        }
                        else if (c1FlexGrid1[i, "tt"].ToString().Trim().Equals("2") == true)
                        {
                            obj.id = c1FlexGrid1[i, "id"].ToString().Trim();
                        }
                        if (sidpn.Trim().Equals("") == true)
                        {
                            MessageBox.Show("Không lấy được thông tin hóa đơn.\nVui lòng tắt chương trình và khởi động lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            c1FlexGrid1.Select(i, c1FlexGrid1.Cols["tientt"].Index);
                            return(null);
                        }
                        try { obj.tientt = Convert.ToDouble(c1FlexGrid1[i, "tientt"].ToString().Trim()); }
                        catch
                        {
                            MessageBox.Show("Tiền thanh toán nhập không đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            c1FlexGrid1.Select(i, c1FlexGrid1.Cols["tientt"].Index);
                            return(null);
                        }
                        if (obj.tientt == 0)
                        {
                            MessageBox.Show("Tiền thanh toán phải lớn hơn 0", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            c1FlexGrid1.Select(i, c1FlexGrid1.Cols["tientt"].Index);
                            return(null);
                        }
                        obj.idpn   = sidpn;
                        obj.ngaytt = Convert.ToDateTime(c1FlexGrid1[i, "ngaytt"].ToString().Trim());
                        if (objphieunhap.ngaytao == obj.ngaytt)
                        {
                            MessageBox.Show("Bản ghi này đã tồn tại.\nVui lòng nhập lại ngày thanh toán", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            c1FlexGrid1.Select(i, c1FlexGrid1.Cols["ngaytt"].Index);
                            return(null);
                        }
                        obj.ghichu = c1FlexGrid1[i, "ghichu"].ToString().Trim();
                        lst.Add(obj);
                    }
                }
                return(lst);
            }
            catch { return(null); }
        }
        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();
            }
        }
        private void Del()
        {
            tienthanhtoanphieunhapBL ctr = new tienthanhtoanphieunhapBL();

            if (c1FlexGrid1.Rows.Count - 1 > 0)
            {
                string sid = c1FlexGrid1[c1FlexGrid1.RowSel, "id"].ToString().Trim();
                if (sid.Trim().Equals("") == false)
                {
                    if (c1FlexGrid1.Rows[c1FlexGrid1.RowSel].AllowEditing == false)
                    {
                        MessageBox.Show("Bạn không thể xóa bản ghi này.\nĐể xóa được bạn vui lòng xóa phiếu nhập hàng.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    tienthanhtoanphieunhap temp = new tienthanhtoanphieunhap();
                    temp = ctr.GetByID(sid);
                    string kq = "";
                    kq = ctr.Delete(sid);
                    if (kq.Trim().Equals("") == true)
                    {
                        try
                        {
                            _ctrlog.Append(Data.use, "Xóa tiền thanh toán ngày: " + temp.ngaytt.ToString("dd/MM/yyyy HH:mm:ss")
                                           + " số tiền: " + temp.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);
                        }
                        catch { }
                        MessageBox.Show("Xóa tiền thanh toán của phiếu nhập thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        HienThiDS();
                    }
                }
                else
                {
                    c1FlexGrid1.Rows.Remove(c1FlexGrid1.RowSel);
                }
            }
        }
Esempio n. 4
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;
     }
 }
 public tienthanhtoanphieunhapBL()
 {
     objtienthanhtoanphieunhapDA = new tienthanhtoanphieunhap();
 }
 /// <summary>
 /// Cập nhật dữ liệu vào bảng: tienthanhtoanphieunhap
 /// </summary>
 /// <param name="obj">objtienthanhtoanphieunhap</param>
 /// <returns>Trả về trắng: Cập nhật thành công; Trả về khác trắng: Cập nhật không thành công</returns>
 public string Update(tienthanhtoanphieunhap objtienthanhtoanphieunhap)
 {
     return(objtienthanhtoanphieunhapDA.Update(objtienthanhtoanphieunhap));
 }
 /// <summary>
 /// Thêm mới dữ liệu vào bảng: tienthanhtoanphieunhap
 /// </summary>
 /// <param name="obj">objtienthanhtoanphieunhap</param>
 /// <returns>Trả về trắng: Thêm mới thành công; Trả về khác trắng: Thêm mới không thành công</returns>
 public string Insert(tienthanhtoanphieunhap objtienthanhtoanphieunhap)
 {
     return(objtienthanhtoanphieunhapDA.Insert(objtienthanhtoanphieunhap));
 }