protected void btnExport_Click(object sender, EventArgs e) { Response.ContentType = "application/force-download"; Response.AddHeader("content-disposition", "attachment; filename=Bao-cao-sct-" + ddlYear.SelectedValue + ".xls"); Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">"); Response.Write("<head>"); Response.Write("<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"); Response.Write("<!--[if gte mso 9]><xml>"); Response.Write("<x:ExcelWorkbook>"); Response.Write("<x:ExcelWorksheets>"); Response.Write("<x:ExcelWorksheet>"); Response.Write("<x:Name>Report Data</x:Name>"); Response.Write("<x:WorksheetOptions>"); Response.Write("<x:Print>"); Response.Write("<x:ValidPrinterInfo/>"); Response.Write("</x:Print>"); Response.Write("</x:WorksheetOptions>"); Response.Write("</x:ExcelWorksheet>"); Response.Write("</x:ExcelWorksheets>"); Response.Write("</x:ExcelWorkbook>"); Response.Write("</xml>"); Response.Write("<![endif]--> "); Response.Write("</head><body>"); //IList<GroupFuel> listGroupFuel = new List<GroupFuel>(); //if (!AspNetCache.CheckCache(Constants.Cache_ReportFuel_GroupFuel_All)) //{ // listGroupFuel = new GroupFuelService().FindAll(); // AspNetCache.SetCache(Constants.Cache_ReportFuel_GroupFuel_All, listGroupFuel); //} //else // listGroupFuel = (IList<GroupFuel>)AspNetCache.GetCache(Constants.Cache_ReportFuel_GroupFuel_All); IList <Fuel> listFuel = new List <Fuel>(); if (!AspNetCache.CheckCache(Constants.Cache_ReportFuel_Fuel_All)) { listFuel = new FuelService().FindAll(); AspNetCache.SetCache(Constants.Cache_ReportFuel_Fuel_All, listFuel); } else { listFuel = (IList <Fuel>)AspNetCache.GetCache(Constants.Cache_ReportFuel_Fuel_All); } ReportFuelService comBSO = new ReportFuelService(); DataTable list = new DataTable(); int AreaId = 0; int SubAreaId = 0; int Year = 0; if (ddlYear.SelectedIndex > 0) { Year = Convert.ToInt32(ddlYear.SelectedValue); } ePower.Core.PagingInfo paging = new ePower.Core.PagingInfo(2000, CurrentPage); list = comBSO.FindList(false, AreaId, SubAreaId, m_UserValidation.OrgId, 0, 0, 0, -1, true, Year, null, null, "", paging); string strHeader = ""; foreach (Fuel group in listFuel) { strHeader = strHeader + "<th>" + group.FuelName + "</th>"; } StringBuilder sb = new StringBuilder(); sb.Append("<table class='table table-bordered table-hover mbn' width='100%'>"); sb.Append("<tr class='primary fs12'>"); sb.Append("<th style='width:5%'>STT</th>"); sb.Append("<th style='width:35%'>Tên doanh nghiệp</th>"); sb.Append("<th style='width:10%'>Địa chỉ</th>"); sb.Append("<th style='width:10%'>Tỉnh/TP</th>"); sb.Append("<th style='width:10%'>Vùng</th>"); sb.Append("<th style='width:10%'>Lĩnh vực SX</th>"); sb.Append("<th style='width:10%'>Ngành nghề SX,KD</th>"); sb.Append(strHeader); sb.Append("<th style='width:10%'>Năng lượng tiêu thụ quy đổi (TOE)</th>"); sb.Append("</tr>"); if (list != null && list.Rows.Count > 0) { for (int i = 0; i < list.Rows.Count; i++) { sb.Append("<tr><td>" + (i + 1) + "</td>"); sb.Append("<td>" + list.Rows[i]["Title"] + "</td>"); sb.Append("<td>" + list.Rows[i]["Address"] + "</td>"); //sb.Append("<td>" + list.Rows[i]["ProvinceName"] + "</td>"); //sb.Append("<td></td>");//Vung //sb.Append("<td>" + list.Rows[i]["RegionName"] + "</td>");//Vung sb.Append("<td>" + list.Rows[i]["ParentAreaName"] + "</td>"); sb.Append("<td>" + list.Rows[i]["AreaName"] + "</td>"); if (list.Rows[i]["Id"] != null && list.Rows[i]["Id"].ToString() != "") { int ReportId = Convert.ToInt32(list.Rows[i]["Id"]); if (ReportId > 0) { DataTable listDetail = new ReportFuelDetailService().GetFuelTOEByReport(ReportId, false); int SumTOE = 0; if (listDetail != null && listDetail.Rows.Count > 0) { foreach (Fuel group in listFuel) { DataRow[] dr = listDetail.Select("FuelId=" + group.Id); if (dr != null && dr.Count() > 0) { sb.Append("<td>"); for (int j = 0; j < dr.Count(); j++) { sb.Append(dr[j]["NoFuel"] + " (" + dr[j]["MeasurementName"] + ")"); } sb.Append("</td>"); } else { sb.Append("<td>0</td>"); } } sb.Append("<td>" + SumTOE + "</td>"); } else { for (int j = 0; j < listFuel.Count; j++) { sb.Append("<td>0</td>"); } sb.Append("<td>0</td>"); } } sb.Append("</tr>"); } } } sb.Append("</table>"); Response.Write(sb.ToString()); Response.Write("</body></html>"); Response.End(); }
void BindTOECurrent() { ltData.Text = ""; IList <GroupFuel> listGroupFuel = new List <GroupFuel>(); if (!AspNetCache.CheckCache(Constants.Cache_ReportFuel_GroupFuel_All)) { listGroupFuel = new GroupFuelService().FindAll(); AspNetCache.SetCache(Constants.Cache_ReportFuel_GroupFuel_All, listGroupFuel); } else { listGroupFuel = (IList <GroupFuel>)AspNetCache.GetCache(Constants.Cache_ReportFuel_GroupFuel_All); } ReportFuelService comBSO = new ReportFuelService(); DataTable list = new DataTable(); int AreaId = 0; int SubAreaId = 0; int Year = 0; //if (ddlOrg.SelectedIndex > 0) // OrgId = Convert.ToInt32(ddlOrg.SelectedValue); ePower.Core.PagingInfo paging = new ePower.Core.PagingInfo(PageSize, CurrentPage); list = comBSO.FindList(false, AreaId, SubAreaId, ItemId, 0, 0, 0, 1, true, Year, null, null, "", paging); ltHeader.Text = ""; foreach (GroupFuel group in listGroupFuel) { ltHeader.Text = ltHeader.Text + "<th>" + group.Title + " (" + group.MeasurementName + ")</th>"; } if (list != null && list.Rows.Count > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.Rows.Count; i++) { sb.Append("<tr><td>" + (i + 1) + "</td>"); sb.Append("<td>" + list.Rows[i]["Title"] + "</td>"); sb.Append("<td>" + list.Rows[i]["Address"] + "</td>"); sb.Append("<td>" + list.Rows[i]["ProvinceName"] + "</td>"); sb.Append("<td></td>");//Vung //sb.Append("<td>" + list.Rows[i]["RegionName"] + "</td>");//Vung sb.Append("<td>" + list.Rows[i]["ParentAreaName"] + "</td>"); sb.Append("<td>" + list.Rows[i]["AreaName"] + "</td>"); if (list.Rows[i]["Id"] != null && list.Rows[i]["Id"].ToString() != "") { int ReportId = Convert.ToInt32(list.Rows[i]["Id"]); if (ReportId > 0) { DataTable listDetail = new ReportFuelDetailService().GetNoFuelDetailGroupByReport(ReportId, false); int SumTOE = 0; if (listDetail != null && listDetail.Rows.Count > 0) { foreach (GroupFuel group in listGroupFuel) { DataRow[] dr = listDetail.Select("GroupFuelId=" + group.Id); if (dr != null && dr.Count() > 0) { sb.Append("<td>" + dr[0]["NoFuel"]); SumTOE = SumTOE + Convert.ToInt32(dr[0]["NoFuel_TOE"]); } else { sb.Append("<td>0</td>"); } } sb.Append("<td>" + SumTOE + "</td>"); } else { for (int j = 0; j < listGroupFuel.Count; j++) { sb.Append("<td>0</td>"); } sb.Append("<td>0</td>"); } } sb.Append("</tr>"); } } ltData.Text = sb.ToString(); } }
//void BindEnterprise() //{ // int EnterpriseId = 1; // Enterprise enter = new Enterprise(); // enter = new EnterpriseService().FindByKey(EnterpriseId); // if (enter != null) // { // txtEnterpriseName.Text = enter.Title; // if (enter.SubAreaId > 0) // ddlSubArea.SelectedValue = enter.SubAreaId.ToString(); // if (enter.AreaId > 0) // ddlArea.SelectedValue = enter.AreaId.ToString(); // if (enter.ProvinceId > 0) // ddlProvince.SelectedValue = enter.ProvinceId.ToString(); // if (enter.DistrictId > 0) // ddlDistrict.SelectedValue = enter.DistrictId.ToString(); // txtAddress.Text = enter.Address; // txtEmail.Text = enter.Email; // txtFax.Text = enter.Fax; // txtPhone.Text = enter.Phone; // txtReportName.Text = enter.ManPerson; // if (enter.ManProvinceId > 0) // ddlProvinceReporter.SelectedValue = enter.ManProvinceId.ToString(); // if (enter.ManDistrictId > 0) // ddlDistrictReporter.SelectedValue = enter.ManDistrictId.ToString(); // txtAddressReporter.Text = enter.ManAddress; // txtEmail.Text = enter.ManEmail; // txtFaxReporter.Text = enter.ManFax; // txtPhoneReporter.Text = enter.ManPhone; // } //} //void BindOrganization() //{ // IList<Organization> list = new List<Organization>(); // if (!AspNetCache.CheckCache(Constants.Cache_ReportFuel_Organization_All)) // { // list = new OrganizationService().FindAll(); // AspNetCache.SetCache(Constants.Cache_ReportFuel_Organization_All, list); // } // else // list = (IList<Organization>)AspNetCache.GetCache(Constants.Cache_ReportFuel_Organization_All); // ddlOrg.DataSource = list; // ddlOrg.DataTextField = "Title"; // ddlOrg.DataValueField = "Id"; // ddlOrg.DataBind(); // ddlOrg.Items.Insert(0, new ListItem("---Tất cả---", "")); //} private void BindData() { ltData.Text = ""; IList <Fuel> listFuel = new List <Fuel>(); if (!AspNetCache.CheckCache(Constants.Cache_ReportFuel_Fuel_All)) { listFuel = new FuelService().FindAll(); AspNetCache.SetCache(Constants.Cache_ReportFuel_Fuel_All, listFuel); } else { listFuel = (IList <Fuel>)AspNetCache.GetCache(Constants.Cache_ReportFuel_Fuel_All); } //IList<GroupFuel> listGroupFuel = new List<GroupFuel>(); //if (!AspNetCache.CheckCache(Constants.Cache_ReportFuel_GroupFuel_All)) //{ // listGroupFuel = new GroupFuelService().FindAll(); // AspNetCache.SetCache(Constants.Cache_ReportFuel_GroupFuel_All, listGroupFuel); //} //else // listGroupFuel = (IList<GroupFuel>)AspNetCache.GetCache(Constants.Cache_ReportFuel_GroupFuel_All); ReportFuelService comBSO = new ReportFuelService(); DataTable list = new DataTable(); int AreaId = 0; int DistrictId = 0; int Year = 0; if (ddlArea.SelectedIndex > 0) { AreaId = Convert.ToInt32(ddlArea.SelectedValue); } if (ddlDistrict.SelectedIndex > 0) { DistrictId = Convert.ToInt32(ddlDistrict.SelectedValue); } if (ddlYear.SelectedIndex > 0) { Year = Convert.ToInt32(ddlYear.SelectedValue); } ePower.Core.PagingInfo paging = new ePower.Core.PagingInfo(PageSize, CurrentPage); list = comBSO.FindList(false, AreaId, 0, m_UserValidation.OrgId, 0, DistrictId, 0, -1, true, Year, null, null, txtKeyword.Text.Trim(), paging); ltHeader.Text = ""; //foreach (GroupFuel group in listGroupFuel) //{ // ltHeader.Text = ltHeader.Text + "<th>" + group.Title + " (" + group.MeasurementName + ")</th>"; //} foreach (Fuel fuel in listFuel) { ltHeader.Text = ltHeader.Text + "<th>" + fuel.FuelName + "</th>"; } if (list != null && list.Rows.Count > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.Rows.Count; i++) { sb.Append("<tr><td class='text-center'>" + (i + 1) + "</td>"); sb.Append("<td>" + list.Rows[i]["Title"] + "</td>"); sb.Append("<td>" + list.Rows[i]["Address"] + "</td>"); //sb.Append("<td>" + list.Rows[i]["ProvinceName"] + "</td>"); //sb.Append("<td></td>");//Vung //sb.Append("<td>" + list.Rows[i]["RegionName"] + "</td>");//Vung sb.Append("<td>" + list.Rows[i]["ParentAreaName"] + "</td>"); sb.Append("<td>" + list.Rows[i]["AreaName"] + "</td>"); if (list.Rows[i]["Id"] != null && list.Rows[i]["Id"].ToString() != "") { int ReportId = Convert.ToInt32(list.Rows[i]["Id"]); if (ReportId > 0) { DataTable listDetail = new ReportFuelDetailService().GetFuelTOEByReport(ReportId, false); int SumTOE = 0; if (listDetail != null && listDetail.Rows.Count > 0) { foreach (Fuel fuel in listFuel) { DataRow[] dr = listDetail.Select("FuelId=" + fuel.Id); if (dr != null && dr.Count() > 0) { sb.Append("<td>"); for (int j = 0; j < dr.Count(); j++) { if (dr[j]["NoFuel_TOE"] != DBNull.Value) { SumTOE = SumTOE + Convert.ToInt32(dr[j]["NoFuel_TOE"]); sb.Append(dr[j]["NoFuel"] + " (" + dr[j]["MeasurementName"] + ")"); } } sb.Append("</td>"); } else { sb.Append("<td>0</td>"); } } sb.Append("<td>" + SumTOE + "</td>"); } else { for (int j = 0; j < listFuel.Count; j++) { sb.Append("<td>0</td>"); } sb.Append("<td>0</td>"); } } sb.Append("</tr>"); } } ltData.Text = sb.ToString(); paging.RowsCount = Convert.ToInt32(list.Rows[0]["Total"]); Paging.PageSize = PageSize; Paging.CurrentPage = CurrentPage; Paging.TotalRecord = Convert.ToInt32(list.Rows[0]["Total"]); Paging.DataLoad(); if (paging.PagesCount <= 1) { ltNotice.Text = "Có tổng số " + paging.RowsCount + " báo cáo"; Paging.Visible = false; } else { ltNotice.Text = "Có" + list.Rows.Count + " trong tổng số " + paging.RowsCount + " báo cáo"; Paging.Visible = true; } } else { ltNotice.Text = ""; Paging.Visible = false; } }