Ejemplo n.º 1
0
        private void UpdatePrivBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (UserNameComboBox.SelectedValue != null && UserNameComboBox.Text != "")
                {
                    UserNameComboBox.BackColor = UserBGColor;
                    if (UserNameComboBox.Text.ToLower() != "admin")
                    {
                        int UserID = int.Parse(UserNameComboBox.SelectedValue.ToString());
                        if (EditAdminsCheckBox.Checked)
                        {
                            if (!PriviligesMgmt.IsPriviligeExist(UserID, EventsMgmt.SelectEventIDbyName("EditAdmins")))
                            {
                                PriviligesMgmt.AddPrivilige(UserID, EventsMgmt.SelectEventIDbyName("EditAdmins"));
                            }
                        }
                        else
                        {
                            if (PriviligesMgmt.IsPriviligeExist(UserID, EventsMgmt.SelectEventIDbyName("EditAdmins")))
                            {
                                PriviligesMgmt.RemovePrivilige(UserID, EventsMgmt.SelectEventIDbyName("EditAdmins"));
                            }
                        }
                        if (AdminCheckBox.Checked == true)
                        {
                            UsersMgmt.MakeUserAdmin(UserID, 1);
                        }
                        else
                        {
                            UsersMgmt.MakeUserAdmin(UserID, 0);
                        }

                        MessageBox.Show(MsgTxt.AddedSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        UserNameComboBox.Text = "";
                    }
                    else
                    {
                        MessageBox.Show(MsgTxt.CannotChangeAdminTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show(MsgTxt.PleaseAddAllRequiredFields, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    UserNameComboBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                    UserNameComboBox.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [UpdatePrivBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();;
            }
        }
Ejemplo n.º 2
0
 private void UpdatePrivBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (Validators.TxtBoxNotEmpty(UserNameComboBox.Text))
         {
             int UserID = int.Parse(UserNameComboBox.SelectedValue.ToString());
             if (UsersMgmt.SelectUserInfoByID(UserID)["IsAdmin"].ToString() == "1")
             {
                 MessageBox.Show(UiText.CannotEditAdminsTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             else
             {
                 foreach (CheckBox aCheckBox in PriviligesGB.Controls.OfType <CheckBox>())
                 {
                     if (aCheckBox.Checked == true)
                     {
                         if (!PriviligesMgmt.IsPriviligeExist(UserID, EventsMgmt.SelectEventIDbyName(aCheckBox.Tag.ToString())))
                         {
                             PriviligesMgmt.AddPrivilige(UserID, EventsMgmt.SelectEventIDbyName(aCheckBox.Tag.ToString()));
                         }
                     }
                     else
                     {
                         if (PriviligesMgmt.IsPriviligeExist(UserID, EventsMgmt.SelectEventIDbyName(aCheckBox.Tag.ToString())))
                         {
                             PriviligesMgmt.RemovePrivilige(UserID, EventsMgmt.SelectEventIDbyName(aCheckBox.Tag.ToString()));
                         }
                     }
                 }
                 MessageBox.Show(MsgTxt.UpdateSuccessfully, MsgTxt.UpdateSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
         else
         {
             MessageBox.Show(MsgTxt.PleaseSelectTxt + " " + MsgTxt.UserTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [UpdatePrivBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
         throw;
     }
 }