private void HienThiDS()
 {
     try
     {
         tienthanhtoanphieunhapBL ctr = new tienthanhtoanphieunhapBL();
         DataTable dt = new DataTable();
         dt = ctr.GetByIDPN(sidpn);
         dt.Columns.Add("tt", typeof(Int32));
         c1FlexGrid1.DataSource = dt;
         FormatGrid();
     }
     catch { }
 }
        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();
            }
        }
示例#3
0
        /// <summary>
        /// Hàm tính tổng tiền mua hàng theo hóa đơn nhập
        /// </summary>
        /// <param name="sidpn">Mã phiếu nhập kiểu string</param>
        /// <returns>Tổng tiền đã mua hàng kiểu double</returns>
        public double GetTongTienByIDPN(string sidpn)
        {
            double tongtien = 0;

            try
            {
                tienthanhtoanphieunhapBL ctr = new tienthanhtoanphieunhapBL();
                DataTable dt = new DataTable();
                dt = GetByIDPN(sidpn);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    double tienofrow = 0;
                    try { tienofrow = Convert.ToDouble(dt.Rows[i]["soluong"].ToString().Trim()) * Convert.ToDouble(dt.Rows[i]["gianhap"].ToString().Trim()); }
                    catch { }
                    tongtien = tongtien + tienofrow;
                }
                return(tongtien);
            }
            catch { return(tongtien); }
        }
        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);
                }
            }
        }
 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;
     }
 }
 private string GenerateWorksheetTKCongNo(WorksheetCollection sheets, DateTime dtdenngay, DataTable dtnhacc, ProgressBar progressBar)
 {
     try
     {
         tblphieunhapkhoBL        ctrpn          = new tblphieunhapkhoBL();
         tblphieunhapkho          objpn          = new tblphieunhapkho();
         tblhangnhapkhoBL         ctrhangnhapkho = new tblhangnhapkhoBL();
         tienthanhtoanphieunhapBL ctrtiendatt    = new tienthanhtoanphieunhapBL();
         Worksheet sheet = sheets.Add("TKCongNoNhapHang");
         sheet.Table.DefaultRowHeight    = 15F;
         sheet.Table.ExpandedColumnCount = 5;
         sheet.Table.ExpandedRowCount    = 5 + dtnhacc.Rows.Count;
         sheet.Table.FullColumns         = 1;
         sheet.Table.FullRows            = 1;
         sheet.Table.Columns.Add(36);
         sheet.Table.Columns.Add(193);
         sheet.Table.Columns.Add(149);
         sheet.Table.Columns.Add(191);
         sheet.Table.Columns.Add(159);
         // -----------------------------------------------
         #region Add Header
         WorksheetRow Row0 = sheet.Table.Rows.Add();
         Row0.Height        = 20;
         Row0.AutoFitHeight = false;
         WorksheetCell cell;
         cell             = Row0.Cells.Add();
         cell.StyleID     = "s75";
         cell.Data.Type   = DataType.String;
         cell.Data.Text   = "TỔNG HỢP CÔNG NỢ NHẬP HÀNG";
         cell.MergeAcross = 4;
         // -----------------------------------------------
         WorksheetRow Row1 = sheet.Table.Rows.Add();
         Row1.AutoFitHeight = false;
         cell             = Row1.Cells.Add();
         cell.StyleID     = "s76";
         cell.Data.Type   = DataType.String;
         cell.Data.Text   = "(Số liệu tính đến ngày " + dtdenngay.ToString("dd/MM/yyyy") + ")";
         cell.MergeAcross = 4;
         // -----------------------------------------------
         WorksheetRow Row2 = sheet.Table.Rows.Add();
         Row2.AutoFitHeight = false;
         cell             = Row2.Cells.Add();
         cell.StyleID     = "m83608040";
         cell.Data.Type   = DataType.String;
         cell.Data.Text   = "Đơn vị tính: VNĐ";
         cell.MergeAcross = 4;
         // -----------------------------------------------
         WorksheetRow Row3 = sheet.Table.Rows.Add();
         Row3.AutoFitHeight = false;
         Row3.Cells.Add("Stt", DataType.String, "s67");
         Row3.Cells.Add("Nhà cung cấp", DataType.String, "s67");
         Row3.Cells.Add("Điện thoại", DataType.String, "s67");
         Row3.Cells.Add("Địa chỉ", DataType.String, "s67");
         Row3.Cells.Add("Tổng tiền còn nợ", DataType.String, "s67");
         #endregion
         // -----------------------------------------------
         #region Add Content
         for (int i = 0; i < dtnhacc.Rows.Count; i++)
         {
             Application.DoEvents();
             progressBar.PerformStep();
             Application.DoEvents();
             string sidnhacc = "";
             try { sidnhacc = dtnhacc.Rows[i]["id"].ToString().Trim(); }
             catch { sidnhacc = "-/-"; }
             string stennhacc = "";
             try { stennhacc = dtnhacc.Rows[i]["ten"].ToString().Trim(); }
             catch { stennhacc = "-/-"; }
             string sdt = "";
             try { sdt = dtnhacc.Rows[i]["dienthoai"].ToString().Trim(); }
             catch { sdt = "-/-"; }
             string sdiachi = "";
             try { sdiachi = dtnhacc.Rows[i]["diachi"].ToString().Trim(); }
             catch { sdiachi = "-/-"; }
             if (sidnhacc.Trim().Equals("") == false)
             {
                 // Lấy hóa đơn gần với ngày thống kê nhất
                 objpn = new tblphieunhapkho();
                 Application.DoEvents();
                 progressBar.PerformStep();
                 Application.DoEvents();
                 objpn = ctrpn.GetNewFirstByNgayTaovsIDKH(dtdenngay.AddDays(1).ToString("yyyy/MM/dd").Trim(), sidnhacc);
                 if (objpn != null)
                 {
                     double tienmuahang = 0;
                     try { tienmuahang = ctrhangnhapkho.GetTongTienByIDPN(objpn.id); }
                     catch { }
                     //double tientt = 0;
                     //tientt = objpn.tienthanhtoan;
                     double chietkhau = 0;
                     chietkhau = objpn.chietkhau;
                     double tiendatt = 0;
                     try { tiendatt = ctrtiendatt.GetTienDaThanhToan(objpn.id); }
                     catch { }
                     double tienconnotoatruoc = 0;
                     try { tienconnotoatruoc = ctrpn.GetTienConNo(objpn.id_nguoicap, objpn.ngaytao); }
                     catch { }
                     double tienconno = 0;
                     tienconno = ((tienmuahang - tiendatt - chietkhau) + tienconnotoatruoc);
                     Application.DoEvents();
                     progressBar.PerformStep();
                     Application.DoEvents();
                     WorksheetRow Row = sheet.Table.Rows.Add();
                     Row.Cells.Add((i + 1).ToString(), DataType.Number, "s68");
                     Row.Cells.Add(stennhacc, DataType.String, "s69");
                     Row.Cells.Add(sdt, DataType.String, "s69");
                     Row.Cells.Add(sdiachi, DataType.String, "s69");
                     Row.Cells.Add(tienconno.ToString().Trim(), DataType.Number, "s70");
                 }
             }
         }
         #endregion
         // -----------------------------------------------
         #region Tính tổng các dòng
         WorksheetRow Row7 = sheet.Table.Rows.Add();
         Row7.AutoFitHeight = false;
         cell             = Row7.Cells.Add();
         cell.StyleID     = "m83608060";
         cell.Data.Type   = DataType.String;
         cell.Data.Text   = "TỔNG CỘNG";
         cell.MergeAcross = 3;
         cell             = Row7.Cells.Add();
         cell.StyleID     = "s74";
         cell.Data.Type   = DataType.Number;
         cell.Formula     = "=SUM(R[-" + dtnhacc.Rows.Count.ToString() + "]C:R[-1]C)";
         #endregion
         // -----------------------------------------------
         //  Options
         // -----------------------------------------------
         sheet.Options.Selected                     = true;
         sheet.Options.ProtectObjects               = false;
         sheet.Options.ProtectScenarios             = false;
         sheet.Options.PageSetup.Header.Margin      = 0.3F;
         sheet.Options.PageSetup.Footer.Margin      = 0.3F;
         sheet.Options.PageSetup.PageMargins.Bottom = 0.75F;
         sheet.Options.PageSetup.PageMargins.Left   = 0.7F;
         sheet.Options.PageSetup.PageMargins.Right  = 0.7F;
         sheet.Options.PageSetup.PageMargins.Top    = 0.75F;
         sheet.Options.Print.HorizontalResolution   = 300;
         sheet.Options.Print.VerticalResolution     = 0;
         sheet.Options.Print.ValidPrinterInfo       = true;
         return("");
     }
     catch (Exception ex) { return(ex.Message); }
 }