示例#1
0
    /// <summary>
    /// Event handler for the click event of btnSave
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            int idRole;
            //Get the id of the selected associate
            DataTable associatesTable = (DataTable)cmbAssociates.DataSource;
            if (cmbAssociates.SelectedIndex == ApplicationConstants.INT_NULL_VALUE || (int)associatesTable.Rows[cmbAssociates.SelectedIndex]["Id"] == ApplicationConstants.INT_NULL_VALUE)
            {
                throw new IndException(ApplicationMessages.EXCEPTION_MUST_SELECT_AN_ASSOCIATE);
            }
            int idAssociate = (int)associatesTable.Rows[cmbAssociates.SelectedIndex]["Id"];

            //get the idRole from Request.Form collection because we load the Role combo on every roundtrip to server
            string roleRequest = Request.Form[ApplicationUtils.GetClientValueName(cmbRoles.ClientID)];
            idRole = (string.IsNullOrEmpty(roleRequest))?ApplicationConstants.INT_NULL_VALUE : Int32.Parse(roleRequest);

            //Save the role for the associate
            //If no role was selected, than this associate will have its role deleted
            if (idRole == ApplicationConstants.INT_NULL_VALUE)
            {
                DeleteAssociateRole(idAssociate);
            }
            else
            {
                InsertOrUpdateAssociateRole(idAssociate, idRole);
            }
        }
        catch (IndException indEx)
        {
            HasErrors = true;
            ReportControlError(indEx);
            return;
        }
        catch (Exception ex)
        {
            HasErrors = true;
            ReportControlError(new IndException(ex));
            return;
        }
    }