Exemplo n.º 1
0
        /// <summary>
        /// Event handler for the save button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, System.EventArgs e)
        {
            BusinessServices.Unit objUnit;

            int    intOrganisationID;           // Users Organisation ID
            int    intParentUnitID;             // Units Parent ID
            string strParentUnitID;             // String equivalent of intParentUnitID
            bool   blnActive;                   // boolean flag indicating if a unit is active
            int    intUnitID;                   // The unit ID

            if (Page.IsValid)
            {
                //1. Get new Unit details and do validation
                intOrganisationID = UserContext.UserData.OrgID;

                //Get parent Unit
                intParentUnitID = 0;

                //If the new unit is in top level, no parent
                if (this.optUnitLevel.Enabled == true)
                {
                    if (this.optUnitLevel.SelectedValue == "1")
                    {
                        intParentUnitID = 0;
                    }
                    else
                    {   //Otherwise choose a parent
                        strParentUnitID = this.trvParentUnit.GetSelectedValue();
                        intParentUnitID = int.Parse(strParentUnitID);
                    }
                }
                // If the control isnt enabled then it must be a unit administrator - choose a parent
                else
                {
                    strParentUnitID = this.trvParentUnit.GetSelectedValue();
                    if (strParentUnitID.Length == 0)
                    {
                        this.lblMessage.Text     = ResourceManager.GetString("lblMessage.NoParent");//"Please select a parent unit";
                        this.lblMessage.CssClass = "WarningMessage";
                        return;
                    }
                    intParentUnitID = int.Parse(strParentUnitID);
                }


                if (this.cboStatus.SelectedValue == "1")
                {
                    blnActive = true;
                }
                else
                {
                    blnActive = false;
                }

                //2. Create new unit
                try
                {
                    objUnit   = new BusinessServices.Unit();
                    intUnitID = objUnit.Create(intOrganisationID, intParentUnitID, this.txtName.Text, blnActive, UserContext.UserID);
                    BusinessServices.Unit.DenyAllForUnit(intOrganisationID, intUnitID);

                    Response.Redirect("UnitDetails.aspx?UnitID=" + intUnitID.ToString());
                }
                catch (BusinessServiceException ex)
                {
                    this.lblMessage.Text     = ex.Message;
                    this.lblMessage.CssClass = "WarningMessage";
                }
            }
        }