public List<EntitySales> GetSalesList(string random, string strWhereSql, string strSalesBySql)
        {
            List<EntitySales> entityList = new List<EntitySales>();

            #region 認証処理

            string companyId = "";
            string groupId = "";
            string userId = "";
            string ipAdress = "";
            string sessionString = "";
            int idFigureCommodity = 0;
            int idFigureCustomer = 0;
            int idFigurePurchase = 0;
            int idFigureSlipNo = 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]);
                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]);
                
                string _message = ExSession.SessionUserUniqueCheck(random, ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]), ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]));
                if (_message != "")
                {
                    EntitySales entity = new EntitySales();
                    entity.MESSAGE = _message;
                    entityList.Add(entity);
                    return entityList;
                }
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetSalesList(認証処理)", ex);
                EntitySales entity = new EntitySales();
                entity.MESSAGE = "認証処理に失敗しました。" + Environment.NewLine + ex.Message.ToString(); ;
                entityList.Add(entity);
                return entityList;
            }
            #endregion

            StringBuilder sb;
            DataTable dt;
            ExMySQLData db;

            try
            {
                db = ExSession.GetSessionDb(ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]),
                                            ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]));

                sb = new StringBuilder();

                ExReportManeger rptMgr = new ExReportManeger();
                rptMgr.idFigureCommodity = idFigureCommodity;
                rptMgr.idFigureCustomer = idFigureCustomer;
                rptMgr.idFigurePurchase = idFigurePurchase;
                rptMgr.idFigureSlipNo = idFigureSlipNo;
                sb.Append(rptMgr.GetSalesListReportSQL(companyId, groupId, strWhereSql, strSalesBySql));

                dt = db.GetDataTable(sb.ToString());

                if (dt.DefaultView.Count > 0)
                {
                    for (int i = 0; i <= dt.DefaultView.Count - 1; i++)
                    {
                        entityList.Add(new EntitySales(ExCast.zCLng(dt.DefaultView[i]["ID"]),
                                                       ExCast.zCLng(dt.DefaultView[i]["NO"]),
                                                       ExCast.zCLng(dt.DefaultView[i]["ESTIMATENO"]),
                                                       ExCast.zCLng(dt.DefaultView[i]["ORDER_NO"]),
                                                       ExCast.zDateNullToDefault(dt.DefaultView[i]["SALES_YMD"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["CUSTOMER_ID"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["CUSTOMER_NM"]),
                                                       ExCast.zCInt(dt.DefaultView[i]["TAX_CHANGE_ID"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["TAX_CHANGE_NM"]),
                                                       ExCast.zCInt(dt.DefaultView[i]["BUSINESS_DIVISION_ID"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["BISNESS_DIVISON_NM"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["SUPPLIER_ID"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["SUPPLIER_NM"]),
                                                       ExCast.zDateNullToDefault(dt.DefaultView[i]["SUPPLY_YMD"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["MEMO"]),
                                                       ExCast.zCInt(dt.DefaultView[i]["INPUT_PERSON"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["INPUT_PERSON_NM"]),
                                                       ExCast.zCInt(dt.DefaultView[i]["REC_NO"]),
                                                       ExCast.zCInt(dt.DefaultView[i]["BREAKDOWN_ID"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["BREAKDOWN_NM"]),
                                                       ExCast.zCInt(dt.DefaultView[i]["DELIVER_DIVISION_ID"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["DELIVER_DIVISION_NM"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["COMMODITY_ID"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["COMMODITY_NAME"]),
                                                       ExCast.zCInt(dt.DefaultView[i]["UNIT_ID"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["UNIT_NM"]),
                                                       ExCast.zCInt(dt.DefaultView[i]["ENTER_NUMBER"]),
                                                       ExCast.zCDbl(dt.DefaultView[i]["NUMBER"]),
                                                       ExCast.zCDbl(dt.DefaultView[i]["UNIT_PRICE"]),
                                                       ExCast.zCDbl(dt.DefaultView[i]["PRICE"]),
                                                       ExCast.zCStr(dt.DefaultView[i]["D_MEMO"])));
                    }
                }

            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetSalesList", ex);
                entityList.Clear();
                EntitySales entity = new EntitySales();
                entity.MESSAGE = CLASS_NM + ".GetSalesList : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString();
                entityList.Add(entity);
            }
            finally
            {
                db = null;
            }

            svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]), 
                                       companyId,
                                       userId,
                                       ipAdress,
                                       sessionString,
                                       DataPgEvidence.PGName.Sales.SalesList,
                                       DataPgEvidence.geOperationType.Select,
                                       "Where:" + strWhereSql + ",Salesby:" + strSalesBySql);

            return entityList;

        }
        public List<EntityPaymentClose> GetPaymentList(string random, string strWhereSql, string strOrderBySql)
        {
            List<EntityPaymentClose> entityList = new List<EntityPaymentClose>();

            #region 認証処理

            string companyId = "";
            string groupId = "";
            string userId = "";
            string ipAdress = "";
            string sessionString = "";
            int idFigureCommodity = 0;
            int idFigurePurchase = 0;
            int idFigureCustomer = 0;
            int idFigureSlipNo = 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]);
                idFigureCommodity = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_GOODS]);
                idFigurePurchase = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_PURCHASE]);
                idFigureCustomer = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_CUSTOMER]);
                idFigureSlipNo = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_SLIP_NO]);

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

            StringBuilder sb;
            DataTable dt;
            ExMySQLData db;

            try
            {
                db = ExSession.GetSessionDb(ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]),
                                            ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]));

                sb = new StringBuilder();

                ExReportManeger rptMgr = new ExReportManeger();
                rptMgr.idFigureCommodity = idFigureCommodity;
                rptMgr.idFigureCustomer = idFigureCustomer;
                rptMgr.idFigurePurchase = idFigurePurchase;
                rptMgr.idFigureSlipNo = idFigureSlipNo;
                sb.Append(rptMgr.GetPaymentListReportSQL(companyId, groupId, strWhereSql, strOrderBySql));

                dt = db.GetDataTable(sb.ToString());

                if (dt.DefaultView.Count > 0)
                {
                    for (int i = 0; i <= dt.DefaultView.Count - 1; i++)
                    {
                        #region Set Entity

                        EntityPaymentClose entity = new EntityPaymentClose();

                        entity.no = ExCast.zCStr(dt.DefaultView[i]["NO"]);
                        entity.purchase_id = ExCast.zCStr(dt.DefaultView[i]["PURCHASE_ID"]);
                        entity.purchase_nm = ExCast.zCStr(dt.DefaultView[i]["PURCHASE_NM"]);
                        entity.payment_close_yyyymmdd = ExCast.zDateNullToDefault(dt.DefaultView[i]["PAYMENT_YYYYMMDD"]);
                        entity.summing_up_group_id = ExCast.zCStr(dt.DefaultView[i]["SUMMING_UP_GROUP_ID"]);
                        entity.summing_up_group_nm = ExCast.zCStr(dt.DefaultView[i]["SUMMING_UP_GROUP_NM"]);
                        entity.person_id = ExCast.zCInt(dt.DefaultView[i]["INPUT_PERSON"]);
                        entity.person_nm = ExCast.zCStr(dt.DefaultView[i]["INPUT_PERSON_NM"]);

                        entity.payment_plan_day = ExCast.zDateNullToDefault(dt.DefaultView[i]["PAYMENT_PLAN_DAY"]);
                        entity.payment_day = ExCast.zCInt(dt.DefaultView[i]["PAYMENT_DAY"]);

                        entity.before_payment_yyyymmdd = ExCast.zDateNullToDefault(dt.DefaultView[i]["BEFORE_PAYMENT_yyyymmdd"]);

                        entity.before_payment_price = ExCast.zCDbl(dt.DefaultView[i]["BEFORE_PAYMENT_PRICE"]);
                        entity.before_payment_price_upd = ExCast.zCDbl(dt.DefaultView[i]["BEFORE_PAYMENT_PRICE"]);
                        entity.payment_cash_price = ExCast.zCDbl(dt.DefaultView[i]["PAYMENT_CASH_PRICE"]);
                        entity.transfer_price = ExCast.zCDbl(dt.DefaultView[i]["TRANSFER_PRICE"]);
                        entity.purchase_price = ExCast.zCDbl(dt.DefaultView[i]["PURCHASE_PRICE"]);
                        entity.no_tax_purchase_price = ExCast.zCDbl(dt.DefaultView[i]["NO_TAX_PURCHASE_PRICE"]);
                        entity.tax = ExCast.zCDbl(dt.DefaultView[i]["TAX"]);

                        entity.payment_price = ExCast.zCDbl(dt.DefaultView[i]["PAYMENT_PRICE"]);

                        // 外税額=税抜金額+消費税額-金額(外税を含めない金額)
                        entity.out_tax = ExCast.zCDbl(dt.DefaultView[i]["OUT_TAX"]);

                        entity.payment_kbn = ExCast.zCInt(dt.DefaultView[i]["PAYMENT_KBN"]);
                        //entity.invoice_kbn_nm = ExCast.zCStr(dt.DefaultView[i]["INVOICE_KBN_NM"]);

                        entity.payment_print_flg = ExCast.zCInt(dt.DefaultView[i]["PAYMENT_PRINT_FLG"]);
                        entity.payment_print_flg_nm = ExCast.zCStr(dt.DefaultView[i]["PAYMENT_PRINT_FLG_NM"]);

                        entity.this_payment_cash_price = ExCast.zCDbl(dt.DefaultView[i]["THIS_PAYMENT_CASH_PRICE"]);

                        entity.payment_cash_receivable_kbn = ExCast.zCInt(dt.DefaultView[i]["PAYMENT_RECEIVABLE_KBN"]);
                        entity.payment_cash_receivable_kbn_nm = ExCast.zCStr(dt.DefaultView[i]["PAYMENT_RECEIVABLE_KBN_NM"]);

                        entity.payment_zan_price = ExCast.zCDbl(dt.DefaultView[i]["PAYMENT_ZAN_PRICE"]);

                        entity.memo = ExCast.zCStr(dt.DefaultView[i]["MEMO"]);

                        entity.payment_exists_flg = 0;
                        entity.exec_flg = false;

                        entity.lock_flg = 0;

                        entityList.Add(entity);

                        #endregion

                    }
                }

            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetPaymentList", ex);
                entityList.Clear();
                EntityPaymentClose entity = new EntityPaymentClose();
                entity.MESSAGE = CLASS_NM + ".GetPaymentList : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString();
                entityList.Add(entity);
            }
            finally
            {
                db = null;
            }

            svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                       companyId,
                                       userId,
                                       ipAdress,
                                       sessionString,
                                       DataPgEvidence.PGName.Order.OrderList,
                                       DataPgEvidence.geOperationType.Select,
                                       "Where:" + strWhereSql + ",Orderby:" + strOrderBySql);

            return entityList;

        }
        public List<EntityEstimate> GetEstimateList(string random, string strWhereSql, string strEstimateBySql)
        {
            List<EntityEstimate> entityList = new List<EntityEstimate>();

            #region 認証処理

            string companyId = "";
            string groupId = "";
            string userId = "";
            string ipAdress = "";
            string sessionString = "";
            int idFigureCommodity = 0;
            int idFigureCustomer = 0;
            int idFigurePurchase = 0;
            int idFigureSlipNo = 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]);
                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]);

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

            StringBuilder sb;
            DataTable dt;
            ExMySQLData db;

            try
            {
                db = ExSession.GetSessionDb(ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]),
                                            ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]));

                sb = new StringBuilder();

                ExReportManeger rptMgr = new ExReportManeger();
                rptMgr.idFigureCommodity = idFigureCommodity;
                rptMgr.idFigureCustomer = idFigureCustomer;
                rptMgr.idFigurePurchase = idFigurePurchase;
                rptMgr.idFigureSlipNo = idFigureSlipNo;
                sb.Append(rptMgr.GetEstimateListReportSQL(companyId, groupId, strWhereSql, strEstimateBySql));

                dt = db.GetDataTable(sb.ToString());

                if (dt.DefaultView.Count > 0)
                {
                    for (int i = 0; i <= dt.DefaultView.Count - 1; i++)
                    {

                        #region Set Entity

                        EntityEstimate _entity = new EntityEstimate();

                        _entity.ID = ExCast.zCLng(dt.DefaultView[i]["ID"]);
                        _entity.NO = ExCast.zFormatForID(dt.DefaultView[i]["NO"], idFigureSlipNo);
                        _entity.ESTIMATE_YMD = ExCast.zDateNullToDefault(dt.DefaultView[i]["Estimate_YMD"]);
                        _entity.CUSTOMER_ID = ExCast.zFormatForID(dt.DefaultView[i]["CUSTOMER_ID"], idFigureCustomer);
                        _entity.CUSTOMER_NM = ExCast.zCStr(dt.DefaultView[i]["CUSTOMER_NM"]);
                        _entity.CUSTOMER_PERSON_NAME = ExCast.zCStr(dt.DefaultView[i]["CUSTOMER_PERSON_NAME"]);
                        _entity.TITLE_NAME = ExCast.zCStr(dt.DefaultView[i]["TITLE_NAME"]);
                        //if (_entity.CUSTOMER_PERSON_NAME == "")
                        //{
                        //    _entity.TITLE_NAME2 = "";
                        //}
                        //else
                        //{
                        //    _entity.TITLE_NAME = "";
                        //    _entity.TITLE_NAME2 = ExCast.zCStr(dt.DefaultView[i]["TITLE_NAME"]); 
                        //}
                        _entity.TAX_CHANGE_ID = ExCast.zCInt(dt.DefaultView[i]["TAX_CHANGE_ID"]);
                        _entity.TAX_CHANGE_NM = ExCast.zCStr(dt.DefaultView[i]["TAX_CHANGE_NM"]);
                        _entity.BUSINESS_DIVISION_ID = ExCast.zCInt(dt.DefaultView[i]["BUSINESS_DIVISION_ID"]);
                        _entity.BUSINESS_DIVISION_NM = ExCast.zCStr(dt.DefaultView[i]["BISNESS_DIVISON_NM"]);
                        _entity.SUPPLIER_ID = ExCast.zFormatForID(dt.DefaultView[i]["SUPPLIER_ID"], idFigureCustomer);
                        _entity.SUPPLIER_NM = ExCast.zCStr(dt.DefaultView[i]["SUPPLIER_NM"]);
                        _entity.SUPPLY_YMD = ExCast.zDateNullToDefault(dt.DefaultView[i]["SUPPLY_YMD"]).Replace(" 頃", "");
                        _entity.TIME_LIMIT_YMD = ExCast.zDateNullToDefault(dt.DefaultView[i]["TIME_LIMIT_YMD"]).Replace(" 頃迄", "");
                        _entity.MEMO = ExCast.zCStr(dt.DefaultView[i]["MEMO"]);
                        _entity.UPDATE_PERSON_ID = ExCast.zCInt(dt.DefaultView[i]["INPUT_PERSON"]);
                        _entity.UPDATE_PERSON_NM = ExCast.zCStr(dt.DefaultView[i]["INPUT_PERSON_NM"]);

                        _entity.COMPANY_NM = ExCast.zCStr(dt.DefaultView[i]["COMPANY_NM"]);
                        string _zip_code = String.Format("{0:0000000}", ExCast.zCDbl(dt.DefaultView[i]["COMPANY_ZIP_CODE"]));
                        _zip_code = _zip_code.Substring(0, 3) + "-" + _zip_code.Substring(3, 4);
                        _entity.COMPANY_ZIP_CODE = _zip_code;
                        _entity.COMPANY_ADRESS1 = ExCast.zCStr(dt.DefaultView[i]["COMPANY_ADRESS1"]);
                        _entity.COMPANY_ADRESS2 = ExCast.zCStr(dt.DefaultView[i]["COMPANY_ADRESS2"]);
                        _entity.COMPANY_TEL = ExCast.zCStr(dt.DefaultView[i]["COMPANY_TEL"]);
                        _entity.COMPANY_FAX = ExCast.zCStr(dt.DefaultView[i]["COMPANY_FAX"]);
                        _entity.COMPANY_MAIL_ADRESS = ExCast.zCStr(dt.DefaultView[i]["COMPANY_MAIL_ADRESS"]);
                        _entity.COMPANY_URL = ExCast.zCStr(dt.DefaultView[i]["COMPANY_URL"]);

                        _entity.REC_NO = ExCast.zCInt(dt.DefaultView[i]["REC_NO"]);
                        _entity.BREAKDOWN_ID = ExCast.zCInt(dt.DefaultView[i]["BREAKDOWN_ID"]);
                        _entity.BREAKDOWN_NM = ExCast.zCStr(dt.DefaultView[i]["BREAKDOWN_NM"]);
                        _entity.DELIVER_DIVISION_ID = ExCast.zCInt(dt.DefaultView[i]["DELIVER_DIVISION_ID"]);
                        _entity.DELIVER_DIVISION_NM = ExCast.zCStr(dt.DefaultView[i]["DELIVER_DIVISION_NM"]);
                        _entity.COMMODITY_ID = ExCast.zFormatForID(dt.DefaultView[i]["COMMODITY_ID"], idFigureCommodity);
                        _entity.COMMODITY_NAME = ExCast.zCStr(dt.DefaultView[i]["COMMODITY_NAME"]);
                        _entity.UNIT_ID = ExCast.zCInt(dt.DefaultView[i]["UNIT_ID"]);
                        _entity.UNIT_NM = ExCast.zCStr(dt.DefaultView[i]["UNIT_NM"]);
                        _entity.ENTER_NUMBER = ExCast.zCInt(dt.DefaultView[i]["ENTER_NUMBER"]);
                        _entity.NUMBER = ExCast.zCDbl(dt.DefaultView[i]["NUMBER"]);
                        _entity.UNIT_PRICE = ExCast.zCDbl(dt.DefaultView[i]["UNIT_PRICE"]);
                        _entity.PRICE = ExCast.zCDbl(dt.DefaultView[i]["PRICE"]);
                        _entity.D_MEMO = ExCast.zCStr(dt.DefaultView[i]["D_MEMO"]);
                        entityList.Add(_entity);

                        #endregion

                    }
                }

            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetEstimateList", ex);
                entityList.Clear();
                EntityEstimate entity = new EntityEstimate();
                entity.MESSAGE = CLASS_NM + ".GetEstimateList : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString();
                entityList.Add(entity);
            }
            finally
            {
                db = null;
            }

            svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]), 
                                       companyId,
                                       userId,
                                       ipAdress,
                                       sessionString,
                                       DataPgEvidence.PGName.Estimate.EstimateList,
                                       DataPgEvidence.geOperationType.Select,
                                       "Where:" + strWhereSql + ",Estimateby:" + strEstimateBySql);

            return entityList;

        }
        public List<EntityInOutDelivery> GetInOutDeliveryList(string random, string strWhereSql, string strOrderBySql)
        {
            List<EntityInOutDelivery> entityList = new List<EntityInOutDelivery>();

            #region 認証処理

            string companyId = "";
            string groupId = "";
            string userId = "";
            string ipAdress = "";
            string sessionString = "";
            int idFigureCommodity = 0;
            int idFigureCustomer = 0;
            int idFigurePurchase = 0;
            int idFigureSlipNo = 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]);
                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]);

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

            StringBuilder sb;
            DataTable dt;
            ExMySQLData db;

            try
            {
                db = ExSession.GetSessionDb(ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]),
                                            ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]));

                sb = new StringBuilder();

                ExReportManeger rptMgr = new ExReportManeger();
                rptMgr.idFigureCommodity = idFigureCommodity;
                rptMgr.idFigureCustomer = idFigureCustomer;
                rptMgr.idFigurePurchase = idFigurePurchase;
                rptMgr.idFigureSlipNo = idFigureSlipNo;

                sb.Append(rptMgr.GetInOutDeliveryListReportSQL(companyId, groupId, strWhereSql, strOrderBySql));

                dt = db.GetDataTable(sb.ToString());

                if (dt.DefaultView.Count > 0)
                {
                    for (int i = 0; i <= dt.DefaultView.Count - 1; i++)
                    {
                        #region Set Entity

                        EntityInOutDelivery _entityInOutDelivery = new EntityInOutDelivery();
                        _entityInOutDelivery.ID = ExCast.zCLng(dt.DefaultView[i]["ID"]);
                        _entityInOutDelivery.NO = ExCast.zCLng(dt.DefaultView[i]["NO"]);
                        _entityInOutDelivery.CAUSE_NO = ExCast.zCLng(dt.DefaultView[i]["CAUSE_NO"]);
                        _entityInOutDelivery.IN_OUT_DELIVERY_YMD = ExCast.zDateNullToDefault(dt.DefaultView[i]["IN_OUT_DELIVERY_YMD"]);
                        _entityInOutDelivery.IN_OUT_DELIVERY_KBN = ExCast.zCInt(dt.DefaultView[i]["IN_OUT_DELIVERY_KBN"]);
                        _entityInOutDelivery.IN_OUT_DELIVERY_KBN_NM = ExCast.zCStr(dt.DefaultView[i]["IN_OUT_DELIVERY_KBN_NM"]);
                        _entityInOutDelivery.IN_OUT_DELIVERY_PROC_KBN = ExCast.zCInt(dt.DefaultView[i]["IN_OUT_DELIVERY_PROC_KBN"]);
                        _entityInOutDelivery.IN_OUT_DELIVERY_PROC_KBN_NM = ExCast.zCStr(dt.DefaultView[i]["IN_OUT_DELIVERY_PROC_KBN_NM"]);
                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_KBN = ExCast.zCInt(dt.DefaultView[i]["IN_OUT_DELIVERY_TO_KBN"]);
                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_KBN_NM = ExCast.zCStr(dt.DefaultView[i]["IN_OUT_DELIVERY_TO_KBN_NM"]);
                        _entityInOutDelivery.INPUT_PERSON = ExCast.zCInt(dt.DefaultView[i]["INPUT_PERSON"]);
                        _entityInOutDelivery.INPUT_PERSON_NM = ExCast.zCStr(dt.DefaultView[i]["INPUT_PERSON_NM"]);
                        _entityInOutDelivery.INPUT_PERSON = ExCast.zCInt(dt.DefaultView[i]["CUSTOMER_ID"]);
                        _entityInOutDelivery.INPUT_PERSON_NM = ExCast.zCStr(dt.DefaultView[i]["INPUT_PERSON_NM"]);

                        // 入出庫区分
                        switch (_entityInOutDelivery.IN_OUT_DELIVERY_KBN)
                        {
                            case 1:     // 入庫
                                // 入出庫先区分
                                switch (_entityInOutDelivery.IN_OUT_DELIVERY_TO_KBN)
                                {
                                    case 1:     // グループ
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_ID = ExCast.zCStr(dt.DefaultView[i]["GROUP_ID_TO"]);
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_NM = ExCast.zCStr(dt.DefaultView[i]["GROUP_ID_TO_NM"]);
                                        break;
                                    case 2:     // 仕入先
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_ID = ExCast.zFormatForID(dt.DefaultView[0]["PURCHASE_ID"], idFigurePurchase);
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_NM = ExCast.zCStr(dt.DefaultView[i]["PURCHASE_NM"]);
                                        break;
                                    default:
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_ID = "";
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_NM = "";
                                        break;
                                }
                                break;
                            case 2:     // 出庫
                                // 入出庫先区分
                                switch (_entityInOutDelivery.IN_OUT_DELIVERY_TO_KBN)
                                {
                                    case 1:     // グループ
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_ID = ExCast.zCStr(dt.DefaultView[i]["GROUP_ID_TO"]);
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_NM = ExCast.zCStr(dt.DefaultView[i]["GROUP_ID_TO_NM"]);
                                        break;
                                    case 2:     // 得意先
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_ID = ExCast.zFormatForID(dt.DefaultView[0]["CUSTOMER_ID"], idFigureCustomer);
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_NM = ExCast.zCStr(dt.DefaultView[i]["CUSTOMER_NM"]);
                                        break;
                                    default:
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_ID = "";
                                        _entityInOutDelivery.IN_OUT_DELIVERY_TO_NM = "";
                                        break;
                                }
                                break;
                            default:
                                _entityInOutDelivery.IN_OUT_DELIVERY_TO_ID = "";
                                _entityInOutDelivery.IN_OUT_DELIVERY_TO_NM = "";
                                break;
                        }

                        _entityInOutDelivery.GROUP_ID_TO = ExCast.zCInt(dt.DefaultView[i]["GROUP_ID_TO"]);
                        _entityInOutDelivery.GROUP_ID_TO_NM = ExCast.zCStr(dt.DefaultView[i]["GROUP_ID_TO_NM"]);
                        _entityInOutDelivery.CUSTOMER_ID = ExCast.zFormatForID(dt.DefaultView[0]["CUSTOMER_ID"], idFigureCustomer);
                        _entityInOutDelivery.CUSTOMER_NM = ExCast.zCStr(dt.DefaultView[i]["CUSTOMER_NM"]);
                        _entityInOutDelivery.PURCHASE_ID = ExCast.zFormatForID(dt.DefaultView[0]["PURCHASE_ID"], idFigurePurchase);
                        _entityInOutDelivery.PURCHASE_NAME = ExCast.zCStr(dt.DefaultView[i]["PURCHASE_NM"]);
                        _entityInOutDelivery.SUM_ENTER_NUMBER = ExCast.zCInt(dt.DefaultView[i]["SUM_ENTER_NUMBER"]);
                        _entityInOutDelivery.SUM_CASE_NUMBER = ExCast.zCDbl(dt.DefaultView[i]["SUM_CASE_NUMBER"]);
                        _entityInOutDelivery.SUM_NUMBER = ExCast.zCDbl(dt.DefaultView[i]["SUM_NUMBER"]);
                        _entityInOutDelivery.MEMO = ExCast.zCStr(dt.DefaultView[i]["MEMO"]);
                        _entityInOutDelivery.REC_NO = ExCast.zCInt(dt.DefaultView[i]["REC_NO"]);
                        _entityInOutDelivery.COMMODITY_ID = ExCast.zCStr(dt.DefaultView[i]["COMMODITY_ID"]);
                        _entityInOutDelivery.COMMODITY_NAME = ExCast.zCStr(dt.DefaultView[i]["COMMODITY_NAME"]);
                        _entityInOutDelivery.UNIT_ID = ExCast.zCInt(dt.DefaultView[i]["UNIT_ID"]);
                        _entityInOutDelivery.UNIT_NM = ExCast.zCStr(dt.DefaultView[i]["UNIT_NM"]);
                        _entityInOutDelivery.ENTER_NUMBER = ExCast.zCInt(dt.DefaultView[i]["ENTER_NUMBER"]);
                        _entityInOutDelivery.CASE_NUMBER = ExCast.zCDbl(dt.DefaultView[i]["CASE_NUMBER"]);
                        _entityInOutDelivery.NUMBER = ExCast.zCDbl(dt.DefaultView[i]["NUMBER"]);
                        _entityInOutDelivery.D_MEMO = ExCast.zCStr(dt.DefaultView[i]["D_MEMO"]);

                        entityList.Add(_entityInOutDelivery);

                        #endregion
                    }
                }

            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetInOutDeliveryList", ex);
                entityList.Clear();
                EntityInOutDelivery entity = new EntityInOutDelivery();
                entity.MESSAGE = CLASS_NM + ".GetInOutDeliveryList : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString();
                entityList.Add(entity);
            }
            finally
            {
                db = null;
            }

            svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                       companyId,
                                       userId,
                                       ipAdress,
                                       sessionString,
                                       DataPgEvidence.PGName.InOutDeliver.InOutDeliverList,
                                       DataPgEvidence.geOperationType.Select,
                                       "Where:" + strWhereSql + ",Orderby:" + strOrderBySql);

            return entityList;

        }
        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;
        }
        public List<EntityPaymentCash> GetPaymentCashList(string random, string strWhereSql, string strOrderBySql)
        {
            List<EntityPaymentCash> entityList = new List<EntityPaymentCash>();

            #region 認証処理

            string companyId = "";
            string groupId = "";
            string userId = "";
            string ipAdress = "";
            string sessionString = "";
            int idFigureCommodity = 0;
            int idFigureCustomer = 0;
            int idFigurePurchase = 0;
            int idFigureSlipNo = 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]);
                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]);

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

            StringBuilder sb;
            DataTable dt;
            ExMySQLData db;

            try
            {
                db = ExSession.GetSessionDb(ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]),
                                            ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]));

                sb = new StringBuilder();

                ExReportManeger rptMgr = new ExReportManeger();
                rptMgr.idFigureCommodity = idFigureCommodity;
                rptMgr.idFigureCustomer = idFigureCustomer;
                rptMgr.idFigurePurchase = idFigurePurchase;
                rptMgr.idFigureSlipNo = idFigureSlipNo;
                sb.Append(rptMgr.GetPaymentCashListReportSQL(companyId, groupId, strWhereSql, strOrderBySql));

                dt = db.GetDataTable(sb.ToString());

                if (dt.DefaultView.Count > 0)
                {
                    for (int i = 0; i <= dt.DefaultView.Count - 1; i++)
                    {
                        EntityPaymentCash _entity = new EntityPaymentCash();

                        _entity.ID = ExCast.zCLng(dt.DefaultView[i]["ID"]);
                        _entity.NO = ExCast.zCLng(dt.DefaultView[i]["NO"]);
                        _entity.PAYMENT_CASH_YMD = ExCast.zDateNullToDefault(dt.DefaultView[i]["PAYMENT_CASH_YMD"]);
                        _entity.INPUT_PERSON = ExCast.zCInt(dt.DefaultView[i]["INPUT_PERSON"]);
                        _entity.INPUT_PERSON_NM = ExCast.zCStr(dt.DefaultView[i]["INPUT_PERSON_NM"]);
                        _entity.PURCHASE_ID = ExCast.zFormatForID(dt.DefaultView[0]["PURCHASE_ID"], idFigurePurchase);
                        _entity.PURCHASE_NM = ExCast.zCStr(dt.DefaultView[i]["PURCHASE_NM"]);
                        _entity.SUM_PRICE = ExCast.zCDbl(dt.DefaultView[i]["SUM_PRICE"]);
                        _entity.MEMO = ExCast.zCStr(dt.DefaultView[i]["MEMO"]);
                        _entity.UPDATE_PERSON_ID = ExCast.zCInt(dt.DefaultView[i]["UPDATE_PERSON_ID"]);
                        _entity.UPDATE_PERSON_NM = ExCast.zCStr(dt.DefaultView[i]["UPDATE_PERSON_NM"]);
                        _entity.REC_NO = ExCast.zCInt(dt.DefaultView[i]["REC_NO"]);
                        _entity.PAYMENT_CASH_DIVISION_ID = ExCast.zCInt(dt.DefaultView[i]["PAYMENT_DIVISION_ID"]);
                        _entity.PAYMENT_CASH_DIVISION_NM = ExCast.zCStr(dt.DefaultView[i]["PAYMENT_DIVISION_NM"]);
                        _entity.PRICE = ExCast.zCDbl(dt.DefaultView[i]["PRICE"]);
                        _entity.BILL_SITE_DAY = ExCast.zDateNullToDefault(dt.DefaultView[i]["BILL_DUE_DATE"]);
                        _entity.D_MEMO = ExCast.zCStr(dt.DefaultView[i]["D_MEMO"]);

                        entityList.Add(_entity);
                    }
                }

            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetPaymentCashList", ex);
                entityList.Clear();
                EntityPaymentCash entity = new EntityPaymentCash();
                entity.MEMO = CLASS_NM + ".GetPaymentCashList : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString();
                entityList.Add(entity);
            }
            finally
            {
                db = null;
            }

            svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                       companyId,
                                       userId,
                                       ipAdress,
                                       sessionString,
                                       DataPgEvidence.PGName.PaymentCash.PaymentCashList,
                                       DataPgEvidence.geOperationType.Select,
                                       "Where:" + strWhereSql + ",Orderby:" + strOrderBySql);

            return entityList;

        }
        public List<EntityStockInventory> GetStockInventoryList(string random, string strWhereSql, string strOrderBySql)
        {
            List<EntityStockInventory> entityList = new List<EntityStockInventory>();

            #region 認証処理

            string companyId = "";
            string groupId = "";
            string userId = "";
            string ipAdress = "";
            string sessionString = "";
            int idFigureCommodity = 0;
            int idFigureCustomer = 0;
            int idFigurePurchase = 0;
            int idFigureSlipNo = 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]);
                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]);

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

            StringBuilder sb;
            DataTable dt;
            ExMySQLData db;

            try
            {
                db = ExSession.GetSessionDb(ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]),
                                            ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]));

                sb = new StringBuilder();

                ExReportManeger rptMgr = new ExReportManeger();
                rptMgr.idFigureCommodity = idFigureCommodity;
                rptMgr.idFigureCustomer = idFigureCustomer;
                rptMgr.idFigurePurchase = idFigurePurchase;
                rptMgr.idFigureSlipNo = idFigureSlipNo;
                sb.Append(rptMgr.GetStockInventoryListReportSQL(companyId, groupId, strWhereSql, strOrderBySql));

                dt = db.GetDataTable(sb.ToString());

                if (dt.DefaultView.Count > 0)
                {
                    for (int i = 0; i <= dt.DefaultView.Count - 1; i++)
                    {
                        #region Set Entity

                        EntityStockInventory entity = new EntityStockInventory();
                        entity.commodity_id = ExCast.zCStr(dt.DefaultView[i]["COMMODITY_ID"]);
                        entity.commodity_name = ExCast.zCStr(dt.DefaultView[i]["COMMODITY_NAME"]);
                        entity.account_inventory_number = ExCast.zCDbl(dt.DefaultView[i]["INVENTORY_NUMBER"]);
                        entity.practice_inventory_number = ExCast.zCDbl(dt.DefaultView[i]["INVENTORY_NUMBER"]);
                        entity.diff_number = 0;

                        entity.exec_flg = false;

                        entity.lock_flg = 0;

                        entityList.Add(entity);

                        #endregion

                    }
                }

            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetStockInventoryList", ex);
                entityList.Clear();
                EntityStockInventory entity = new EntityStockInventory();
                entity.MESSAGE = CLASS_NM + ".GetStockInventoryList : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString();
                entityList.Add(entity);
            }
            finally
            {
                db = null;
            }

            svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                       companyId,
                                       userId,
                                       ipAdress,
                                       sessionString,
                                       DataPgEvidence.PGName.StockInventory.StockInventoryInp,
                                       DataPgEvidence.geOperationType.Select,
                                       "Where:" + strWhereSql + ",Orderby:" + strOrderBySql);

            return entityList;

        }
        public List<EntitySalesCreditBalance> GetSalesCreditBalanaceList(string random, string strWhereSql, string strOrderBySql)
        {
            List<EntitySalesCreditBalance> entityList = new List<EntitySalesCreditBalance>();

            #region 認証処理

            string companyId = "";
            string groupId = "";
            string userId = "";
            string ipAdress = "";
            string sessionString = "";
            int idFigureCommodity = 0;
            int idFigureCustomer = 0;
            int idFigurePurchase = 0;
            int idFigureSlipNo = 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]);
                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]);

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

            StringBuilder sb;
            DataTable dt;
            ExMySQLData db;
            long rec_no = 0;

            try
            {
                db = ExSession.GetSessionDb(ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]),
                                            ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]));

                sb = new StringBuilder();

                ExReportManeger rptMgr = new ExReportManeger();
                rptMgr.idFigureCommodity = idFigureCommodity;
                rptMgr.idFigureCustomer = idFigureCustomer;
                rptMgr.idFigurePurchase = idFigurePurchase;
                rptMgr.idFigureSlipNo = idFigureSlipNo;
                sb.Append(rptMgr.GetSalesCreditBalanaceListReportSQL(companyId, groupId, strWhereSql, strOrderBySql));

                dt = db.GetDataTable(sb.ToString());

                if (dt.DefaultView.Count > 0)
                {
                    for (int i = 0; i <= dt.DefaultView.Count - 1; i++)
                    {
                        #region Set Entity

                        rec_no += 1;

                        EntitySalesCreditBalance entity = new EntitySalesCreditBalance();
                        entity.rec_no = rec_no;
                        entity.ym = ExCast.zCStr(dt.DefaultView[i]["YM"]);
                        entity.invoice_id = ExCast.zCStr(dt.DefaultView[i]["INVOICE_ID"]);
                        entity.invoice_nm = ExCast.zCStr(dt.DefaultView[i]["INVOICE_NAME"]);
                        entity.before_sales_credit_balacne = ExCast.zCDbl(dt.DefaultView[i]["BEFORE_SALES_CREDIT_BALANCE"]);
                        entity.before_sales_credit_balacne_upd = ExCast.zCDbl(dt.DefaultView[i]["BEFORE_SALES_CREDIT_BALANCE"]);
                        entity.this_receipt_price = ExCast.zCDbl(dt.DefaultView[i]["THIS_RECEIPT_PRICE"]);
                        entity.this_receipt_percent = ExCast.zCDbl(dt.DefaultView[i]["THIS_RECEIPT_PERCENT"]);
                        entity.this_sales_credit_price = ExCast.zCDbl(dt.DefaultView[i]["THIS_SALES_PRICE"]);
                        entity.this_tax = ExCast.zCDbl(dt.DefaultView[i]["THIS_SALES_TAX"]);
                        entity.this_sales_credit_balance = ExCast.zCDbl(dt.DefaultView[i]["THIS_SALES_CREDIT_BALANCE"]);

                        entity.exec_flg = false;

                        entity.lock_flg = 0;

                        entityList.Add(entity);

                        #endregion

                    }
                }

            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetSalesCreditBalanaceList", ex);
                entityList.Clear();
                EntitySalesCreditBalance entity = new EntitySalesCreditBalance();
                entity.MESSAGE = CLASS_NM + ".GetSalesCreditBalanaceList : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString();
                entityList.Add(entity);
            }
            finally
            {
                db = null;
            }

            svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                       companyId,
                                       userId,
                                       ipAdress,
                                       sessionString,
                                       DataPgEvidence.PGName.Order.OrderList,
                                       DataPgEvidence.geOperationType.Select,
                                       "Where:" + strWhereSql + ",Orderby:" + strOrderBySql);

            return entityList;

        }