Exemplo n.º 1
0
        public ActionResult ExportData_IU(ApplicationHeaderInfo pInfo, App_Detail_PLD01_HDCN_Info pDetail,
                                          List <AppDocumentInfo> pAppDocumentInfo, List <AppFeeFixInfo> pFeeFixInfo)
        {
            try
            {
                string language = AppsCommon.GetCurrentLang();

                // Fill export_header
                string fileName_docx = System.Web.HttpContext.Current.Server.MapPath("/Content/Export/" + "D01_VI_" + TradeMarkAppCode.AppCode_TM_4C2_PLD_01_HDCN + ".docx");

                AppsCommon.Prepare_Data_Export_D01(ref pDetail, pInfo, pAppDocumentInfo, pFeeFixInfo);

                List <App_Detail_PLD01_HDCN_Info> _lst = new List <App_Detail_PLD01_HDCN_Info>();
                _lst.Add(pDetail);

                DataSet _ds_all = ConvertData.ConvertToDataSet <App_Detail_PLD01_HDCN_Info>(_lst, false);
                _ds_all.Tables[0].TableName = "Table_4c2";

                CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

                string _tempfile    = "TM_PLD01_HDCN.rpt";
                string _datetimenow = DateTime.Now.ToString("ddMMyyyyHHmm");
                string fileName_pdf = System.Web.HttpContext.Current.Server.MapPath("/Content/Export/" + "D01_VN_" + _datetimenow + ".pdf");
                if (language == Language.LangVI)
                {
                    fileName_pdf = System.Web.HttpContext.Current.Server.MapPath("/Content/Export/" + "D01_VN_" + _datetimenow + ".pdf");
                    SessionData.CurrentUser.FilePreview = "/Content/Export/" + "D01_VN_" + _datetimenow + ".pdf";
                }
                else
                {
                    _tempfile    = "TM_PLD01_HDCN_EN.rpt"; // tiếng anh
                    fileName_pdf = System.Web.HttpContext.Current.Server.MapPath("/Content/Export/" + "D01_EN_" + _datetimenow + ".pdf");
                    SessionData.CurrentUser.FilePreview = "/Content/Export/" + "D01_EN_" + _datetimenow + ".pdf";
                }
                oRpt.Load(Path.Combine(Server.MapPath("~/Report/"), _tempfile));
                //oRpt.Load(Path.Combine(Server.MapPath("~/Report/"), "TM_PLD01_HDCN.rpt"));

                if (_ds_all != null)
                {
                    oRpt.SetDataSource(_ds_all);
                }
                oRpt.Refresh();

                Response.Buffer = false;
                Response.ClearContent();
                Response.ClearHeaders();

                System.IO.Stream oStream   = oRpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                byte[]           byteArray = new byte[oStream.Length];
                oStream.Read(byteArray, 0, Convert.ToInt32(oStream.Length - 1));
                System.IO.File.WriteAllBytes(fileName_pdf, byteArray.ToArray()); // Requires System.Linq

                return(Json(new { success = 0 }));
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                return(Json(new { success = 0 }));
            }
        }
Exemplo n.º 2
0
        public ActionResult ExportData_View(decimal pAppHeaderId, string p_appCode, decimal p_View_Translate)
        {
            try
            {
                string language = AppsCommon.GetCurrentLang();
                ApplicationHeaderInfo      applicationHeaderInfo = new ApplicationHeaderInfo();
                App_Detail_PLD01_HDCN_Info app_Detail            = new App_Detail_PLD01_HDCN_Info();
                List <AppFeeFixInfo>       appFeeFixInfos        = new List <AppFeeFixInfo>();
                List <AppDocumentInfo>     appDocumentInfos      = new List <AppDocumentInfo>();

                App_Detail_PLD01_HDCN_BL objBL = new App_Detail_PLD01_HDCN_BL();
                app_Detail = objBL.GetByID(pAppHeaderId, language, ref applicationHeaderInfo, ref appDocumentInfos, ref appFeeFixInfos);

                string        _fileTemp = System.Web.HttpContext.Current.Server.MapPath("/Content/AppForms/D01_VI.docx");
                DocumentModel document  = DocumentModel.Load(_fileTemp);

                AppsCommon.Prepare_Data_Export_D01(ref app_Detail, applicationHeaderInfo, appDocumentInfos, appFeeFixInfos);

                List <App_Detail_PLD01_HDCN_Info> _lst = new List <App_Detail_PLD01_HDCN_Info>();
                _lst.Add(app_Detail);

                DataSet _ds_all = ConvertData.ConvertToDataSet <App_Detail_PLD01_HDCN_Info>(_lst, false);
                _ds_all.Tables[0].TableName = "Table_4c2";
                CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

                string _datetimenow = DateTime.Now.ToString("ddMMyyyyHHmm");
                string _tempfile    = "TM_PLD01_HDCN.rpt";
                string fileName_pdf = System.Web.HttpContext.Current.Server.MapPath("/Content/Export/" + "D01_VN_" + _datetimenow + ".pdf");
                if (p_View_Translate == 1)
                {
                    // nếu là tiếng việt thì xem bản tiếng anh và ngược lại
                    if (applicationHeaderInfo.Languague_Code == Language.LangVI)
                    {
                        _tempfile    = "TM_PLD01_HDCN_EN.rpt"; // tiếng anh
                        fileName_pdf = System.Web.HttpContext.Current.Server.MapPath("/Content/Export/" + "D01_EN_" + _datetimenow + ".pdf");
                        SessionData.CurrentUser.FilePreview = "/Content/Export/" + "D01_EN_" + _datetimenow + ".pdf";
                    }
                    else
                    {
                        fileName_pdf = System.Web.HttpContext.Current.Server.MapPath("/Content/Export/" + "D01_VN_" + _datetimenow + ".pdf");
                        SessionData.CurrentUser.FilePreview = "/Content/Export/" + "D01_VN_" + _datetimenow + ".pdf";
                    }
                }
                else
                {
                    if (applicationHeaderInfo.Languague_Code == Language.LangVI)
                    {
                        fileName_pdf = System.Web.HttpContext.Current.Server.MapPath("/Content/Export/" + "D01_VN_" + _datetimenow + ".pdf");
                        SessionData.CurrentUser.FilePreview = "/Content/Export/" + "D01_VN_" + _datetimenow + ".pdf";
                    }
                    else
                    {
                        _tempfile    = "TM_PLD01_HDCN_EN.rpt"; // tiếng anh
                        fileName_pdf = System.Web.HttpContext.Current.Server.MapPath("/Content/Export/" + "D01_EN_" + _datetimenow + ".pdf");
                        SessionData.CurrentUser.FilePreview = "/Content/Export/" + "D01_EN_" + _datetimenow + ".pdf";
                    }
                }
                oRpt.Load(Path.Combine(Server.MapPath("~/Report/"), _tempfile));
                if (_ds_all != null)
                {
                    oRpt.SetDataSource(_ds_all);
                }
                oRpt.Refresh();

                Response.Buffer = false;
                Response.ClearContent();
                Response.ClearHeaders();

                System.IO.Stream oStream   = oRpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                byte[]           byteArray = new byte[oStream.Length];
                oStream.Read(byteArray, 0, Convert.ToInt32(oStream.Length - 1));
                System.IO.File.WriteAllBytes(fileName_pdf, byteArray.ToArray()); // Requires System.Linq

                return(Json(new { success = 0 }));
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                return(Json(new { success = 0 }));
            }
        }