예제 #1
0
        public EntityReport ReportOut(string random, string rptKbn, string pgId, string parameters)
        {
            EntityReport        entity;
            EntityReportSetting entitySetting;

            #region 認証処理

            string companyId           = "";
            string groupId             = "";
            string userId              = "";
            string ipAdress            = "";
            string sessionString       = "";
            int    reportSizeUser      = 0;
            int    idFigureCommodity   = 0;
            int    idFigureCustomer    = 0;
            int    idFigurePurchase    = 0;
            int    idFigureSlipNo      = 0;
            int    rpTotalAuthorityKbn = 0;

            try
            {
                companyId           = ExCast.zCStr(HttpContext.Current.Session[ExSession.COMPANY_ID]);
                groupId             = ExCast.zCStr(HttpContext.Current.Session[ExSession.GROUP_ID]);
                userId              = ExCast.zCStr(HttpContext.Current.Session[ExSession.USER_ID]);
                ipAdress            = ExCast.zCStr(HttpContext.Current.Session[ExSession.IP_ADRESS]);
                sessionString       = ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]);
                reportSizeUser      = ExCast.zCInt(HttpContext.Current.Session[ExSession.REPORT_SAVE_SIZE_USER]);
                idFigureCommodity   = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_GOODS]);
                idFigureCustomer    = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_CUSTOMER]);
                idFigurePurchase    = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_PURCHASE]);
                idFigureSlipNo      = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_SLIP_NO]);
                rpTotalAuthorityKbn = ExCast.zCInt(HttpContext.Current.Session[ExSession.REPORT_TOTAL_AUTHORITY_KBN]);

                string _message = ExSession.SessionUserUniqueCheck(random, ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]), ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]));
                if (_message != "")
                {
                    entity         = new EntityReport();
                    entity.MESSAGE = _message;
                    return(entity);
                }
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".ReportOut(認証処理)", ex);
                entity         = new EntityReport();
                entity.MESSAGE = CLASS_NM + ".ReportOut : 認証処理に失敗しました。" + Environment.NewLine + ex.Message.ToString();
                return(entity);
            }

            #endregion

            ExMySQLData db = ExSession.GetSessionDb(ExCast.zCInt(userId), sessionString);

            try
            {
                #region Get Report Setting

                entitySetting = GetReportSetting(random, pgId);

                if (entitySetting == null)
                {
                    entitySetting               = new EntityReportSetting();
                    entitySetting.user_id       = ExCast.zCInt(userId);
                    entitySetting.pg_id         = pgId;
                    entitySetting.group_id_from = ExCast.zCInt(groupId).ToString();
                    entitySetting.group_id_to   = ExCast.zCInt(groupId).ToString();
                }
                else if (entitySetting != null)
                {
                    if (!string.IsNullOrEmpty(entitySetting.MESSAGE))
                    {
                        entitySetting               = new EntityReportSetting();
                        entitySetting.user_id       = ExCast.zCInt(userId);
                        entitySetting.pg_id         = pgId;
                        entitySetting.group_id_from = ExCast.zCInt(groupId).ToString();
                        entitySetting.group_id_to   = ExCast.zCInt(groupId).ToString();
                    }
                    else
                    {
                        if (ExCast.zCInt(entitySetting.group_id_from) == 0 && ExCast.zCInt(entitySetting.group_id_to) == 0)
                        {
                            entitySetting.group_id_from = ExCast.zCInt(groupId).ToString();
                            entitySetting.group_id_to   = ExCast.zCInt(groupId).ToString();
                        }
                    }
                }

                if (rpTotalAuthorityKbn < 2)
                {
                    entitySetting.group_id_from = ExCast.zCInt(groupId).ToString();
                    entitySetting.group_id_to   = ExCast.zCInt(groupId).ToString();
                }

                #endregion

                entity = new EntityReport();

                DataReport.geReportKbn kbn    = (DataReport.geReportKbn)ExCast.zCInt(rptKbn);
                ExReportManeger        rptMgr = new ExReportManeger();
                rptMgr.idFigureCommodity = idFigureCommodity;
                rptMgr.idFigureCustomer  = idFigureCustomer;
                rptMgr.idFigurePurchase  = idFigurePurchase;
                rptMgr.idFigureSlipNo    = idFigureSlipNo;
                rptMgr.entitySetting     = entitySetting;
                rptMgr.rptKbn            = kbn;

                #region Report FilePath Setting

                bool _ret = rptMgr.GetReportFilePath(pgId, companyId, userId);
                if (_ret == false)
                {
                    entity.MESSAGE = CommonUtl.gstrErrMsg;
                    return(entity);
                }
                entity.downLoadFilePath = rptMgr.reportFilePath;
                entity.downLoadFileName = rptMgr.reportFileName;
                entity.downLoadFileSize = rptMgr.reportFileSize.ToString();
                entity.downLoadUrl      = CommonUtl.gstrMainUrl + rptMgr.reportDir;

                #endregion

                DataSet ds = db.GetDataSet(rptMgr.ReportSQL(pgId, companyId, groupId, parameters), rptMgr.GetPGIDXsd(pgId));

                #region Export xsd

                System.IO.StreamWriter xmlSW = null;
                try
                {
                    xmlSW = new System.IO.StreamWriter(CommonUtl.gstrReportTemp + rptMgr.GetPGIDXsd(pgId) + ".xsd");
                    ds.WriteXmlSchema(xmlSW);
                    xmlSW.Close();
                }
                catch (Exception ex)
                {
                    CommonUtl.ExLogger.Error(CLASS_NM + ".WriteXmlSchema", ex);
                }
                finally
                {
                    if (xmlSW != null)
                    {
                        xmlSW.Dispose();
                        xmlSW = null;
                    }
                }

                #endregion

                if (ds.Tables[0].Rows.Count == 0)
                {
                    entity.MESSAGE = "データが存在しません。";
                    entity.ret     = false;
                    return(entity);
                }

                string _fileType     = "";
                string _DownloadType = "";
                switch (kbn)
                {
                case DataReport.geReportKbn.OutPut:
                    _fileType     = "PDF";
                    _DownloadType = "出力";

                    if (rptMgr.ReportToPdf(ds, pgId) == true)
                    {
                        entity.ret = true;
                    }
                    else
                    {
                        entity.MESSAGE = CommonUtl.gstrErrMsg;
                        entity.ret     = false;
                    }
                    break;

                case DataReport.geReportKbn.Download:
                    _fileType     = "PDF";
                    _DownloadType = "ダウンロード";

                    if (rptMgr.ReportToPdf(ds, pgId) == true)
                    {
                        entity.ret = true;
                    }
                    else
                    {
                        entity.MESSAGE = CommonUtl.gstrErrMsg;
                        entity.ret     = false;
                    }
                    break;

                case DataReport.geReportKbn.Csv:
                    _fileType     = "CSV";
                    _DownloadType = "ダウンロード";

                    if (rptMgr.DataTableToCsv(ds.Tables[0]) == true)
                    {
                        entity.ret = true;
                    }
                    else
                    {
                        entity.MESSAGE = CommonUtl.gstrErrMsg;
                        entity.ret     = false;
                    }
                    break;

                default:
                    break;
                }

                //entity.downLoadFilePath = @"d:\HostingSpaces\Users\EW20121725\Sales.system-innovation.net\wwwroot\temp\顧客マスタ一覧.csv";
                //System.IO.FileInfo fi = new System.IO.FileInfo(entity.downLoadFilePath);
                //entity.downLoadFileSize = fi.Length.ToString();
                if (reportSizeUser < ExCast.zCDbl(entity.downLoadFileSize) / 1000000)
                {
                    entity.MESSAGE = _fileType + "ファイルのサイズが" + reportSizeUser.ToString() + "Mバイトを超える為、" + _DownloadType + "できません。";
                    return(entity);
                }
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".ReportOut", ex);
                entity         = new EntityReport();
                entity.MESSAGE = CLASS_NM + ".ReportOut : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString();
                return(entity);
            }

            return(entity);
        }