private void BindUserName(int OrgId) { if (OrgId > 0) { EnterpriseService objlogic = new EnterpriseService(); Enterprise obj = new Enterprise(); obj = objlogic.FindByKey(OrgId); if (obj != null) { lblName.Text = obj.Title; lblEmail.Text = obj.Email; lblAddress.Text = obj.Address; lblTel.Text = obj.Phone; } } }
protected void btn_edit_Click(object sender, EventArgs e) { try { EnterpriseService objlogic = new EnterpriseService(); Enterprise obj = new Enterprise(); obj = objlogic.FindByKey(memVal.OrgId); if (obj != null) { if (ddlProvince.SelectedIndex > 0) { obj.ProvinceId = Convert.ToInt32(ddlProvince.SelectedValue); } if (ddlDistrict.SelectedIndex > 0) { obj.DistrictId = Convert.ToInt32(ddlDistrict.SelectedValue); } if (ddlArea.SelectedIndex > 0) { obj.AreaId = Convert.ToInt32(ddlArea.SelectedValue); } else { obj.AreaId = 0; } if (ddlSubArea.SelectedIndex > 0) { obj.SubAreaId = Convert.ToInt32(ddlSubArea.SelectedValue); } else { obj.SubAreaId = 0; } IFormatProvider culture = new System.Globalization.CultureInfo("en-US", true); obj.TaxCode = txtMST.Text.Trim(); obj.CustomerCode = txtCustomerCode.Text.Trim(); obj.Phone = txtPhone.Text; obj.Email = txtEmail.Text; obj.Fax = txtFax.Text; obj.ManPerson = txtResponsible.Text; obj.Address = txtAddress.Text; obj.OwnerId = Convert.ToInt32(ddlOwner.SelectedValue); obj.ParentName = txtParentName.Text; if (ddlProvinceReporter.SelectedIndex > 0) { obj.ManProvinceId = Convert.ToInt32(ddlProvinceReporter.SelectedValue); } else { obj.ManProvinceId = 0; } if (ddlDistrictReporter.SelectedIndex > 0) { obj.ManDistrictId = Convert.ToInt32(ddlDistrictReporter.SelectedValue); } else { obj.ManDistrictId = 0; } obj.ManAddress = txtAddressReporter.Text; obj.ManPhone = txtPhoneReporter.Text; obj.ManFax = txtFaxReporter.Text; obj.ManEmail = txtManEmail.Text; if (txtActiveYear.Text.Trim() != "") { obj.ActiveYear = Convert.ToInt32(txtActiveYear.Text.Trim()); } int _MoHinhQLNL = 0; if (cbMoHinhQLNL_DaAD.Checked) { _MoHinhQLNL = 1; } if (cbMoHinhQLNL_DaAD_ISO.Checked) { _MoHinhQLNL = 2; } obj.MoHinhQLNL = _MoHinhQLNL; int tmpMoHinhQLNL = obj.MoHinhQLNL; //obj.ReportTemplate = Convert.ToInt32(ddlReportTemplate.SelectedValue); if (memVal.OrgId > 0) { if (objlogic.Update(obj) != null) { try { /*Cap nhat lich su*/ EnterpriseHistory objHist = new EnterpriseHistory(); objHist.Address = obj.Address; objHist.AreaId = obj.AreaId; objHist.DistrictId = obj.DistrictId; objHist.Email = obj.Email; objHist.Fax = obj.Fax; objHist.Id = obj.Id; objHist.Info = obj.Info; objHist.IsActive = obj.IsActive; objHist.IsConfirm = obj.IsConfirm; objHist.IsDelete = obj.IsDelete; objHist.IsImportant = obj.IsImportant; objHist.ManAddress = obj.ManAddress; objHist.ManDistrictId = obj.ManDistrictId; objHist.ManEmail = obj.ManEmail; objHist.ManFax = obj.ManFax; objHist.ManPerson = obj.ManPerson; objHist.ManPhone = obj.ManPhone; objHist.ManProvinceId = obj.ManProvinceId; objHist.MST = obj.TaxCode; objHist.OrganizationId = obj.OrganizationId; objHist.ParentName = obj.ParentName; objHist.Phone = obj.Phone; objHist.ProvinceId = obj.ProvinceId; objHist.ShortName = obj.ShortName; objHist.SubAreaId = obj.SubAreaId; objHist.Title = obj.Title; objHist.MoHinhQLNL = tmpMoHinhQLNL; new EnterpriseHistoryService().Insert(objHist); } catch { } error.Text = "<div class='alert alert-sm alert-success bg-gradient'>Cập nhật thành công !</div>"; } else { error.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Cập nhật không thành công !</div>"; } } } } catch (Exception ex) { error.Text = ex.Message.ToString(); } }
private void BindData() { if (memVal.UserId > 0 && memVal.OrgId > 0) { EnterpriseService objlogic = new EnterpriseService(); Enterprise obj = new Enterprise(); obj = objlogic.FindByKey(Convert.ToInt32(memVal.OrgId)); if (obj != null) { txtTitle.Text = obj.Title; try { if (obj.ProvinceId > 0) { ddlProvince.SelectedValue = obj.ProvinceId.ToString(); BindDistrict(); if (obj.DistrictId > 0) { ddlDistrict.SelectedValue = obj.DistrictId.ToString(); } } } catch { } if (obj.AreaId > 0) { ddlArea.SelectedValue = obj.AreaId.ToString(); BindSubArea(); if (obj.SubAreaId > 0) { ddlSubArea.SelectedValue = obj.SubAreaId.ToString(); } } //if (obj.ReportTemplate != null && obj.ReportTemplate > 0) // ddlReportTemplate.SelectedValue = obj.ReportTemplate.ToString(); txtMST.Text = obj.TaxCode; txtCustomerCode.Text = obj.CustomerCode; txtPhone.Text = obj.Phone; txtFax.Text = obj.Fax; txtEmail.Text = obj.Email; txtResponsible.Text = obj.ManPerson; txtAddress.Text = obj.Address; if (obj.OwnerId > 0) { ddlOwner.SelectedValue = obj.OwnerId.ToString(); } txtNote.Text = obj.Info; txtParentName.Text = obj.ParentName; if (obj.ManProvinceId > 0) { ddlProvinceReporter.SelectedValue = obj.ManProvinceId.ToString(); BindDistrictReporter(); if (obj.ManDistrictId > 0) { ddlDistrictReporter.SelectedValue = obj.ManDistrictId.ToString(); } } if (obj.ActiveYear > 0) { txtActiveYear.Text = obj.ActiveYear.ToString(); } txtAddressReporter.Text = obj.ManAddress; txtPhoneReporter.Text = obj.ManPhone; txtFaxReporter.Text = obj.ManFax; txtManEmail.Text = obj.ManEmail; int _MoHinhQLNL = obj.MoHinhQLNL; switch (_MoHinhQLNL) { case 0: cbMoHinhQLNL_ChuaAD.Checked = true; break; case 1: cbMoHinhQLNL_DaAD.Checked = true; break; case 2: cbMoHinhQLNL_DaAD_ISO.Checked = true; break; } ePower.DE.Domain.Member member = new ePower.DE.Domain.Member(); member = new MemberService().FindByKey(memVal.UserId); if (member != null) { ltrAdminName.Text = member.AccountName; txtAdminName.Text = member.AccountName; txtAdminEmail.Text = member.Email; txtAddressMember.Text = member.Address; txtFullName.Text = member.FullName; txtPhoneMember.Text = member.Phone; } } } }
private void BindData() { if (ItemId > 0) { EnterpriseService objlogic = new EnterpriseService(); Enterprise obj = new Enterprise(); obj = objlogic.FindByKey(ItemId); if (obj != null) { txtTitle.Text = obj.Title; if (obj.AreaId > 0) { ddlArea.SelectedValue = obj.AreaId.ToString(); BindSubArea(); if (obj.SubAreaId > 0) { ddlSubArea.SelectedValue = obj.SubAreaId.ToString(); } } if (obj.ProvinceId > 0) { ddlProvince.SelectedValue = obj.ProvinceId.ToString(); BindDistrict(); if (obj.DistrictId > 0) { ddlDistrict.SelectedValue = obj.DistrictId.ToString(); } } txtMST.Text = obj.TaxCode; txtCustomerCode.Text = obj.CustomerCode; txtPhone.Text = obj.Phone; txtFax.Text = obj.Fax; txtEmail.Text = obj.Email; txtResponsible.Text = obj.ManPerson; txtAddress.Text = obj.Address; if (obj.OwnerId > 0) { ddlOwner.SelectedValue = obj.OwnerId.ToString(); } cbxActive.Checked = obj.IsActive; if (obj.ActiveYear > 0) { txtAtiveYear.Text = obj.ActiveYear.ToString(); } txtNote.Text = obj.Info; OrgId = obj.OrganizationId; txtParentName.Text = obj.ParentName; if (obj.ManProvinceId > 0) { ddlProvinceReporter.SelectedValue = obj.ManProvinceId.ToString(); BindDistrictReporter(); if (obj.ManDistrictId > 0) { ddlDistrictReporter.SelectedValue = obj.ManDistrictId.ToString(); } } txtAddressReporter.Text = obj.ManAddress; txtPhoneReporter.Text = obj.ManPhone; txtFaxReporter.Text = obj.ManFax; txtManEmail.Text = obj.ManEmail; } } //if (ImportantYears != "" && ImportantYears.Contains(DateTime.Today.ToString("yyyy"))) //{ // divImportantYear.Visible = false; //} //else divImportantYear.Visible = true; }
protected void voidbindexcel(int Idbaocao) { #region get data WordExtend ex = new WordExtend(); string temp = "TempReport/TemMauBaoCao" + drpmaubaocao.SelectedValue + ".dot"; ex.OpenFile(Server.MapPath(ResolveUrl("~") + temp)); Enterprise or = new Enterprise(); EnterpriseService orser = new EnterpriseService(); or = orser.FindByKey(Convert.ToInt32(memVal.OrgId)); if (or != null) { ex.WriteToMergeField("BC_Title", or.Title); } else { ex.WriteToMergeField("BC_Title", ""); } ex.WriteToMergeField("BC_Year", DateTime.Now.Year.ToString()); ex.WriteToMergeField("BC_NgayLap", DateTime.Now.ToString("dd/MM/yyyy")); DataTable dt = new DataTable(); DataTable dthientai = new DataTable(); DataTable dtdukien = new DataTable(); DataSet dshientai = new DataSet("tbl1"); DataSet dsdukien = new DataSet("tbl1"); if (memVal.OrgId > 0) { dt = new ReportFuelService().GetReportByxuatphieu(Idbaocao); } // DataRow dr; dt.Columns.Add("dvnhietnang", typeof(string)); dt.Columns.Add("dvnhieulieu", typeof(string)); dthientai = dt.Clone(); dtdukien = dt.Clone(); foreach (DataRow item in dt.Rows) { if (Convert.ToBoolean(item["IsNextYear"]) == true) { 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(); } else { 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); } } dshientai.Merge(dthientai); if (dshientai.Tables.Count > 0) { dshientai.Tables[0].TableName = "tbl1"; ex.WriteDataSetToMergeField(dshientai); } dsdukien.Merge(dtdukien); if (dsdukien.Tables.Count > 0) { dsdukien.Tables[0].TableName = "tbl2"; ex.WriteDataSetToMergeField(dsdukien); } // dsg.Tables.Add(dst); //var dt2 = ExcelExportHelper.CreateGroupInDT(dt, "DepName", "STT"); #endregion ex.Save(Server.MapPath(ResolveUrl("~") + "TempReport/mauBaoCao.dot")); HttpContext.Current.Response.Redirect(string.Format("~/Download.aspx?fp={0}&fn={1}", Path.GetFileName(Server.MapPath(ResolveUrl("~") + "TempReport/mauBaoCao.dot")), "" )); }
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 btnExportWord_Click(object sender, EventArgs e) { #region get data WordExtend ex = new WordExtend(); string temp = "TempReport/TemMauBaoCao1_1.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", memVal.UserName); 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) { int iCurrentYear = Convert.ToInt32(dtinfo.Rows[0]["Year"]); string NextYear = dtinfo.Rows[0]["Year"].ToString(); ex.WriteToMergeField("BC_NextYear", NextYear); } 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); ex.WriteToMergeField("BC_Owner", ""); 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", ""); DataTable dthientai = new DataTable(); DataSet dshientai = new DataSet("tbl1"); DataTable tblProductResult = CreateFuelData(); DataTable dtElectrict = GetFuelGroup(tblProductResult, ReportKey.FuelGroupKey_POWER, "="); DataTable dtNotElectrict = GetFuelGroup(tblProductResult, ReportKey.FuelGroupKey_POWER, "<>"); dshientai.Merge(dtNotElectrict); dshientai.Tables[0].TableName = "tbl1"; int k = 1; foreach (DataRow r in dtElectrict.Rows) { string eName = string.Format("e{0}Name", k); ex.WriteToMergeField(eName, r["FuelName"].ToString()); string e1Me = string.Format("e{0}Me", k); ex.WriteToMergeField(e1Me, r["MeasurementName"].ToString()); string e1No = string.Format("e{0}No", k); ex.WriteToMergeField(e1No, r["NoFuel"].ToString()); string e1Reason = string.Format("e{0}Reason", k); ex.WriteToMergeField(e1Reason, r["Reason"].ToString()); k++; } ex.WriteDataSetToMergeField(dshientai); #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")), "" )); }