예제 #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("");
        }