/// <summary> /// This function executes the cmd paramenter by using ExecuteNonQuery. In addition, /// this fuction sets the following SqlParameters: /// /// @id - base object id /// @updatedby - Current windows username /// @updateddate - the update parameter /// /// throws a MyErrorType.ConCurrentcyObjectUpdate exception if the update /// doesn't return a value > 0. /// </summary> /// <param name="cmd">A SqlCommand object with update statement. (function will update @id, @updatedby, and @updateddate paramenters.)</param> /// <param name="updateDate">The date the @updateddate parameter should be updated to in the database</param> protected void Update(SqlCommand cmd, DateTime updateDate) { cmd.Parameters.Add("@id", SqlDbType.Int).Value = _intID; cmd.Parameters.Add("@updatedby", SqlDbType.VarChar).Value = LocalUser.WindowsUserName; cmd.Parameters.Add("@updateddate", SqlDbType.DateTime).Value = updateDate; if (DBSettings.ExecuteNonQuery(this.GetType().Name, cmd) <= 0) { throw new MyException(this.GetType().Name, MyErrorType.ConcurrencyObjectUpdate, new Exception()); } }
protected void Delete(SqlCommand cmd) { cmd.Parameters.Add("@id", SqlDbType.Int).Value = _intID; cmd.Parameters.Add("@updatedby", SqlDbType.VarChar).Value = _strUpdatedBy; cmd.Parameters.Add("@updateddate", SqlDbType.DateTime).Value = _updatedDate; if (!(DBSettings.ExecuteNonQuery(this.GetType().Name, cmd) > 0)) { throw new MyException(this.GetType().Name, MyErrorType.ConcurrencyObjectUpdate, new Exception()); } }
protected void Insert(SqlCommand cmd, DateTime updateDate) { cmd.CommandText += "SET @ident = SCOPE_IDENTITY(); "; cmd.Parameters.Add("@updatedby", SqlDbType.VarChar).Value = LocalUser.WindowsUserName; cmd.Parameters.Add("@updateddate", SqlDbType.DateTime).Value = updateDate; SqlParameter paramId = new SqlParameter("@ident", SqlDbType.Int); paramId.Direction = ParameterDirection.Output; cmd.Parameters.Add(paramId); if (DBSettings.ExecuteNonQuery(this.GetType().Name, cmd) > 0) { if (!DBNull.Value.Equals(paramId.Value)) { _intID = (int)paramId.Value; } } else { throw new ArgumentNullException(this.GetType().Name + "Id", "The insert failed to return a unique identifier for the " + this.GetType().Name); } }