Ejemplo n.º 1
0
    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")),
                                                            ""
                                                            ));
    }
Ejemplo n.º 2
0
    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")),
                                                            ""
                                                            ));
    }
Ejemplo n.º 3
0
    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")),
                                                            ""
                                                            ));
    }