Esempio n. 1
0
        private void XuatBBLuong(object sender, WaitWindowEventArgs e)
        {
            string tenNVLapBieu  = (string)e.Arguments[0];
            string saveFileName  = (string)e.Arguments[1];
            var    ngaydauthang  = MyUtility.FirstDayOfMonth(m_Thang);
            var    ngaycuoithang = MyUtility.LastDayOfMonth(m_Thang);
            //#region lấy dữ liệu kết lương để xuất

            var tableKetLuongThang        = DAO.LayKetLuongThang(ngaydauthang);
            var tableThongsoKetluongThang = DAO.LayThongsoKetluongThang(ngaydauthang);
            var tableDSNVChiCongnhatThang = DAO.LayTableCongNhat(ngaydauthang);
            var tableTongLuongCongnhat    = SqlDataAccessHelper.ExecuteQueryString(
                @"select  CAST(SUM (SoNgayCong*DonGiaLuong) as float)  from DSNVChiCongNhatThang where Thang=@Thang",
                new string[] { "@Thang" }, new object[] { ngaydauthang });
            var tongLuongCongnhat  = (tableTongLuongCongnhat.Rows[0][0] != DBNull.Value) ? (double)tableTongLuongCongnhat.Rows[0][0] : 0d;
            var tongLuongDieuchinh = (from DataRow row in tableKetLuongThang.Rows
                                      let luongdieuchinh = (row["LuongDieuChinh"] != DBNull.Value)
                                                                                                                           ? (double)row["LuongDieuChinh"]
                                                                                                                           : 0d
                                                           select luongdieuchinh).Sum();
            var tableKetcongNgay = DAO.LayKetcongNgay(ngaydauthang, ngaycuoithang);
            var tableKetcongCa   = DAO.LayKetcongCa(ngaydauthang, ngaycuoithang);
            var tableXPVang      = DAO.LayTableXPVang(ngaydauthang, ngaycuoithang);
            var tableNgayLe      = DAO.DocNgayLe(ngaydauthang, ngaycuoithang);
            var dsnv             = new List <cUserInfo>();

            ChuanBiDuLieuXuatLuong(dsnv, ngaydauthang, ngaycuoithang, tableKetLuongThang, tableKetcongNgay, tableKetcongCa, tableXPVang, tableNgayLe, tableDSNVChiCongnhatThang);

            //#endregion

            //fortesting testing region [02]
            using (var p = new ExcelPackage()) {
                //1. xuat bb bang thong so san luong, don gia, he so pc
                #region lay thong so cac loai pc de ghi cot tieu de
                int pc30   = (int)tableThongsoKetluongThang.Rows[0]["HSPCDem"];
                int pc50   = (int)tableThongsoKetluongThang.Rows[0]["HSPCTangCuong"];
                int pctcc3 = (int)tableThongsoKetluongThang.Rows[0]["HSPCTangCuong_Dem"];
                int pc100  = (int)tableThongsoKetluongThang.Rows[0]["HSPC200"];
                int pc160  = (int)tableThongsoKetluongThang.Rows[0]["HSPC260"];
                int pc200  = (int)tableThongsoKetluongThang.Rows[0]["HSPC300"];
                int pc290  = (int)tableThongsoKetluongThang.Rows[0]["HSPC390"];
                #endregion
                //2. xuat bb bang ket cong thang
                #region ghi sheet bang ket cong thang trinh ky

                p.Workbook.Worksheets.Add("BangKetCong");
                var ws = p.Workbook.Worksheets["BangKetCong"];
                ws.Name = "BangKetCong";                 //Setting Sheet's name
                XL.ExportSheetBangKetcongThang(ws, ngaydauthang, ngaycuoithang, dsnv, string.Empty, string.Empty, pc30, pc50, pctcc3, pc100, pc160, pc200, pc290);

                #endregion
                //3. xuat bb chi tiết kết công
                #region ghi sheet chi tiết kết công

                p.Workbook.Worksheets.Add("ChiTietKetCong");
                ws      = p.Workbook.Worksheets["ChiTietKetCong"];
                ws.Name = "ChiTietKetCong";                 //Setting Sheet's name
                XL.ExportSheetBangChiTietKetCong(ws, ngaydauthang, ngaycuoithang, dsnv, pc30, pc50, pctcc3, pc100, pc160, pc200, pc290);

                #endregion
                //4. xuat bb bang luong cong nhat
                #region ghi sheet bang luong cong nhat

                p.Workbook.Worksheets.Add("BangLuongCongNhat");
                ws      = p.Workbook.Worksheets["BangLuongCongNhat"];
                ws.Name = "BangLuongCongNhat";
                XL.ExportSheetBangLuongCongNhat(ws, ngaydauthang, tableDSNVChiCongnhatThang);

                #endregion
                //5. xuat bb bang luong chinh thuc
                #region ghi sheet bảng lương

                p.Workbook.Worksheets.Add("BangLuong");
                ws      = p.Workbook.Worksheets["BangLuong"];
                ws.Name = "BangLuong";
                XL.ExportSheetBangLuong(ws, m_Thang, dsnv, tenNVLapBieu);

                #endregion
                //6. xuat bb bang tong hop so lieu giam doc ky duyet
                #region ghi sheet bảng tổng hợp số liệu

                p.Workbook.Worksheets.Add("BangTongHopChi");
                ws      = p.Workbook.Worksheets["BangTongHopChi"];
                ws.Name = "BangTongHopChi";
                XL.ExportSheetTongHopChi(ws, m_Thang, tableThongsoKetluongThang, tongLuongCongnhat, tongLuongDieuchinh);

                #endregion
                //7. xuat sheet thong ke sữa
                #region ghi sheet thống kê BD ĐH

                p.Workbook.Worksheets.Add("BangThongKeBoiDuongDocHai");
                ws      = p.Workbook.Worksheets["BangThongKeBoiDuongDocHai"];
                ws.Name = "BangThongKeBoiDuongDocHai";
                XL.ExportSheetBangThongKeSua(ws, ngaydauthang, ngaycuoithang, dsnv);

                #endregion


                Byte[] bytes = p.GetAsByteArray();
                XL.XuatFileExcel(saveFileName, bytes, "frm4LuuHSPC XuatBBLuong");
            }
        }