void BindReportDetail() { DataTable dtCurrent = new ReportFuelDetailService().GetNoFuelDetailByReport(ReportId, false); rptNoFuelCurrent.DataSource = dtCurrent; rptNoFuelCurrent.DataBind(); ltTotal_TOE.Text = "Tổng năng lượng tiêu thụ quy đổi ra TOE: <span style='color:red'>" + No_TOE + "</span>"; }
void BindReportDetailNext() { DataTable dtFuture = new ReportFuelDetailService().GetNoFuelDetailByReport(ReportId, true); rptNoFuelFuture.DataSource = dtFuture; rptNoFuelFuture.DataBind(); ltTotal_TOE_Future.Text = "Tổng năng lượng tiêu thụ dự kiến quy đổi ra TOE: <span style='color:red'>" + No_TOE_Future + "</span>"; }
protected void btnDelete_Click(object sender, EventArgs e) { LinkButton btnDelete = (LinkButton)sender; ReportFuelDetailService faqsBSO = new ReportFuelDetailService(); faqsBSO.Delete(Convert.ToInt32(btnDelete.CommandArgument)); BindReportDetail(); }
private DataTable CreateFuelData() { DataTable dtCurrent = new ReportFuelDetailService().GetNoFuelDetailByReport(ReportId, false); ReportModels rp = new ReportModels(); var allFuel = (from a in rp.DE_Fuel join b in rp.DE_Measurement on a.MeasurementId equals b.Id join c in rp.DE_GroupFuel on a.GroupFuelId equals c.Id select new { a.Id, a.GroupFuelId, a.FuelName, b.MeasurementName, c.GroupCode, a.FuelOrder }).ToList(); DataTable res = new DataTable(); res.Columns.Add("stt", typeof(string)); res.Columns.Add("FuelName", typeof(string)); res.Columns.Add("MeasurementName", typeof(string)); res.Columns.Add("NoFuel", typeof(string)); res.Columns.Add("Reason", typeof(string)); res.Columns.Add("GroupCode", typeof(string)); res.Columns.Add("FuelOrder", typeof(string)); int i = 1; foreach (var item in allFuel) { DataRow r = res.NewRow(); r["stt"] = i.ToString(); r["FuelName"] = item.FuelName; r["MeasurementName"] = item.MeasurementName; r["GroupCode"] = item.GroupCode; r["FuelOrder"] = item.FuelOrder; bool check = false; foreach (DataRow x in dtCurrent.Rows) { if (x["FuelId"].ToString() == item.Id.ToString()) { check = true; r["NoFuel"] = x["NoFuel"]; r["Reason"] = x["Reason"]; break; } } if (check == false) { r["NoFuel"] = ""; r["Reason"] = ""; } res.Rows.Add(r); i++; } return(res); }
void BindReportDetail() { DataTable dtCurrent = new ReportFuelDetailService().GetNoFuelDetailByReport(ReportId, false); rptNoFuelCurrent.DataSource = dtCurrent; rptNoFuelCurrent.DataBind(); DataTable dtFuture = new ReportFuelDetailService().GetNoFuelDetailByReport(ReportId, true); rptNoFuelFuture.DataSource = dtFuture; rptNoFuelFuture.DataBind(); }
private void BindDataDetail() { if (hdnDetailId.Value != "") { ReportFuelDetail reportDetail = new ReportFuelDetailService().FindByKey(Convert.ToInt32(hdnDetailId.Value)); if (reportDetail != null) { try { if (reportDetail.FuelId > 0) { ddlFuel.SelectedValue = reportDetail.FuelId.ToString(); BindMeasurement(); } if (reportDetail.MeasurementId > 0) { ddlMeasure.SelectedValue = reportDetail.MeasurementId.ToString(); BindTOE(); } } catch { } txtPropose.Text = reportDetail.Reason; if (reportDetail.NoFuel > 0) { txtNoFuel.Text = reportDetail.NoFuel.ToString(); } if (reportDetail.Price > 0) { txtPrice.Text = reportDetail.Price.ToString(); } if (reportDetail.No_RateTOE > 0) { txtNoTOE.Text = Tool.ConvertDecimalToString(reportDetail.No_RateTOE); } hdnNextYear.Value = reportDetail.IsNextYear ? "1" : "0"; if (reportDetail.IsNextYear) { ltTitle.Text = "Mức nhiên liệu tiêu thụ dự kiến năm " + (reportDetail.Year + 1).ToString(); } else { //ltTitle.Text = "Mức nhiên liệu tiêu thụ năm " + reportDetail.Year; ltTitle.Text = "Mức nhiên liệu tiêu thụ năm " + ReportYear.ToString(); } } } }
protected void btnSaveFuel_Click(object sender, EventArgs e) { try { ReportFuelDetail faqs = ReceiveHtmlDetail(); ReportFuelDetailService faqsBSO = new ReportFuelDetailService(); if (hdnDetailId.Value != "") { //faqs = faqsBSO.FindByKey(ReportDetailId); faqs.Id = Convert.ToInt32(hdnDetailId.Value); if (faqsBSO.Update(faqs) != null) { clientview.Text = "<div class='alert alert-sm alert-success bg-gradient'>Lưu thông tin Thành công !</div>"; if (hdnNextYear.Value == "0") { BindReportDetail(); } } else { clientview.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Lưu thông tin không Thành công !</div>"; } } else { if (faqsBSO.Insert(faqs) > 0) { clientview.Text = "<div class='alert alert-sm alert-success bg-gradient'>Lưu thông tin Thành công !</div>"; if (hdnNextYear.Value == "0") { BindReportDetail(); } } else { clientview.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Lưu thông tin không Thành công !</div>"; } } } catch (Exception ex) { clientview.Text = ex.Message.ToString(); } }
private void BindData() { if (ReportId > 0) { try { ReportFuel faqs = new ReportFuel(); ReportFuelService faqsBSO = new ReportFuelService(); faqs = faqsBSO.FindByKey(ReportId); EnterpriseId = faqs.EnterpriseId; ReportYear = faqs.Year; } catch (Exception ex) { clientview.Text = ex.Message.ToString(); } } else { if (ReportDetailId > 0) { ReportFuelDetail reportDetail = new ReportFuelDetailService().FindByKey(ReportDetailId); if (reportDetail != null) { ddlFuelType.SelectedValue = reportDetail.GroupFuelId.ToString(); ddlFuel.SelectedValue = reportDetail.FuelId.ToString(); ddlMeasure.SelectedValue = reportDetail.MeasurementId.ToString(); txtPropose.Text = reportDetail.Reason; txtNoFuel.Text = reportDetail.NoFuel.ToString(); txtPrice.Text = reportDetail.Price.ToString(); txtNoTOE.Text = reportDetail.No_RateTOE.ToString(); ReportFuel faqs = new ReportFuel(); ReportFuelService faqsBSO = new ReportFuelService(); faqs = faqsBSO.FindByKey(reportDetail.ReportId); EnterpriseId = faqs.EnterpriseId; ReportYear = faqs.Year; ReportId = reportDetail.ReportId; isnext = reportDetail.IsNextYear == true ? 1 : 0; } } } }
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(); } }
protected void btnImport_Click(object sender, EventArgs e) { lterror.Text = ""; if (flReport.HasFile) { string strext = Path.GetExtension(flReport.PostedFile.FileName).Substring(1); if (strext == "xls" || strext == "xlsx") { string fullfilename = "~/UserFile/" + flReport.FileName; if (File.Exists(Server.MapPath(fullfilename))) { lterror.Text = "File đã tồn tại, vui lòng đổi tên khác"; return; } flReport.PostedFile.SaveAs(Server.MapPath(fullfilename)); if (File.Exists(Server.MapPath(fullfilename))) { log.Info("File: " + flReport.FileName); DataTable dt = new DataTable(); string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", Server.MapPath(fullfilename)); string query = String.Format("select * from [{0}$]", "Sheet1"); SecurityBSO securityBSO = new SecurityBSO(); OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString); DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); DataTable myTable = dataSet.Tables[0]; EnterpriseService comBSO = new EnterpriseService(); int rowi = 0; foreach (DataRow drow in myTable.Rows) { rowi++; log.Info("Dong thu: " + rowi); try { ReportTemp2014 temp = new ReportTemp2014(); Enterprise enter = new Enterprise(); int eId = 0; enter.Title = drow["Ten_DN"].ToString(); temp.Title = enter.Title; log.Info("Doanh nghiep: " + enter.Title); enter.OrganizationId = Convert.ToInt32(drow["SCT_ID"]); temp.OrgId = enter.OrganizationId; if (drow["DiaChi"] != DBNull.Value) { enter.Address = drow["DiaChi"].ToString(); temp.Address = enter.Address; } if (drow["LinhVuc_Id"] != DBNull.Value && drow["LinhVuc_Id"].ToString() != "") { temp.AreaId = Convert.ToInt32(drow["LinhVuc_Id"]); enter.AreaId = temp.AreaId; } enter.ProvinceId = Convert.ToInt32(drow["TinhTP_ID"]); enter.ManProvinceId = enter.ProvinceId; enter.OrganizationId = Convert.ToInt32(drow["SCT_ID"]); if (drow["Ma_DN"] != DBNull.Value && drow["Ma_DN"].ToString().Trim() != "") { eId = Convert.ToInt32(drow["Ma_DN"]); //enter = comBSO.FindByKey(eId); } else { enter.ActiveYear = 2015; enter.CustomerCode = ""; enter.TaxCode = ""; if (drow["PhanNganh"] != DBNull.Value && drow["PhanNganh"].ToString() != "") { DataTable dtSub = new AreaService().getAreaByName(drow["PhanNganh"].ToString()); if (dtSub != null && dtSub.Rows.Count > 0) { enter.SubAreaId = Convert.ToInt32(dtSub.Rows[0]["Id"]); temp.SubAreaId = enter.SubAreaId; } else { Area sub = new Area(); sub.AreaName = drow["PhanNganh"].ToString(); sub.ParentId = enter.AreaId; sub.IsStatus = 1; sub.SortOrder = 0; int subId = new AreaService().Insert(sub); temp.SubAreaId = subId; enter.SubAreaId = subId; } enter.Info = drow["PhanNganh"].ToString(); temp.SubAreaName = drow["PhanNganh"].ToString(); } eId = comBSO.Insert(enter);//Them doanh nghiep if (eId > 0) { Organization org = new OrganizationService().FindByKey(enter.OrganizationId); //Tao tai khoan doanh nghiep Utils objUtil = new Utils(); MemberService memberService = new MemberService(); int STT = 0; STT = new EnterpriseService().GetNoAccount(enter.OrganizationId); STT++; ePower.DE.Domain.Member member = new ePower.DE.Domain.Member(); member.EnterpriseId = eId; member.IsDelete = false; member.AccountName = "dn." + Utils.UCS2Convert(org.Title).Replace(" ", "").Replace("-", "").ToLower() + "." + STT.ToString("000"); member.Password = securityBSO.EncPwd("abc123"); int mId = memberService.Insert(member); if (mId < 0) { log.Info("Khong tao duoc tai khoan"); } } else { log.Info("Khong tao duoc DN"); } } if (eId > 0) { ReportFuel report = new ReportFuel(); ReportFuelService reportService = new ReportFuelService(); report.EnterpriseId = eId; report.OrganizationId = enter.OrganizationId; report.ReportDate = DateTime.Now; report.CompanyName = enter.Title; report.Address = enter.Address; report.ApprovedSatus = true; report.AprovedDate = DateTime.Now; report.AreaId = enter.AreaId; report.ConfirmedDate = DateTime.Now; report.Created = DateTime.Now; report.DistrictId = enter.DistrictId; report.Email = enter.Email; report.Fax = enter.Fax; report.IsFiveYear = false; report.IsDelete = false; report.Phone = enter.Phone; report.ReportDate = DateTime.Now; report.SendSatus = 1; report.Year = 2018; report.SubAreaId = enter.SubAreaId; report.Year = Convert.ToInt32(txtPlanYear.Text.Trim()); temp.EnterpriseId = eId; int reportId = reportService.Insert(report); if (reportId > 0) { ReportFuelDetailService serviceDetail = new ReportFuelDetailService(); ReportFuelDetail detail = new ReportFuelDetail(); int detailid = 0; if (drow["Dien_kWh"] != DBNull.Value && drow["Dien_kWh"].ToString().Trim() != "") { temp.Dien_kWh = drow["Dien_kWh"].ToString(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 1; detail.MeasurementId = 1; detail.No_RateTOE = 0.0001543m; detail.Price = 0; detail.Year = 2017; if (drow["Dien_kWh"] != DBNull.Value && drow["Dien_kWh"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["Dien_kWh"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them dien loi"); } } if (drow["ThanDa_Tan"] != DBNull.Value && drow["ThanDa_Tan"].ToString().Trim() != "") { detail = new ReportFuelDetail(); temp.Than_Tan = drow["ThanDa_Tan"].ToString(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 2; detail.MeasurementId = 2; detail.No_RateTOE = 0.7m; detail.Price = 0; detail.Year = 2017; if (drow["ThanDa_Tan"] != DBNull.Value && drow["ThanDa_Tan"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["ThanDa_Tan"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them than da_tan loi"); } } if (drow["Than12_Tan"] != DBNull.Value && drow["Than12_Tan"].ToString().Trim() != "") { detail = new ReportFuelDetail(); temp.Than_Tan = drow["Than12_Tan"].ToString(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 3; detail.MeasurementId = 2; detail.No_RateTOE = 0.7m; detail.Price = 0; detail.Year = 2017; if (drow["Than12_Tan"] != DBNull.Value && drow["Than12_Tan"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["Than12_Tan"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them than 12 loi"); } } if (drow["Than34_Tan"] != DBNull.Value && drow["Than34_Tan"].ToString().Trim() != "") { detail = new ReportFuelDetail(); temp.Than_Tan = drow["Than34_Tan"].ToString(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 4; detail.MeasurementId = 2; detail.No_RateTOE = 0.6m; detail.Price = 0; detail.Year = 2017; if (drow["Than34_Tan"] != DBNull.Value && drow["Than34_Tan"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["Than34_Tan"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them than34 loi"); } } if (drow["Than56_Tan"] != DBNull.Value && drow["Than56_Tan"].ToString().Trim() != "") { detail = new ReportFuelDetail(); temp.Than_Tan = drow["Than56_Tan"].ToString(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 5; detail.MeasurementId = 2; detail.No_RateTOE = 0.5m; detail.Price = 0; detail.Year = 2017; if (drow["Than56_Tan"] != DBNull.Value && drow["Than56_Tan"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["Than56_Tan"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them than56 loi"); } } if (drow["DO_Tan"] != DBNull.Value && drow["DO_Tan"].ToString().Trim() != "") { detail = new ReportFuelDetail(); temp.DO_Tan = drow["DO_Tan"].ToString(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 6; detail.MeasurementId = 2; detail.No_RateTOE = 1.02m; detail.Price = 0; detail.Year = 2017; if (drow["DO_Tan"] != DBNull.Value && drow["DO_Tan"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["DO_Tan"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them dau do_tan loi"); } } if (drow["DO_lit"] != DBNull.Value && drow["DO_lit"].ToString().Trim() != "") { temp.DO_lit = drow["DO_lit"].ToString(); detail = new ReportFuelDetail(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 6; detail.MeasurementId = 3; detail.No_RateTOE = 0.00088m; detail.Price = 0; detail.Year = 2017; if (drow["DO_lit"] != DBNull.Value && drow["DO_lit"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["DO_lit"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them dauDO_lit loi"); } } if (drow["FO_Tan"] != DBNull.Value && drow["FO_Tan"].ToString().Trim() != "") { temp.FO_Tan = drow["FO_Tan"].ToString(); detail = new ReportFuelDetail(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 7; detail.MeasurementId = 2; detail.No_RateTOE = 0.99m; detail.Price = 0; detail.Year = 2017; if (drow["FO_Tan"] != DBNull.Value && drow["FO_Tan"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["FO_Tan"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them dau FO_tan loi"); } } if (drow["FO_lit"] != DBNull.Value && drow["FO_lit"].ToString().Trim() != "") { temp.FO_lit = drow["FO_lit"].ToString(); detail = new ReportFuelDetail(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 7; detail.MeasurementId = 3; detail.No_RateTOE = 0.00094m; detail.Price = 0; detail.Year = 2017; if (drow["FO_lit"] != DBNull.Value && drow["FO_lit"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["FO_lit"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them dau FO_Lit loi"); } } if (drow["Xang_Tan"] != DBNull.Value && drow["Xang_Tan"].ToString().Trim() != "") { temp.Xang_Tan = drow["Xang_Tan"].ToString(); detail = new ReportFuelDetail(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 11; detail.MeasurementId = 2; detail.No_RateTOE = 1.05m; detail.Price = 0; detail.Year = 2017; if (drow["Xang_Tan"] != DBNull.Value && drow["Xang_Tan"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["Xang_Tan"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them xang_tan loi"); } } if (drow["Xang_lit"] != DBNull.Value && drow["Xang_lit"].ToString().Trim() != "") { temp.Xang_lit = drow["Xang_lit"].ToString(); detail = new ReportFuelDetail(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 11; detail.MeasurementId = 3; detail.No_RateTOE = 0.00083m; detail.Price = 0; detail.Year = 2017; if (drow["Xang_lit"] != DBNull.Value && drow["Xang_lit"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["Xang_lit"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them xang_lit loi"); } } if (drow["Gas_Tan"] != DBNull.Value && drow["Gas_Tan"].ToString().Trim() != "") { temp.Gas_Tan = drow["Gas_Tan"].ToString(); detail = new ReportFuelDetail(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 10; detail.MeasurementId = 4; detail.No_RateTOE = 0.0009m; detail.Price = 0; detail.Year = 2017; if (drow["Gas_Tan"] != DBNull.Value && drow["Gas_Tan"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["Gas_Tan"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them Gas_Tan loi"); } } if (drow["Khi_m3"] != DBNull.Value && drow["Khi_m3"].ToString().Trim() != "") { temp.Khi_M3 = drow["Khi_m3"].ToString(); detail = new ReportFuelDetail(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 10; detail.MeasurementId = 1; detail.No_RateTOE = 0.0009m; detail.Price = 0; detail.Year = 2017; if (drow["Khi_m3"] != DBNull.Value && drow["Khi_m3"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["Khi_m3"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them Khi_m3 loi"); } } if (drow["LPG_Tan"] != DBNull.Value && drow["LPG_Tan"].ToString().Trim() != "") { temp.LPG_Tan = drow["LPG_Tan"].ToString(); detail = new ReportFuelDetail(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 8; detail.MeasurementId = 2; detail.No_RateTOE = 1.09m; detail.Price = 0; detail.Year = 2017; if (drow["LPG_Tan"] != DBNull.Value && drow["LPG_Tan"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["LPG_Tan"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them LPG loi"); } } if (drow["NLPL_Tan"] != DBNull.Value && drow["NLPL_Tan"].ToString().Trim() != "") { temp.NLPL_Tan = drow["NLPL_Tan"].ToString(); detail = new ReportFuelDetail(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 12; detail.MeasurementId = 2; detail.No_RateTOE = 1.05m; detail.Price = 0; detail.Year = 2017; if (drow["NLPL_Tan"] != DBNull.Value && drow["NLPL_Tan"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["NLPL_Tan"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them NLPL loi"); } } if (drow["Khac_tan"] != DBNull.Value && drow["Khac_tan"].ToString().Trim() != "") { temp.KhacSoDo = drow["Khac_tan"].ToString(); detail = new ReportFuelDetail(); detail.EnterpriseId = report.EnterpriseId; detail.FuelId = 1; detail.MeasurementId = 1; detail.No_RateTOE = 0.0002770000m; detail.Price = 0; detail.Year = 2017; if (drow["Khac_tan"] != DBNull.Value && drow["Khac_tan"].ToString() != "") { detail.NoFuel = Convert.ToDecimal(drow["Khac_tan"]); } detail.NoFuel_TOE = detail.No_RateTOE * detail.NoFuel; detail.ReportId = reportId; detailid = serviceDetail.Insert(detail); if (detailid <= 0) { log.Info("Them khac loi"); } } if (drow["GhiChu"] != DBNull.Value && drow["GhiChu"].ToString().Trim() != "") { temp.Note = drow["GhiChu"].ToString(); } EnterpriseYearService eYService = new EnterpriseYearService(); EnterpriseYear ey = new EnterpriseYear(); ey.EnterpriseId = eId; ey.ReportId = reportId; ey.Year = 2017; ey.IsKey = true; if (drow["No_TOE"] != DBNull.Value && drow["No_TOE"].ToString().Trim() != "") { ey.No_TOE = Convert.ToDecimal(drow["No_TOE"]); } temp.No_TOE = ey.No_TOE; temp.Year = 2017; int retTemp = new ReportTemp2014Service().Insert(temp);//Them bao cao tam ey.IsDelete = false; ey.Year = temp.Year; int retempId = eYService.Insert(ey);//Them nam bao cao if (retempId <= 0) { log.Info("Them bao cao loi loi"); } } else { log.Info("Khong tao duoc bao cao"); } } } catch (Exception ex) { log.Error("Loi import du lieu dong thu i: " + rowi, ex); } } } else { lterror.Text = "Không upload được file"; } } else { lterror.Text = "Chỉ chọn file Excel đuôi .xls và .xlsx"; } } else { lterror.Text = "File không tồn tại"; } }
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 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; } }
protected void btnExport_Click(object sender, EventArgs e) { #region get data WordExtend ex = new WordExtend(); string temp = "TempReport/TemMauBaoCao" + drpmaubaocao.SelectedValue + ".doc"; ex.OpenFile(Server.MapPath(ResolveUrl("~") + temp)); Enterprise or = new Enterprise(); EnterpriseService orser = new EnterpriseService(); or = orser.FindByKey(Convert.ToInt32(memVal.OrgId)); DataTable dtinfo = new DataTable(); ex.WriteToMergeField("BC_MaDN", ""); if (memVal.OrgId > 0) { dtinfo = new ReportFuelService().GetInfoReportFuel(ReportId); } if (or != null) { ex.WriteToMergeField("BC_Title", or.Title); ex.WriteToMergeField("BC_TenCoSo", or.Title); ex.WriteToMergeField("BC_TenCoSo1", or.Title); ex.WriteToMergeField("BC_TenCoSo2", or.Title); } else { ex.WriteToMergeField("BC_TenCoSo", ""); } if (dtinfo.Rows[0]["Year"] != DBNull.Value) { string NextYear = (Convert.ToInt32(dtinfo.Rows[0]["Year"]) + 1).ToString(); ex.WriteToMergeField("BC_NextYear", NextYear); ex.WriteToMergeField("BC_NextYear1", NextYear); ex.WriteToMergeField("BC_NextYear2", NextYear); ex.WriteToMergeField("BC_Year", dtinfo.Rows[0]["Year"].ToString()); ex.WriteToMergeField("BC_Year1", dtinfo.Rows[0]["Year"].ToString()); } if (dtinfo.Rows[0]["Responsible"] != DBNull.Value) { ex.WriteToMergeField("BC_ChiuTrachNhiem", dtinfo.Rows[0]["Responsible"].ToString()); } else { ex.WriteToMergeField("BC_ChiuTrachNhiem", ""); } if (dtinfo.Rows[0]["ReportDate"] != DBNull.Value) { ex.WriteToMergeField("BC_NgayLap", Convert.ToDateTime(dtinfo.Rows[0]["ReportDate"]).ToString("dd/MM/yyyy")); ex.WriteToMergeField("BC_NgayBC", Convert.ToDateTime(dtinfo.Rows[0]["ReportDate"]).ToString("dd/MM/yyyy")); } if (dtinfo.Rows[0]["ReceivedDate"] != DBNull.Value) { ex.WriteToMergeField("BC_NgayNhan", Convert.ToDateTime(dtinfo.Rows[0]["ReceivedDate"]).ToString("dd/MM/yyyy")); } else { ex.WriteToMergeField("BC_NgayNhan", ""); } if (dtinfo.Rows[0]["ConfirmedDate"] != DBNull.Value) { ex.WriteToMergeField("BC_NgayXacNhan", Convert.ToDateTime(dtinfo.Rows[0]["ConfirmedDate"]).ToString("dd/MM/yyyy")); } else { ex.WriteToMergeField("BC_NgayXacNhan", ""); } if (dtinfo.Rows[0]["SubAreaName"] != DBNull.Value) { ex.WriteToMergeField("BC_PhanNganh", dtinfo.Rows[0]["SubAreaName"].ToString()); } else { ex.WriteToMergeField("BC_PhanNganh", ""); } if (dtinfo.Rows[0]["TaxCode"] != DBNull.Value) { ex.WriteToMergeField("BC_TaxCode", dtinfo.Rows[0]["TaxCode"].ToString()); } else { ex.WriteToMergeField("BC_TaxCode", ""); } ex.WriteToMergeField("BC_Owner", ltOwner.Text); if (or.Address != null) { ex.WriteToMergeField("BC_DiaChi", or.Address); } if (dtinfo.Rows[0]["DistrictName"] != DBNull.Value) { ex.WriteToMergeField("BC_Huyen", dtinfo.Rows[0]["DistrictName"].ToString()); } else { ex.WriteToMergeField("BC_Huyen", ""); } if (dtinfo.Rows[0]["ProvinceName"] != DBNull.Value) { ex.WriteToMergeField("BC_Tinh", dtinfo.Rows[0]["ProvinceName"].ToString()); } else { ex.WriteToMergeField("BC_Tinh", ""); } if (dtinfo.Rows[0]["ReporterName"] != DBNull.Value) { ex.WriteToMergeField("BC_NguoiBC", dtinfo.Rows[0]["ReporterName"].ToString()); } else { ex.WriteToMergeField("BC_NguoiBC", ""); } if (dtinfo.Rows[0]["Fax"] != DBNull.Value) { ex.WriteToMergeField("BC_Fax", dtinfo.Rows[0]["Fax"].ToString()); } else { ex.WriteToMergeField("BC_Fax", ""); } if (dtinfo.Rows[0]["Email"] != DBNull.Value) { ex.WriteToMergeField("BC_Email", dtinfo.Rows[0]["Email"].ToString()); } else { ex.WriteToMergeField("BC_Email", ""); } if (dtinfo.Rows[0]["Phone"] != DBNull.Value) { ex.WriteToMergeField("BC_DienThoai", dtinfo.Rows[0]["Phone"].ToString()); } else { ex.WriteToMergeField("BC_DienThoai", ""); } if (dtinfo.Rows[0]["ParentName"] != DBNull.Value) { ex.WriteToMergeField("BC_TenCtyMe", dtinfo.Rows[0]["ParentName"].ToString()); } else { ex.WriteToMergeField("BC_TenCtyMe", ""); } if (dtinfo.Rows[0]["AddressParent"] != null) { ex.WriteToMergeField("BC_DiaChiP", dtinfo.Rows[0]["AddressParent"].ToString()); } else { ex.WriteToMergeField("BC_DiaChiP", ""); } if (dtinfo.Rows[0]["DistrictNameP"] != null) { ex.WriteToMergeField("BC_HuyenP", dtinfo.Rows[0]["DistrictNameP"].ToString()); } else { ex.WriteToMergeField("BC_HuyenP", ""); } if (dtinfo.Rows[0]["ProvinceNameP"] != DBNull.Value) { ex.WriteToMergeField("BC_TinhP", dtinfo.Rows[0]["ProvinceNameP"].ToString()); } else { ex.WriteToMergeField("BC_TinhP", ""); } if (dtinfo.Rows[0]["PhoneParent"] != DBNull.Value) { ex.WriteToMergeField("BC_DienThoaiP", dtinfo.Rows[0]["PhoneParent"].ToString()); } else { ex.WriteToMergeField("BC_DienThoaiP", ""); } if (dtinfo.Rows[0]["FaxParent"] != DBNull.Value) { ex.WriteToMergeField("BC_FaxP", dtinfo.Rows[0]["FaxParent"].ToString()); } else { ex.WriteToMergeField("BC_FaxP", ""); } if (dtinfo.Rows[0]["EmailParent"] != DBNull.Value) { ex.WriteToMergeField("BC_EmailP", dtinfo.Rows[0]["EmailParent"].ToString()); } else { ex.WriteToMergeField("BC_EmailP", ""); } if (or.ActiveYear > 0) { ex.WriteToMergeField("ActiveYear", or.ActiveYear.ToString()); } else { ex.WriteToMergeField("ActiveYear", ""); } Infrastructure infra = new Infrastructure(); InfrastructureService infraService = new InfrastructureService(); infra = infraService.GetInfrastructureByReport(ReportId); if (infra != null) { if (infra.ProduceAreaNo > 0) { ex.WriteToMergeField("ProduceAreaNo", infra.ProduceAreaNo.ToString()); } else { ex.WriteToMergeField("ProduceAreaNo", ""); } if (infra.OfficeAreaNo > 0) { ex.WriteToMergeField("OfficeAreaNo", infra.OfficeAreaNo.ToString()); } else { ex.WriteToMergeField("OfficeAreaNo", ""); } if (infra.ProduceEmployeeNo > 0) { ex.WriteToMergeField("ProduceEmployeeNo", infra.ProduceEmployeeNo.ToString()); } else { ex.WriteToMergeField("ProduceEmployeeNo", ""); } if (infra.OfficeEmployeeNo > 0) { ex.WriteToMergeField("OfficeEmployeeNo", infra.OfficeEmployeeNo.ToString()); } else { ex.WriteToMergeField("OfficeEmployeeNo", ""); } } else { ex.WriteToMergeField("ProduceAreaNo", ""); ex.WriteToMergeField("OfficeAreaNo", ""); ex.WriteToMergeField("ProduceEmployeeNo", ""); ex.WriteToMergeField("OfficeEmployeeNo", ""); } UsingElectrict usingElectrict = new UsingElectrict(); UsingElectrictService usingElectrictService = new UsingElectrictService(); usingElectrict = usingElectrictService.GetUsingElectrictByReport(ReportId, false); if (usingElectrict != null) { //Su dung dien 2 if (usingElectrict.Quantity > 0) { ex.WriteToMergeField("QuantityResult2", usingElectrict.Quantity.ToString()); } else { ex.WriteToMergeField("QuantityResult2", ""); } if (usingElectrict.InstalledCapacity > 0) { ex.WriteToMergeField("InstalledCapacityResult2", usingElectrict.InstalledCapacity.ToString()); } else { ex.WriteToMergeField("InstalledCapacityResult2", ""); } if (usingElectrict.Capacity > 0) { ex.WriteToMergeField("CapacityResult2", usingElectrict.Capacity.ToString()); } else { ex.WriteToMergeField("CapacityResult2", ""); } if (usingElectrict.BuyCost > 0) { ex.WriteToMergeField("BuyCostResult2", usingElectrict.BuyCost.ToString()); } else { ex.WriteToMergeField("BuyCostResult2", ""); } if (usingElectrict.BuyCost > 0 && usingElectrict.Capacity > 0) { ex.WriteToMergeField("BuyPriceResult2", Math.Round((usingElectrict.BuyCost / (usingElectrict.Capacity * 1000)), 0).ToString()); } else { ex.WriteToMergeField("BuyPriceResult2", ""); } if (usingElectrict.ProduceQty > 0) { ex.WriteToMergeField("ProduceQtyResult2", usingElectrict.ProduceQty.ToString()); } else { ex.WriteToMergeField("ProduceQtyResult2", ""); } if (usingElectrict.Technology != null) { ex.WriteToMergeField("TechnologyResult2", usingElectrict.Technology.ToString()); } else { ex.WriteToMergeField("TechnologyResult2", ""); } if (usingElectrict.FuelId > 0) { Fuel fuel = new Fuel(); fuel = new FuelService().FindByKey(usingElectrict.FuelId); if (fuel != null) { ex.WriteToMergeField("FuelNameResult2", fuel.FuelName); ex.WriteToMergeField("FuelNameResult", fuel.FuelName); } else { ex.WriteToMergeField("FuelNameResult2", ""); ex.WriteToMergeField("FuelNameResult", ""); } } else { ex.WriteToMergeField("FuelNameResult2", ""); ex.WriteToMergeField("FuelNameResult", ""); } if (usingElectrict.PriceProduce > 0) { ex.WriteToMergeField("PriceProduceResult2", usingElectrict.PriceProduce.ToString()); } else { ex.WriteToMergeField("PriceProduceResult2", ""); } //Su dung dien 1 if (usingElectrict.Quantity > 0) { ex.WriteToMergeField("QuantityResult", usingElectrict.Quantity.ToString()); } else { ex.WriteToMergeField("QuantityResult", ""); } if (usingElectrict.InstalledCapacity > 0) { ex.WriteToMergeField("InstalledCapacityResult", usingElectrict.InstalledCapacity.ToString()); } else { ex.WriteToMergeField("InstalledCapacityResult", ""); } if (usingElectrict.Capacity > 0) { ex.WriteToMergeField("CapacityResult", usingElectrict.Capacity.ToString()); } else { ex.WriteToMergeField("CapacityResult", ""); } if (usingElectrict.BuyCost > 0) { ex.WriteToMergeField("BuyCostResult", usingElectrict.BuyCost.ToString()); } else { ex.WriteToMergeField("BuyCostResult", ""); } if (usingElectrict.BuyCost > 0 && usingElectrict.Capacity > 0) { ex.WriteToMergeField("BuyPriceResult", Math.Round((usingElectrict.BuyCost / (usingElectrict.Capacity * 1000)), 0).ToString()); } else { ex.WriteToMergeField("BuyPriceResult", ""); } if (usingElectrict.ProduceQty > 0) { ex.WriteToMergeField("ProduceQtyResult", usingElectrict.ProduceQty.ToString()); } else { ex.WriteToMergeField("ProduceQtyResult", ""); } if (usingElectrict.Technology != null) { ex.WriteToMergeField("TechnologyResult", usingElectrict.Technology.ToString()); } else { ex.WriteToMergeField("TechnologyResult", ""); } if (usingElectrict.FuelId > 0) { ex.WriteToMergeField("FuelNameResult", usingElectrict.FuelId.ToString()); } else { ex.WriteToMergeField("FuelNameResult", ""); } } else { ex.WriteToMergeField("QuantityResult2", ""); ex.WriteToMergeField("InstalledCapacityResult2", ""); ex.WriteToMergeField("CapacityResult2", ""); ex.WriteToMergeField("BuyCostResult2", ""); ex.WriteToMergeField("ProduceQtyResult2", ""); ex.WriteToMergeField("TechnologyResult2", ""); ex.WriteToMergeField("FuelNameResult2", ""); ex.WriteToMergeField("PriceProduceResult2", ""); ex.WriteToMergeField("QuantityResult", ""); ex.WriteToMergeField("InstalledCapacityResult", ""); ex.WriteToMergeField("CapacityResult", ""); ex.WriteToMergeField("BuyCostResult", ""); ex.WriteToMergeField("ProduceQtyResult", ""); ex.WriteToMergeField("TechnologyResult", ""); ex.WriteToMergeField("FuelNameResult", ""); } usingElectrict = new UsingElectrict(); usingElectrict = usingElectrictService.GetUsingElectrictByReport(ReportId, true); if (usingElectrict != null) { //Su dung dien 2 if (usingElectrict.Quantity > 0) { ex.WriteToMergeField("QuantityPlan", usingElectrict.Quantity.ToString()); } else { ex.WriteToMergeField("QuantityPlan", ""); } if (usingElectrict.InstalledCapacity > 0) { ex.WriteToMergeField("InstalledCapacityPlan", usingElectrict.InstalledCapacity.ToString()); } else { ex.WriteToMergeField("InstalledCapacityPlan", ""); } if (usingElectrict.Capacity > 0) { ex.WriteToMergeField("CapacityPlan", usingElectrict.Capacity.ToString()); } else { ex.WriteToMergeField("CapacityPlan", ""); } if (usingElectrict.BuyCost > 0) { ex.WriteToMergeField("BuyCostPlan", usingElectrict.BuyCost.ToString()); } else { ex.WriteToMergeField("BuyCostPlan", ""); } if (usingElectrict.BuyCost > 0) { ex.WriteToMergeField("BuyPricePlan", usingElectrict.BuyCost.ToString()); } else { ex.WriteToMergeField("BuyPricePlan", ""); } if (usingElectrict.ProduceQty > 0) { ex.WriteToMergeField("ProduceQtyPlan", usingElectrict.ProduceQty.ToString()); } else { ex.WriteToMergeField("ProduceQtyPlan", ""); } if (usingElectrict.Technology != null) { ex.WriteToMergeField("TechnologyPlan", usingElectrict.Technology.ToString()); } else { ex.WriteToMergeField("TechnologyPlan", ""); } if (usingElectrict.FuelId > 0) { Fuel fuel = new Fuel(); fuel = new FuelService().FindByKey(usingElectrict.FuelId); if (fuel != null) { ex.WriteToMergeField("FuelNamePlan", fuel.FuelName); } else { ex.WriteToMergeField("FuelNamePlan", ""); } } else { ex.WriteToMergeField("FuelNamePlan", ""); } if (usingElectrict.PriceProduce > 0) { ex.WriteToMergeField("PriceProducePlan", usingElectrict.PriceProduce.ToString()); } else { ex.WriteToMergeField("PriceProducePlan", ""); } } else { ex.WriteToMergeField("QuantityPlan", ""); ex.WriteToMergeField("InstalledCapacityPlan", ""); ex.WriteToMergeField("CapacityPlan", ""); ex.WriteToMergeField("BuyCostPlan", ""); ex.WriteToMergeField("ProduceQtyPlan", ""); ex.WriteToMergeField("TechnologyPlan", ""); ex.WriteToMergeField("FuelNamePlan", ""); ex.WriteToMergeField("PriceProducePlan", ""); } DataTable dthientai = new DataTable(); DataTable dtdukien = new DataTable(); DataSet dshientai = new DataSet("tbl1"); DataTable dt = new DataTable(); dt = new ReportFuelDetailService().GetNoFuelDetailByReport(ReportId, false); dt.Columns.Add("dvnhietnang", typeof(string)); dt.Columns.Add("dvnhieulieu", typeof(string)); dthientai = dt.Clone(); foreach (DataRow item in dt.Rows) { DataRow workRow = null; workRow = dthientai.NewRow(); workRow = item; if (workRow["MeasurementName"].ToString().Contains("Mét khối")) { workRow["dvnhietnang"] = "kJ/m3"; } else { workRow["dvnhietnang"] = "kJ/kg"; } if (workRow["MeasurementName"].ToString().Contains("tấn") || workRow["MeasurementName"].ToString().Contains("Klg")) { workRow["dvnhieulieu"] = "kJ/tấn"; } else { workRow["dvnhieulieu"] = "đ/m3"; } workRow.AcceptChanges(); dthientai.AcceptChanges(); dthientai.ImportRow(workRow); } dt = new ReportFuelDetailService().GetNoFuelDetailByReport(ReportId, true); dt.Columns.Add("dvnhietnang", typeof(string)); dt.Columns.Add("dvnhieulieu", typeof(string)); dtdukien = dt.Clone(); foreach (DataRow item in dt.Rows) { DataRow workRow = null; workRow = dtdukien.NewRow(); workRow = item; if (workRow["MeasurementName"].ToString().Contains("Mét khối")) { workRow["dvnhietnang"] = "kJ/m3"; } else { workRow["dvnhietnang"] = "kJ/kg"; } if (workRow["MeasurementName"].ToString().Contains("tấn") || workRow["MeasurementName"].ToString().Contains("Klg")) { workRow["dvnhieulieu"] = "kJ/tấn"; } else { workRow["dvnhieulieu"] = "đ/m3"; } workRow.AcceptChanges(); dtdukien.ImportRow(workRow); dtdukien.AcceptChanges(); } ProductCapacityService productCapacityService = new ProductCapacityService(); DataTable tblProductResult = new DataTable(); tblProductResult = productCapacityService.GetDataCapacity(ReportId, false); dshientai.Merge(tblProductResult); dshientai.Tables[0].TableName = "tbl1"; dshientai.Merge(dthientai); dshientai.Tables[1].TableName = "tbl2"; //ex.WriteDataSetToMergeField(dshientai); DataTable tblProductPlan = new DataTable(); tblProductPlan = productCapacityService.GetDataCapacity(ReportId, true); dshientai.Merge(tblProductPlan); dshientai.Tables[2].TableName = "tbl3"; dshientai.Merge(dtdukien); dshientai.Tables[3].TableName = "tbl4"; //ex.WriteDataSetToMergeField(dshientai); DataSet dsData = new DataSet(); PlanTBService plangpservice = new PlanTBService(); PlanTKNLService plangTKNLservice = new PlanTKNLService(); DataTable tblGPTKNLPlan = new DataTable(); tblGPTKNLPlan = plangTKNLservice.GetPlanTKNLEnerprise(Convert.ToInt32(memVal.OrgId), ReportId, false, true); dshientai.Merge(tblGPTKNLPlan); dshientai.Tables[4].TableName = "tbl5"; DataTable tblTBPlan = new DataTable(); tblTBPlan = plangpservice.GetPlanTBEnterprise(memVal.OrgId, ReportId, false, true); dshientai.Merge(tblTBPlan); dshientai.Tables[5].TableName = "tbl6"; dshientai.Merge(tblProductPlan.Copy()); dshientai.Tables[6].TableName = "tbl7"; dshientai.Merge(dthientai.Copy()); dshientai.Tables[7].TableName = "tbl8"; DataTable tblGPTKNLResult = new DataTable(); tblGPTKNLResult = plangTKNLservice.GetPlanTKNLEnerprise(Convert.ToInt32(memVal.OrgId), ReportId, false, false); dshientai.Merge(tblGPTKNLResult); dshientai.Tables[8].TableName = "tbl9"; DataTable tblTBResult = new DataTable(); tblTBResult = plangpservice.GetPlanTBEnterprise(memVal.OrgId, ReportId, false, false); dshientai.Merge(tblTBResult); dshientai.Tables[9].TableName = "tbl10"; dshientai.Tables.Add(tblTBResult.Copy()); dshientai.Tables[10].TableName = "tbl11"; ex.WriteDataSetToMergeField(dshientai); // dsg.Tables.Add(dst); //var dt2 = ExcelExportHelper.CreateGroupInDT(dt, "DepName", "STT"); #endregion ex.Save(Server.MapPath(ResolveUrl("~") + "TempReport/" + memVal.UserName + ".Bao-cao-hang-nam-" + dtinfo.Rows[0]["Year"] + ".doc")); HttpContext.Current.Response.Redirect(string.Format("~/Download.aspx?fp={0}&fn={1}", System.IO.Path.GetFileName(Server.MapPath(ResolveUrl("~") + "TempReport/" + memVal.UserName + ".Bao-cao-hang-nam-" + dtinfo.Rows[0]["Year"] + ".doc")), "" )); }
protected void btnApproved_Click(object sender, EventArgs e) { try { ReportFuelService faqsBSO = new ReportFuelService(); if (rblApproved.SelectedIndex == 1) { ReportLog log = new ReportLog(); log.ActionName = "Phê duyệt báo cáo"; log.Comment = txtmota.Text; log.ReportId = ReportId; log.Created = DateTime.Now; log.MemberId = memVal.UserId; log.UserName = memVal.UserName; log.Status = "Yêu cầu bổ sung, hiệu chỉnh"; log.LogType = Convert.ToInt32(LogType.ANNUALREPORT); new ReportLogService().Insert(log); if (faqsBSO.UpdateStatusEnterprise(ReportId, 3) > 0) { if (fAttachApp.HasFile) { string strPath = Server.MapPath("~/UserFile/Report/"); try { string strFilename = ""; strFilename = memVal.UserName + "_" + ReportYear + "_" + new Random(10).Next(100) + System.IO.Path.GetExtension(fAttachApp.FileName).ToLower(); if (System.IO.File.Exists(strPath + strFilename)) { strFilename = memVal.UserName + "_" + ReportYear + "_" + new Random(10).Next(100) + System.IO.Path.GetExtension(fAttachApp.FileName).ToLower(); } fAttachApp.PostedFile.SaveAs(strPath + strFilename); ReportAttachFile reportAtt = new ReportAttachFile(); reportAtt.ReportId = ReportId; reportAtt.PathFile = strFilename; reportAtt.Created = DateTime.Now; reportAtt.ActionName = "SCT đã tải file báo cáo"; reportAtt.Comment = txtmota.Text; reportAtt.UserName = memVal.UserName; reportAtt.UserId = memVal.UserId; reportAtt.ReportType = Convert.ToInt32(LogType.ANNUALREPORT); if (new ReportAttachFileService().Insert(reportAtt) > 0) { BindReportFile(); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(this, GetType(), "sendreport", "sendreport();", true); return; } } Response.Redirect(ResolveUrl("~") + "Admin/ListReportProcessing/Default.aspx"); } } else { IFormatProvider culture = new System.Globalization.CultureInfo("en-US", true); if (faqsBSO.ApproveReport(ReportId, DateTime.ParseExact(txtApprovedDate.Text, "dd/MM/yyyy", culture), (rblApproved.SelectedIndex == 0)) > 0) { 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 listDetail = new ReportFuelDetailService().GetTOEByReport(ReportId); decimal SumTOE = 0; decimal SumTOEP = 0; if (listDetail != null && listDetail.Rows.Count > 0) { if (listDetail.Rows.Count > 2) { SumTOE = Convert.ToDecimal(listDetail.Rows[0]["NoFuel_TOE"]); SumTOEP = Convert.ToDecimal(listDetail.Rows[1]["NoFuel_TOE"]); } else { if (Convert.ToBoolean(listDetail.Rows[0]["IsNextYear"])) { SumTOEP = Convert.ToDecimal(listDetail.Rows[0]["NoFuel_TOE"]); } else { SumTOE = Convert.ToDecimal(listDetail.Rows[0]["NoFuel_TOE"]); } } } EnterpriseYearService enterService = new EnterpriseYearService(); int i = enterService.UpdateTOE(EnterpriseId, ReportYear, ReportId, SumTOE, SumTOEP); if (i == 0) { EnterpriseYear enterYear = new EnterpriseYear(); enterYear.IsKey = false; enterYear.No_TOE = SumTOE; enterYear.NoTOE_Plan = SumTOEP; enterYear.Year = ReportYear; enterYear.EnterpriseId = EnterpriseId; enterYear.ReportId = ReportId; enterService.Insert(enterYear); } ReportLog log = new ReportLog(); log.ActionName = "Phê duyệt báo cáo"; log.Comment = txtmota.Text; log.ReportId = ReportId; log.Created = DateTime.Now; log.MemberId = memVal.UserId; log.UserName = memVal.UserName; log.Status = "Đã duyệt báo cáo"; log.LogType = Convert.ToInt32(LogType.ANNUALREPORT); new ReportLogService().Insert(log); Response.Redirect(ResolveUrl("~") + "Admin/ListReportProcessing/Default.aspx"); } else { //clientview.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Xảy ra lỗi chưa phê duyệt được báo cáo. Vui lòng thử lại!</div>"; ScriptManager.RegisterStartupScript(this, GetType(), "showformDetail", "approvedReport();", true); } } } catch (Exception ex) { //clientview.Text = ex.Message.ToString(); } }