Example #1
0
        public void RegisterUser(RegisterForm RegisterForm)
        {
            // 既に登録済みのデータか確認
            UserSearchService SearchService = new UserSearchService();
            UserDto           UserInfoDto   = SearchService.SearchUserWithPrimaryKeyUserId(RegisterForm.UserId);

            if (UserInfoDto != null)
            {
                // ユーザ情報が存在する場合
                Console.WriteLine("ユーザー情報がありません.");
                return;
            }

            OracleConnection Connection = null;

            try
            {
                // 接続文字列の取得(Web.configから取得)
                string ConnectionString = ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
                // DB接続の準備
                Connection = new OracleConnection(ConnectionString);
                // DB接続開始
                Connection.Open();

                // SQL生成
                string RegisterSql = "INSERT INTO USER_MNG.USER_MNG_TBL(USER_ID, PASSWORD, USER_NAME, USER_GENDER, REGISTER_PROG_ID, REGISTER_USER_ID, REGISTER_DATE, UPDATE_PROG_ID, UPDATE_USER_ID, UPDATE_DATE) "
                                     + "VALUES (:USER_ID, :PASSWORD, :USER_NAME, :USER_GENDER, :REGISTER_PROG_ID, :REGISTER_USER_ID, :REGISTER_DATE, :UPDATE_PROG_ID, :UPDATE_USER_ID, :UPDATE_DATE)";
                // 実行するSQLの準備
                OracleCommand Command = new OracleCommand(RegisterSql, Connection);
                Command.Parameters.Add(new OracleParameter(":USER_ID", RegisterForm.UserId));
                Command.Parameters.Add(new OracleParameter(":PASSWORD", RegisterForm.Password));
                Command.Parameters.Add(new OracleParameter(":USER_NAME", RegisterForm.UserName));
                Command.Parameters.Add(new OracleParameter(":USER_GENDER", RegisterForm.UserGender));
                Command.Parameters.Add(new OracleParameter(":REGISTER_PROG_ID", "REGISTER"));
                Command.Parameters.Add(new OracleParameter(":REGISTER_USER_ID", RegisterForm.UserId));
                Command.Parameters.Add(new OracleParameter(":REGISTER_DATE", DateTime.Now));
                Command.Parameters.Add(new OracleParameter(":UPDATE_PROG_ID", "REGISTER"));
                Command.Parameters.Add(new OracleParameter(":UPDATE_USER_ID", RegisterForm.UserId));
                Command.Parameters.Add(new OracleParameter(":UPDATE_DATE", DateTime.Now));

                // SQL実行
                Command.ExecuteNonQuery();
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                // DB接続終了
                Connection.Close();
                Connection.Dispose();
            }
        }
Example #2
0
        /// <summary>
        /// ユーザ情報更新
        /// </summary>
        /// <param name="EditForm"></param>
        public void UpdateUserWithPrimaryKey(EditForm EditForm)
        {
            // ユーザ情報が存在することを確認
            UserSearchService SearchService = new UserSearchService();
            UserDto           UserInfoDto   = SearchService.SearchUserWithPrimaryKeyUserId(EditForm.UserId);

            if (UserInfoDto == null)
            {
                // ユーザ情報が存在しない場合
                return;
            }

            OracleConnection Connection = null;

            try
            {
                // 接続文字列の取得(Web.configから取得)
                string ConnectionString = ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
                // DB接続の準備
                Connection = new OracleConnection(ConnectionString);
                // DB接続開始
                Connection.Open();
                // トランザクション開始
                OracleTransaction Transaction = Connection.BeginTransaction();

                // SQL生成
                string UpdateSql = "UPDATE USER_MNG.USER_MNG_TBL SET USER_NAME = :USER_NAME, USER_GENDER = :USER_GENDER, UPDATE_PROG_ID = :UPDATE_PROG_ID, UPDATE_USER_ID = :UPDATE_USER_ID, UPDATE_DATE = :UPDATE_DATE "
                                   + "WHERE USER_ID = :USER_ID";
                // 実行するSQLの準備
                OracleCommand Command = new OracleCommand(UpdateSql, Connection);
                // パラメータ値の設定
                Command.Parameters.Add(new OracleParameter(":USER_NAME", EditForm.UserName));
                Command.Parameters.Add(new OracleParameter(":USER_GENDER", EditForm.UserGender));
                Command.Parameters.Add(new OracleParameter(":UPDATE_PROG_ID", "UPDATE"));
                Command.Parameters.Add(new OracleParameter(":UPDATE_USER_ID", EditForm.UserId));
                Command.Parameters.Add(new OracleParameter(":UPDATE_DATE", DateTime.Now));
                Command.Parameters.Add(new OracleParameter(":USER_ID", EditForm.UserId));
                // SQL実行
                Command.ExecuteNonQuery();

                Transaction.Commit();
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                // DB接続終了
                Connection.Close();
                Connection.Dispose();
            }
        }