Beispiel #1
0
        public string UpdateClass(string random, List <EntityClass> entity, int classKbn)
        {
            #region 認証処理

            string companyId     = "";
            string groupId       = "";
            string userId        = "";
            string ipAdress      = "";
            string sessionString = "";
            string personId      = "";

            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]);
                personId      = ExCast.zCStr(HttpContext.Current.Session[ExSession.PERSON_ID]);

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

            #endregion

            #region Field

            StringBuilder sb = new StringBuilder();
            DataTable     dt;
            ExMySQLData   db        = null;
            string        _Id       = "";
            int           _classKbn = 0;

            #endregion

            #region データ存在チェック

            sb = new StringBuilder();

            #region SQL

            _classKbn = ((classKbn - 1)) * 3 + 1;

            sb.Length = 0;
            sb.Append("SELECT MT.* " + Environment.NewLine);
            sb.Append("  FROM M_CLASS AS MT" + Environment.NewLine);
            sb.Append(" WHERE MT.COMPANY_ID = " + companyId + Environment.NewLine);
            sb.Append("   AND MT.DELETE_FLG = 0 " + Environment.NewLine);
            sb.Append("   AND MT.CLASS_DIVISION_ID = " + _classKbn.ToString() + Environment.NewLine);
            sb.Append(" ORDER BY MT.COMPANY_ID " + Environment.NewLine);
            sb.Append("         ,MT.ID " + Environment.NewLine);

            #endregion

            db = ExSession.GetSessionDb(ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]),
                                        ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]));
            dt = db.GetDataTable(sb.ToString());

            string ret_msg = "";
            if (dt.DefaultView.Count > 0)
            {
                for (int i = 0; i <= dt.DefaultView.Count - 1; i++)
                {
                    long lngClassId = ExCast.zCLng(dt.DefaultView[i]["ID"]);
                    bool exists_flg = false;
                    for (int i_ = 0; i_ <= entity.Count - 1; i_++)
                    {
                        if (ExCast.zCLng(entity[i_].id) == lngClassId)
                        {
                            exists_flg = true;
                        }
                    }

                    string strClassId = string.Format("{0:000}", ExCast.zCDbl(lngClassId));

                    if (exists_flg == false)
                    {
                        bool _ret = false;

                        switch (classKbn)
                        {
                        case 1:         // 得意先分類
                            _ret = DataExists.IsExistData(db, companyId, "", "M_CUSTOMER", "GROUP1_ID", strClassId, CommonUtl.geStrOrNumKbn.String);
                            if (_ret == true)
                            {
                                ret_msg += "得意先分類ID : " + strClassId + " は得意先マスタで使用されている為、削除できません。" + Environment.NewLine;
                            }
                            break;

                        case 2:         // 商品分類
                            _ret = DataExists.IsExistData(db, companyId, "", "M_COMMODITY", "GROUP1_ID", strClassId, CommonUtl.geStrOrNumKbn.String);
                            if (_ret == true)
                            {
                                ret_msg += "商品分類ID : " + strClassId + " は商品マスタで使用されている為、削除できません。" + Environment.NewLine;
                            }
                            break;

                        case 3:         // 仕入先分類
                            _ret = DataExists.IsExistData(db, companyId, "", "M_PURCHASE", "GROUP1_ID", strClassId, CommonUtl.geStrOrNumKbn.String);
                            if (_ret == true)
                            {
                                ret_msg += "仕入先分類ID : " + strClassId + " は仕入先マスタで使用されている為、削除できません。" + Environment.NewLine;
                            }
                            break;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(ret_msg))
                {
                    return(ret_msg);
                }
            }


            #endregion

            #region Databese Open

            try
            {
                db = new ExMySQLData(ExCast.zCStr(HttpContext.Current.Session[ExSession.DB_CONNECTION_STR]));
                db.DbOpen();
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateClass(DbOpen)", ex);
                return(CLASS_NM + ".UpdateClass(DbOpen) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region BeginTransaction

            try
            {
                db.ExBeginTransaction();
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateClass(BeginTransaction)", ex);
                return(CLASS_NM + ".UpdateClass(BeginTransaction) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region Delete

            try
            {
                #region Delete SQL

                _classKbn = ((classKbn - 1)) * 3 + 1;

                sb.Length = 0;
                sb.Append("DELETE FROM M_CLASS " + Environment.NewLine);
                sb.Append(" WHERE COMPANY_ID = " + companyId + Environment.NewLine);
                sb.Append("   AND CLASS_DIVISION_ID = " + _classKbn.ToString() + Environment.NewLine);

                #endregion

                db.ExecuteSQL(sb.ToString(), false);
            }
            catch (Exception ex)
            {
                db.ExRollbackTransaction();
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateClass(Delete)", ex);
                return(CLASS_NM + ".UpdateClass(Delete) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region Insert

            try
            {
                for (int i = 0; i <= entity.Count - 1; i++)
                {
                    // 空行は無視する
                    if (!string.IsNullOrEmpty(entity[i].id))
                    {
                        #region Insert SQL

                        sb.Length = 0;
                        sb.Append("INSERT INTO M_CLASS " + Environment.NewLine);
                        sb.Append("       ( COMPANY_ID" + Environment.NewLine);
                        sb.Append("       , CLASS_DIVISION_ID" + Environment.NewLine);
                        sb.Append("       , ID" + Environment.NewLine);
                        sb.Append("       , NAME" + Environment.NewLine);
                        sb.Append("       , MEMO" + Environment.NewLine);
                        sb.Append("       , DISPLAY_FLG" + Environment.NewLine);
                        sb.Append("       , UPDATE_FLG" + Environment.NewLine);
                        sb.Append("       , DELETE_FLG" + Environment.NewLine);
                        sb.Append("       , CREATE_PG_ID" + Environment.NewLine);
                        sb.Append("       , CREATE_ADRESS" + Environment.NewLine);
                        sb.Append("       , CREATE_USER_ID" + Environment.NewLine);
                        sb.Append("       , CREATE_PERSON_ID" + Environment.NewLine);
                        sb.Append("       , CREATE_DATE" + Environment.NewLine);
                        sb.Append("       , CREATE_TIME" + Environment.NewLine);
                        sb.Append("       , UPDATE_PG_ID" + Environment.NewLine);
                        sb.Append("       , UPDATE_ADRESS" + Environment.NewLine);
                        sb.Append("       , UPDATE_USER_ID" + Environment.NewLine);
                        sb.Append("       , UPDATE_PERSON_ID" + Environment.NewLine);
                        sb.Append("       , UPDATE_DATE" + Environment.NewLine);
                        sb.Append("       , UPDATE_TIME" + Environment.NewLine);
                        sb.Append(")" + Environment.NewLine);
                        sb.Append("SELECT  " + companyId + Environment.NewLine);                                                        // COMPANY_ID
                        sb.Append("       ," + _classKbn.ToString() + Environment.NewLine);                                             // Class_DIVISION_ID
                        sb.Append("       ," + ExEscape.zRepStr(ExCast.zNumZeroFormat("{0:000}", entity[i].id)) + Environment.NewLine); // ID
                        sb.Append("       ," + ExEscape.zRepStr(entity[i].name) + Environment.NewLine);                                 // NAME
                        sb.Append("       ," + ExEscape.zRepStr(entity[i].memo) + Environment.NewLine);                                 // MEMO
                        sb.Append("       ," + entity[i].display_division_id + Environment.NewLine);                                    // DISPLAY_FLG
                        sb.Append(CommonUtl.GetInsSQLCommonColums(CommonUtl.UpdKbn.Ins,
                                                                  PG_NM,
                                                                  "M_Class",
                                                                  ExCast.zCInt(personId),
                                                                  _Id,
                                                                  ipAdress,
                                                                  userId));

                        #endregion

                        db.ExecuteSQL(sb.ToString(), false);
                    }
                }
            }
            catch (Exception ex)
            {
                db.ExRollbackTransaction();
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateClass(Insert)", ex);
                return(CLASS_NM + ".UpdateClass(Insert) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region PG排他制御

            try
            {
                DataPgLock.DelLockPg(companyId, userId, PG_NM, "", ipAdress, false, db);
            }
            catch (Exception ex)
            {
                db.ExRollbackTransaction();
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateClass(DelLockPg)", ex);
                return(CLASS_NM + ".UpdateClass(DelLockPg) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region CommitTransaction

            try
            {
                db.ExCommitTransaction();
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateClass(CommitTransaction)", ex);
                return(CLASS_NM + ".UpdateClass(CommitTransaction) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region Database Close

            try
            {
                db.DbClose();
            }
            catch (Exception ex)
            {
                db.ExRollbackTransaction();
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateClass(DbClose)", ex);
                return(CLASS_NM + ".UpdateClass(DbClose) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }
            finally
            {
                db = null;
            }

            #endregion

            #region Add Evidence

            try
            {
                svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                           companyId,
                                           userId,
                                           ipAdress,
                                           sessionString,
                                           PG_NM,
                                           DataPgEvidence.geOperationType.DeleteAndInsert,
                                           "");
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateClass(Add Evidence)", ex);
                return(CLASS_NM + ".UpdateClass(Add Evidence) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            return("");
        }
Beispiel #2
0
        public string ChkClassExist(string random, int classKbn, string Id)
        {
            #region 認証処理

            string companyId     = "";
            string groupId       = "";
            string userId        = "";
            string ipAdress      = "";
            string sessionString = "";

            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]);

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

            #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();

                int _classKbn = ((classKbn - 1)) * 3 + 1;

                #region Exist Data

                bool _ret = false;

                switch (_classKbn)
                {
                case 1:         // 得意先分類
                    _ret = DataExists.IsExistData(db, companyId, "", "M_CUSTOMER", "GROUP1_ID", string.Format("{0:000", ExCast.zCInt(Id)), CommonUtl.geStrOrNumKbn.String);
                    if (_ret == true)
                    {
                        return("得意先分類ID : " + Id + " は得意先マスタで使用されている為、削除できません。");
                    }
                    break;

                case 2:         // 商品分類
                    _ret = DataExists.IsExistData(db, companyId, "", "M_COMMODITY", "GROUP1_ID", string.Format("{0:000", ExCast.zCInt(Id)), CommonUtl.geStrOrNumKbn.String);
                    if (_ret == true)
                    {
                        return("商品分類ID : " + Id + " は商品マスタで使用されている為、削除できません。");
                    }
                    break;

                case 3:         // 仕入先分類
                    _ret = DataExists.IsExistData(db, companyId, "", "M_PURCHASE", "GROUP1_ID", string.Format("{0:000", ExCast.zCInt(Id)), CommonUtl.geStrOrNumKbn.String);
                    if (_ret == true)
                    {
                        return("仕入先分類ID : " + Id + " は仕入先マスタで使用されている為、削除できません。");
                    }
                    break;
                }

                #endregion
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".ChkClassExist", ex);
                return(CLASS_NM + ".ChkClassExist : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString());
            }
            finally
            {
                db = null;
            }

            svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                       companyId,
                                       userId,
                                       ipAdress,
                                       sessionString,
                                       PG_NM,
                                       DataPgEvidence.geOperationType.Select,
                                       "");

            return("");
        }
        public string UpdatePerson(string random, int type, long Id, EntityPerson entity)
        {
            #region 認証処理

            string companyId     = "";
            string groupId       = "";
            string userId        = "";
            string ipAdress      = "";
            string sessionString = "";
            string personId      = "";

            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]);
                personId      = ExCast.zCStr(HttpContext.Current.Session[ExSession.PERSON_ID]);

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

            #endregion

            #region Field

            StringBuilder sb = new StringBuilder();
            DataTable     dt;
            ExMySQLData   db  = null;
            string        _Id = "";

            #endregion

            #region Databese Open

            try
            {
                db = new ExMySQLData(ExCast.zCStr(HttpContext.Current.Session[ExSession.DB_CONNECTION_STR]));
                db.DbOpen();
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdatePerson(DbOpen)", ex);
                return(CLASS_NM + ".UpdatePerson(DbOpen) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region BeginTransaction

            try
            {
                db.ExBeginTransaction();
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdatePerson(BeginTransaction)", ex);
                return(CLASS_NM + ".UpdatePerson(BeginTransaction) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region Get Max Master ID

            if (type == 1 && Id == 0)
            {
                try
                {
                    DataMasterId.GetMaxMasterId(companyId,
                                                "",
                                                db,
                                                DataMasterId.geMasterMaxIdKbn.Person,
                                                out _Id);
                    if (_Id == "")
                    {
                        return("ID取得に失敗しました。");
                    }
                }
                catch (Exception ex)
                {
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdatePerson(GetMaxMasterId)", ex);
                    return(CLASS_NM + ".UpdatePerson(GetMaxMasterId) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }
            }
            else
            {
                _Id = Id.ToString();
            }

            #endregion

            #region Insert

            if (type == 1)
            {
                try
                {
                    #region Delete SQL

                    sb.Length = 0;
                    sb.Append("DELETE FROM M_PERSON " + Environment.NewLine);
                    sb.Append(" WHERE DELETE_FLG = 1 " + Environment.NewLine);
                    sb.Append("   AND COMPANY_ID = " + companyId + Environment.NewLine);
                    sb.Append("   AND ID = " + _Id.ToString() + Environment.NewLine);

                    #endregion

                    db.ExecuteSQL(sb.ToString(), false);

                    #region Insert SQL

                    sb.Length = 0;
                    sb.Append("INSERT INTO M_PERSON " + Environment.NewLine);
                    sb.Append("       ( COMPANY_ID" + Environment.NewLine);
                    sb.Append("       , ID" + Environment.NewLine);
                    sb.Append("       , GROUP_ID" + Environment.NewLine);
                    sb.Append("       , NAME" + Environment.NewLine);
                    sb.Append("       , MEMO" + Environment.NewLine);
                    sb.Append("       , DISPLAY_FLG" + Environment.NewLine);
                    sb.Append("       , UPDATE_FLG" + Environment.NewLine);
                    sb.Append("       , DELETE_FLG" + Environment.NewLine);
                    sb.Append("       , CREATE_PG_ID" + Environment.NewLine);
                    sb.Append("       , CREATE_ADRESS" + Environment.NewLine);
                    sb.Append("       , CREATE_USER_ID" + Environment.NewLine);
                    sb.Append("       , CREATE_PERSON_ID" + Environment.NewLine);
                    sb.Append("       , CREATE_DATE" + Environment.NewLine);
                    sb.Append("       , CREATE_TIME" + Environment.NewLine);
                    sb.Append("       , UPDATE_PG_ID" + Environment.NewLine);
                    sb.Append("       , UPDATE_ADRESS" + Environment.NewLine);
                    sb.Append("       , UPDATE_USER_ID" + Environment.NewLine);
                    sb.Append("       , UPDATE_PERSON_ID" + Environment.NewLine);
                    sb.Append("       , UPDATE_DATE" + Environment.NewLine);
                    sb.Append("       , UPDATE_TIME" + Environment.NewLine);
                    sb.Append(")" + Environment.NewLine);
                    sb.Append("SELECT  " + companyId + Environment.NewLine);                                                // COMPANY_ID
                    sb.Append("       ," + _Id.ToString() + Environment.NewLine);                                           // ID
                    sb.Append("       ," + entity.group_id + Environment.NewLine);                                          // GROUP_ID
                    sb.Append("       ," + ExEscape.zRepStr(entity.name) + Environment.NewLine);                            // NAME
                    sb.Append("       ," + ExEscape.zRepStr(entity.memo) + Environment.NewLine);                            // MEMO
                    sb.Append("       ," + entity.display_division_id + Environment.NewLine);                               // DISPLAY_FLG
                    sb.Append(CommonUtl.GetInsSQLCommonColums(CommonUtl.UpdKbn.Ins,
                                                              PG_NM,
                                                              "M_PERSON",
                                                              ExCast.zCInt(personId),
                                                              _Id,
                                                              ipAdress,
                                                              userId));

                    #endregion

                    db.ExecuteSQL(sb.ToString(), false);
                }
                catch (Exception ex)
                {
                    db.ExRollbackTransaction();
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdatePerson(Insert)", ex);
                    return(CLASS_NM + ".UpdatePerson(Insert) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }
            }

            #endregion

            #region Update

            if (type == 0)
            {
                try
                {
                    #region SQL

                    sb.Length = 0;
                    sb.Append("UPDATE M_PERSON " + Environment.NewLine);
                    sb.Append(CommonUtl.GetUpdSQLCommonColums(PG_NM,
                                                              ExCast.zCInt(personId),
                                                              ipAdress,
                                                              userId,
                                                              0));
                    sb.Append("      ,GROUP_ID = " + entity.group_id + Environment.NewLine);
                    sb.Append("      ,NAME = " + ExEscape.zRepStr(entity.name) + Environment.NewLine);
                    sb.Append("      ,MEMO = " + ExEscape.zRepStr(entity.memo) + Environment.NewLine);
                    sb.Append("      ,DISPLAY_FLG = " + entity.display_division_id + Environment.NewLine);
                    sb.Append(" WHERE COMPANY_ID = " + companyId + Environment.NewLine);        // COMPANY_ID
                    sb.Append("   AND ID = " + Id.ToString() + Environment.NewLine);            // ID

                    #endregion

                    db.ExecuteSQL(sb.ToString(), false);
                }
                catch (Exception ex)
                {
                    db.ExRollbackTransaction();
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdatePerson(Update)", ex);
                    return(CLASS_NM + ".UpdatePerson(Update) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }
            }

            #endregion

            #region Delete

            if (type == 2)
            {
                #region Exist Data

                try
                {
                    bool _ret = false;

                    _ret = DataExists.IsExistData(db, companyId, groupId, "T_ESTIMATE_H", "PERSON_ID", Id.ToString(), CommonUtl.geStrOrNumKbn.Number);
                    if (_ret == true)
                    {
                        return("担当ID : " + string.Format("{0:000}", Id) + " は見積データの入力担当者に使用されている為、削除できません。");
                    }

                    _ret = DataExists.IsExistData(db, companyId, groupId, "T_ORDER_H", "PERSON_ID", Id.ToString(), CommonUtl.geStrOrNumKbn.Number);
                    if (_ret == true)
                    {
                        return("担当ID : " + string.Format("{0:000}", Id) + " は受注データの入力担当者に使用されている為、削除できません。");
                    }

                    _ret = DataExists.IsExistData(db, companyId, groupId, "T_SALES_H", "PERSON_ID", Id.ToString(), CommonUtl.geStrOrNumKbn.Number);
                    if (_ret == true)
                    {
                        return("担当ID : " + string.Format("{0:000}", Id) + " は売上データの入力担当者に使用されている為、削除できません。");
                    }

                    _ret = DataExists.IsExistData(db, companyId, groupId, "T_RECEIPT_H", "PERSON_ID", Id.ToString(), CommonUtl.geStrOrNumKbn.Number);
                    if (_ret == true)
                    {
                        return("担当ID : " + string.Format("{0:000}", Id) + " は入金データの入力担当者に使用されている為、削除できません。");
                    }
                }
                catch (Exception ex)
                {
                    db.ExRollbackTransaction();
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdatePerson(Exist Data)", ex);
                    return(CLASS_NM + ".UpdatePerson(Exist Data) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }

                #endregion

                #region Update

                try
                {
                    sb.Length = 0;
                    sb.Append("UPDATE M_PERSON " + Environment.NewLine);
                    sb.Append(CommonUtl.GetUpdSQLCommonColums(PG_NM,
                                                              ExCast.zCInt(personId),
                                                              ipAdress,
                                                              userId,
                                                              1));
                    sb.Append(" WHERE COMPANY_ID = " + companyId + Environment.NewLine);    // COMPANY_ID
                    sb.Append("   AND ID = " + Id.ToString() + Environment.NewLine);        // ID

                    db.ExecuteSQL(sb.ToString(), false);
                }
                catch (Exception ex)
                {
                    db.ExRollbackTransaction();
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdatePerson(Delete)", ex);
                    return(CLASS_NM + ".UpdatePerson(Delete) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }

                #endregion
            }

            #endregion

            #region PG排他制御

            if (type == 0 || type == 2)
            {
                try
                {
                    DataPgLock.DelLockPg(companyId, userId, PG_NM, "", ipAdress, false, db);
                }
                catch (Exception ex)
                {
                    db.ExRollbackTransaction();
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdatePerson(DelLockPg)", ex);
                    return(CLASS_NM + ".UpdatePerson(DelLockPg) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }
            }

            #endregion

            #region CommitTransaction

            try
            {
                db.ExCommitTransaction();
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdatePerson(CommitTransaction)", ex);
                return(CLASS_NM + ".UpdatePerson(CommitTransaction) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region Database Close

            try
            {
                db.DbClose();
            }
            catch (Exception ex)
            {
                db.ExRollbackTransaction();
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdatePerson(DbClose)", ex);
                return(CLASS_NM + ".UpdatePerson(DbClose) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }
            finally
            {
                db = null;
            }

            #endregion

            #region Add Evidence

            try
            {
                switch (type)
                {
                case 0:
                    svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                               companyId,
                                               userId,
                                               ipAdress,
                                               sessionString,
                                               PG_NM,
                                               DataPgEvidence.geOperationType.Update,
                                               "ID:" + Id.ToString());
                    break;

                case 1:
                    svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                               companyId,
                                               userId,
                                               ipAdress,
                                               sessionString,
                                               PG_NM,
                                               DataPgEvidence.geOperationType.Insert,
                                               "ID:" + _Id.ToString());
                    break;

                case 2:
                    svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                               companyId,
                                               userId,
                                               ipAdress,
                                               sessionString,
                                               PG_NM,
                                               DataPgEvidence.geOperationType.Delete,
                                               "ID:" + Id.ToString());
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdatePerson(Add Evidence)", ex);
                return(CLASS_NM + ".UpdatePerson(Add Evidence) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region Return

            if (type == 1 && Id == 0)
            {
                return("Auto Insert success : " + "ID : " + _Id.ToString() + "で登録しました。");
            }
            else
            {
                return("");
            }

            #endregion
        }
Beispiel #4
0
        public string UpdateCommodity(string random, int type, string Id, EntityCommodity entity)
        {
            #region 認証処理

            string companyId     = "";
            string groupId       = "";
            string userId        = "";
            string ipAdress      = "";
            string sessionString = "";
            string personId      = "";

            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]);
                personId      = ExCast.zCStr(HttpContext.Current.Session[ExSession.PERSON_ID]);

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

            #endregion

            #region Field

            StringBuilder sb = new StringBuilder();
            DataTable     dt;
            ExMySQLData   db  = null;
            string        _Id = "";

            #endregion

            #region Databese Open

            try
            {
                db = new ExMySQLData(ExCast.zCStr(HttpContext.Current.Session[ExSession.DB_CONNECTION_STR]));
                db.DbOpen();
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(DbOpen)", ex);
                return(CLASS_NM + ".UpdateCommodity(DbOpen) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region BeginTransaction

            try
            {
                db.ExBeginTransaction();
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(BeginTransaction)", ex);
                return(CLASS_NM + ".UpdateCommodity(BeginTransaction) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region Get Max Master ID

            if (type == 1 && (Id == "" || Id == "0"))
            {
                try
                {
                    DataMasterId.GetMaxMasterId(companyId,
                                                "",
                                                db,
                                                DataMasterId.geMasterMaxIdKbn.Commodity,
                                                out _Id);

                    if (_Id == "")
                    {
                        return("ID取得に失敗しました。");
                    }
                }
                catch (Exception ex)
                {
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(GetMaxMasterId)", ex);
                    return(CLASS_NM + ".UpdateCommodity(GetMaxMasterId) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }
            }
            else
            {
                _Id = Id;
            }

            #endregion

            #region Insert

            if (type == 1)
            {
                try
                {
                    #region Delete SQL

                    sb.Length = 0;
                    sb.Append("DELETE FROM M_COMMODITY " + Environment.NewLine);
                    sb.Append(" WHERE DELETE_FLG = 1 " + Environment.NewLine);
                    sb.Append("   AND COMPANY_ID = " + companyId + Environment.NewLine);
                    sb.Append("   AND ID = " + ExEscape.zRepStr(ExCast.zNumZeroNothingFormat(_Id)) + Environment.NewLine);

                    #endregion

                    db.ExecuteSQL(sb.ToString(), false);

                    #region Insert SQL

                    string _main_purchase_id = entity.main_purchase_id;
                    if (ExCast.IsNumeric(_main_purchase_id))
                    {
                        _main_purchase_id = ExCast.zCDbl(_main_purchase_id).ToString();
                    }

                    #region SQL

                    sb.Length = 0;
                    sb.Append("INSERT INTO M_COMMODITY " + Environment.NewLine);
                    sb.Append("       ( COMPANY_ID" + Environment.NewLine);
                    sb.Append("       , ID" + Environment.NewLine);
                    sb.Append("       , ID2" + Environment.NewLine);
                    sb.Append("       , NAME" + Environment.NewLine);
                    sb.Append("       , KANA" + Environment.NewLine);
                    sb.Append("       , UNIT_ID" + Environment.NewLine);
                    sb.Append("       , ENTER_NUMBER" + Environment.NewLine);
                    sb.Append("       , NUMBER_DECIMAL_DIGIT" + Environment.NewLine);
                    sb.Append("       , UNIT_DECIMAL_DIGIT" + Environment.NewLine);
                    sb.Append("       , TAXATION_DIVISION_ID" + Environment.NewLine);
                    sb.Append("       , INVENTORY_MANAGEMENT_DIVISION_ID" + Environment.NewLine);
                    sb.Append("       , PURCHASE_LOT" + Environment.NewLine);
                    sb.Append("       , LEAD_TIME" + Environment.NewLine);
                    sb.Append("       , JUST_INVENTORY_NUMBER" + Environment.NewLine);
                    sb.Append("       , INVENTORY_NUMBER" + Environment.NewLine);
                    sb.Append("       , INVENTORY_EVALUATION_ID" + Environment.NewLine);
                    sb.Append("       , MAIN_PURCHASE_ID" + Environment.NewLine);
                    sb.Append("       , RETAIL_PRICE_SKIP_TAX" + Environment.NewLine);
                    sb.Append("       , RETAIL_PRICE_BEFORE_TAX" + Environment.NewLine);
                    sb.Append("       , SALES_UNIT_PRICE_SKIP_TAX" + Environment.NewLine);
                    sb.Append("       , SALES_UNIT_PRICE_BEFORE_TAX" + Environment.NewLine);
                    sb.Append("       , SALES_COST_PRICE_SKIP_TAX" + Environment.NewLine);
                    sb.Append("       , SALES_COST_PRICE_BEFORE_TAX" + Environment.NewLine);
                    sb.Append("       , PURCHASE_UNIT_PRICE_SKIP_TAX" + Environment.NewLine);
                    sb.Append("       , PURCHASE_UNIT_PRICE_BEFORE_TAX" + Environment.NewLine);
                    sb.Append("       , GROUP1_ID" + Environment.NewLine);
                    sb.Append("       , GROUP2_ID" + Environment.NewLine);
                    sb.Append("       , GROUP3_ID" + Environment.NewLine);
                    sb.Append("       , MEMO" + Environment.NewLine);
                    sb.Append("       , DISPLAY_FLG" + Environment.NewLine);
                    sb.Append("       , UPDATE_FLG" + Environment.NewLine);
                    sb.Append("       , DELETE_FLG" + Environment.NewLine);
                    sb.Append("       , CREATE_PG_ID" + Environment.NewLine);
                    sb.Append("       , CREATE_ADRESS" + Environment.NewLine);
                    sb.Append("       , CREATE_USER_ID" + Environment.NewLine);
                    sb.Append("       , CREATE_PERSON_ID" + Environment.NewLine);
                    sb.Append("       , CREATE_DATE" + Environment.NewLine);
                    sb.Append("       , CREATE_TIME" + Environment.NewLine);
                    sb.Append("       , UPDATE_PG_ID" + Environment.NewLine);
                    sb.Append("       , UPDATE_ADRESS" + Environment.NewLine);
                    sb.Append("       , UPDATE_USER_ID" + Environment.NewLine);
                    sb.Append("       , UPDATE_PERSON_ID" + Environment.NewLine);
                    sb.Append("       , UPDATE_DATE" + Environment.NewLine);
                    sb.Append("       , UPDATE_TIME" + Environment.NewLine);
                    sb.Append(")" + Environment.NewLine);
                    sb.Append("SELECT  " + companyId + Environment.NewLine);                                                // COMPANY_ID
                    sb.Append("       ," + ExEscape.zRepStr(ExCast.zNumZeroNothingFormat(_Id)) + Environment.NewLine);      // ID
                    sb.Append("       ," + ExCast.zIdForNumIndex(_Id) + Environment.NewLine);                               // ID2
                    sb.Append("       ," + ExEscape.zRepStr(entity.name) + Environment.NewLine);                            // NAME
                    sb.Append("       ," + ExEscape.zRepStr(entity.kana) + Environment.NewLine);                            // KANA
                    sb.Append("       ," + entity.unit_id + Environment.NewLine);                                           // UNIT_ID
                    sb.Append("       ," + entity.enter_number + Environment.NewLine);                                      // ENTER_NUMBER
                    sb.Append("       ," + entity.number_decimal_digit + Environment.NewLine);                              // NUMBER_DECIMAL_DIGIT
                    sb.Append("       ," + entity.unit_decimal_digit + Environment.NewLine);                                // UNIT_DECIMAL_DIGIT
                    sb.Append("       ," + entity.taxation_divition_id + Environment.NewLine);                              // TAXATION_DIVISION_ID
                    sb.Append("       ," + entity.inventory_management_division_id + Environment.NewLine);                  // INVENTORY_MANAGEMENT_DIVISION_ID
                    sb.Append("       ," + entity.purchase_lot + Environment.NewLine);                                      // PURCHASE_LOT
                    sb.Append("       ," + entity.lead_time + Environment.NewLine);                                         // LEAD_TIME
                    sb.Append("       ," + entity.just_inventory_number + Environment.NewLine);                             // JUST_INVENTORY_NUMBER
                    sb.Append("       ," + entity.inventory_number + Environment.NewLine);                                  // INVENTORY_NUMBER
                    sb.Append("       ," + entity.inventory_evaluation_id + Environment.NewLine);                           // INVENTORY_EVALUATION_ID
                    sb.Append("       ," + ExEscape.zRepStr(_main_purchase_id) + Environment.NewLine);                      // MAIN_PURCHASE_ID
                    sb.Append("       ," + entity.retail_price_skip_tax + Environment.NewLine);                             // RETAIL_PRICE_SKIP_TAX
                    sb.Append("       ," + entity.retail_price_before_tax + Environment.NewLine);                           // RETAIL_PRICE_BEFORE_TAX
                    sb.Append("       ," + entity.sales_unit_price_skip_tax + Environment.NewLine);                         // SALES_UNIT_PRICE_SKIP_TAX
                    sb.Append("       ," + entity.sales_unit_price_before_tax + Environment.NewLine);                       // SALES_UNIT_PRICE_BEFORE_TAX
                    sb.Append("       ," + entity.sales_cost_price_skip_tax + Environment.NewLine);                         // SALES_COST_PRICE_SKIP_TAX
                    sb.Append("       ," + entity.sales_cost_price_before_tax + Environment.NewLine);                       // SALES_COST_PRICE_BEFORE_TAX
                    sb.Append("       ," + entity.purchase_unit_price_skip_tax + Environment.NewLine);                      // PURCHASE_UNIT_PRICE_SKIP_TAX
                    sb.Append("       ," + entity.purchase_unit_price_before_tax + Environment.NewLine);                    // PURCHASE_UNIT_PRICE_BEFORE_TAX
                    sb.Append("       ," + ExEscape.zRepStr(entity.group1_id) + Environment.NewLine);                       // GROUP1_ID
                    sb.Append("       ," + ExEscape.zRepStr(entity.group2_id) + Environment.NewLine);                       // GROUP2_ID
                    sb.Append("       ," + ExEscape.zRepStr(entity.group3_id) + Environment.NewLine);                       // GROUP3_ID
                    sb.Append("       ," + ExEscape.zRepStr(entity.memo) + Environment.NewLine);                            // MEMO
                    sb.Append("       ," + entity.display_division_id + Environment.NewLine);                               // DISPLAY_FLG
                    sb.Append(CommonUtl.GetInsSQLCommonColums(CommonUtl.UpdKbn.Ins,
                                                              PG_NM,
                                                              "M_COMMODITY",
                                                              ExCast.zCInt(personId),
                                                              _Id,
                                                              ipAdress,
                                                              userId));

                    #endregion

                    #endregion

                    db.ExecuteSQL(sb.ToString(), false);

                    #region Commodity Inventory Insert

                    try
                    {
                        #region Delete SQL

                        sb.Length = 0;
                        sb.Append("DELETE FROM M_COMMODITY_INVENTORY " + Environment.NewLine);
                        sb.Append(" WHERE COMPANY_ID = " + companyId + Environment.NewLine);                                   // COMPANY_ID
                        sb.Append("   AND ID = " + ExEscape.zRepStr(ExCast.zNumZeroNothingFormat(_Id)) + Environment.NewLine); // ID

                        #endregion

                        db.ExecuteSQL(sb.ToString(), false);

                        #region SQL

                        sb.Length = 0;
                        sb.Append("SELECT MT.* " + Environment.NewLine);
                        sb.Append("  FROM SYS_M_COMPANY_GROUP AS MT" + Environment.NewLine);
                        sb.Append(" WHERE MT.COMPANY_ID = " + companyId + Environment.NewLine);
                        sb.Append("   AND MT.DELETE_FLG = 0 " + Environment.NewLine);
                        sb.Append(" ORDER BY MT.ID " + Environment.NewLine);

                        #endregion

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

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

                                sb.Length = 0;
                                sb.Append("INSERT INTO M_COMMODITY_INVENTORY " + Environment.NewLine);
                                sb.Append("       ( COMPANY_ID" + Environment.NewLine);
                                sb.Append("       , GROUP_ID" + Environment.NewLine);
                                sb.Append("       , ID" + Environment.NewLine);
                                sb.Append("       , INVENTORY_NUMBER" + Environment.NewLine);
                                sb.Append("       , UPDATE_FLG" + Environment.NewLine);
                                sb.Append("       , DELETE_FLG" + Environment.NewLine);
                                sb.Append("       , CREATE_PG_ID" + Environment.NewLine);
                                sb.Append("       , CREATE_ADRESS" + Environment.NewLine);
                                sb.Append("       , CREATE_USER_ID" + Environment.NewLine);
                                sb.Append("       , CREATE_PERSON_ID" + Environment.NewLine);
                                sb.Append("       , CREATE_DATE" + Environment.NewLine);
                                sb.Append("       , CREATE_TIME" + Environment.NewLine);
                                sb.Append("       , UPDATE_PG_ID" + Environment.NewLine);
                                sb.Append("       , UPDATE_ADRESS" + Environment.NewLine);
                                sb.Append("       , UPDATE_USER_ID" + Environment.NewLine);
                                sb.Append("       , UPDATE_PERSON_ID" + Environment.NewLine);
                                sb.Append("       , UPDATE_DATE" + Environment.NewLine);
                                sb.Append("       , UPDATE_TIME" + Environment.NewLine);
                                sb.Append(")" + Environment.NewLine);
                                sb.Append("SELECT  " + companyId + Environment.NewLine);                                                        // COMPANY_ID
                                sb.Append("       ," + ExCast.zCStr(dt.DefaultView[i]["ID"]) + Environment.NewLine);                            // GROUP_ID
                                sb.Append("       ," + ExEscape.zRepStr(ExCast.zNumZeroNothingFormat(_Id)) + Environment.NewLine);              // ID
                                sb.Append("       ,0" + Environment.NewLine);                                                                   // INVENTORY_NUMBER
                                sb.Append(CommonUtl.GetInsSQLCommonColums(CommonUtl.UpdKbn.Ins,
                                                                          PG_NM,
                                                                          "M_COMMODITY_INVENTORY",
                                                                          ExCast.zCInt(personId),
                                                                          _Id,
                                                                          ipAdress,
                                                                          userId));

                                #endregion

                                db.ExecuteSQL(sb.ToString(), false);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        db.ExRollbackTransaction();
                        CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(Commodity Inventory Insert)", ex);
                        return(CLASS_NM + ".UpdateCommodity(Commodity Inventory Insert) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                    }

                    #endregion
                }
                catch (Exception ex)
                {
                    db.ExRollbackTransaction();
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(Insert)", ex);
                    return(CLASS_NM + ".UpdateCommodity(Insert) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }
            }

            #endregion

            #region Update

            if (type == 0)
            {
                try
                {
                    #region SQL

                    string _main_purchase_id = entity.main_purchase_id;
                    if (ExCast.IsNumeric(_main_purchase_id))
                    {
                        _main_purchase_id = ExCast.zCDbl(_main_purchase_id).ToString();
                    }

                    sb.Length = 0;
                    sb.Append("UPDATE M_COMMODITY " + Environment.NewLine);
                    sb.Append(CommonUtl.GetUpdSQLCommonColums(PG_NM,
                                                              ExCast.zCInt(personId),
                                                              ipAdress,
                                                              userId,
                                                              0));
                    sb.Append("      ,NAME = " + ExEscape.zRepStr(entity.name) + Environment.NewLine);
                    sb.Append("      ,KANA = " + ExEscape.zRepStr(entity.kana) + Environment.NewLine);
                    sb.Append("      ,UNIT_ID = " + entity.unit_id + Environment.NewLine);
                    sb.Append("      ,ENTER_NUMBER = " + entity.enter_number + Environment.NewLine);
                    sb.Append("      ,NUMBER_DECIMAL_DIGIT = " + entity.number_decimal_digit + Environment.NewLine);
                    sb.Append("      ,UNIT_DECIMAL_DIGIT = " + entity.unit_decimal_digit + Environment.NewLine);
                    sb.Append("      ,TAXATION_DIVISION_ID = " + entity.taxation_divition_id + Environment.NewLine);
                    sb.Append("      ,INVENTORY_MANAGEMENT_DIVISION_ID = " + entity.inventory_management_division_id + Environment.NewLine);
                    sb.Append("      ,PURCHASE_LOT = " + entity.purchase_lot + Environment.NewLine);
                    sb.Append("      ,LEAD_TIME = " + entity.lead_time + Environment.NewLine);
                    sb.Append("      ,JUST_INVENTORY_NUMBER = " + entity.just_inventory_number + Environment.NewLine);
                    sb.Append("      ,INVENTORY_NUMBER = " + entity.inventory_number + Environment.NewLine);
                    sb.Append("      ,INVENTORY_EVALUATION_ID = " + entity.inventory_evaluation_id + Environment.NewLine);
                    sb.Append("      ,MAIN_PURCHASE_ID = " + ExEscape.zRepStr(_main_purchase_id) + Environment.NewLine);
                    sb.Append("      ,RETAIL_PRICE_SKIP_TAX = " + entity.retail_price_skip_tax + Environment.NewLine);
                    sb.Append("      ,RETAIL_PRICE_BEFORE_TAX = " + entity.retail_price_before_tax + Environment.NewLine);
                    sb.Append("      ,SALES_UNIT_PRICE_SKIP_TAX = " + entity.sales_unit_price_skip_tax + Environment.NewLine);
                    sb.Append("      ,SALES_UNIT_PRICE_BEFORE_TAX = " + entity.sales_unit_price_before_tax + Environment.NewLine);
                    sb.Append("      ,SALES_COST_PRICE_SKIP_TAX = " + entity.sales_cost_price_skip_tax + Environment.NewLine);
                    sb.Append("      ,SALES_COST_PRICE_BEFORE_TAX = " + entity.sales_cost_price_before_tax + Environment.NewLine);
                    sb.Append("      ,PURCHASE_UNIT_PRICE_SKIP_TAX = " + entity.purchase_unit_price_skip_tax + Environment.NewLine);
                    sb.Append("      ,PURCHASE_UNIT_PRICE_BEFORE_TAX = " + entity.purchase_unit_price_before_tax + Environment.NewLine);
                    sb.Append("      ,GROUP1_ID = " + ExEscape.zRepStr(entity.group1_id) + Environment.NewLine);
                    sb.Append("      ,GROUP2_ID = " + ExEscape.zRepStr(entity.group2_id) + Environment.NewLine);
                    sb.Append("      ,GROUP3_ID = " + ExEscape.zRepStr(entity.group3_id) + Environment.NewLine);
                    sb.Append("      ,MEMO = " + ExEscape.zRepStr(entity.memo) + Environment.NewLine);
                    sb.Append("      ,DISPLAY_FLG = " + entity.display_division_id + Environment.NewLine);
                    sb.Append(" WHERE COMPANY_ID = " + companyId + Environment.NewLine);                                  // COMPANY_ID
                    sb.Append("   AND ID = " + ExEscape.zRepStr(ExCast.zNumZeroNothingFormat(Id)) + Environment.NewLine); // ID

                    #endregion

                    db.ExecuteSQL(sb.ToString(), false);
                }
                catch (Exception ex)
                {
                    db.ExRollbackTransaction();
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(Update)", ex);
                    return(CLASS_NM + ".UpdateCommodity(Insert) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }
            }

            #endregion

            #region Delete

            if (type == 2)
            {
                #region Exist Data

                try
                {
                    bool _ret = false;

                    _ret = DataExists.IsExistData(db, companyId, groupId, "T_ESTIMATE_D", "COMMODITY_ID", ExCast.zNumZeroNothingFormat(Id), CommonUtl.geStrOrNumKbn.String);
                    if (_ret == true)
                    {
                        return("商品ID : " + Id + " は見積データに使用されている為、削除できません。");
                    }

                    _ret = DataExists.IsExistData(db, companyId, groupId, "T_ORDER_D", "COMMODITY_ID", ExCast.zNumZeroNothingFormat(Id), CommonUtl.geStrOrNumKbn.String);
                    if (_ret == true)
                    {
                        return("商品ID : " + Id + " は受注データに使用されている為、削除できません。");
                    }

                    _ret = DataExists.IsExistData(db, companyId, groupId, "T_SALES_D", "COMMODITY_ID", ExCast.zNumZeroNothingFormat(Id), CommonUtl.geStrOrNumKbn.String);
                    if (_ret == true)
                    {
                        return("商品ID : " + Id + " は売上データに使用されている為、削除できません。");
                    }
                }
                catch (Exception ex)
                {
                    db.ExRollbackTransaction();
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(Exist Data)", ex);
                    return(CLASS_NM + ".UpdateCommodity(Exist Data) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }

                #endregion

                #region Delete Commodity Inventory

                try
                {
                    sb.Length = 0;
                    sb.Append("UPDATE M_COMMODITY_INVENTORY " + Environment.NewLine);
                    sb.Append(CommonUtl.GetUpdSQLCommonColums(PG_NM,
                                                              ExCast.zCInt(personId),
                                                              ipAdress,
                                                              userId,
                                                              1));
                    sb.Append(" WHERE COMPANY_ID = " + companyId + Environment.NewLine);                                  // COMPANY_ID
                    sb.Append("   AND ID = " + ExEscape.zRepStr(ExCast.zNumZeroNothingFormat(Id)) + Environment.NewLine); // ID

                    db.ExecuteSQL(sb.ToString(), false);
                }
                catch (Exception ex)
                {
                    db.ExRollbackTransaction();
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(Delete Commodity Inventory)", ex);
                    return(CLASS_NM + ".UpdateCommodity(Commodity Inventory) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }

                #endregion

                #region Update

                try
                {
                    sb.Length = 0;
                    sb.Append("UPDATE M_COMMODITY " + Environment.NewLine);
                    sb.Append(CommonUtl.GetUpdSQLCommonColums(PG_NM,
                                                              ExCast.zCInt(personId),
                                                              ipAdress,
                                                              userId,
                                                              1));
                    sb.Append(" WHERE COMPANY_ID = " + companyId + Environment.NewLine);                                  // COMPANY_ID
                    sb.Append("   AND ID = " + ExEscape.zRepStr(ExCast.zNumZeroNothingFormat(Id)) + Environment.NewLine); // ID

                    db.ExecuteSQL(sb.ToString(), false);
                }
                catch (Exception ex)
                {
                    db.ExRollbackTransaction();
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(Delete)", ex);
                    return(CLASS_NM + ".UpdateCommodity(Delete) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }

                #endregion
            }

            #endregion

            #region PG排他制御

            if (type == 0 || type == 2)
            {
                try
                {
                    DataPgLock.DelLockPg(companyId, userId, PG_NM, "", ipAdress, false, db);
                }
                catch (Exception ex)
                {
                    db.ExRollbackTransaction();
                    CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(DelLockPg)", ex);
                    return(CLASS_NM + ".UpdateCommodity(DelLockPg) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
                }
            }

            #endregion

            #region CommitTransaction

            try
            {
                db.ExCommitTransaction();
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(CommitTransaction)", ex);
                return(CLASS_NM + ".UpdateCommodity(CommitTransaction) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region Database Close

            try
            {
                db.DbClose();
            }
            catch (Exception ex)
            {
                db.ExRollbackTransaction();
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(DbClose)", ex);
                return(CLASS_NM + ".UpdateCommodity(DbClose) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }
            finally
            {
                db = null;
            }

            #endregion

            #region Add Evidence

            try
            {
                switch (type)
                {
                case 0:
                    svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                               companyId,
                                               userId,
                                               ipAdress,
                                               sessionString,
                                               PG_NM,
                                               DataPgEvidence.geOperationType.Update,
                                               "ID:" + Id.ToString());
                    break;

                case 1:
                    svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                               companyId,
                                               userId,
                                               ipAdress,
                                               sessionString,
                                               PG_NM,
                                               DataPgEvidence.geOperationType.Insert,
                                               "ID:" + _Id.ToString());
                    break;

                case 2:
                    svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                               companyId,
                                               userId,
                                               ipAdress,
                                               sessionString,
                                               PG_NM,
                                               DataPgEvidence.geOperationType.Delete,
                                               "ID:" + Id.ToString());
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".UpdateCommodity(Add Evidence)", ex);
                return(CLASS_NM + ".UpdateCommodity(Add Evidence) : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message);
            }

            #endregion

            #region Return

            if (type == 1 && (Id == "0" || Id == ""))
            {
                return("Auto Insert success : " + "ID : " + _Id.ToString() + "で登録しました。");
            }
            else
            {
                return("");
            }

            #endregion
        }
        public EntityCopying CopyCheck(string random, string tblName, string Id)
        {
            EntityCopying entity;

            #region 認証処理

            string companyId     = "";
            string groupId       = "";
            string userId        = "";
            string ipAdress      = "";
            string sessionString = "";
            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]);

                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 EntityCopying();
                    entity.MESSAGE = _message;
                    return(entity);
                }
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".CopyCheck(認証処理)", ex);
                entity         = new EntityCopying();
                entity.MESSAGE = CLASS_NM + ".CopyCheck : 認証処理に失敗しました。" + Environment.NewLine + ex.Message.ToString();;
                return(entity);
            }

            #endregion

            #region Field

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

            entity = new EntityCopying();
            entity.is_exists_data  = false;
            entity.is_lock_success = false;
            entity.ret             = false;

            string get_col1Value    = "";
            string get_col2Value    = "";
            string get_col3Value    = "";
            string get_col4Value    = "";
            string get_col5Value    = "";
            string lock_check_pg_id = "";
            string lock_check_id    = "";

            #endregion

            try
            {
                // 複写時存在チェック
                switch (tblName)
                {
                    #region マスタ系

                case "SYS_M_COMPANY_GROUP":
                    lock_check_id         = Id;
                    lock_check_pg_id      = DataPgEvidence.PGName.Mst.CompanyGroup;
                    entity.is_exists_data = DataExists.IsExistData(db, companyId, "", tblName, "ID", Id, CommonUtl.geStrOrNumKbn.String);
                    break;

                case "M_CUSTOMER":
                    lock_check_id         = Id;
                    lock_check_pg_id      = DataPgEvidence.PGName.Mst.Customer;
                    entity.is_exists_data = DataExists.IsExistData(db, companyId, "", tblName, "ID", Id, CommonUtl.geStrOrNumKbn.String);
                    break;

                case "M_PERSON":
                    lock_check_id         = Id;
                    lock_check_pg_id      = DataPgEvidence.PGName.Mst.Person;
                    entity.is_exists_data = DataExists.IsExistData(db, companyId, "", tblName, "ID", Id, CommonUtl.geStrOrNumKbn.Number);
                    break;

                case "M_COMMODITY":
                    lock_check_id         = Id;
                    lock_check_pg_id      = DataPgEvidence.PGName.Mst.Commodity;
                    entity.is_exists_data = DataExists.IsExistData(db, companyId, "", tblName, "ID", Id, CommonUtl.geStrOrNumKbn.String);
                    break;

                    #endregion

                    #region 伝票入力系

                    #region 売上入力系

                case "T_ESTIMATE_H":
                    lock_check_id         = groupId + "-" + Id;
                    lock_check_pg_id      = DataPgEvidence.PGName.Estimate.EstimateInp;
                    entity.is_exists_data = DataExists.IsExistData(db, companyId, groupId, tblName, "NO", Id, CommonUtl.geStrOrNumKbn.Number);

                    if (entity.is_exists_data)
                    {
                        // 受注計上済チェック
                        if (DataExists.IsExistData(db, companyId, groupId, "T_ORDER_H", "ESTIMATENO", Id, CommonUtl.geStrOrNumKbn.Number))
                        {
                            entity.MESSAGE = "複写先ID : " + Id + " は受注計上済の為、複写できません。";
                            return(entity);
                        }

                        // 売上計上済チェック
                        if (DataExists.IsExistData(db, companyId, groupId, "T_SALES_H", "ESTIMATENO", Id, CommonUtl.geStrOrNumKbn.Number))
                        {
                            entity.MESSAGE = "複写先ID : " + Id + " は売上計上済の為、複写できません。";
                            return(entity);
                        }
                    }

                    break;

                case "T_ORDER_H":
                    lock_check_id         = groupId + "-" + Id;
                    lock_check_pg_id      = DataPgEvidence.PGName.Order.OrderInp;
                    entity.is_exists_data = DataExists.IsExistData(db, companyId, groupId, tblName, "NO", Id, CommonUtl.geStrOrNumKbn.Number);

                    if (entity.is_exists_data)
                    {
                        // 売上計上済チェック
                        if (DataExists.IsExistData(db, companyId, groupId, "T_SALES_H", "ORDER_NO", Id, CommonUtl.geStrOrNumKbn.Number))
                        {
                            entity.MESSAGE = "複写先ID : " + Id + " は売上計上済の為、複写できません。";
                            return(entity);
                        }
                    }

                    break;

                case "T_SALES_H":
                    lock_check_id         = groupId + "-" + Id;
                    lock_check_pg_id      = DataPgEvidence.PGName.Sales.SalesInp;
                    entity.is_exists_data = DataExists.IsExistData(db, companyId, groupId, tblName, "NO", Id, CommonUtl.geStrOrNumKbn.Number);

                    if (entity.is_exists_data)
                    {
                        DataExists.GetData(db,
                                           companyId,
                                           groupId,
                                           tblName,
                                           "NO",
                                           Id,
                                           CommonUtl.geStrOrNumKbn.Number,
                                           "TBL.INVOICE_ID",
                                           "TBL.INVOICE_NO",
                                           "TBL.RECEIPT_NO",
                                           "TBL.BUSINESS_DIVISION_ID",
                                           "date_format(TBL.SALES_YMD , " + ExEscape.SQL_YMD + ") AS SALES_YMD",
                                           "INVOICE_ID",
                                           "INVOICE_NO",
                                           "RECEIPT_NO",
                                           "BUSINESS_DIVISION_ID",
                                           "SALES_YMD",
                                           ref get_col1Value,
                                           ref get_col2Value,
                                           ref get_col3Value,
                                           ref get_col4Value,
                                           ref get_col5Value
                                           );

                        // 掛売上
                        if (ExCast.zCInt(get_col4Value) == 1)
                        {
                            // 請求締切済チェック
                            if (DataClose.IsInvoiceClose(companyId, db, ExCast.zNumZeroNothingFormat(get_col1Value), ExCast.zDateNullToDefault(get_col5Value)))
                            {
                                entity.is_lock_success = false;
                                entity.ret             = false;
                                entity.MESSAGE         = "複写先ID : " + Id + " は請求締切済の為、複写できません。";
                                return(entity);
                            }
                        }

                        // 請求済チェック
                        // 都度請求分も請求番号が設定されている為、不許可とする
                        if (ExCast.zCLng(get_col2Value) != 0)
                        {
                            entity.MESSAGE = "複写先ID : " + Id + " は請求済の為、複写できません。";
                            return(entity);
                        }

                        // 入金済チェック
                        if (ExCast.zCLng(get_col2Value) != 0)
                        {
                            if (DataExists.IsExistData(db, companyId, groupId, "T_RECEIPT_H", "INVOICE_NO", ExCast.zCLng(get_col2Value).ToString(), CommonUtl.geStrOrNumKbn.Number))
                            {
                                entity.MESSAGE = "複写先ID : " + Id + " は入金計上済の為、複写できません。";
                                return(entity);
                            }
                        }
                    }
                    break;

                case "T_RECEIPT_H":
                    lock_check_id         = groupId + "-" + Id;
                    lock_check_pg_id      = DataPgEvidence.PGName.Receipt.ReceiptInp;
                    entity.is_exists_data = DataExists.IsExistData(db, companyId, groupId, tblName, "NO", Id, CommonUtl.geStrOrNumKbn.Number);
                    break;

                    #endregion

                    #region 在庫入力系

                case "T_IN_OUT_DELIVERY_H":
                    lock_check_id         = groupId + "-" + Id;
                    lock_check_pg_id      = DataPgEvidence.PGName.InOutDeliver.InOutDeliverInp;
                    entity.is_exists_data = DataExists.IsExistData(db, companyId, groupId, tblName, "NO", Id, CommonUtl.geStrOrNumKbn.Number);

                    if (entity.is_exists_data)
                    {
                        // 売上計上分チェック
                        if (DataExists.IsExistDataDouble(db, companyId, groupId, "T_IN_OUT_DELIVERY_H", "NO", Id, "IN_OUT_DELIVERY_PROC_KBN", "2", CommonUtl.geStrOrNumKbn.Number))
                        {
                            entity.MESSAGE = "複写先ID : " + Id + " は売上計上分の為、複写できません。";
                            return(entity);
                        }

                        // 仕入計上分チェック
                        if (DataExists.IsExistDataDouble(db, companyId, groupId, "T_IN_OUT_DELIVERY_H", "NO", Id, "IN_OUT_DELIVERY_PROC_KBN", "3", CommonUtl.geStrOrNumKbn.Number))
                        {
                            entity.MESSAGE = "複写先ID : " + Id + " は仕入計上分の為、複写できません。";
                            return(entity);
                        }
                    }

                    break;

                    #endregion

                    #endregion

                default:
                    entity.is_exists_data = false;
                    break;
                }

                // 排他制御
                string strErr = DataPgLock.SetLockPg(companyId, userId, lock_check_pg_id, lock_check_id, ipAdress, db, out lockFlg);
                if (strErr != "")
                {
                    entity.MESSAGE         = CLASS_NM + ".CopyCheck : 排他制御(ロック情報取得)に失敗しました。" + Environment.NewLine + strErr;
                    entity.is_lock_success = false;
                    entity.ret             = false;
                }
                else
                {
                    if (lockFlg == DataPgLock.geLovkFlg.Lock)
                    {
                        entity.is_lock_success = false;
                        entity.ret             = false;
                        entity.MESSAGE         = "複写先ID : " + Id + " は他ユーザーにて現在更新中の為、複写できません。";
                    }
                    else
                    {
                        entity.is_lock_success = true;
                        entity.ret             = true;
                    }
                }
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".CopyCheck", ex);
                entity         = new EntityCopying();
                entity.MESSAGE = CLASS_NM + ".CopyCheck : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString();;
            }

            return(entity);
        }