// save a book private void _btnSave_Click(object sender, System.EventArgs e) { // choose file SaveFileDialog dlg = new SaveFileDialog(); dlg.DefaultExt = "xls"; dlg.FileName = "*.xls"; if (dlg.ShowDialog() != DialogResult.OK) { return; } // clear book _book.Clear(); _book.Sheets.Clear(); // copy grids to book sheets foreach (TabPage pg in _tab.TabPages) { C1FlexGrid grid = pg.Controls[0] as C1FlexGrid; XLSheet sheet = _book.Sheets.Add(grid.Name); SaveSheet(grid, sheet, false); } // save selected sheet index _book.Sheets.SelectedIndex = _tab.SelectedIndex; // save the book _book.Save(dlg.FileName); }
private void btnExcel_Click(object sender, EventArgs e) { try { if (gridView2.RowCount > 0) { C1XLBook xls = null; xls = new C1XLBook(); xls.Sheets.RemoveAt(0); //Console.WriteLine("Building Excel File..."); Thread.Sleep(500); XLSheet Sheet = xls.Sheets.Add("AQL"); Create_Sheet(ref Sheet, gridView2); Thread.Sleep(500); #region Create WorkBook //Console.WriteLine("Sending xls to path..."); string _patch = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string _filename; _filename = "AQL_Report_" + DateTime.Now.ToString("yyyy") + "-" + DateTime.Now.ToString("MM").ToUpper() + "-" + DateTime.Now.ToString("dd").ToUpper() + ".xlsx"; xls.Save(_patch + _filename); Thread.Sleep(500); System.Diagnostics.Process.Start(_patch + _filename); //Console.WriteLine("Excel Completed..."); Thread.Sleep(500); #endregion } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public MainWindow() { InitializeComponent(); // C1XLBookがExcelブックを表すクラス C1XLBook book = new C1XLBook(); // XLSheetがExcelのシートを表す XLSheet sheet = book.Sheets[0]; // 1行目の1から3列目に値を設定する sheet[0, 0].Value = 1; sheet[0, 1].Value = 2; sheet[0, 2].Value = 3; // スタイルを設定する XLStyle style = new XLStyle(book); style.ForeColor = Colors.Blue; sheet[0, 1].Style = style; // 式を用いる // 1行目の1から3列のSUM(合計)を4列目に求める sheet[0, 3].Formula = "SUM(A1: C1)"; // 画像を設定する WriteableBitmap img = new WriteableBitmap(new BitmapImage(new Uri("icon.png", UriKind.Relative))); sheet[1, 0].Value = img; // 保存する book.Save(@"C:\<ドキュメントフォルダのパス>\mybook.xls"); }
private static void InternalSave(Action <C1XLBook> action) { var dlg = new SaveFileDialog(); dlg.Filter = "Excel Files (*.xlsx)|*.xlsx"; if (dlg.ShowDialog() == true) { try { var book = new C1XLBook(); if (action != null) { action(book); } using (var stream = dlg.OpenFile()) { book.Save(stream); } } catch (Exception x) { MessageBox.Show(x.Message); } } }
public MainWindow() { InitializeComponent(); C1XLBook book = new C1XLBook(); // ファイルを読み込む book.Load(@"C:\<ドキュメントフォルダのパス>\mybook.xls"); // シートを編集する book.Sheets[0][0, 0].Value = 5; // データをFlexGrid用に加工する List <int> list = new List <int>(); list.Add(Convert.ToInt32(book.Sheets[0][0, 0].Value)); list.Add(Convert.ToInt32(book.Sheets[0][0, 1].Value)); list.Add(Convert.ToInt32(book.Sheets[0][0, 2].Value)); // FlexGridで表示する FlexGrid.ItemsSource = list; // 別名で保存する book.Save(@"\mybook2.xls"); }
/// <summary> /// Saves the current book into an XLSX stream. /// </summary> /// <param name="stream"></param> public void Save(Stream stream) { // create the book to save var book = new C1XLBook(); book.Sheets.Clear(); // no sheets if (Sheets.Count == 0) { var xlSheet = book.Sheets.Add("Sheet1"); ExcelFilter.Save(this, xlSheet); } else { // save each sheet foreach (var sheet in Sheets) { var xlSheet = book.Sheets.Add(sheet.SheetName); ExcelFilter.Save(sheet.Grid, xlSheet); } } // save the book book.Save(stream, C1.WPF.Excel.FileFormat.OpenXml); }
private void button1_Click(object sender, System.EventArgs e) { // step 1: create a new workbook C1XLBook book = new C1XLBook(); // step 2: get the sheet that was created by default, give it a name XLSheet sheet = book.Sheets[0]; sheet.Name = "Hello World"; // step 3: create styles for odd and even values XLStyle styleOdd = new XLStyle(book); styleOdd.Font = new Font("Tahoma", 9, FontStyle.Italic); styleOdd.ForeColor = Color.Blue; XLStyle styleEven = new XLStyle(book); styleEven.Font = new Font("Tahoma", 9, FontStyle.Bold); styleEven.ForeColor = Color.Red; // step 3: write content and format into some cells for (int i = 0; i < 100; i++) { XLCell cell = sheet[i, 0]; cell.Value = i + 1; cell.Style = ((i + 1) % 2 == 0)? styleEven: styleOdd; } // step 4: save the file string fileName = Application.StartupPath + @"\hello.xls"; book.Save(fileName); System.Diagnostics.Process.Start(fileName); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lnkArtilceExcel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { string appPath = Path.Combine(Application.StartupPath, "Resources\\ArticleDemo.xlsx"); //Code is added by irfan for Mantis issue on 09/02/2018=============================== C1XLBook book = new C1XLBook(); book.Load(appPath); XLSheetCollection sheets = book.Sheets; XLSheet articleSheet = sheets[0]; if (articleSheet.Rows.Count > 0) { if (articleSheet.Rows.Count != 1) { for (int i = 1; i <= articleSheet.Rows.Count; i++) { i = 1; articleSheet.Rows.RemoveAt(i); } book.Save(appPath); } } //======================================================================================== System.Diagnostics.Process.Start(appPath); } catch (Exception ex) { CommonFunc.ShowMessage(ex.Message, MessageType.Information); Logger.Log(ex.Message, Logger.LogingLevel.Error); } }
private void _btnSave_Click(object sender, RoutedEventArgs e) { Debug.Assert(_book != null); var dlg = new SaveFileDialog(); dlg.Filter = "Excel Files (*.xlsx)|*.xlsx"; if (dlg.ShowDialog().Value) { try { // information _lblStatus.Text = string.Format("Saving {0}...", dlg.SafeFileName); // save workbook using (var stream = dlg.OpenFile()) { _book.Save(stream); } _lblStatus.Text = string.Format("Saved {0}", dlg.SafeFileName);; } catch (Exception x) { MessageBox.Show(x.Message); } } }
private void ContextMenu_export_grfstk(object sender, System.EventArgs e) { SaveFileDialog dlg = new SaveFileDialog(); dlg.DefaultExt = "xls"; dlg.Filter = "Excel |*.xls"; dlg.InitialDirectory = ic.iniC.pathSaveExcelAppointment; dlg.FileName = "*.xls"; if (dlg.ShowDialog() != DialogResult.OK) { return; } // clear book C1XLBook _book = new C1XLBook(); XLSheet sheet = _book.Sheets.Add("stock" + DateTime.Now.ToString("dd-MM-") + DateTime.Now.Year.ToString()); ic.SaveSheet(grfStk, sheet, _book, false); _book.Sheets.SelectedIndex = 0; // save the book _book.Save(dlg.FileName); if (File.Exists(dlg.FileName)) { //Process p = new Process(); //p.StartInfo.FileName = dlg.FileName; //p.Start(); string argument = "/select, \"" + dlg.FileName + "\""; Process.Start("explorer.exe", argument); } }
private void Save(C1XLBook wb) { if (wb != null) { string path = Path.Combine(Application.StartupPath, "test.xls"); if (cbOpenXml.Checked) { path += "x"; } if (_radioDialog.Checked) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = GetFilter(cbOpenXml.Checked); dlg.Title = "Save As MS Excel File"; dlg.OverwritePrompt = true; dlg.RestoreDirectory = true; DialogResult dr = dlg.ShowDialog(); if (dr != DialogResult.OK) { return; } path = dlg.FileName; } wb.Save(path); if (_cbPreview.Checked) { try { Process.Start(path); } catch { } } } }
public void ExportBudgetForPrimavera(string saveLoc, int budgetID) { SqlDataReader dr; C1XLBook book = new C1XLBook(); XLSheet sheet = book.Sheets[0]; int indx; decimal tmpRate; // must be output with the following columns // code,blank,description,quantity,uom,hours,rate,cost dr = CBBudgetLine.GetExportListByBudget(budgetID); indx = 0; tmpRate = 0; while (dr.Read()) { sheet[indx, 3].Value = dr["Activity"]; // code sheet[indx, 4].Value = ""; // blank sheet[indx, 5].Value = dr["FullDescription"]; // description sheet[indx, 6].Value = dr["Quantity"].ToString(); // quantity sheet[indx, 7].Value = dr["UOM"]; // uom sheet[indx, 8].Value = dr["TotalHours"].ToString(); // hours tmpRate = GetHourRate(Convert.ToInt32(dr["TotalHours"]), Convert.ToDecimal(dr["TotalDollars"])); sheet[indx, 9].Value = tmpRate.ToString("#,##0.00"); // rate sheet[indx, 10].Value = Convert.ToDecimal(dr["TotalDollars"]).ToString("#,##0.00"); // cost indx++; } dr.Close(); book.Save(saveLoc); }
public string WriteExcle(FlexigridParam param, dynamic[] query, int from = 1) { var names = param.QType.GetString().Split(','); var cols = param.Cols.GetString().Split(','); C1XLBook _book = new C1XLBook(); string path = @"~/Files/a.xls"; string xlsPath = System.Web.HttpContext.Current.Server.MapPath(path); _book.Load(xlsPath); string guid = Guid.NewGuid().ToString(); string saveFileName = xlsPath.Path(guid); XLSheet sheet = _book.Sheets[0]; XLCell cell = sheet[0, 0]; Dictionary <string, string> propertyName; PropertyInfo[] properties; for (int i = 0; i < names.Length; i++) { cell = sheet[0, i]; if (!string.IsNullOrWhiteSpace(names[i])) { cell.Value = names[i]; //列值 } } for (int i = 0; i < query.Length; i++) { propertyName = new Dictionary <string, string>(); if (query[i] == null) { continue; } Type type = query[i].GetType(); properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo property in properties) { object o = property.GetValue(query[i], null); if (!string.IsNullOrEmpty(property.Name) && o != null) { propertyName.Add(property.Name, o.ToString()); } } int j = 0; cols.All(a => { cell = sheet[i + from, j]; if (propertyName.ContainsKey(a)) //列名 { cell.Value = propertyName[a]; //列值 } j++; return(true); }); } _book.Save(saveFileName); LogClassModels.WriteServiceLog(LogType.Operation, string.Format("../../../Files/{0}.xls", guid) + ",", "导出数据", Result.Succeed); //写入日志 return(string.Format("../../../Files/{0}.xls", guid)); //path.Replace("b",guid); }
public void Save(string filename, C1FlexGrid flexgrid) { // create the book to save var book = new C1XLBook(); book.Sheets.Clear(); var xlSheet = book.Sheets.Add("Sheet1"); ExcelExport.ExcelFilter.Save(flexgrid, xlSheet); // save the book book.Save(filename, C1.WPF.Excel.FileFormat.OpenXml); }
public void ExportBudgetForPrimavera(string saveLoc, int PCNID) { SqlDataReader dr; C1XLBook book = new C1XLBook(); XLSheet sheet = book.Sheets[0]; int indx; decimal tmpRate; // must be output with the following columns // code,blank,description,quantity,uom,hours,rate,cost // dr = CBBudgetLine.GetExportListByBudget(budgetID); dr = CBBudgetLine.GetExportList_Expense_ByPCNID(PCNID); indx = 1; tmpRate = 0; sheet[0, 3].Value = "PCNID"; sheet[0, 4].Value = "Code"; sheet[0, 5].Value = "Description"; sheet[0, 6].Value = "DlrsPerItem"; // quantity sheet[0, 7].Value = "NumItems"; sheet[0, 8].Value = "MUPerc"; sheet[0, 9].Value = "MarkUp"; // uom sheet[0, 10].Value = "TotalCost"; while (dr.Read()) { sheet[indx, 3].Value = dr["PCNID"]; // code sheet[indx, 4].Value = dr["Code"]; // description sheet[indx, 5].Value = dr["Description"].ToString(); sheet[indx, 6].Value = dr["DlrsPerItem"]; // quantity sheet[indx, 7].Value = dr["NumItems"]; sheet[indx, 8].Value = dr["MUPerc"]; sheet[indx, 9].Value = dr["MarkUp"]; // uom sheet[indx, 10].Value = dr["TotalCost"].ToString(); // hours // tmpRate = GetHourRate(Convert.ToInt32(dr["TotalHours"]), Convert.ToDecimal(dr["TotalDollars"])); // sheet[indx, 9].Value = tmpRate.ToString("#,##0.00"); // rate // sheet[indx, 10].Value = Convert.ToDecimal(dr["TotalDollars"]).ToString("#,##0.00"); // cost indx++; } dr.Close(); book.Save(saveLoc); }
public void NestedReferencesClassMappingTest() { using (var stream = new MemoryStream()) { // Create some test data to parse using (var book = new C1XLBook()) { var sheet = book.Sheets[0]; // Write the header fields sheet[0, 0].Value = "AId"; sheet[0, 1].Value = "BId"; sheet[0, 2].Value = "CId"; sheet[0, 3].Value = "DId"; // Write out the first record sheet[1, 0].Value = "a1"; sheet[1, 1].Value = "b1"; sheet[1, 2].Value = "c1"; sheet[1, 3].Value = "d1"; // Write out the second record sheet[2, 0].Value = "a2"; sheet[2, 1].Value = "b2"; sheet[2, 2].Value = "c2"; sheet[2, 3].Value = "d2"; // Save it to the stream book.Save(stream); } // Now parse the Excel file stream.Position = 0; using (var excel = _factory.CreateReader(stream)) { excel.Configuration.RegisterClassMap <AMap>(); var records = excel.GetRecords <A>().ToList(); // Make sure we got our records Assert.AreEqual(2, records.Count); for (var i = 0; i < records.Count; i++) { var rowId = i + 1; var row = records[i]; Assert.AreEqual("a" + rowId, row.Id); Assert.AreEqual("b" + rowId, row.B.Id); Assert.AreEqual("c" + rowId, row.B.C.Id); Assert.AreEqual("d" + rowId, row.B.C.D.Id); } } } }
public void EnsureInternalsAreSetupWhenPassingReaderAndConfigTest() { using (var stream = new MemoryStream()) { // Make sure the stream is a valid Excel file using (var book = new C1XLBook()) { book.Save(stream); } stream.Position = 0; var config = new ExcelConfiguration(); using (var excel = new ExcelReader(stream, config)) { Assert.AreSame(config, excel.Configuration); } } }
/// <summary> /// Closes the writer and saves the written data to the stream. Automatically called /// when disposed. /// </summary> public void Close() { if (_book != null) { // Set the column widths if we are doing auto sizing PerformColumnResize(); // Now save the Excel file to the output stream _book.Save(_stream, FileFormat.OpenXml); // Clean up and dispose of everything _book?.Dispose(); _graphics?.Dispose(); _sheet = null; _book = null; _graphics = null; } }
private void BtnExcel_Click(object sender, EventArgs e) { //throw new NotImplementedException(); if (grfRptName.Row == 1 && grfRpt.Rows.Count > 0) { SaveFileDialog dlg = new SaveFileDialog(); dlg.DefaultExt = "xls"; dlg.Filter = "Excel |*.xls"; dlg.InitialDirectory = ic.iniC.pathSaveExcelAppointment; dlg.FileName = "*.xls"; if (dlg.ShowDialog() != DialogResult.OK) { return; } // clear book C1XLBook _book = new C1XLBook(); //_book.Clear(); //_book.Sheets.Clear(); // copy grids to book sheets //foreach (TabPage pg in _tab.TabPages) //{ // C1FlexGrid grid = pg.Controls[0] as C1FlexGrid; XLSheet sheet = _book.Sheets.Add("pharmacy"); ic.SaveSheet(grfRpt, sheet, _book, false); //} // save selected sheet index if (_book.Sheets.Count >= 1) { _book.Sheets.SelectedIndex = 1; } // save the book _book.Save(dlg.FileName); Application.DoEvents(); Process.Start("explorer.exe", dlg.FileName); } }
private string CreateExcelFile() { //clear Excel book, remove the single blank sheet _c1xl.Clear(); _c1xl.Sheets.Clear(); _c1xl.DefaultFont = new Font("Tahoma", 8); //create Excel styles _styTitle = new XLStyle(_c1xl); _styHeader = new XLStyle(_c1xl); _styMoney = new XLStyle(_c1xl); _styOrder = new XLStyle(_c1xl); //set up styles _styTitle.Font = new Font(_c1xl.DefaultFont.Name, 15, FontStyle.Bold); _styTitle.ForeColor = Color.Blue; _styHeader.Font = new Font(_c1xl.DefaultFont, FontStyle.Bold); _styHeader.ForeColor = Color.White; _styHeader.BackColor = Color.DarkGray; _styMoney.Format = XLStyle.FormatDotNetToXL("c"); _styOrder.Font = _styHeader.Font; _styOrder.ForeColor = Color.Red; //create report with one sheet per category DataTable dt = GetCategories(); foreach (DataRow dr in dt.Rows) { CreateSheet(dr); } //save xls file string uid = System.Guid.NewGuid().ToString(); string filename = Server.MapPath("~") + "\\Temp\\testexcel" + uid + ".xls"; _c1xl.Save(filename); return(filename); }
public void ExportBudgetForPrimavera_GetDrawingLogMainByProjList(string saveLoc, string xml, int sortCode, int drwgSpec) { SqlDataReader dr; C1XLBook book = new C1XLBook(); XLSheet sheet = book.Sheets[0]; int indx; decimal tmpRate; // must be output with the following columns // code,blank,description,quantity,uom,hours,rate,cost // dr = CBBudgetLine.GetExportListByBudget(budgetID); dr = CBDrawingLog.GetExportListForDrawingLog_Proj(xml, sortCode, drwgSpec); indx = 0; tmpRate = 0; while (dr.Read()) { sheet[indx, 3].Value = dr["DrawingID"].ToString(); // code sheet[indx, 4].Value = ""; // blank sheet[indx, 5].Value = dr["Department"]; // description sheet[indx, 6].Value = dr["Project"].ToString(); // quantity sheet[indx, 7].Value = dr["ProjectNumber"]; // uom sheet[indx, 8].Value = dr["Title1"].ToString(); // hours sheet[indx, 9].Value = dr["RevisionNumber"].ToString(); sheet[indx, 10].Value = dr["IssueDate"].ToString(); // rate sheet[indx, 11].Value = dr["IssuedFor"].ToString(); // cost sheet[indx, 12].Value = dr["TransNo"].ToString(); indx++; } dr.Close(); book.Save(saveLoc); }
private static void InternalSave(Action<C1XLBook> action) { var dlg = new SaveFileDialog(); dlg.Filter = "Excel Files (*.xlsx)|*.xlsx"; if (dlg.ShowDialog() == true) { try { var book = new C1XLBook(); if (action != null) { action(book); } using (var stream = dlg.OpenFile()) { book.Save(stream); } } catch (Exception x) { MessageBox.Show(x.Message); } } }
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); } } } } }
static public void ToExcel(C1TrueDBGrid _Dgd) { if (_Dgd.RowCount == 0) { return; } string filename = ""; var book = new C1XLBook(); try { SaveFileDialog dialog = new SaveFileDialog { Filter = "*.xls|*.xls", FileName = "DgdExcel.xls" }; if (dialog.ShowDialog() == DialogResult.OK) { filename = dialog.FileName; var sheet = book.Sheets[0]; sheet.Name = "Page1"; XLStyle style = new XLStyle(book); DateTimeFormatInfo dtfi = CultureInfo.CurrentCulture.DateTimeFormat; style.Format = XLStyle.FormatDotNetToXL(dtfi.ShortDatePattern); var k = 0; for (int i = 0; i < _Dgd.Columns.Count; i++) { if (_Dgd.Splits[0].DisplayColumns[i] == null) { break; } if (_Dgd.Splits[0].DisplayColumns[i].Visible) { sheet[0, k].Value = _Dgd.Columns[i].Caption; k++; } } for (int i = 0; i < _Dgd.RowCount; i++) { k = 0; for (int j = 0; j < _Dgd.Columns.Count; j++) { if (_Dgd.Splits[0].DisplayColumns[j] == null) { break; } if (_Dgd.Splits[0].DisplayColumns[j].Visible) { var obj = _Dgd[i, j]; if (obj != null) { if (obj.GetType() == typeof(DateTime)) { sheet[i + 1, k].Style = style; } sheet[i + 1, k].Value = _Dgd[i, j]; } else { sheet[i + 1, k].Value = ""; } k++; } } } book.Save(filename); } } catch (Exception ex) { MBox.ShowErr(ex.Message); return; } finally { book.Dispose(); } if (MBox.ShowAsk(string.Format("数据导出成功。保存路径:{0}\r\n是否打开?", filename))) { System.Diagnostics.Process.Start(filename); } }
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) { 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); } }
public void FullNewViewMultiBoth(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; } 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; ArrayList removeRow = new ArrayList(); ArrayList hideRow = new ArrayList(); 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"); xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\NewBillTongQuat.xlsx"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))); } XLStyle xlstStyleLeftCH = new XLStyle(xlbBook); xlstStyleLeftCH.AlignHorz = XLAlignHorzEnum.Left; xlstStyleLeftCH.AlignVert = XLAlignVertEnum.Center; xlstStyleLeftCH.Font = new Font("Times New Roman", 10, FontStyle.Bold); xlstStyleLeftCH.SetBorderColor(Color.Black); xlstStyleLeftCH.BorderTop = XLLineStyleEnum.Thin; xlstStyleLeftCH.WordWrap = false; 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 setValReplace(rBillNo, cBillNo, "{%BILL_NO%}", txtBillNo.Text); //Ngay Thang Nam DateTime dtime = DateTime.Today; setValReplace(rBillDate, cBillDate, "{%NGAY%}", dtime.ToString("dd")); setValReplace(rBillDate, cBillDate, "{%THANG%}", dtime.ToString("MM")); setValReplace(rBillDate, cBillDate, "{%NAM%}", dtime.ToString("yyyy")); //Nam setValReplace(rBillMonth, cBillMonth, "{%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 setValReplace(rCustomer, cCustomer, "{%TEN_CONG_TY%}", Name); //Contact setValReplace(rContact, cContact, "{%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(); setVal(rOffice, 2, Office); setVal(rPhone, 2, OfficePhone); setVal(rBank, 10, Bank); setVal(rAccountName, 10, AccountName); setVal(rAccount, 10, Account); } } } //setVal(rRate, cRate, xlsSheet[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", Func.FormatNumber_New(txtUsdExchange.Text))); //setVal(rRateDate, cRateDate, xlsSheet[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 viewNumber = 1; string strSum = ""; int line = 0; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); line = rRent - 3 + j; removeRow.Add(line + 2); mergeCell(line, line + 1, 1, 3); mergeCell(line, line, 4, 5); mergeCell(line + 1, line + 1, 4, 5); mergeCell(line + 2, line + 2, 4, 5); mergeCell(line, line, 6, 7); mergeCell(line + 1, line + 1, 6, 7); mergeCell(line, line, 8, 9); mergeCell(line + 1, line + 1, 8, 9); mergeCell(line, line, 10, 11); mergeCell(line + 1, line + 1, 10, 11); mergeCell(line, line, 12, 13); mergeCell(line + 1, line + 1, 12, 13); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; int k = 0; if (dt.Rows.Count <= 0) { for (int rHideLine = 0; rHideLine < 13; rHideLine++) { //setHideRow(rHideLine + line - 1); } setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; } else { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; foreach (DataRow rowType in dt.Rows) { 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 (tmp02 > 0) { if (count >= 1) { xlsSheet.Rows.Insert(rRent + 1 + j); xlsSheetEn.Rows.Insert(rRent + 1 + j); j++; } count++; int tmp = rRent + j; setVal(tmp, 1, YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4)); setVal(tmp, 4, rowType["Area"]); setVal(tmp, 6, rowType["MonthRentPriceVND"]); setVal(tmp, 8, rowType["MonthRentSumVND"]); setVal(tmp, 10, rowType["VatRentPriceVND"]); setVal(tmp, 12, rowType["LastRentSumVND"]); mergeCell(tmp, tmp, 1, 3); mergeCell(tmp, tmp, 4, 5); mergeCell(tmp, tmp, 6, 7); mergeCell(tmp, tmp, 8, 9); mergeCell(tmp, tmp, 10, 11); mergeCell(tmp, tmp, 12, 13); mergeCell(tmp, tmp, 1, 3); mergeCell(tmp, tmp, 4, 5); for (int col = 1; col <= 13; col++) { setStyle(tmp, col, xlstStyle); } setStyle(tmp, 4, xlstStyleC1); setStyle(tmp, 6, xlstStyle0); setStyle(tmp, 8, xlstStyle0); setStyle(tmp, 10, xlstStyle0); setStyle(tmp, 12, xlstStyle0); LastSumPriceVND[0] += Convert.ToDecimal(rowType["LastRentSumVND"]); } else { k++; } } mergeCell(rRent + 1 + j, rRent + 1 + j, 1, 11); setVal(rRent + 1 + j, 12, LastSumPriceVND[0]); mergeCell(rRent + 1 + j, rRent + 1 + j, 12, 13); //Format setStyle(rRent + 1 + j, 12, xlstStyleSum1); setStyle(rRent + 1 + j, 13, xlstStyleSum0); sumRow += dt.Rows.Count - 1 - k; //Phi quan ly line = rManager - 3 + j; setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; removeRow.Add(line + 2); mergeCell(line, line + 1, 1, 3); mergeCell(line, line, 4, 5); mergeCell(line + 1, line + 1, 4, 5); mergeCell(line + 2, line + 2, 4, 5); mergeCell(line, line, 6, 7); mergeCell(line + 1, line + 1, 6, 7); mergeCell(line, line, 8, 9); mergeCell(line + 1, line + 1, 8, 9); mergeCell(line, line, 10, 11); mergeCell(line + 1, line + 1, 10, 11); mergeCell(line, line, 12, 13); mergeCell(line + 1, line + 1, 12, 13); ////En k = 0; count = 0; foreach (DataRow row in dt.Rows) { decimal tmp02 = Convert.ToDecimal(row["LastManagerSumVND"]); if (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"]); setVal(tmp, 1, YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4)); setVal(tmp, 4, row["Area"]); setVal(tmp, 6, row["MonthManagerPriceVND"]); setVal(tmp, 8, row["MonthManagerSumVND"]); setVal(tmp, 10, row["VatManagerPriceVND"]); setVal(tmp, 12, row["LastManagerSumVND"]); mergeCell(tmp, tmp, 1, 3); mergeCell(tmp, tmp, 4, 5); for (int col = 1; col <= 13; col++) { setStyle(tmp, col, xlstStyle); } setStyle(tmp, 4, xlstStyleC1); setStyle(tmp, 6, xlstStyle0); setStyle(tmp, 8, xlstStyle0); setStyle(tmp, 10, xlstStyle0); setStyle(tmp, 12, xlstStyle0); mergeCell(tmp, tmp, 1, 3); mergeCell(tmp, tmp, 4, 5); mergeCell(tmp, tmp, 6, 7); mergeCell(tmp, tmp, 8, 9); mergeCell(tmp, tmp, 10, 11); mergeCell(tmp, tmp, 12, 13); LastSumPriceVND[1] += Convert.ToDecimal(row["LastManagerSumVND"]); } else { k++; } } mergeCell(rManager + 1 + j, rManager + 1 + j, 1, 11); setVal(rManager + 1 + j, 12, LastSumPriceVND[1]); mergeCell(rManager + 1 + j, rManager + 1 + j, 12, 13); setStyle(rManager + 1 + j, 12, xlstStyleSum0); sumRow += dt.Rows.Count - 1 - k; } } else { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; for (int rRentLine = 0; rRentLine < 15; rRentLine++) { //setHideRow(rRentLine + rRent - 4 + line); } } } 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; removeRow.Add(line + 2); mergeCell(line, line + 1, 1, 3); mergeCell(line, line, 4, 5); mergeCell(line + 1, line + 1, 4, 5); mergeCell(line + 2, line + 2, 4, 5); mergeCell(line, line, 6, 7); mergeCell(line + 1, line + 1, 6, 7); mergeCell(line, line, 8, 9); mergeCell(line + 1, line + 1, 8, 9); mergeCell(line, line, 10, 11); mergeCell(line + 1, line + 1, 10, 11); mergeCell(line, line, 12, 13); mergeCell(line + 1, line + 1, 12, 13); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; 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"]); // Phi gui xe setVal(tmp, 1, TariffsParkingName); setVal(tmp, 4, Num); setVal(tmp, 6, row["PriceVND"]); setVal(tmp, 8, row["SumVND"]); setVal(tmp, 10, row["VatVND"]); setVal(tmp, 12, row["LastPriceVND"]); mergeCell(tmp, tmp, 1, 3); mergeCell(tmp, tmp, 4, 5); for (int col = 1; col <= 13; col++) { setStyle(tmp, col, xlstStyle); } setStyle(tmp, 4, xlstStyleC1); setStyle(tmp, 5, xlstStyleC1); setStyle(tmp, 6, xlstStyle0); setStyle(tmp, 8, xlstStyle0); setStyle(tmp, 10, xlstStyle0); setStyle(tmp, 12, xlstStyle0); mergeCell(tmp, tmp, 1, 3); mergeCell(tmp, tmp, 4, 5); mergeCell(tmp, tmp, 6, 7); mergeCell(tmp, tmp, 8, 9); mergeCell(tmp, tmp, 10, 11); mergeCell(tmp, tmp, 12, 13); LastSumPriceVND[2] += Convert.ToDecimal(row["LastPriceVND"]); } setVal(rParking + 1 + j, 12, LastSumPriceVND[2]); mergeCell(rParking + 1 + j, rParking + 1 + j, 1, 11); mergeCell(rParking + 1 + j, rParking + 1 + j, 12, 13); setStyle(rParking + 1 + j, 12, xlstStyleSum0); mergeCell(rParking + 1 + j, rParking + 1 + j, 1, 11); sumRow += dt.Rows.Count - 1; } else { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; for (int rHideLine = 0; rHideLine < 6; rHideLine++) { //setHideRow(rHideLine + line - 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; removeRow.Add(line + 2); //Phi ngoai gio mergeCell(line, line + 1, 1, 2); mergeCell(line, line + 1, 4, 4); mergeCell(line, line, 6, 7); mergeCell(line + 1, line + 1, 6, 7); mergeCell(line, line, 8, 9); mergeCell(line + 1, line + 1, 8, 9); mergeCell(line, line, 10, 11); mergeCell(line + 1, line + 1, 10, 11); mergeCell(line, line, 12, 13); mergeCell(line + 1, line + 1, 12, 13); /////En if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; 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"]); setVal(tmp, 1, BeginDate + "~" + EndDate); setVal(tmp, 3, row["RentArea"]); setVal(tmp, 5, ExtraHour); setVal(tmp, 4, "Diện tích"); if ("0".Equals(ExtratimeType)) { setVal(tmp, 4, "m2*h"); } setVal(tmp, 6, row["PriceVND"]); setVal(tmp, 8, row["SumVND"]); setVal(tmp, 10, row["VatVND"]); setVal(tmp, 12, row["LastPriceVND"]); LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]); mergeCell(tmp, tmp, 1, 2); for (int col = 1; col <= 13; col++) { setStyle(tmp, col, xlstStyle); } ///////////////////// setStyle(tmp, 4, xlstStyleC1); setStyle(tmp, 5, xlstStyleC1); setStyle(tmp, 6, xlstStyle0); setStyle(tmp, 7, xlstStyle0); setStyle(tmp, 8, xlstStyle0); setStyle(tmp, 9, xlstStyle0); setStyle(tmp, 10, xlstStyle0); setStyle(tmp, 11, xlstStyle0); setStyle(tmp, 12, xlstStyle0); setStyle(tmp, 13, xlstStyle0); mergeCell(tmp, tmp, 1, 3); mergeCell(tmp, tmp, 6, 7); mergeCell(tmp, tmp, 8, 9); mergeCell(tmp, tmp, 10, 11); mergeCell(tmp, tmp, 12, 13); } } else { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; for (int rHideLine = 0; rHideLine < 6; rHideLine++) { //setHideRow(rHideLine + line - 1); } } mergeCell(rExtra + 1 + j, rExtra + 1 + j, 1, 11); setVal(rExtra + 1 + j, 12, LastSumPriceVND[3]); mergeCell(rExtra + 1 + j, rExtra + 1 + j, 12, 13); setStyle(rExtra + 1 + j, 12, xlstStyleSum1); setStyle(rExtra + 1 + j, 13, xlstStyleSum0); 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; removeRow.Add(line + 2); //Phi dien mergeCell(line, line + 1, 1, 1); mergeCell(line, line + 1, 2, 2); mergeCell(line, line, 12, 13); mergeCell(line + 1, line + 1, 12, 13); /////En for (int col = 1; col < 13; col++) { setStyle(line, col, xlstStyleH); setStyle(line + 1, col, xlstStyleH); setStyle(line + 2, col, xlstStyleH); } if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; 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; } setVal(tmp, 1, DateFrom); setVal(tmp, 2, DateTo); setVal(tmp, 3, FromIndex); setVal(tmp, 4, ToIndex); setVal(tmp, 5, row["OtherFee01"]); setVal(tmp, 6, Mount); setVal(tmp, 7, row["PriceVND"]); setVal(tmp, 8, row["Sum"]); setVal(tmp, 9, row["SumVAT"]); setVal(tmp, 10, row["OtherFee02"]); setVal(tmp, 11, row["ElecPricePercent"]); setVal(tmp, 12, row["LastPriceVND"]); mergeCell(tmp, tmp, 12, 13); for (int col = 1; col <= 13; col++) { setStyle(tmp, col, xlstStyle); } ///////////////// setStyle(tmp, 3, xlstStyleC2); setStyle(tmp, 4, xlstStyleC2); setStyle(tmp, 5, xlstStyleC0); setStyle(tmp, 6, xlstStyle2); setStyle(tmp, 7, xlstStyle0); setStyle(tmp, 8, xlstStyle0); setStyle(tmp, 9, xlstStyle0); setStyle(tmp, 10, xlstStyle0); setStyle(tmp, 11, xlstStyle2); setStyle(tmp, 12, xlstStyle0); } 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"]); } } } } /////////////////////////// setVal(rElec + 1 + j, 12, Decimal.Round(LastSumPriceVND[4], 0)); mergeCell(rElec + 1 + j, rElec + 1 + j, 1, 11); mergeCell(rElec + 1 + j, rElec + 1 + j, 12, 13); //// setStyle(rElec + 1 + j, 12, xlstStyleSum0); mergeCell(rElec + 1 + j, rElec + 1 + j, 1, 11); mergeCell(rElec + 1 + j, rElec + 1 + j, 12, 13); sumRow += dt.Rows.Count - 1; } else { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; for (int rHideLine = 0; rHideLine < 6; rHideLine++) { //setHideRow(rHideLine + line - 1); } } } } ds = new DataSet(); //Phi 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; removeRow.Add(line + 2); //Phi nuoc mergeCell(line, line + 1, 1, 1); mergeCell(line, line + 1, 2, 2); mergeCell(line, line, 12, 13); mergeCell(line + 1, line + 1, 12, 13); for (int col = 1; col < 13; col++) { setStyle(line, col, xlstStyleH); setStyle(line + 1, col, xlstStyleH); setStyle(line + 2, col, xlstStyleH); } for (int col = 1; col < 13; col++) { setStyle(line, col, xlstStyleH); setStyle(line + 1, col, xlstStyleH); setStyle(line + 2, col, xlstStyleH); } if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; 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; } setVal(tmp, 1, DateFrom); setVal(tmp, 2, DateTo); setVal(tmp, 3, FromIndex); setVal(tmp, 4, ToIndex); setVal(tmp, 5, Mount); setVal(tmp, 6, row["PriceVND"]); setVal(tmp, 8, row["OtherFee01"]); setVal(tmp, 7, row["Sum"]); setVal(tmp, 9, row["SumVAT"]); setVal(tmp, 10, row["OtherFee02"]); setVal(tmp, 11, row["WaterPricePercent"]); setVal(tmp, 12, row["LastPriceVND"]); for (int col = 1; col <= 13; col++) { setStyle(tmp, col, xlstStyle); } setStyle(tmp, 3, xlstStyleC2); setStyle(tmp, 4, xlstStyleC2); setStyle(tmp, 5, xlstStyleC2); setStyle(tmp, 6, xlstStyle0); setStyle(tmp, 7, xlstStyle0); setStyle(tmp, 8, xlstStyle0); setStyle(tmp, 9, xlstStyle0); setStyle(tmp, 10, xlstStyle2); setStyle(tmp, 11, xlstStyle2); setStyle(tmp, 12, xlstStyle0); mergeCell(tmp, tmp, 12, 13); } DataSet dsSum = new DataSet(); //Nuoc //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) { LastSumPriceVND[5] += Convert.ToDecimal(row["LastPriceVND"]); } } } } setVal(rWater + 1 + j, 12, Decimal.Round(LastSumPriceVND[5], 0)); mergeCell(rWater + 1 + j, rWater + 1 + j, 1, 11); mergeCell(rWater + 1 + j, rWater + 1 + j, 12, 13); setStyle(rWater + 1 + j, 12, xlstStyleSum0); sumRow += dt.Rows.Count - 1; } else { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; for (int rHideLine = 0; rHideLine < 6; rHideLine++) { //setHideRow(rHideLine + line - 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; removeRow.Add(line + 2); //Phi khác mergeCell(line, line + 1, 1, 1); mergeCell(line, line + 1, 2, 2); mergeCell(line, line + 1, 3, 3); mergeCell(line, line + 1, 4, 4); for (int col = 1; col < 13; col++) { setStyle(line, col, xlstStyleH); setStyle(line + 1, col, xlstStyleH); setStyle(line + 2, col, xlstStyleH); } mergeCell(line, line, 12, 13); mergeCell(line + 1, line + 1, 12, 13); if (ds != null) { int count = 0; DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; 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"]); setVal(tmp, 1, Service); setVal(tmp, 2, Func.ParseString(row["Unit"])); setVal(tmp, 3, ServiceDateFrom); setVal(tmp, 4, ServiceDateTo); setVal(tmp, 5, Mount); setVal(tmp, 6, row["PriceVND"]); setVal(tmp, 8, row["SumVND"]); setVal(tmp, 10, row["VatVND"]); setVal(tmp, 12, row["LastPriceVND"]); mergeCell(tmp, tmp, 6, 7); mergeCell(tmp, tmp, 8, 9); mergeCell(tmp, tmp, 10, 11); mergeCell(tmp, tmp, 12, 13); for (int col = 1; col <= 13; col++) { setStyle(tmp, col, xlstStyle); } setStyle(tmp, 5, xlstStyleC2); setStyle(tmp, 6, xlstStyle0); setStyle(tmp, 8, xlstStyle0); setStyle(tmp, 10, xlstStyle0); setStyle(tmp, 12, xlstStyle0); LastSumPriceVND[6] += Convert.ToDecimal(row["LastPriceVND"]); } setVal(rService + 1 + j, 12, LastSumPriceVND[6]); setStyle(rService + 1 + j, 12, xlstStyleSum0); mergeCell(rService + 1 + j, rService + 1 + j, 1, 11); mergeCell(rService + 1 + j, rService + 1 + j, 12, 13); sumRow += dt.Rows.Count - 1; } else { setVal(line - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; for (int rHideLine = 0; rHideLine < 6; rHideLine++) { //setHideRow(rHideLine + line - 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 + ""; sql += " and isnull(PaidVND,0) > 0"; string strYearMonth = ""; int lineTmp = rPaid - 2 + j; removeRow.Add(lineTmp + 1); /////En mergeCell(lineTmp, lineTmp + 1, 1, 1); mergeCell(lineTmp, lineTmp, 2, 3); mergeCell(lineTmp, lineTmp, 4, 5); mergeCell(lineTmp, lineTmp, 6, 7); mergeCell(lineTmp, lineTmp, 8, 9); mergeCell(lineTmp, lineTmp, 12, 13); /////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 }; int iPaidNo = 0; DataTable dtPaid = DbHelper.GetDataTable(sql); if (dtPaid.Rows.Count > 0) { setVal(lineTmp - 1, 0, viewNumber + "."); iPaidNo = viewNumber; viewNumber++; for (int i = 0; i < dtPaid.Rows.Count; i++) { string PaymentType = Func.ParseString(dtPaid.Rows[i]["PaymentType"]); string MoneyVND = Func.ParseString(dtPaid.Rows[i]["MoneyVND"]); 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 tmpVND = Convert.ToDecimal(MoneyVND) - Convert.ToDecimal(PaidVND); PaidPriceVND += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); setVal(rPaid + m, 1, YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4)); switch (PaymentType) { case "1": //Rent setVal(rPaid + m, 2, dtPaid.Rows[i]["PaidVND"]); PaidSumVND[0] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "2": //Manager setVal(rPaid + m, 4, dtPaid.Rows[i]["PaidVND"]); PaidSumVND[1] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "3": //Parking setVal(rPaid + m, 6, dtPaid.Rows[i]["PaidVND"]); PaidSumVND[2] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "4": //Extra setVal(rPaid + m, 8, dtPaid.Rows[i]["PaidVND"]); PaidSumVND[3] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "5": setVal(rPaid + m, 10, dtPaid.Rows[i]["PaidVND"]); PaidSumVND[4] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "6": setVal(rPaid + m, 11, dtPaid.Rows[i]["PaidVND"]); PaidSumVND[5] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; case "7": setVal(rPaid + m, 12, dtPaid.Rows[i]["PaidVND"]); PaidSumVND[6] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]); break; default: break; } ///////////////////////////////////////////////// for (int col = 1; col <= 13; col++) { setStyle(rPaid + m, col, xlstStyle); } //Rent setStyle(rPaid + m, 2, xlstStyle0); setStyle(rPaid + m, 3, xlstStyle0); //Manager setStyle(rPaid + m, 4, xlstStyle0); setStyle(rPaid + m, 5, xlstStyle0); //Parking setStyle(rPaid + m, 6, xlstStyle0); setStyle(rPaid + m, 7, xlstStyle0); //Extra setStyle(rPaid + m, 8, xlstStyle0); setStyle(rPaid + m, 9, xlstStyle0); setStyle(rPaid + m, 10, xlstStyle0); setStyle(rPaid + m, 11, xlstStyle0); setStyle(rPaid + m, 12, xlstStyle0); setStyle(rPaid + m, 13, xlstStyle0); mergeCell(rPaid + m, rPaid + m, 2, 3); mergeCell(rPaid + m, rPaid + m, 4, 5); mergeCell(rPaid + m, rPaid + m, 6, 7); mergeCell(rPaid + m, rPaid + m, 8, 9); mergeCell(rPaid + m, rPaid + m, 12, 13); } } else { setVal(lineTmp - 1, 0, viewNumber + "."); iPaidNo = viewNumber; viewNumber++; for (int rHideLine = 0; rHideLine < 6; rHideLine++) { //setHideRow(rHideLine + lineTmp - 1); } } lineTmp = rPaid - 2 + j; setVal(lineTmp + 3, 2, PaidSumVND[0]); setVal(lineTmp + 3, 4, PaidSumVND[1]); setVal(lineTmp + 3, 6, PaidSumVND[2]); setVal(lineTmp + 3, 8, PaidSumVND[3]); setVal(lineTmp + 3, 10, PaidSumVND[4]); setVal(lineTmp + 3, 11, PaidSumVND[5]); setVal(lineTmp + 3, 12, PaidSumVND[6]); mergeCell(lineTmp + 3, lineTmp + 3, 2, 3); mergeCell(lineTmp + 3, lineTmp + 3, 4, 5); mergeCell(lineTmp + 3, lineTmp + 3, 6, 7); mergeCell(lineTmp + 3, lineTmp + 3, 8, 9); mergeCell(lineTmp + 3, lineTmp + 3, 12, 13); /////////////// setStyle(lineTmp + 3, 2, xlstStyleSum1); setStyle(lineTmp + 3, 3, xlstStyleSum0); setStyle(lineTmp + 3, 4, xlstStyleSum0); setStyle(lineTmp + 3, 5, xlstStyleSum0); setStyle(lineTmp + 3, 6, xlstStyleSum0); setStyle(lineTmp + 3, 7, xlstStyleSum0); setStyle(lineTmp + 3, 8, xlstStyleSum0); setStyle(lineTmp + 3, 9, xlstStyleSum0); setStyle(lineTmp + 3, 10, xlstStyleSum0); setStyle(lineTmp + 3, 11, xlstStyleSum0); setStyle(lineTmp + 3, 12, xlstStyleSum0); setStyle(lineTmp + 3, 13, xlstStyleSum0); ///////////////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; removeRow.Add(lineTmp + 1); //////En mergeCell(lineTmp, lineTmp + 1, 1, 1); mergeCell(lineTmp, lineTmp, 2, 3); mergeCell(lineTmp, lineTmp, 4, 5); mergeCell(lineTmp, lineTmp, 6, 7); mergeCell(lineTmp, lineTmp, 8, 9); mergeCell(lineTmp, lineTmp, 12, 13); //////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); if (dtDept.Rows.Count > 0) { setVal(lineTmp - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; for (int i = 0; i < dtDept.Rows.Count; i++) { string PaymentType = Func.ParseString(dtDept.Rows[i]["PaymentType"]); 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; DeptPriceVND += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); setVal(rDept + m, 1, YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4)); switch (PaymentType) { case "1": //Rent setVal(rDept + m, 3, dtDept.Rows[i]["DeptVND"]); DeptSumVND[0] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "2": //Manager setVal(rDept + m, 5, dtDept.Rows[i]["DeptVND"]); DeptSumVND[1] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "3": //Parking setVal(rDept + m, 7, dtDept.Rows[i]["DeptVND"]); DeptSumVND[2] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "4": //Extra setVal(rDept + m, 9, dtDept.Rows[i]["DeptVND"]); DeptSumVND[3] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "5": setVal(rDept + m, 10, dtDept.Rows[i]["DeptVND"]); DeptSumVND[4] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "6": setVal(rDept + m, 11, dtDept.Rows[i]["DeptVND"]); DeptSumVND[5] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; case "7": setVal(rDept + m, 13, dtDept.Rows[i]["DeptVND"]); DeptSumVND[6] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]); break; default: break; } for (int col = 1; col <= 13; col++) { setStyle(rDept + m, col, xlstStyle); } setStyle(rDept + m, 2, xlstStyle1); setStyle(rDept + m, 3, xlstStyle0); //Manager setStyle(rDept + m, 4, xlstStyle1); setStyle(rDept + m, 5, xlstStyle0); //Parking setStyle(rDept + m, 6, xlstStyle1); setStyle(rDept + m, 7, xlstStyle0); //Extra setStyle(rDept + m, 8, xlstStyle1); setStyle(rDept + m, 9, xlstStyle0); setStyle(rDept + m, 10, xlstStyle0); setStyle(rDept + m, 11, xlstStyle0); setStyle(rDept + m, 12, xlstStyle1); setStyle(rDept + m, 13, xlstStyle0); mergeCell(rDept + m, rDept + m, 2, 3); mergeCell(rDept + m, rDept + m, 4, 5); mergeCell(rDept + m, rDept + m, 6, 7); mergeCell(rDept + m, rDept + m, 8, 9); mergeCell(rDept + m, rDept + m, 10, 11); mergeCell(rDept + m, rDept + m, 12, 13); } } else { setVal(lineTmp - 1, 0, viewNumber + "."); strSum += viewNumber + " + "; viewNumber++; for (int rHideLine = 0; rHideLine < 5; rHideLine++) { //setHideRow(rHideLine + lineTmp - 1); } } lineTmp = rDept - 2 + j; setVal(lineTmp + 3, 3, DeptSumVND[0]); setVal(lineTmp + 3, 5, DeptSumVND[1]); setVal(lineTmp + 3, 7, DeptSumVND[2]); setVal(lineTmp + 3, 9, DeptSumVND[3]); setVal(lineTmp + 3, 10, DeptSumVND[4]); setVal(lineTmp + 3, 11, DeptSumVND[5]); setVal(lineTmp + 3, 13, DeptSumVND[6]); setStyle(lineTmp + 3, 2, xlstStyleSum1); setStyle(lineTmp + 3, 3, xlstStyleSum0); setStyle(lineTmp + 3, 4, xlstStyleSum0); setStyle(lineTmp + 3, 5, xlstStyleSum0); setStyle(lineTmp + 3, 6, xlstStyleSum0); setStyle(lineTmp + 3, 7, xlstStyleSum0); setStyle(lineTmp + 3, 8, xlstStyleSum0); setStyle(lineTmp + 3, 9, xlstStyleSum0); setStyle(lineTmp + 3, 10, xlstStyleSum0); setStyle(lineTmp + 3, 11, xlstStyleSum0); setStyle(lineTmp + 3, 12, xlstStyleSum0); setStyle(lineTmp + 3, 13, xlstStyleSum0); mergeCell(lineTmp + 3, lineTmp + 3, 2, 3); mergeCell(lineTmp + 3, lineTmp + 3, 4, 5); mergeCell(lineTmp + 3, lineTmp + 3, 6, 7); mergeCell(lineTmp + 3, lineTmp + 3, 8, 9); mergeCell(lineTmp + 3, lineTmp + 3, 10, 11); mergeCell(lineTmp + 3, lineTmp + 3, 12, 13); strSum = strSum.Substring(0, strSum.Length - 2) + (iPaidNo > 0 ? " - " + iPaidNo : "") + ":"; 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; //setVal(rSumVND + j, cSumVND - 2, Func.FormatNumber_New(AllSumUSD)); setVal(rSumVND + j, cSumVND, Func.FormatNumber_New(Math.Truncate(Convert.ToDecimal(AllSumVND))).Replace(",00", "")); mergeCell(rSumVND + j, rSumVND + j, 10, 13); //format //setStyle(rSumVND + j, cSumVND - 2, xlstStyleCH); setStyle(rSumVND + j, cSumVND, xlstStyleCH); //AllSumVND += Convert.ToDecimal(AllSumUSD * Convert.ToDecimal(txtUsdExchange.Text)); string strMoney = Func.docso(Convert.ToDecimal(AllSumVND)); string strMoneyEn = Func.DocSo_En(Convert.ToDecimal(AllSumVND)); //Hop Dong setValReplace(rContract, cContract, "{%HOP_DONG%}", String.IsNullOrEmpty(contract) ? "" : contract.Substring(1)); //Sum 1 + 2... setVal(rSum + j - 1, 7, strSum); //Sum số tiền setVal(rSum + j - 1, 10, Func.FormatNumber_New(Math.Truncate(Convert.ToDecimal(AllSumVND))).Replace(",00", "")); mergeCell(rSum + j - 1, rSum + j - 1, 10, 13); setStyle(rSum + j - 1, 10, xlstStyleCSum0); //Chữ //mergeCell(rSumRead + j, rSumRead + j, 7, 13); setVal(rSum + j + 1, 7, strMoney.ToUpper()); xlsSheetEn[rSum + j + 1, 7].Value = strMoneyEn.ToUpper(); setStyle(rSum + j + 1, 7, xlstStyleLeftCH); removeRow.Sort(); removeRow.Reverse(); for (int r = 0; r < removeRow.Count; r++) { setHideRow(Func.ParseInt(removeRow[r])); } 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 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 btnExport_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT *"; sql += " FROM Report_BuildingInfo where id = 42"; 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.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 fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\NuocTieuThuThang.xlsx"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\NuocTieuThuThang")) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\NuocTieuThuThang")); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\NuocTieuThuThang\NuocTieuThuThang" + strDT + ".xlsx"; string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/NuocTieuThuThang/NuocTieuThuThang" + strDT + ".xlsx"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { int stt = 0; string id = rowType["id"].ToString(); string sheet = "Report"; int NumOfCol = Func.ParseInt(rowType["NoOfColumn"].ToString()); string SqlSelect = rowType["SqlSelect"].ToString(); SqlSelect = SqlSelect.Replace("{%DATE_FROM%}", Func.FormatYYYYmmdd(txtFromDate.Text)); SqlSelect = SqlSelect.Replace("{%DATE_TO%}", Func.FormatYYYYmmdd(txtToDate.Text)); SqlSelect = SqlSelect.Replace("{%TOA_NHA%}", Func.ParseString(Session["__BUILDINGID__"])); XLSheet xlsSheet = xlbBook.Sheets[sheet]; xlsSheet[0, 1].Value = xlsSheet[0, 1].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'")); xlsSheet[0, 1].Value = xlsSheet[0, 1].Value.ToString().Replace("{%THANG_NAM%}", txtFromDate.Text + "~" + txtToDate.Text); int CellY = Func.ParseInt(rowType["CellBeginY"].ToString()); int CellX = Func.ParseInt(rowType["CellBeginX"].ToString()); using (SqlCommand cmSheet = db.CreateCommand(SqlSelect)) { DataSet dsSheet = new DataSet(); SqlDataAdapter daSheet = new SqlDataAdapter(cmSheet); daSheet.Fill(dsSheet); if (dsSheet != null) { DataTable dtSheet = dsSheet.Tables[0]; foreach (DataRow rowSheet in dtSheet.Rows) { xlsSheet[CellY + stt, CellX].Style = xlstStyle; xlsSheet[CellY + stt, CellX].Value = ++stt + ""; for (int k = 0; k < NumOfCol; k++) { xlsSheet[CellY + stt - 1, CellX + k + 1].Value = rowSheet[k]; xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyle; } } } } } xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } }
private void cmdExcel_Click(object sender, EventArgs e) { try { string reportcode = "BHYT_21A_EXCEL"; string duongdan = Utility.GetPathExcel(reportcode); var book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); XLSheet sheet = book.Sheets[0]; DataTable dt = m_dataTH; int idxRow = 6; int idxColSh = 0; string codintion = string.Format("Từ ngày {0} đến ngày {1}. Tuyến {2}", dtpFromDate.Value.ToString("dd/MM/yyyy"), dtpToDate.Value.ToString("dd/MM/yyyy"), cboTuyen.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); int sttloaidichvu = 1; if (chktuyen.Checked) { for (int i = 0; i < dt.Rows.Count; i++) { if (i == 0) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(dt.Rows[i]["DoiTuong"]), HamDungChung.styleStringLeft_Bold(book)); idxRow = idxRow + 1; sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); sttloaidichvu = sttloaidichvu + 1; idxRow = idxRow + 1; } else { if (dt.Rows[i]["DoiTuong"].ToString() != dt.Rows[i - 1]["DoiTuong"].ToString()) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(dt.Rows[i]["DoiTuong"]), HamDungChung.styleStringLeft_Bold(book)); idxRow = idxRow + 1; sttloaidichvu = 1; sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); sttloaidichvu = sttloaidichvu + 1; idxRow = idxRow + 1; } if (dt.Rows[i]["DoiTuong"].ToString() == dt.Rows[i - 1]["DoiTuong"].ToString() && dt.Rows[i]["Ten_nhombaocao_dichvu"].ToString() != dt.Rows[i - 1]["Ten_nhombaocao_dichvu"].ToString()) { sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); sttloaidichvu = sttloaidichvu + 1; idxRow = idxRow + 1; } } sheet[idxRow, idxColSh].SetValue(Convert.ToString(dt.Rows[i]["ma_QD"]), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ma_chitiet_bhyt"]), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToDecimal(dt.Rows[i]["SO_LUONG"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToDecimal(dt.Rows[i]["soluong_nt"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToDecimal(dt.Rows[i]["DON_GIA"]), HamDungChung.styleDecimalBoldAllBorder_Money(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToDecimal(dt.Rows[i]["thanh_tien"]), HamDungChung.styleDecimalBoldAllBorder_Money(book)); idxRow = idxRow + 1; } } else { for (int i = 0; i < dt.Rows.Count; i++) { if (i == 0) { sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); sttloaidichvu = sttloaidichvu + 1; idxRow = idxRow + 1; } else { if (dt.Rows[i]["Ten_nhombaocao_dichvu"].ToString() != dt.Rows[i - 1]["Ten_nhombaocao_dichvu"].ToString()) { sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); sttloaidichvu = sttloaidichvu + 1; idxRow = idxRow + 1; } } sheet[idxRow, idxColSh].SetValue(Convert.ToString(dt.Rows[i]["ma_QD"]), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ma_chitiet_bhyt"]), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToDecimal(dt.Rows[i]["SO_LUONG"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToDecimal(dt.Rows[i]["soluong_nt"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToDecimal(dt.Rows[i]["DON_GIA"]), HamDungChung.styleDecimalBoldAllBorder_Money(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToDecimal(dt.Rows[i]["thanh_tien"]), HamDungChung.styleDecimalBoldAllBorder_Money(book)); idxRow = idxRow + 1; } } sheet[idxRow, idxColSh + 3].SetValue(Convert.ToDecimal(dt.Compute("Sum(SO_LUONG)", "1=1")), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToDecimal(dt.Compute("Sum(soluong_nt)", "1=1")), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToDecimal(dt.Compute("Sum(thanh_tien)", "1=1")), HamDungChung.styleDecimalBoldAllBorder_Money(book)); string getdate = string.Format("Ngày {0} tháng {1} năm {2}", dtpNgayIn.Value.Day, dtpNgayIn.Value.Month, dtpNgayIn.Value.Year); sheet[idxRow + 2, 5].SetValue(getdate, HamDungChung.styleStringCenter_UnBorder(book)); sheet[idxRow + 3, 1].SetValue("NGƯỜI LẬP BẢNG", HamDungChung.styleDecimalBoldAllBorder_Money(book)); sheet[idxRow + 3, 4].SetValue("PHÒNG TÀI CHÍNH KẾ TOÁN", HamDungChung.styleDecimalBoldAllBorder_Money(book)); sheet[idxRow + 3, 5].SetValue("GIÁM ĐỐC BỆNH VIỆN", HamDungChung.styleDecimalBoldAllBorder_Money(book)); // vị trí dòng dữ liệu của table tiếp theo, vị trí cột bắt đầu t? 0 string getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); string pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); } catch (Exception ex) { Utility.ShowMsg("Lỗi: " + ex.Message); } }
protected void btnExport_Click(object sender, EventArgs e) { string yearmonth = drpYear.SelectedValue; string building = Func.ParseString(Session["__BUILDINGID__"]); DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT *"; sql += " FROM BD_BudgetSchedule "; sql += " WHERE BuildingId = '" + building + "' "; sql += " and YearMonth = '" + yearmonth + "' "; sql += " and id ='" + drpBudgetExport.SelectedValue + "' and DelFlag = 0 Order by id"; using (SqlDatabase db = new SqlDatabase()) { C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\NganSach.xlsx"); 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__"]) + @"\NganSach" + strDT + ".xlsx"; string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/NganSach" + 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); string sheet = "NganSach"; XLSheet xlsSheet = xlbBook.Sheets[sheet]; string IDs = ""; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { xlsSheet[0, 1].Value = xlsSheet[0, 1].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + building + "'")); xlsSheet[0, 1].Value = xlsSheet[0, 1].Value.ToString().Replace("{%NAM_THANG%}", "NĂM " + yearmonth); int j = 2; DataTable dtReport = ds.Tables[0]; foreach (DataRow rowType in dtReport.Rows) { string Budget = rowType["Budget"].ToString(); string id = rowType["id"].ToString(); IDs += ",'" + id + "'"; xlsSheet[2, j].Value = id; xlsSheet[3, j].Value = Budget; j += 2; } for (int i = j; i < j * 12; i++) { XLColumn col = new XLColumn(); col = xlsSheet.Columns[j]; xlsSheet.Columns.Remove(col); } } } if (String.IsNullOrEmpty(IDs)) { mvMessage.AddError("Hiện tại chưa có Kỳ ngân sách nào được tạo"); return; } DataTable dtTable = new DataTable(); dtTable.Columns.Add("SessionId", Type.GetType("System.String")); dtTable.Columns.Add("BuggetScheduleId", Type.GetType("System.Int32")); dtTable.Columns.Add("PaymentId", Type.GetType("System.Int32")); dtTable.Columns.Add("ParentId", Type.GetType("System.String")); string buildingId = Func.ParseString(Session["__BUILDINGID__"]); string sessionId = Session.SessionID; string sqlTmp = "Select * from BD_BudgetScheduleDetail where BuggetScheduleId in (" + IDs.Substring(1) + ") and delFlag = 0 Order by ParentId"; DbHelper.ExecuteNonQuery("Delete From BD_BudgetScheduleDetailReport where SessionId = '" + sessionId + "'"); DataTable dt = DbHelper.GetDataTable(sqlTmp); foreach (DataRow dr in dt.Rows) { if (dr["ParentId"].ToString() == "0") { int j = 1; int BuggetScheduleId = Func.ParseInt(dr["BuggetScheduleId"]); int PaymentId = Func.ParseInt(dr["PaymentId"]); string ParentId = dr["ParentId"].ToString(); dtTable.Rows.Add(sessionId, BuggetScheduleId, PaymentId, ParentId); GetChildItems(dr["PaymentId"].ToString(), dt, dtTable, j); } } using (SqlBulkCopy copy = new SqlBulkCopy(Gnt.Configuration.ApplicationConfiguration.ConnectionString)) { copy.DestinationTableName = "BD_BudgetScheduleDetailReport"; copy.BatchSize = 3000; copy.BulkCopyTimeout = 99999; copy.ColumnMappings.Add(0, "SessionId"); copy.ColumnMappings.Add(1, "BuggetScheduleId"); copy.ColumnMappings.Add(2, "PaymentId"); copy.ColumnMappings.Add(3, "ParentId"); copy.WriteToServer(dtTable); } ds = new DataSet(); sql = "Select * from BD_BudgetScheduleDetailReport where SessionId = '" + sessionId + "' Order by Id"; int k = 5; int colData = -1; string bsId = ""; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { DataTable dtReport = ds.Tables[0]; foreach (DataRow rowType in dtReport.Rows) { string PaymentType = rowType["PaymentType"].ToString(); string InVND = rowType["InVND"].ToString(); string InUSD = rowType["InUSD"].ToString(); string OutVND = rowType["OutVND"].ToString(); string OutUSD = rowType["OutUSD"].ToString(); string PaymentId = rowType["PaymentId"].ToString(); int colNo = Func.ParseInt(rowType["colNo"].ToString()); string id = rowType["BuggetScheduleId"].ToString(); string ParentId = rowType["ParentId"].ToString(); //string PaymentId = rowType["PaymentId"].ToString(); //xlsSheet[2, j].Value = id; //xlsSheet[3, j].Value = Budget; //j += 2; if (!bsId.Equals(id)) { k = 5; colData += 2; bsId = id; } xlsSheet[k, 1].Value = PaymentType; xlsSheet[k, colData + 1].Value = Func.ParseDouble(InUSD); xlsSheet[k, colData + 2].Value = Func.ParseDouble(InVND); //xlsSheet[k, colData + 3].Value = Func.ParseDouble(OutUSD); //xlsSheet[k, colData + 4].Value = Func.ParseDouble(OutVND); xlsSheet[k, 0].Value = PaymentId; XLStyle xlstStyle = new XLStyle(xlbBook); xlstStyle.AlignHorz = XLAlignHorzEnum.Left; xlstStyle.WordWrap = false; 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; if ("0".Equals(ParentId)) { xlstStyle.BackColor = Color.Orange; } xlsSheet[k, 1].Style = xlstStyle; xlstStyle = new XLStyle(xlbBook); if (String.IsNullOrEmpty(ParentId)) { xlstStyle.BackColor = Color.Orange; } xlstStyle.WordWrap = false; 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.AlignHorz = XLAlignHorzEnum.Center; xlsSheet[k, colData + 1].Style = xlstStyle; xlsSheet[k, colData + 2].Style = xlstStyle; //xlsSheet[k, colData+3].Style = xlstStyle; //xlsSheet[k, colData+4].Style = xlstStyle; k++; } } } //ds = new DataSet(); //sql = string.Empty; //sql = " SELECT *"; //sql += " FROM BD_PaymentReportMonth "; //sql += " WHERE BuildingId = '" + building + "' "; //sql += " and YearMonth = '" + yearmonth + "' order by id"; //using (db = new SqlDatabase()) //{ // using (SqlCommand cm = db.CreateCommand(sql)) // { // SqlDataAdapter da = new SqlDataAdapter(cm); // da.Fill(ds); // if (ds != null) // { // xlbBook = new C1XLBook(); // fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BaoCaoThuChiThang.xlsx"); // if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))) // { // Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))); // } // strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); // strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoThuChiThang" + strDT + ".xlsx"; // strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/BaoCaoThuChiThang" + strDT + ".xlsx"; // 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); // sheet = "BaoCao"; // xlsSheet = xlbBook.Sheets[sheet]; // int i = 5; // xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + building + "'")); // xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%NAM_THANG%}", "THÁNG" + yearmonth.Substring(4, 2) + "/" + yearmonth.Substring(0, 4)); // DataTable dtReport = ds.Tables[0]; // foreach (DataRow rowType in dtReport.Rows) // { // int colNo = Func.ParseInt(rowType["colNo"]); // string PaymentType = rowType["PaymentType"].ToString(); // string InVND = rowType["InVND"].ToString(); // string InUSD = rowType["InUSD"].ToString(); // string OutVND = rowType["OutVND"].ToString(); // string OutUSD = rowType["OutUSD"].ToString(); // bool bold = rowType["bold"].ToString().Equals("1") ? true : false; // XLCellRange mrCell = new XLCellRange(i, i, 0, 3); // xlsSheet.MergedCells.Add(mrCell); // xlsSheet[i, 0].Value = "." + " ".PadLeft(colNo * 3, ' ') + PaymentType; // xlsSheet[i, 4].Value = Func.ParseDouble(InUSD); // xlsSheet[i, 5].Value = Func.ParseDouble(InVND); // xlsSheet[i, 6].Value = Func.ParseDouble(OutUSD); // xlsSheet[i, 7].Value = Func.ParseDouble(OutVND); // XLStyle xlstStyle = new XLStyle(xlbBook); // xlstStyle.AlignHorz = XLAlignHorzEnum.Left; // xlstStyle.WordWrap = false; // 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; // xlsSheet[i, 0].Style = xlstStyle; // xlsSheet[i, 1].Style = xlstStyle; // xlsSheet[i, 2].Style = xlstStyle; // xlsSheet[i, 3].Style = xlstStyle; // xlstStyle = new XLStyle(xlbBook); // xlstStyle.WordWrap = false; // 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.AlignHorz = XLAlignHorzEnum.Center; // xlsSheet[i, 4].Style = xlstStyle; // xlsSheet[i, 5].Style = xlstStyle; // xlsSheet[i, 6].Style = xlstStyle; // xlsSheet[i, 7].Style = xlstStyle; // i++; // } // xlbBook.Save(fileNameDes); // ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); // } // } //} xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } }
public static Boolean ArticleDataExportListToExcel(ArticleDataExportModel articleDataExportModel, string FilePathName) { Boolean result = false; //Application ExcelApp = new Application(); //Workbook ExcelWorkBook = null; //Worksheet ExcelWorkSheet = null; //ExcelApp.Visible = false; //// Get a new workbook. //ExcelWorkBook = ExcelApp.Workbooks.Add(Missing.Value); ////ExcelWorkBook = ExcelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet); //try //{ // IList<PurchaseDetails> listPurchaseDetails = new List<PurchaseDetails>(); // listPurchaseDetails = articleDataExportModel.PurchaseDetails; // ExcelWorkSheet = ExcelWorkBook.Worksheets.Add(); //Adding New sheet in Excel Workbook // ExcelWorkSheet.Name = "PurchaseDetails"; // ListsToExcel(listPurchaseDetails, ref ExcelWorkSheet); // IList<SalesDetails> listSalesDetails = new List<SalesDetails>(); // listSalesDetails = articleDataExportModel.SalesDetails; // ExcelWorkSheet = ExcelWorkBook.Worksheets.Add(); //Adding New sheet in Excel Workbook // ExcelWorkSheet.Name = "SalesDetails"; // ListsToExcel(listSalesDetails, ref ExcelWorkSheet); // IList<CharDetails> listCharDetails = new List<CharDetails>(); // listCharDetails = articleDataExportModel.CharDetails; // ExcelWorkSheet = ExcelWorkBook.Worksheets.Add(); //Adding New sheet in Excel Workbook // ExcelWorkSheet.Name = "CharDetails"; // ListsToExcel(listCharDetails, ref ExcelWorkSheet); // IList<TaxDetails> listTaxDetails = new List<TaxDetails>(); // listTaxDetails = articleDataExportModel.TaxDetails; // ExcelWorkSheet = ExcelWorkBook.Worksheets.Add(); //Adding New sheet in Excel Workbook // ExcelWorkSheet.Name = "TaxDetails"; // ListsToExcel(listTaxDetails, ref ExcelWorkSheet); // IList<ArticleDetails> listArticleDetails = new List<ArticleDetails>(); // listArticleDetails = articleDataExportModel.ArticleDetails; // ExcelWorkSheet = ExcelWorkBook.Worksheets.Add(); //Adding New sheet in Excel Workbook // ExcelWorkSheet.Name = "ArticleDetails"; // ListsToExcel(listArticleDetails, ref ExcelWorkSheet); // ExcelWorkBook.SaveAs(FilePathName); // ExcelWorkBook.Close(); // ExcelApp.Quit(); // Marshal.ReleaseComObject(ExcelWorkSheet); // Marshal.ReleaseComObject(ExcelWorkBook); // Marshal.ReleaseComObject(ExcelApp); // result = true; C1XLBook ExcelWorkBook = new C1XLBook(); //vipin on 02-04-2016 try { IList <ArticleDetails> listArticleDetails = new List <ArticleDetails>(); listArticleDetails = articleDataExportModel.ArticleDetails; // ExcelWorkSheet = ExcelWorkBook.Worksheets.Add(); //Adding New sheet in Excel Workbook XLSheet ExcelWorkSheet4 = ExcelWorkBook.Sheets[0]; // ExcelWorkSheet4.Name = "ArticleDetails";Article Data ExcelWorkSheet4.Name = "Article Data"; ListsToExcelUsingC1(listArticleDetails, ref ExcelWorkSheet4, "Article Data"); IList <TaxDetails> listTaxDetails = new List <TaxDetails>(); listTaxDetails = articleDataExportModel.TaxDetails; // ExcelWorkSheet = ExcelWorkBook.Worksheets.Add(); //Adding New sheet in Excel Workbook XLSheet ExcelWorkSheet3 = ExcelWorkBook.Sheets.Add(); ExcelWorkSheet3.Name = "Article Tax"; ListsToExcelUsingC1(listTaxDetails, ref ExcelWorkSheet3, "Article Tax"); IList <CharDetails> listCharDetails = new List <CharDetails>(); listCharDetails = articleDataExportModel.CharDetails; // ExcelWorkSheet = ExcelWorkBook.Worksheets.Add(); //Adding New sheet in Excel Workbook XLSheet ExcelWorkSheet2 = ExcelWorkBook.Sheets.Add(); ExcelWorkSheet2.Name = "Article Char"; ListsToExcelUsingC1(listCharDetails, ref ExcelWorkSheet2, "Article Char"); IList <SalesDetails> listSalesDetails = new List <SalesDetails>(); listSalesDetails = articleDataExportModel.SalesDetails; // ExcelWorkSheet = ExcelWorkBook.Worksheets.Add(); //Adding New sheet in Excel Workbook XLSheet ExcelWorkSheet1 = ExcelWorkBook.Sheets.Add(); ExcelWorkSheet1.Name = "Barcode Pricing"; ListsToExcelUsingC1(listSalesDetails, ref ExcelWorkSheet1, "Barcode Pricing"); IList <PurchaseDetails> listPurchaseDetails = new List <PurchaseDetails>(); listPurchaseDetails = articleDataExportModel.PurchaseDetails; // ExcelWorkSheet = ExcelWorkBook.Worksheets.Add(); //Adding New sheet in Excel Workbook // Worksheet ExcelWorkSheet = ExcelWorkBook.Worksheets[1]; XLSheet ExcelWorkSheet0 = ExcelWorkBook.Sheets.Add(); ExcelWorkSheet0.Name = "Add. Purchase UOMs"; ListsToExcelUsingC1(listPurchaseDetails, ref ExcelWorkSheet0, "Add. Purchase UOMs"); ExcelWorkBook.Save(FilePathName); // ExcelWorkBook.Close(); // xlApp.Quit(); // Marshal.ReleaseComObject(ExcelWorkSheet); // Marshal.ReleaseComObject(ExcelWorkBook); // Marshal.ReleaseComObject(xlApp); result = true; } catch (Exception exHandle) { Logging.Logger.Log(exHandle, Logging.Logger.LogingLevel.Error); throw exHandle; } finally { foreach (Process process in Process.GetProcessesByName("Excel")) { process.Kill(); } } return(result); }
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 ActionResult ExportResults(int id) { C1.C1Excel.C1XLBook book = new C1XLBook(); book.Author = "Kevin Griffin"; var sheet = book.Sheets[0]; using (var context = new LeadGenContext()) { // sheet 0, contact info sheet.Name = "Respondents"; var responseEvents = context.Responses.Include("OriginalEvent").Include("Responses").Include("Responses.OriginalQuestion").Where(p => p.OriginalEvent.EventId == id); sheet[0, 0].Value = "First Name"; sheet[0, 1].Value = "Last Name"; sheet[0, 2].Value = "Email Address"; sheet[0, 3].Value = "Zip Code"; int currentRow = 1; foreach (var response in responseEvents) { sheet[currentRow, 0].Value = response.FirstName; sheet[currentRow, 1].Value = response.LastName; sheet[currentRow, 2].Value = response.EmailAddress; sheet[currentRow, 3].Value = response.ZipCode; currentRow++; } sheet = book.Sheets.Add(); sheet.Name = "Results"; var results = new List<QuestionResult>(); foreach (var e in responseEvents) { foreach (var q in e.Responses.OrderBy(p => p.OriginalQuestion.QuestionId)) { // is q in result list? QuestionResponse q1 = q; var questionResults = results.Where(p => p.QuestionText == q1.OriginalQuestion.QuestionText); if (questionResults.Any()) { // is answer in questionResult var first = questionResults.First(); var answers = first.QuestionAnswers.Where(p => p.AnswerText == q1.Answer); if (answers.Any()) { var firstAnswer = answers.First(); firstAnswer.AnswerCount++; } else { first.QuestionAnswers.Add(new Answer() { AnswerText = q.Answer, AnswerCount = 1 }); } } else { results.Add(new QuestionResult { QuestionText = q.OriginalQuestion.QuestionText, QuestionAnswers = new List<Answer>() { new Answer() { AnswerCount = 1, AnswerText = q.Answer } } }); } } } sheet[0, 0].Value = "Question Text"; sheet[0, 1].Value = "Answer Count"; sheet[0, 2].Value = "Answer Text"; currentRow = 1; foreach (var questionResult in results) { sheet[currentRow, 0].Value = questionResult.QuestionText; currentRow++; foreach (var answer in questionResult.QuestionAnswers) { sheet[currentRow, 1].Value = answer.AnswerCount; sheet[currentRow, 2].Value = answer.AnswerText; currentRow++; } } sheet = book.Sheets.Add(); sheet.Name = "Results per Attendee"; sheet[0, 0].Value = "Attendee Name"; sheet[0, 1].Value = "Question Text"; sheet[0, 2].Value = "Answer Text"; currentRow = 1; foreach (var response in context.Responses.Where(p => p.OriginalEvent.EventId == id).Include("Responses")) { sheet[currentRow, 0].Value = string.Format("{0} {1}", response.FirstName, response.LastName); foreach (var r in response.Responses) { sheet[currentRow, 1].Value = r.OriginalQuestion.QuestionText; sheet[currentRow, 2].Value = r.Answer; currentRow++; } } } var tempFile = System.IO.Path.GetTempFileName(); book.Save(tempFile); return File(tempFile, "application/vnd.ms-excel", "event.xls"); }
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); } } } }
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); } }
private void cmdExportToExcel_Click(object sender, EventArgs e) { try { int trangthai = -1; if (radTatca.Checked) { trangthai = -1; } if (radDathuchien.Checked) { trangthai = 1; } if (radChuathuchien.Checked) { trangthai = 0; } DataTable dtDanhsach = SPs.BaocaoThongkedanhsachThuchienchucnang(dtFromDate.Value, dtToDate.Value, Utility.Int16Dbnull(cboDoituongKCB.SelectedValue, -1), Utility.sDbnull(cboKhoa.SelectedValue, "KKB"), Args, Utility.Int32Dbnull(txtdichvu.MyID, -1), trangthai).GetDataSet().Tables[0]; if (dtDanhsach.Rows.Count > 0) { Utility.SetDataSourceForDataGridEx(grdResult, dtDanhsach, false, true, "1=1", ""); string reportcode = ""; string duongdan = ""; string codintion = ""; DataTable dt = new DataTable(); int idxRow = 0; int idxColSh = 0; var book = new C1XLBook(); XLSheet sheet = book.Sheets[0]; string getTime = ""; string pathDirectory = ""; switch (Args.Substring(0, 2)) { case "SA": reportcode = "baocao_thongkedanhsach_sieuam"; duongdan = Utility.GetPathExcel(reportcode); book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); sheet = book.Sheets[0]; dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_khoaphong"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["ket_qua"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; case "XQ": reportcode = "baocao_thongkedanhsach_xquang"; duongdan = Utility.GetPathExcel(reportcode); book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); sheet = book.Sheets[0]; dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_khoaphong"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["ket_qua"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; break; case "DT": break; case "NS": reportcode = "baocao_thongkedanhsach_noisoi"; duongdan = Utility.GetPathExcel(reportcode); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_khoaphong"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["ket_qua"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; case "PT": reportcode = "baocao_thongkedanhsach_pttt"; duongdan = Utility.GetPathExcel(reportcode); book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); sheet = book.Sheets[0]; dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["phuongphap_vocam"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["ngay_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["loai_phauthuat"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(dt.Rows[i]["bacsy_gayme"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; case "TT": reportcode = "baocao_thongkedanhsach_tt"; duongdan = Utility.GetPathExcel(reportcode); book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); sheet = book.Sheets[0]; dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["phuongphap_vocam"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["ngay_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["loai_phauthuat"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(dt.Rows[i]["bacsy_gayme"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; default: reportcode = "baocao_thongkedanhsach_tt"; duongdan = Utility.GetPathExcel(reportcode); book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); sheet = book.Sheets[0]; dt = dtDanhsach; idxRow = 7; idxColSh = 0; codintion = string.Format("Từ ngày {0} đến ngày {1}. Đối tượng: {2}", dtFromDate.Value.ToString("dd/MM/yyyy"), dtToDate.Value.ToString("dd/MM/yyyy"), cboDoituongKCB.Text); sheet[3, idxColSh].SetValue(Convert.ToString(codintion), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["nam_sinh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["gioi_tinh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["IsBHYT"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["ten_chitietdichvu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["phuongphap_vocam"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["ngay_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["loai_phauthuat"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(dt.Rows[i]["nguoi_thuchien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(dt.Rows[i]["bacsy_gayme"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(dt.Rows[i]["ghi_chu"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); break; } } else { Utility.ShowMsg("Không có dữ liệu để báo cáo!"); } // ExcelUtlity.ExportGridEx(grdResult); } catch (Exception exception) { Utility.ShowMsg("Lỗi:" + exception.Message); } }
protected void btnExport_Click(object sender, EventArgs e) { string building = Func.ParseString(Session["__BUILDINGID__"]); DbHelper.ExecuteNonQuery("Delete from BD_PaymentReportMonth Where BuildingId = '" + building + "' and substring(yearmonth,1,4) = '" + DateTime.Now.Year.ToString() + "'"); DataTable dtTable = new DataTable(); dtTable.Columns.Add("YearMonth", Type.GetType("System.String")); dtTable.Columns.Add("BuildingId", Type.GetType("System.String")); dtTable.Columns.Add("PaymentType", Type.GetType("System.String")); dtTable.Columns.Add("PaymentId", Type.GetType("System.String")); dtTable.Columns.Add("colNo", Type.GetType("System.String")); dtTable.Columns.Add("ItemLevel", Type.GetType("System.String")); dtTable.Columns.Add("ParentId", Type.GetType("System.String")); string buildingId = Func.ParseString(Session["__BUILDINGID__"]); string sqlTmp = "Select Name,id,ParentId,ItemLevel from BD_PaymentType Where delflag = '0' and BuildingId = '" + buildingId + "' "; sqlTmp += "Union "; sqlTmp += "Select Name,id,ParentId,ItemLevel from Mst_PaymentType"; DataTable dt = DbHelper.GetDataTable("Select * from (" + sqlTmp + ") A order by id"); foreach (DataRow dr in dt.Rows) { if (dr["ParentId"].ToString() == "") { int j = 1; ListItem item = new ListItem(); item.Text = dr["Name"].ToString(); item.Value = dr["Id"].ToString(); for (int k = 0; k < 13; k++) { string month = Func.ParseString(k).PadLeft(2, '0'); string yearmonthTmp = DateTime.Now.Year.ToString() + month; dtTable.Rows.Add(yearmonthTmp, building, item.Text, item.Value, k, dr["ItemLevel"].ToString(), dr["ParentId"].ToString()); } GetChildItems(dr["Id"].ToString(), dt, dtTable, j); } } using (SqlBulkCopy copy = new SqlBulkCopy(Gnt.Configuration.ApplicationConfiguration.ConnectionString)) { copy.DestinationTableName = "BD_PaymentReportMonth"; copy.BatchSize = 3000; copy.BulkCopyTimeout = 99999; copy.ColumnMappings.Add(0, "YearMonth"); copy.ColumnMappings.Add(1, "BuildingId"); copy.ColumnMappings.Add(2, "PaymentType"); copy.ColumnMappings.Add(3, "PaymentId"); copy.ColumnMappings.Add(4, "colNo"); copy.ColumnMappings.Add(5, "ItemLevel"); copy.ColumnMappings.Add(6, "ParentId"); copy.WriteToServer(dtTable); } using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString)) { con.Open(); using (SqlCommand cm = new SqlCommand("sp_PaymentMonthReport", con)) { try { cm.CommandType = CommandType.StoredProcedure; cm.Parameters.AddWithValue("@BuildingId", building); cm.Parameters.AddWithValue("@Year", drpYear.SelectedValue); cm.Parameters.AddWithValue("@Created", DateTime.Now.ToString("yyyyMMddHHmmss")); cm.Parameters.AddWithValue("@CreatedBy", Page.User.Identity.Name); cm.Parameters.AddWithValue("@Modified", DateTime.Now.ToString("yyyyMMddHHmmss")); cm.Parameters.AddWithValue("@ModifiedBy", Page.User.Identity.Name); cm.CommandTimeout = 9999; int ret = cm.ExecuteNonQuery(); } catch (Exception ex) { ApplicationLog.WriteError(ex); } finally { con.Close(); } } } DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT id,YearMonth,BuildingId,PaymentType,isnull(InVND,0) InVND,isnull(InUSD,0) InUSD,isnull(OutVND,0) OutVND,isnull(OutUSD,0) OutUSD,Created,CreatedBy,Modified,ModifiedBy,PaymentId,colNo,bold,ItemLevel,ParentId"; sql += " FROM BD_PaymentReportMonth "; sql += " WHERE BuildingId = '" + building + "' "; sql += " order by yearmonth, id"; 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(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BaoCaoThuChiThang.xlsx"); if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoThuChiThang")) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoThuChiThang")); } string strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoThuChiThang\BaoCaoThuChiThang" + strDT + ".xlsx"; string strFilePathExport = "Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/BaoCaoThuChiThang/BaoCaoThuChiThang" + strDT + ".xlsx"; string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); string sheet = "BaoCao"; XLSheet xlsSheet = xlbBook.Sheets[sheet]; xlsSheet[0, 2].Value = xlsSheet[0, 2].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + building + "'")); xlsSheet[0, 2].Value = xlsSheet[0, 2].Value.ToString().Replace("{%NAM_THANG%}", "NĂM " + drpYear.SelectedValue); int k = 5; int colData = 6; string bsId = ""; string[] alpha = "A. B. C. D. E. F. G. H. I. J. K. L. M. N. O. P. Q. R. S. T. U. V. W. X. Y. Z.".Split(' '); string[] alphaLevel2 = "I. II. III. IV. V. VI. VII. VIII. IX. X. XI. XII. XII. XIV.".Split(' '); string[] alphaLevel3 = "1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.".Split(' '); string[] alphaLevel4 = "a. b. c. d. e. f. g. h. i. j. k. l. m. n. o. p. q. r. s. t. u. v. w.".Split(' '); int level1 = -1; int level2 = -1; int level3 = -1; int level4 = -1; xlsSheet.Columns[1].Width = 300; xlsSheet.Columns[2].Width = 300; xlsSheet.Columns[3].Width = 300; xlsSheet.Columns[4].Width = 300; xlsSheet.Columns[5].Width = 300; int lastrow = 0; decimal inSumVND = 0; decimal outSumVND = 0; DataTable dtReport = ds.Tables[0]; foreach (DataRow rowType in dtReport.Rows) { string PaymentType = rowType["PaymentType"].ToString(); //string InVND = rowType["InVND"].ToString(); //string InUSD = rowType["InUSD"].ToString(); //string OutVND = rowType["OutVND"].ToString(); //string OutUSD = rowType["OutUSD"].ToString(); string PaymentId = rowType["PaymentId"].ToString(); int colNo = Func.ParseInt(rowType["colNo"].ToString()); string id = rowType["yearmonth"].ToString(); string ParentId = rowType["ParentId"].ToString(); string itemLevel = rowType["ItemLevel"].ToString(); //string PaymentId = rowType["PaymentId"].ToString(); //xlsSheet[2, j].Value = id; //xlsSheet[3, j].Value = Budget; //j += 2; XLStyle xlstStyleAll = new XLStyle(xlbBook); xlstStyleAll.WordWrap = false; xlstStyleAll.Font = new Font("", 8, FontStyle.Regular); xlstStyleAll.SetBorderColor(Color.Black); xlstStyleAll.BorderBottom = XLLineStyleEnum.Thin; xlstStyleAll.BorderTop = XLLineStyleEnum.Thin; xlstStyleAll.BorderLeft = XLLineStyleEnum.Thin; xlstStyleAll.BorderRight = XLLineStyleEnum.Thin; xlstStyleAll.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleLeft = new XLStyle(xlbBook); xlstStyleLeft.WordWrap = false; xlstStyleLeft.Font = new Font("", 8, FontStyle.Regular); xlstStyleLeft.SetBorderColor(Color.Black); xlstStyleLeft.BorderBottom = XLLineStyleEnum.Thin; xlstStyleLeft.BorderTop = XLLineStyleEnum.Thin; xlstStyleLeft.BorderLeft = XLLineStyleEnum.Thin; xlstStyleLeft.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleRight = new XLStyle(xlbBook); xlstStyleRight.WordWrap = false; xlstStyleRight.Font = new Font("", 8, FontStyle.Regular); xlstStyleRight.SetBorderColor(Color.Black); xlstStyleRight.BorderBottom = XLLineStyleEnum.Thin; xlstStyleRight.BorderTop = XLLineStyleEnum.Thin; xlstStyleRight.BorderRight = XLLineStyleEnum.Thin; xlstStyleRight.Format = "#,##0.00_);(#,##0.00)"; XLStyle xlstStyleMiddle = new XLStyle(xlbBook); xlstStyleMiddle.WordWrap = false; xlstStyleMiddle.Font = new Font("", 8, FontStyle.Regular); xlstStyleMiddle.SetBorderColor(Color.Black); xlstStyleMiddle.BorderBottom = XLLineStyleEnum.Thin; xlstStyleMiddle.BorderTop = XLLineStyleEnum.Thin; xlstStyleMiddle.Format = "#,##0.00_);(#,##0.00)"; xlsSheet[k, 2].Style = xlstStyleLeft; xlsSheet[k, 3].Style = xlstStyleMiddle; xlsSheet[k, 4].Style = xlstStyleMiddle; xlsSheet[k, 5].Style = xlstStyleMiddle; xlsSheet[k, 6].Style = xlstStyleRight; if (itemLevel.Equals("0")) { xlstStyleAll.BackColor = Color.Orange; xlstStyleLeft.BackColor = Color.Orange; xlstStyleRight.BackColor = Color.Orange; xlstStyleMiddle.BackColor = Color.Orange; } else { xlstStyleAll.BackColor = Color.White; xlstStyleLeft.BackColor = Color.White; xlstStyleRight.BackColor = Color.White; xlstStyleMiddle.BackColor = Color.White; } if (itemLevel.Equals("0") || itemLevel.Equals("1") || itemLevel.Equals("2")) { xlstStyleAll.Font = new Font("", 8, FontStyle.Bold); xlstStyleLeft.Font = new Font("", 8, FontStyle.Bold); xlstStyleRight.Font = new Font("", 8, FontStyle.Bold); xlstStyleMiddle.Font = new Font("", 8, FontStyle.Bold); } xlsSheet[k, colData].Style = xlstStyleAll; if (!bsId.Equals(id)) { if (k > 5) { lastrow = k; xlsSheet[k, 2].Value = alpha[level1 + 1]; xlsSheet[k, 3].Value = "CÂN ĐỐI THU - CHI (Phần Lãi)"; xlsSheet[k, colData].Value = Func.ParseDouble(inSumVND - outSumVND); } k = 5; colData++; bsId = id; level1 = -1; } int col = Func.ParseInt(itemLevel) + 3; if (itemLevel.Equals("0")) { level1++; xlsSheet[k, col - 1].Value = alpha[level1]; level2 = -1; } else if (itemLevel.Equals("1")) { level2++; xlsSheet[k, col - 1].Value = alphaLevel2[level2]; level3 = -1; } else if (itemLevel.Equals("2")) { level3++; xlsSheet[k, col - 1].Value = alphaLevel3[level3]; level4 = -1; } else if (itemLevel.Equals("3")) { level4++; xlsSheet[k, col - 1].Value = alphaLevel4[level4]; } xlsSheet[k, col].Value = PaymentType; xlsSheet[k, colData].Value = rowType["InVND"]; xlsSheet[k, 0].Value = PaymentId; if (PaymentId.Equals("9")) { inSumVND = Convert.ToDecimal(rowType["InVND"]); } else if (PaymentId.Equals("10")) { outSumVND = Convert.ToDecimal(rowType["InVND"]); } xlsSheet[k, colData].Style = xlstStyleAll; k++; if (k == lastrow) { XLStyle xlstStyleLast = new XLStyle(xlbBook); xlstStyleLast.WordWrap = false; xlstStyleLast.Font = new Font("", 8, FontStyle.Regular); xlstStyleLast.SetBorderColor(Color.Black); xlstStyleLast.BorderBottom = XLLineStyleEnum.Thin; xlstStyleLast.BorderTop = XLLineStyleEnum.Thin; xlstStyleLast.BorderLeft = XLLineStyleEnum.Thin; xlstStyleLast.BorderRight = XLLineStyleEnum.Thin; xlstStyleLast.Font = new Font("", 8, FontStyle.Bold); xlstStyleLast.BackColor = Color.Orange; xlstStyleLast.Format = "#,##0.00_);(#,##0.00)"; xlsSheet[k, colData].Value = inSumVND - outSumVND; xlsSheet[k, colData].Style = xlstStyleLast; } } xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } } } }
private void cboXuatTrenLuoi_Click(object sender, EventArgs e) { try { _dtData = SPs.BaoCaoChiDinhHangNgay(dtFromDate.Value, dtToDate.Value, Utility.Int16Dbnull(cboDoituongKCB.SelectedValue, -1), Utility.Int16Dbnull(cboTinhTrang.SelectedValue, -1)).GetDataSet(). Tables[0]; if (_dtData.Rows.Count > 0) { Utility.SetDataSourceForDataGridEx(grdList, _dtData, true, true, "1=1", ""); const string reportcode = "BAOCAO_HANGNGAY"; string duongdan = Utility.GetPathExcel(reportcode); var book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); XLSheet sheet = book.Sheets[0]; DataTable dt = _dtData; int idxRow = 5; int idxColSh = 0; string condition = string.Format("Từ ngày {0} đến {1} - Đối tượng : {2} - Trạng thái :{3} ", dtFromDate.Text, dtToDate.Text, cboDoituongKCB.SelectedIndex >= 0 ? Utility.sDbnull(cboDoituongKCB.Text) : "Tất cả", cboTinhTrang.SelectedIndex > 0 ? Utility.sDbnull(cboTinhTrang.Text) : "Tất cả"); sheet[3, idxColSh].SetValue(Convert.ToString(condition), HamDungChung.styleStringCenter(book)); int idx = 0; foreach (GridEXRow grdExRow in grdList.GetDataRows()) { if (idx == 0) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(grdExRow.Cells["DoiTuong"]), HamDungChung.styleStringLeft_Bold(book)); idxRow = idxRow + 1; } else { if (dt.Rows[idx]["DoiTuong"].ToString() != dt.Rows[idx - 1]["DoiTuong"].ToString()) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(grdExRow.Cells["DoiTuong"]), HamDungChung.styleStringLeft_Bold(book)); idxRow = idxRow + 1; } //if (dt.Rows[i]["DoiTuong"].ToString() == dt.Rows[i - 1]["DoiTuong"].ToString() && dt.Rows[i]["Ten_nhombaocao_dichvu"].ToString() != dt.Rows[i - 1]["Ten_nhombaocao_dichvu"].ToString()) //{ // sheet[idxRow, idxColSh].SetValue(string.Format("{0}.{1}", sttloaidichvu, Convert.ToString(dt.Rows[i]["Ten_nhombaocao_dichvu"])), HamDungChung.styleStringLeft_Bold(book)); // sttloaidichvu = sttloaidichvu + 1; // idxRow = idxRow + 1; //} } sheet[idxRow, idxColSh].SetValue(Convert.ToString(idx + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToInt64(grdExRow.Cells["id_benhnhan"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(grdExRow.Cells["ma_luotkham"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(grdExRow.Cells["ten_benhnhan"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(grdExRow.Cells["nam_sinh"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(grdExRow.Cells["gioitinh"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(grdExRow.Cells["mathe_bhyt"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(grdExRow.Cells["gt_the_tu"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(grdExRow.Cells["gt_the_den"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(grdExRow.Cells["dia_chi"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(grdExRow.Cells["mabenh_chinh"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(grdExRow.Cells["mabenh_phu"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(grdExRow.Cells["ma_kcbbd"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(grdExRow.Cells["ngay_vao"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(grdExRow.Cells["ngay_ra"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 15].SetValue(Convert.ToDecimal(grdExRow.Cells["tong_tien"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 16].SetValue(Convert.ToDecimal(grdExRow.Cells["t_bhyt_chitra"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 17].SetValue(Convert.ToDecimal(grdExRow.Cells["t_bnhan_chitra"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 18].SetValue(Convert.ToString(grdExRow.Cells["loai_kcb"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 19].SetValue(Convert.ToString(grdExRow.Cells["loai_dichvu"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 20].SetValue(Convert.ToString(grdExRow.Cells["ma_dichvu"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 21].SetValue(Convert.ToString(grdExRow.Cells["ten_dichvu"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 22].SetValue(Convert.ToDecimal(grdExRow.Cells["so_luong"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 23].SetValue(Convert.ToDecimal(grdExRow.Cells["don_gia"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 24].SetValue(Convert.ToDecimal(grdExRow.Cells["thanh_tien"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 25].SetValue(Convert.ToDecimal(grdExRow.Cells["bhyt_chitra"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 26].SetValue(Convert.ToDecimal(grdExRow.Cells["bnhan_chitra"].Value), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 27].SetValue(Convert.ToString(grdExRow.Cells["ngay_thanhtoan"].Value), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 28].SetValue(Convert.ToString(grdExRow.Cells["ten_dung_tuyen"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 29].SetValue(Convert.ToString(grdExRow.Cells["DoiTuong"]), HamDungChung.styleStringLeft(book)); idx++; idxRow = idxRow + 1; } // vị trí dòng dữ liệu của table tiếp theo, vị trí cột bắt đầu t? 0 string getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); string pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); } else { Utility.ShowMsg("Không có dữ liệu để báo cáo!"); } } catch (Exception ex) { Utility.ShowMsg("Lỗi: " + ex.Message); } }
protected void btnExport_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT *"; sql += " FROM Report_BuildingInfo where id = 43"; 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.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 fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\LamNgoaiGio.xlsx"); 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__"]) + @"\LamNgoaiGio" + strDT + ".xlsx"; string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/LamNgoaiGio" + 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); DataTable dt = ds.Tables[0]; foreach (DataRow rowType in dt.Rows) { int stt = 0; string id = rowType["id"].ToString(); string sheet = "Report"; int NumOfCol = Func.ParseInt(rowType["NoOfColumn"].ToString()); string SqlSelect = rowType["SqlSelect"].ToString(); SqlSelect = SqlSelect.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()); 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 = ++stt; for (int k = 0; k < NumOfCol; k++) { //string tmp = rowSheet[k].ToString(); //switch (rowSheet[k].GetType().Name) //{ // case "Decimal": // xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseDouble(tmp); // break; // case "Double": // xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseDouble(tmp); // break; // case "Int32": // xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseInt(tmp); // break; // case "Single": // xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseInt(tmp); // break; // default: // xlsSheet[CellY + stt - 1, CellX + k + 1].Value = tmp; // break; //} //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = tmp; xlsSheet[CellY + stt - 1, CellX + k + 1].Value = rowSheet[k]; xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyle; } } } } //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); //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") + ".xlsx"; //string fileName = Path.Combine(tmpFolder, name); // string fileNameDes = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl_1.xlsxx"); 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) { string yearmonth = drpYear.SelectedValue; string building = Func.ParseString(Session["__BUILDINGID__"]); DataSet ds = new DataSet(); string sql = string.Empty; sql = " SELECT *"; sql += " FROM BD_BudgetSchedule "; sql += " WHERE BuildingId = '" + building + "' "; sql += " and YearMonth = '" + yearmonth + "' "; sql += drpBudgetExport.SelectedValue.Equals("") ? "" : " and id ='" + drpBudgetExport.SelectedValue + "'"; sql += " and DelFlag = 0 Order by id"; using (SqlDatabase db = new SqlDatabase()) { C1XLBook xlbBook = new C1XLBook(); string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\NganSach.xlsx"); 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__"]) + @"\NganSach" + strDT + ".xlsx"; string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/NganSach" + 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); string sheet = "NganSach"; XLSheet xlsSheet = xlbBook.Sheets[sheet]; string IDs = ""; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { xlsSheet[0, 2].Value = xlsSheet[0, 2].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + building + "'")); xlsSheet[0, 2].Value = xlsSheet[0, 2].Value.ToString().Replace("{%NAM_THANG%}", "NĂM " + yearmonth); int j = 7; DataTable dtReport = ds.Tables[0]; foreach (DataRow rowType in dtReport.Rows) { string Budget = rowType["Budget"].ToString(); string id = rowType["id"].ToString(); IDs += ",'" + id + "'"; xlsSheet[2, j].Value = id; xlsSheet[3, j].Value = Budget; j++; } for (int i = j; i < j * 12; i++) { XLColumn col = new XLColumn(); col = xlsSheet.Columns[j]; xlsSheet.Columns.Remove(col); } } } if (String.IsNullOrEmpty(IDs)) { mvMessage.AddError("Hiện tại chưa có Kỳ ngân sách nào được tạo"); return; } string buildingId = Func.ParseString(Session["__BUILDINGID__"]); string sessionId = Session.SessionID; DbHelper.ExecuteNonQuery("Delete From BD_BudgetScheduleDetailReport where SessionId = '" + sessionId + "'"); string[] idList = IDs.Substring(1).Split(','); for (int m = 0; m < idList.Length; m++) { string sqlTmp = "Select * from BD_BudgetScheduleDetail where BuggetScheduleId in (" + idList[m] + ") and delFlag = 0 Order by Id"; DataTable dtTable = new DataTable(); dtTable.Columns.Add("SessionId", Type.GetType("System.String")); dtTable.Columns.Add("BuggetScheduleId", Type.GetType("System.Int32")); dtTable.Columns.Add("PaymentType", Type.GetType("System.String")); dtTable.Columns.Add("PaymentId", Type.GetType("System.Int32")); dtTable.Columns.Add("ParentId", Type.GetType("System.Int32")); dtTable.Columns.Add("InVND", Type.GetType("System.Double")); dtTable.Columns.Add("InUSD", Type.GetType("System.Decimal")); dtTable.Columns.Add("OutVND", Type.GetType("System.Double")); dtTable.Columns.Add("OutUSD", Type.GetType("System.Decimal")); dtTable.Columns.Add("ItemLevel", Type.GetType("System.String")); DataTable dt = DbHelper.GetDataTable(sqlTmp); foreach (DataRow dr in dt.Rows) { if (dr["ParentId"].ToString() == "0") { int j = 1; int BuggetScheduleId = Func.ParseInt(dr["BuggetScheduleId"]); string PaymentType = dr["PaymentType"].ToString(); int PaymentId = Func.ParseInt(dr["PaymentId"]); int ParentId = Func.ParseInt(dr["ParentId"]); double InVND = Func.ParseDouble(dr["InVND"]); decimal InUSD = Func.ParseInt(dr["InUSD"]); double OutVND = Func.ParseDouble(dr["OutVND"]); decimal OutUSD = Func.ParseInt(dr["OutUSD"]); string itemLevel = Func.ParseString(dr["itemLevel"]); dtTable.Rows.Add(sessionId, BuggetScheduleId, PaymentType, PaymentId, ParentId, InVND, InUSD, OutVND, OutUSD, itemLevel); GetChildItems(Func.ParseString(PaymentId), dt, dtTable, j); } } using (SqlBulkCopy copy = new SqlBulkCopy(Gnt.Configuration.ApplicationConfiguration.ConnectionString)) { copy.DestinationTableName = "BD_BudgetScheduleDetailReport"; copy.BatchSize = 3000; copy.BulkCopyTimeout = 99999; copy.ColumnMappings.Add(0, "SessionId"); copy.ColumnMappings.Add(1, "BuggetScheduleId"); copy.ColumnMappings.Add(2, "PaymentType"); copy.ColumnMappings.Add(3, "PaymentId"); copy.ColumnMappings.Add(4, "ParentId"); copy.ColumnMappings.Add(5, "InVND"); copy.ColumnMappings.Add(6, "InUSD"); copy.ColumnMappings.Add(7, "OutVND"); copy.ColumnMappings.Add(8, "OutUSD"); copy.ColumnMappings.Add(9, "ItemLevel"); copy.WriteToServer(dtTable); } } ds = new DataSet(); sql = "Select * from BD_BudgetScheduleDetailReport where SessionId = '" + sessionId + "' Order by BuggetScheduleId,Id"; int k = 5; int colData = 6; string bsId = ""; string[] alpha = "A. B. C. D. E. F. G. H. I. J. K. L. M. N. O. P. Q. R. S. T. U. V. W. X. Y. Z.".Split(' '); string[] alphaLevel2 = "I. II. III. IV. V. VI. VII. VIII. IX. X. XI. XII. XII. XIV.".Split(' '); string[] alphaLevel3 = "1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.".Split(' '); string[] alphaLevel4 = "a. b. c. d. e. f. g. h. i. j. k. l. m. n. o. p. q. r. s. t. u. v. w.".Split(' '); int level1 = -1; int level2 = -1; int level3 = -1; int level4 = -1; xlsSheet.Columns[1].Width = 300; xlsSheet.Columns[2].Width = 300; xlsSheet.Columns[3].Width = 300; xlsSheet.Columns[4].Width = 300; xlsSheet.Columns[5].Width = 300; int lastrow = 0; using (SqlCommand cm = db.CreateCommand(sql)) { SqlDataAdapter da = new SqlDataAdapter(cm); da.Fill(ds); if (ds != null) { double inSumVND = 0; double outSumVND = 0; DataTable dtReport = ds.Tables[0]; foreach (DataRow rowType in dtReport.Rows) { XLStyle xlstStyleAll = new XLStyle(xlbBook); //xlstStyleAll.AlignHorz = XLAlignHorzEnum.Left; xlstStyleAll.WordWrap = false; xlstStyleAll.Font = new Font("", 8, FontStyle.Regular); xlstStyleAll.SetBorderColor(Color.Black); xlstStyleAll.BorderBottom = XLLineStyleEnum.Thin; xlstStyleAll.BorderTop = XLLineStyleEnum.Thin; xlstStyleAll.BorderLeft = XLLineStyleEnum.Thin; xlstStyleAll.BorderRight = XLLineStyleEnum.Thin; XLStyle xlstStyleLeft = new XLStyle(xlbBook); //xlstStyleLeft.AlignHorz = XLAlignHorzEnum.Left; xlstStyleLeft.WordWrap = false; xlstStyleLeft.Font = new Font("", 8, FontStyle.Regular); xlstStyleLeft.SetBorderColor(Color.Black); xlstStyleLeft.BorderBottom = XLLineStyleEnum.Thin; xlstStyleLeft.BorderTop = XLLineStyleEnum.Thin; xlstStyleLeft.BorderLeft = XLLineStyleEnum.Thin; XLStyle xlstStyleRight = new XLStyle(xlbBook); //xlstStyleRight.AlignHorz = XLAlignHorzEnum.Left; xlstStyleRight.WordWrap = false; xlstStyleRight.Font = new Font("", 8, FontStyle.Regular); xlstStyleRight.SetBorderColor(Color.Black); xlstStyleRight.BorderBottom = XLLineStyleEnum.Thin; xlstStyleRight.BorderTop = XLLineStyleEnum.Thin; xlstStyleRight.BorderRight = XLLineStyleEnum.Thin; XLStyle xlstStyleMiddle = new XLStyle(xlbBook); //xlstStyleMiddle.AlignHorz = XLAlignHorzEnum.Left; xlstStyleMiddle.WordWrap = false; xlstStyleMiddle.Font = new Font("", 8, FontStyle.Regular); xlstStyleMiddle.SetBorderColor(Color.Black); xlstStyleMiddle.BorderBottom = XLLineStyleEnum.Thin; xlstStyleMiddle.BorderTop = XLLineStyleEnum.Thin; xlsSheet[k, 2].Style = xlstStyleLeft; xlsSheet[k, 3].Style = xlstStyleMiddle; xlsSheet[k, 4].Style = xlstStyleMiddle; xlsSheet[k, 5].Style = xlstStyleMiddle; xlsSheet[k, 6].Style = xlstStyleRight; string PaymentType = rowType["PaymentType"].ToString(); string InVND = rowType["InVND"].ToString(); string InUSD = rowType["InUSD"].ToString(); string OutVND = rowType["OutVND"].ToString(); string OutUSD = rowType["OutUSD"].ToString(); string PaymentId = rowType["PaymentId"].ToString(); int colNo = Func.ParseInt(rowType["colNo"].ToString()); string id = rowType["BuggetScheduleId"].ToString(); string ParentId = rowType["ParentId"].ToString(); string itemLevel = rowType["ItemLevel"].ToString(); if (itemLevel.Equals("0")) { xlstStyleAll.BackColor = Color.Orange; xlstStyleLeft.BackColor = Color.Orange; xlstStyleRight.BackColor = Color.Orange; xlstStyleMiddle.BackColor = Color.Orange; } else { xlstStyleAll.BackColor = Color.White; xlstStyleLeft.BackColor = Color.White; xlstStyleRight.BackColor = Color.White; xlstStyleMiddle.BackColor = Color.White; } if (itemLevel.Equals("0") || itemLevel.Equals("1") || itemLevel.Equals("2")) { xlstStyleAll.Font = new Font("", 8, FontStyle.Bold); xlstStyleLeft.Font = new Font("", 8, FontStyle.Bold); xlstStyleRight.Font = new Font("", 8, FontStyle.Bold); xlstStyleMiddle.Font = new Font("", 8, FontStyle.Bold); } xlsSheet[k, colData].Style = xlstStyleAll; //j += 2; if (!bsId.Equals(id)) { if (k > 5) { lastrow = k; xlsSheet[k, 2].Value = alpha[level1+1]; xlsSheet[k, 3].Value = "CÂN ĐỐI THU - CHI (Phần Lãi)"; //xlsSheet[k, colData + 1].Value = Func.ParseDouble(InUSD); xlsSheet[k, colData].Value = Func.ParseDouble(inSumVND - outSumVND); } k = 5; colData++; bsId = id; level1 = -1; } int col = Func.ParseInt(itemLevel) + 3; if (itemLevel.Equals("0")) { level1++; xlsSheet[k, col - 1].Value = alpha[level1]; level2 = -1; } else if (itemLevel.Equals("1")) { level2++; xlsSheet[k, col - 1].Value = alphaLevel2[level2]; level3 = -1; } else if (itemLevel.Equals("2")) { level3++; xlsSheet[k, col - 1].Value = alphaLevel3[level3]; level4 = -1; } else if (itemLevel.Equals("3")) { level4++; xlsSheet[k, col - 1].Value = alphaLevel4[level4]; } xlsSheet[k, col].Value = PaymentType; //xlsSheet[k, colData + 1].Value = Func.ParseDouble(InUSD); xlsSheet[k, colData].Value = Func.ParseDouble(InVND); ////xlsSheet[k, colData + 3].Value = Func.ParseDouble(OutUSD); ////xlsSheet[k, colData + 4].Value = Func.ParseDouble(OutVND); xlsSheet[k, 0].Value = PaymentId; if (PaymentId.Equals("9")) { inSumVND = Func.ParseDouble(InVND); } else if (PaymentId.Equals("10")) { outSumVND = Func.ParseDouble(InVND); } //XLStyle xlstStyleAll = new XLStyle(xlbBook); //xlstStyleAll.AlignHorz = XLAlignHorzEnum.Left; //xlstStyleAll.WordWrap = false; //xlstStyleAll.Font = new Font("", 8, FontStyle.Regular); //xlstStyleAll.SetBorderColor(Color.Black); //xlstStyleAll.BorderBottom = XLLineStyleEnum.Thin; //xlstStyleAll.BorderTop = XLLineStyleEnum.Thin; //xlstStyleAll.BorderLeft = XLLineStyleEnum.Thin; //xlstStyleAll.BorderRight = XLLineStyleEnum.Thin; //XLStyle xlstStyleLeft = new XLStyle(xlbBook); //xlstStyleLeft.AlignHorz = XLAlignHorzEnum.Left; //xlstStyleLeft.WordWrap = false; //xlstStyleLeft.Font = new Font("", 8, FontStyle.Regular); //xlstStyleLeft.SetBorderColor(Color.Black); //xlstStyleLeft.BorderBottom = XLLineStyleEnum.Thin; //xlstStyleLeft.BorderTop = XLLineStyleEnum.Thin; //xlstStyleLeft.BorderLeft = XLLineStyleEnum.Thin; //XLStyle xlstStyleRight = new XLStyle(xlbBook); //xlstStyleRight.AlignHorz = XLAlignHorzEnum.Left; //xlstStyleRight.WordWrap = false; //xlstStyleRight.Font = new Font("", 8, FontStyle.Regular); //xlstStyleRight.SetBorderColor(Color.Black); //xlstStyleRight.BorderBottom = XLLineStyleEnum.Thin; //xlstStyleRight.BorderTop = XLLineStyleEnum.Thin; //xlstStyleRight.BorderRight = XLLineStyleEnum.Thin; //XLStyle xlstStyleMiddle = new XLStyle(xlbBook); //xlstStyleMiddle.AlignHorz = XLAlignHorzEnum.Left; //xlstStyleMiddle.WordWrap = false; //xlstStyleMiddle.Font = new Font("", 8, FontStyle.Regular); //xlstStyleMiddle.SetBorderColor(Color.Black); //xlstStyleMiddle.BorderBottom = XLLineStyleEnum.Thin; //xlstStyleMiddle.BorderTop = XLLineStyleEnum.Thin; //xlsSheet[k, 2].Style = xlstStyleLeft; //xlsSheet[k, 3].Style = xlstStyleMiddle; //xlsSheet[k, 4].Style = xlstStyleMiddle; //xlsSheet[k, 5].Style = xlstStyleMiddle; //xlsSheet[k, 6].Style = xlstStyleRight; //if (itemLevel.Equals("0")) //{ // xlstStyleAll.BackColor = Color.Orange; // xlstStyleLeft.BackColor = Color.Orange; // xlstStyleRight.BackColor = Color.Orange; // xlstStyleMiddle.BackColor = Color.Orange; //} //else //{ // xlstStyleAll.BackColor = Color.White; // xlstStyleLeft.BackColor = Color.White; // xlstStyleRight.BackColor = Color.White; // xlstStyleMiddle.BackColor = Color.White; //} //if (itemLevel.Equals("0") || itemLevel.Equals("1") || itemLevel.Equals("2")) //{ // xlstStyleAll.Font = new Font("", 8, FontStyle.Bold); // xlstStyleLeft.Font = new Font("", 8, FontStyle.Bold); // xlstStyleRight.Font = new Font("", 8, FontStyle.Bold); // xlstStyleMiddle.Font = new Font("", 8, FontStyle.Bold); //} xlsSheet[k, colData].Style = xlstStyleAll; k++; if (k == lastrow) { XLStyle xlstStyleLast = new XLStyle(xlbBook); xlstStyleLast.WordWrap = false; xlstStyleLast.Font = new Font("", 8, FontStyle.Regular); xlstStyleLast.SetBorderColor(Color.Black); xlstStyleLast.BorderBottom = XLLineStyleEnum.Thin; xlstStyleLast.BorderTop = XLLineStyleEnum.Thin; xlstStyleLast.BorderLeft = XLLineStyleEnum.Thin; xlstStyleLast.BorderRight = XLLineStyleEnum.Thin; xlstStyleLast.Font = new Font("", 8, FontStyle.Bold); xlstStyleLast.BackColor = Color.Orange; xlsSheet[k, colData].Value = Func.ParseDouble(inSumVND - outSumVND); xlsSheet[k, colData].Style = xlstStyleLast; } } } } //ds = new DataSet(); //sql = string.Empty; //sql = " SELECT *"; //sql += " FROM BD_PaymentReportMonth "; //sql += " WHERE BuildingId = '" + building + "' "; //sql += " and YearMonth = '" + yearmonth + "' order by id"; //using (db = new SqlDatabase()) //{ // using (SqlCommand cm = db.CreateCommand(sql)) // { // SqlDataAdapter da = new SqlDataAdapter(cm); // da.Fill(ds); // if (ds != null) // { // xlbBook = new C1XLBook(); // fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BaoCaoThuChiThang.xlsx"); // if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))) // { // Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]))); // } // strDT = DateTime.Now.ToString("yyyyMMddHHmmss"); // strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoThuChiThang" + strDT + ".xlsx"; // strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/BaoCaoThuChiThang" + strDT + ".xlsx"; // 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); // sheet = "BaoCao"; // xlsSheet = xlbBook.Sheets[sheet]; // int i = 5; // xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + building + "'")); // xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%NAM_THANG%}", "THÁNG" + yearmonth.Substring(4, 2) + "/" + yearmonth.Substring(0, 4)); // DataTable dtReport = ds.Tables[0]; // foreach (DataRow rowType in dtReport.Rows) // { // int colNo = Func.ParseInt(rowType["colNo"]); // string PaymentType = rowType["PaymentType"].ToString(); // string InVND = rowType["InVND"].ToString(); // string InUSD = rowType["InUSD"].ToString(); // string OutVND = rowType["OutVND"].ToString(); // string OutUSD = rowType["OutUSD"].ToString(); // bool bold = rowType["bold"].ToString().Equals("1") ? true : false; // XLCellRange mrCell = new XLCellRange(i, i, 0, 3); // xlsSheet.MergedCells.Add(mrCell); // xlsSheet[i, 0].Value = "." + " ".PadLeft(colNo * 3, ' ') + PaymentType; // xlsSheet[i, 4].Value = Func.ParseDouble(InUSD); // xlsSheet[i, 5].Value = Func.ParseDouble(InVND); // xlsSheet[i, 6].Value = Func.ParseDouble(OutUSD); // xlsSheet[i, 7].Value = Func.ParseDouble(OutVND); // XLStyle xlstStyle = new XLStyle(xlbBook); // xlstStyle.AlignHorz = XLAlignHorzEnum.Left; // xlstStyle.WordWrap = false; // 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; // xlsSheet[i, 0].Style = xlstStyle; // xlsSheet[i, 1].Style = xlstStyle; // xlsSheet[i, 2].Style = xlstStyle; // xlsSheet[i, 3].Style = xlstStyle; // xlstStyle = new XLStyle(xlbBook); // xlstStyle.WordWrap = false; // 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.AlignHorz = XLAlignHorzEnum.Center; // xlsSheet[i, 4].Style = xlstStyle; // xlsSheet[i, 5].Style = xlstStyle; // xlsSheet[i, 6].Style = xlstStyle; // xlsSheet[i, 7].Style = xlstStyle; // i++; // } // xlbBook.Save(fileNameDes); // ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); // } // } //} xlbBook.Save(fileNameDes); ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true); } }
/// <summary> /// hàm thực iheenj viecj /// export to excel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdExportToExcel_Click(object sender, EventArgs e) { try { try { _dtData = SPs.ThuocSotonghopthuocHangngay(dtFromDate.Value, dtToDate.Value, Utility.Int16Dbnull(cboStock.SelectedValue, -1), Utility.Int16Dbnull(cboDoiTuong.SelectedValue, -1), Utility.Int16Dbnull(cbotinhtrang.SelectedValue, -1), "").GetDataSet(). Tables[0]; if (_dtData.Rows.Count > 0) { Utility.SetDataSourceForDataGridEx(grdList, _dtData, true, true, "1=1", ""); const string reportcode = "thuoc_sotonghop_hangngay"; string duongdan = Utility.GetPathExcel(reportcode); var book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); XLSheet sheet = book.Sheets[0]; DataTable dt = _dtData; int idxRow = 6; int idxColSh = 0; string condition = string.Format("Từ ngày {0} đến {1} - Đối tượng : {2} - Tình trạng :{3}", dtFromDate.Text, dtToDate.Text, cboDoiTuong.SelectedIndex >= 0 ? Utility.sDbnull(cboDoiTuong.Text) : "Tất cả", cbotinhtrang.SelectedIndex > 0 ? Utility.sDbnull(cbotinhtrang.Text) : "Tất cả"); const int idxRowT = 5; const int idxColShT = 0; //sheet[5, 0].SetValue("STT", HamDungChung.styleStringCenter(book)); //sheet[5, 1].SetValue("HỌ TÊN NGƯỜI BỆNH", HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Columns.Count; i++) { if (Utility.sDbnull(dt.Columns[i].ColumnName) == "ten_benhnhan") { sheet[idxRowT, idxColShT + i].SetValue(Utility.sDbnull("HỌ TÊN NGƯỜI BỆNH"), HamDungChung.styleStringCenter_Bold(book)); } sheet[idxRowT, idxColShT + i].SetValue(Utility.sDbnull(dt.Columns[i].ColumnName), HamDungChung.styleStringCenter_Bold(book)); if (i >= 2) { sheet[idxRowT, idxColShT + i].SetValue(Utility.sDbnull(dt.Columns[i].ColumnName), HamDungChung.styleStringCenter_Rotate(book)); } } //sheet[3, idxColSh].SetValue(Convert.ToString(condition), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); for (int j = 2; j < dt.Columns.Count; j++) { sheet[idxRow, idxColSh + j].SetValue(Convert.ToString(dt.Rows[i][dt.Columns[j].ColumnName]), HamDungChung.styleNumber(book)); } idxRow = idxRow + 1; } // vị trí dòng dữ liệu của table tiếp theo, vị trí cột bắt đầu t? 0 string getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); string pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); } else { Utility.ShowMsg("Không có dữ liệu để báo cáo!"); } } catch (Exception ex) { Utility.ShowMsg("Lỗi: " + ex.Message); } //Janus.Windows.GridEX.GridEXRow[] gridExRows = grdList.GetCheckedRows(); //if (grdList.RowCount <= 0) //{ // Utility.ShowMsg("Không có dữ liệu", "Thông báo"); // grdList.Focus(); // return; //} //saveFileDialog1.Filter = "Excel File(*.xls)|*.xls"; //saveFileDialog1.FileName = string.Format("{0}.xls", baocaO_TIEUDE1.TIEUDE); ////saveFileDialog1.ShowDialog(); //if (saveFileDialog1.ShowDialog() == DialogResult.OK) //{ // string sPath = saveFileDialog1.FileName; // FileStream fs = new FileStream(sPath, FileMode.Create); // fs.CanWrite.CompareTo(true); // fs.CanRead.CompareTo(true); // gridEXExporter1.Export(fs); // fs.Dispose(); //} //saveFileDialog1.Dispose(); //saveFileDialog1.Reset(); } catch (Exception exception) { } }
public void RPT2(C1XLBook book, C1.Win.C1FlexGrid.C1FlexGrid vs, string title, string filename) { //string ID="RPT1"; book = new C1XLBook(); XLSheet sheet = book.Sheets[0]; FormatExcel.Init_Excel(sheet); sheet.Name = "Sheet1"; XLStyle Title = FormatExcel.Get_Style(book, 16, true, XLAlignVertEnum.Center, XLAlignHorzEnum.Center, true, false, ""); XLStyle Caption = FormatExcel.Get_Style(book, 10, true, XLAlignVertEnum.Center, XLAlignHorzEnum.Center, true, true, ""); XLStyle StringN = FormatExcel.Get_Style(book, 10, false, XLAlignVertEnum.Undefined, XLAlignHorzEnum.Undefined, false, false, ""); XLStyle String = FormatExcel.Get_Style(book, 10, false, XLAlignVertEnum.Undefined, XLAlignHorzEnum.Undefined, false, true, ""); XLStyle Number = FormatExcel.Get_Style(book, 10, false, XLAlignVertEnum.Undefined, XLAlignHorzEnum.Undefined, false, true, "#,##0.00"); sheet.Columns[0].Width = 500; int r = 0, cols = 0; ArrayList a = new ArrayList(); for (int i = 0; i < vs.Cols.Count; i++) { if (vs.Cols[i].Visible == true) { cols++; a.Add(i); } } sheet.MergedCells.Add(r, 0, 1, cols); sheet.Rows[r].Height = 800; FormatExcel.Set_Cell(sheet[r, 0], T_String.GetDataFromSQL("COM_N1", "FILA01A"), Title); r++; sheet.MergedCells.Add(r, 0, 1, cols); sheet.Rows[r].Height = 800; FormatExcel.Set_Cell(sheet[r, 0], title, Title); r++; FormatExcel.Set_Cell(sheet[r, cols - 6], PublicFunction.L_Get_RPT("RptTa", 1) + ":" + PublicFunction.A_UserID, StringN); r++; FormatExcel.Set_Cell(sheet[r, cols - 6], PublicFunction.L_Get_RPT("RptTa", 2) + ":" + T_String.GetDate().ToString("yyyy/MM/dd HH:mm"), StringN); r++; for (int j = 0; j < vs.Rows.Count; j++) { for (int i = 0; i < a.Count; i++) { if (j == 0) { FormatExcel.Set_Cell(sheet[r, i], vs.Rows[j][(int)a[i]] + "", Caption); } else { if (vs.Cols[(int)a[i]].DataType == typeof(DateTime)) { try { FormatExcel.Set_Cell(sheet[r, i], DateTime.Parse(vs.Rows[j][(int)a[i]] + "").ToString(vs.Cols[(int)a[i]].Format), String); sheet.Columns[i].Width = 1500; } catch { FormatExcel.Set_Cell(sheet[r, i], "", String); } } else { if (vs.Cols[(int)a[i]].DataType == typeof(Boolean)) { if (vs.GetDataDisplay(j, (int)a[i]) + "" != "True") { FormatExcel.Set_Cell(sheet[r, i], "False", String); } else { FormatExcel.Set_Cell(sheet[r, i], "True", String); } } else { if (vs.Cols[(int)a[i]].DataType == typeof(String)) { FormatExcel.Set_Cell(sheet[r, i], vs.GetDataDisplay(j, (int)a[i]) + "", String); } else { // FormatExcel.Set_Cell(sheet[r,i],"",String); // sheet[r,i].Value= T_String.IsNullTo00(vs.GetDataDisplay(j,(int)a[i])); FormatExcel.Set_Cell(sheet[r, i], vs.GetDataDisplay(j, (int)a[i]) + "", String); } //FormatExcel.Set_Cell(sheet[r,i], vs.GetDataDisplay(j,(int)a[i])+"",Number); } } } } r++; } sheet.Columns[1].Width = 1200; sheet.Columns[2].Width = 1000; sheet.Columns[3].Width = 3000; try { string fileName = Application.StartupPath + @"\\Reports\\" + filename + ".xls"; book.Save(fileName); System.Diagnostics.Process.Start(fileName); } catch { MessageBox.Show("You must close " + filename + ".xls file first!!!!!"); return; } }
/// <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); } } } }
public void RPTta(C1XLBook book, string RPT_ID, string title, string wh) { //string ID="RPT1"; book = new C1XLBook(); XLSheet sheet = book.Sheets[0]; FormatExcel.Init_Excel(sheet); sheet.Name = "Sheet1"; XLStyle Title = FormatExcel.Get_Style(book, 16, true, XLAlignVertEnum.Center, XLAlignHorzEnum.Center, true, false, ""); XLStyle Caption = FormatExcel.Get_Style(book, 10, true, XLAlignVertEnum.Center, XLAlignHorzEnum.Center, true, true, ""); XLStyle StringN = FormatExcel.Get_Style(book, 10, false, XLAlignVertEnum.Undefined, XLAlignHorzEnum.Undefined, false, false, ""); XLStyle String = FormatExcel.Get_Style(book, 10, false, XLAlignVertEnum.Undefined, XLAlignHorzEnum.Undefined, false, true, ""); XLStyle INT = FormatExcel.Get_Style(book, 10, false, XLAlignVertEnum.Undefined, XLAlignHorzEnum.Undefined, false, true, "#,###"); XLStyle GIO = FormatExcel.Get_Style(book, 10, false, XLAlignVertEnum.Undefined, XLAlignHorzEnum.Undefined, false, true, "#,###"); XLStyle DOU = FormatExcel.Get_Style(book, 10, false, XLAlignVertEnum.Undefined, XLAlignHorzEnum.Undefined, false, true, "#,###.##"); string sql = ""; sql = "Select * from FILE07B where RPT_ID=N'" + RPT_ID + "' and SHO_BT=1 ORDER BY SEQ_NO"; Func.RecordSet rscon = new Func.RecordSet(sql, PublicFunction.C_con); sql = GET_SQL(rscon, wh); Func.RecordSet rs = new RecordSet(sql, PublicFunction.C_con); try { if (rs.rows <= 0) { return; } } catch { return; } int r = 0, cols = 0; ArrayList a = new ArrayList(); a.Add(0); sheet.Columns[0].Width = 680; for (int i = 0; i < rs.cols; i++) { cols++; a.Add(i); } // tieu de sheet.MergedCells.Add(r, 0, 1, cols); sheet.Rows[r].Height = 800; FormatExcel.Set_Cell(sheet[r, 0], T_String.GetDataFromSQL("COM_N1", "FILA01A"), Title); r++; sheet.MergedCells.Add(r, 0, 1, cols); sheet.Rows[r].Height = 800; FormatExcel.Set_Cell(sheet[r, 0], title, Title); r++; FormatExcel.Set_Cell(sheet[r, cols - 2], PublicFunction.L_Get_RPT("RptTa", 1) + ":" + PublicFunction.A_UserID, StringN); r++; FormatExcel.Set_Cell(sheet[r, cols - 2], PublicFunction.L_Get_RPT("RptTa", 2) + ":" + T_String.GetDate().ToString("yyyy/MM/dd HH:mm"), StringN); r++; FormatExcel.Set_Cell(sheet[r, 0], "STT", Caption); for (int i = 0; i < rscon.rows; i++) { FormatExcel.Set_Cell(sheet[r, i + 1], rscon.record(i, "COL_NM"), Caption); sheet.Columns[i + 1].Width = T_String.IsNullTo0(rscon.record(i, "WID_VL")) * 17; } r++; // for (int i = 0; i < rs.rows; i++) { FormatExcel.Set_Cell(sheet[r, 0], i + 1 + "", INT); for (int c = 0; c < rscon.rows; c++) { int c1 = c + 1; switch (rscon.record(c, "TYP_ID") + "") { case "1": // DateTime { try { FormatExcel.Set_Cell(sheet[r, c1], DateTime.Parse(rs.record(i, c) + "").ToString("yyyy/MM/dd"), String); } catch { FormatExcel.Set_Cell(sheet[r, c1], "", String); } break; } case "2": // boolean { if (rs.record(i, c) + "" != "True") { FormatExcel.Set_Cell(sheet[r, c1], "False", String); } else { FormatExcel.Set_Cell(sheet[r, c1], "True", String); } break; } case "": { FormatExcel.Set_Cell(sheet[r, c1], rs.record(i, c), String); break; } case "3": // 00:00 { FormatExcel.Set_Cell(sheet[r, c1], T_String.IsNullTo00(rs.record(i, c)).ToString("##:##"), String); // if(rscon.record(c,"SUM_BT")+""=="True") // { // a[c1]= T_String.CongTG(T_String.IsNullTo00(a[c1]+""),T_String.IsNullTo00(rs.record(i,c))); // } break; } case "4": // double { FormatExcel.Set_Cell(sheet[r, c1], T_String.IsNullTo00(rs.record(i, c)).ToString("#,###.##"), DOU); if (rscon.record(c, "SUM_BT") + "" == "True") { a[c1] = T_String.IsNullTo00(a[c1] + "") + T_String.IsNullTo00(rs.record(i, c)); } break; } case "5": // int { FormatExcel.Set_Cell(sheet[r, c1], T_String.IsNullTo00(rs.record(i, c)).ToString("#,###.##"), INT); if (rscon.record(c, "SUM_BT") + "" == "True") { a[c1] = T_String.IsNullTo00(a[c1] + "") + T_String.IsNullTo00(rs.record(i, c)); } break; } } } r++; if (i + 1 == rs.rows) //dong cuoi { for (int c = 0; c < rscon.rows; c++) { int c1 = c + 1; if (rscon.record(c, "SUM_BT") + "" == "True") { switch (rscon.record(c, "TYP_ID") + "") { // case "3": // 00:00 // { // FormatExcel.Set_Cell(sheet[r,c1], T_String.IsNullTo00(a[c1]+"").ToString("##:##"),String); // break; // } case "4": // double { FormatExcel.Set_Cell(sheet[r, c1], T_String.IsNullTo00(a[c1] + "").ToString("#,###.##"), DOU); break; } case "5": // int { FormatExcel.Set_Cell(sheet[r, c1], T_String.IsNullTo00(a[c1] + "").ToString("#,###.##"), INT); break; } } } } } } // } try { string fileName = Application.StartupPath + @"\\Reports\\TAPO_" + RPT_ID + ".xls"; book.Save(fileName); System.Diagnostics.Process.Start(fileName); } catch { MessageBox.Show("You must close TAPO_" + RPT_ID + ".xls file first!!!!!"); return; } }
private void cmdExportToExcel_Click(object sender, EventArgs e) { try { _dtData = SPs.BaocaoThongkeSonoitru(dtFromDate.Value, dtToDate.Value, Utility.Int16Dbnull(cboDoituongKCB.SelectedValue, -1), Utility.Int16Dbnull(txtNhanvientiepdon.txtMyID, -1), Utility.sDbnull(cboKhoa.SelectedValue, "KKB"), thamso, Utility.Int16Dbnull(cboTinhTrang.SelectedValue, -1)).GetDataSet(). Tables[0]; if (_dtData.Rows.Count > 0) { Utility.SetDataSourceForDataGridEx(grdList, _dtData, true, true, "1=1", ""); const string reportcode = "baocao_thongke_sokhambenh_noitru"; string duongdan = Utility.GetPathExcel(reportcode); var book = new C1XLBook(); book.Load(duongdan); book.DefaultFont = new Font("Time New Roman", 11, FontStyle.Regular); XLSheet sheet = book.Sheets[0]; DataTable dt = _dtData; int idxRow = 9; int idxColSh = 0; string condition = string.Format("Từ ngày {0} đến {1} - Đối tượng : {2} - Tình trạng :{3}", dtFromDate.Text, dtToDate.Text, cboDoituongKCB.SelectedIndex >= 0 ? Utility.sDbnull(cboDoituongKCB.Text) : "Tất cả", cboTinhTrang.SelectedIndex > 0 ? Utility.sDbnull(cboKhoa.Text) : "Tất cả"); sheet[4, idxColSh].SetValue(Convert.ToString(condition), HamDungChung.styleStringCenter(book)); for (int i = 0; i < dt.Rows.Count; i++) { sheet[idxRow, idxColSh].SetValue(Convert.ToString(i + 1), HamDungChung.styleStringCenter(book)); sheet[idxRow, idxColSh + 1].SetValue(Convert.ToString(dt.Rows[i]["ten_benhnhan"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 2].SetValue(Convert.ToString(dt.Rows[i]["tuoinam"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 3].SetValue(Convert.ToString(dt.Rows[i]["tuoinu"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 4].SetValue(Convert.ToString(dt.Rows[i]["IsCongNhanVienChuc"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 5].SetValue(Convert.ToString(dt.Rows[i]["Isbhyt"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 6].SetValue(Convert.ToString(dt.Rows[i]["thanh_thi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 7].SetValue(Convert.ToString(dt.Rows[i]["nong_thon"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 8].SetValue(Convert.ToString(dt.Rows[i]["Nho12thang"]), HamDungChung.styleNumber(book)); sheet[idxRow, idxColSh + 9].SetValue(Convert.ToString(dt.Rows[i]["tu1den15tuoi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 10].SetValue(Convert.ToString(dt.Rows[i]["nghe_nghiep"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 11].SetValue(Convert.ToString(dt.Rows[i]["dia_chi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 12].SetValue(Convert.ToString(dt.Rows[i]["noi_gioithieu"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 13].SetValue(Convert.ToString(dt.Rows[i]["ngay_vaovien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 14].SetValue(Convert.ToString(dt.Rows[i]["ngay_chuyenvien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 15].SetValue(Convert.ToString(dt.Rows[i]["ngay_ravien"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 16].SetValue(Convert.ToString(dt.Rows[i]["chandoantuyenduoi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 17].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 18].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 19].SetValue(Convert.ToString(dt.Rows[i]["ten_benh"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 20].SetValue(Convert.ToString(dt.Rows[i]["khoi"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 21].SetValue(Convert.ToString(dt.Rows[i]["do_giam"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 22].SetValue(Convert.ToString(dt.Rows[i]["nang_hon"]), HamDungChung.styleStringLeft(book)); sheet[idxRow, idxColSh + 23].SetValue(Convert.ToString(dt.Rows[i]["khong_thay_doi"]), HamDungChung.styleStringLeft(book)); idxRow = idxRow + 1; } // vị trí dòng dữ liệu của table tiếp theo, vị trí cột bắt đầu t? 0 string getTime = Convert.ToString(DateTime.Now.ToString("yyyyMMddhhmmss")); string pathDirectory = AppDomain.CurrentDomain.BaseDirectory + "TemplateExcel\\ExportExcel\\"; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } book.Save(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls"); Process.Start( new ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory + "\\TemplateExcel\\ExportExcel\\" + reportcode + getTime + ".xls")); } else { Utility.ShowMsg("Không có dữ liệu để báo cáo!"); } } catch (Exception ex) { Utility.ShowMsg("Lỗi: " + ex.Message); } }
public void ViewMultiBoth(string lsYearmonth) { //string lsYearmonth = ""; //foreach (ListItem lstItem in lstSelectedYearMonth.Items) //{ // lsYearmonth += ",'" + lstItem.Value + "'"; // if (String.Compare(DateTime.Now.ToString("yyyyMMdd"), lstItem.Value) < 0) // { // using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString)) // { // con.Open(); // using (SqlCommand cm = new SqlCommand("sp_PaymentDetailOneCustomerRentManager", con)) // { // try // { // cm.CommandType = CommandType.StoredProcedure; // cm.Parameters.AddWithValue("@BuildingId", Func.ParseString(Session["__BUILDINGID__"])); // cm.Parameters.AddWithValue("@CustomerId", lblCustomerId.Text); // cm.Parameters.AddWithValue("@YearMonth", lstItem.Value); // cm.Parameters.AddWithValue("@Created", DateTime.Now.ToString("yyyyMMddHHmmss")); // cm.Parameters.AddWithValue("@CreatedBy", Page.User.Identity.Name); // cm.Parameters.AddWithValue("@Modified", DateTime.Now.ToString("yyyyMMddHHmmss")); // cm.Parameters.AddWithValue("@ModifiedBy", Page.User.Identity.Name); // cm.CommandTimeout = 9999; // int ret = cm.ExecuteNonQuery(); // } // catch (Exception ex) // { // ApplicationLog.WriteError(ex); // } // finally // { // con.Close(); // } // } // } // } //} 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 = 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; 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("Times New Roman", 12, 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("Times New Roman", 12, 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("Times New Roman", 12, 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__"]) + @"\Bill_" + lblCustomerId.Text + "_" + strDT + ".xlsx"; string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/Bill_" + lblCustomerId.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") + ".xls"); File.Copy(fileName, fileNameDes); xlbBook.Load(fileNameDes); XLSheet xlsSheet = xlbBook.Sheets["TongHop"]; XLSheet 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%}", 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%}", txtUsdExchange.Text); xlsSheetEn[rRateDate, cRateDate].Value = xlsSheetEn[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 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]; foreach (DataRow rowType in dt.Rows) { if (count >= 1) { xlsSheet.Rows.Insert(rRent + 1 + j); xlsSheetEn.Rows.Insert(rRent + 1 + j); j++; } count++; int tmp = rRent + j; 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["BeginContract"]); if (!contractIdLst.ContainsKey(ContractId + "(" + BeginContract.Substring(0, 10) + ")")) { contractIdLst.Add(ContractId + "(" + BeginContract.Substring(0, 10) + ")", ContractNo + "(" + BeginContract.Substring(0, 10) + ")"); contract += ";" + ContractNo + "(" + 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); ////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"]); } 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; row++) { for (int col = 1; col <= 13; col++) { xlsSheet[row, col].Style = xlstStyle; xlsSheetEn[row, col].Style = xlstStyle; } } sumRow += dt.Rows.Count - 1; //////////////////////// 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 count = 0; foreach (DataRow row in dt.Rows) { 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 = 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); ////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, 19].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"]); } 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; 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; } } 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"; 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,LastPriceUSD,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, 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 <= 12; 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, B.LastPriceVND, B.LastPriceUSD, 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 + ")"; 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, B.LastPriceVND, B.LastPriceUSD, 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 + ")"; 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,LastPriceVND,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; } 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 = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")"; 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"]; 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 = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth not in (" + lsYearmonth + ")"; 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 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(txtUsdExchange.Text)); 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%}", 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%}", 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); 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); } } } }
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) { 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); } }
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); } }
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); } } } }
/// </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 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); } } } }
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); }