Beispiel #1
0
        private void Btn_Add_Role_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (TextBoxRoleName.Text == "")
                {
                    MessageBox.Show("Role Name is required", "Warning", MessageBoxButton.OK);
                    TextBoxRoleName.Focus();
                }
                else
                {
                    MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are You Sure?", "Insert Confirmation", System.Windows.MessageBoxButton.YesNo);

                    if (messageBoxResult == MessageBoxResult.Yes)


                    {
                        var checkrole = connection.Roles.FirstOrDefault(S => S.Name == TextBoxRoleName.Text);
                        if (checkrole == null)
                        {
                            var input_role = new Role(TextBoxRoleName.Text);
                            connection.Roles.Add(input_role);
                            var insert = connection.SaveChanges();
                            if (insert >= 1)
                            {
                                MessageBox.Show("Role has been inserted");
                            }
                            reset_addrole();
                            TB_M_Role.ItemsSource = connection.Roles.ToList();
                        }
                        else
                        {
                            MessageBox.Show("Role has been used");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            Combo_User_Role.ItemsSource = connection.Roles.ToList();
        }
        /// <summary>
        /// The Method that get called on Page Load Event
        /// </summary>
        /// <param name="sender">Event Source</param>
        /// <param name="eventArgument">Event Data</param>
        protected void Page_Load(object sender, EventArgs eventArgument)
        {
            DataProvider.AuthorizeUser();
            MasterPage masterPage = this.Page.Master;
            Header     headerPage = (Header)masterPage;

            headerPage.DisplayDataFromMasterPage(Session["UserName"].ToString());
            //Session["EnableProductSelection"] = false;
            //Session["AddAllOption"] = "As Selected";
            headerPage.DisplayProductSelectionControl(false);

            if (!Page.IsPostBack)
            {
                LabelRequiredFields.Text = Resources.Labels.RequiredFields;
                if (Request.Form["ROLE_ID"] != null)
                {
                    if (Request.QueryString["action"] == "update")
                    {
                        HiddenRoleID.Value = Request.Form["ROLE_ID"].ToString();
                        GetRoleDetails();
                        ButtonUpdate.Visible = true;
                        ButtonAdd.Visible    = false;
                    }
                    else
                    {
                        ButtonAdd.Visible    = true;
                        ButtonUpdate.Visible = false;
                    }
                }
                else
                {
                    ButtonAdd.Visible    = true;
                    ButtonUpdate.Visible = false;
                }
            }
            TextBoxRoleName.Focus();
        }