Пример #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        //Get the cached gateway.
        ApplicationConfigurationDatasetGateway appConfigGateway = SessionStateSink.AdminAppConfigGateway;

        //Get a new WebStoreAppConfigRow.
        ApplicationConfigurationDataset.EcommerceAppConfigRow newRow = InterpriseHelper.AddNewStoreAppConfigRow(appConfigGateway);

        //Set the values from the add form.
        newRow.BeginEdit();
        newRow.Name        = txtName.Text;
        newRow.GroupName   = txtGroupName.Text;
        newRow.ConfigValue = txtConfigValue.Text;
        newRow.Description = txtDescription.Text;
        newRow.EndEdit();

        //Attempt to save the new record.
        if (InterpriseHelper.SaveStoreAppConfigs(appConfigGateway))
        {
            //The new record was saved.

            //Show the commands and hide the add new form.
            pnlCommands.Visible = true;
            pnlAddNew.Visible   = false;

            //Re-bind the data.
            BindData();
        }
        else
        {
            //Record was not saved we need to show the violations.
            HandleViolations(newRow);

            //Reject any changes that were made.
            appConfigGateway.RejectChanges();
        }
    }
Пример #2
0
    protected void gvAppConfig_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //Get the dataset.
        ApplicationConfigurationDatasetGateway appConfigGateway = SessionStateSink.AdminAppConfigGateway;

        //Get the updating row from the grid.
        GridViewRow gridRow = gvAppConfig.Rows[e.RowIndex];

        //Get the matching row from the table.

        //ApplicationConfigurationDataset.EcommerceStoreAppConfigRow rowToUpdate = GetRowToUpdate(
        //    appConfigGateway.EcommerceStoreAppConfig, (Guid)gvAppConfig.DataKeys[e.RowIndex]["AppConfigGUID"]);

        ApplicationConfigurationDataset.EcommerceAppConfigRow rowToUpdate = GetRowToUpdate(
            appConfigGateway.EcommerceAppConfig, (Guid)gvAppConfig.DataKeys[e.RowIndex]["AppConfigGUID"]);

        //Update the record with the data from the grid.
        rowToUpdate.BeginEdit();
        rowToUpdate.Name        = ((TextBox)gridRow.Cells[1].FindControl("txtName")).Text;
        rowToUpdate.GroupName   = ((TextBox)gridRow.Cells[2].FindControl("txtGroupName")).Text;
        rowToUpdate.ConfigValue = ((TextBox)gridRow.Cells[3].FindControl("txtConfigValue")).Text;
        rowToUpdate.Description = ((TextBox)gridRow.Cells[4].FindControl("txtDescription")).Text;
        rowToUpdate.EndEdit();

        try
        {
            //Save the changes
            if (InterpriseHelper.SaveStoreAppConfigs(appConfigGateway))
            {
                //Take the item out of edit mode.
                gvAppConfig.EditIndex = -1;
                //Re-bind the data.
                BindData();
            }
            else
            {
                //Record was not saved we need to show the violations.
                HandleViolations(rowToUpdate);

                //Reject any changes that were made.
                appConfigGateway.RejectChanges();
            }
        }
        catch (DataConcurrencyException)
        {
            //We had a concurrency error.

            //Re-load the data from the database (This will also apply the current sort).
            LoadData();
            //Apply the current filter.
            ApplyFilter(SessionStateSink.AdminAppConfigGateway);

            //Add the conncurency violation.
            m_violations.Add("The record you were working with was modified by another user."
                             + " Your changes have been lost and the record has been refreshed with the new data.");

            //Take the item out of edit mode.
            gvAppConfig.EditIndex = -1;
            //Re-bind the data.
            BindData();
        }
    }