Пример #1
0
        public static void Save( SqlConnection sqlConnection, SqlTransaction sqlTransaction, ItemStatus itemStatus )
        {
            SqlConnection connection = sqlConnection;
            SqlTransaction transaction = sqlTransaction;

            if ( connection == null )
            {
                connection =
                    CustomSqlHelper.CreateConnection( CustomSqlHelper.GetConnectionStringFromConnectionStrings( "BHL" ) );
            }

            bool isTransactionCoordinator = CustomSqlHelper.IsTransactionCoordinator( transaction );

            try
            {
                transaction = CustomSqlHelper.BeginTransaction( connection, transaction, isTransactionCoordinator );

                new ItemStatusDAL().ItemStatusManageAuto( connection, transaction, itemStatus );

                CustomSqlHelper.CommitTransaction( transaction, isTransactionCoordinator );
            }
            catch ( Exception ex )
            {
                CustomSqlHelper.RollbackTransaction( transaction, isTransactionCoordinator );

                throw new Exception( "Exception in Save", ex );
            }
            finally
            {
                CustomSqlHelper.CloseConnection( connection, isTransactionCoordinator );
            }
        }
Пример #2
0
        protected void Page_Load( object sender, EventArgs e )
        {
            if ( !IsPostBack )
            {
                BHLProvider bp = new BHLProvider();
                CustomGenericList<ItemStatus> itemStatuses = bp.ItemStatusSelectAll();

                itemStatuses.Sort();

                ItemStatus emptyItemStatus = new ItemStatus();
                emptyItemStatus.ItemStatusID = -1;
                emptyItemStatus.ItemStatusName = "";
                itemStatuses.Insert( 0, emptyItemStatus );

                ddlItemStatuses.DataSource = itemStatuses;
                ddlItemStatuses.DataTextField = "ItemStatusName";
                ddlItemStatuses.DataValueField = "ItemStatusID";
                ddlItemStatuses.DataBind();
            }
        }
Пример #3
0
 /// <summary>
 /// Update values in ItemStatus. Returns an object of type ItemStatus.
 /// </summary>
 /// <param name="sqlConnection">Sql connection or null.</param>
 /// <param name="sqlTransaction">Sql transaction or null.</param>
 /// <param name="value">Object of type ItemStatus.</param>
 /// <returns>Object of type ItemStatus.</returns>
 public ItemStatus ItemStatusUpdateAuto(
     SqlConnection sqlConnection,
     SqlTransaction sqlTransaction,
     ItemStatus value)
 {
     return ItemStatusUpdateAuto(sqlConnection, sqlTransaction,
         value.ItemStatusID,
         value.ItemStatusName);
 }
Пример #4
0
        /// <summary>
        /// Manage ItemStatus object.
        /// If the object is of type CustomObjectBase, 
        /// then either insert values into, delete values from, or update values in ItemStatus.
        /// </summary>
        /// <param name="sqlConnection">Sql connection or null.</param>
        /// <param name="sqlTransaction">Sql transaction or null.</param>
        /// <param name="value">Object of type ItemStatus.</param>
        /// <returns>Object of type CustomDataAccessStatus<ItemStatus>.</returns>
        public CustomDataAccessStatus<ItemStatus> ItemStatusManageAuto(
            SqlConnection sqlConnection,
            SqlTransaction sqlTransaction,
            ItemStatus value)
        {
            if (value.IsNew && !value.IsDeleted)
            {

                ItemStatus returnValue = ItemStatusInsertAuto(sqlConnection, sqlTransaction,
                    value.ItemStatusID,
                        value.ItemStatusName);

                return new CustomDataAccessStatus<ItemStatus>(
                    CustomDataAccessContext.Insert,
                    true, returnValue);
            }
            else if (!value.IsNew && value.IsDeleted)
            {
                if (ItemStatusDeleteAuto(sqlConnection, sqlTransaction,
                    value.ItemStatusID))
                {
                return new CustomDataAccessStatus<ItemStatus>(
                    CustomDataAccessContext.Delete,
                    true, value);
                }
                else
                {
                return new CustomDataAccessStatus<ItemStatus>(
                    CustomDataAccessContext.Delete,
                    false, value);
                }
            }
            else if (value.IsDirty && !value.IsDeleted)
            {

                ItemStatus returnValue = ItemStatusUpdateAuto(sqlConnection, sqlTransaction,
                    value.ItemStatusID,
                        value.ItemStatusName);

                return new CustomDataAccessStatus<ItemStatus>(
                    CustomDataAccessContext.Update,
                    true, returnValue);
            }
            else
            {
                return new CustomDataAccessStatus<ItemStatus>(
                    CustomDataAccessContext.NA,
                    false, value);
            }
        }
 public void SaveItemStatus( ItemStatus itemStatus )
 {
     ItemStatusDAL.Save( null, null, itemStatus );
 }
Пример #6
0
        protected void saveAsNewButton_Click( object sender, EventArgs e )
        {
            if ( validate() )
            {
                if ( idTextBox.Text.Trim().Length == 0 )
                {
                    errorPanel.Controls.Add( new LiteralControl( "* Please include a unique ID before saving" ) );
                    errorPanel.Visible = true;
                    return;
                }
                else
                {
                    int id = 0;
                    if ( int.TryParse( idTextBox.Text.Trim(), out id ) )
                    {
                        BHLProvider bp = new BHLProvider();

                        CustomGenericList<ItemStatus> itemStatuses = bp.ItemStatusSelectAll();
                        foreach ( ItemStatus its in itemStatuses )
                        {
                            if ( its.ItemStatusID == id )
                            {
                                errorPanel.Controls.Add( new LiteralControl( "* The item status id " + id.ToString() +
                                    " is not a unique id, please use another one." ) );
                                errorPanel.Visible = true;
                                return;
                            }
                        }

                        ItemStatus itemStatus = new ItemStatus( id, statusTextBox.Text.Trim() );
                        itemStatus.IsNew = true;

                        bp.SaveItemStatus( itemStatus );
                    }
                    else
                    {
                        errorPanel.Controls.Add( new LiteralControl( "* The item status id " + idTextBox.Text.Trim() +
                            " is not numeric, please use numbers only." ) );
                        errorPanel.Visible = true;
                        return;
                    }
                }
            }
            else
            {
                return;
            }

            Response.Redirect( "/Admin/Dashboard.aspx" );
        }
Пример #7
0
        protected void saveButton_Click( object sender, EventArgs e )
        {
            if ( validate() )
            {
                if ( hidId.Value.Length == 0 )
                {
                    errorPanel.Controls.Add( new LiteralControl( "* Please select an item status before saving" ) );
                    errorPanel.Visible = true;
                    return;
                }

                ItemStatus itemStatus = new ItemStatus( int.Parse( hidId.Value ), statusTextBox.Text.Trim() );

                itemStatus.IsNew = false;

                BHLProvider bp = new BHLProvider();
                bp.SaveItemStatus( itemStatus );
            }
            else
            {
                return;
            }

            Response.Redirect( "/Admin/Dashboard.aspx" );
        }