//--------------------------------------------------------------------------------- #region "** object model" /// <summary> /// Saves the content of a C1FlexGrid into an XLSheet. /// </summary> public static void Save(C1FlexGrid flex, XLSheet sheet) { // clear style cache if this is a new book if(!object.ReferenceEquals(sheet.Book, _lastBook)) { _cellStyles.Clear(); _excelStyles.Clear(); _lastBook = sheet.Book; } // save global parameters sheet.DefaultRowHeight = PixelsToTwips(flex.Rows.DefaultSize); sheet.DefaultColumnWidth = PixelsToTwips(flex.Columns.DefaultSize); sheet.ShowGridLines = flex.GridLinesVisibility != GridLinesVisibility.None; sheet.ShowHeaders = flex.HeadersVisibility != HeadersVisibility.None; sheet.OutlinesBelow = flex.GroupRowPosition == GroupRowPosition.BelowData; // save columns sheet.Columns.Clear(); foreach(Column col in flex.Columns) { dynamic c = sheet.Columns.Add(); if(!col.Width.IsAuto) { c.Width = PixelsToTwips(col.ActualWidth); } c.Visible = col.Visible; if(col.CellStyle is ExcelCellStyle) { c.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)col.CellStyle); } } sheet.Rows.Clear(); //save column headers XLStyle headerStyle = default(XLStyle); headerStyle = new XLStyle(sheet.Book); headerStyle.Font = new XLFont("Microsoft YaHei", 10, true, false); headerStyle.BorderLeft = XLLineStyleEnum.Thin; headerStyle.BorderTop = XLLineStyleEnum.Thin; headerStyle.BorderRight = XLLineStyleEnum.Thin; headerStyle.BorderBottom = XLLineStyleEnum.Thin; //save column headers foreach(Row row in flex.ColumnHeaders.Rows) { dynamic r = sheet.Rows.Add(); if(row.Height > -1) { r.Height = PixelsToTwips(row.Height); } if(row.CellStyle is ExcelCellStyle) { r.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)row.CellStyle); } if(row is ExcelRow) { r.OutlineLevel = ((ExcelRow)row).Level; } for(int c = 0; c <= flex.ColumnHeaders.Columns.Count - 1; c++) { // save cell value dynamic cell = sheet[row.Index, c]; string colHeader = flex.Columns[c].Header; cell.Value = colHeader; // make column headers bold cell.Style = headerStyle; } r.Visible = row.Visible; } // save rows foreach(Row row in flex.Rows) { dynamic r = sheet.Rows.Add(); if(row.Height > -1) { r.Height = PixelsToTwips(row.Height); } if(row.CellStyle is ExcelCellStyle) { r.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)row.CellStyle); } if(row is ExcelRow) { r.OutlineLevel = ((ExcelRow)row).Level; } r.Visible = row.Visible; } XLStyle dateTimeStyle = default(XLStyle); dateTimeStyle = new XLStyle(sheet.Book); dateTimeStyle.Font = new XLFont("Microsoft YaHei", 10, false, false); dateTimeStyle.Format = "yyyy/mm/dd"; dateTimeStyle.BorderLeft = XLLineStyleEnum.Thin; dateTimeStyle.BorderTop = XLLineStyleEnum.Thin; dateTimeStyle.BorderRight = XLLineStyleEnum.Thin; dateTimeStyle.BorderBottom = XLLineStyleEnum.Thin; XLStyle normalStyle = default(XLStyle); normalStyle = new XLStyle(sheet.Book); normalStyle.Font = new XLFont("Microsoft YaHei", 10, false, false); normalStyle.BorderLeft = XLLineStyleEnum.Thin; normalStyle.BorderTop = XLLineStyleEnum.Thin; normalStyle.BorderRight = XLLineStyleEnum.Thin; normalStyle.BorderBottom = XLLineStyleEnum.Thin; // save cells for(int r = flex.ColumnHeaders.Rows.Count; r <= flex.Rows.Count; r++) { for(int c = 0; c <= flex.Columns.Count - 1; c++) { // save cell value dynamic cell = sheet[r, c]; dynamic obj = flex[r - 1, c]; if(obj is DateTime) { cell.Style = dateTimeStyle; } else { cell.Style = normalStyle; } cell.Value = obj is FrameworkElement ? 0 : obj; // save cell formula and style //dynamic row = flex.Rows[r - 1] as ExcelRow; //if(row != null) //{ // // save cell formula // dynamic col = flex.Columns[c]; // // save cell style // dynamic cs = row.GetCellStyle(col) as ExcelCellStyle; // if(cs != null) // { // cell.Style = GetXLStyle(flex, sheet, cs); // } //} } } // save selection dynamic sel = flex.Selection; if(sel.IsValid) { dynamic xlSel = new XLCellRange(sheet, sel.Row, sel.Row2, sel.Column, sel.Column2); sheet.SelectedCells.Clear(); sheet.SelectedCells.Add(xlSel); } }
/// <summary> /// Saves the content of a C1FlexGrid into an XLSheet. /// </summary> public static void Save(C1FlexGrid flex, XLSheet sheet) { // clear style cache if this is a new book if (sheet.Book != _lastBook) { _cellStyles.Clear(); _excelStyles.Clear(); _lastBook = sheet.Book; } // save global parameters sheet.DefaultRowHeight = PixelsToTwips(flex.Rows.DefaultSize); sheet.DefaultColumnWidth = PixelsToTwips(flex.Columns.DefaultSize); sheet.Locked = flex.IsReadOnly; sheet.ShowGridLines = flex.GridLinesVisibility != GridLinesVisibility.None; sheet.ShowHeaders = flex.HeadersVisibility != HeadersVisibility.None; sheet.OutlinesBelow = flex.GroupRowPosition == GroupRowPosition.BelowData; // save columns sheet.Columns.Clear(); foreach (Column col in flex.Columns) { var c = sheet.Columns.Add(); if (!col.Width.IsAuto) { c.Width = PixelsToTwips(col.ActualWidth); } c.Visible = col.Visible; if (col.CellStyle is ExcelCellStyle) { c.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)col.CellStyle); } } // save rows sheet.Rows.Clear(); foreach (Row row in flex.Rows) { var r = sheet.Rows.Add(); if (row.Height > -1) { r.Height = PixelsToTwips(row.Height); } if (row.CellStyle is ExcelCellStyle) { r.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)row.CellStyle); } if (row is ExcelRow) { r.OutlineLevel = ((ExcelRow)row).Level; } r.Visible = row.Visible; } // save cells for (int r = 0; r < flex.Rows.Count; r++) { for (int c = 0; c < flex.Columns.Count; c++) { // save cell value var cell = sheet[r, c]; var obj = flex[r, c]; cell.Value = obj is FrameworkElement ? 0 : obj; // save cell formula and style var row = flex.Rows[r] as ExcelRow; if (row != null) { // save cell formula var col = flex.Columns[c]; var formula = row.GetDataEditor(col); if (formula.StartsWith("=")) { cell.Formula = formula; } // save cell style var cs = row.GetCellStyle(col) as ExcelCellStyle; if (cs != null) { cell.Style = GetXLStyle(flex, sheet, cs); } } } } // save selection var sel = flex.Selection; if (sel.IsValid) { var xlSel = new XLCellRange(sheet, sel.Row, sel.Row2, sel.Column, sel.Column2); sheet.SelectedCells.Clear(); sheet.SelectedCells.Add(xlSel); } // save merged cells var xmm = flex.MergeManager as ExcelMergeManager; if (xmm != null) { xmm.SetMergedRanges(sheet); } }
protected void btnExport_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT *"; sql += " FROM v_GuiXeThang"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; sql += " AND ((NgayKetThuc is null) OR "; sql += " (NgayKetThuc is not null and substring(NgayKetThuc,1,6) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'))"; using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); db.Close(); if (ds != null) { C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\GuixeThang.xls"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\GuiXeThang" + strDT + ".xls"; string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/GuiXeThang" + strDT + ".xls"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLSheet xlsSheet = xlbBook.Sheets["GuiXeThang"]; //xlsSheet.Name = drpMonth.SelectedValue + "_" + drpYear.SelectedValue; int i = 4; XLCellRange mrCell = new XLCellRange(0, 0, 0, 2); xlsSheet.MergedCells.Add(mrCell); XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; XLStyle xlstStyle01 = new XLStyle(xlbBook); xlstStyle01.AlignHorz = XLAlignHorzEnum.Center; xlstStyle01.Font = new Font("", 10, FontStyle.Bold); xlstStyle.SetBorderColor(Color.Black); xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue+"/"+drpYear.SelectedValue); int stt = 0; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string col01 = rowType[0].ToString(); string col02 = rowType[1].ToString(); string col03 = rowType[2].ToString(); string col04 = rowType[3].ToString(); string col05 = rowType[4].ToString(); string col06 = rowType[5].ToString(); string col07 = Func.FormatDMY(rowType[6].ToString()); string col08 = Func.FormatDMY(rowType[7].ToString()); string col09 = rowType[8].ToString(); xlsSheet[i, 0].Value = ++stt; xlsSheet[i, 1].Value = col03; xlsSheet[i, 2].Value = col04; xlsSheet[i, 3].Value = col05; xlsSheet[i, 4].Value = col06; xlsSheet[i, 5].Value = col07; xlsSheet[i, 6].Value = col08; xlsSheet[i, 7].Value = col09; xlsSheet[i, 0].Style = xlstStyle; xlsSheet[i, 1].Style = xlstStyle; xlsSheet[i, 2].Style = xlstStyle; xlsSheet[i, 3].Style = xlstStyle; xlsSheet[i, 4].Style = xlstStyle; xlsSheet[i, 5].Style = xlstStyle; xlsSheet[i, 6].Style = xlstStyle; xlsSheet[i, 7].Style = xlstStyle; ++i; } ////ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('/CSV/DownloadZipFile.aspx'," + PopupWidth + "," + PopupHeight + ",'EditFlat', true);", true); ////xlsSheet[i++, 0].Value = "Ghi chú:"; //DataSet ds1 = new DataSet(); //sql = string.Empty; //sql = " SELECT *"; //sql += " FROM BD_WorkingHour"; //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1"; //sql += " Order By Name"; //using (SqlCommand cm1 = db.CreateCommand(sql)) //{ // SqlDataAdapter da1 = new SqlDataAdapter(cm1); // da1.Fill(ds1); // db.Close(); // if (ds != null) // { // xlsSheet[i++ + 1, 0].Value = "Ghi chú:"; // DataTable dt1 = ds1.Tables[0]; // foreach (DataRow rowType in dt1.Rows) // { // i++; // string Ma = rowType["WorkingHourId"].ToString(); // string Name = rowType["Name"].ToString(); // xlsSheet[i, 0].Value = Ma + ":"; // xlsSheet[i, 1].Value = Name; // } // xlsSheet[i + 1, 0].Value = "OF:"; // xlsSheet[i + 1, 1].Value = "OF: nghỉ"; // } //} //string dataPath = HttpContext.Current.Server.MapPath(@"\Building\Staff\DataTmp"); //string tmpFolder = dataPath; //if (!Directory.Exists(tmpFolder)) //{ // Directory.CreateDirectory(tmpFolder); //} //string name = "KhaiBaoLichLamViec_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls"; //string fileName = Path.Combine(tmpFolder, name); // string fileNameDes = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl_1.xlsx"); xlbBook.Save(fileNameDes); //Session["ZipFilePath"] = null; //Session["ZipFilePath"] = fileName; ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } }
protected void btnView_Click(object sender, EventArgs e) { int rBillNo = 0; int cBillNo = 1; int rBillDate = 0; int cBillDate = 10; int rBillMonth = 2; int cBillMonth = 0; int rContact = 5; int cContact = 3; int rCustomer = 5; int cCustomer = 9; int rContract = 7; int cContract = 1; int rRate = 11; int cRate = 9; int rRateDate = 11; int cRateDate = 12; int rRent = 15; int cRent = 1; int rManager = 23; int cManager = 1; int rParking = 31; int cParking = 1; int rExtra = 39; int cExtra = 1; int rElec = 47; int cElec = 1; int rWater = 55; int cWater = 1; int rService = 63; int cService = 1; int rPaid = 70; int cPaid = 1; int rDept = 77; int cDept = 1; int check = DbHelper.GetCount("Select count(*) from PaymentBillInfo Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + lblCustomerId.Text + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"); if (check == 0) { mvMessage.AddError("Xin vui lòng tạo hóa đơn trước khi xem"); return; } mvMessage.CheckRequired(txtBillDate, "Ngày xuất Hóa đơn là danh mục bắt buộc"); mvMessage.CheckRequired(txtBillNo, "Số Hóa đơn là danh mục bắt buộc"); mvMessage.CheckRequired(txtUsdExchange, "Tỉ giá USD-VN là danh mục bắt buộc"); mvMessage.CheckRequired(txtUsdExchangeDate, "Ngày tỉ giá là danh mục bắt buộc"); //ShowData(drpYear.SelectedValue + drpMonth.SelectedValue); C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BillTongQuat.xlsx"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))); } XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; xlstStyle.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleH = new XLStyle(xlbBook); xlstStyleH.AlignHorz = XLAlignHorzEnum.Center; xlstStyleH.AlignVert = XLAlignVertEnum.Center; xlstStyleH.Font = new Font("", 8, FontStyle.Bold); xlstStyleH.SetBorderColor(Color.Black); xlstStyleH.BorderBottom = XLLineStyleEnum.Thin; xlstStyleH.BorderTop = XLLineStyleEnum.Thin; xlstStyleH.BorderLeft = XLLineStyleEnum.Thin; xlstStyleH.BorderRight = XLLineStyleEnum.Thin; xlstStyleH.WordWrap = true; string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BillTongQuat" + strDT + ".xlsx"; string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/BillTongQuat" + strDT + ".xlsx"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLSheet xlsSheet = xlbBook.Sheets["TongHop"]; xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%BILL_NO%}", txtBillNo.Text); xlsSheet[1, 8].Value = xlsSheet[1, 8].Value.ToString().Replace("{%NGAY%}", DateTime.Today.ToString("dd")); xlsSheet[1, 8].Value = xlsSheet[1, 8].Value.ToString().Replace("{%THANG%}", DateTime.Today.ToString("MM")); xlsSheet[1, 8].Value = xlsSheet[1, 8].Value.ToString().Replace("{%NAM%}", DateTime.Today.ToString("yyyy")); using (SqlDatabase db = new SqlDatabase()) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT Name, ContactName"; sql += " FROM Customer"; sql += " WHERE CustomerId = '" + lblCustomerId.Text + "' "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string Name = rowType[0].ToString(); string ContactName = rowType[1].ToString(); xlsSheet[6, 0].Value = xlsSheet[6, 0].Value.ToString().Replace("{%TEN_CONG_TY%}", Name); xlsSheet[7, 0].Value = xlsSheet[7, 0].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName); } } } Hashtable contractIdLst = new Hashtable(); string contract = ""; ds = new DataSet(); sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone"; sql += " FROM Mst_Building"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string Bank = rowType["Bank"].ToString(); string Account = rowType["Account"].ToString(); string AccountName = rowType["AccountName"].ToString(); string Office = rowType["Office"].ToString(); string OfficeAddress = rowType["OfficeAddress"].ToString(); string OfficePhone = rowType["OfficePhone"].ToString(); xlsSheet[62, 0].Value = xlsSheet[62, 0].Value.ToString().Replace("{%VAN_PHONG%}", Office); xlsSheet[63, 0].Value = xlsSheet[63, 0].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone); xlsSheet[65, 0].Value = xlsSheet[65, 0].Value.ToString().Replace("{%NGAN_HANG%}", Bank); xlsSheet[66, 0].Value = xlsSheet[66, 0].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName); xlsSheet[67, 0].Value = xlsSheet[67, 0].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account); } } } xlsSheet[56, 0].Value = xlsSheet[56, 0].Value.ToString().Replace("{%TI_GIA%}", txtUsdExchange.Text).Replace("{%NGAY_AP_DUNG%}", txtUsdExchangeDate.Text); //Thue phong ds = new DataSet(); sql = " Select *"; sql += " FROM PaymentRoom"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; int j = 0; double[] LastSumPriceVND = new double[7] { 0, 0, 0, 0, 0, 0, 0 }; float[] LastSumPriceUSD = new float[7] { 0, 0, 0, 0, 0, 0, 0 }; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(17 + j); j++; } count++; int tmp = 16 + j; string id = Func.ParseString(rowType["id"]); string BuildingId = Func.ParseString(rowType["BuildingId"]); string CustomerId = Func.ParseString(rowType["CustomerId"]); string ContractId = Func.ParseString(rowType["ContractId"]); string RoomId = Func.ParseString(rowType["RoomId"]); string OtherFee01 = Func.ParseString(rowType["OtherFee01"]); string OtherFee02 = Func.ParseString(rowType["OtherFee02"]); string YearMonth = Func.ParseString(rowType["YearMonth"]); string Area = Func.ParseString(rowType["Area"]); string Name = Func.ParseString(rowType["Name"]); string Regional = Func.ParseString(rowType["Regional"]); string Floor = Func.ParseString(rowType["Floor"]); string RentPriceVND = Func.ParseString(rowType["MonthRentPriceVND"]); string RentPriceUSD = Func.ParseString(rowType["MonthRentPriceUSD"]); string VatVND = Func.ParseString(rowType["VatRentPriceVND"]); string VatUSD = Func.ParseString(rowType["VatRentPriceUSD"]); string SumVND = Func.ParseString(rowType["MonthRentSumVND"]); string SumUSD = Func.ParseString(rowType["MonthRentSumUSD"]); string LastPriceVND = Func.ParseString(rowType["LastRentSumVND"]); string LastPriceUSD = Func.ParseString(rowType["LastRentSumUSD"]); string BeginContract = Func.ParseString(rowType["BeginContract"]); if (!contractIdLst.ContainsKey(ContractId + "(" + BeginContract + ")")) { contractIdLst.Add(ContractId + "(" + BeginContract + ")", ContractId + "(" + BeginContract + ")"); contract += ";" + ContractId + "(" + BeginContract + ")"; } xlsSheet[tmp, 1].Value = Name; xlsSheet[tmp, 4].Value = Regional; xlsSheet[tmp, 5].Value = Floor; xlsSheet[tmp, 6].Value = Func.ParseFloat(Area); xlsSheet[tmp, 7].Value = Func.ParseFloat(RentPriceUSD); xlsSheet[tmp, 8].Value = Func.ParseFloat(RentPriceVND); xlsSheet[tmp, 9].Value = Func.ParseFloat(SumUSD); xlsSheet[tmp, 10].Value = Func.ParseFloat(SumVND); xlsSheet[tmp, 11].Value = Func.ParseFloat(VatUSD); xlsSheet[tmp, 12].Value = Func.ParseFloat(VatVND); xlsSheet[tmp, 13].Value = Func.ParseFloat(LastPriceUSD); xlsSheet[tmp, 14].Value = Func.ParseFloat(LastPriceVND); XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); for (int col = 1; col <= 14; col++) { xlsSheet[tmp, col].Style = xlstStyle; } LastSumPriceVND[0] += Func.ParseFloat(LastPriceVND); LastSumPriceUSD[0] += Func.ParseFloat(LastPriceUSD); } xlsSheet[17 + j, 13].Value = LastSumPriceUSD[0]; xlsSheet[17 + j, 14].Value = LastSumPriceVND[0]; int line = 20 + j; //Quan ly XLCellRange mCell = new XLCellRange(line, line + 1, 1, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 1, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 1, 5, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 7, 8); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 9, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 11, 12); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 13, 14); xlsSheet.MergedCells.Add(mCell); for (int col = 1; col <= 14; col++) { xlsSheet[line, col].Style = xlstStyleH; } count = 0; foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(23 + j); j++; } count++; int tmp = 22; string id = Func.ParseString(row["id"]); string BuildingId = Func.ParseString(row["BuildingId"]); string CustomerId = Func.ParseString(row["CustomerId"]); string ContractId = Func.ParseString(row["ContractId"]); string RoomId = Func.ParseString(row["RoomId"]); string ManagerPriceVND = Func.ParseString(row["MonthManagerPriceVND"]); string ManagerPriceUSD = Func.ParseString(row["MonthManagerPriceUSD"]); string VatVND = Func.ParseString(row["VatManagerPriceVND"]); string VatUSD = Func.ParseString(row["VatManagerPriceUSD"]); string OtherFee01 = Func.ParseString(row["OtherFee01"]); string OtherFee02 = Func.ParseString(row["OtherFee02"]); string SumVND = Func.ParseString(row["MonthManagerSumVND"]); string SumUSD = Func.ParseString(row["MonthManagerSumUSD"]); string LastPriceVND = Func.ParseString(row["LastManagerSumVND"]); string LastPriceUSD = Func.ParseString(row["LastManagerSumUSD"]); string YearMonth = Func.ParseString(row["YearMonth"]); string Area = Func.ParseString(row["Area"]); string Name = Func.ParseString(row["Name"]); string Regional = Func.ParseString(row["Regional"]); string Floor = Func.ParseString(row["Floor"]); xlsSheet[tmp, 1].Value = Name; xlsSheet[tmp, 4].Value = Regional; xlsSheet[tmp, 5].Value = Floor; xlsSheet[tmp, 6].Value = Func.ParseFloat(Area); xlsSheet[tmp, 7].Value = Func.ParseFloat(ManagerPriceUSD); xlsSheet[tmp, 8].Value = Func.ParseFloat(ManagerPriceVND); xlsSheet[tmp, 9].Value = Func.ParseFloat(SumUSD); xlsSheet[tmp, 10].Value = Func.ParseFloat(SumVND); xlsSheet[tmp, 11].Value = Func.ParseFloat(VatUSD); xlsSheet[tmp, 12].Value = Func.ParseFloat(VatVND); xlsSheet[tmp, 13].Value = Func.ParseFloat(LastPriceUSD); xlsSheet[tmp, 14].Value = Func.ParseFloat(LastPriceVND); XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); for (int col = 1; col <= 14; col++) { xlsSheet[tmp, col].Style = xlstStyle; } LastSumPriceVND[1] += Func.ParseFloat(LastPriceVND); LastSumPriceUSD[1] += Func.ParseFloat(LastPriceUSD); } xlsSheet[23 + j, 13].Value = LastSumPriceUSD[1]; xlsSheet[23 + j, 14].Value = LastSumPriceVND[1]; } } ds = new DataSet(); //Xuất ra toàn bộ nội dung theo Trang sql = " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVND, PriceUSD, SUM(VatVND) AS VatVND,SUM(VatUSD) AS VatUSD, SUM(SumVND) AS SumVND, SUM(SumUSD) AS SumUSD, SUM(LastPriceVND) AS LastPriceVND"; sql += " , SUM(LastPriceUSD) AS LastPriceUSD"; sql += " FROM dbo.PaymentParking"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; int line = 26 + j; //Phi gui xe XLCellRange mCell = new XLCellRange(line, line + 1, 1, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 7, 8); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 9, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 11, 12); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 13, 14); xlsSheet.MergedCells.Add(mCell); for (int col = 1; col <= 14; col++) { xlsSheet[line, col].Style = xlstStyleH; } foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(29 + j); j++; } count++; int tmp = 28 + j; string Num = Func.ParseString(row["Num"]); string TariffsParkingName = Func.ParseString(row["TariffsParkingName"]); string PriceVND = Func.ParseString(row["PriceVND"]); string PriceUSD = Func.ParseString(row["PriceUSD"]); string VatVND = Func.ParseString(row["VatVND"]); string VatUSD = Func.ParseString(row["VatUSD"]); string SumVND = Func.ParseString(row["SumVND"]); string SumUSD = Func.ParseString(row["SumUSD"]); string LastPriceVND = Func.ParseString(row["LastPriceVND"]); string LastPriceUSD = Func.ParseString(row["LastPriceUSD"]); xlsSheet[tmp, 1].Value = TariffsParkingName; xlsSheet[tmp, 6].Value = Num; xlsSheet[tmp, 7].Value = Func.ParseFloat(PriceUSD); xlsSheet[tmp, 8].Value = Func.ParseFloat(PriceVND); xlsSheet[tmp, 9].Value = Func.ParseFloat(SumUSD); xlsSheet[tmp, 10].Value = Func.ParseFloat(SumVND); xlsSheet[tmp, 11].Value = Func.ParseFloat(VatUSD); xlsSheet[tmp, 12].Value = Func.ParseFloat(VatVND); xlsSheet[tmp, 13].Value = Func.ParseFloat(LastPriceUSD); xlsSheet[tmp, 14].Value = Func.ParseFloat(LastPriceVND); XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 5); xlsSheet.MergedCells.Add(mrCell); for (int col = 1; col <= 14; col++) { xlsSheet[tmp, col].Style = xlstStyle; } LastSumPriceVND[2] += Func.ParseFloat(LastPriceVND); LastSumPriceUSD[2] += Func.ParseFloat(LastPriceUSD); } xlsSheet[29 + j, 13].Value = LastSumPriceUSD[2]; xlsSheet[29 + j, 14].Value = LastSumPriceVND[2]; } } //Lam ngoai gio ds = new DataSet(); sql = " SELECT * "; sql += " FROM PaymentExtraTime"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; int line = 32 + j; //Phi ngoai gio XLCellRange mCell = new XLCellRange(line, line + 1, 1, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 7, 8); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 9, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 11, 12); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 13, 14); xlsSheet.MergedCells.Add(mCell); for (int col = 1; col <= 14; col++) { xlsSheet[line, col].Style = xlstStyleH; } foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(35 + j); j++; } count++; int tmp = 34 + j; //string id = Func.ParseString(row["id"]); string ExtraHour = Func.ParseString(row["ExtraHour"]); string WorkingDate = Func.ParseString(row["WorkingDate"]); string PriceVND = Func.ParseString(row["PriceVND"]); string PriceUSD = Func.ParseString(row["PriceUSD"]); string VatUSD = Func.ParseString(row["VatUSD"]); string VatVND = Func.ParseString(row["VatVND"]); //string OtherFee01 = Func.ParseString(row["OtherFee01"]); //string OtherFee02 = Func.ParseString(row["OtherFee02"]); string SumVND = Func.ParseString(row["SumVND"]); string SumUSD = Func.ParseString(row["SumUSD"]); string LastPriceVND = Func.ParseString(row["LastPriceVND"]); string LastPriceUSD = Func.ParseString(row["LastPriceUSD"]); xlsSheet[tmp, 1].Value = WorkingDate; xlsSheet[tmp, 6].Value = ExtraHour; xlsSheet[tmp, 7].Value = Func.ParseFloat(PriceUSD); xlsSheet[tmp, 8].Value = Func.ParseFloat(PriceVND); xlsSheet[tmp, 9].Value = Func.ParseFloat(SumUSD); xlsSheet[tmp, 10].Value = Func.ParseFloat(SumVND); xlsSheet[tmp, 11].Value = Func.ParseFloat(VatUSD); xlsSheet[tmp, 12].Value = Func.ParseFloat(VatVND); xlsSheet[tmp, 13].Value = Func.ParseFloat(LastPriceUSD); xlsSheet[tmp, 14].Value = Func.ParseFloat(LastPriceVND); XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 5); xlsSheet.MergedCells.Add(mrCell); for (int col = 1; col <= 14; col++) { xlsSheet[tmp, col].Style = xlstStyle; } LastSumPriceVND[3] += Func.ParseFloat(LastPriceVND); LastSumPriceUSD[3] += Func.ParseFloat(LastPriceUSD); } xlsSheet[35 + j, 13].Value = LastSumPriceUSD[3]; xlsSheet[35 + j, 14].Value = LastSumPriceVND[3]; } } ds = new DataSet(); //Dien //Xuất ra toàn bộ nội dung theo Trang sql = " SELECT A.DateFrom, A.DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, "; sql += " B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name "; sql += " FROM PaymentElecWater AS A INNER JOIN "; sql += " PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId"; sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0 and A.YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; sql += " Order by A.DateFrom, B.FromIndex"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; int line = 38 + j; //Phi dien XLCellRange mCell = new XLCellRange(line, line + 1, 1, 1); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 1, 2, 2); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 1, 3, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 1, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 1, 5, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 7, 8); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 9, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 11, 12); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 13, 14); xlsSheet.MergedCells.Add(mCell); for (int col = 1; col <= 14; col++) { xlsSheet[line, col].Style = xlstStyleH; } foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(41 + j); j++; } count++; int tmp = 40 + j; string Name = Func.ParseString(row["Name"]); string DateFrom = Func.ParseString(row["DateFrom"]); string DateTo = Func.ParseString(row["DateTo"]); string FromIndex = Func.ParseString(row["FromIndex"]); string ToIndex = Func.ParseString(row["ToIndex"]); string OtherFee01 = Func.ParseString(row["OtherFee01"]); string Mount = Func.ParseString(row["Mount"]); string PriceVND = Func.ParseString(row["PriceVND"]); string PriceUSD = Func.ParseString(row["PriceUSD"]); string VatUSD = Func.ParseString(row["VatUSD"]); string VatVND = Func.ParseString(row["VatVND"]); string SumVND = Func.ParseString(row["SumVND"]); string SumUSD = Func.ParseString(row["SumUSD"]); string LastPriceVND = Func.ParseString(row["LastPriceVND"]); string LastPriceUSD = Func.ParseString(row["LastPriceUSD"]); xlsSheet[tmp, 1].Value = DateFrom; xlsSheet[tmp, 2].Value = DateTo; xlsSheet[tmp, 3].Value = FromIndex; xlsSheet[tmp, 4].Value = ToIndex; xlsSheet[tmp, 5].Value = OtherFee01; xlsSheet[tmp, 6].Value = Mount; xlsSheet[tmp, 7].Value = Func.ParseFloat(PriceUSD); xlsSheet[tmp, 8].Value = Func.ParseFloat(PriceVND); xlsSheet[tmp, 9].Value = Func.ParseFloat(SumUSD); xlsSheet[tmp, 10].Value = Func.ParseFloat(SumVND); xlsSheet[tmp, 11].Value = Func.ParseFloat(VatUSD); xlsSheet[tmp, 12].Value = Func.ParseFloat(VatVND); xlsSheet[tmp, 13].Value = Func.ParseFloat(LastPriceUSD); xlsSheet[tmp, 14].Value = Func.ParseFloat(LastPriceVND); for (int col = 1; col <= 14; col++) { xlsSheet[tmp, col].Style = xlstStyle; } LastSumPriceVND[4] += Func.ParseFloat(LastPriceVND); LastSumPriceUSD[4] += Func.ParseFloat(LastPriceUSD); } xlsSheet[41 + j, 13].Value = LastSumPriceUSD[4]; xlsSheet[41 + j, 14].Value = LastSumPriceVND[4]; } } ////Water //sql = string.Empty; ////Xuất ra toàn bộ nội dung theo Trang //sql += " SELECT A.DateFrom, A.DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, "; //sql += " B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name "; //sql += " FROM PaymentElecWater AS A INNER JOIN "; //sql += " PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId"; //sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and A.YearMonth = '" + YearMonth + "'"; //sql += " Order by A.DateFrom, B.FromIndex"; ds = new DataSet(); //Service sql = string.Empty; sql = " SELECT * "; sql += " FROM PaymentService"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; sql += " Order By ServiceDate "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; int line = 44 + j; //Phi khác XLCellRange mCell = new XLCellRange(line, line + 1, 1, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 1, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 1, 5, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 7, 8); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 9, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 11, 12); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 13, 14); xlsSheet.MergedCells.Add(mCell); for (int col = 1; col <= 14; col++) { xlsSheet[line, col].Style = xlstStyleH; } foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(41 + j); j++; } count++; int tmp = 46 + j++; string Service = Func.ParseString(row["Service"]); string ServiceDateFrom = Func.ParseString(row["ServiceDateFrom"]); string ServiceDateTo = Func.ParseString(row["ServiceDateTo"]); string PriceVND = Func.ParseString(row["PriceVND"]); string PriceUSD = Func.ParseString(row["PriceUSD"]); string VatUSD = Func.ParseString(row["VatUSD"]); string VatVND = Func.ParseString(row["VatVND"]); string Mount = Func.ParseString(row["Mount"]); //string OtherFee02 = Func.ParseString(row["OtherFee02"]); string SumVND = Func.ParseString(row["SumVND"]); string SumUSD = Func.ParseString(row["SumUSD"]); string LastPriceVND = Func.ParseString(row["LastPriceVND"]); string LastPriceUSD = Func.ParseString(row["LastPriceUSD"]); xlsSheet[tmp, 1].Value = Service; xlsSheet[tmp, 4].Value = ServiceDateFrom; xlsSheet[tmp, 5].Value = ServiceDateTo; xlsSheet[tmp, 6].Value = Mount; xlsSheet[tmp, 7].Value = Func.ParseFloat(PriceUSD); xlsSheet[tmp, 8].Value = Func.ParseFloat(PriceVND); xlsSheet[tmp, 9].Value = Func.ParseFloat(SumUSD); xlsSheet[tmp, 10].Value = Func.ParseFloat(SumVND); xlsSheet[tmp, 11].Value = Func.ParseFloat(VatUSD); xlsSheet[tmp, 12].Value = Func.ParseFloat(VatVND); xlsSheet[tmp, 13].Value = Func.ParseFloat(LastPriceUSD); xlsSheet[tmp, 14].Value = Func.ParseFloat(LastPriceVND); XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); for (int col = 1; col <= 14; col++) { xlsSheet[tmp, col].Style = xlstStyle; } LastSumPriceVND[5] += Func.ParseFloat(LastPriceVND); LastSumPriceUSD[5] += Func.ParseFloat(LastPriceUSD); } xlsSheet[47 + j, 13].Value = LastSumPriceUSD[5]; xlsSheet[47 + j, 14].Value = LastSumPriceVND[5]; } } double AllSumVND = 0; float AllSumUSD = 0; for (int i = 0; i < 7; i++) { AllSumVND += LastSumPriceVND[i]; AllSumUSD += LastSumPriceUSD[i]; } string strMoney = Func.docso(Convert.ToInt32(AllSumVND)); xlsSheet[8, 0].Value = xlsSheet[8, 0].Value.ToString().Replace("{%HOP_DONG%}", contract.Substring(1)); xlsSheet[57 + j, 0].Value = xlsSheet[57 + j, 0].Value.ToString().Replace("{%TONG%}", Func.ParseString(AllSumVND)); xlsSheet[58 + j, 0].Value = xlsSheet[58 + j, 0].Value.ToString().Replace("{%TONG_CHU%}", strMoney.ToUpper()); //j--; //XLSheet source = xlbBook.Sheets["tpl"]; //for (int row = 22; row <= 26; row++) //{ // for (int col = 1; col <= 12; col++) // { // xlsSheet[row + j, col].Style = source[row, col].Style; // xlsSheet[row + j, col].Value = source[row, col].Value; // } //} //XLCellRange mrCell = new XLCellRange(22 + j, 23 + j, 1, 1); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 23 + j, 2, 2); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 23 + j, 3, 4); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 22 + j, 5, 6); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 22 + j, 7, 8); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 22 + j, 9, 10); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 22 + j, 11, 12); //xlsSheet.MergedCells.Add(mrCell); //ds = new DataSet(); //sql = " SELECT Service, Mount, PriceUSD, PriceVND, SumUSD, SumVND, VatUSD, VatVND, LastPriceUSD, LastPriceVND, Unit"; //sql += " FROM PaymentBookingService"; //sql += " WHERE BookingId = '" + hidId.Value + "' "; //j = 0; //using (SqlCommand cm = db.CreateCommand(sql)) //{ // SqlDataAdapter da = new SqlDataAdapter(cm); // da.Fill(ds); // if (ds != null) // { // DataTable dt = ds.Tables[0]; // foreach (DataRow rowType in dt.Rows) // { // if (j >= 1) // { // xlsSheet.Rows.Insert(19); // } // int tmp = 24 + j++; // string Service = rowType["Service"].ToString(); // string Mount = rowType["Mount"].ToString(); // string Unit = rowType["Unit"].ToString(); // string PriceUSD = rowType["PriceUSD"].ToString(); // string PriceVND = rowType["PriceVND"].ToString(); // string SumUSD = rowType["SumUSD"].ToString(); // string SumVND = rowType["SumVND"].ToString(); // string VatUSD = rowType["VatUSD"].ToString(); // string VatVND = rowType["VatVND"].ToString(); // string LastPriceUSD = rowType["LastPriceUSD"].ToString(); // string LastPriceVND = rowType["LastPriceVND"].ToString(); // xlsSheet[tmp, 1].Value = Service; // xlsSheet[tmp, 2].Value = Func.ParseFloat(Mount); // xlsSheet[tmp, 3].Value = Unit; // xlsSheet[tmp, 5].Value = Func.ParseFloat(PriceUSD); // xlsSheet[tmp, 6].Value = Func.ParseFloat(PriceVND); // xlsSheet[tmp, 7].Value = Func.ParseFloat(SumUSD); // xlsSheet[tmp, 8].Value = Func.ParseFloat(SumVND); // xlsSheet[tmp, 9].Value = Func.ParseFloat(VatUSD); // xlsSheet[tmp, 10].Value = Func.ParseFloat(VatVND); // xlsSheet[tmp, 11].Value = Func.ParseFloat(LastPriceUSD); // xlsSheet[tmp, 12].Value = Func.ParseFloat(LastPriceVND); // for (int col = 1; col <= 12; col++) // { // xlsSheet[tmp, col].Style = xlstStyle; // } // } // } //} xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } }
public void ViewMultiBoth(string lsYearmonth) { string[] strTmpYearMonth = lsYearmonth.Split(','); string maxYearMonth = ""; for (int l = 0; l < strTmpYearMonth.Length; l++) { string tmp = strTmpYearMonth[l]; if (maxYearMonth == "") maxYearMonth = tmp; if (maxYearMonth.CompareTo(tmp) < 0) maxYearMonth = tmp; } if (String.IsNullOrEmpty(lsYearmonth)) { mvMessage.AddError("Phải chọn ít nhất 1 tháng"); return; } //lsYearmonth = lsYearmonth.Substring(1); int rBillNo = 0; int cBillNo = 1; int rBillDate = 0; int cBillDate = 10; int rBillMonth = 2; int cBillMonth = 0; int rContact = 5; int cContact = 3; int rCustomer = 5; int cCustomer = 7; int rContract = 7; int cContract = 1; int rRate = 11; int cRate = 9; int rRateDate = 11; int cRateDate = 12; int rRent = 15; int rManager = 23; int rParking = 31; int rExtra = 39; int rElec = 47; int rWater = 55; int rService = 63; int rPaid = 70; int rDept = 77; int rOffice = 88; int cOffice = 1; int rPhone = 89; int cPhone = 1; int rBank = 88; int cBank = 7; int rAccountName = 89; int cAccountName = 7; int rAccount = 90; int cAccount = 7; int rSum = 81; int cSum = 12; int rSumVND = 80; int cSumVND = 12; int rSumRead = 82; int cSumRead = 13; int check = DbHelper.GetCount("Select count(*) from PaymentBillInfo Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + lblCustomerId.Text + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"); if (check == 0) { mvMessage.AddError("Xin vui lòng tạo hóa đơn trước khi xem"); return; } mvMessage.CheckRequired(txtBillDate, "Ngày xuất Hóa đơn là danh mục bắt buộc"); mvMessage.CheckRequired(txtBillNo, "Số Hóa đơn là danh mục bắt buộc"); mvMessage.CheckRequired(txtUsdExchange, "Tỉ giá USD-VN là danh mục bắt buộc"); mvMessage.CheckRequired(txtUsdExchangeDate, "Ngày tỉ giá là danh mục bắt buộc"); //ShowData(drpYear.SelectedValue + drpMonth.SelectedValue); xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BillTongQuat.xlsx"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))); } XLStyle xlstStyleC = new XLStyle(xlbBook); xlstStyleC.AlignHorz = XLAlignHorzEnum.Center; xlstStyleC.AlignVert = XLAlignVertEnum.Center; xlstStyleC.WordWrap = true; xlstStyleC.Font = new Font("Times New Roman", 10, FontStyle.Regular); xlstStyleC.SetBorderColor(Color.Black); xlstStyleC.BorderBottom = XLLineStyleEnum.Thin; xlstStyleC.BorderTop = XLLineStyleEnum.Thin; xlstStyleC.BorderLeft = XLLineStyleEnum.Thin; xlstStyleC.BorderRight = XLLineStyleEnum.Thin; xlstStyleC.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleC2 = new XLStyle(xlbBook); xlstStyleC2.AlignHorz = XLAlignHorzEnum.Center; xlstStyleC2.AlignVert = XLAlignVertEnum.Center; xlstStyleC2.WordWrap = true; xlstStyleC2.Font = new Font("Times New Roman", 10, FontStyle.Regular); xlstStyleC2.SetBorderColor(Color.Black); xlstStyleC2.BorderBottom = XLLineStyleEnum.Thin; xlstStyleC2.BorderTop = XLLineStyleEnum.Thin; xlstStyleC2.BorderLeft = XLLineStyleEnum.Thin; xlstStyleC2.BorderRight = XLLineStyleEnum.Thin; xlstStyleC2.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleC1 = new XLStyle(xlbBook); xlstStyleC1.AlignHorz = XLAlignHorzEnum.Center; xlstStyleC1.AlignVert = XLAlignVertEnum.Center; xlstStyleC1.WordWrap = true; xlstStyleC1.Font = new Font("Times New Roman", 10, FontStyle.Regular); xlstStyleC1.SetBorderColor(Color.Black); xlstStyleC1.BorderBottom = XLLineStyleEnum.Thin; xlstStyleC1.BorderTop = XLLineStyleEnum.Thin; xlstStyleC1.BorderLeft = XLLineStyleEnum.Thin; xlstStyleC1.BorderRight = XLLineStyleEnum.Thin; xlstStyleC1.Format = "#,##0.0_);(#,##0.0)"; XLStyle xlstStyleC0 = new XLStyle(xlbBook); xlstStyleC0.AlignHorz = XLAlignHorzEnum.Center; xlstStyleC0.AlignVert = XLAlignVertEnum.Center; xlstStyleC0.WordWrap = true; xlstStyleC0.Font = new Font("Times New Roman", 10, FontStyle.Regular); xlstStyleC0.SetBorderColor(Color.Black); xlstStyleC0.BorderBottom = XLLineStyleEnum.Thin; xlstStyleC0.BorderTop = XLLineStyleEnum.Thin; xlstStyleC0.BorderLeft = XLLineStyleEnum.Thin; xlstStyleC0.BorderRight = XLLineStyleEnum.Thin; xlstStyleC0.Format = "#,##0_);(#,##0)"; XLStyle xlstStyleCH = new XLStyle(xlbBook); xlstStyleCH.AlignHorz = XLAlignHorzEnum.Center; xlstStyleCH.AlignVert = XLAlignVertEnum.Center; xlstStyleCH.Font = new Font("Times New Roman", 10, FontStyle.Bold); xlstStyleCH.SetBorderColor(Color.Black); xlstStyleCH.BorderBottom = XLLineStyleEnum.Thin; xlstStyleCH.BorderTop = XLLineStyleEnum.Thin; xlstStyleCH.BorderLeft = XLLineStyleEnum.Thin; xlstStyleCH.BorderRight = XLLineStyleEnum.Thin; xlstStyleCH.WordWrap = true; XLStyle xlstStyleCSum2 = new XLStyle(xlbBook); xlstStyleCSum2.AlignHorz = XLAlignHorzEnum.Center; xlstStyleCSum2.AlignVert = XLAlignVertEnum.Center; xlstStyleCSum2.Font = new Font("Times New Roman", 10, FontStyle.Bold); xlstStyleCSum2.SetBorderColor(Color.Black); xlstStyleCSum2.BorderBottom = XLLineStyleEnum.Thin; xlstStyleCSum2.BorderTop = XLLineStyleEnum.Thin; xlstStyleCSum2.BorderLeft = XLLineStyleEnum.Thin; xlstStyleCSum2.BorderRight = XLLineStyleEnum.Thin; xlstStyleCSum2.WordWrap = true; xlstStyleCSum2.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleCSum1 = new XLStyle(xlbBook); xlstStyleCSum1.AlignHorz = XLAlignHorzEnum.Center; xlstStyleCSum1.AlignVert = XLAlignVertEnum.Center; xlstStyleCSum1.Font = new Font("Times New Roman", 10, FontStyle.Bold); xlstStyleCSum1.SetBorderColor(Color.Black); xlstStyleCSum1.BorderBottom = XLLineStyleEnum.Thin; xlstStyleCSum1.BorderTop = XLLineStyleEnum.Thin; xlstStyleCSum1.BorderLeft = XLLineStyleEnum.Thin; xlstStyleCSum1.BorderRight = XLLineStyleEnum.Thin; xlstStyleCSum1.WordWrap = true; xlstStyleCSum1.Format = "#,##0_);(#,##0)"; XLStyle xlstStyleCSum0 = new XLStyle(xlbBook); xlstStyleCSum0.AlignHorz = XLAlignHorzEnum.Center; xlstStyleCSum0.AlignVert = XLAlignVertEnum.Center; xlstStyleCSum0.Font = new Font("Times New Roman", 10, FontStyle.Bold); xlstStyleCSum0.SetBorderColor(Color.Black); xlstStyleCSum0.BorderBottom = XLLineStyleEnum.Thin; xlstStyleCSum0.BorderTop = XLLineStyleEnum.Thin; xlstStyleCSum0.BorderLeft = XLLineStyleEnum.Thin; xlstStyleCSum0.BorderRight = XLLineStyleEnum.Thin; xlstStyleCSum0.WordWrap = true; xlstStyleCSum0.Format = "#,##0_);(#,##0)"; XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.AlignVert = XLAlignVertEnum.Center; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("Times New Roman", 10, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; xlstStyle.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyle2 = new XLStyle(xlbBook); xlstStyle2.AlignHorz = XLAlignHorzEnum.Right; xlstStyle2.AlignVert = XLAlignVertEnum.Center; xlstStyle2.WordWrap = true; xlstStyle2.Font = new Font("Times New Roman", 10, FontStyle.Regular); xlstStyle2.SetBorderColor(Color.Black); xlstStyle2.BorderBottom = XLLineStyleEnum.Thin; xlstStyle2.BorderTop = XLLineStyleEnum.Thin; xlstStyle2.BorderLeft = XLLineStyleEnum.Thin; xlstStyle2.BorderRight = XLLineStyleEnum.Thin; xlstStyle2.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyle1 = new XLStyle(xlbBook); xlstStyle1.AlignHorz = XLAlignHorzEnum.Right; xlstStyle1.AlignVert = XLAlignVertEnum.Center; xlstStyle1.WordWrap = true; xlstStyle1.Font = new Font("Times New Roman", 10, FontStyle.Regular); xlstStyle1.SetBorderColor(Color.Black); xlstStyle1.BorderBottom = XLLineStyleEnum.Thin; xlstStyle1.BorderTop = XLLineStyleEnum.Thin; xlstStyle1.BorderLeft = XLLineStyleEnum.Thin; xlstStyle1.BorderRight = XLLineStyleEnum.Thin; xlstStyle1.Format = "#,##0.0_);(#,##0.0)"; XLStyle xlstStyle0 = new XLStyle(xlbBook); xlstStyle0.AlignHorz = XLAlignHorzEnum.Right; xlstStyle0.AlignVert = XLAlignVertEnum.Center; xlstStyle0.WordWrap = true; xlstStyle0.Font = new Font("Times New Roman", 10, FontStyle.Regular); xlstStyle0.SetBorderColor(Color.Black); xlstStyle0.BorderBottom = XLLineStyleEnum.Thin; xlstStyle0.BorderTop = XLLineStyleEnum.Thin; xlstStyle0.BorderLeft = XLLineStyleEnum.Thin; xlstStyle0.BorderRight = XLLineStyleEnum.Thin; xlstStyle0.Format = "#,##0_);(#,##0)"; XLStyle xlstStyleH = new XLStyle(xlbBook); xlstStyleH.AlignHorz = XLAlignHorzEnum.Center; xlstStyleH.AlignVert = XLAlignVertEnum.Center; xlstStyleH.Font = new Font("Times New Roman", 10, FontStyle.Bold); xlstStyleH.SetBorderColor(Color.Black); xlstStyleH.BorderBottom = XLLineStyleEnum.Thin; xlstStyleH.BorderTop = XLLineStyleEnum.Thin; xlstStyleH.BorderLeft = XLLineStyleEnum.Thin; xlstStyleH.BorderRight = XLLineStyleEnum.Thin; xlstStyleH.WordWrap = true; XLStyle xlstStyleSum2 = new XLStyle(xlbBook); xlstStyleSum2.AlignHorz = XLAlignHorzEnum.Right; xlstStyleSum2.AlignVert = XLAlignVertEnum.Center; xlstStyleSum2.Font = new Font("Times New Roman", 10, FontStyle.Bold); xlstStyleSum2.SetBorderColor(Color.Black); xlstStyleSum2.BorderBottom = XLLineStyleEnum.Thin; xlstStyleSum2.BorderTop = XLLineStyleEnum.Thin; xlstStyleSum2.BorderLeft = XLLineStyleEnum.Thin; xlstStyleSum2.BorderRight = XLLineStyleEnum.Thin; xlstStyleSum2.WordWrap = true; xlstStyleSum2.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleSum1 = new XLStyle(xlbBook); xlstStyleSum1.AlignHorz = XLAlignHorzEnum.Right; xlstStyleSum1.AlignVert = XLAlignVertEnum.Center; xlstStyleSum1.Font = new Font("Times New Roman", 10, FontStyle.Bold); xlstStyleSum1.SetBorderColor(Color.Black); xlstStyleSum1.BorderBottom = XLLineStyleEnum.Thin; xlstStyleSum1.BorderTop = XLLineStyleEnum.Thin; xlstStyleSum1.BorderLeft = XLLineStyleEnum.Thin; xlstStyleSum1.BorderRight = XLLineStyleEnum.Thin; xlstStyleSum1.WordWrap = true; xlstStyleSum1.Format = "#,##0_);(#,##0)"; XLStyle xlstStyleSum0 = new XLStyle(xlbBook); xlstStyleSum0.AlignHorz = XLAlignHorzEnum.Right; xlstStyleSum0.AlignVert = XLAlignVertEnum.Center; xlstStyleSum0.Font = new Font("Times New Roman", 10, FontStyle.Bold); xlstStyleSum0.SetBorderColor(Color.Black); xlstStyleSum0.BorderBottom = XLLineStyleEnum.Thin; xlstStyleSum0.BorderTop = XLLineStyleEnum.Thin; xlstStyleSum0.BorderLeft = XLLineStyleEnum.Thin; xlstStyleSum0.BorderRight = XLLineStyleEnum.Thin; xlstStyleSum0.WordWrap = true; xlstStyleSum0.Format = "#,##0_);(#,##0)"; if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\Bill")) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\Bill")); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\Bill\Bill_" + lblCustomerId.Text + "_" + strDT + ".xlsx"; string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/Bill/Bill_" + lblCustomerId.Text + "_" + strDT + ".xlsx"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); xlsSheet = xlbBook.Sheets["TongHop"]; xlsSheetEn = xlbBook.Sheets["TongHop_En"]; //Bill No xlsSheet[rBillNo, cBillNo].Value = xlsSheet[rBillNo, cBillNo].Value.ToString().Replace("{%BILL_NO%}", txtBillNo.Text); xlsSheetEn[rBillNo, cBillNo].Value = xlsSheetEn[rBillNo, cBillNo].Value.ToString().Replace("{%BILL_NO%}", txtBillNo.Text); //Ngay Thang Nam DateTime dtime = DateTime.Today; string strTmp = xlsSheet[rBillDate, cBillDate].Value.ToString().Replace("{%NGAY%}", dtime.ToString("dd")); strTmp = strTmp.Replace("{%THANG%}", dtime.ToString("MM")); xlsSheet[rBillDate, cBillDate].Value = strTmp.Replace("{%NAM%}", dtime.ToString("yyyy")); strTmp = xlsSheetEn[rBillDate, cBillDate].Value.ToString().Replace("{%NGAY%}", dtime.ToString("dd")); strTmp = strTmp.Replace("{%THANG%}", dtime.ToString("MM")); xlsSheetEn[rBillDate, cBillDate].Value = strTmp.Replace("{%NAM%}", dtime.ToString("yyyy")); //Nam xlsSheet[rBillMonth, cBillMonth].Value = xlsSheet[rBillMonth, cBillMonth].Value.ToString().Replace("{%NAM_THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); xlsSheetEn[rBillMonth, cBillMonth].Value = xlsSheetEn[rBillMonth, cBillMonth].Value.ToString().Replace("{%NAM_THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); using (SqlDatabase db = new SqlDatabase()) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT Name, ContactName"; sql += " FROM Customer"; sql += " WHERE CustomerId = '" + lblCustomerId.Text + "' "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string Name = rowType[0].ToString(); string ContactName = rowType[1].ToString(); //Customer xlsSheet[rCustomer, cCustomer].Value = xlsSheet[rCustomer, cCustomer].Value.ToString().Replace("{%TEN_CONG_TY%}", Name); xlsSheetEn[rCustomer, cCustomer].Value = xlsSheetEn[rCustomer, cCustomer].Value.ToString().Replace("{%TEN_CONG_TY%}", Name); //Contact xlsSheet[rContact, cContact].Value = xlsSheet[rContact, cContact].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName); xlsSheetEn[rContact, cContact].Value = xlsSheetEn[rContact, cContact].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName); } } } Hashtable contractIdLst = new Hashtable(); string contract = ""; ds = new DataSet(); sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone"; sql += " FROM Mst_Building"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string Bank = rowType["Bank"].ToString(); string Account = rowType["Account"].ToString(); string AccountName = rowType["AccountName"].ToString(); string Office = rowType["Office"].ToString(); string OfficeAddress = rowType["OfficeAddress"].ToString(); string OfficePhone = rowType["OfficePhone"].ToString(); xlsSheet[rOffice, cOffice].Value = xlsSheet[rOffice, cOffice].Value.ToString().Replace("{%VAN_PHONG%}", Office); xlsSheet[rPhone, cPhone].Value = xlsSheet[rPhone, cPhone].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone); xlsSheet[rBank, cBank].Value = xlsSheet[rBank, cBank].Value.ToString().Replace("{%NGAN_HANG%}", Bank); xlsSheet[rAccountName, cAccountName].Value = xlsSheet[rAccountName, cAccountName].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName); xlsSheet[rAccount, cAccount].Value = xlsSheet[rAccount, cAccount].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account); xlsSheetEn[rOffice, cOffice].Value = xlsSheetEn[rOffice, cOffice].Value.ToString().Replace("{%VAN_PHONG%}", Office); xlsSheetEn[rPhone, cPhone].Value = xlsSheetEn[rPhone, cPhone].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone); xlsSheetEn[rBank, cBank].Value = xlsSheetEn[rBank, cBank].Value.ToString().Replace("{%NGAN_HANG%}", Bank); xlsSheetEn[rAccountName, cAccountName].Value = xlsSheetEn[rAccountName, cAccountName].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName); xlsSheetEn[rAccount, cAccount].Value = xlsSheetEn[rAccount, cAccount].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account); } } } xlsSheet[rRate, cRate].Value = xlsSheet[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", Func.FormatNumber_New(txtUsdExchange.Text)); xlsSheet[rRateDate, cRateDate].Value = xlsSheet[rRateDate, cRateDate].Value.ToString().Replace("{%NGAY_AP_DUNG%}", txtUsdExchangeDate.Text); xlsSheetEn[rRate, cRate].Value = xlsSheetEn[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", Func.FormatNumber_New(txtUsdExchange.Text)); xlsSheetEn[rRateDate, cRateDate].Value = xlsSheetEn[rRateDate, cRateDate].Value.ToString().Replace("{%NGAY_AP_DUNG%}", txtUsdExchangeDate.Text); //Thue phong ds = new DataSet(); sql = " Select A.*, B.ContractDate"; sql += " FROM PaymentRoom A, RentContract B"; sql += " WHERE A.ContractId = B.ContractId and A.BuildingId = B.BuildingId and A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and A.YearMonth in (" + lsYearmonth + ")"; sql += " and A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and A.YearMonth in (" + lsYearmonth + ")"; int sumRow = 0; int j = 0; decimal[] LastSumPriceVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; decimal[] LastSumPriceUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; decimal PaidPriceVND = 0; decimal PaidPriceUSD = 0; int line = 0; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rRent - 3 + j; XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; int k = 0; foreach (DataRow rowType in dt.Rows) { decimal tmp01 = Convert.ToDecimal(rowType["LastRentSumUSD"]); decimal tmp02 = Convert.ToDecimal(rowType["LastRentSumVND"]); string ContractId = Func.ParseString(rowType["ContractId"]); string ContractNo = Func.ParseString(rowType["ContractNo"]); string YearMonth = Func.ParseString(rowType["YearMonth"]); string Area = Func.ParseString(rowType["Area"]); string Name = Func.ParseString(rowType["Name"]); string Regional = Func.ParseString(rowType["Regional"]); string Floor = Func.ParseString(rowType["Floor"]); string BeginContract = Func.ParseString(rowType["ContractDate"]); if (!contractIdLst.ContainsKey(ContractId + "(" + Func.FormatDMY(BeginContract) + ")")) { contractIdLst.Add(ContractId + "(" + Func.FormatDMY(BeginContract) + ")", ContractNo + "(" + Func.FormatDMY(BeginContract) + ")"); contract += ";" + ContractNo + "(" + Func.FormatDMY(BeginContract) + ")"; } if (tmp01 > 0 || tmp02 > 0) { if (count >= 1) { xlsSheet.Rows.Insert(rRent + 1 + j); xlsSheetEn.Rows.Insert(rRent + 1 + j); j++; } count++; int tmp = rRent + j; xlsSheet[tmp, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); xlsSheet[tmp, 4].Value = rowType["Area"]; xlsSheet[tmp, 6].Value = rowType["MonthRentPriceUSD"]; xlsSheet[tmp, 7].Value = rowType["MonthRentPriceVND"]; xlsSheet[tmp, 8].Value = rowType["MonthRentSumUSD"]; xlsSheet[tmp, 9].Value = rowType["MonthRentSumVND"]; xlsSheet[tmp, 10].Value = rowType["VatRentPriceUSD"]; xlsSheet[tmp, 11].Value = rowType["VatRentPriceVND"]; xlsSheet[tmp, 12].Value = rowType["LastRentSumUSD"]; xlsSheet[tmp, 13].Value = rowType["LastRentSumVND"]; XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheet.MergedCells.Add(mrCell); ////EN xlsSheetEn[tmp, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); xlsSheetEn[tmp, 4].Value = rowType["Area"]; xlsSheetEn[tmp, 6].Value = rowType["MonthRentPriceUSD"]; xlsSheetEn[tmp, 7].Value = rowType["MonthRentPriceVND"]; xlsSheetEn[tmp, 8].Value = rowType["MonthRentSumUSD"]; xlsSheetEn[tmp, 9].Value = rowType["MonthRentSumVND"]; xlsSheetEn[tmp, 10].Value = rowType["VatRentPriceUSD"]; xlsSheetEn[tmp, 11].Value = rowType["VatRentPriceVND"]; xlsSheetEn[tmp, 12].Value = rowType["LastRentSumUSD"]; xlsSheetEn[tmp, 13].Value = rowType["LastRentSumVND"]; mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheetEn.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheetEn.MergedCells.Add(mrCell); for (int col = 1; col <= 13; col++) { xlsSheet[tmp, col].Style = xlstStyle; xlsSheetEn[tmp, col].Style = xlstStyle; } ////EN //Format //xlsSheet[tmp, 1].Style = xlstStyle2; //xlsSheet[tmp, 2].Style = xlstStyle2; //xlsSheet[tmp, 3].Style = xlstStyle2; xlsSheet[tmp, 4].Style = xlstStyleC1; xlsSheet[tmp, 5].Style = xlstStyleC1; xlsSheet[tmp, 6].Style = xlstStyle1; xlsSheet[tmp, 7].Style = xlstStyle0; xlsSheet[tmp, 8].Style = xlstStyle1; xlsSheet[tmp, 9].Style = xlstStyle0; xlsSheet[tmp, 10].Style = xlstStyle1; xlsSheet[tmp, 11].Style = xlstStyle0; xlsSheet[tmp, 12].Style = xlstStyle1; xlsSheet[tmp, 13].Style = xlstStyle0; //////////// //xlsSheetEn[tmp, 1].Style = xlstStyle2; //xlsSheetEn[tmp, 2].Style = xlstStyle2; //xlsSheetEn[tmp, 3].Style = xlstStyle2; xlsSheetEn[tmp, 4].Style = xlstStyleC1; xlsSheetEn[tmp, 5].Style = xlstStyleC1; xlsSheetEn[tmp, 6].Style = xlstStyle1; xlsSheetEn[tmp, 7].Style = xlstStyle0; xlsSheetEn[tmp, 8].Style = xlstStyle1; xlsSheetEn[tmp, 9].Style = xlstStyle0; xlsSheetEn[tmp, 10].Style = xlstStyle1; xlsSheetEn[tmp, 11].Style = xlstStyle0; xlsSheetEn[tmp, 12].Style = xlstStyle1; xlsSheetEn[tmp, 13].Style = xlstStyle0; LastSumPriceVND[0] += Convert.ToDecimal(rowType["LastRentSumVND"]); LastSumPriceUSD[0] += Convert.ToDecimal(rowType["LastRentSumUSD"]); } else { k++; } } mCell = new XLCellRange(rRent + 1 + j, rRent + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); xlsSheet[rRent + 1 + j, 12].Value = LastSumPriceUSD[0]; xlsSheet[rRent + 1 + j, 13].Value = LastSumPriceVND[0]; xlsSheetEn[rRent + 1 + j, 12].Value = LastSumPriceUSD[0]; xlsSheetEn[rRent + 1 + j, 13].Value = LastSumPriceVND[0]; //Format xlsSheet[rRent + 1 + j, 12].Style = xlstStyleSum1; xlsSheet[rRent + 1 + j, 13].Style = xlstStyleSum0; xlsSheetEn[rRent + 1 + j, 12].Style = xlstStyleSum1; xlsSheetEn[rRent + 1 + j, 13].Style = xlstStyleSum0; //for (int row = rRent + sumRow; row <= rRent + dt.Rows.Count - k; row++) //{ // for (int col = 1; col <= 13; col++) // { // xlsSheet[row, col].Style = xlstStyle; // xlsSheetEn[row, col].Style = xlstStyle; // } //} sumRow += dt.Rows.Count - 1 - k; //////////////////////// //for (int col = 1; col <= 13; col++) //{ // xlsSheet[rRent + 1 + j, col].Style = xlstStyleSum; // xlsSheetEn[rRent + 1 + j, col].Style = xlstStyleSum; //} line = rManager - 3 + j; mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); ////En mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheetEn.MergedCells.Add(mCell); ////En k = 0; count = 0; foreach (DataRow row in dt.Rows) { decimal tmp01 = Convert.ToDecimal(row["LastManagerSumUSD"]); decimal tmp02 = Convert.ToDecimal(row["LastManagerSumVND"]); if (tmp01 > 0 || tmp02 > 0) { if (count >= 1) { xlsSheet.Rows.Insert(rManager + 1 + j); xlsSheetEn.Rows.Insert(rManager + 1 + j); j++; } count++; int tmp = rManager + j; string YearMonth = Func.ParseString(row["YearMonth"]); string Area = Func.ParseString(row["Area"]); string Name = Func.ParseString(row["Name"]); xlsSheet[tmp, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); xlsSheet[tmp, 4].Value = row["Area"]; xlsSheet[tmp, 6].Value = row["MonthManagerPriceUSD"]; xlsSheet[tmp, 7].Value = row["MonthManagerPriceVND"]; xlsSheet[tmp, 8].Value = row["MonthManagerSumUSD"]; xlsSheet[tmp, 9].Value = row["MonthManagerSumVND"]; xlsSheet[tmp, 10].Value = row["VatManagerPriceUSD"]; xlsSheet[tmp, 11].Value = row["VatManagerPriceVND"]; xlsSheet[tmp, 12].Value = row["LastManagerSumUSD"]; xlsSheet[tmp, 13].Value = row["LastManagerSumVND"]; XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheet.MergedCells.Add(mrCell); ////En xlsSheetEn[tmp, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); xlsSheetEn[tmp, 4].Value = row["Area"]; xlsSheetEn[tmp, 6].Value = row["MonthManagerPriceUSD"]; xlsSheetEn[tmp, 7].Value = row["MonthManagerPriceVND"]; xlsSheetEn[tmp, 8].Value = row["MonthManagerSumUSD"]; xlsSheetEn[tmp, 9].Value = row["MonthManagerSumVND"]; xlsSheetEn[tmp, 10].Value = row["VatManagerPriceUSD"]; xlsSheetEn[tmp, 11].Value = row["VatManagerPriceVND"]; xlsSheetEn[tmp, 12].Value = row["LastManagerSumUSD"]; xlsSheetEn[tmp, 13].Value = row["LastManagerSumVND"]; for (int col = 1; col <= 13; col++) { xlsSheet[tmp, col].Style = xlstStyle; xlsSheetEn[tmp, col].Style = xlstStyle; } //format //xlsSheetEn[tmp, 1].Style = xlstStyle2; //xlsSheetEn[tmp, 2].Style = xlstStyle2; //xlsSheetEn[tmp, 3].Style = xlstStyle2; xlsSheetEn[tmp, 4].Style = xlstStyleC1; xlsSheetEn[tmp, 5].Style = xlstStyle2; xlsSheetEn[tmp, 6].Style = xlstStyle1; xlsSheetEn[tmp, 7].Style = xlstStyle0; xlsSheetEn[tmp, 8].Style = xlstStyle1; xlsSheetEn[tmp, 9].Style = xlstStyle0; xlsSheetEn[tmp, 10].Style = xlstStyle1; xlsSheetEn[tmp, 11].Style = xlstStyle0; xlsSheetEn[tmp, 12].Style = xlstStyle1; xlsSheetEn[tmp, 13].Style = xlstStyle0; //// //xlsSheet[tmp, 1].Style = xlstStyle2; //xlsSheet[tmp, 2].Style = xlstStyle2; //xlsSheet[tmp, 3].Style = xlstStyle2; xlsSheet[tmp, 4].Style = xlstStyleC1; xlsSheet[tmp, 5].Style = xlstStyle2; xlsSheet[tmp, 6].Style = xlstStyle1; xlsSheet[tmp, 7].Style = xlstStyle0; xlsSheet[tmp, 8].Style = xlstStyle1; xlsSheet[tmp, 9].Style = xlstStyle0; xlsSheet[tmp, 10].Style = xlstStyle1; xlsSheet[tmp, 11].Style = xlstStyle0; xlsSheet[tmp, 12].Style = xlstStyle1; xlsSheet[tmp, 13].Style = xlstStyle0; mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheetEn.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheetEn.MergedCells.Add(mrCell); ////En LastSumPriceVND[1] += Convert.ToDecimal(row["LastManagerSumVND"]); LastSumPriceUSD[1] += Convert.ToDecimal(row["LastManagerSumUSD"]); } else { k++; } } mCell = new XLCellRange(rManager + 1 + j, rManager + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); xlsSheet[rManager + 1 + j, 12].Value = LastSumPriceUSD[1]; xlsSheet[rManager + 1 + j, 13].Value = LastSumPriceVND[1]; xlsSheetEn[rManager + 1 + j, 12].Value = LastSumPriceUSD[1]; xlsSheetEn[rManager + 1 + j, 13].Value = LastSumPriceVND[1]; xlsSheet[rManager + 1 + j, 12].Style = xlstStyleSum1; xlsSheet[rManager + 1 + j, 13].Style = xlstStyleSum0; xlsSheetEn[rManager + 1 + j, 12].Style = xlstStyleSum1; xlsSheetEn[rManager + 1 + j, 13].Style = xlstStyleSum0; //for (int row = rManager + sumRow; row <= rManager + sumRow + dt.Rows.Count - k; row++) //{ // for (int col = 1; col <= 13; col++) // { // xlsSheet[row, col].Style = xlstStyle; // xlsSheetEn[row, col].Style = xlstStyle; // } //} //for (int col = 1; col <= 13; col++) //{ // xlsSheet[rManager + 1 + j, col].Style = xlstStyleSum; // xlsSheetEn[rManager + 1 + j, col].Style = xlstStyleSum; //} sumRow += dt.Rows.Count - 1 - k; } } ds = new DataSet(); //Xuất ra toàn bộ nội dung theo Trang sql = " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVND, PriceUSD, SUM(VatVND) AS VatVND,SUM(VatUSD) AS VatUSD, SUM(SumVND) AS SumVND, SUM(SumUSD) AS SumUSD, SUM(LastPriceVND) AS LastPriceVND"; sql += " , SUM(LastPriceUSD) AS LastPriceUSD"; sql += " FROM dbo.PaymentParking"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")"; sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat, daysParking"; sql += " HAVING (SUM(LastPriceVND) >0 or SUM(LastPriceUSD) >0)"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rParking - 3 + j; XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); ////En mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheetEn.MergedCells.Add(mCell); ////En if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rParking + 1 + j); xlsSheetEn.Rows.Insert(rParking + 1 + j); j++; } count++; int tmp = rParking + j; string Num = Func.ParseString(row["Num"]); string TariffsParkingName = Func.ParseString(row["TariffsParkingName"]); xlsSheet[tmp, 1].Value = TariffsParkingName; xlsSheet[tmp, 4].Value = Num; xlsSheet[tmp, 6].Value = row["PriceUSD"]; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["SumUSD"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 10].Value = row["VatUSD"]; xlsSheet[tmp, 11].Value = row["VatVND"]; xlsSheet[tmp, 12].Value = row["LastPriceUSD"]; xlsSheet[tmp, 13].Value = row["LastPriceVND"]; XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheet.MergedCells.Add(mrCell); /////En xlsSheetEn[tmp, 1].Value = TariffsParkingName; xlsSheetEn[tmp, 4].Value = Num; xlsSheetEn[tmp, 6].Value = row["PriceUSD"]; xlsSheetEn[tmp, 7].Value = row["PriceVND"]; xlsSheetEn[tmp, 8].Value = row["SumUSD"]; xlsSheetEn[tmp, 9].Value = row["SumVND"]; xlsSheetEn[tmp, 10].Value = row["VatUSD"]; xlsSheetEn[tmp, 11].Value = row["VatVND"]; xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"]; xlsSheetEn[tmp, 13].Value = row["LastPriceVND"]; for (int col = 1; col <= 13; col++) { xlsSheet[tmp, col].Style = xlstStyle; xlsSheetEn[tmp, col].Style = xlstStyle; } ////EN //Format xlsSheetEn[tmp, 4].Style = xlstStyleC1; xlsSheetEn[tmp, 5].Style = xlstStyleC1; //////////////// xlsSheetEn[tmp, 6].Style = xlstStyle1; xlsSheetEn[tmp, 7].Style = xlstStyle0; xlsSheetEn[tmp, 8].Style = xlstStyle1; xlsSheetEn[tmp, 9].Style = xlstStyle0; xlsSheetEn[tmp, 10].Style = xlstStyle1; xlsSheetEn[tmp, 11].Style = xlstStyle0; xlsSheetEn[tmp, 12].Style = xlstStyle1; xlsSheetEn[tmp, 13].Style = xlstStyle0; xlsSheet[tmp, 4].Style = xlstStyleC1; xlsSheet[tmp, 5].Style = xlstStyleC1; ////// xlsSheet[tmp, 6].Style = xlstStyle1; xlsSheet[tmp, 7].Style = xlstStyle0; xlsSheet[tmp, 8].Style = xlstStyle1; xlsSheet[tmp, 9].Style = xlstStyle0; xlsSheet[tmp, 10].Style = xlstStyle1; xlsSheet[tmp, 11].Style = xlstStyle0; xlsSheet[tmp, 12].Style = xlstStyle1; xlsSheet[tmp, 13].Style = xlstStyle0; mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheetEn.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheetEn.MergedCells.Add(mrCell); /////En LastSumPriceVND[2] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[2] += Convert.ToDecimal(row["LastPriceUSD"]); } xlsSheet[rParking + 1 + j, 12].Value = LastSumPriceUSD[2]; xlsSheet[rParking + 1 + j, 13].Value = LastSumPriceVND[2]; mCell = new XLCellRange(rParking + 1 + j, rParking + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); /////En xlsSheetEn[rParking + 1 + j, 12].Value = LastSumPriceUSD[2]; xlsSheetEn[rParking + 1 + j, 13].Value = LastSumPriceVND[2]; ///// xlsSheetEn[rParking + 1 + j, 12].Style = xlstStyleSum1; xlsSheetEn[rParking + 1 + j, 13].Style = xlstStyleSum0; xlsSheet[rParking + 1 + j, 12].Style = xlstStyleSum1; xlsSheet[rParking + 1 + j, 13].Style = xlstStyleSum0; mCell = new XLCellRange(rParking + 1 + j, rParking + 1 + j, 1, 11); xlsSheetEn.MergedCells.Add(mCell); /////En //for (int row = rParking + sumRow; row <= rParking + sumRow + dt.Rows.Count; row++) //{ // for (int col = 1; col <= 13; col++) // { // xlsSheet[row, col].Style = xlstStyle; // xlsSheetEn[row, col].Style = xlstStyle; // } //} //for (int col = 1; col <= 13; col++) //{ // xlsSheet[rParking + 1 + j, col].Style = xlstStyleSum; // xlsSheetEn[rParking + 1 + j, col].Style = xlstStyleSum; //} sumRow += dt.Rows.Count - 1; } } ds = new DataSet(); sql = "SELECT id"; sql += " ,YearMonth,BuildingId,CustomerId,RoomId,ExtraHour,VAT,OtherFee01,OtherFee02"; sql += " ,PriceUSD,PriceVND,VatUSD,VatVND,SumUSD,SumVND,IsNull(LastPriceUSD,0) LastPriceUSD ,IsNull(LastPriceVND,0) LastPriceVND "; sql += " ,RentArea,dbo.fnDateTime(FromWD) BeginDate,dbo.fnDateTime(EndWD) EndDate,ExtratimeType"; sql += " FROM PaymentExtraTimeMonth"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rExtra - 3 + j; //Phi dien XLCellRange mCell = new XLCellRange(line, line + 2, 1, 2); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 1, 3, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); /////En mCell = new XLCellRange(line, line + 2, 1, 2); xlsSheetEn.MergedCells.Add(mCell); /////En mCell = new XLCellRange(line, line + 1, 3, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 4, 4); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheetEn.MergedCells.Add(mCell); /////En if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rExtra + 1 + j); xlsSheetEn.Rows.Insert(rExtra + 1 + j); j++; } count++; int tmp = rExtra + j; string ExtraHour = Func.ParseString(row["ExtraHour"]); string BeginDate = Func.ParseString(row["BeginDate"]); string EndDate = Func.ParseString(row["EndDate"]); string ExtratimeType = Func.ParseString(row["ExtratimeType"]); xlsSheet[tmp, 1].Value = BeginDate + "~" + EndDate; xlsSheet[tmp, 3].Value = row["RentArea"]; xlsSheet[tmp, 5].Value = ExtraHour; xlsSheet[tmp, 4].Value = "Diện tích"; if ("0".Equals(ExtratimeType)) { xlsSheet[tmp, 4].Value = "m2*h"; } xlsSheet[tmp, 6].Value = row["PriceUSD"]; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["SumUSD"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 10].Value = row["VatUSD"]; xlsSheet[tmp, 11].Value = row["VatVND"]; xlsSheet[tmp, 12].Value = row["LastPriceUSD"]; xlsSheet[tmp, 13].Value = row["LastPriceVND"]; LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[3] += Convert.ToDecimal(row["LastPriceUSD"]); XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 2); xlsSheet.MergedCells.Add(mrCell); xlsSheetEn.MergedCells.Add(mrCell); //////En xlsSheetEn[tmp, 1].Value = BeginDate + "~" + EndDate; xlsSheetEn[tmp, 5].Value = ExtraHour; xlsSheetEn[tmp, 3].Value = row["RentArea"]; xlsSheetEn[tmp, 4].Value = "Area"; if ("0".Equals(ExtratimeType)) { xlsSheetEn[tmp, 4].Value = "m2*h"; } xlsSheetEn[tmp, 6].Value = row["PriceUSD"]; xlsSheetEn[tmp, 7].Value = row["PriceVND"]; xlsSheetEn[tmp, 8].Value = row["SumUSD"]; xlsSheetEn[tmp, 9].Value = row["SumVND"]; xlsSheetEn[tmp, 10].Value = row["VatUSD"]; xlsSheetEn[tmp, 11].Value = row["VatVND"]; xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"]; xlsSheetEn[tmp, 13].Value = row["LastPriceVND"]; for (int col = 1; col <= 13; col++) { xlsSheet[tmp, col].Style = xlstStyle; xlsSheetEn[tmp, col].Style = xlstStyle; } ////EN //Format xlsSheetEn[tmp, 3].Style = xlstStyleC1; xlsSheetEn[tmp, 4].Style = xlstStyleC1; xlsSheetEn[tmp, 5].Style = xlstStyleC1; ///////////////////// xlsSheetEn[tmp, 6].Style = xlstStyle1; xlsSheetEn[tmp, 7].Style = xlstStyle0; xlsSheetEn[tmp, 8].Style = xlstStyle1; xlsSheetEn[tmp, 9].Style = xlstStyle0; xlsSheetEn[tmp, 10].Style = xlstStyle1; xlsSheetEn[tmp, 11].Style = xlstStyle0; xlsSheetEn[tmp, 12].Style = xlstStyle1; xlsSheetEn[tmp, 13].Style = xlstStyle0; ///////////////////// xlsSheet[tmp, 4].Style = xlstStyleC1; xlsSheet[tmp, 5].Style = xlstStyleC1; xlsSheet[tmp, 6].Style = xlstStyle1; xlsSheet[tmp, 7].Style = xlstStyle0; xlsSheet[tmp, 8].Style = xlstStyle1; xlsSheet[tmp, 9].Style = xlstStyle0; xlsSheet[tmp, 10].Style = xlstStyle1; xlsSheet[tmp, 11].Style = xlstStyle0; xlsSheet[tmp, 12].Style = xlstStyle1; xlsSheet[tmp, 13].Style = xlstStyle0; //LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]); //LastSumPriceUSD[3] += Convert.ToDecimal(row["LastPriceUSD"]); mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheetEn.MergedCells.Add(mrCell); //////En } mCell = new XLCellRange(rExtra + 1 + j, rExtra + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); xlsSheet[rExtra + 1 + j, 12].Value = LastSumPriceUSD[3]; xlsSheet[rExtra + 1 + j, 13].Value = LastSumPriceVND[3]; xlsSheetEn[rExtra + 1 + j, 12].Value = LastSumPriceUSD[3]; xlsSheetEn[rExtra + 1 + j, 13].Value = LastSumPriceVND[3]; xlsSheetEn[rExtra + 1 + j, 12].Style = xlstStyleSum1; xlsSheetEn[rExtra + 1 + j, 13].Style = xlstStyleSum0; xlsSheet[rExtra + 1 + j, 12].Style = xlstStyleSum1; xlsSheet[rExtra + 1 + j, 13].Style = xlstStyleSum0; //for (int row = rExtra + sumRow; row <= rExtra + sumRow + dt.Rows.Count; row++) //{ // for (int col = 1; col <= 13; col++) // { // xlsSheet[row, col].Style = xlstStyle; // xlsSheetEn[row, col].Style = xlstStyle; // } //} //for (int col = 1; col <= 13; col++) //{ // xlsSheet[rExtra + 1 + j, col].Style = xlstStyleSum; // xlsSheetEn[rExtra + 1 + j, col].Style = xlstStyleSum; //} sumRow += dt.Rows.Count - 1; } } ds = new DataSet(); //Dien //Xuất ra toàn bộ nội dung theo Trang sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, isnull(B.Mount,0) * isnull(B.PriceVND,0) as Sum, (isnull(B.Mount,0) * isnull(B.PriceVND,0))*isnull(A.Vat, 0)/100 as SumVAT , B.PriceUSD, B.SumVND, B.SumUSD, "; sql += " B.VatVND, B.VatUSD ,IsNull(B.LastPriceUSD,0) LastPriceUSD ,IsNull(B.LastPriceVND,0) LastPriceVND , B.Name, B.WaterPricePercent,B.ElecPricePercent "; sql += " FROM PaymentElecWater AS A INNER JOIN "; sql += " PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId"; sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0 and A.YearMonth in (" + lsYearmonth + ") and B.DetailType = 1"; sql += " Order by A.DateFrom, B.FromIndex"; bool rElecVat = true; bool rWaterVat = true; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rElec - 3 + j; //Phi dien XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 3, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 5, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 7, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 8, 8); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 9, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 10, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 11, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 12, 13); xlsSheet.MergedCells.Add(mCell); /////En mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 3, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 4, 4); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 5, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 7, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 8, 8); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 9, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 10, 10); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 11, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 12, 13); xlsSheetEn.MergedCells.Add(mCell); /////En for (int col = 1; col < 13; col++) { xlsSheet[line, col].Style = xlstStyleH; xlsSheet[line + 1, col].Style = xlstStyleH; xlsSheet[line + 2, col].Style = xlstStyleH; xlsSheetEn[line, col].Style = xlstStyleH; xlsSheetEn[line + 1, col].Style = xlstStyleH; xlsSheetEn[line + 2, col].Style = xlstStyleH; } if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rElec + 1 + j); xlsSheetEn.Rows.Insert(rElec + 1 + j); j++; } count++; int tmp = rElec + j; string DateFrom = Func.ParseString(row["DateFrom"]); string DateTo = Func.ParseString(row["DateTo"]); string FromIndex = Func.ParseString(row["FromIndex"]); string ToIndex = Func.ParseString(row["ToIndex"]); string OtherFee01 = Func.ParseString(row["OtherFee01"]); string OtherFee02 = Func.ParseString(row["OtherFee02"]); string Mount = Func.ParseString(row["Mount"]); string ElecPricePercent = Func.ParseString(row["ElecPricePercent"]); string vat = Func.ParseString(row["vat"]); if (rElecVat) { setValReplace(line, 9, "(%VAT)", "(" + vat.Replace(",00", "") + "%VAT)"); rElecVat = false; } xlsSheet[tmp, 1].Value = DateFrom; xlsSheet[tmp, 2].Value = DateTo; xlsSheet[tmp, 3].Value = FromIndex; xlsSheet[tmp, 4].Value = ToIndex; xlsSheet[tmp, 5].Value = row["OtherFee01"]; xlsSheet[tmp, 6].Value = Mount; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["Sum"]; xlsSheet[tmp, 9].Value = row["SumVAT"]; xlsSheet[tmp, 10].Value = row["OtherFee02"]; xlsSheet[tmp, 11].Value = row["ElecPricePercent"]; xlsSheet[tmp, 12].Value = row["LastPriceVND"]; mCell = new XLCellRange(tmp, tmp, 12, 13); xlsSheet.MergedCells.Add(mCell); /////En xlsSheetEn[tmp, 1].Value = DateFrom; xlsSheetEn[tmp, 2].Value = DateTo; xlsSheetEn[tmp, 3].Value = FromIndex; xlsSheetEn[tmp, 4].Value = ToIndex; xlsSheetEn[tmp, 5].Value = row["OtherFee01"]; xlsSheetEn[tmp, 6].Value = Mount; xlsSheetEn[tmp, 7].Value = row["PriceVND"]; xlsSheetEn[tmp, 8].Value = row["Sum"]; xlsSheetEn[tmp, 9].Value = row["SumVAT"]; xlsSheetEn[tmp, 10].Value = row["OtherFee02"]; xlsSheetEn[tmp, 11].Value = row["ElecPricePercent"]; xlsSheetEn[tmp, 12].Value = row["LastPriceVND"]; for (int col = 1; col <= 13; col++) { xlsSheet[tmp, col].Style = xlstStyle; xlsSheetEn[tmp, col].Style = xlstStyle; } ////EN //Format //xlsSheetEn[tmp, 1].Style = xlstStyleC1; //xlsSheetEn[tmp, 2].Style = xlstStyleC1; ///////En //for (int col = 1; col <= 12; col++) //{ // xlsSheet[tmp, col].Style = xlstStyle2; // xlsSheetEn[tmp, col].Style = xlstStyle2; //} ///////////////// xlsSheetEn[tmp, 3].Style = xlstStyleC2; xlsSheetEn[tmp, 4].Style = xlstStyleC2; xlsSheetEn[tmp, 5].Style = xlstStyleC0; xlsSheetEn[tmp, 6].Style = xlstStyle2; xlsSheetEn[tmp, 7].Style = xlstStyle0; xlsSheetEn[tmp, 8].Style = xlstStyle0; xlsSheetEn[tmp, 9].Style = xlstStyle0; xlsSheetEn[tmp, 10].Style = xlstStyle0; xlsSheetEn[tmp, 11].Style = xlstStyle2; xlsSheetEn[tmp, 12].Style = xlstStyle0; ///////////////// xlsSheet[tmp, 3].Style = xlstStyleC2; xlsSheet[tmp, 4].Style = xlstStyleC2; xlsSheet[tmp, 5].Style = xlstStyleC0; xlsSheet[tmp, 6].Style = xlstStyle2; xlsSheet[tmp, 7].Style = xlstStyle0; xlsSheet[tmp, 8].Style = xlstStyle0; xlsSheet[tmp, 9].Style = xlstStyle0; xlsSheet[tmp, 10].Style = xlstStyle0; xlsSheet[tmp, 11].Style = xlstStyle2; xlsSheet[tmp, 12].Style = xlstStyle0; mCell = new XLCellRange(tmp, tmp, 12, 13); xlsSheetEn.MergedCells.Add(mCell); /////En //LastSumPriceVND[4] += Convert.ToDecimal(row["LastPriceVND"]); //LastSumPriceUSD[4] += Convert.ToDecimal(row["LastPriceUSD"]); } //decimal result = Math.Round(LastSumPriceVND[4], 1); //result = Math.Round(result, 0); DataSet dsSum = new DataSet(); //Dien //Xuất ra toàn bộ nội dung theo Trang string sqlSum = " SELECT IsNull(A.LastPriceUSD,0) LastPriceUSD ,IsNull(A.LastPriceVND,0) LastPriceVND "; sqlSum += " FROM PaymentElecWater AS A "; sqlSum += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId > 0 and A.YearMonth in (" + lsYearmonth + ") and A.DetailType = 1"; using (SqlCommand cmSum = db.CreateCommand(sqlSum)) { SqlDataAdapter daSum = new SqlDataAdapter(cmSum); daSum.Fill(dsSum); if (daSum != null) { DataTable dtSum = dsSum.Tables[0]; if (dtSum.Rows.Count > 0) { foreach (DataRow row in dtSum.Rows) { LastSumPriceUSD[4] += Convert.ToDecimal(row["LastPriceUSD"]); LastSumPriceVND[4] += Convert.ToDecimal(row["LastPriceVND"]); } } } } /////////////////////////// xlsSheet[rElec + 1 + j, 12].Value = Decimal.Round(LastSumPriceVND[4], 0); mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn[rElec + 1 + j, 12].Value = LastSumPriceVND[4]; //// xlsSheet[rElec + 1 + j, 12].Style = xlstStyleSum0; xlsSheetEn[rElec + 1 + j, 12].Style = xlstStyleSum0; mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 1, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 12, 13); xlsSheetEn.MergedCells.Add(mCell); //for (int col = 1; col <= 13; col++) //{ // xlsSheet[rElec + 1 + j, col].Style = xlstStyleSum; // xlsSheetEn[rElec + 1 + j, col].Style = xlstStyleSum; //} sumRow += dt.Rows.Count - 1; } } } ds = new DataSet(); //Nuoc //Xuất ra toàn bộ nội dung theo Trang sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, isnull(B.Mount,0) * isnull(B.PriceVND,0) as Sum, (isnull(B.Mount,0) * isnull(B.PriceVND,0))*isnull(A.Vat, 0)/100 as SumVAT ,B.PriceUSD, B.SumVND, B.SumUSD, "; sql += " B.VatVND, B.VatUSD,IsNull(B.LastPriceUSD,0) LastPriceUSD,IsNull(B.LastPriceVND,0) LastPriceVND, B.Name, B.WaterPricePercent,B.ElecPricePercent "; sql += " FROM PaymentElecWater AS A INNER JOIN "; sql += " PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId"; sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and A.YearMonth in (" + lsYearmonth + ") and B.DetailType = 2"; sql += " Order by A.DateFrom, B.FromIndex"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rWater - 3 + j; //Phi dien XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 3, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 6, 6); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 7, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 8, 8); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 9, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 10, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 11, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 12, 13); xlsSheet.MergedCells.Add(mCell); /////En mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 3, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 4, 4); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 6, 6); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 7, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 8, 8); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 9, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 10, 10); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 11, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 12, 13); xlsSheetEn.MergedCells.Add(mCell); /////En for (int col = 1; col < 13; col++) { xlsSheet[line, col].Style = xlstStyleH; xlsSheet[line + 1, col].Style = xlstStyleH; xlsSheet[line + 2, col].Style = xlstStyleH; xlsSheetEn[line, col].Style = xlstStyleH; xlsSheetEn[line + 1, col].Style = xlstStyleH; xlsSheetEn[line + 2, col].Style = xlstStyleH; } for (int col = 1; col < 13; col++) { xlsSheet[line, col].Style = xlstStyleH; xlsSheet[line + 1, col].Style = xlstStyleH; xlsSheet[line + 2, col].Style = xlstStyleH; xlsSheetEn[line, col].Style = xlstStyleH; xlsSheetEn[line + 1, col].Style = xlstStyleH; xlsSheetEn[line + 2, col].Style = xlstStyleH; } if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rWater + 1 + j); xlsSheetEn.Rows.Insert(rWater + 1 + j); j++; } count++; int tmp = rWater + j; string DateFrom = Func.ParseString(row["DateFrom"]); string DateTo = Func.ParseString(row["DateTo"]); string FromIndex = Func.ParseString(row["FromIndex"]); string ToIndex = Func.ParseString(row["ToIndex"]); string OtherFee01 = Func.ParseString(row["OtherFee01"]); string OtherFee02 = Func.ParseString(row["OtherFee02"]); string Mount = Func.ParseString(row["Mount"]); string vat = Func.ParseString(row["vat"]); if (rWaterVat) { setValReplace(line, 9, "(%VAT)", "(" + vat.Replace(",00", "") + "%VAT)"); rWaterVat = false; } xlsSheet[tmp, 1].Value = DateFrom; xlsSheet[tmp, 2].Value = DateTo; xlsSheet[tmp, 3].Value = FromIndex; xlsSheet[tmp, 4].Value = ToIndex; xlsSheet[tmp, 5].Value = Mount; xlsSheet[tmp, 6].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["OtherFee01"]; xlsSheet[tmp, 7].Value = row["Sum"]; xlsSheet[tmp, 9].Value = row["SumVAT"]; xlsSheet[tmp, 10].Value = row["OtherFee02"]; xlsSheet[tmp, 11].Value = row["WaterPricePercent"]; xlsSheet[tmp, 12].Value = row["LastPriceVND"]; /////En xlsSheetEn[tmp, 1].Value = DateFrom; xlsSheetEn[tmp, 2].Value = DateTo; xlsSheetEn[tmp, 3].Value = FromIndex; xlsSheetEn[tmp, 4].Value = ToIndex; xlsSheetEn[tmp, 5].Value = Mount; xlsSheetEn[tmp, 6].Value = row["PriceVND"]; xlsSheetEn[tmp, 7].Value = row["OtherFee01"]; xlsSheetEn[tmp, 8].Value = row["VatVND"]; xlsSheetEn[tmp, 9].Value = row["SumVND"]; xlsSheetEn[tmp, 10].Value = row["OtherFee02"]; xlsSheetEn[tmp, 11].Value = row["WaterPricePercent"]; xlsSheetEn[tmp, 12].Value = row["LastPriceVND"]; /////En for (int col = 1; col <= 13; col++) { xlsSheet[tmp, col].Style = xlstStyle; xlsSheetEn[tmp, col].Style = xlstStyle; } ///////////////// xlsSheetEn[tmp, 3].Style = xlstStyleC2; xlsSheetEn[tmp, 4].Style = xlstStyleC2; xlsSheetEn[tmp, 5].Style = xlstStyleC2; xlsSheetEn[tmp, 6].Style = xlstStyle0; xlsSheetEn[tmp, 6].Style = xlstStyle0; xlsSheetEn[tmp, 7].Style = xlstStyle0; xlsSheetEn[tmp, 8].Style = xlstStyle0; xlsSheetEn[tmp, 9].Style = xlstStyle0; xlsSheetEn[tmp, 10].Style = xlstStyle2; xlsSheetEn[tmp, 11].Style = xlstStyle2; xlsSheetEn[tmp, 12].Style = xlstStyle0; ///////////////// xlsSheet[tmp, 3].Style = xlstStyleC2; xlsSheet[tmp, 4].Style = xlstStyleC2; xlsSheet[tmp, 5].Style = xlstStyleC2; xlsSheet[tmp, 6].Style = xlstStyle0; xlsSheet[tmp, 7].Style = xlstStyle0; xlsSheet[tmp, 8].Style = xlstStyle0; xlsSheet[tmp, 9].Style = xlstStyle0; xlsSheet[tmp, 10].Style = xlstStyle2; xlsSheet[tmp, 11].Style = xlstStyle2; xlsSheet[tmp, 12].Style = xlstStyle0; //LastSumPriceVND[5] += Convert.ToDecimal(row["LastPriceVND"]); //LastSumPriceUSD[5] += Convert.ToDecimal(row["LastPriceUSD"]); mCell = new XLCellRange(tmp, tmp, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); } //xlsSheet[rWater + 1 + j, 12].Value = LastSumPriceVND[5]; //xlsSheetEn[rWater + 1 + j, 12].Value = LastSumPriceVND[5]; /////////////// //xlsSheet[rWater + 1 + j, 12].Style = xlstStyleSum0; //xlsSheetEn[rWater + 1 + j, 12].Style = xlstStyleSum0; //mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 1, 11); //xlsSheet.MergedCells.Add(mCell); //xlsSheetEn.MergedCells.Add(mCell); //mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 12, 13); //xlsSheet.MergedCells.Add(mCell); //xlsSheetEn.MergedCells.Add(mCell); ////for (int col = 1; col <= 13; col++) ////{ //// xlsSheet[rWater + 1 + j, col].Style = xlstStyleSum; //// xlsSheetEn[rWater + 1 + j, col].Style = xlstStyleSum; ////} //sumRow += dt.Rows.Count - 1; //decimal result = Math.Round(LastSumPriceVND[4], 1); //result = Math.Round(result, 0); DataSet dsSum = new DataSet(); //Dien //Xuất ra toàn bộ nội dung theo Trang string sqlSum = " SELECT IsNull(A.LastPriceUSD,0) LastPriceUSD ,IsNull(A.LastPriceVND,0) LastPriceVND "; sqlSum += " FROM PaymentElecWater AS A "; sqlSum += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId > 0 and A.YearMonth in (" + lsYearmonth + ") and A.DetailType = 2"; using (SqlCommand cmSum = db.CreateCommand(sqlSum)) { SqlDataAdapter daSum = new SqlDataAdapter(cmSum); daSum.Fill(dsSum); if (daSum != null) { DataTable dtSum = dsSum.Tables[0]; if (dtSum.Rows.Count > 0) { foreach (DataRow row in dtSum.Rows) { LastSumPriceUSD[5] += Convert.ToDecimal(row["LastPriceUSD"]); LastSumPriceVND[5] += Convert.ToDecimal(row["LastPriceVND"]); } } } } /////////////////////////// xlsSheet[rWater + 1 + j, 12].Value = Decimal.Round(LastSumPriceVND[5], 0); mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn[rWater + 1 + j, 12].Value = LastSumPriceVND[5]; //// xlsSheet[rWater + 1 + j, 12].Style = xlstStyleSum0; xlsSheetEn[rWater + 1 + j, 12].Style = xlstStyleSum0; mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 1, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 12, 13); xlsSheetEn.MergedCells.Add(mCell); //for (int col = 1; col <= 13; col++) //{ // xlsSheet[rElec + 1 + j, col].Style = xlstStyleSum; // xlsSheetEn[rElec + 1 + j, col].Style = xlstStyleSum; //} sumRow += dt.Rows.Count - 1; } } } //Service ds = new DataSet(); sql = string.Empty; sql = " SELECT Service,dbo.fnDateTime(ServiceDateFrom) ServiceDateFrom,dbo.fnDateTime(ServiceDateTo) ServiceDateTo,PriceVND,PriceUSD,VatUSD,VatVND,Mount,Unit,SumVND,SumUSD,isnull(LastPriceVND,0) LastPriceVND,isnull(LastPriceUSD,0) LastPriceUSD"; sql += " FROM PaymentService"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")"; sql += " Order By ServiceDate "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rService - 3 + j; //Phi khác XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 3, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 5, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); /////En mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 3, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 4, 4); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 5, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheetEn.MergedCells.Add(mCell); /////En for (int col = 1; col < 13; col++) { xlsSheet[line, col].Style = xlstStyleH; xlsSheet[line + 1, col].Style = xlstStyleH; xlsSheet[line + 2, col].Style = xlstStyleH; xlsSheetEn[line, col].Style = xlstStyleH; xlsSheetEn[line + 1, col].Style = xlstStyleH; xlsSheetEn[line + 2, col].Style = xlstStyleH; } mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rService + 1 + j); xlsSheetEn.Rows.Insert(rService + 1 + j); j++; } count++; int tmp = rService + j; string Service = Func.ParseString(row["Service"]); string ServiceDateFrom = Func.ParseString(row["ServiceDateFrom"]); string ServiceDateTo = Func.ParseString(row["ServiceDateTo"]); string Mount = Func.ParseString(row["Mount"]); xlsSheet[tmp, 1].Value = Service; xlsSheet[tmp, 2].Value = Func.ParseString(row["Unit"]); xlsSheet[tmp, 3].Value = ServiceDateFrom; xlsSheet[tmp, 4].Value = ServiceDateTo; xlsSheet[tmp, 5].Value = Mount; xlsSheet[tmp, 6].Value = row["PriceUSD"]; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["SumUSD"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 10].Value = row["VatUSD"]; xlsSheet[tmp, 11].Value = row["VatVND"]; xlsSheet[tmp, 12].Value = row["LastPriceUSD"]; xlsSheet[tmp, 13].Value = row["LastPriceVND"]; /////En xlsSheetEn[tmp, 1].Value = Service; xlsSheetEn[tmp, 2].Value = Func.ParseString(row["Unit"]); xlsSheetEn[tmp, 3].Value = ServiceDateFrom; xlsSheetEn[tmp, 4].Value = ServiceDateTo; xlsSheetEn[tmp, 5].Value = Mount; xlsSheetEn[tmp, 6].Value = row["PriceUSD"]; xlsSheetEn[tmp, 7].Value = row["PriceVND"]; xlsSheetEn[tmp, 8].Value = row["SumUSD"]; xlsSheetEn[tmp, 9].Value = row["SumVND"]; xlsSheetEn[tmp, 10].Value = row["VatUSD"]; xlsSheetEn[tmp, 11].Value = row["VatVND"]; xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"]; xlsSheetEn[tmp, 13].Value = row["LastPriceVND"]; /////En for (int col = 1; col <= 13; col++) { xlsSheet[tmp, col].Style = xlstStyle; xlsSheetEn[tmp, col].Style = xlstStyle; } ////////////////////////// xlsSheetEn[tmp, 5].Style = xlstStyleC2; xlsSheetEn[tmp, 6].Style = xlstStyle0; xlsSheetEn[tmp, 7].Style = xlstStyle1; xlsSheetEn[tmp, 8].Style = xlstStyle0; xlsSheetEn[tmp, 9].Style = xlstStyle1; xlsSheetEn[tmp, 10].Style = xlstStyle0; xlsSheetEn[tmp, 11].Style = xlstStyle1; xlsSheetEn[tmp, 12].Style = xlstStyle0; xlsSheetEn[tmp, 13].Style = xlstStyle1; //////////////// xlsSheet[tmp, 5].Style = xlstStyleC2; xlsSheet[tmp, 6].Style = xlstStyle0; xlsSheet[tmp, 7].Style = xlstStyle1; xlsSheet[tmp, 8].Style = xlstStyle0; xlsSheet[tmp, 9].Style = xlstStyle1; xlsSheet[tmp, 10].Style = xlstStyle0; xlsSheet[tmp, 11].Style = xlstStyle1; xlsSheet[tmp, 12].Style = xlstStyle0; xlsSheet[tmp, 13].Style = xlstStyle1; //for (int col = 1; col <= 13; col++) //{ // xlsSheet[tmp, col].Style = xlstStyle; // xlsSheetEn[tmp, col].Style = xlstStyle; //} LastSumPriceVND[6] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[6] += Convert.ToDecimal(row["LastPriceUSD"]); } xlsSheet[rService + 1 + j, 12].Value = LastSumPriceUSD[6]; xlsSheet[rService + 1 + j, 13].Value = LastSumPriceVND[6]; xlsSheetEn[rService + 1 + j, 12].Value = LastSumPriceUSD[6]; xlsSheetEn[rService + 1 + j, 13].Value = LastSumPriceVND[6]; /////////////// xlsSheetEn[rService + 1 + j, 12].Style = xlstStyleSum1; xlsSheetEn[rService + 1 + j, 13].Style = xlstStyleSum0; //// xlsSheet[rService + 1 + j, 12].Style = xlstStyleSum1; xlsSheet[rService + 1 + j, 13].Style = xlstStyleSum0; mCell = new XLCellRange(rService + 1 + j, rService + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); //for (int col = 1; col <= 13; col++) //{ // xlsSheet[rService + 1 + j, col].Style = xlstStyleSum; // xlsSheetEn[rService + 1 + j, col].Style = xlstStyleSum; //} sumRow += dt.Rows.Count - 1; } } } //Paid sql = "Select PaymentType,isnull(MoneyUSD,0) MoneyUSD,isnull(MoneyVND,0) MoneyVND,isnull(PaidUSD,0) PaidUSD,isnull(PaidVND,0) PaidVND,isnull(ExchangeType,0) ExchangeType,isnull(UsdExchange,0) UsdExchange,isnull(YearMonth,0) YearMonth"; sql += " From PaymentBillDetail"; sql += " Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ") and YearMonth <= " + maxYearMonth + ""; string strYearMonth = ""; int lineTmp = rPaid - 2 + j; //Paid XLCellRange mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13); xlsSheet.MergedCells.Add(mCellTmp); /////En mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13); xlsSheetEn.MergedCells.Add(mCellTmp); /////En Hashtable rowNo = new Hashtable(); decimal[] PaidSumVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; decimal[] PaidSumUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; DataTable dtPaid = DbHelper.GetDataTable(sql); for (int i = 0; i < dtPaid.Rows.Count; i++) { string PaymentType = Func.ParseString(dtPaid.Rows[i]["PaymentType"]); string MoneyUSD = Func.ParseString(dtPaid.Rows[i]["MoneyUSD"]); string MoneyVND = Func.ParseString(dtPaid.Rows[i]["MoneyVND"]); string PaidUSD = Func.ParseString(dtPaid.Rows[i]["PaidUSD"]); string PaidVND = Func.ParseString(dtPaid.Rows[i]["PaidVND"]); string ExchangeType = Func.ParseString(dtPaid.Rows[i]["ExchangeType"]); string UsdExchange = Func.ParseString(dtPaid.Rows[i]["UsdExchange"]); string YearMonth = Func.ParseString(dtPaid.Rows[i]["YearMonth"]); if (!rowNo.Contains(YearMonth)) { if (rowNo.Count != 0) { xlsSheet.Rows.Insert(rPaid + j + 1); xlsSheetEn.Rows.Insert(rPaid + j + 1); j++; } rowNo.Add(YearMonth, j); } int m = Func.ParseInt(rowNo[YearMonth]); strYearMonth = YearMonth; decimal tmpUSD = Convert.ToDecimal(MoneyUSD) - Convert.ToDecimal(PaidUSD); decimal tmpVND = Convert.ToDecimal(MoneyVND) - Convert.ToDecimal(PaidVND); PaidPriceUSD += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidPriceVND += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); xlsSheet[rPaid + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); xlsSheetEn[rPaid + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); switch (PaymentType) { case "1": //Rent xlsSheet[rPaid + m, 2].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + m, 3].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 2].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheetEn[rPaid + m, 3].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[0] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[0] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "2": //Manager xlsSheet[rPaid + m, 4].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + m, 5].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 4].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheetEn[rPaid + m, 5].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[1] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[1] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "3": //Parking xlsSheet[rPaid + m, 6].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + m, 7].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 6].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheetEn[rPaid + m, 7].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[2] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[2] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "4": //Extra xlsSheet[rPaid + m, 8].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + m, 9].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 8].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheetEn[rPaid + m, 9].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[3] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[3] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "5": xlsSheet[rPaid + m, 10].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 10].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[4] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[4] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "6": xlsSheet[rPaid + m, 11].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 11].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[5] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[5] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "7": xlsSheet[rPaid + m, 12].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + m, 13].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 12].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheetEn[rPaid + m, 13].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[6] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[6] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; default: break; } ///////////////////////////////////////////////// for (int col = 1; col <= 13; col++) { xlsSheet[rPaid + m, col].Style = xlstStyle; xlsSheetEn[rPaid + m, col].Style = xlstStyle; } //Rent xlsSheet[rPaid + m, 2].Style = xlstStyle1; xlsSheet[rPaid + m, 3].Style = xlstStyle0; xlsSheetEn[rPaid + m, 2].Style = xlstStyle1; xlsSheetEn[rPaid + m, 3].Style = xlstStyle0; //Manager xlsSheet[rPaid + m, 4].Style = xlstStyle1; xlsSheet[rPaid + m, 5].Style = xlstStyle0; xlsSheetEn[rPaid + m, 4].Style = xlstStyle1; xlsSheetEn[rPaid + m, 5].Style = xlstStyle0; //Parking xlsSheet[rPaid + m, 6].Style = xlstStyle1; xlsSheet[rPaid + m, 7].Style = xlstStyle0; xlsSheetEn[rPaid + m, 6].Style = xlstStyle1; xlsSheetEn[rPaid + m, 7].Style = xlstStyle0; //Extra xlsSheet[rPaid + m, 8].Style = xlstStyle1; xlsSheet[rPaid + m, 9].Style = xlstStyle0; xlsSheetEn[rPaid + m, 8].Style = xlstStyle1; xlsSheetEn[rPaid + m, 9].Style = xlstStyle0; xlsSheet[rPaid + m, 10].Style = xlstStyle0; xlsSheetEn[rPaid + m, 10].Style = xlstStyle0; xlsSheet[rPaid + m, 11].Style = xlstStyle0; xlsSheetEn[rPaid + m, 11].Style = xlstStyle0; xlsSheet[rPaid + m, 12].Style = xlstStyle1; xlsSheet[rPaid + m, 13].Style = xlstStyle0; xlsSheetEn[rPaid + m, 12].Style = xlstStyle1; xlsSheetEn[rPaid + m, 13].Style = xlstStyle0; ///////////////////////////////////////////////// //for (int row = rPaid + m; row <= rPaid + 1 + j; row++) //{ // for (int col = 1; col <= 13; col++) // { // xlsSheet[row, col].Style = xlstStyle; // } //} } lineTmp = rPaid - 2 + j; xlsSheet[lineTmp + 3, 2].Value = PaidSumUSD[0]; xlsSheet[lineTmp + 3, 3].Value = PaidSumVND[0]; xlsSheet[lineTmp + 3, 4].Value = PaidSumUSD[1]; xlsSheet[lineTmp + 3, 5].Value = PaidSumVND[1]; xlsSheet[lineTmp + 3, 6].Value = PaidSumUSD[2]; xlsSheet[lineTmp + 3, 7].Value = PaidSumVND[2]; xlsSheet[lineTmp + 3, 8].Value = PaidSumUSD[3]; xlsSheet[lineTmp + 3, 9].Value = PaidSumVND[3]; xlsSheet[lineTmp + 3, 10].Value = PaidSumVND[4]; xlsSheet[lineTmp + 3, 11].Value = PaidSumVND[5]; xlsSheet[lineTmp + 3, 12].Value = PaidSumUSD[6]; xlsSheet[lineTmp + 3, 13].Value = PaidSumVND[6]; /////En xlsSheetEn[lineTmp + 3, 2].Value = PaidSumUSD[0]; xlsSheetEn[lineTmp + 3, 3].Value = PaidSumVND[0]; xlsSheetEn[lineTmp + 3, 4].Value = PaidSumUSD[1]; xlsSheetEn[lineTmp + 3, 5].Value = PaidSumVND[1]; xlsSheetEn[lineTmp + 3, 6].Value = PaidSumUSD[2]; xlsSheetEn[lineTmp + 3, 7].Value = PaidSumVND[2]; xlsSheetEn[lineTmp + 3, 8].Value = PaidSumUSD[3]; xlsSheetEn[lineTmp + 3, 9].Value = PaidSumVND[3]; xlsSheetEn[lineTmp + 3, 10].Value = PaidSumVND[4]; xlsSheetEn[lineTmp + 3, 11].Value = PaidSumVND[5]; xlsSheetEn[lineTmp + 3, 12].Value = PaidSumUSD[6]; xlsSheetEn[lineTmp + 3, 13].Value = PaidSumVND[6]; /////En ///////////////// xlsSheetEn[lineTmp + 3, 2].Style = xlstStyleSum1; xlsSheetEn[lineTmp + 3, 3].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 4].Style = xlstStyleSum1; xlsSheetEn[lineTmp + 3, 5].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 6].Style = xlstStyleSum1; xlsSheetEn[lineTmp + 3, 7].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 8].Style = xlstStyleSum1; xlsSheetEn[lineTmp + 3, 9].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 10].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 11].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 12].Style = xlstStyleSum1; xlsSheetEn[lineTmp + 3, 13].Style = xlstStyleSum0; /////////////// xlsSheet[lineTmp + 3, 2].Style = xlstStyleSum1; xlsSheet[lineTmp + 3, 3].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 4].Style = xlstStyleSum1; xlsSheet[lineTmp + 3, 5].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 6].Style = xlstStyleSum1; xlsSheet[lineTmp + 3, 7].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 8].Style = xlstStyleSum1; xlsSheet[lineTmp + 3, 9].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 10].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 11].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 12].Style = xlstStyleSum1; xlsSheet[lineTmp + 3, 13].Style = xlstStyleSum0; //for (int col = 1; col <= 13; col++) //{ // xlsSheet[lineTmp + 3, col].Style = xlstStyleSum; // xlsSheetEn[lineTmp + 3, col].Style = xlstStyleSum; //} ///////////////DEPT sql = " Select *"; sql += " From v_DeptBill"; sql += " Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth not in (" + lsYearmonth + ") and YearMonth < " + maxYearMonth + ""; sql += " And (DeptUsd <> 0 or DeptVnd <> 0)"; strYearMonth = ""; lineTmp = rDept - 2 + j; //Paid mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13); xlsSheet.MergedCells.Add(mCellTmp); //////En mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13); xlsSheetEn.MergedCells.Add(mCellTmp); //////En rowNo = new Hashtable(); decimal DeptPriceVND = 0; decimal DeptPriceUSD = 0; decimal[] DeptSumVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; decimal[] DeptSumUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; DataTable dtDept = DbHelper.GetDataTable(sql); for (int i = 0; i < dtDept.Rows.Count; i++) { string PaymentType = Func.ParseString(dtDept.Rows[i]["PaymentType"]); string DeptUSD = Func.ParseString(dtDept.Rows[i]["DeptUSD"]); string DeptVND = Func.ParseString(dtDept.Rows[i]["DeptVND"]); string YearMonth = Func.ParseString(dtDept.Rows[i]["YearMonth"]); if (!rowNo.Contains(YearMonth)) { if (rowNo.Count != 0) { xlsSheet.Rows.Insert(rDept + j + 1); xlsSheetEn.Rows.Insert(rDept + j + 1); j++; } rowNo.Add(YearMonth, j); } int m = Func.ParseInt(rowNo[YearMonth]); strYearMonth = YearMonth; DeptPriceUSD += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptPriceVND += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); xlsSheet[rDept + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); xlsSheetEn[rDept + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); //xlsSheetEn[rDept + m, 2].Value = 0; //xlsSheetEn[rDept + m, 3].Value = 0; //xlsSheetEn[rDept + m, 4].Value = 0; //xlsSheetEn[rDept + m, 5].Value = 0; //xlsSheetEn[rDept + m, 6].Value = 0; //xlsSheetEn[rDept + m, 7].Value = 0; //xlsSheetEn[rDept + m, 8].Value = 0; //xlsSheetEn[rDept + m, 9].Value = 0; //xlsSheetEn[rDept + m, 10].Value = 0; //xlsSheetEn[rDept + m, 11].Value = 0; //xlsSheetEn[rDept + m, 12].Value = 0; //xlsSheetEn[rDept + m, 13].Value = 0; //xlsSheet[rDept + m, 2].Value = 0; //xlsSheet[rDept + m, 3].Value = 0; //xlsSheet[rDept + m, 4].Value = 0; //xlsSheet[rDept + m, 5].Value = 0; //xlsSheet[rDept + m, 6].Value = 0; //xlsSheet[rDept + m, 7].Value = 0; //xlsSheet[rDept + m, 8].Value = 0; //xlsSheet[rDept + m, 9].Value = 0; //xlsSheet[rDept + m, 10].Value = 0; //xlsSheet[rDept + m, 11].Value = 0; //xlsSheet[rDept + m, 12].Value = 0; //xlsSheet[rDept + m, 13].Value = 0; switch (PaymentType) { case "1": //Rent xlsSheet[rDept + m, 2].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheet[rDept + m, 3].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 2].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheetEn[rDept + m, 3].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[0] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[0] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "2": //Manager xlsSheet[rDept + m, 4].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheet[rDept + m, 5].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 4].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheetEn[rDept + m, 5].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[1] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[1] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "3": //Parking xlsSheet[rDept + m, 6].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheet[rDept + m, 7].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 6].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheetEn[rDept + m, 7].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[2] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[2] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "4": //Extra xlsSheet[rDept + m, 8].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheet[rDept + m, 9].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 8].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheetEn[rDept + m, 9].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[3] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[3] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "5": xlsSheet[rDept + m, 10].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 10].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[4] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[4] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "6": xlsSheet[rDept + m, 11].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 11].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[5] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[5] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "7": xlsSheet[rDept + m, 12].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheet[rDept + m, 13].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 12].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheetEn[rDept + m, 13].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[6] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[6] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; default: break; } for (int col = 1; col <= 13; col++) { xlsSheet[rDept + m, col].Style = xlstStyle; xlsSheetEn[rDept + m, col].Style = xlstStyle; } //////////////// xlsSheet[rDept + m, 2].Style = xlstStyle1; xlsSheet[rDept + m, 3].Style = xlstStyle0; xlsSheetEn[rDept + m, 2].Style = xlstStyle1; xlsSheetEn[rDept + m, 3].Style = xlstStyle0; //Manager xlsSheet[rDept + m, 4].Style = xlstStyle1; xlsSheet[rDept + m, 5].Style = xlstStyle0; xlsSheetEn[rDept + m, 4].Style = xlstStyle1; xlsSheetEn[rDept + m, 5].Style = xlstStyle0; //Parking xlsSheet[rDept + m, 6].Style = xlstStyle1; xlsSheet[rDept + m, 7].Style = xlstStyle0; xlsSheetEn[rDept + m, 6].Style = xlstStyle1; xlsSheetEn[rDept + m, 7].Style = xlstStyle0; //Extra xlsSheet[rDept + m, 8].Style = xlstStyle1; xlsSheet[rDept + m, 9].Style = xlstStyle0; xlsSheetEn[rDept + m, 8].Style = xlstStyle1; xlsSheetEn[rDept + m, 9].Style = xlstStyle0; xlsSheet[rDept + m, 10].Style = xlstStyle0; xlsSheetEn[rDept + m, 10].Style = xlstStyle0; xlsSheet[rDept + m, 11].Style = xlstStyle0; xlsSheetEn[rDept + m, 11].Style = xlstStyle0; xlsSheet[rDept + m, 12].Style = xlstStyle1; xlsSheet[rDept + m, 13].Style = xlstStyle0; xlsSheetEn[rDept + m, 12].Style = xlstStyle1; xlsSheetEn[rDept + m, 13].Style = xlstStyle0; //for (int row = rDept + m; row <= rDept + 1 + j; row++) //{ // for (int col = 1; col <= 13; col++) // { // xlsSheet[row, col].Style = xlstStyle; // xlsSheetEn[row, col].Style = xlstStyle; // } //} } lineTmp = rDept - 2 + j; xlsSheet[lineTmp + 3, 2].Value = DeptSumUSD[0]; xlsSheet[lineTmp + 3, 3].Value = DeptSumVND[0]; xlsSheet[lineTmp + 3, 4].Value = DeptSumUSD[1]; xlsSheet[lineTmp + 3, 5].Value = DeptSumVND[1]; xlsSheet[lineTmp + 3, 6].Value = DeptSumUSD[2]; xlsSheet[lineTmp + 3, 7].Value = DeptSumVND[2]; xlsSheet[lineTmp + 3, 8].Value = DeptSumUSD[3]; xlsSheet[lineTmp + 3, 9].Value = DeptSumVND[3]; xlsSheet[lineTmp + 3, 10].Value = DeptSumVND[4]; xlsSheet[lineTmp + 3, 11].Value = DeptSumVND[5]; xlsSheet[lineTmp + 3, 12].Value = DeptSumUSD[6]; xlsSheet[lineTmp + 3, 13].Value = DeptSumVND[6]; //////En xlsSheetEn[lineTmp + 3, 2].Value = DeptSumUSD[0]; xlsSheetEn[lineTmp + 3, 3].Value = DeptSumVND[0]; xlsSheetEn[lineTmp + 3, 4].Value = DeptSumUSD[1]; xlsSheetEn[lineTmp + 3, 5].Value = DeptSumVND[1]; xlsSheetEn[lineTmp + 3, 6].Value = DeptSumUSD[2]; xlsSheetEn[lineTmp + 3, 7].Value = DeptSumVND[2]; xlsSheetEn[lineTmp + 3, 8].Value = DeptSumUSD[3]; xlsSheetEn[lineTmp + 3, 9].Value = DeptSumVND[3]; xlsSheetEn[lineTmp + 3, 10].Value = DeptSumVND[4]; xlsSheetEn[lineTmp + 3, 11].Value = DeptSumVND[5]; xlsSheetEn[lineTmp + 3, 12].Value = DeptSumUSD[6]; xlsSheetEn[lineTmp + 3, 13].Value = DeptSumVND[6]; //////En ///////////////////////// xlsSheet[lineTmp + 3, 2].Style = xlstStyleSum1; xlsSheet[lineTmp + 3, 3].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 4].Style = xlstStyleSum1; xlsSheet[lineTmp + 3, 5].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 6].Style = xlstStyleSum1; xlsSheet[lineTmp + 3, 7].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 8].Style = xlstStyleSum1; xlsSheet[lineTmp + 3, 9].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 10].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 11].Style = xlstStyleSum0; xlsSheet[lineTmp + 3, 12].Style = xlstStyleSum1; xlsSheet[lineTmp + 3, 13].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 2].Style = xlstStyleSum1; xlsSheetEn[lineTmp + 3, 3].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 4].Style = xlstStyleSum1; xlsSheetEn[lineTmp + 3, 5].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 6].Style = xlstStyleSum1; xlsSheetEn[lineTmp + 3, 7].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 8].Style = xlstStyleSum1; xlsSheetEn[lineTmp + 3, 9].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 10].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 11].Style = xlstStyleSum0; xlsSheetEn[lineTmp + 3, 12].Style = xlstStyleSum1; xlsSheetEn[lineTmp + 3, 13].Style = xlstStyleSum0; //for (int col = 1; col <= 13; col++) //{ // xlsSheet[lineTmp + 3, col].Style = xlstStyleSum; // xlsSheetEn[lineTmp + 3, col].Style = xlstStyleSum; //} //xlsSheet[lineTmp + 3, 1].Style = xlstStyleSum; //xlsSheetEn[lineTmp + 3, 1].Style = xlstStyleSum; decimal AllSumVND = 0; decimal AllSumUSD = 0; for (int i = 0; i < 7; i++) { AllSumVND += LastSumPriceVND[i]; AllSumUSD += LastSumPriceUSD[i]; } AllSumVND -= PaidPriceVND; AllSumUSD -= PaidPriceUSD; AllSumVND += DeptPriceVND; AllSumUSD += DeptPriceUSD; xlsSheet[rSumVND + j, cSumVND - 2].Value = Func.FormatNumber_New(AllSumUSD); xlsSheet[rSumVND + j, cSumVND - 2].Value += " (USD)"; xlsSheet[rSumVND + j, cSumVND].Value = Func.FormatNumber_New(Math.Truncate(Convert.ToDecimal(AllSumVND))).Replace(",00", ""); xlsSheet[rSumVND + j, cSumVND].Value += " (VND)"; xlsSheetEn[rSumVND + j, cSumVND - 2].Value = Func.FormatNumber_New(AllSumUSD); xlsSheetEn[rSumVND + j, cSumVND - 2].Value += " (USD)"; xlsSheetEn[rSumVND + j, cSumVND].Value = Func.FormatNumber_New(Math.Truncate(Convert.ToDecimal(AllSumVND))).Replace(",00", ""); xlsSheetEn[rSumVND + j, cSumVND].Value += " (VND)"; mCellTmp = new XLCellRange(rSumVND + j, rSumVND + j, cSumVND - 2, cSum - 1); xlsSheetEn.MergedCells.Add(mCellTmp); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(rSumVND + j, rSumVND + j, cSumVND, cSum + 1); xlsSheetEn.MergedCells.Add(mCellTmp); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(rSumVND + j, rSumVND + j, 6, 9); xlsSheetEn.MergedCells.Add(mCellTmp); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(rSumVND + j + 1, rSumVND + j + 1, 6, 9); xlsSheetEn.MergedCells.Add(mCellTmp); xlsSheet.MergedCells.Add(mCellTmp); //mCellTmp = new XLCellRange(rSumVND + j, rSumVND + j, cSum - 2, cSum - 1); //xlsSheet.MergedCells.Add(mCellTmp); //mCellTmp = new XLCellRange(rSumVND + j, rSumVND + j, cSum, cSum + 1); //xlsSheet.MergedCells.Add(mCellTmp); ///// ////////// //format xlsSheet[rSumVND + j, cSumVND - 2].Style = xlstStyleCH; xlsSheet[rSumVND + j, cSumVND].Style = xlstStyleCH; xlsSheetEn[rSumVND + j, cSumVND - 2].Style = xlstStyleCH; xlsSheetEn[rSumVND + j, cSumVND].Style = xlstStyleCH; /////////////// AllSumVND += Convert.ToDecimal(AllSumUSD * Convert.ToDecimal(txtUsdExchange.Text)); string strMoney = Func.docso(Convert.ToDecimal(AllSumVND)); string strMoneyEn = Func.DocSo_En(Convert.ToDecimal(AllSumVND)); xlsSheet[rContract, cContract].Value = xlsSheet[rContract, cContract].Value.ToString().Replace("{%HOP_DONG%}", String.IsNullOrEmpty(contract) ? "" : contract.Substring(1)); //xlsSheet[rSum + j, cSum].Value = Convert.ToInt32(AllSumVND); xlsSheet[rSum + j, cSumVND].Value = Func.FormatNumber_New(Math.Truncate(Convert.ToDecimal(AllSumVND))).Replace(",00", ""); xlsSheet[rSum + j, cSumVND].Value += " (VND)"; xlsSheetEn[rSum + j, cSumVND].Value = Func.FormatNumber_New(Math.Truncate(Convert.ToDecimal(AllSumVND))).Replace(",00", ""); xlsSheetEn[rSum + j, cSumVND].Value += " (VND)"; mCellTmp = new XLCellRange(rSum + j, rSum + j, cSum, cSum + 1); xlsSheet.MergedCells.Add(mCellTmp); xlsSheet[rSum + j, cSum].Style = xlstStyleCSum0; xlsSheet[rSum + j, cSum + 1].Style = xlstStyleCSum0; xlsSheet[rSumRead + j, 6].Value = xlsSheet[rSumRead + j, 6].Value.ToString().Replace("{%TONG_CHU%}", strMoney.ToUpper()); xlsSheetEn[rContract, cContract].Value = xlsSheetEn[rContract, cContract].Value.ToString().Replace("{%HOP_DONG%}", String.IsNullOrEmpty(contract) ? "" : contract.Substring(1)); //xlsSheetEn[rSum + j, cSum].Value = Convert.ToInt32(AllSumVND); mCellTmp = new XLCellRange(rSum + j, rSum + j, cSum, cSum + 1); xlsSheetEn.MergedCells.Add(mCellTmp); xlsSheetEn[rSum + j, cSum].Style = xlstStyleCSum0; xlsSheetEn[rSum + j, cSum + 1].Style = xlstStyleCSum0; xlsSheetEn[rSumRead + j, 6].Value = xlsSheetEn[rSumRead + j, 6].Value.ToString().Replace("{%TONG_CHU%}", strMoneyEn.ToUpper()); //xlsSheetEn[rSumRead + j, cSumRead].Value = xlsSheetEn[rSumRead + j, cSumRead].Value.ToString().Replace("{%TONG_CHU%}", strMoneyEn.ToUpper()); mCellTmp = new XLCellRange(rSumRead + j, rSumRead + j, 6, 13); xlsSheetEn.MergedCells.Add(mCellTmp); xlsSheet.MergedCells.Add(mCellTmp); for (int i = 6; i <= 13; i++) { xlsSheet[rSumRead + j, i].Style = xlstStyle0; xlsSheetEn[rSumRead + j, i].Style = xlstStyle0; } mCellTmp = new XLCellRange(rSum + j, rSum + j, cSum, cSum + 1); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(84 + j, 84 + j, 1, 13); xlsSheet.MergedCells.Add(mCellTmp); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(85 + j, 85 + j, 1, 13); xlsSheet.MergedCells.Add(mCellTmp); xlsSheetEn.MergedCells.Add(mCellTmp); for (int i = 0; i < 4; i++) { mCellTmp = new XLCellRange(87 + j + i, 87 + j + i, 1, 6); xlsSheet.MergedCells.Add(mCellTmp); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(87 + j + i, 87 + j + i, 7, 13); xlsSheet.MergedCells.Add(mCellTmp); xlsSheetEn.MergedCells.Add(mCellTmp); } mCellTmp = new XLCellRange(92 + j, 92 + j, 9, 11); xlsSheet.MergedCells.Add(mCellTmp); xlsSheetEn.MergedCells.Add(mCellTmp); xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } }
protected void btnExport_Click(object sender, EventArgs e) { string type = Func.ParseString(Request["type"]); DataSet ds = new DataSet(); string sql = string.Empty; //sql = " SELECT *"; //sql += " FROM v_BuildingStatusInfo"; //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and StatusDate >= '" + Func.FormatYYYYmmdd(txtFromDate.Text.Substring(0, 10)) + "' and StatusDate <= '" + Func.FormatYYYYmmdd(txtToDate.Text.Substring(0, 10)) + "' and Type = '" + type + "'"; sql = " SELECT right('0'+convert(varchar,[Month]),2) + '/' + convert(varchar,[Year]),[Week],MainName,SubName"; sql += " ,dbo.fnDateTime(ExecDate),ExecCompany,ExecDescription,ExecComment,ExecConfirmer,ModifiedBy,dbo.fnDateTime(Modified)"; sql += " FROM BD_Maintenance "; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; sql += " and convert(varchar,[Year]) + right('0'+convert(varchar,[Month]),2) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; sql += " and convert(varchar,[Year]) + right('0'+convert(varchar,[Month]),2) <= '" + drpYearTo.SelectedValue + drpMonthTo.SelectedValue + "'"; sql += " and DelFlag = '0' "; sql += " and UPPER(IsMaintenance) = 'X' "; sql += " Order by right('0'+convert(varchar,[Month]),2) + '/' + convert(varchar,[Year]), MainName, SubName,Week "; using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); db.Close(); if (ds != null) { C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\KeHoachBaoTri.xlsx"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\KeHoachBaoTri")) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\KeHoachBaoTri")); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = ""; string strFilePathExport = ""; strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\KeHoachBaoTri\KeHoachBaoTri" + strDT + ".xlsx"; strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/KeHoachBaoTri/KeHoachBaoTri" + strDT + ".xlsx"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); string sheet = "KeHoachBaoTri"; XLSheet xlsSheet = xlbBook.Sheets[sheet]; int i = 3; XLCellRange mrCell = new XLCellRange(0, 0, 0, 2); xlsSheet.MergedCells.Add(mrCell); XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.AlignVert = XLAlignVertEnum.Center; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; XLStyle xlstStyleB = new XLStyle(xlbBook); xlstStyleB.AlignHorz = XLAlignHorzEnum.Left; xlstStyleB.AlignVert = XLAlignVertEnum.Top; xlstStyleB.WordWrap = false; xlstStyleB.Font = new Font("", 8, FontStyle.Regular); xlstStyleB.SetBorderColor(Color.Black); xlstStyleB.BorderBottom = XLLineStyleEnum.Thin; xlstStyleB.BorderTop = XLLineStyleEnum.Thin; xlstStyleB.BorderLeft = XLLineStyleEnum.Thin; xlstStyleB.BorderRight = XLLineStyleEnum.Thin; xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%BUILDING%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); string tmp = Func.ParseString( xlsSheet[1, 0].Value); tmp = tmp.Replace("{%NAM%}", drpYear.SelectedValue); tmp = tmp.Replace("{%THANG%}", drpMonth.SelectedValue); tmp = tmp.Replace("{%NAM_TO%}", drpYearTo.SelectedValue); tmp = tmp.Replace("{%THANG_TO%}", drpMonthTo.SelectedValue); xlsSheet[1, 0].Value = tmp; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string col01 = rowType[0].ToString(); string col02 = rowType[1].ToString(); string col03 = rowType[2].ToString(); string col04 = rowType[3].ToString(); string col05 = rowType[4].ToString(); string col06 = rowType[5].ToString(); string col07 = rowType[6].ToString(); string col08 = rowType[7].ToString(); string col09 = rowType[8].ToString(); string col10 = rowType[9].ToString(); string col11 = rowType[10].ToString(); xlsSheet[i, 0].Value = col01; xlsSheet[i, 1].Value = col02; xlsSheet[i, 2].Value = col03; xlsSheet[i, 3].Value = col04; xlsSheet[i, 4].Value = col05; xlsSheet[i, 5].Value = col06; xlsSheet[i, 6].Value = col07; xlsSheet[i, 7].Value = col08; xlsSheet[i, 8].Value = col09; xlsSheet[i, 9].Value = col10; xlsSheet[i, 10].Value = col11; xlsSheet[i, 0].Style = xlstStyle; xlsSheet[i, 1].Style = xlstStyleB; xlsSheet[i, 2].Style = xlstStyleB; xlsSheet[i, 3].Style = xlstStyleB; xlsSheet[i, 4].Style = xlstStyleB; xlsSheet[i, 5].Style = xlstStyleB; xlsSheet[i, 6].Style = xlstStyleB; xlsSheet[i, 7].Style = xlstStyleB; xlsSheet[i, 8].Style = xlstStyleB; xlsSheet[i, 9].Style = xlstStyleB; xlsSheet[i, 10].Style = xlstStyleB; xlsSheet[i, 11].Style = xlstStyleB; ++i; } ////ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('/CSV/DownloadZipFile.aspx'," + PopupWidth + "," + PopupHeight + ",'EditFlat', true);", true); ////xlsSheet[i++, 0].Value = "Ghi chú:"; //DataSet ds1 = new DataSet(); //sql = string.Empty; //sql = " SELECT *"; //sql += " FROM BD_WorkingHour"; //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1"; //sql += " Order By Name"; //using (SqlCommand cm1 = db.CreateCommand(sql)) //{ // SqlDataAdapter da1 = new SqlDataAdapter(cm1); // da1.Fill(ds1); // db.Close(); // if (ds != null) // { // xlsSheet[i++ + 1, 0].Value = "Ghi chú:"; // DataTable dt1 = ds1.Tables[0]; // foreach (DataRow rowType in dt1.Rows) // { // i++; // string Ma = rowType["WorkingHourId"].ToString(); // string Name = rowType["Name"].ToString(); // xlsSheet[i, 0].Value = Ma + ":"; // xlsSheet[i, 1].Value = Name; // } // xlsSheet[i + 1, 0].Value = "OF:"; // xlsSheet[i + 1, 1].Value = "OF: nghỉ"; // } //} //string dataPath = HttpContext.Current.Server.MapPath(@"\Building\Staff\DataTmp"); //string tmpFolder = dataPath; //if (!Directory.Exists(tmpFolder)) //{ // Directory.CreateDirectory(tmpFolder); //} //string name = "KhaiBaoLichLamViec_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls"; //string fileName = Path.Combine(tmpFolder, name); // string fileNameDes = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl_1.xlsx"); xlbBook.Save(fileNameDes); //Session["ZipFilePath"] = null; //Session["ZipFilePath"] = fileName; ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } }
/// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnExport2_Click(object sender, EventArgs e) { string buildingId = Func.ParseString(Session["__BUILDINGID__"]); string sql = "Select CustomerId, Name From Customer Where BuildingId = '" + buildingId + "' and DelFlag = 0 order by CustomerId"; Hashtable CusList = new Hashtable(); DataTable dtCus = DbHelper.GetDataTable(sql); foreach (DataRow drCus in dtCus.Rows) { if (!CusList.Contains(drCus["CustomerId"].ToString())) { CusList.Add(drCus["CustomerId"].ToString(), drCus["Name"].ToString()); } } Hashtable PaymentList = new Hashtable(); sql = "Select * from v_PaymentBillDetailGeneral Where BuildingId = '" + buildingId + "' order by CustomerId"; DataTable dt = DbHelper.GetDataTable(sql); foreach (DataRow dr in dt.Rows) { string CustomerId = dr["CustomerId"].ToString(); string key = CustomerId; DeptInfo tmp; if (!PaymentList.Contains(key)) { tmp = new DeptInfo(); tmp.CustomerId = CustomerId; tmp.Customer = Func.ParseString(CusList[CustomerId]); PaymentList.Add(key, tmp); } string PaymentType = dr["PaymentType"].ToString(); decimal MoneyUSD = Convert.ToDecimal(dr["MoneyUSD"]); decimal MoneyVND = Convert.ToDecimal(dr["MoneyVND"]); decimal PaidUSD = Convert.ToDecimal(dr["PaidUSD"]); decimal PaidVND = Convert.ToDecimal(dr["PaidVND"]); tmp = (DeptInfo)PaymentList[key]; switch (PaymentType) { case "1": tmp.RentUSD = MoneyUSD; tmp.RentVND = MoneyVND; tmp.RentPaidUSD = PaidUSD; tmp.RentPaidVND = PaidVND; break; case "2": tmp.ManagerUSD = MoneyUSD; tmp.ManagerVND = MoneyVND; tmp.ManagerPaidUSD = PaidUSD; tmp.ManagerPaidVND = PaidVND; break; case "3": tmp.ParkingUSD = MoneyUSD; tmp.ParkingVND = MoneyVND; tmp.ParkingPaidUSD = PaidUSD; tmp.ParkingPaidVND = PaidVND; break; case "4": tmp.ExtraUSD = MoneyUSD; tmp.ExtraVND = MoneyVND; tmp.ExtraPaidUSD = PaidUSD; tmp.ExtraPaidVND = PaidVND; break; case "5": tmp.ElecUSD = MoneyUSD; tmp.ElecVND = MoneyVND; tmp.ElecPaidUSD = PaidUSD; tmp.ElecPaidVND = PaidVND; break; case "6": tmp.WaterUSD = MoneyUSD; tmp.WaterVND = MoneyVND; tmp.WaterPaidUSD = PaidUSD; tmp.WaterPaidVND = PaidVND; break; case "7": tmp.ServiceUSD = MoneyUSD; tmp.ServiceVND = MoneyVND; tmp.ServicePaidUSD = PaidUSD; tmp.ServicePaidVND = PaidVND; break; case "8": tmp.BookingUSD = MoneyUSD; tmp.BookingVND = MoneyVND; tmp.BookingPaidUSD = PaidUSD; tmp.BookingPaidVND = PaidVND; break; default: break; } } C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BaoCaoCongNo_TongQuat.xlsx"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoCongNo")) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoCongNo")); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoCongNo\BaoCaoCongNo_TongQuat" + strDT + ".xlsx"; string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/BaoCaoCongNo/BaoCaoCongNo_TongQuat" + strDT + ".xlsx"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLStyle xlstStyle2 = new XLStyle(xlbBook); xlstStyle2.AlignVert = XLAlignVertEnum.Center; xlstStyle2.WordWrap = false; xlstStyle2.Font = new Font("", 8, FontStyle.Regular); xlstStyle2.SetBorderColor(Color.Black); xlstStyle2.BorderBottom = XLLineStyleEnum.Thin; xlstStyle2.BorderTop = XLLineStyleEnum.Thin; xlstStyle2.BorderLeft = XLLineStyleEnum.Thin; xlstStyle2.BorderRight = XLLineStyleEnum.Thin; xlstStyle2.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyle1 = new XLStyle(xlbBook); xlstStyle1.AlignVert = XLAlignVertEnum.Center; xlstStyle1.WordWrap = false; xlstStyle1.Font = new Font("", 8, FontStyle.Regular); xlstStyle1.SetBorderColor(Color.Black); xlstStyle1.BorderBottom = XLLineStyleEnum.Thin; xlstStyle1.BorderTop = XLLineStyleEnum.Thin; xlstStyle1.BorderLeft = XLLineStyleEnum.Thin; xlstStyle1.BorderRight = XLLineStyleEnum.Thin; xlstStyle1.Format = "#,##0.0_);(#,##0.0)"; XLStyle xlstStyle0 = new XLStyle(xlbBook); xlstStyle0.AlignVert = XLAlignVertEnum.Center; xlstStyle0.WordWrap = false; xlstStyle0.Font = new Font("", 8, FontStyle.Regular); xlstStyle0.SetBorderColor(Color.Black); xlstStyle0.BorderBottom = XLLineStyleEnum.Thin; xlstStyle0.BorderTop = XLLineStyleEnum.Thin; xlstStyle0.BorderLeft = XLLineStyleEnum.Thin; xlstStyle0.BorderRight = XLLineStyleEnum.Thin; xlstStyle0.Format = "#,##0_);(#,##0)"; XLStyle xlstStyleB2 = new XLStyle(xlbBook); xlstStyleB2.AlignHorz = XLAlignHorzEnum.Right; xlstStyleB2.AlignVert = XLAlignVertEnum.Center; xlstStyleB2.WordWrap = false; xlstStyleB2.Font = new Font("", 8, FontStyle.Bold); xlstStyleB2.SetBorderColor(Color.Black); xlstStyleB2.BorderBottom = XLLineStyleEnum.Thin; xlstStyleB2.BorderTop = XLLineStyleEnum.Thin; xlstStyleB2.BorderLeft = XLLineStyleEnum.Thin; xlstStyleB2.BorderRight = XLLineStyleEnum.Thin; xlstStyleB2.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleB1 = new XLStyle(xlbBook); xlstStyleB1.AlignHorz = XLAlignHorzEnum.Right; xlstStyleB1.AlignVert = XLAlignVertEnum.Center; xlstStyleB1.WordWrap = false; xlstStyleB1.Font = new Font("", 8, FontStyle.Bold); xlstStyleB1.SetBorderColor(Color.Black); xlstStyleB1.BorderBottom = XLLineStyleEnum.Thin; xlstStyleB1.BorderTop = XLLineStyleEnum.Thin; xlstStyleB1.BorderLeft = XLLineStyleEnum.Thin; xlstStyleB1.BorderRight = XLLineStyleEnum.Thin; xlstStyleB1.Format = "#,##0.0_);(#,##0.0)"; XLStyle xlstStyleB0 = new XLStyle(xlbBook); xlstStyleB0.AlignHorz = XLAlignHorzEnum.Right; xlstStyleB0.AlignVert = XLAlignVertEnum.Center; xlstStyleB0.WordWrap = false; xlstStyleB0.Font = new Font("", 8, FontStyle.Bold); xlstStyleB0.SetBorderColor(Color.Black); xlstStyleB0.BorderBottom = XLLineStyleEnum.Thin; xlstStyleB0.BorderTop = XLLineStyleEnum.Thin; xlstStyleB0.BorderLeft = XLLineStyleEnum.Thin; xlstStyleB0.BorderRight = XLLineStyleEnum.Thin; xlstStyleB0.Format = "#,##0_);(#,##0)"; decimal[] AllSumUsd = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; decimal[] AllSumVnd = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; string sheet = "BaoCao"; XLSheet xlsSheet = xlbBook.Sheets[sheet]; int i = 5; xlsSheet[0, 1].Value = xlsSheet[0, 1].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + buildingId + "'")); int j = 1; foreach (DictionaryEntry tmp in PaymentList) { string key = (string)tmp.Key; DeptInfo dept = (DeptInfo)tmp.Value; xlsSheet[i, 0 + j].Value = Func.ParseString(i - 4); xlsSheet[i, 1 + j].Value = dept.CustomerId; xlsSheet[i, 2 + j].Value = dept.Customer; xlsSheet[i, 3 + j].Value = dept.RentUSD; xlsSheet[i, 4 + j].Value = dept.RentVND; xlsSheet[i, 5 + j].Value = dept.ManagerUSD; xlsSheet[i, 6 + j].Value = dept.ManagerVND; xlsSheet[i, 7 + j].Value = dept.ParkingUSD; xlsSheet[i, 8 + j].Value = dept.ParkingVND; xlsSheet[i, 9 + j].Value = dept.ExtraUSD; xlsSheet[i, 10 + j].Value = dept.ExtraVND; //xlsSheet[i, 11 + j].Value = dept.ElecUSD; xlsSheet[i, 11 + j].Value = dept.ElecVND; //xlsSheet[i, 13 + j].Value = dept.WaterUSD; xlsSheet[i, 12 + j].Value = dept.WaterVND; xlsSheet[i, 13 + j].Value = dept.ServiceUSD; xlsSheet[i, 14 + j].Value = dept.ServiceVND; xlsSheet[i, 15 + j].Value = dept.BookingUSD; xlsSheet[i, 16 + j].Value = dept.BookingVND; xlsSheet[i, 17 + j].Value = dept.SumUSD(); xlsSheet[i, 18 + j].Value = dept.SumVND(); //----------------------- xlsSheet[i, j + 19].Value = dept.RentPaidUSD; xlsSheet[i, j + 20].Value = dept.RentPaidVND; xlsSheet[i, j + 21].Value = dept.ManagerPaidUSD; xlsSheet[i, j + 22].Value = dept.ManagerPaidVND; xlsSheet[i, j + 23].Value = dept.ParkingPaidUSD; xlsSheet[i, j + 24].Value = dept.ParkingPaidVND; xlsSheet[i, j + 25].Value = dept.ExtraPaidUSD; xlsSheet[i, j + 26].Value = dept.ExtraPaidVND; //xlsSheet[i, 11 + j + 18].Value = dept.ElecPaidUSD; xlsSheet[i, j + 27].Value = dept.ElecPaidVND; //xlsSheet[i, 13 + j + 18].Value = dept.WaterPaidUSD; xlsSheet[i, j + 28].Value = dept.WaterPaidVND; xlsSheet[i, j + 29].Value = dept.ServicePaidUSD; xlsSheet[i, j + 30].Value = dept.ServicePaidVND; xlsSheet[i, j + 31].Value = dept.BookingPaidUSD; xlsSheet[i, j + 32].Value = dept.BookingPaidVND; xlsSheet[i, j + 33].Value = dept.SumPaidUSD(); xlsSheet[i, j + 34].Value = dept.SumPaidVND(); xlsSheet[i, j + 35].Value = dept.SumUSD() - dept.SumPaidUSD(); xlsSheet[i, j + 36].Value = dept.SumVND() - dept.SumPaidVND(); ///////////////// AllSumUsd[0] += dept.RentUSD; AllSumVnd[0] += dept.RentVND; AllSumUsd[1] += dept.ManagerUSD; AllSumVnd[1] += dept.ManagerVND; AllSumUsd[2] += dept.ParkingUSD; AllSumVnd[2] += dept.ParkingVND; AllSumUsd[3] += dept.ExtraUSD; AllSumVnd[3] += dept.ExtraVND; AllSumUsd[4] += dept.ElecUSD; AllSumVnd[4] += dept.ElecVND; AllSumUsd[5] += dept.WaterUSD; AllSumVnd[5] += dept.WaterVND; AllSumUsd[6] += dept.ServiceUSD; AllSumVnd[6] += dept.ServiceVND; AllSumUsd[7] += dept.BookingUSD; AllSumVnd[7] += dept.BookingVND; AllSumUsd[8] += dept.SumUSD(); AllSumVnd[8] += dept.SumVND(); //----------------------- AllSumUsd[9] += dept.RentPaidUSD; AllSumVnd[9] += dept.RentPaidVND; AllSumUsd[10] += dept.ManagerPaidUSD; AllSumVnd[10] += dept.ManagerPaidVND; AllSumUsd[11] += dept.ParkingPaidUSD; AllSumVnd[11] += dept.ParkingPaidVND; AllSumUsd[12] += dept.ExtraPaidUSD; AllSumVnd[12] += dept.ExtraPaidVND; AllSumUsd[13] += dept.ElecPaidUSD; AllSumVnd[13] += dept.ElecPaidVND; AllSumUsd[14] += dept.WaterPaidUSD; AllSumVnd[14] += dept.WaterPaidVND; AllSumUsd[15] += dept.ServicePaidUSD; AllSumVnd[15] += dept.ServicePaidVND; AllSumUsd[16] += dept.BookingPaidUSD; AllSumVnd[16] += dept.BookingPaidVND; AllSumUsd[17] += dept.SumPaidUSD(); AllSumVnd[17] += dept.SumPaidVND(); AllSumUsd[18] += dept.SumUSD() - dept.SumPaidUSD(); AllSumVnd[18] += dept.SumVND() - dept.SumPaidVND(); for (int m = 0; m < 37; m++) { xlsSheet[i, m + j].Style = xlstStyle1; } //////////////////////////////////////////// xlsSheet[i, 4 + j].Style = xlstStyle0; xlsSheet[i, 6 + j].Style = xlstStyle0; xlsSheet[i, 8 + j].Style = xlstStyle0; xlsSheet[i, 10 + j].Style = xlstStyle0; xlsSheet[i, 11 + j].Style = xlstStyle0; xlsSheet[i, 12 + j].Style = xlstStyle0; xlsSheet[i, 14 + j].Style = xlstStyle0; xlsSheet[i, 16 + j].Style = xlstStyle0; xlsSheet[i, 18 + j].Style = xlstStyle0; xlsSheet[i, j + 20].Style = xlstStyle0; xlsSheet[i, j + 22].Style = xlstStyle0; xlsSheet[i, j + 24].Style = xlstStyle0; xlsSheet[i, j + 26].Style = xlstStyle0; xlsSheet[i, j + 27].Style = xlstStyle0; xlsSheet[i, j + 28].Style = xlstStyle0; xlsSheet[i, j + 30].Style = xlstStyle0; xlsSheet[i, j + 32].Style = xlstStyle0; xlsSheet[i, j + 34].Style = xlstStyle0; xlsSheet[i, j + 36].Style = xlstStyle0; i++; } xlsSheet[i, 3 + j].Value = AllSumUsd[0]; xlsSheet[i, 4 + j].Value = AllSumVnd[0]; xlsSheet[i, 5 + j].Value = AllSumUsd[1]; xlsSheet[i, 6 + j].Value = AllSumVnd[1]; xlsSheet[i, 7 + j].Value = AllSumUsd[2]; xlsSheet[i, 8 + j].Value = AllSumVnd[2]; xlsSheet[i, 9 + j].Value = AllSumUsd[3]; xlsSheet[i, 10 + j].Value = AllSumVnd[3]; xlsSheet[i, 11 + j].Value = AllSumVnd[4]; xlsSheet[i, 12 + j].Value = AllSumVnd[5]; xlsSheet[i, 13 + j].Value = AllSumUsd[6]; xlsSheet[i, 14 + j].Value = AllSumVnd[6]; xlsSheet[i, 15 + j].Value = AllSumUsd[7]; xlsSheet[i, 16 + j].Value = AllSumVnd[7]; xlsSheet[i, 17 + j].Value = AllSumUsd[8]; xlsSheet[i, 18 + j].Value = AllSumVnd[8]; //----------------------- //----------------------- xlsSheet[i, j + 19].Value = AllSumUsd[9]; xlsSheet[i, j + 20].Value = AllSumVnd[9]; xlsSheet[i, j + 21].Value = AllSumUsd[10]; xlsSheet[i, j + 22].Value = AllSumVnd[10]; xlsSheet[i, j + 23].Value = AllSumUsd[11]; xlsSheet[i, j + 24].Value = AllSumVnd[11]; xlsSheet[i, j + 25].Value = AllSumUsd[12]; xlsSheet[i, j + 26].Value = AllSumVnd[12]; xlsSheet[i, j + 27].Value = AllSumVnd[13]; xlsSheet[i, j + 28].Value = AllSumVnd[14]; xlsSheet[i, j + 29].Value = AllSumUsd[15]; xlsSheet[i, j + 30].Value = AllSumVnd[15]; xlsSheet[i, j + 31].Value = AllSumUsd[16]; xlsSheet[i, j + 32].Value = AllSumVnd[16]; xlsSheet[i, j + 33].Value = AllSumUsd[17]; xlsSheet[i, j + 34].Value = AllSumVnd[17]; xlsSheet[i, j + 35].Value = AllSumUsd[18]; xlsSheet[i, j + 36].Value = AllSumVnd[18]; XLCellRange mrCell = new XLCellRange(i, i, 1, 3); xlsSheet.MergedCells.Add(mrCell); xlsSheet[i, 1].Value = "Tổng Cộng"; for (int m = 0; m < 37; m++) { xlsSheet[i, m + j].Style = xlstStyleB1; } ///////////////////////////////////////// xlsSheet[i, 4 + j].Style = xlstStyleB0; xlsSheet[i, 6 + j].Style = xlstStyleB0; xlsSheet[i, 8 + j].Style = xlstStyleB0; xlsSheet[i, 10 + j].Style = xlstStyleB0; xlsSheet[i, 11 + j].Style = xlstStyleB0; xlsSheet[i, 12 + j].Style = xlstStyleB0; xlsSheet[i, 14 + j].Style = xlstStyleB0; xlsSheet[i, 16 + j].Style = xlstStyleB0; xlsSheet[i, 18 + j].Style = xlstStyleB0; xlsSheet[i, j + 20].Style = xlstStyleB0; xlsSheet[i, j + 22].Style = xlstStyleB0; xlsSheet[i, j + 24].Style = xlstStyleB0; xlsSheet[i, j + 26].Style = xlstStyleB0; xlsSheet[i, j + 27].Style = xlstStyleB0; xlsSheet[i, j + 28].Style = xlstStyleB0; xlsSheet[i, j + 30].Style = xlstStyleB0; xlsSheet[i, j + 32].Style = xlstStyleB0; xlsSheet[i, j + 34].Style = xlstStyleB0; xlsSheet[i, j + 36].Style = xlstStyleB0; ///////////////////////////////////////// XLSheet source = xlbBook.Sheets["tpl"]; for (int row = 2; row <= 4; row++) { for (int col = 1; col <= 17; col++) { xlsSheet[row, col].Style = source[row, col].Style; xlsSheet[row, col].Value = source[row, col].Value; } } for (int row = 6; row <= 8; row++) { for (int col = 4; col <= 23; col++) { xlsSheet[row - 4, col + 14].Style = source[row, col].Style; xlsSheet[row - 4, col + 14].Value = source[row, col].Value; } } mrCell = new XLCellRange(2, 4, 1, 1); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(2, 4, 2, 2); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(2, 4, 3, 3); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(2, 2, 4, 17); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(2, 2, 20, 33); xlsSheet.MergedCells.Add(mrCell); for (int m = 0; m < 17; m++) { mrCell = new XLCellRange(3, 3, 4 + m, 5 + m); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(3, 3, 6 + m, 7 + m); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(3, 3, 8 + m, 9 + m); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(3, 3, 10 + m, 11 + m); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(3, 3, 14 + m, 15 + m); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(3, 3, 16 + m, 17 + m); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(2, 3, 18 + m, 19 + m); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(2, 3, 20 + m, 21 + m); xlsSheet.MergedCells.Add(mrCell); m += 15; } xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnExport_Click(object sender, EventArgs e) { string[] dateOfWeekVN = { "T2", "T3", "T4", "T5", "T6", "T7", "CN" }; string[] dateOfWeekEN = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sartuday", "Sunday" }; Dictionary<string, string> dictionary = new Dictionary<string, string>(); dictionary.Add("monday", "T2"); dictionary.Add("tuesday", "T3"); dictionary.Add("wednesday", "T4"); dictionary.Add("thursday", "T5"); dictionary.Add("friday", "T6"); dictionary.Add("saturday", "T7"); dictionary.Add("sunday", "CN"); DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT *"; sql += " FROM BD_Staff"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1 and jobtypeid = '"+ hidJobType.Value +"'"; sql += " Order By Name"; using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); db.Close(); if (ds != null) { mvMessage.SetCompleteMessage("File CSV đã xuất thành công."); C1XLBook xlbBook = new C1XLBook(); XLSheet xlsSheet = xlbBook.Sheets[0]; xlsSheet.Name = drpMonth.SelectedValue + "_" + drpYear.SelectedValue; int i = 0; XLCellRange mrCell = new XLCellRange(0, 0, 0, 2); xlsSheet.MergedCells.Add(mrCell); XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.Font = new Font("", 12, FontStyle.Bold); xlstStyle.SetBorderColor(Color.Black); xlsSheet[i, 0].Value = "Tháng " + drpMonth.SelectedValue + "/" + drpYear.SelectedValue; xlsSheet[i, 0].Style = xlstStyle; xlsSheet[i + 1, 0].Value = "STT"; xlsSheet[i + 1, 1].Value = "Mã Nhân Viên"; xlsSheet[i + 1, 2].Value = "Họ và Tên"; XLStyle xlstStyle01 = new XLStyle(xlbBook); xlstStyle01.AlignHorz = XLAlignHorzEnum.Center; xlstStyle01.Font = new Font("", 10, FontStyle.Bold); xlstStyle.SetBorderColor(Color.Black); for (int j = 1; j <= 31; j++) { xlsSheet[i, 2 + j].Value = j; DateTime date = new DateTime(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue), j); xlsSheet[i + 1, 2 + j].Value = dictionary[date.DayOfWeek.ToString().ToLower()]; xlsSheet[i, 2 + j].Style = xlstStyle01; xlsSheet[i + 1, 2 + j].Style = xlstStyle01; if (j == DateTime.DaysInMonth(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue))) { break; } } i++; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { int No = i; i++; string StaffId = rowType["StaffId"].ToString(); string Name = rowType["Name"].ToString(); xlsSheet[i, 0].Value = No; xlsSheet[i, 1].Value = StaffId; xlsSheet[i, 2].Value = Name; xlsSheet[i, 0].Style = xlstStyle01; xlsSheet[i, 1].Style = xlstStyle01; xlsSheet[i, 2].Style = xlstStyle01; } //ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('/CSV/DownloadZipFile.aspx'," + PopupWidth + "," + PopupHeight + ",'EditFlat', true);", true); //xlsSheet[i++, 0].Value = "Ghi chú:"; DataSet ds1 = new DataSet(); sql = string.Empty; sql = " SELECT *"; sql += " FROM BD_WorkingHour"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1 and jobtypeid = '"+ hidJobType.Value +"'"; sql += " Order By Name"; using (SqlCommand cm1 = db.CreateCommand(sql)) { SqlDataAdapter da1 = new SqlDataAdapter(cm1); da1.Fill(ds1); db.Close(); if (ds != null) { xlsSheet[i++ + 1, 0].Value = "Ghi chú:"; DataTable dt1 = ds1.Tables[0]; foreach (DataRow rowType in dt1.Rows) { i++; string Ma = rowType["WorkingHourId"].ToString(); string Name = rowType["Name"].ToString(); xlsSheet[i, 0].Value = Ma + ":"; xlsSheet[i, 1].Value = Name; } xlsSheet[i + 1, 0].Value = "OF:"; xlsSheet[i + 1, 1].Value = "OF: nghỉ"; } } string dataPath = HttpContext.Current.Server.MapPath(@"\Building\Staff\DataTmp"); string tmpFolder = dataPath; if (!Directory.Exists(tmpFolder)) { Directory.CreateDirectory(tmpFolder); } string name ="KhaiBaoLichLamViec_"+ DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls"; string fileName = Path.Combine(tmpFolder, name); xlbBook.Save(fileName); //Session["ZipFilePath"] = null; //Session["ZipFilePath"] = fileName; ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../Staff/DataTmp/" + name + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } }
protected void btnExport_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT *"; sql += " FROM vBuildingRoomInfo"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); db.Close(); string selectDate = Func.FormatYYYYmmdd(txtDate.Text); if (ds != null) { C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\TongHopDienTichTrong.xls"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + strDT + ".xls"; string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/TongHopDienTich" + strDT + ".xls"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLSheet xlsSheet = xlbBook.Sheets["TongHop"]; //xlsSheet.Name = drpMonth.SelectedValue + "_" + drpYear.SelectedValue; int i = 4; XLCellRange mrCell = new XLCellRange(0, 0, 0, 2); xlsSheet.MergedCells.Add(mrCell); XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.Font = new Font("", 12, FontStyle.Bold); xlstStyle.SetBorderColor(Color.Black); XLStyle xlstStyle01 = new XLStyle(xlbBook); xlstStyle01.AlignHorz = XLAlignHorzEnum.Center; xlstStyle01.Font = new Font("", 10, FontStyle.Bold); xlstStyle.SetBorderColor(Color.Black); xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%BUILDING%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%NGAY%}", txtDate.Text); DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string col01 = rowType[0].ToString(); string col02 = rowType[1].ToString(); string col03 = rowType[2].ToString(); string col04 = rowType[3].ToString(); string col05 = rowType[4].ToString(); string col06 = rowType[5].ToString(); xlsSheet[i, 0].Value = col02; xlsSheet[i, 1].Value = col03; xlsSheet[i, 2].Value = col04; xlsSheet[i, 3].Value = col05; xlsSheet[i, 4].Value = DbHelper.GetScalar("Select sum(Area) from vRentRoom Where BuildingId = '" + col01 + "' and Regional ='" + col02 + "' and Floor = '" + col03 + "' and (BeginContract <= '" + selectDate + "' and (EndContract >= '" + selectDate + "' or EndContract is null))"); xlsSheet[i, 5].Value = col05; xlsSheet[i, 0].Style = xlstStyle01; xlsSheet[i, 1].Style = xlstStyle01; xlsSheet[i, 2].Style = xlstStyle01; ++i; } ////ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('/CSV/DownloadZipFile.aspx'," + PopupWidth + "," + PopupHeight + ",'EditFlat', true);", true); ////xlsSheet[i++, 0].Value = "Ghi chú:"; //DataSet ds1 = new DataSet(); //sql = string.Empty; //sql = " SELECT *"; //sql += " FROM BD_WorkingHour"; //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1"; //sql += " Order By Name"; //using (SqlCommand cm1 = db.CreateCommand(sql)) //{ // SqlDataAdapter da1 = new SqlDataAdapter(cm1); // da1.Fill(ds1); // db.Close(); // if (ds != null) // { // xlsSheet[i++ + 1, 0].Value = "Ghi chú:"; // DataTable dt1 = ds1.Tables[0]; // foreach (DataRow rowType in dt1.Rows) // { // i++; // string Ma = rowType["WorkingHourId"].ToString(); // string Name = rowType["Name"].ToString(); // xlsSheet[i, 0].Value = Ma + ":"; // xlsSheet[i, 1].Value = Name; // } // xlsSheet[i + 1, 0].Value = "OF:"; // xlsSheet[i + 1, 1].Value = "OF: nghỉ"; // } //} //string dataPath = HttpContext.Current.Server.MapPath(@"\Building\Staff\DataTmp"); //string tmpFolder = dataPath; //if (!Directory.Exists(tmpFolder)) //{ // Directory.CreateDirectory(tmpFolder); //} //string name = "KhaiBaoLichLamViec_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls"; //string fileName = Path.Combine(tmpFolder, name); // string fileNameDes = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl_1.xlsx"); xlbBook.Save(fileNameDes); //Session["ZipFilePath"] = null; //Session["ZipFilePath"] = fileName; ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } }
public void DoExport() { int rBillNo = 0; int cBillNo = 1; int rBillDate = 0; int cBillDate = 10; int rBillMonth = 2; int cBillMonth = 0; int rContact = 5; int cContact = 3; int rCustomer = 5; int cCustomer = 7; int rContract = 7; int cContract = 1; int rRate = 11; int cRate = 9; int rRateDate = 11; int cRateDate = 12; int rRent = 15; int rManager = 23; int rParking = 31; int rExtra = 39; int rElec = 47; int rWater = 55; int rService = 63; int rPaid = 70; int rDept = 77; int rOffice = 88; int cOffice = 3; int rPhone = 89; int cPhone = 3; int rBank = 88; int cBank = 7; int rAccountName = 89; int cAccountName = 7; int rAccount = 90; int cAccount = 7; int rSum = 81; int cSum = 12; int rSumVND = 80; int cSumVND = 12; int rSumRead = 82; int cSumRead = 13; //// using (SqlDatabase db = new SqlDatabase()) { DataSet ds = new DataSet(); DataSet dsCus = new DataSet(); string sql = string.Empty; string Bank = ""; string Account = ""; string AccountName = ""; string Office = ""; string OfficeAddress = ""; string OfficePhone = ""; ds = new DataSet(); sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone"; sql += " FROM Mst_Building"; sql += " WHERE BuildingId = '" + sBuildingId + "' "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { Bank = rowType["Bank"].ToString(); Account = rowType["Account"].ToString(); AccountName = rowType["AccountName"].ToString(); Office = rowType["Office"].ToString(); OfficeAddress = rowType["OfficeAddress"].ToString(); OfficePhone = rowType["OfficePhone"].ToString(); } } } //Danh sách Bill sql = " Select BillDate,UsdExchangeDate,UsdExchange,BillNo,B.Name,B.ContactName,A.CustomerId, A.YearMonths, A.Id "; sql += " From PaymentBillInfo A, Customer B"; sql += " Where A.BuildingId = B.BuildingId and A.CustomerId = B.CustomerId and B.DelFlag = 0 and A.BuildingId = '" + sBuildingId + "' and YearMonth = '" + sYearMonth + "'"; string BillDate = ""; string UsdExchangeDate = ""; string UsdExchange = ""; string BillNo = ""; string Name = ""; string ContactName = ""; string CustomerId = ""; string lsYearmonth = ""; string id = ""; string maxYearMonth = ""; using (SqlCommand cmCus = db.CreateCommand(sql)) { SqlDataAdapter daCus = new SqlDataAdapter(cmCus); daCus.Fill(dsCus); if (dsCus != null) { string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); DataTable dtCus = dsCus.Tables[0]; foreach (DataRow rowCus in dtCus.Rows) { BillDate = rowCus[0].ToString(); UsdExchangeDate = rowCus[1].ToString(); UsdExchange = rowCus[2].ToString(); BillNo = rowCus[3].ToString(); Name = rowCus[4].ToString(); ContactName = rowCus[5].ToString(); CustomerId = rowCus[6].ToString(); lsYearmonth = rowCus[7].ToString(); id = rowCus[8].ToString(); string[] strTmpYearMonth = lsYearmonth.Split(','); for (int l = 0; l < strTmpYearMonth.Length; l++) { string tmp = strTmpYearMonth[l]; if (maxYearMonth == "") maxYearMonth = tmp; if (maxYearMonth.CompareTo(tmp) < 0) maxYearMonth = tmp; } C1XLBook xlbBook = new C1XLBook(); //ShowData(drpYear.SelectedValue + drpMonth.SelectedValue); XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.AlignVert = XLAlignVertEnum.Center; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; xlstStyle.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleH = new XLStyle(xlbBook); xlstStyleH.AlignHorz = XLAlignHorzEnum.Center; xlstStyleH.AlignVert = XLAlignVertEnum.Center; xlstStyleH.Font = new Font("", 8, FontStyle.Bold); xlstStyleH.SetBorderColor(Color.Black); xlstStyleH.BorderBottom = XLLineStyleEnum.Thin; xlstStyleH.BorderTop = XLLineStyleEnum.Thin; xlstStyleH.BorderLeft = XLLineStyleEnum.Thin; xlstStyleH.BorderRight = XLLineStyleEnum.Thin; xlstStyleH.WordWrap = true; XLStyle xlstStyleSum = new XLStyle(xlbBook); xlstStyleSum.AlignHorz = XLAlignHorzEnum.Right; xlstStyleSum.AlignVert = XLAlignVertEnum.Center; xlstStyleSum.Font = new Font("", 8, FontStyle.Bold); xlstStyleSum.SetBorderColor(Color.Black); xlstStyleSum.BorderBottom = XLLineStyleEnum.Thin; xlstStyleSum.BorderTop = XLLineStyleEnum.Thin; xlstStyleSum.BorderLeft = XLLineStyleEnum.Thin; xlstStyleSum.BorderRight = XLLineStyleEnum.Thin; xlstStyleSum.WordWrap = true; string fileName = sFilePath + @"\Template\BillTongQuat.xlsx"; if (!Directory.Exists(sFilePath + @"\Building\" + sBuildingId + @"\Bill")) { Directory.CreateDirectory(sFilePath + @"\Report\Building\" + sBuildingId + @"\Bill"); } string strFilePath = sFilePath + @"\Building\" + sBuildingId + @"\Bill\Bill" + "_" + CustomerId + "_" + BillNo + id + "_" + strDT + ".xlsx"; string strFilePathExport = sFilePath.Replace(@"\", "/") + @"/Building/" + sBuildingId + @"/Bill/Bill" + "_" + CustomerId + "_" + BillNo + id + "_" + strDT + ".xlsx"; string fileNameDes = strFilePath; //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + sBuildingId + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLSheet xlsSheet = xlbBook.Sheets["TongHop"]; XLSheet xlsSheetEn = xlbBook.Sheets["TongHop_En"]; //Thông tin về Ngân hàng của Tòa Nhà xlsSheet[rOffice, cOffice].Value = xlsSheet[rOffice, cOffice].Value.ToString().Replace("{%VAN_PHONG%}", Office); xlsSheet[rPhone, cPhone].Value = xlsSheet[rPhone, cPhone].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone); xlsSheet[rBank, cBank].Value = xlsSheet[rBank, cBank].Value.ToString().Replace("{%NGAN_HANG%}", Bank); xlsSheet[rAccountName, cAccountName].Value = xlsSheet[rAccountName, cAccountName].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName); xlsSheet[rAccount, cAccount].Value = xlsSheet[rAccount, cAccount].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account); //Thông tin về Ngân hàng của Tòa Nhà //Customer xlsSheet[rCustomer, cCustomer].Value = xlsSheet[rCustomer, cCustomer].Value.ToString().Replace("{%TEN_CONG_TY%}", Name); //Contact xlsSheet[rContact, cContact].Value = xlsSheet[rContact, cContact].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName); //Bill No xlsSheet[rBillNo, cBillNo].Value = xlsSheet[rBillNo, cBillNo].Value.ToString().Replace("{%BILL_NO%}", BillNo); /////////////////////////////////////////// //Thông tin về Ngân hàng của Tòa Nhà xlsSheetEn[rOffice, cOffice].Value = xlsSheetEn[rOffice, cOffice].Value.ToString().Replace("{%VAN_PHONG%}", Office); xlsSheetEn[rPhone, cPhone].Value = xlsSheetEn[rPhone, cPhone].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone); xlsSheetEn[rBank, cBank].Value = xlsSheetEn[rBank, cBank].Value.ToString().Replace("{%NGAN_HANG%}", Bank); xlsSheetEn[rAccountName, cAccountName].Value = xlsSheetEn[rAccountName, cAccountName].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName); xlsSheetEn[rAccount, cAccount].Value = xlsSheetEn[rAccount, cAccount].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account); //Thông tin về Ngân hàng của Tòa Nhà //Customer xlsSheetEn[rCustomer, cCustomer].Value = xlsSheetEn[rCustomer, cCustomer].Value.ToString().Replace("{%TEN_CONG_TY%}", Name); //Contact xlsSheetEn[rContact, cContact].Value = xlsSheetEn[rContact, cContact].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName); //Bill No xlsSheetEn[rBillNo, cBillNo].Value = xlsSheetEn[rBillNo, cBillNo].Value.ToString().Replace("{%BILL_NO%}", BillNo); /////////////////////////////////////////// //Ngay Thang Nam DateTime dtime = DateTime.Today; string strTmp = xlsSheet[rBillDate, cBillDate].Value.ToString().Replace("{%NGAY%}", dtime.ToString("dd")); strTmp = strTmp.Replace("{%THANG%}", dtime.ToString("MM")); xlsSheet[rBillDate, cBillDate].Value = strTmp.Replace("{%NAM%}", dtime.ToString("yyyy")); strTmp = xlsSheetEn[rBillDate, cBillDate].Value.ToString().Replace("{%NGAY%}", dtime.ToString("dd")); strTmp = strTmp.Replace("{%THANG%}", dtime.ToString("MM")); xlsSheetEn[rBillDate, cBillDate].Value = strTmp.Replace("{%NAM%}", dtime.ToString("yyyy")); //Nam xlsSheet[rBillMonth, cBillMonth].Value = xlsSheet[rBillMonth, cBillMonth].Value.ToString().Replace("{%NAM_THANG%}", sMonth + "/" + sYear); xlsSheetEn[rBillMonth, cBillMonth].Value = xlsSheetEn[rBillMonth, cBillMonth].Value.ToString().Replace("{%NAM_THANG%}", sMonth + "/" + sYear); //Thông tin Tỉ giá xlsSheet[rRate, cRate].Value = xlsSheet[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", UsdExchange); xlsSheet[rRateDate, cRateDate].Value = xlsSheet[rRateDate, cRateDate].Value.ToString().Replace("{%NGAY_AP_DUNG%}", UsdExchangeDate); //Thông tin Tỉ giá xlsSheetEn[rRate, cRate].Value = xlsSheetEn[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", UsdExchange); xlsSheetEn[rRateDate, cRateDate].Value = xlsSheetEn[rRateDate, cRateDate].Value.ToString().Replace("{%NGAY_AP_DUNG%}", UsdExchangeDate); Hashtable contractIdLst = new Hashtable(); string contract = ""; //// //Thue phong ds = new DataSet(); sql = " Select A.*, B.ContractDate"; sql += " FROM PaymentRoom A, RentContract B"; sql += " WHERE A.ContractId = B.ContractId and A.BuildingId = B.BuildingId and A.BuildingId = '" + sBuildingId + "' and A.CustomerId = '" + CustomerId + "' and A.YearMonth in (" + lsYearmonth + ")"; int sumRow = 0; int j = 0; decimal[] LastSumPriceVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; decimal[] LastSumPriceUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; decimal PaidPriceVND = 0; decimal PaidPriceUSD = 0; int line = 0; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rRent - 3 + j; XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; int k = 0; foreach (DataRow rowType in dt.Rows) { decimal tmp01 = Convert.ToDecimal(rowType["LastRentSumUSD"]); decimal tmp02 = Convert.ToDecimal(rowType["LastRentSumVND"]); string ContractId = Func.ParseString(rowType["ContractId"]); string ContractNo = Func.ParseString(rowType["ContractNo"]); string YearMonth = Func.ParseString(rowType["YearMonth"]); string Area = Func.ParseString(rowType["Area"]); string Regional = Func.ParseString(rowType["Regional"]); string Floor = Func.ParseString(rowType["Floor"]); string BeginContract = Func.ParseString(rowType["ContractDate"]); if (!contractIdLst.ContainsKey(ContractId + "(" + Func.FormatDMY(BeginContract) + ")")) { contractIdLst.Add(ContractId + "(" + Func.FormatDMY(BeginContract) + ")", ContractNo + "(" + Func.FormatDMY(BeginContract) + ")"); contract += ";" + ContractNo + "(" + Func.FormatDMY(BeginContract) + ")"; } if (tmp01 > 0 || tmp02 > 0) { if (count >= 1) { xlsSheet.Rows.Insert(rRent + 1 + j); xlsSheetEn.Rows.Insert(rRent + 1 + j); j++; } count++; int tmp = rRent + j; xlsSheet[tmp, 1].Value = Name; xlsSheet[tmp, 4].Value = rowType["Area"]; xlsSheet[tmp, 6].Value = rowType["MonthRentPriceUSD"]; xlsSheet[tmp, 7].Value = rowType["MonthRentPriceVND"]; xlsSheet[tmp, 8].Value = rowType["MonthRentSumUSD"]; xlsSheet[tmp, 9].Value = rowType["MonthRentSumVND"]; xlsSheet[tmp, 10].Value = rowType["VatRentPriceUSD"]; xlsSheet[tmp, 11].Value = rowType["VatRentPriceVND"]; xlsSheet[tmp, 12].Value = rowType["LastRentSumUSD"]; xlsSheet[tmp, 13].Value = rowType["LastRentSumVND"]; XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheet.MergedCells.Add(mrCell); ////EN xlsSheetEn[tmp, 1].Value = Name; xlsSheetEn[tmp, 4].Value = rowType["Area"]; xlsSheetEn[tmp, 6].Value = rowType["MonthRentPriceUSD"]; xlsSheetEn[tmp, 7].Value = rowType["MonthRentPriceVND"]; xlsSheetEn[tmp, 8].Value = rowType["MonthRentSumUSD"]; xlsSheetEn[tmp, 9].Value = rowType["MonthRentSumVND"]; xlsSheetEn[tmp, 10].Value = rowType["VatRentPriceUSD"]; xlsSheetEn[tmp, 11].Value = rowType["VatRentPriceVND"]; xlsSheetEn[tmp, 12].Value = rowType["LastRentSumUSD"]; xlsSheetEn[tmp, 13].Value = rowType["LastRentSumVND"]; mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheetEn.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheetEn.MergedCells.Add(mrCell); ////EN LastSumPriceVND[0] += Convert.ToDecimal(rowType["LastRentSumVND"]); LastSumPriceUSD[0] += Convert.ToDecimal(rowType["LastRentSumUSD"]); } else { k++; } } mCell = new XLCellRange(rRent + 1 + j, rRent + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); xlsSheet[rRent + 1 + j, 12].Value = LastSumPriceUSD[0]; xlsSheet[rRent + 1 + j, 13].Value = LastSumPriceVND[0]; xlsSheetEn[rRent + 1 + j, 12].Value = LastSumPriceUSD[0]; xlsSheetEn[rRent + 1 + j, 13].Value = LastSumPriceVND[0]; for (int row = rRent + sumRow; row <= rRent + dt.Rows.Count - k; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; xlsSheetEn[row, col].Style = xlstStyle; } } sumRow += dt.Rows.Count - 1 - k; //////////////////////// for (int col = 1; col <= 13; col++) { xlsSheet[rRent + 1 + j, col].Style = xlstStyleSum; xlsSheetEn[rRent + 1 + j, col].Style = xlstStyleSum; } line = rManager - 3 + j; mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); ////En mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheetEn.MergedCells.Add(mCell); ////En k = 0; count = 0; foreach (DataRow row in dt.Rows) { decimal tmp01 = Convert.ToDecimal(row["LastManagerSumUSD"]); decimal tmp02 = Convert.ToDecimal(row["LastManagerSumVND"]); if (tmp01 > 0 || tmp02 > 0) { if (count >= 1) { xlsSheet.Rows.Insert(rManager + 1 + j); xlsSheetEn.Rows.Insert(rManager + 1 + j); j++; } count++; int tmp = rManager + j; string YearMonth = Func.ParseString(row["YearMonth"]); string Area = Func.ParseString(row["Area"]); xlsSheet[tmp, 1].Value = Name; xlsSheet[tmp, 4].Value = row["Area"]; xlsSheet[tmp, 6].Value = row["MonthManagerPriceUSD"]; xlsSheet[tmp, 7].Value = row["MonthManagerPriceVND"]; xlsSheet[tmp, 8].Value = row["MonthManagerSumUSD"]; xlsSheet[tmp, 9].Value = row["MonthManagerSumVND"]; xlsSheet[tmp, 10].Value = row["VatManagerPriceUSD"]; xlsSheet[tmp, 11].Value = row["VatManagerPriceVND"]; xlsSheet[tmp, 12].Value = row["LastManagerSumUSD"]; xlsSheet[tmp, 13].Value = row["LastManagerSumVND"]; XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheet.MergedCells.Add(mrCell); ////En xlsSheetEn[tmp, 1].Value = Name; xlsSheetEn[tmp, 4].Value = row["Area"]; xlsSheetEn[tmp, 6].Value = row["MonthManagerPriceUSD"]; xlsSheetEn[tmp, 7].Value = row["MonthManagerPriceVND"]; xlsSheetEn[tmp, 8].Value = row["MonthManagerSumUSD"]; xlsSheetEn[tmp, 9].Value = row["MonthManagerSumVND"]; xlsSheetEn[tmp, 10].Value = row["VatManagerPriceUSD"]; xlsSheetEn[tmp, 11].Value = row["VatManagerPriceVND"]; xlsSheetEn[tmp, 12].Value = row["LastManagerSumUSD"]; xlsSheetEn[tmp, 13].Value = row["LastManagerSumVND"]; mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheetEn.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheetEn.MergedCells.Add(mrCell); ////En LastSumPriceVND[1] += Convert.ToDecimal(row["LastManagerSumVND"]); LastSumPriceUSD[1] += Convert.ToDecimal(row["LastManagerSumUSD"]); } else { k++; } } mCell = new XLCellRange(rManager + 1 + j, rManager + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); xlsSheet[rManager + 1 + j, 12].Value = LastSumPriceUSD[1]; xlsSheet[rManager + 1 + j, 13].Value = LastSumPriceVND[1]; xlsSheetEn[rManager + 1 + j, 12].Value = LastSumPriceUSD[1]; xlsSheetEn[rManager + 1 + j, 13].Value = LastSumPriceVND[1]; for (int row = rManager + sumRow; row <= rManager + sumRow + dt.Rows.Count - k; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; xlsSheetEn[row, col].Style = xlstStyle; } } for (int col = 1; col <= 13; col++) { xlsSheet[rManager + 1 + j, col].Style = xlstStyleSum; xlsSheetEn[rManager + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1 - k; } } ds = new DataSet(); //Xuất ra toàn bộ nội dung theo Trang sql = " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVND, PriceUSD, SUM(VatVND) AS VatVND,SUM(VatUSD) AS VatUSD, SUM(SumVND) AS SumVND, SUM(SumUSD) AS SumUSD, SUM(LastPriceVND) AS LastPriceVND"; sql += " , SUM(LastPriceUSD) AS LastPriceUSD"; sql += " FROM dbo.PaymentParking"; sql += " WHERE BuildingId = '" + sBuildingId + "' and CustomerId = '" + CustomerId + "' and YearMonth in (" + lsYearmonth + ")"; sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat, daysParking"; sql += " HAVING (SUM(LastPriceVND) >0 or SUM(LastPriceUSD) >0)"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rParking - 3 + j; XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); ////En mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheetEn.MergedCells.Add(mCell); ////En if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rParking + 1 + j); xlsSheetEn.Rows.Insert(rParking + 1 + j); j++; } count++; int tmp = rParking + j; string Num = Func.ParseString(row["Num"]); string TariffsParkingName = Func.ParseString(row["TariffsParkingName"]); xlsSheet[tmp, 1].Value = TariffsParkingName; xlsSheet[tmp, 4].Value = Num; xlsSheet[tmp, 6].Value = row["PriceUSD"]; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["SumUSD"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 10].Value = row["VatUSD"]; xlsSheet[tmp, 11].Value = row["VatVND"]; xlsSheet[tmp, 12].Value = row["LastPriceUSD"]; xlsSheet[tmp, 13].Value = row["LastPriceVND"]; XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheet.MergedCells.Add(mrCell); /////En xlsSheetEn[tmp, 1].Value = TariffsParkingName; xlsSheetEn[tmp, 4].Value = Num; xlsSheetEn[tmp, 6].Value = row["PriceUSD"]; xlsSheetEn[tmp, 7].Value = row["PriceVND"]; xlsSheetEn[tmp, 8].Value = row["SumUSD"]; xlsSheetEn[tmp, 9].Value = row["SumVND"]; xlsSheetEn[tmp, 10].Value = row["VatUSD"]; xlsSheetEn[tmp, 11].Value = row["VatVND"]; xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"]; xlsSheetEn[tmp, 13].Value = row["LastPriceVND"]; mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheetEn.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheetEn.MergedCells.Add(mrCell); /////En LastSumPriceVND[2] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[2] += Convert.ToDecimal(row["LastPriceUSD"]); } xlsSheet[rParking + 1 + j, 12].Value = LastSumPriceUSD[2]; xlsSheet[rParking + 1 + j, 13].Value = LastSumPriceVND[2]; mCell = new XLCellRange(rParking + 1 + j, rParking + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); /////En xlsSheetEn[rParking + 1 + j, 12].Value = LastSumPriceUSD[2]; xlsSheetEn[rParking + 1 + j, 13].Value = LastSumPriceVND[2]; mCell = new XLCellRange(rParking + 1 + j, rParking + 1 + j, 1, 11); xlsSheetEn.MergedCells.Add(mCell); /////En for (int row = rParking + sumRow; row <= rParking + sumRow + dt.Rows.Count; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; xlsSheetEn[row, col].Style = xlstStyle; } } for (int col = 1; col <= 13; col++) { xlsSheet[rParking + 1 + j, col].Style = xlstStyleSum; xlsSheetEn[rParking + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1; } } ds = new DataSet(); sql = "SELECT id"; sql += " ,YearMonth,BuildingId,CustomerId,RoomId,ExtraHour,VAT,OtherFee01,OtherFee02"; sql += " ,PriceUSD,PriceVND,VatUSD,VatVND,SumUSD,SumVND,IsNull(LastPriceUSD,0) LastPriceUSD ,IsNull(LastPriceVND,0) LastPriceVND "; sql += " ,RentArea,dbo.fnDateTime(FromWD) BeginDate,dbo.fnDateTime(EndWD) EndDate,ExtratimeType"; sql += " FROM PaymentExtraTimeMonth"; sql += " WHERE BuildingId = '" + sBuildingId + "' and CustomerId = '" + CustomerId + "' and YearMonth in (" + lsYearmonth + ")"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rExtra - 3 + j; //Phi dien XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); /////En mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 4, 4); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheetEn.MergedCells.Add(mCell); /////En if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rExtra + 1 + j); xlsSheetEn.Rows.Insert(rExtra + 1 + j); j++; } count++; int tmp = rExtra + j; string ExtraHour = Func.ParseString(row["ExtraHour"]); string BeginDate = Func.ParseString(row["BeginDate"]); string EndDate = Func.ParseString(row["EndDate"]); string ExtratimeType = Func.ParseString(row["ExtratimeType"]); xlsSheet[tmp, 1].Value = BeginDate + "~" + EndDate; xlsSheet[tmp, 5].Value = ExtraHour; xlsSheet[tmp, 4].Value = "Diện tích"; if ("0".Equals(ExtratimeType)) { xlsSheet[tmp, 4].Value = "m2*h"; } xlsSheet[tmp, 6].Value = row["PriceUSD"]; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["SumUSD"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 10].Value = row["VatUSD"]; xlsSheet[tmp, 11].Value = row["VatVND"]; xlsSheet[tmp, 12].Value = row["LastPriceUSD"]; xlsSheet[tmp, 13].Value = row["LastPriceVND"]; LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[3] += Convert.ToDecimal(row["LastPriceUSD"]); XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); //////En xlsSheetEn[tmp, 1].Value = BeginDate + "~" + EndDate; xlsSheetEn[tmp, 5].Value = ExtraHour; xlsSheetEn[tmp, 4].Value = "Di?n tích"; if ("0".Equals(ExtratimeType)) { xlsSheetEn[tmp, 4].Value = "m2*h"; } xlsSheetEn[tmp, 6].Value = row["PriceUSD"]; xlsSheetEn[tmp, 7].Value = row["PriceVND"]; xlsSheetEn[tmp, 8].Value = row["SumUSD"]; xlsSheetEn[tmp, 9].Value = row["SumVND"]; xlsSheetEn[tmp, 10].Value = row["VatUSD"]; xlsSheetEn[tmp, 11].Value = row["VatVND"]; xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"]; xlsSheetEn[tmp, 13].Value = row["LastPriceVND"]; //LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]); //LastSumPriceUSD[3] += Convert.ToDecimal(row["LastPriceUSD"]); mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheetEn.MergedCells.Add(mrCell); //////En for (int col = 1; col <= 13; col++) { xlsSheet[tmp, col].Style = xlstStyle; xlsSheetEn[tmp, col].Style = xlstStyle; } } mCell = new XLCellRange(rExtra + 1 + j, rExtra + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); xlsSheet[rExtra + 1 + j, 12].Value = LastSumPriceUSD[3]; xlsSheet[rExtra + 1 + j, 13].Value = LastSumPriceVND[3]; xlsSheetEn[rExtra + 1 + j, 12].Value = LastSumPriceUSD[3]; xlsSheetEn[rExtra + 1 + j, 13].Value = LastSumPriceVND[3]; for (int row = rExtra + sumRow; row <= rExtra + sumRow + dt.Rows.Count; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; xlsSheetEn[row, col].Style = xlstStyle; } } for (int col = 1; col <= 13; col++) { xlsSheet[rExtra + 1 + j, col].Style = xlstStyleSum; xlsSheetEn[rExtra + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1; } } ds = new DataSet(); //Dien //Xuất ra toàn bộ nội dung theo Trang sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, "; sql += " B.VatVND, B.VatUSD ,IsNull(B.LastPriceUSD,0) LastPriceUSD ,IsNull(B.LastPriceVND,0) LastPriceVND , B.Name, B.WaterPricePercent,B.ElecPricePercent "; sql += " FROM PaymentElecWater AS A INNER JOIN "; sql += " PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId"; sql += " WHERE A.BuildingId = '" + sBuildingId + "' and A.CustomerId = '" + CustomerId + "' and TarrifsOfWaterId = 0 and A.YearMonth in (" + lsYearmonth + ")"; sql += " Order by A.DateFrom, B.FromIndex"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rElec - 3 + j; //Phi dien XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 3, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 5, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 7, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 8, 8); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 9, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 10, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 11, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 12, 13); xlsSheet.MergedCells.Add(mCell); /////En mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 3, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 4, 4); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 5, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 7, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 8, 8); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 9, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 10, 10); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 11, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 12, 13); xlsSheetEn.MergedCells.Add(mCell); /////En for (int col = 1; col < 13; col++) { xlsSheet[line, col].Style = xlstStyleH; xlsSheet[line + 1, col].Style = xlstStyleH; xlsSheet[line + 2, col].Style = xlstStyleH; xlsSheetEn[line, col].Style = xlstStyleH; xlsSheetEn[line + 1, col].Style = xlstStyleH; xlsSheetEn[line + 2, col].Style = xlstStyleH; } if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rElec + 1 + j); xlsSheetEn.Rows.Insert(rElec + 1 + j); j++; } count++; int tmp = rElec + j; string DateFrom = Func.ParseString(row["DateFrom"]); string DateTo = Func.ParseString(row["DateTo"]); string FromIndex = Func.ParseString(row["FromIndex"]); string ToIndex = Func.ParseString(row["ToIndex"]); string OtherFee01 = Func.ParseString(row["OtherFee01"]); string OtherFee02 = Func.ParseString(row["OtherFee02"]); string Mount = Func.ParseString(row["Mount"]); string ElecPricePercent = Func.ParseString(row["ElecPricePercent"]); xlsSheet[tmp, 1].Value = DateFrom; xlsSheet[tmp, 2].Value = DateTo; xlsSheet[tmp, 3].Value = FromIndex; xlsSheet[tmp, 4].Value = ToIndex; xlsSheet[tmp, 5].Value = OtherFee01; xlsSheet[tmp, 6].Value = Mount; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["VatVND"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 10].Value = row["OtherFee02"]; xlsSheet[tmp, 11].Value = row["ElecPricePercent"]; xlsSheet[tmp, 12].Value = row["LastPriceVND"]; mCell = new XLCellRange(tmp, tmp, 12, 13); xlsSheet.MergedCells.Add(mCell); /////En xlsSheetEn[tmp, 1].Value = DateFrom; xlsSheetEn[tmp, 2].Value = DateTo; xlsSheetEn[tmp, 3].Value = FromIndex; xlsSheetEn[tmp, 4].Value = ToIndex; xlsSheetEn[tmp, 5].Value = OtherFee01; xlsSheetEn[tmp, 6].Value = Mount; xlsSheetEn[tmp, 7].Value = row["PriceVND"]; xlsSheetEn[tmp, 8].Value = row["VatVND"]; xlsSheetEn[tmp, 9].Value = row["SumVND"]; xlsSheetEn[tmp, 10].Value = row["OtherFee02"]; xlsSheetEn[tmp, 11].Value = row["ElecPricePercent"]; xlsSheetEn[tmp, 12].Value = row["LastPriceVND"]; mCell = new XLCellRange(tmp, tmp, 12, 13); xlsSheetEn.MergedCells.Add(mCell); /////En for (int col = 1; col <= 12; col++) { xlsSheet[tmp, col].Style = xlstStyle; xlsSheetEn[tmp, col].Style = xlstStyle; } LastSumPriceVND[4] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[4] += Convert.ToDecimal(row["LastPriceUSD"]); } xlsSheet[rElec + 1 + j, 12].Value = LastSumPriceVND[4]; mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn[rElec + 1 + j, 12].Value = LastSumPriceVND[4]; mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 1, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 12, 13); xlsSheetEn.MergedCells.Add(mCell); for (int col = 1; col <= 13; col++) { xlsSheet[rElec + 1 + j, col].Style = xlstStyleSum; xlsSheetEn[rElec + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1; } } } ds = new DataSet(); //Nuoc //Xuất ra toàn bộ nội dung theo Trang sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, "; sql += " B.VatVND, B.VatUSD,IsNull(B.LastPriceUSD,0) LastPriceUSD,IsNull(B.LastPriceVND,0) LastPriceVND, B.Name, B.WaterPricePercent,B.ElecPricePercent "; sql += " FROM PaymentElecWater AS A INNER JOIN "; sql += " PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId"; sql += " WHERE A.BuildingId = '" + sBuildingId + "' and A.CustomerId = '" + CustomerId + "' and TarrifsOfElecId = 0 and A.YearMonth in (" + lsYearmonth + ")"; sql += " Order by A.DateFrom, B.FromIndex"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rWater - 3 + j; //Phi dien XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 3, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 6, 6); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 7, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 8, 8); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 9, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 10, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 11, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 12, 13); xlsSheet.MergedCells.Add(mCell); /////En mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 3, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 4, 4); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 6, 6); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 7, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 8, 8); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 9, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 10, 10); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 11, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 12, 13); xlsSheetEn.MergedCells.Add(mCell); /////En for (int col = 1; col < 13; col++) { xlsSheet[line, col].Style = xlstStyleH; xlsSheet[line + 1, col].Style = xlstStyleH; xlsSheet[line + 2, col].Style = xlstStyleH; xlsSheetEn[line, col].Style = xlstStyleH; xlsSheetEn[line + 1, col].Style = xlstStyleH; xlsSheetEn[line + 2, col].Style = xlstStyleH; } if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rWater + 1 + j); xlsSheetEn.Rows.Insert(rWater + 1 + j); j++; } count++; int tmp = rWater + j; string DateFrom = Func.ParseString(row["DateFrom"]); string DateTo = Func.ParseString(row["DateTo"]); string FromIndex = Func.ParseString(row["FromIndex"]); string ToIndex = Func.ParseString(row["ToIndex"]); string OtherFee01 = Func.ParseString(row["OtherFee01"]); string OtherFee02 = Func.ParseString(row["OtherFee02"]); string Mount = Func.ParseString(row["Mount"]); xlsSheet[tmp, 1].Value = DateFrom; xlsSheet[tmp, 2].Value = DateTo; xlsSheet[tmp, 3].Value = FromIndex; xlsSheet[tmp, 4].Value = ToIndex; xlsSheet[tmp, 5].Value = Mount; xlsSheet[tmp, 6].Value = row["PriceVND"]; xlsSheet[tmp, 7].Value = row["OtherFee01"]; xlsSheet[tmp, 8].Value = row["VatVND"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 10].Value = row["OtherFee02"]; xlsSheet[tmp, 11].Value = row["WaterPricePercent"]; xlsSheet[tmp, 12].Value = row["LastPriceVND"]; /////En xlsSheetEn[tmp, 1].Value = DateFrom; xlsSheetEn[tmp, 2].Value = DateTo; xlsSheetEn[tmp, 3].Value = FromIndex; xlsSheetEn[tmp, 4].Value = ToIndex; xlsSheetEn[tmp, 5].Value = Mount; xlsSheetEn[tmp, 6].Value = row["PriceVND"]; xlsSheetEn[tmp, 7].Value = row["OtherFee01"]; xlsSheetEn[tmp, 8].Value = row["VatVND"]; xlsSheetEn[tmp, 9].Value = row["SumVND"]; xlsSheetEn[tmp, 10].Value = row["OtherFee02"]; xlsSheetEn[tmp, 11].Value = row["WaterPricePercent"]; xlsSheetEn[tmp, 12].Value = row["LastPriceVND"]; /////En for (int col = 1; col <= 12; col++) { xlsSheet[tmp, col].Style = xlstStyle; xlsSheetEn[tmp, col].Style = xlstStyle; } LastSumPriceVND[5] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[5] += Convert.ToDecimal(row["LastPriceUSD"]); mCell = new XLCellRange(tmp, tmp, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); } xlsSheet[rWater + 1 + j, 12].Value = LastSumPriceVND[5]; xlsSheetEn[rWater + 1 + j, 12].Value = LastSumPriceVND[5]; mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); for (int col = 1; col <= 13; col++) { xlsSheet[rWater + 1 + j, col].Style = xlstStyleSum; xlsSheetEn[rWater + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1; } } } //Service ds = new DataSet(); sql = string.Empty; sql = " SELECT Service,dbo.fnDateTime(ServiceDateFrom) ServiceDateFrom,dbo.fnDateTime(ServiceDateTo) ServiceDateTo,PriceVND,PriceUSD,VatUSD,VatVND,Mount,Unit,SumVND,SumUSD,isnull(LastPriceVND,0) LastPriceVND,isnull(LastPriceUSD,0) LastPriceUSD"; sql += " FROM PaymentService"; sql += " WHERE BuildingId = '" + sBuildingId + "' and CustomerId = '" + CustomerId + "' and YearMonth in (" + lsYearmonth + ")"; sql += " Order By ServiceDate "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rService - 3 + j; //Phi khác XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 3, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 5, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); /////En mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 3, 3); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 4, 4); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 5, 5); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheetEn.MergedCells.Add(mCell); /////En for (int col = 1; col < 13; col++) { xlsSheet[line, col].Style = xlstStyleH; xlsSheet[line + 1, col].Style = xlstStyleH; xlsSheet[line + 2, col].Style = xlstStyleH; xlsSheetEn[line, col].Style = xlstStyleH; xlsSheetEn[line + 1, col].Style = xlstStyleH; xlsSheetEn[line + 2, col].Style = xlstStyleH; } mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rService + 1 + j); xlsSheetEn.Rows.Insert(rService + 1 + j); j++; } count++; int tmp = rService + j; string Service = Func.ParseString(row["Service"]); string ServiceDateFrom = Func.ParseString(row["ServiceDateFrom"]); string ServiceDateTo = Func.ParseString(row["ServiceDateTo"]); string Mount = Func.ParseString(row["Mount"]); xlsSheet[tmp, 1].Value = Service; xlsSheet[tmp, 2].Value = Func.ParseString(row["Unit"]); xlsSheet[tmp, 3].Value = ServiceDateFrom; xlsSheet[tmp, 4].Value = ServiceDateTo; xlsSheet[tmp, 5].Value = Mount; xlsSheet[tmp, 6].Value = row["PriceUSD"]; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["SumUSD"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 10].Value = row["VatUSD"]; xlsSheet[tmp, 11].Value = row["VatVND"]; xlsSheet[tmp, 12].Value = row["LastPriceUSD"]; xlsSheet[tmp, 13].Value = row["LastPriceVND"]; /////En xlsSheetEn[tmp, 1].Value = Service; xlsSheetEn[tmp, 2].Value = Func.ParseString(row["Unit"]); xlsSheetEn[tmp, 3].Value = ServiceDateFrom; xlsSheetEn[tmp, 4].Value = ServiceDateTo; xlsSheetEn[tmp, 5].Value = Mount; xlsSheetEn[tmp, 6].Value = row["PriceUSD"]; xlsSheetEn[tmp, 7].Value = row["PriceVND"]; xlsSheetEn[tmp, 8].Value = row["SumUSD"]; xlsSheetEn[tmp, 9].Value = row["SumVND"]; xlsSheetEn[tmp, 10].Value = row["VatUSD"]; xlsSheetEn[tmp, 11].Value = row["VatVND"]; xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"]; xlsSheetEn[tmp, 13].Value = row["LastPriceVND"]; /////En for (int col = 1; col <= 13; col++) { xlsSheet[tmp, col].Style = xlstStyle; xlsSheetEn[tmp, col].Style = xlstStyle; } LastSumPriceVND[6] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[6] += Convert.ToDecimal(row["LastPriceUSD"]); } xlsSheet[rService + 1 + j, 12].Value = LastSumPriceUSD[6]; xlsSheet[rService + 1 + j, 13].Value = LastSumPriceVND[6]; xlsSheetEn[rService + 1 + j, 12].Value = LastSumPriceUSD[6]; xlsSheetEn[rService + 1 + j, 13].Value = LastSumPriceVND[6]; mCell = new XLCellRange(rService + 1 + j, rService + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheetEn.MergedCells.Add(mCell); for (int col = 1; col <= 13; col++) { xlsSheet[rService + 1 + j, col].Style = xlstStyleSum; xlsSheetEn[rService + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1; } } } //Paid sql = "Select *"; sql += " From PaymentBillDetail"; sql += " Where BuildingId = '" + sBuildingId + "' and CustomerId = '" + CustomerId + "' and YearMonth in (" + lsYearmonth + ") and YearMonth < " + maxYearMonth + ""; string strYearMonth = ""; int lineTmp = rPaid - 2 + j; //Paid XLCellRange mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13); xlsSheet.MergedCells.Add(mCellTmp); /////En mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13); xlsSheetEn.MergedCells.Add(mCellTmp); /////En Hashtable rowNo = new Hashtable(); decimal[] PaidSumVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; decimal[] PaidSumUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; DataTable dtPaid = DbHelper.GetDataTable(sql); for (int i = 0; i < dtPaid.Rows.Count; i++) { string PaymentType = Func.ParseString(dtPaid.Rows[i]["PaymentType"]); string MoneyUSD = Func.ParseString(dtPaid.Rows[i]["MoneyUSD"]); string MoneyVND = Func.ParseString(dtPaid.Rows[i]["MoneyVND"]); string PaidUSD = Func.ParseString(dtPaid.Rows[i]["PaidUSD"]); string PaidVND = Func.ParseString(dtPaid.Rows[i]["PaidVND"]); string ExchangeType = Func.ParseString(dtPaid.Rows[i]["ExchangeType"]); string YearMonth = Func.ParseString(dtPaid.Rows[i]["YearMonth"]); if (!rowNo.Contains(YearMonth)) { if (rowNo.Count != 0) { xlsSheet.Rows.Insert(rPaid + j + 1); xlsSheetEn.Rows.Insert(rPaid + j + 1); j++; } rowNo.Add(YearMonth, j); } int m = Func.ParseInt(rowNo[YearMonth]); strYearMonth = YearMonth; decimal tmpUSD = Convert.ToDecimal(MoneyUSD) - Convert.ToDecimal(PaidUSD); decimal tmpVND = Convert.ToDecimal(MoneyVND) - Convert.ToDecimal(PaidVND); PaidPriceUSD += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidPriceVND += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); xlsSheet[rPaid + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); xlsSheetEn[rPaid + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); switch (PaymentType) { case "1": //Rent xlsSheet[rPaid + m, 2].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + m, 3].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 2].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheetEn[rPaid + m, 3].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[0] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[0] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "2": //Manager xlsSheet[rPaid + m, 4].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + m, 5].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 4].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheetEn[rPaid + m, 5].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[1] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[1] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "3": //Parking xlsSheet[rPaid + m, 6].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + m, 7].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 6].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheetEn[rPaid + m, 7].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[2] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[2] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "4": //Extra xlsSheet[rPaid + m, 8].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + m, 9].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 8].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheetEn[rPaid + m, 9].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[3] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[3] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "5": xlsSheet[rPaid + m, 10].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 10].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[4] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[4] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "6": xlsSheet[rPaid + m, 11].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 11].Value = dtPaid.Rows[i]["PaidVND"]; PaidSumUSD[5] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidSumVND[5] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "7": xlsSheet[rPaid + m, 12].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + m, 13].Value = dtPaid.Rows[i]["PaidVND"]; xlsSheetEn[rPaid + m, 12].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheetEn[rPaid + m, 13].Value = dtPaid.Rows[i]["PaidVND"]; break; default: break; } for (int row = rPaid + m; row <= rPaid + 1 + j; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; } } } lineTmp = rPaid - 2 + j; xlsSheet[lineTmp + 3, 2].Value = PaidSumUSD[0]; xlsSheet[lineTmp + 3, 3].Value = PaidSumVND[0]; xlsSheet[lineTmp + 3, 4].Value = PaidSumUSD[1]; xlsSheet[lineTmp + 3, 5].Value = PaidSumVND[1]; xlsSheet[lineTmp + 3, 6].Value = PaidSumUSD[2]; xlsSheet[lineTmp + 3, 7].Value = PaidSumVND[2]; xlsSheet[lineTmp + 3, 8].Value = PaidSumUSD[3]; xlsSheet[lineTmp + 3, 9].Value = PaidSumVND[3]; xlsSheet[lineTmp + 3, 10].Value = PaidSumVND[4]; xlsSheet[lineTmp + 3, 11].Value = PaidSumVND[5]; xlsSheet[lineTmp + 3, 12].Value = PaidSumUSD[6]; xlsSheet[lineTmp + 3, 13].Value = PaidSumVND[6]; /////En xlsSheetEn[lineTmp + 3, 2].Value = PaidSumUSD[0]; xlsSheetEn[lineTmp + 3, 3].Value = PaidSumVND[0]; xlsSheetEn[lineTmp + 3, 4].Value = PaidSumUSD[1]; xlsSheetEn[lineTmp + 3, 5].Value = PaidSumVND[1]; xlsSheetEn[lineTmp + 3, 6].Value = PaidSumUSD[2]; xlsSheetEn[lineTmp + 3, 7].Value = PaidSumVND[2]; xlsSheetEn[lineTmp + 3, 8].Value = PaidSumUSD[3]; xlsSheetEn[lineTmp + 3, 9].Value = PaidSumVND[3]; xlsSheetEn[lineTmp + 3, 10].Value = PaidSumVND[4]; xlsSheetEn[lineTmp + 3, 11].Value = PaidSumVND[5]; xlsSheetEn[lineTmp + 3, 12].Value = PaidSumUSD[6]; xlsSheetEn[lineTmp + 3, 13].Value = PaidSumVND[6]; /////En for (int col = 1; col <= 13; col++) { xlsSheet[lineTmp + 3, col].Style = xlstStyleSum; xlsSheetEn[lineTmp + 3, col].Style = xlstStyleSum; } ///////////////DEPT sql = " Select *"; sql += " From v_DeptBill"; sql += " Where BuildingId = '" + sBuildingId + "' and CustomerId = '" + CustomerId + "' and YearMonth not in (" + lsYearmonth + ") and YearMonth < " + maxYearMonth + ""; sql += " And (DeptUsd <> 0 or DeptVnd <> 0)"; strYearMonth = ""; lineTmp = rDept - 2 + j; //Paid mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13); xlsSheet.MergedCells.Add(mCellTmp); //////En mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9); xlsSheetEn.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13); xlsSheetEn.MergedCells.Add(mCellTmp); //////En rowNo = new Hashtable(); decimal DeptPriceVND = 0; decimal DeptPriceUSD = 0; decimal[] DeptSumVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; decimal[] DeptSumUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; DataTable dtDept = DbHelper.GetDataTable(sql); for (int i = 0; i < dtDept.Rows.Count; i++) { string PaymentType = Func.ParseString(dtDept.Rows[i]["PaymentType"]); string DeptUSD = Func.ParseString(dtDept.Rows[i]["DeptUSD"]); string DeptVND = Func.ParseString(dtDept.Rows[i]["DeptVND"]); string YearMonth = Func.ParseString(dtDept.Rows[i]["YearMonth"]); if (!rowNo.Contains(YearMonth)) { if (rowNo.Count != 0) { xlsSheet.Rows.Insert(rDept + j + 1); xlsSheetEn.Rows.Insert(rDept + j + 1); j++; } rowNo.Add(YearMonth, j); } int m = Func.ParseInt(rowNo[YearMonth]); strYearMonth = YearMonth; DeptPriceUSD += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptPriceVND += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); xlsSheet[rDept + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); xlsSheetEn[rDept + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); switch (PaymentType) { case "1": //Rent xlsSheet[rDept + m, 2].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheet[rDept + m, 3].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 2].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheetEn[rDept + m, 3].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[0] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[0] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "2": //Manager xlsSheet[rDept + m, 4].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheet[rDept + m, 5].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 4].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheetEn[rDept + m, 5].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[1] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[1] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "3": //Parking xlsSheet[rDept + m, 6].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheet[rDept + m, 7].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 6].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheetEn[rDept + m, 7].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[2] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[2] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "4": //Extra xlsSheet[rDept + m, 8].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheet[rDept + m, 9].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 8].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheetEn[rDept + m, 9].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[3] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[3] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "5": xlsSheet[rDept + m, 10].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 10].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[4] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[4] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "6": xlsSheet[rDept + m, 11].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 11].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[5] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[5] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "7": xlsSheet[rDept + m, 12].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheet[rDept + m, 13].Value = dtDept.Rows[i]["DeptVND"]; xlsSheetEn[rDept + m, 12].Value = dtDept.Rows[i]["DeptUSD"]; xlsSheetEn[rDept + m, 13].Value = dtDept.Rows[i]["DeptVND"]; DeptSumUSD[6] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]); DeptSumVND[6] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; default: break; } for (int row = rDept + m; row <= rDept + 1 + j; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; xlsSheetEn[row, col].Style = xlstStyle; } } } lineTmp = rDept - 2 + j; xlsSheet[lineTmp + 3, 2].Value = DeptSumUSD[0]; xlsSheet[lineTmp + 3, 3].Value = DeptSumVND[0]; xlsSheet[lineTmp + 3, 4].Value = DeptSumUSD[1]; xlsSheet[lineTmp + 3, 5].Value = DeptSumVND[1]; xlsSheet[lineTmp + 3, 6].Value = DeptSumUSD[2]; xlsSheet[lineTmp + 3, 7].Value = DeptSumVND[2]; xlsSheet[lineTmp + 3, 8].Value = DeptSumUSD[3]; xlsSheet[lineTmp + 3, 9].Value = DeptSumVND[3]; xlsSheet[lineTmp + 3, 10].Value = DeptSumVND[4]; xlsSheet[lineTmp + 3, 11].Value = DeptSumVND[5]; xlsSheet[lineTmp + 3, 12].Value = DeptSumUSD[6]; xlsSheet[lineTmp + 3, 13].Value = DeptSumVND[6]; //////En xlsSheetEn[lineTmp + 3, 2].Value = DeptSumUSD[0]; xlsSheetEn[lineTmp + 3, 3].Value = DeptSumVND[0]; xlsSheetEn[lineTmp + 3, 4].Value = DeptSumUSD[1]; xlsSheetEn[lineTmp + 3, 5].Value = DeptSumVND[1]; xlsSheetEn[lineTmp + 3, 6].Value = DeptSumUSD[2]; xlsSheetEn[lineTmp + 3, 7].Value = DeptSumVND[2]; xlsSheetEn[lineTmp + 3, 8].Value = DeptSumUSD[3]; xlsSheetEn[lineTmp + 3, 9].Value = DeptSumVND[3]; xlsSheetEn[lineTmp + 3, 10].Value = DeptSumVND[4]; xlsSheetEn[lineTmp + 3, 11].Value = DeptSumVND[5]; xlsSheetEn[lineTmp + 3, 12].Value = DeptSumUSD[6]; xlsSheetEn[lineTmp + 3, 13].Value = DeptSumVND[6]; //////En for (int col = 1; col <= 13; col++) { xlsSheet[lineTmp + 3, col].Style = xlstStyleSum; xlsSheetEn[lineTmp + 3, col].Style = xlstStyleSum; } xlsSheet[lineTmp + 3, 1].Style = xlstStyleSum; xlsSheetEn[lineTmp + 3, 1].Style = xlstStyleSum; decimal AllSumVND = 0; decimal AllSumUSD = 0; for (int i = 0; i < 7; i++) { AllSumVND += LastSumPriceVND[i]; AllSumUSD += LastSumPriceUSD[i]; } AllSumVND -= PaidPriceVND; AllSumUSD -= PaidPriceUSD; AllSumVND += DeptPriceVND; AllSumUSD += DeptPriceUSD; xlsSheet[rSumVND + j, cSumVND].Value = Func.FormatNumber_New(AllSumUSD); xlsSheet[rSumVND + j, cSumVND].Value += "(USD)"; xlsSheet[rSumVND + j, cSumVND + 1].Value = Func.FormatNumber_New(AllSumVND); xlsSheet[rSumVND + j, cSumVND + 1].Value += "(VND)"; xlsSheetEn[rSumVND + j, cSumVND].Value = Func.FormatNumber_New(AllSumUSD); xlsSheetEn[rSumVND + j, cSumVND].Value += "(USD)"; xlsSheetEn[rSumVND + j, cSumVND + 1].Value = Func.FormatNumber_New(AllSumVND); xlsSheetEn[rSumVND + j, cSumVND + 1].Value += "(VND)"; AllSumVND += Convert.ToDecimal(AllSumUSD * Convert.ToDecimal(UsdExchange)); string strMoney = Func.docso(Convert.ToInt32(AllSumVND)); string strMoneyEn = Func.DocSo_En(Convert.ToInt32(AllSumVND)); xlsSheet[rContract, cContract].Value = xlsSheet[rContract, cContract].Value.ToString().Replace("{%HOP_DONG%}", String.IsNullOrEmpty(contract) ? "" : contract.Substring(1)); xlsSheet[rSum + j, cSum].Value = Convert.ToInt32(AllSumVND); mCellTmp = new XLCellRange(rSum + j, rSum + j, cSum, cSum + 1); xlsSheet.MergedCells.Add(mCellTmp); xlsSheet[rSum + j, cSum].Style = xlstStyleSum; xlsSheet[rSum + j, cSum + 1].Style = xlstStyleSum; xlsSheet[rSumRead + j, cSumRead].Value = xlsSheet[rSumRead + j, cSumRead].Value.ToString().Replace("{%TONG_CHU%}", strMoney.ToUpper()); xlsSheetEn[rContract, cContract].Value = xlsSheetEn[rContract, cContract].Value.ToString().Replace("{%HOP_DONG%}", String.IsNullOrEmpty(contract) ? "" : contract.Substring(1)); xlsSheetEn[rSum + j, cSum].Value = Convert.ToInt32(AllSumVND); mCellTmp = new XLCellRange(rSum + j, rSum + j, cSum, cSum + 1); xlsSheetEn.MergedCells.Add(mCellTmp); xlsSheetEn[rSum + j, cSum].Style = xlstStyleSum; xlsSheetEn[rSum + j, cSum + 1].Style = xlstStyleSum; xlsSheetEn[rSumRead + j, cSumRead].Value = xlsSheetEn[rSumRead + j, cSumRead].Value.ToString().Replace("{%TONG_CHU%}", strMoneyEn.ToUpper()); xlbBook.Save(fileNameDes); xlbBook.Clear(); //ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } } }
//--------------------------------------------------------------------------------- #region "** object model" /// <summary> /// Saves the content of a C1FlexGrid into an XLSheet. /// </summary> public static void Save(C1FlexGrid flex, XLSheet sheet) { // clear style cache if this is a new book if (!object.ReferenceEquals(sheet.Book, _lastBook)) { _cellStyles.Clear(); _excelStyles.Clear(); _lastBook = sheet.Book; } // save global parameters sheet.DefaultRowHeight = PixelsToTwips(flex.Rows.DefaultSize); sheet.DefaultColumnWidth = PixelsToTwips(flex.Columns.DefaultSize); sheet.Locked = flex.IsReadOnly; sheet.ShowGridLines = flex.GridLinesVisibility != GridLinesVisibility.None; sheet.ShowHeaders = flex.HeadersVisibility != HeadersVisibility.None; sheet.OutlinesBelow = flex.GroupRowPosition == GroupRowPosition.BelowData; // save columns sheet.Columns.Clear(); foreach (Column col in flex.Columns) { dynamic c = sheet.Columns.Add(); if (!col.Width.IsAuto) { c.Width = PixelsToTwips(col.ActualWidth); } c.Visible = col.Visible; if (col.CellStyle is ExcelCellStyle) { c.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)col.CellStyle); } } sheet.Rows.Clear(); //save column headers XLStyle headerStyle = default(XLStyle); headerStyle = new XLStyle(sheet.Book); headerStyle.Font = new XLFont("Arial", 10, true, false); foreach (Row row in flex.ColumnHeaders.Rows) { dynamic r = sheet.Rows.Add(); if (row.Height > -1) { r.Height = PixelsToTwips(row.Height); } if (row.CellStyle is ExcelCellStyle) { r.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)row.CellStyle); } if (row is ExcelRow) { r.OutlineLevel = ((ExcelRow)row).Level; } for (int c = 0; c <= flex.ColumnHeaders.Columns.Count - 1; c++) { // save cell value dynamic cell = sheet[row.Index, c]; string colHeader = flex.ColumnHeaders[row.Index, c] != null ? flex.ColumnHeaders[row.Index, c].ToString() : flex.Columns[c].ColumnName; cell.Value = colHeader; // make column headers bold cell.Style = headerStyle; } r.Visible = row.Visible; } // save rows foreach (Row row in flex.Rows) { dynamic r = sheet.Rows.Add(); if (row.Height > -1) { r.Height = PixelsToTwips(row.Height); } if (row.CellStyle is ExcelCellStyle) { r.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)row.CellStyle); } if (row is ExcelRow) { r.OutlineLevel = ((ExcelRow)row).Level; } r.Visible = row.Visible; } int rowStart = flex.ColumnHeaders.Rows.Count; // save cells for (int r = 0; r <= flex.Rows.Count - 1; r++, rowStart++) { for (int c = 0; c <= flex.Columns.Count - 1; c++) { // save cell value dynamic cell = sheet[rowStart, c]; dynamic obj = flex[r, c]; cell.Value = obj is FrameworkElement ? 0 : obj; // save cell formula and style dynamic row = flex.Rows[r] as ExcelRow; if (row != null) { // save cell formula dynamic col = flex.Columns[c]; // save cell style dynamic cs = row.GetCellStyle(col) as ExcelCellStyle; if (cs != null) { cell.Style = GetXLStyle(flex, sheet, cs); } } } } // save selection dynamic sel = flex.Selection; if (sel.IsValid) { dynamic xlSel = new XLCellRange(sheet, sel.Row, sel.Row2, sel.Column, sel.Column2); sheet.SelectedCells.Clear(); sheet.SelectedCells.Add(xlSel); } }
protected void btnExport_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT *"; sql += " FROM v_TicketStubs"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; sql += " AND (ReceiveDate is not null and substring(ReceiveDate,1,6) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "')"; using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); db.Close(); if (ds != null) { C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\ThongTinVeXeLuot.xls"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\ThongTinVeXeLuot")) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\ThongTinVeXeLuot")); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\ThongTinVeXeLuot\ThongTinVeXeLuot" + strDT + ".xls"; string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/ThongTinVeXeLuot/ThongTinVeXeLuot" + strDT + ".xls"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLSheet xlsSheet = xlbBook.Sheets["BaoCao"]; int i = 3; XLCellRange mrCell = new XLCellRange(0, 0, 0, 2); xlsSheet.MergedCells.Add(mrCell); XLStyle xlstStyle = new XLStyle(xlbBook); //xlstStyle.AlignHorz = XLAlignHorzEnum.Left; xlstStyle.AlignVert = XLAlignVertEnum.Top; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; xlstStyle.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyle01 = new XLStyle(xlbBook); xlstStyle01.AlignHorz = XLAlignHorzEnum.Center; xlstStyle01.AlignVert = XLAlignVertEnum.Top; xlstStyle01.WordWrap = true; xlstStyle01.Font = new Font("", 8, FontStyle.Regular); xlstStyle01.SetBorderColor(Color.Black); xlstStyle01.BorderBottom = XLLineStyleEnum.Thin; xlstStyle01.BorderTop = XLLineStyleEnum.Thin; xlstStyle01.BorderLeft = XLLineStyleEnum.Thin; xlstStyle01.BorderRight = XLLineStyleEnum.Thin; xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue+"/"+drpYear.SelectedValue); string seriTmp = ""; decimal remainTmp = 0; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string col01 = rowType[0].ToString(); string col02 = rowType[1].ToString(); string col03 = Func.FormatDMY(rowType[2].ToString()); string col04 = rowType[3].ToString(); string col05 = rowType[4].ToString(); string col06 = Func.FormatDMY(rowType[5].ToString()); string col07 = rowType[6].ToString(); string col08 = rowType[7].ToString(); string col09 = rowType[8].ToString(); string col10 = rowType[9].ToString(); string col11 = rowType[10].ToString(); string col12 = rowType[11].ToString(); string col13 = rowType[12].ToString(); if (!seriTmp.Equals(col01)) { xlsSheet[i, 0].Value = col01; xlsSheet[i, 1].Value = rowType[1]; xlsSheet[i, 2].Value = col03; xlsSheet[i, 3].Value = col04; xlsSheet[i, 4].Value = col05; xlsSheet[i, 0].Style = xlstStyle; xlsSheet[i, 1].Style = xlstStyle; xlsSheet[i, 2].Style = xlstStyle; xlsSheet[i, 3].Style = xlstStyle; xlsSheet[i, 4].Style = xlstStyle; int remain = Func.ParseInt(col02) - Func.ParseInt(col09); remainTmp = remain; xlsSheet[i, 11].Value = remain; seriTmp = col01; } else { remainTmp -= Convert.ToDecimal(col09); xlsSheet[i, 11].Value = remainTmp; } xlsSheet[i, 5].Value = col06; xlsSheet[i, 6].Value = col07; xlsSheet[i, 7].Value = col08; xlsSheet[i, 8].Value = rowType[8]; xlsSheet[i, 9].Value = rowType[9]; xlsSheet[i, 10].Value = rowType[10]; xlsSheet[i,12].Value = col13; xlsSheet[i, 5].Style = xlstStyle; xlsSheet[i, 6].Style = xlstStyle; xlsSheet[i, 7].Style = xlstStyle; xlsSheet[i, 8].Style = xlstStyle; xlsSheet[i, 9].Style = xlstStyle; xlsSheet[i, 10].Style = xlstStyle; xlsSheet[i, 11].Style = xlstStyle; xlsSheet[i, 12].Style = xlstStyle; ++i; } xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } }
protected void btnView_Click(object sender, EventArgs e) { mvMessage.CheckRequired(txtContractDate, "Ngày xuất HĐ : Danh mục phải nhập"); mvMessage.CheckRequired(txtContractNo, "Hợp đồng số : Danh mục phải nhập"); mvMessage.CheckRequired(txtRate, "Tỉ giá quy đổi USD->VND : Danh mục phải nhập"); mvMessage.CheckRequired(txtRateDate, "Thời gian quy đổi: Danh mục phải nhập"); if (!mvMessage.IsValid) return; C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BillPhongHop.xlsx"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BillPhongHop")) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BillPhongHop")); } decimal[] LastSumPriceVND = { 0, 0, 0 }; decimal[] LastSumPriceUSD = { 0, 0, 0 }; XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; xlstStyle.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleSum = new XLStyle(xlbBook); xlstStyleSum.AlignHorz = XLAlignHorzEnum.Right; xlstStyleSum.AlignVert = XLAlignVertEnum.Center; xlstStyleSum.Font = new Font("Times New Roman", 10, FontStyle.Bold); xlstStyleSum.SetBorderColor(Color.Black); xlstStyleSum.BorderBottom = XLLineStyleEnum.Thin; xlstStyleSum.BorderTop = XLLineStyleEnum.Thin; xlstStyleSum.BorderLeft = XLLineStyleEnum.Thin; xlstStyleSum.BorderRight = XLLineStyleEnum.Thin; xlstStyleSum.WordWrap = true; xlstStyleSum.Format = "#,##0.00_);(#,##0.00)"; string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"BillPhongHop\BillPhongHop" + "_" + lnbCustomerId.Text + "_" + strDT + ".xlsx"; string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/BillPhongHop/BillPhongHop" + "_" + lnbCustomerId.Text + "_" + strDT + ".xlsx"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLSheet xlsSheet = xlbBook.Sheets["HoaDon"]; int k = 2; xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%NGAY%}", DateTime.Today.ToString("dd")); xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%THANG%}", DateTime.Today.ToString("MM")); xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%NAM%}", DateTime.Today.ToString("yyyy")); using (SqlDatabase db = new SqlDatabase()) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT Name, ContactName"; sql += " FROM Customer"; sql += " WHERE CustomerId = '" + lnbCustomerId.Text + "' "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string Name = rowType[0].ToString(); string ContactName = rowType[1].ToString(); xlsSheet[6, 0].Value = xlsSheet[6, 0].Value.ToString().Replace("{%TEN_CONG_TY%}", Name); xlsSheet[7, 0].Value = xlsSheet[7, 0].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName); xlsSheet[9, 0].Value = xlsSheet[9, 0].Value.ToString().Replace("{%NGAY_HOP_DONG%}", lblBookingDate.Text).Replace("{%HOP_DONG%}", txtContractNo.Text); xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%GIO_TU%}", drpHourFrom.SelectedValue); xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%PHUT_TU%}", drpMinuteFrom.Value); xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%GIO_DEN%}", drpHourTo.SelectedValue); xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%PHUT_DEN%}", drpMinuteTo.Value); xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%NGAY_THUE%}", lblBookingDate.Text); } } } ds = new DataSet(); sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone"; sql += " FROM Mst_Building"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string Bank = rowType["Bank"].ToString(); string Account = rowType["Account"].ToString(); string AccountName = rowType["AccountName"].ToString(); string Office = rowType["Office"].ToString(); string OfficeAddress = rowType["OfficeAddress"].ToString(); string OfficePhone = rowType["OfficePhone"].ToString(); xlsSheet[35, 0].Value = xlsSheet[35, 0].Value.ToString().Replace("{%VAN_PHONG%}", Office); xlsSheet[36, 0].Value = xlsSheet[36, 0].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone); xlsSheet[38, 0].Value = xlsSheet[38, 0].Value.ToString().Replace("{%NGAN_HANG%}", Bank); xlsSheet[39, 0].Value = xlsSheet[39, 0].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName); xlsSheet[40, 0].Value = xlsSheet[40, 0].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account); } } } XLCellRange mrCell = new XLCellRange(0, 0, 0, 0); xlsSheet[27, 0].Value = xlsSheet[27, 0].Value.ToString().Replace("{%TI_GIA%}", Func.FormatNumber_New(txtRate.Text)).Replace("{%NGAY_AP_DUNG%}", txtRateDate.Text.Substring(0, 10)); ds = new DataSet(); sql = " SELECT *"; sql += " FROM v_BookingRoomInfo"; sql += " WHERE BookingId = '" + hidId.Value + "' "; int j = 0; int count = 0; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(18 + 1 + j); j++; } count++; int tmp = 18 + j; string Name = rowType["Name"].ToString(); string Regional = rowType["Regional"].ToString(); string Floor = rowType["Floor"].ToString(); string Area = rowType["Area"].ToString(); string PriceUSD = rowType["PriceUSD"].ToString(); string PriceVND = rowType["PriceVND"].ToString(); string SumUSD = rowType["SumUSD"].ToString(); string SumVND = rowType["SumVND"].ToString(); string VatUSD = rowType["VatUSD"].ToString(); string VatVND = rowType["VatVND"].ToString(); string LastPriceUSD = rowType["LastPriceUSD"].ToString(); string LastPriceVND = rowType["LastPriceVND"].ToString(); string BookingId = rowType["BookingId"].ToString(); xlsSheet[tmp, 1].Value = Name; xlsSheet[tmp, 2].Value = Regional; xlsSheet[tmp, 3].Value = Floor; xlsSheet[tmp, 4].Value = rowType["Area"]; xlsSheet[tmp, 5].Value = rowType["PriceUSD"]; xlsSheet[tmp, 6].Value = rowType["PriceVND"]; xlsSheet[tmp, 7].Value = rowType["SumUSD"]; xlsSheet[tmp, 8].Value = rowType["SumVND"]; xlsSheet[tmp, 9].Value = rowType["VatUSD"]; xlsSheet[tmp, 10].Value = rowType["VatVND"]; xlsSheet[tmp, 11].Value = rowType["LastPriceUSD"]; xlsSheet[tmp, 12].Value = rowType["LastPriceVND"]; LastSumPriceVND[0] += Convert.ToDecimal(rowType["LastPriceVND"]); LastSumPriceUSD[0] += Convert.ToDecimal(rowType["LastPriceUSD"]); for (int col = 1; col <= 12; col++) { xlsSheet[tmp, col].Style = xlstStyle; } } mrCell = new XLCellRange(18 + 1 + j, 18 + 1 + j, 1, 10); xlsSheet.MergedCells.Add(mrCell); xlsSheet[18 + 1 + j, 11].Value = LastSumPriceUSD[0]; xlsSheet[18 + 1 + j, 12].Value = LastSumPriceVND[0]; for (int col = 1; col <= 12; col++) { xlsSheet[18 + 1 + j, col].Style = xlstStyleSum; } } } XLSheet source = xlbBook.Sheets["tpl"]; for (int row = 21; row <= 25; row++) { for (int col = 0; col <= 12; col++) { xlsSheet[row + j, col].Style = source[row, col].Style; xlsSheet[row + j, col].Value = source[row, col].Value; } } //XLCellRange mrCell = new XLCellRange(22 + j, 23 + j, 1, 1); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 23 + j, 2, 2); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 23 + j, 3, 4); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 22 + j, 5, 6); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 22 + j, 7, 8); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 22 + j, 9, 10); //xlsSheet.MergedCells.Add(mrCell); //mrCell = new XLCellRange(22 + j, 22 + j, 11, 12); //xlsSheet.MergedCells.Add(mrCell); ds = new DataSet(); sql = " SELECT Service, Mount, PriceUSD, PriceVND, SumUSD, SumVND, VatUSD, VatVND, LastPriceUSD, LastPriceVND, Unit"; sql += " FROM PaymentBookingService"; sql += " WHERE BookingId = '" + hidId.Value + "' and (Delflag is null or Delflag = 0)"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(24 + 1 + j); j++; } count++; int tmp = 24 + j; string Service = rowType["Service"].ToString(); string Mount = rowType["Mount"].ToString(); string Unit = rowType["Unit"].ToString(); string PriceUSD = rowType["PriceUSD"].ToString(); string PriceVND = rowType["PriceVND"].ToString(); string SumUSD = rowType["SumUSD"].ToString(); string SumVND = rowType["SumVND"].ToString(); string VatUSD = rowType["VatUSD"].ToString(); string VatVND = rowType["VatVND"].ToString(); string LastPriceUSD = rowType["LastPriceUSD"].ToString(); string LastPriceVND = rowType["LastPriceVND"].ToString(); xlsSheet[tmp, 1].Value = Service; xlsSheet[tmp, 2].Value = rowType["Mount"]; xlsSheet[tmp, 3].Value = Unit; mrCell = new XLCellRange(tmp, tmp, 3, 4); xlsSheet.MergedCells.Add(mrCell); xlsSheet[tmp, 5].Value = rowType["PriceUSD"]; xlsSheet[tmp, 6].Value = rowType["PriceVND"]; xlsSheet[tmp, 7].Value = rowType["SumUSD"]; xlsSheet[tmp, 8].Value = rowType["SumVND"]; xlsSheet[tmp, 9].Value = rowType["VatUSD"]; xlsSheet[tmp, 10].Value = rowType["VatVND"]; xlsSheet[tmp, 11].Value = rowType["LastPriceUSD"]; xlsSheet[tmp, 12].Value = rowType["LastPriceVND"]; LastSumPriceVND[1] += Convert.ToDecimal(rowType["LastPriceVND"]); LastSumPriceUSD[1] += Convert.ToDecimal(rowType["LastPriceUSD"]); for (int col = 1; col <= 12; col++) { xlsSheet[tmp, col].Style = xlstStyle; } } mrCell = new XLCellRange(24 + 1 + j, 24 + 1 + j, 1, 10); xlsSheet.MergedCells.Add(mrCell); xlsSheet[24 + 1 + j, 11].Value = LastSumPriceUSD[1]; xlsSheet[24 + 1 + j, 12].Value = LastSumPriceVND[1]; for (int col = 1; col <= 12; col++) { xlsSheet[24 + 1 + j, col].Style = xlstStyleSum; } } } //////////////////Da Tra ds = new DataSet(); sql = " SELECT Sum(isnull(MoneyUSD,0)) USD, Sum(isnull(MoneyVND,0)) VND"; sql += " FROM Payment"; sql += " WHERE BookingId = '" + hidId.Value + "' and (Delflag is null or Delflag = 0)"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { int tmp = 29 + j; xlsSheet[tmp, 2].Value = (Func.ParseString(rowType["USD"]) == "" ? 0 : rowType["USD"]); xlsSheet[tmp, 4].Value = (Func.ParseString(rowType["VND"]) == "" ? 0 : rowType["VND"]); LastSumPriceVND[2] += Convert.ToDecimal(Func.ParseString(rowType["VND"]) == "" ? 0 : rowType["VND"]); LastSumPriceUSD[2] += Convert.ToDecimal(Func.ParseString(rowType["USD"]) == "" ? 0 : rowType["USD"]); } } } //////////////////Da Tra xlsSheet[28 + j, 2].Value = Func.FormatNumber_New(LastSumPriceUSD[0] + LastSumPriceUSD[1]); xlsSheet[28 + j, 4].Value = Func.FormatNumber_New(LastSumPriceVND[0] + LastSumPriceVND[1]); xlsSheet[30 + j, 2].Value = Func.FormatNumber_New(Convert.ToDecimal(txtRate.Text) * (LastSumPriceUSD[0] + LastSumPriceUSD[1] - LastSumPriceUSD[2])); xlsSheet[30 + j, 4].Value = Func.FormatNumber_New(LastSumPriceVND[0] + LastSumPriceVND[1] - LastSumPriceVND[2]); xlsSheet[31 + j, 3].Value = Func.FormatNumber_New(Convert.ToDecimal(txtRate.Text) * (LastSumPriceUSD[0] + LastSumPriceUSD[1] - LastSumPriceUSD[2]) + (LastSumPriceVND[0] + LastSumPriceVND[1] - LastSumPriceVND[2])); xlsSheet[32 + j, 2].Value = Func.docso(Convert.ToInt32(Convert.ToDecimal(txtRate.Text) * (LastSumPriceUSD[0] + LastSumPriceUSD[1] - LastSumPriceUSD[2]) + (LastSumPriceVND[0] + LastSumPriceVND[1] - LastSumPriceVND[2]))).ToUpper(); //xlsSheet[28 + j, 2].Style = xlstStyleSum; //xlsSheet[28 + j, 4].Style = xlstStyleSum; //xlsSheet[30 + j, 2].Style = xlstStyleSum; //xlsSheet[30 + j, 4].Style = xlstStyleSum; //xlsSheet[31 + j, 3].Style = xlstStyleSum; xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } }
protected void btnExport_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT *"; sql += " FROM v_MonthParkingCount"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; sql += " Order By CompanyName"; using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); db.Close(); if (ds != null) { C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl.xlsx"); xlbBook.Load(fileName); XLSheet xlsSheet = xlbBook.Sheets["DANH SÁCH BẢO VỆ"]; //xlsSheet.Name = drpMonth.SelectedValue + "_" + drpYear.SelectedValue; int i = 0; XLCellRange mrCell = new XLCellRange(0, 0, 0, 2); xlsSheet.MergedCells.Add(mrCell); XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.Font = new Font("", 12, FontStyle.Bold); xlstStyle.SetBorderColor(Color.Black); xlsSheet[i, 0].Value = "Tháng " + drpMonth.SelectedValue + "/" + drpYear.SelectedValue; xlsSheet[i, 0].Style = xlstStyle; xlsSheet[i + 1, 0].Value = "STT"; xlsSheet[i + 1, 1].Value = "Mã Nhân Viên"; xlsSheet[i + 1, 2].Value = "Họ và Tên"; XLStyle xlstStyle01 = new XLStyle(xlbBook); xlstStyle01.AlignHorz = XLAlignHorzEnum.Center; xlstStyle01.Font = new Font("", 10, FontStyle.Bold); xlstStyle.SetBorderColor(Color.Black); for (int j = 1; j <= 31; j++) { //xlsSheet[i, 2 + j].Value = j; //DateTime date = new DateTime(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue), j); //xlsSheet[i + 1, 2 + j].Value = dictionary[date.DayOfWeek.ToString().ToLower()]; //xlsSheet[i, 2 + j].Style = xlstStyle01; //xlsSheet[i + 1, 2 + j].Style = xlstStyle01; //if (j == DateTime.DaysInMonth(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue))) //{ // break; //} } //i++; //DataTable dt = ds.Tables[0]; //foreach (DataRow rowType in dt.Rows) //{ // int No = i; // i++; // string StaffId = rowType["StaffId"].ToString(); // string Name = rowType["Name"].ToString(); // xlsSheet[i, 0].Value = No; // xlsSheet[i, 1].Value = StaffId; // xlsSheet[i, 2].Value = Name; // xlsSheet[i, 0].Style = xlstStyle01; // xlsSheet[i, 1].Style = xlstStyle01; // xlsSheet[i, 2].Style = xlstStyle01; //} ////ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('/CSV/DownloadZipFile.aspx'," + PopupWidth + "," + PopupHeight + ",'EditFlat', true);", true); ////xlsSheet[i++, 0].Value = "Ghi chú:"; //DataSet ds1 = new DataSet(); //sql = string.Empty; //sql = " SELECT *"; //sql += " FROM BD_WorkingHour"; //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1"; //sql += " Order By Name"; //using (SqlCommand cm1 = db.CreateCommand(sql)) //{ // SqlDataAdapter da1 = new SqlDataAdapter(cm1); // da1.Fill(ds1); // db.Close(); // if (ds != null) // { // xlsSheet[i++ + 1, 0].Value = "Ghi chú:"; // DataTable dt1 = ds1.Tables[0]; // foreach (DataRow rowType in dt1.Rows) // { // i++; // string Ma = rowType["WorkingHourId"].ToString(); // string Name = rowType["Name"].ToString(); // xlsSheet[i, 0].Value = Ma + ":"; // xlsSheet[i, 1].Value = Name; // } // xlsSheet[i + 1, 0].Value = "OF:"; // xlsSheet[i + 1, 1].Value = "OF: nghỉ"; // } //} //string dataPath = HttpContext.Current.Server.MapPath(@"\Building\Staff\DataTmp"); //string tmpFolder = dataPath; //if (!Directory.Exists(tmpFolder)) //{ // Directory.CreateDirectory(tmpFolder); //} //string name = "KhaiBaoLichLamViec_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls"; //string fileName = Path.Combine(tmpFolder, name); string fileName1 = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl_1.xlsx"); xlbBook.Save(fileName1); //Session["ZipFilePath"] = null; //Session["ZipFilePath"] = fileName; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../Staff/DataTmp/" + name + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } }
protected void btnExport_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT A.GroupName, B.MaintenanceItem, B.ScheduleDate"; sql += " FROM BD_SuppliesGroup AS A Left outer JOIN"; sql += " BD_SuppliesGroupMaintenance AS B ON A.id = B.SuppliesGroupId"; sql += " and substring(ScheduleDate,1,4) = '" + drpYear.SelectedValue + "'"; sql += " and B.DelFlag = 0 Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.SuppliesType = '" + hidSuppliesType.Value + "'"; sql += " Order by GroupName, MaintenanceItem"; using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { C1XLBook xlbBook = new C1XLBook(); XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Left; xlstStyle.AlignVert = XLAlignVertEnum.Center; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; XLStyle xlstStyleS = new XLStyle(xlbBook); xlstStyleS.AlignHorz = XLAlignHorzEnum.Left; xlstStyleS.AlignVert = XLAlignVertEnum.Center; xlstStyleS.WordWrap = true; xlstStyleS.Font = new Font("", 8, FontStyle.Regular); xlstStyleS.SetBorderColor(Color.Black); xlstStyleS.BorderBottom = XLLineStyleEnum.Thin; xlstStyleS.BorderTop = XLLineStyleEnum.Thin; xlstStyleS.BorderLeft = XLLineStyleEnum.Thin; xlstStyleS.BorderRight = XLLineStyleEnum.Thin; xlstStyleS.BackColor = Color.Red; string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BaoTriDinhKy.xls"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoTriDinhKy")) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoTriDinhKy")); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoTriDinhKy\BaoTriDinhKy" + strDT + ".xls"; string strFilePathExport = "../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/BaoTriDinhKy/BaoTriDinhKy" + strDT + ".xls"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLSheet xlsSheet = xlbBook.Sheets["BaoTri"]; xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%NAM%}", drpYear.SelectedValue); int stt = 0; XLCellRange mCell = new XLCellRange(0, 0, 0, 0); int i = 4; DataTable dt = ds.Tables[0]; string tmpMaintenanceItem = ""; foreach (DataRow rowType in dt.Rows) { string GroupName = rowType["GroupName"].ToString(); string MaintenanceItem = rowType["MaintenanceItem"].ToString(); string ScheduleDate = rowType["ScheduleDate"].ToString(); if (String.IsNullOrEmpty(tmpMaintenanceItem)) { tmpMaintenanceItem = GroupName + MaintenanceItem; i++; } if (!tmpMaintenanceItem.Equals(GroupName + MaintenanceItem)) { i++; tmpMaintenanceItem = GroupName + MaintenanceItem; } xlsSheet[i, 1].Value = GroupName; xlsSheet[i, 2].Value = MaintenanceItem; mCell = new XLCellRange(i, i, 2, 3); xlsSheet.MergedCells.Add(mCell); xlsSheet[i, 1].Style = xlstStyle; xlsSheet[i, 2].Style = xlstStyle; for (int m = 0; m <= 51; m++) { xlsSheet[i, m].Style = xlstStyle; if ("X".Equals(xlsSheet[i, m].Value)) { xlsSheet[i, m].Style = xlstStyleS; } } if (!String.IsNullOrEmpty(ScheduleDate)) { int month = Func.ParseInt(ScheduleDate.Substring(4, 2)); int date = Func.ParseInt(ScheduleDate.Substring(6, 2)); int x = month * 4; if (date >= 1 && date <= 7) x += 0; if (date >= 8 && date <= 14) x += 1; if (date >= 15 && date <= 21) x += 2; if (date >= 22 && date <= 31) x += 3; xlsSheet[i, x].Value = "X"; xlsSheet[i, x].Style = xlstStyleS; } } i = 5; int k = 1; string tmp = xlsSheet[i, 1].Value.ToString(); xlsSheet[i, 0].Value = k; int y = i; i++; mCell = new XLCellRange(0, 0, 0, 0); ; while (!String.IsNullOrEmpty(Func.ParseString(xlsSheet[i, 1].Value))) { if (xlsSheet[i, 1].Value.ToString() != tmp) { tmp = xlsSheet[i, 1].Value.ToString(); mCell = new XLCellRange(y, i - 1, 1, 1); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(y, i - 1, 0, 0); xlsSheet.MergedCells.Add(mCell); y = i; xlsSheet[i, 0].Value = ++k; } i++; } mCell = new XLCellRange(y, i - 1, 1, 1); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(y, i - 1, 0, 0); xlsSheet.MergedCells.Add(mCell); xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } }
protected void btnView_Click(object sender, EventArgs e) { int rBillNo = 0; int cBillNo = 1; int rBillDate = 0; int cBillDate = 10; int rBillMonth = 2; int cBillMonth = 0; int rContact = 5; int cContact = 3; int rCustomer = 5; int cCustomer = 9; int rContract = 7; int cContract = 1; int rRate = 11; int cRate = 9; int rRateDate = 11; int cRateDate = 12; int rRent = 15; int rManager = 23; int rParking = 31; int rExtra = 39; int rElec = 47; int rWater = 55; int rService = 63; int rPaid = 70; int rDept = 77; int rOffice = 88; int cOffice = 3; int rPhone = 89; int cPhone = 3; int rBank = 89; int cBank = 7; int rAccountName = 91; int cAccountName = 7; int rAccount = 92; int cAccount = 7; int rSum = 81; int cSum = 11; int rSumRead = 82; int cSumRead = 13; int check = DbHelper.GetCount("Select count(*) from PaymentBillInfo Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + lblCustomerId.Text + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"); if (check == 0) { mvMessage.AddError("Xin vui lòng tạo hóa đơn trước khi xem"); return; } mvMessage.CheckRequired(txtBillDate, "Ngày xuất Hóa đơn là danh mục bắt buộc"); mvMessage.CheckRequired(txtBillNo, "Số Hóa đơn là danh mục bắt buộc"); mvMessage.CheckRequired(txtUsdExchange, "Tỉ giá USD-VN là danh mục bắt buộc"); mvMessage.CheckRequired(txtUsdExchangeDate, "Ngày tỉ giá là danh mục bắt buộc"); //ShowData(drpYear.SelectedValue + drpMonth.SelectedValue); C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BillTongQuat.xlsx"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))); } XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.AlignVert = XLAlignVertEnum.Center; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; xlstStyle.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleH = new XLStyle(xlbBook); xlstStyleH.AlignHorz = XLAlignHorzEnum.Center; xlstStyleH.AlignVert = XLAlignVertEnum.Center; xlstStyleH.Font = new Font("", 8, FontStyle.Bold); xlstStyleH.SetBorderColor(Color.Black); xlstStyleH.BorderBottom = XLLineStyleEnum.Thin; xlstStyleH.BorderTop = XLLineStyleEnum.Thin; xlstStyleH.BorderLeft = XLLineStyleEnum.Thin; xlstStyleH.BorderRight = XLLineStyleEnum.Thin; xlstStyleH.WordWrap = true; XLStyle xlstStyleSum = new XLStyle(xlbBook); xlstStyleSum.AlignHorz = XLAlignHorzEnum.Right; xlstStyleSum.AlignVert = XLAlignVertEnum.Center; xlstStyleSum.Font = new Font("", 8, FontStyle.Bold); xlstStyleSum.SetBorderColor(Color.Black); xlstStyleSum.BorderBottom = XLLineStyleEnum.Thin; xlstStyleSum.BorderTop = XLLineStyleEnum.Thin; xlstStyleSum.BorderLeft = XLLineStyleEnum.Thin; xlstStyleSum.BorderRight = XLLineStyleEnum.Thin; xlstStyleSum.WordWrap = true; string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BillTongQuat" + strDT + ".xlsx"; string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/BillTongQuat" + strDT + ".xlsx"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLSheet xlsSheet = xlbBook.Sheets["TongHop"]; //Bill No xlsSheet[rBillNo, cBillNo].Value = xlsSheet[rBillNo, cBillNo].Value.ToString().Replace("{%BILL_NO%}", txtBillNo.Text); //Ngay Thang Nam DateTime dtime = DateTime.Today; string strTmp = xlsSheet[rBillDate, cBillDate].Value.ToString().Replace("{%NGAY%}", dtime.ToString("dd")); strTmp = strTmp.Replace("{%THANG%}", dtime.ToString("MM")); xlsSheet[rBillDate, cBillDate].Value = strTmp.Replace("{%NAM%}", dtime.ToString("yyyy")); //Nam xlsSheet[rBillMonth, cBillMonth].Value = xlsSheet[rBillMonth, cBillMonth].Value.ToString().Replace("{%NAM_THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); using (SqlDatabase db = new SqlDatabase()) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT Name, ContactName"; sql += " FROM Customer"; sql += " WHERE CustomerId = '" + lblCustomerId.Text + "' "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string Name = rowType[0].ToString(); string ContactName = rowType[1].ToString(); //Customer xlsSheet[rCustomer, cCustomer].Value = xlsSheet[rCustomer, cCustomer].Value.ToString().Replace("{%TEN_CONG_TY%}", Name); //Contact xlsSheet[rContact, cContact].Value = xlsSheet[rContact, cContact].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName); } } } Hashtable contractIdLst = new Hashtable(); string contract = ""; ds = new DataSet(); sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone"; sql += " FROM Mst_Building"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string Bank = rowType["Bank"].ToString(); string Account = rowType["Account"].ToString(); string AccountName = rowType["AccountName"].ToString(); string Office = rowType["Office"].ToString(); string OfficeAddress = rowType["OfficeAddress"].ToString(); string OfficePhone = rowType["OfficePhone"].ToString(); xlsSheet[rOffice, cOffice].Value = xlsSheet[rOffice, cOffice].Value.ToString().Replace("{%VAN_PHONG%}", Office); xlsSheet[rPhone, cPhone].Value = xlsSheet[rPhone, cPhone].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone); xlsSheet[rBank, cBank].Value = xlsSheet[rBank, cBank].Value.ToString().Replace("{%NGAN_HANG%}", Bank); xlsSheet[rAccountName, cAccountName].Value = xlsSheet[rAccountName, cAccountName].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName); xlsSheet[rAccount, cAccount].Value = xlsSheet[rAccount, cAccount].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account); } } } xlsSheet[rRate, cRate].Value = xlsSheet[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", txtUsdExchange.Text); xlsSheet[rRateDate, cRateDate].Value = xlsSheet[rRateDate, cRateDate].Value.ToString().Replace("{%NGAY_AP_DUNG%}", txtUsdExchangeDate.Text); //Thue phong ds = new DataSet(); sql = " Select *"; sql += " FROM PaymentRoom"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; int sumRow = 0; int j = 0; decimal[] LastSumPriceVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; decimal[] LastSumPriceUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 }; decimal PaidPriceVND = 0; decimal PaidPriceUSD = 0; int line = 0; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rRent - 3 + j; XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rRent + j); j++; } count++; int tmp = rRent + j; string ContractId = Func.ParseString(rowType["ContractId"]); string YearMonth = Func.ParseString(rowType["YearMonth"]); string Area = Func.ParseString(rowType["Area"]); string Name = Func.ParseString(rowType["Name"]); string Regional = Func.ParseString(rowType["Regional"]); string Floor = Func.ParseString(rowType["Floor"]); string BeginContract = Func.ParseString(rowType["BeginContract"]); if (!contractIdLst.ContainsKey(ContractId + "(" + BeginContract.Substring(0, 10) + ")")) { contractIdLst.Add(ContractId + "(" + BeginContract.Substring(0, 10) + ")", ContractId + "(" + BeginContract.Substring(0, 10) + ")"); contract += ";" + ContractId + "(" + BeginContract.Substring(0, 10) + ")"; } xlsSheet[tmp, 1].Value = Name; xlsSheet[tmp, 4].Value = rowType["Area"]; xlsSheet[tmp, 6].Value = rowType["MonthRentPriceUSD"]; xlsSheet[tmp, 7].Value = rowType["MonthRentPriceVND"]; xlsSheet[tmp, 8].Value = rowType["MonthRentSumUSD"]; xlsSheet[tmp, 9].Value = rowType["MonthRentSumVND"]; xlsSheet[tmp, 10].Value = rowType["VatRentPriceUSD"]; xlsSheet[tmp, 11].Value = rowType["VatRentPriceVND"]; xlsSheet[tmp, 12].Value = rowType["LastRentSumUSD"]; xlsSheet[tmp, 13].Value = rowType["LastRentSumVND"]; XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheet.MergedCells.Add(mrCell); LastSumPriceVND[0] += Convert.ToDecimal(rowType["LastRentSumVND"]); LastSumPriceUSD[0] += Convert.ToDecimal(rowType["LastRentSumUSD"]); } mCell = new XLCellRange(rRent + 1 + j, rRent + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheet[rRent + 1 + j, 12].Value = LastSumPriceUSD[0]; xlsSheet[rRent + 1 + j, 13].Value = LastSumPriceVND[0]; for (int row = rRent + sumRow - 2; row <= rRent + dt.Rows.Count; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; } } sumRow += dt.Rows.Count - 1; //////////////////////// for (int col = 1; col <= 11; col++) { xlsSheet[rRent + 1 + j, col].Style = xlstStyleSum; } line = rManager - 3 + j; mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); count = 0; foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rManager + j); j++; } count++; int tmp = rManager; string YearMonth = Func.ParseString(row["YearMonth"]); string Area = Func.ParseString(row["Area"]); string Name = Func.ParseString(row["Name"]); xlsSheet[tmp, 1].Value = Name; xlsSheet[tmp, 4].Value = row["Area"]; xlsSheet[tmp, 6].Value = row["MonthManagerPriceUSD"]; xlsSheet[tmp, 7].Value = row["MonthManagerPriceVND"]; xlsSheet[tmp, 8].Value = row["MonthManagerSumUSD"]; xlsSheet[tmp, 9].Value = row["MonthManagerSumVND"]; xlsSheet[tmp, 19].Value = row["VatManagerPriceUSD"]; xlsSheet[tmp, 11].Value = row["VatManagerPriceVND"]; xlsSheet[tmp, 12].Value = row["LastManagerSumUSD"]; xlsSheet[tmp, 13].Value = row["LastManagerSumVND"]; XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheet.MergedCells.Add(mrCell); LastSumPriceVND[1] += Convert.ToDecimal(row["LastManagerSumVND"]); LastSumPriceUSD[1] += Convert.ToDecimal(row["LastManagerSumUSD"]); } mCell = new XLCellRange(rManager + 1 + j, rManager + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheet[rManager + 1 + j, 12].Value = LastSumPriceUSD[1]; xlsSheet[rManager + 1 + j, 13].Value = LastSumPriceVND[1]; for (int row = rManager + sumRow - 2; row <= rManager + sumRow + dt.Rows.Count; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; } } for (int col = 1; col <= 11; col++) { xlsSheet[rManager + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1; } } ds = new DataSet(); //Xuất ra toàn bộ nội dung theo Trang sql = " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVND, PriceUSD, SUM(VatVND) AS VatVND,SUM(VatUSD) AS VatUSD, SUM(SumVND) AS SumVND, SUM(SumUSD) AS SumUSD, SUM(LastPriceVND) AS LastPriceVND"; sql += " , SUM(LastPriceUSD) AS LastPriceUSD"; sql += " FROM dbo.PaymentParking"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rParking - 3 + j; XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rParking + 1 + j); j++; } count++; int tmp = rParking + j; string Num = Func.ParseString(row["Num"]); string TariffsParkingName = Func.ParseString(row["TariffsParkingName"]); xlsSheet[tmp, 1].Value = TariffsParkingName; xlsSheet[tmp, 4].Value = Num; xlsSheet[tmp, 6].Value = row["PriceUSD"]; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["SumUSD"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 10].Value = row["VatUSD"]; xlsSheet[tmp, 11].Value = row["VatVND"]; xlsSheet[tmp, 12].Value = row["LastPriceUSD"]; xlsSheet[tmp, 13].Value = row["LastPriceVND"]; XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheet.MergedCells.Add(mrCell); LastSumPriceVND[2] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[2] += Convert.ToDecimal(row["LastPriceUSD"]); } xlsSheet[rParking + 1 + j, 12].Value = LastSumPriceUSD[2]; xlsSheet[rParking + 1 + j, 13].Value = LastSumPriceVND[2]; mCell = new XLCellRange(rParking + 1 + j, rParking + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); for (int row = rParking + sumRow - 2; row <= rParking + sumRow + dt.Rows.Count; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; } } for (int col = 1; col <= 11; col++) { xlsSheet[rParking + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1; } } //Lam ngoai gio ds = new DataSet(); sql = " SELECT ExtraHour, dbo.fnDateTime(WorkingDate) WorkingDate, PriceVND,PriceUSD,VatUSD,VatVND,SumVND,SumUSD,LastPriceVND,LastPriceUSD "; sql += " FROM PaymentExtraTime"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rExtra - 3 + j; //Phi dien XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 2, line + 2, 4, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rExtra + 1 + j); j++; } count++; int tmp = rExtra + j; //string id = Func.ParseString(row["id"]); string ExtraHour = Func.ParseString(row["ExtraHour"]); string WorkingDate = Func.ParseString(row["WorkingDate"]); xlsSheet[tmp, 1].Value = WorkingDate; xlsSheet[tmp, 4].Value = ExtraHour; xlsSheet[tmp, 6].Value = row["PriceUSD"]; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["SumUSD"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 10].Value = row["VatUSD"]; xlsSheet[tmp, 11].Value = row["VatVND"]; xlsSheet[tmp, 12].Value = row["LastPriceUSD"]; xlsSheet[tmp, 13].Value = row["LastPriceVND"]; XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(tmp, tmp, 4, 5); xlsSheet.MergedCells.Add(mrCell); for (int col = 1; col <= 13; col++) { xlsSheet[tmp, col].Style = xlstStyle; } LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[3] += Convert.ToDecimal(row["LastPriceUSD"]); } mCell = new XLCellRange(rExtra + 1 + j, rExtra + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); xlsSheet[rExtra + 1 + j, 12].Value = LastSumPriceUSD[3]; xlsSheet[rExtra + 1 + j, 13].Value = LastSumPriceVND[3]; for (int row = rExtra + sumRow - 2; row <= rExtra + sumRow + dt.Rows.Count; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; } } for (int col = 1; col <= 12; col++) { xlsSheet[rExtra + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1; } } ds = new DataSet(); //Dien //Xuất ra toàn bộ nội dung theo Trang sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, "; sql += " B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name "; sql += " FROM PaymentElecWater AS A INNER JOIN "; sql += " PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId"; sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0 and A.YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; sql += " Order by A.DateFrom, B.FromIndex"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rElec - 3 + j; //Phi dien XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 3, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 5, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 7, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 8, 8); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 9, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 9, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 11, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 12, 13); xlsSheet.MergedCells.Add(mCell); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rElec + 1 + j); j++; } count++; int tmp = rElec + j; string DateFrom = Func.ParseString(row["DateFrom"]); string DateTo = Func.ParseString(row["DateTo"]); string FromIndex = Func.ParseString(row["FromIndex"]); string ToIndex = Func.ParseString(row["ToIndex"]); string OtherFee01 = Func.ParseString(row["OtherFee01"]); string OtherFee02 = Func.ParseString(row["OtherFee02"]); string Mount = Func.ParseString(row["Mount"]); xlsSheet[tmp, 1].Value = DateFrom; xlsSheet[tmp, 2].Value = DateTo; xlsSheet[tmp, 3].Value = FromIndex; xlsSheet[tmp, 4].Value = ToIndex; xlsSheet[tmp, 5].Value = OtherFee01; xlsSheet[tmp, 6].Value = Mount; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["VatVND"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 11].Value = row["OtherFee02"]; xlsSheet[tmp, 12].Value = row["LastPriceVND"]; mCell = new XLCellRange(tmp, tmp, 9, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(tmp, tmp, 12, 13); xlsSheet.MergedCells.Add(mCell); for (int col = 1; col <= 12; col++) { xlsSheet[tmp, col].Style = xlstStyle; } LastSumPriceVND[4] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[4] += Convert.ToDecimal(row["LastPriceUSD"]); } xlsSheet[rElec + 1 + j, 12].Value = LastSumPriceVND[4]; mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 12, 13); xlsSheet.MergedCells.Add(mCell); for (int row = rElec + sumRow - 2; row <= rElec + sumRow + dt.Rows.Count; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; } } for (int col = 1; col <= 11; col++) { xlsSheet[rElec + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1; } } ds = new DataSet(); //Nuoc //Xuất ra toàn bộ nội dung theo Trang sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, "; sql += " B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name "; sql += " FROM PaymentElecWater AS A INNER JOIN "; sql += " PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId"; sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and A.YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; sql += " Order by A.DateFrom, B.FromIndex"; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rWater - 3 + j; //Phi dien XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 2, 2); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 3, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 6, 6); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 7, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 8, 8); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 9, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 9, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 11, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 12, 13); xlsSheet.MergedCells.Add(mCell); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rWater + 1 + j); j++; } count++; int tmp = rWater + j; string DateFrom = Func.ParseString(row["DateFrom"]); string DateTo = Func.ParseString(row["DateTo"]); string FromIndex = Func.ParseString(row["FromIndex"]); string ToIndex = Func.ParseString(row["ToIndex"]); string OtherFee01 = Func.ParseString(row["OtherFee01"]); string OtherFee02 = Func.ParseString(row["OtherFee02"]); string Mount = Func.ParseString(row["Mount"]); xlsSheet[tmp, 1].Value = DateFrom; xlsSheet[tmp, 2].Value = DateTo; xlsSheet[tmp, 3].Value = FromIndex; xlsSheet[tmp, 4].Value = ToIndex; xlsSheet[tmp, 5].Value = Mount; xlsSheet[tmp, 6].Value = row["PriceVND"]; xlsSheet[tmp, 7].Value = row["OtherFee01"]; xlsSheet[tmp, 8].Value = row["VatVND"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 11].Value = row["OtherFee02"]; xlsSheet[tmp, 12].Value = row["LastPriceVND"]; for (int col = 1; col <= 12; col++) { xlsSheet[tmp, col].Style = xlstStyle; } LastSumPriceVND[5] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[5] += Convert.ToDecimal(row["LastPriceUSD"]); mCell = new XLCellRange(tmp, tmp, 9, 10); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(tmp, tmp, 12, 13); xlsSheet.MergedCells.Add(mCell); } xlsSheet[rWater + 1 + j, 12].Value = LastSumPriceVND[5]; mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 12, 13); xlsSheet.MergedCells.Add(mCell); for (int row = rWater + sumRow - 2; row <= rWater + sumRow + dt.Rows.Count; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; } } for (int col = 1; col <= 11; col++) { xlsSheet[rWater + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1; } } //Service ds = new DataSet(); sql = string.Empty; sql = " SELECT Service,dbo.fnDateTime(ServiceDateFrom) ServiceDateFrom,dbo.fnDateTime(ServiceDateTo) ServiceDateTo,PriceVND,PriceUSD,VatUSD,VatVND,Mount,SumVND,SumUSD,LastPriceVND,LastPriceUSD "; sql += " FROM PaymentService"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; sql += " Order By ServiceDate "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rService - 3 + j; //Phi khác XLCellRange mCell = new XLCellRange(line, line + 2, 1, 2); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 3, 3); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line + 2, 4, 4); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 2, 5, 5); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 6, 7); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 8, 9); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 10, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line, line, 12, 13); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(line + 1, line + 1, 12, 13); xlsSheet.MergedCells.Add(mCell); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; foreach (DataRow row in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rService + j); j++; } count++; int tmp = rService + j; string Service = Func.ParseString(row["Service"]); string ServiceDateFrom = Func.ParseString(row["ServiceDateFrom"]); string ServiceDateTo = Func.ParseString(row["ServiceDateTo"]); string Mount = Func.ParseString(row["Mount"]); xlsSheet[tmp, 1].Value = Service; xlsSheet[tmp, 3].Value = ServiceDateFrom; xlsSheet[tmp, 4].Value = ServiceDateTo; xlsSheet[tmp, 5].Value = Mount; xlsSheet[tmp, 6].Value = row["PriceUSD"]; xlsSheet[tmp, 7].Value = row["PriceVND"]; xlsSheet[tmp, 8].Value = row["SumUSD"]; xlsSheet[tmp, 9].Value = row["SumVND"]; xlsSheet[tmp, 10].Value = row["VatUSD"]; xlsSheet[tmp, 11].Value = row["VatVND"]; xlsSheet[tmp, 12].Value = row["LastPriceUSD"]; xlsSheet[tmp, 13].Value = row["LastPriceVND"]; for (int col = 1; col <= 13; col++) { xlsSheet[tmp, col].Style = xlstStyle; } LastSumPriceVND[6] += Convert.ToDecimal(row["LastPriceVND"]); LastSumPriceUSD[6] += Convert.ToDecimal(row["LastPriceUSD"]); } xlsSheet[rService + 1 + j, 12].Value = LastSumPriceUSD[6]; xlsSheet[rService + 1 + j, 13].Value = LastSumPriceVND[6]; mCell = new XLCellRange(rService + 1 + j, rService + 1 + j, 1, 11); xlsSheet.MergedCells.Add(mCell); mCell = new XLCellRange(rService + 1 + j, rService + 1 + j, 12, 13); xlsSheet.MergedCells.Add(mCell); for (int row = rService + sumRow - 2; row <= rService + sumRow + dt.Rows.Count; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; } } for (int col = 1; col <= 11; col++) { xlsSheet[rService + 1 + j, col].Style = xlstStyleSum; } sumRow += dt.Rows.Count - 1; } } //Paid sql = "Select *"; sql += " From PaymentBillDetail"; sql += " Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; DataTable dtPaid = DbHelper.GetDataTable(sql); for (int i = 0; i < dtPaid.Rows.Count; i++) { string PaymentType = Func.ParseString(dtPaid.Rows[i]["PaymentType"]); string MoneyUSD = Func.ParseString(dtPaid.Rows[i]["MoneyUSD"]); string MoneyVND = Func.ParseString(dtPaid.Rows[i]["MoneyVND"]); string PaidUSD = Func.ParseString(dtPaid.Rows[i]["PaidUSD"]); string PaidVND = Func.ParseString(dtPaid.Rows[i]["PaidVND"]); string ExchangeType = Func.ParseString(dtPaid.Rows[i]["ExchangeType"]); string UsdExchange = Func.ParseString(dtPaid.Rows[i]["UsdExchange"]); string YearMonth = Func.ParseString(dtPaid.Rows[i]["YearMonth"]); decimal tmpUSD = Convert.ToDecimal(MoneyUSD) - Convert.ToDecimal(PaidUSD); decimal tmpVND = Convert.ToDecimal(MoneyVND) - Convert.ToDecimal(PaidVND); PaidPriceUSD += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]); PaidPriceVND += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); xlsSheet[rPaid + j, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4); switch (PaymentType) { case "1": //Rent xlsSheet[rPaid + 1 + j, 2].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + 1 + j, 3].Value = dtPaid.Rows[i]["PaidVND"]; break; case "2": //Manager xlsSheet[rPaid + 1 + j, 4].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + 1 + j, 5].Value = dtPaid.Rows[i]["PaidVND"]; break; case "3": //Parking xlsSheet[rPaid + 1 + j, 6].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + 1 + j, 7].Value = dtPaid.Rows[i]["PaidVND"]; break; case "4": //Extra xlsSheet[rPaid + 1 + j, 8].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + 1 + j, 9].Value = dtPaid.Rows[i]["PaidVND"]; break; case "5": xlsSheet[rPaid + 1 + j, 10].Value = dtPaid.Rows[i]["PaidVND"]; break; case "6": xlsSheet[rPaid + 1 + j, 11].Value = dtPaid.Rows[i]["PaidVND"]; break; case "7": xlsSheet[rPaid + 1 + j, 12].Value = dtPaid.Rows[i]["PaidUSD"]; xlsSheet[rPaid + 1 + j, 13].Value = dtPaid.Rows[i]["PaidVND"]; break; default: break; } } int lineTmp = rPaid - 2 + j; //Phi khác XLCellRange mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13); xlsSheet.MergedCells.Add(mCellTmp); for (int row = lineTmp; row <= rPaid + 1 + j; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; } } xlsSheet[lineTmp + 3, 1].Style = xlstStyleSum; lineTmp = rDept - 2 + j; //Dept mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9); xlsSheet.MergedCells.Add(mCellTmp); mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13); xlsSheet.MergedCells.Add(mCellTmp); for (int row = lineTmp; row <= rDept + 1 + j; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; } } xlsSheet[lineTmp + 3, 1].Style = xlstStyleSum; decimal AllSumVND = 0; decimal AllSumUSD = 0; for (int i = 0; i < 7; i++) { AllSumVND += LastSumPriceVND[i]; AllSumUSD += LastSumPriceUSD[i]; } AllSumVND -= PaidPriceVND; AllSumUSD -= PaidPriceUSD; AllSumVND += Convert.ToDecimal(AllSumUSD * Convert.ToDecimal(txtUsdExchange.Text)); string strMoney = Func.docso(Convert.ToInt32(AllSumVND)); xlsSheet[rContract, cContract].Value = xlsSheet[rContract, cContract].Value.ToString().Replace("{%HOP_DONG%}", contract.Substring(1)); xlsSheet[rSum + j, cSum].Value = Convert.ToInt32(AllSumVND); xlsSheet[rSumRead + j, cSumRead].Value = xlsSheet[rSumRead + j, cSumRead].Value.ToString().Replace("{%TONG_CHU%}", strMoney.ToUpper()); xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } }
protected void btnExport_Click(object sender, EventArgs e) { C1XLBook xlbBook = new C1XLBook(); XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Left; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; //xlstStyle.Format = "#,##0.00_);(#,##0.00)"; xlstStyle.AlignVert = XLAlignVertEnum.Top; XLStyle xlstStyleN = new XLStyle(xlbBook); xlstStyleN.AlignHorz = XLAlignHorzEnum.Right; xlstStyleN.WordWrap = true; xlstStyleN.Font = new Font("", 8, FontStyle.Regular); xlstStyleN.SetBorderColor(Color.Black); xlstStyleN.BorderBottom = XLLineStyleEnum.Thin; xlstStyleN.BorderTop = XLLineStyleEnum.Thin; xlstStyleN.BorderLeft = XLLineStyleEnum.Thin; xlstStyleN.BorderRight = XLLineStyleEnum.Thin; xlstStyleN.Format = "#,##0.00_);(#,##0.00)"; xlstStyleN.AlignVert = XLAlignVertEnum.Top; XLStyle xlstStyleS = new XLStyle(xlbBook); xlstStyleS.AlignHorz = XLAlignHorzEnum.Left; xlstStyleS.WordWrap = true; xlstStyleS.Font = new Font("", 8, FontStyle.Bold); xlstStyleS.SetBorderColor(Color.Black); xlstStyleS.BorderBottom = XLLineStyleEnum.Thin; xlstStyleS.BorderTop = XLLineStyleEnum.Thin; xlstStyleS.BorderLeft = XLLineStyleEnum.Thin; xlstStyleS.BorderRight = XLLineStyleEnum.Thin; xlstStyleS.Format = "#,##0.00_);(#,##0.00)"; xlstStyleS.AlignVert = XLAlignVertEnum.Top; string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\MayMocThietBi.xls"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\MayMocThietBi")) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\MayMocThietBi")); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\MayMocThietBi\MayMocThietBi" + strDT + ".xls"; string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/MayMocThietBi/MayMocThietBi" + strDT + ".xls"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); DataSet ds = new DataSet(); string sql = string.Empty; //sql = " SELECT *"; //sql += " FROM Report_BuildingInfo where delflag = '0'"; ////sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; ////sql += " AND ((NgayKetThuc is null) OR "; ////sql += " (NgayKetThuc is not null and substring(NgayKetThuc,1,6) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'))"; //using (SqlDatabase db = new SqlDatabase()) //{ // using (SqlCommand cm = db.CreateCommand(sql)) // { // SqlDataAdapter da = new SqlDataAdapter(cm); // da.Fill(ds); // if (ds != null) // { // XLSheet xlsSheetMenu = xlbBook.Sheets["Menu"]; // xlsSheetMenu[2, 1].Value = xlsSheetMenu[2, 1].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); // DataTable dt = ds.Tables[0]; // foreach (DataRow rowType in dt.Rows) // { // int stt = 0; // string id = rowType["id"].ToString(); // string sheet = rowType["Sheet"].ToString(); // int NumOfCol = Func.ParseInt(rowType["NoOfColumn"].ToString()); // string SqlSelect = rowType["SqlSelect"].ToString().Replace("{%NAM_THANG%}", drpYear.SelectedValue + drpMonth.SelectedValue); // SqlSelect = SqlSelect.Replace("{%TOA_NHA%}", Func.ParseString(Session["__BUILDINGID__"])); // int CellY = Func.ParseInt(rowType["CellBeginY"].ToString()); // int CellX = Func.ParseInt(rowType["CellBeginX"].ToString()); // string[] Col = rowType["SumCol"].ToString().Split(','); // decimal[] SumCol = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // using (SqlCommand cmSheet = db.CreateCommand(SqlSelect)) // { // DataSet dsSheet = new DataSet(); // SqlDataAdapter daSheet = new SqlDataAdapter(cmSheet); // daSheet.Fill(dsSheet); // if (dsSheet != null) // { // XLSheet xlsSheet = xlbBook.Sheets[sheet]; // DataTable dtSheet = dsSheet.Tables[0]; // foreach (DataRow rowSheet in dtSheet.Rows) // { // xlsSheet[CellY + stt, CellX].Style = xlstStyle; // xlsSheet[CellY + stt, CellX].Value = Func.ParseString(++stt); // for (int k = 0; k < NumOfCol; k++) // { // string tmp = rowSheet[k].ToString(); // xlsSheet[CellY + stt - 1, CellX + k + 1].Value = rowSheet[k]; // xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyle; // switch (rowSheet[k].GetType().Name) // { // case "Decimal": // //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseDouble(tmp); // //break; // SumCol[k] += Convert.ToDecimal(rowSheet[k]); // xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyleN; // break; // case "Double": // //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseDouble(tmp); // SumCol[k] += Convert.ToDecimal(rowSheet[k]); // xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyleN; // break; // //break; // case "Int32": // //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseInt(tmp); // SumCol[k] += Convert.ToDecimal(rowSheet[k]); // xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyleN; // break; // //break; // case "Single": // SumCol[k] += Convert.ToDecimal(rowSheet[k]); // xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyleN; // break; // //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = rowSheet[k];// Func.ParseInt(tmp); // //xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyleN; // default: // xlsSheet[CellY + stt - 1, CellX + k + 1].Value = tmp; // xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyle; // break; // } // //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = tmp; // //xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyle; // } // } // if (!String.IsNullOrEmpty(Col[0])) // { // for (int m = 0; m < NumOfCol + 1; m++) // { // xlsSheet[CellY + stt, m].Style = xlstStyleS; // } // } // if (!String.IsNullOrEmpty(Col[0])) // { // xlsSheet[CellY + stt, 0].Value = "Tổng cộng"; // XLCellRange mrCell = new XLCellRange(CellY + stt, CellY + stt, 0, Func.ParseInt(Col[0])); // xlsSheet.MergedCells.Add(mrCell); // for (int m = 0; m <= Func.ParseInt(Col[0]); m++) // { // xlsSheet[CellY + stt, m].Style = xlstStyleS; // } // } // for (int m = 0; m < Col.Length; m++) // { // if (!String.IsNullOrEmpty(Col[m])) // { // xlsSheet[CellY + stt, CellX + Func.ParseInt(Col[m]) + 1].Value = SumCol[Func.ParseInt(Col[m])]; // xlsSheet[CellY + stt, CellX + Func.ParseInt(Col[m]) + 1].Style = xlstStyleS; // } // } // } // } // } // } // } //} ds = new DataSet(); sql = string.Empty; sql = " SELECT *"; sql += " FROM Report_BuildingInfo where id = 54 and delflag = '2'"; using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { int stt = 0; string id = rowType["id"].ToString(); string sheet = "BaoCao"; int NumOfCol = Func.ParseInt(rowType["NoOfColumn"].ToString()); string SqlSelect = rowType["SqlSelect"].ToString().Replace("{%NAM_THANG%}", drpYear.SelectedValue + drpMonth.SelectedValue); SqlSelect = SqlSelect.Replace("{%TOA_NHA%}", Func.ParseString(Session["__BUILDINGID__"])); int CellY = Func.ParseInt(rowType["CellBeginY"].ToString()); int CellX = Func.ParseInt(rowType["CellBeginX"].ToString()); string[] Col = rowType["SumCol"].ToString().Split(','); decimal[] SumCol = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; XLCellRange mrCell = new XLCellRange(0, 0, 0, 0); string group = ""; int i = 0; using (SqlCommand cmSheet = db.CreateCommand(SqlSelect)) { DataSet dsSheet = new DataSet(); SqlDataAdapter daSheet = new SqlDataAdapter(cmSheet); daSheet.Fill(dsSheet); if (dsSheet != null) { XLSheet xlsSheet = xlbBook.Sheets[sheet]; xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%TOA_NHA%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); DataTable dtSheet = dsSheet.Tables[0]; foreach (DataRow rowSheet in dtSheet.Rows) { string col11 = rowSheet[NumOfCol].ToString(); if (!group.Equals(col11)) { xlsSheet[CellY + i, CellX].Value = col11; group = col11; for (int k = 0; k <= NumOfCol; k++) { xlsSheet[CellY + i, CellX + k].Style = xlstStyleS; } mrCell = new XLCellRange(CellY + i, CellY + i, 0, NumOfCol); xlsSheet.MergedCells.Add(mrCell); xlsSheet[CellY + i, CellX].Style = xlstStyleS; i++; } xlsSheet[CellY + i, CellX + 0].Value = ++stt; xlsSheet[CellY + i, CellX + 0].Style = xlstStyle; for (int m = 1; m <= NumOfCol; m++) { xlsSheet[CellY + i, CellX + m].Value = rowSheet[m - 1]; xlsSheet[CellY + i, CellX + m].Style = xlstStyle; } ++i; } } } } } } } xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); }
public void mergeCell(int rowFrom, int rowTo, int colFrom, int colTo) { XLCellRange mergeCell = new XLCellRange(rowFrom, rowTo, colFrom, colTo); xlsSheet.MergedCells.Add(mergeCell); xlsSheetEn.MergedCells.Add(mergeCell); }
//--------------------------------------------------------------------------------- #region "** object model" /// <summary> /// Saves the content of a C1FlexGrid into an XLSheet. /// </summary> public static void Save(C1FlexGrid flex, XLSheet sheet) { // clear style cache if this is a new book if (!object.ReferenceEquals(sheet.Book, _lastBook)) { _cellStyles.Clear(); _excelStyles.Clear(); _lastBook = sheet.Book; } // save global parameters sheet.DefaultRowHeight = PixelsToTwips(flex.Rows.DefaultSize); sheet.DefaultColumnWidth = PixelsToTwips(flex.Columns.DefaultSize); sheet.ShowGridLines = flex.GridLinesVisibility != GridLinesVisibility.None; sheet.ShowHeaders = flex.HeadersVisibility != HeadersVisibility.None; sheet.OutlinesBelow = flex.GroupRowPosition == GroupRowPosition.BelowData; // save columns sheet.Columns.Clear(); foreach (Column col in flex.Columns) { dynamic c = sheet.Columns.Add(); if (!col.Width.IsAuto) { c.Width = PixelsToTwips(col.ActualWidth); } c.Visible = col.Visible; if (col.CellStyle is ExcelCellStyle) { c.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)col.CellStyle); } } sheet.Rows.Clear(); //save column headers XLStyle headerStyle = default(XLStyle); headerStyle = new XLStyle(sheet.Book); headerStyle.Font = new XLFont("Microsoft YaHei", 10, true, false); headerStyle.BorderLeft = XLLineStyleEnum.Thin; headerStyle.BorderTop = XLLineStyleEnum.Thin; headerStyle.BorderRight = XLLineStyleEnum.Thin; headerStyle.BorderBottom = XLLineStyleEnum.Thin; //save column headers foreach (Row row in flex.ColumnHeaders.Rows) { dynamic r = sheet.Rows.Add(); if (row.Height > -1) { r.Height = PixelsToTwips(row.Height); } if (row.CellStyle is ExcelCellStyle) { r.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)row.CellStyle); } if (row is ExcelRow) { r.OutlineLevel = ((ExcelRow)row).Level; } for (int c = 0; c <= flex.ColumnHeaders.Columns.Count - 1; c++) { // save cell value dynamic cell = sheet[row.Index, c]; string colHeader = flex.Columns[c].Header; cell.Value = colHeader; // make column headers bold cell.Style = headerStyle; } r.Visible = row.Visible; } // save rows foreach (Row row in flex.Rows) { dynamic r = sheet.Rows.Add(); if (row.Height > -1) { r.Height = PixelsToTwips(row.Height); } if (row.CellStyle is ExcelCellStyle) { r.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)row.CellStyle); } if (row is ExcelRow) { r.OutlineLevel = ((ExcelRow)row).Level; } r.Visible = row.Visible; } XLStyle dateTimeStyle = default(XLStyle); dateTimeStyle = new XLStyle(sheet.Book); dateTimeStyle.Font = new XLFont("Microsoft YaHei", 10, false, false); dateTimeStyle.Format = "yyyy/mm/dd"; dateTimeStyle.BorderLeft = XLLineStyleEnum.Thin; dateTimeStyle.BorderTop = XLLineStyleEnum.Thin; dateTimeStyle.BorderRight = XLLineStyleEnum.Thin; dateTimeStyle.BorderBottom = XLLineStyleEnum.Thin; XLStyle normalStyle = default(XLStyle); normalStyle = new XLStyle(sheet.Book); normalStyle.Font = new XLFont("Microsoft YaHei", 10, false, false); normalStyle.BorderLeft = XLLineStyleEnum.Thin; normalStyle.BorderTop = XLLineStyleEnum.Thin; normalStyle.BorderRight = XLLineStyleEnum.Thin; normalStyle.BorderBottom = XLLineStyleEnum.Thin; // save cells for (int r = flex.ColumnHeaders.Rows.Count; r <= flex.Rows.Count; r++) { for (int c = 0; c <= flex.Columns.Count - 1; c++) { // save cell value dynamic cell = sheet[r, c]; dynamic obj = flex[r - 1, c]; if (obj is DateTime) { cell.Style = dateTimeStyle; } else { cell.Style = normalStyle; } cell.Value = obj is FrameworkElement ? 0 : obj; // save cell formula and style //dynamic row = flex.Rows[r - 1] as ExcelRow; //if(row != null) //{ // // save cell formula // dynamic col = flex.Columns[c]; // // save cell style // dynamic cs = row.GetCellStyle(col) as ExcelCellStyle; // if(cs != null) // { // cell.Style = GetXLStyle(flex, sheet, cs); // } //} } } // save selection dynamic sel = flex.Selection; if (sel.IsValid) { dynamic xlSel = new XLCellRange(sheet, sel.Row, sel.Row2, sel.Column, sel.Column2); sheet.SelectedCells.Clear(); sheet.SelectedCells.Add(xlSel); } }
public static XLSheet ToXLSheet(this Worksheet worksheet, C1XLBook host, int sheetIndex) { int nRows = worksheet.Data.Count; int nCols = worksheet.Data.Max(x => x.Count); // Set sheet-wide properties var c1Sheet = sheetIndex < host.Sheets.Count ? host.Sheets[sheetIndex] : host.Sheets.Add(); c1Sheet.Name = worksheet.Name; c1Sheet.DefaultColumnWidth = worksheet.DefaultColumnWidth ?? DefaultColumnWidth; c1Sheet.DefaultRowHeight = worksheet.DefaultRowHeight ?? DefaultRowHeight; // Rows and columns c1Sheet.Rows.Clear(); foreach (var row in worksheet.Rows) { c1Sheet.Rows.Add(new XLRow { Height = row.Height ?? c1Sheet.DefaultRowHeight, Style = row.Style.ToXLStyle(host) }); } c1Sheet.Columns.Clear(); foreach (var col in worksheet.Colunms) { c1Sheet.Columns.Add(new XLColumn { Width = col.Width ?? c1Sheet.DefaultColumnWidth, Style = col.Style.ToXLStyle(host) }); } // Fill the table for (int i = 0; i < nRows; i++) { for (int j = 0; j < nCols; j++) { if (j < worksheet.Data[i].Count) { c1Sheet[i, j].Value = worksheet.Data[i][j]; } } } // Global style var tableRange = new XLCellRange(c1Sheet, 0, nRows - 1, 0, nCols - 1); tableRange.Style = worksheet.GlobalStyle.ToXLStyle(host); // Range-based styles foreach (var rs in worksheet.RangeStyles) { var styleRange = new XLCellRange(c1Sheet, rs.Range.From.Row, rs.Range.To.Row, rs.Range.From.Col, rs.Range.To.Col); styleRange.Style = rs.Style.ToXLStyle(host); // Merged cells if (rs.Style.MergedCells == true) { c1Sheet.MergedCells.Add(styleRange); } } return(c1Sheet); }
protected void btnExport_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); string sql = string.Empty; C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\GuixeThang.xlsx"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\GuixeThang")) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\GuixeThang")); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\GuixeThang\GuiXeThang" + strDT + ".xlsx"; string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/GuixeThang/GuiXeThang" + strDT + ".xlsx"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); sql = " SELECT *"; sql += " FROM v_GuiXeThang"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; sql += " AND substring(NgayGui,1,6) <= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "' AND ((NgayKetThuc is null) OR "; sql += " (NgayKetThuc is not null and rtrim(LTRIM(NgayKetThuc)) <> '' and substring(NgayKetThuc,1,6) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "')) Order by CustomerId"; string[] sheetName = { "Oto", "XeMay", "XeDap", "Oto_HetHD", "XeMay_HetHD", "XeDap_HetHD" }; int[] lines = { 4, 4, 4, 4, 4, 4 }; using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); db.Close(); if (ds != null) { int i = 4; XLCellRange mrCell = new XLCellRange(0, 0, 0, 2); XLStyle xlstStyle = new XLStyle(xlbBook); //xlstStyle.AlignHorz = XLAlignHorzEnum.Left; xlstStyle.AlignVert = XLAlignVertEnum.Top; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; xlstStyle.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyle01 = new XLStyle(xlbBook); xlstStyle01.AlignHorz = XLAlignHorzEnum.Center; xlstStyle01.AlignVert = XLAlignVertEnum.Top; xlstStyle01.WordWrap = true; xlstStyle01.Font = new Font("", 8, FontStyle.Regular); xlstStyle01.SetBorderColor(Color.Black); xlstStyle01.BorderBottom = XLLineStyleEnum.Thin; xlstStyle01.BorderTop = XLLineStyleEnum.Thin; xlstStyle01.BorderLeft = XLLineStyleEnum.Thin; xlstStyle01.BorderRight = XLLineStyleEnum.Thin; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { XLSheet xlsSheet = xlbBook.Sheets[sheetName[Func.ParseInt(rowType[10]) - 1]]; string col01 = rowType[0].ToString(); string col02 = rowType[1].ToString(); string col03 = rowType[2].ToString(); string col04 = rowType[3].ToString(); string col05 = rowType[4].ToString(); string col06 = rowType[5].ToString(); string col07 = Func.FormatDMY(rowType[6].ToString()); string col08 = Func.FormatDMY(rowType[7].ToString()); string col09 = rowType[8].ToString(); i = lines[Func.ParseInt(rowType[10]) - 1]; xlsSheet[i, 0].Value = i - 3; xlsSheet[i, 1].Value = col03; xlsSheet[i, 2].Value = col04; xlsSheet[i, 3].Value = col05; xlsSheet[i, 4].Value = col06; xlsSheet[i, 5].Value = col07; xlsSheet[i, 6].Value = col08; xlsSheet[i, 7].Value = col09; xlsSheet[i, 0].Style = xlstStyle01; xlsSheet[i, 1].Style = xlstStyle; xlsSheet[i, 2].Style = xlstStyle; xlsSheet[i, 3].Style = xlstStyle01; xlsSheet[i, 4].Style = xlstStyle; xlsSheet[i, 5].Style = xlstStyle01; xlsSheet[i, 6].Style = xlstStyle01; xlsSheet[i, 7].Style = xlstStyle; //++i; lines[Func.ParseInt(rowType[10]) - 1]++; } } } } /////////////////////////////////////// sql = " SELECT *"; sql += " FROM v_GuiXeThang"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; sql += " AND ((substring(NgayGui,1,6) > '" + drpYear.SelectedValue + drpMonth.SelectedValue + "') OR "; sql += " (NgayKetThuc is not null and rtrim(LTRIM(NgayKetThuc)) <> '' and substring(NgayKetThuc,1,6) < '" + drpYear.SelectedValue + drpMonth.SelectedValue + "')) Order by CustomerId"; ds = new DataSet(); using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); db.Close(); if (ds != null) { int i = 4; XLCellRange mrCell = new XLCellRange(0, 0, 0, 2); //xlsSheet.MergedCells.Add(mrCell); XLStyle xlstStyle = new XLStyle(xlbBook); //xlstStyle.AlignHorz = XLAlignHorzEnum.Left; xlstStyle.AlignVert = XLAlignVertEnum.Top; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; xlstStyle.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyle01 = new XLStyle(xlbBook); xlstStyle01.AlignHorz = XLAlignHorzEnum.Center; xlstStyle01.AlignVert = XLAlignVertEnum.Top; xlstStyle01.WordWrap = true; xlstStyle01.Font = new Font("", 8, FontStyle.Regular); xlstStyle01.SetBorderColor(Color.Black); xlstStyle01.BorderBottom = XLLineStyleEnum.Thin; xlstStyle01.BorderTop = XLLineStyleEnum.Thin; xlstStyle01.BorderLeft = XLLineStyleEnum.Thin; xlstStyle01.BorderRight = XLLineStyleEnum.Thin; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { XLSheet xlsSheet = xlbBook.Sheets[sheetName[Func.ParseInt(rowType[10]) + 2]]; string col01 = rowType[0].ToString(); string col02 = rowType[1].ToString(); string col03 = rowType[2].ToString(); string col04 = rowType[3].ToString(); string col05 = rowType[4].ToString(); string col06 = rowType[5].ToString(); string col07 = Func.FormatDMY(rowType[6].ToString()); string col08 = Func.FormatDMY(rowType[7].ToString()); string col09 = rowType[8].ToString(); i = lines[Func.ParseInt(rowType[10]) + 2]; xlsSheet[i, 0].Value = i - 3; xlsSheet[i, 1].Value = col03; xlsSheet[i, 2].Value = col04; xlsSheet[i, 3].Value = col05; xlsSheet[i, 4].Value = col06; xlsSheet[i, 5].Value = col07; xlsSheet[i, 6].Value = col08; xlsSheet[i, 7].Value = col09; xlsSheet[i, 0].Style = xlstStyle01; xlsSheet[i, 1].Style = xlstStyle; xlsSheet[i, 2].Style = xlstStyle; xlsSheet[i, 3].Style = xlstStyle01; xlsSheet[i, 4].Style = xlstStyle; xlsSheet[i, 5].Style = xlstStyle01; xlsSheet[i, 6].Style = xlstStyle01; xlsSheet[i, 7].Style = xlstStyle; lines[Func.ParseInt(rowType[10]) + 2]++; } } } } /////////////////////////////////////// XLSheet sheet = xlbBook.Sheets["OTo"]; sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); sheet = xlbBook.Sheets["OTo"]; sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); sheet = xlbBook.Sheets["OTo"]; sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); sheet = xlbBook.Sheets["OTo"]; sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); sheet = xlbBook.Sheets["OTo"]; sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); sheet = xlbBook.Sheets["XeMay"]; sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); sheet = xlbBook.Sheets["XeDap"]; sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); sheet = xlbBook.Sheets["OTo_HetHD"]; sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); sheet = xlbBook.Sheets["XeMay_HetHD"]; sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); sheet = xlbBook.Sheets["XeDap_HetHD"]; sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue); xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); }
protected void btnExport_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT *"; sql += " FROM v_BuildingTechStatusInfo"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and StatusDate >= '"+ Func.FormatYYYYmmdd(txtFromDate.Text.Substring(0,10)) +"' and StatusDate <= '"+ Func.FormatYYYYmmdd(txtToDate.Text.Substring(0,10)) +"'"; using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); db.Close(); if (ds != null) { C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\SuCoKyThuat.xls"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\SuCoKyThuat")) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\SuCoKyThuat")); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\SuCoKyThuat\SuCoKyThuat" + strDT + ".xls"; string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/SuCoKyThuat/SuCoKyThuat" + strDT + ".xls"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLSheet xlsSheet = xlbBook.Sheets["SuCoKyThuat"]; int i = 3; XLCellRange mrCell = new XLCellRange(0, 0, 0, 2); xlsSheet.MergedCells.Add(mrCell); XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Left; xlstStyle.AlignVert = XLAlignVertEnum.Top; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; XLStyle xlstStyle01 = new XLStyle(xlbBook); xlstStyle01.AlignHorz = XLAlignHorzEnum.Center; xlstStyle01.AlignVert = XLAlignVertEnum.Top; xlstStyle01.WordWrap = true; xlstStyle01.Font = new Font("", 8, FontStyle.Regular); xlstStyle01.SetBorderColor(Color.Black); xlstStyle01.BorderBottom = XLLineStyleEnum.Thin; xlstStyle01.BorderTop = XLLineStyleEnum.Thin; xlstStyle01.BorderLeft = XLLineStyleEnum.Thin; xlstStyle01.BorderRight = XLLineStyleEnum.Thin; xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%BUILDING%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%TU_NGAY%}", txtFromDate.Text); xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%DEN_NGAY%}", txtToDate.Text); DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string col01 = Func.FormatDMY(rowType[0].ToString()); string col02 = rowType[1].ToString(); string col03 = rowType[2].ToString(); string col04 = rowType[3].ToString(); string col05 = rowType[4].ToString(); string col06 = rowType[5].ToString(); string col07 = rowType[6].ToString(); string col08 = rowType[7].ToString(); string col09 = rowType[8].ToString(); string col10 = rowType[9].ToString(); string col11 = rowType[10].ToString(); string col12 = rowType[11].ToString(); xlsSheet[i, 0].Value = col01; xlsSheet[i, 1].Value = col02; xlsSheet[i, 2].Value = col03; xlsSheet[i, 3].Value = col04; xlsSheet[i, 4].Value = col05; xlsSheet[i, 5].Value = col06; xlsSheet[i, 6].Value = col07; xlsSheet[i, 7].Value = col08; xlsSheet[i, 8].Value = col09; xlsSheet[i, 9].Value = col10; xlsSheet[i, 10].Value = col11; xlsSheet[i, 0].Style = xlstStyle01; xlsSheet[i, 1].Style = xlstStyle; xlsSheet[i, 2].Style = xlstStyle; xlsSheet[i, 3].Style = xlstStyle; xlsSheet[i, 4].Style = xlstStyle; xlsSheet[i, 5].Style = xlstStyle; xlsSheet[i, 6].Style = xlstStyle; xlsSheet[i, 7].Style = xlstStyle; xlsSheet[i, 8].Style = xlstStyle; xlsSheet[i, 9].Style = xlstStyle; xlsSheet[i, 10].Style = xlstStyle; ++i; } xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } }
protected void btnView_Click(object sender, EventArgs e) { C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BillPhongHop.xlsx"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))); } decimal LastSumPriceVND = 0; decimal LastSumPriceUSD = 0; XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.WordWrap = true; xlstStyle.Font = new Font("", 8, FontStyle.Regular); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BillPhongHop" + strDT + ".xlsx"; string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/BillPhongHop" + strDT + ".xlsx"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLSheet xlsSheet = xlbBook.Sheets["HoaDon"]; int k = 2; xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%NGAY%}", DateTime.Today.ToString("dd")); xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%THANG%}", DateTime.Today.ToString("MM")); xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%NAM%}", DateTime.Today.ToString("yyyy")); using (SqlDatabase db = new SqlDatabase()) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT Name, ContactName"; sql += " FROM Customer"; sql += " WHERE CustomerId = '" + lnbCustomerId.Text + "' "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string Name = rowType[0].ToString(); string ContactName = rowType[1].ToString(); xlsSheet[6, 0].Value = xlsSheet[6, 0].Value.ToString().Replace("{%TEN_CONG_TY%}", Name); xlsSheet[7, 0].Value = xlsSheet[7, 0].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName); xlsSheet[9, 0].Value = xlsSheet[9, 0].Value.ToString().Replace("{%NGAY_HOP_DONG%}", lblBookingDate.Text); xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%GIO_TU%}", drpHourFrom.SelectedValue); xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%PHUT_TU%}", drpMinuteFrom.Value); xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%GIO_DEN%}", drpHourTo.SelectedValue); xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%PHUT_DEN%}", drpMinuteTo.Value); xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%NGAY_THUE%}", lblBookingDate.Text); } } } ds = new DataSet(); sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone"; sql += " FROM Mst_Building"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' "; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { int tmp = 2; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string Bank = rowType["Bank"].ToString(); string Account = rowType["Account"].ToString(); string AccountName = rowType["AccountName"].ToString(); string Office = rowType["Office"].ToString(); string OfficeAddress = rowType["OfficeAddress"].ToString(); string OfficePhone = rowType["OfficePhone"].ToString(); xlsSheet[30 + tmp, 0].Value = xlsSheet[30 + tmp, 0].Value.ToString().Replace("{%VAN_PHONG%}", Office); xlsSheet[31 + tmp, 0].Value = xlsSheet[31 + tmp, 0].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone); xlsSheet[33 + tmp, 0].Value = xlsSheet[33 + tmp, 0].Value.ToString().Replace("{%NGAN_HANG%}", Bank); xlsSheet[34 + tmp, 0].Value = xlsSheet[34 + tmp, 0].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName); xlsSheet[35 + tmp, 0].Value = xlsSheet[35 + tmp, 0].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account); } } } xlsSheet[27, 3].Value = Convert.ToDecimal(txtRate.Text); xlsSheet[27, 7].Value = txtRateDate.Text.Substring(0, 10); ds = new DataSet(); sql = " SELECT *"; sql += " FROM v_BookingRoomInfo"; sql += " WHERE BookingId = '" + hidId.Value + "' "; int j = 0; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { if (j >= 1) { xlsSheet.Rows.Insert(18); } int tmp = 18 + j++; string Name = rowType["Name"].ToString(); string Regional = rowType["Regional"].ToString(); string Floor = rowType["Floor"].ToString(); string Area = rowType["Area"].ToString(); string PriceUSD = rowType["PriceUSD"].ToString(); string PriceVND = rowType["PriceVND"].ToString(); string SumUSD = rowType["SumUSD"].ToString(); string SumVND = rowType["SumVND"].ToString(); string VatUSD = rowType["VatUSD"].ToString(); string VatVND = rowType["VatVND"].ToString(); string LastPriceUSD = rowType["LastPriceUSD"].ToString(); string LastPriceVND = rowType["LastPriceVND"].ToString(); string BookingId = rowType["BookingId"].ToString(); xlsSheet[tmp, 1].Value = Name; xlsSheet[tmp, 2].Value = Regional; xlsSheet[tmp, 3].Value = Floor; xlsSheet[tmp, 4].Value = rowType["Area"]; xlsSheet[tmp, 5].Value = rowType["PriceUSD"]; xlsSheet[tmp, 6].Value = rowType["PriceVND"]; xlsSheet[tmp, 7].Value = rowType["SumUSD"]; xlsSheet[tmp, 8].Value = rowType["SumVND"]; xlsSheet[tmp, 9].Value = rowType["VatUSD"]; xlsSheet[tmp, 10].Value = rowType["VatVND"]; xlsSheet[tmp, 11].Value = rowType["LastPriceUSD"]; xlsSheet[tmp, 12].Value = rowType["LastPriceVND"]; LastSumPriceVND += Convert.ToDecimal(rowType["LastPriceVND"]); LastSumPriceUSD += Convert.ToDecimal(rowType["LastPriceUSD"]); for (int col = 1; col <= 12; col++) { xlsSheet[tmp, col].Style = xlstStyle; } } } } j--; XLSheet source = xlbBook.Sheets["tpl"]; for (int row = 22; row <= 26; row++) { for (int col = 1; col <= 12; col++) { xlsSheet[row + j, col].Style = source[row, col].Style; xlsSheet[row + j, col].Value = source[row, col].Value; } } XLCellRange mrCell = new XLCellRange(22 + j, 23 + j, 1, 1); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(22 + j, 23 + j, 2, 2); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(22 + j, 23 + j, 3, 4); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(22 + j, 22 + j, 5, 6); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(22 + j, 22 + j, 7, 8); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(22 + j, 22 + j, 9, 10); xlsSheet.MergedCells.Add(mrCell); mrCell = new XLCellRange(22 + j, 22 + j, 11, 12); xlsSheet.MergedCells.Add(mrCell); ds = new DataSet(); sql = " SELECT Service, Mount, PriceUSD, PriceVND, SumUSD, SumVND, VatUSD, VatVND, LastPriceUSD, LastPriceVND, Unit"; sql += " FROM PaymentBookingService"; sql += " WHERE BookingId = '" + hidId.Value + "' "; j = 0; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { if (j >= 1) { xlsSheet.Rows.Insert(19); } int tmp = 24 + j++; string Service = rowType["Service"].ToString(); string Mount = rowType["Mount"].ToString(); string Unit = rowType["Unit"].ToString(); string PriceUSD = rowType["PriceUSD"].ToString(); string PriceVND = rowType["PriceVND"].ToString(); string SumUSD = rowType["SumUSD"].ToString(); string SumVND = rowType["SumVND"].ToString(); string VatUSD = rowType["VatUSD"].ToString(); string VatVND = rowType["VatVND"].ToString(); string LastPriceUSD = rowType["LastPriceUSD"].ToString(); string LastPriceVND = rowType["LastPriceVND"].ToString(); xlsSheet[tmp, 1].Value = Service; xlsSheet[tmp, 2].Value = rowType["Mount"]; xlsSheet[tmp, 3].Value = Unit; xlsSheet[tmp, 5].Value = rowType["PriceUSD"]; xlsSheet[tmp, 6].Value = rowType["PriceVND"]; xlsSheet[tmp, 7].Value = rowType["SumUSD"]; xlsSheet[tmp, 8].Value = rowType["SumVND"]; xlsSheet[tmp, 9].Value = rowType["VatUSD"]; xlsSheet[tmp, 10].Value = rowType["VatVND"]; xlsSheet[tmp, 11].Value = rowType["LastPriceUSD"]; xlsSheet[tmp, 12].Value = rowType["LastPriceVND"]; LastSumPriceVND += Convert.ToDecimal(rowType["LastPriceVND"]); LastSumPriceUSD += Convert.ToDecimal(rowType["LastPriceUSD"]); for (int col = 1; col <= 12; col++) { xlsSheet[tmp, col].Style = xlstStyle; } } } } xlsSheet[28 + j - 1, 2].Value = LastSumPriceVND; xlsSheet[29 + j - 1, 2].Value = Func.docso(Convert.ToInt32(LastSumPriceVND)); xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnExport_Click(object sender, EventArgs e) { string job = ""; switch (hidJobType.Value) { case "1": job = "BV"; break; case "2": job = "VS"; break; case "3": job = "KT"; break; case "4": job = "QL"; break; default: break; } string buildingId = Func.ParseString(Session["__BUILDINGID__"]); Hashtable staffIdRow = new Hashtable(); string[] dateOfWeekVN = { "T2", "T3", "T4", "T5", "T6", "T7", "CN" }; string[] dateOfWeekEN = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sartuday", "Sunday" }; Dictionary<string, string> dictionary = new Dictionary<string, string>(); dictionary.Add("monday", "T2"); dictionary.Add("tuesday", "T3"); dictionary.Add("wednesday", "T4"); dictionary.Add("thursday", "T5"); dictionary.Add("friday", "T6"); dictionary.Add("saturday", "T7"); dictionary.Add("sunday", "CN"); DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT *"; sql += " FROM BD_WorkingWorkedInfo"; sql += " WHERE BuildingId = '" + buildingId + "' and DelFlag = 0 and jobtypeid = '" + hidJobType.Value + "'"; sql += " and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; Hashtable scheduleLst = new Hashtable(); using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); db.Close(); if (ds != null) { DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { string StaffId = rowType["StaffId"].ToString(); string WorkingHourId = rowType["WorkingHourId"].ToString(); string WorkingDate = rowType["WorkingDate"].ToString().Substring(6, 2); if (!String.IsNullOrEmpty(WorkingHourId) && scheduleLst.ContainsKey(StaffId + WorkingDate)) { scheduleLst.Add(StaffId + WorkingDate, WorkingHourId); } } } } } ds = new DataSet(); sql = " SELECT *"; sql += " FROM BD_Staff"; sql += " WHERE BuildingId = '" + buildingId + "' and DelFlag = 0 and jobtypeid = '" + hidJobType.Value + "' and SUBSTRING(JobBegin,0,7) <= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "' and (JobEnd = '' or JobEnd is Null or SUBSTRING(JobEnd,0,7) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "')"; sql += " Order By Name"; using (SqlDatabase db = new SqlDatabase()) { using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); db.Close(); if (ds != null) { mvMessage.SetCompleteMessage("File CSV đã xuất thành công."); C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\LichLamViec.xls"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + buildingId)); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + buildingId + @"\" + buildingId + "_LichLamViec_" + job + "_" + strDT + "export.xls"; string strFilePathExport = @"../../Report/Building/" + buildingId + @"/" + buildingId + "_LichLamViec_" + job + "_" + strDT + "export.xls"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); string sheet = "LichLamViec"; XLSheet xlsSheet = xlbBook.Sheets[sheet]; int i = 0; XLCellRange mrCell = new XLCellRange(0, 0, 1, 2); xlsSheet.MergedCells.Add(mrCell); XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Center; xlstStyle.Font = new Font("", 12, FontStyle.Bold); xlstStyle.SetBorderColor(Color.Black); xlstStyle.BorderBottom = XLLineStyleEnum.Thin; xlstStyle.BorderTop = XLLineStyleEnum.Thin; xlstStyle.BorderLeft = XLLineStyleEnum.Thin; xlstStyle.BorderRight = XLLineStyleEnum.Thin; xlsSheet[i, 1].Value = "Tháng " + drpMonth.SelectedValue + "/" + drpYear.SelectedValue; xlsSheet[i, 1].Style = xlstStyle; xlsSheet[i + 1, 1].Value = "STT"; //xlsSheet[i + 1, 1].Value = "Mã Nhân Viên"; xlsSheet[i + 1, 2].Value = "Họ và Tên"; XLStyle xlstStyle01 = new XLStyle(xlbBook); xlstStyle01.AlignHorz = XLAlignHorzEnum.Left; xlstStyle01.Font = new Font("", 10, FontStyle.Bold); xlstStyle01.SetBorderColor(Color.Black); xlstStyle01.BorderBottom = XLLineStyleEnum.Thin; xlstStyle01.BorderTop = XLLineStyleEnum.Thin; xlstStyle01.BorderLeft = XLLineStyleEnum.Thin; xlstStyle01.BorderRight = XLLineStyleEnum.Thin; for (int j = 1; j <= 31; j++) { xlsSheet[i, 2 + j].Value = j; DateTime date = new DateTime(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue), j); xlsSheet[i + 1, 2 + j].Value = dictionary[date.DayOfWeek.ToString().ToLower()]; xlsSheet[i, 2 + j].Style = xlstStyle01; xlsSheet[i + 1, 2 + j].Style = xlstStyle01; if (j == DateTime.DaysInMonth(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue))) { break; } } i++; DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { int No = i; i++; string StaffId = rowType["ID"].ToString(); string Name = rowType["Name"].ToString(); staffIdRow.Add(StaffId, i); xlsSheet[i, 1].Value = No; xlsSheet[i, 0].Value = StaffId; xlsSheet[i, 2].Value = Name; xlsSheet[i, 0].Style = xlstStyle01; xlsSheet[i, 1].Style = xlstStyle01; xlsSheet[i, 2].Style = xlstStyle01; for (int j = 1; j <= 31; j++) { if (scheduleLst.ContainsKey(StaffId + "" + j.ToString().PadLeft(2, '0'))) { xlsSheet[i, 2 + j].Value = scheduleLst[StaffId + "" + j.ToString().PadLeft(2, '0')]; xlsSheet[i, 2 + j].Style = xlstStyle01; } else { xlsSheet[i, 2 + j].Style = xlstStyle01; } if (j == DateTime.DaysInMonth(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue))) { break; } } } ds = new DataSet(); sql = string.Empty; //sql = " SELECT *"; //sql += " FROM BD_WorkingWorkedInfo"; //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1 and jobtypeid = '" + hidJobType.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'"; //sql += " Order By StaffId"; //using (SqlCommand cm1 = db.CreateCommand(sql)) //{ // SqlDataAdapter da1 = new SqlDataAdapter(cm1); // da1.Fill(ds); // db.Close(); // if (ds != null) // { // xlsSheet[i++ + 1, 2].Value = "Ghi chú:"; // DataTable dt1 = ds.Tables[0]; // foreach (DataRow rowType in dt1.Rows) // { // i++; // string StaffId = rowType["StaffId"].ToString(); // string WorkingHourId = rowType["WorkingHourId"].ToString(); // string WorkingDate = rowType["WorkingDate"].ToString().Substring(6, 2); // int col = Func.ParseInt(WorkingDate) + 2; // int row = Func.ParseInt(staffIdRow[StaffId]); // xlsSheet[row, col].Value = WorkingHourId; // } // } //} DataSet ds1 = new DataSet(); sql = string.Empty; sql = " SELECT *"; sql += " FROM BD_WorkingHour"; sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1 and jobtypeid = '" + hidJobType.Value + "'"; sql += " Order By Name"; using (SqlCommand cm1 = db.CreateCommand(sql)) { SqlDataAdapter da1 = new SqlDataAdapter(cm1); da1.Fill(ds1); db.Close(); if (ds != null) { xlsSheet[i++ + 1, 2].Value = "Ghi chú:"; DataTable dt1 = ds1.Tables[0]; foreach (DataRow rowType in dt1.Rows) { i++; string Ma = rowType["WorkingHourId"].ToString(); string Name = rowType["Name"].ToString(); xlsSheet[i, 2].Value = Ma + ":" + Name; } xlsSheet[i + 1, 2].Value = "OFF:nghỉ"; } } xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } }
/// <summary> /// Saves the content of a C1FlexGrid into an XLSheet. /// </summary> public static void Save(C1FlexGrid flex, XLSheet sheet) { // clear style cache if this is a new book if (sheet.Book != _lastBook) { _cellStyles.Clear(); _excelStyles.Clear(); _lastBook = sheet.Book; } // save global parameters sheet.DefaultRowHeight = PixelsToTwips(flex.Rows.DefaultSize); sheet.DefaultColumnWidth = PixelsToTwips(flex.Columns.DefaultSize); sheet.Locked = flex.IsReadOnly; sheet.ShowGridLines = flex.GridLinesVisibility != GridLinesVisibility.None; sheet.ShowHeaders = flex.HeadersVisibility != HeadersVisibility.None; sheet.OutlinesBelow = flex.GroupRowPosition == GroupRowPosition.BelowData; // save columns sheet.Columns.Clear(); foreach (Column col in flex.Columns) { var c = sheet.Columns.Add(); if (!col.Width.IsAuto) { c.Width = PixelsToTwips(col.ActualWidth); } c.Visible = col.Visible; if (col.CellStyle is ExcelCellStyle) { c.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)col.CellStyle); } } // save rows sheet.Rows.Clear(); foreach (Row row in flex.Rows) { var r = sheet.Rows.Add(); if (row.Height > -1) { r.Height = PixelsToTwips(row.Height); } if (row.CellStyle is ExcelCellStyle) { r.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)row.CellStyle); } if (row is ExcelRow) { r.OutlineLevel = ((ExcelRow)row).Level; } r.Visible = row.Visible; } // save cells for (int r = 0; r < flex.Rows.Count; r++) { for (int c = 0; c < flex.Columns.Count; c++) { // save cell value var cell = sheet[r, c]; var obj = flex[r, c]; cell.Value = obj is FrameworkElement ? 0 : obj; // save cell formula and style var row = flex.Rows[r] as ExcelRow; if (row != null) { // save cell formula var col = flex.Columns[c]; var formula = row.GetDataEditor(col); if (formula.StartsWith("=")) { cell.Formula = formula; } // save cell style var cs = row.GetCellStyle(col) as ExcelCellStyle; if (cs != null) { cell.Style = GetXLStyle(flex, sheet, cs); } } } } // save selection var sel = flex.Selection; if (sel.IsValid) { var xlSel = new XLCellRange(sheet, sel.Row, sel.Row2, sel.Column, sel.Column2); sheet.SelectedCells.Clear(); sheet.SelectedCells.Add(xlSel); } // save merged cells var xmm = flex.MergeManager as ExcelMergeManager; if (xmm != null) { xmm.SetMergedRanges(sheet); } }