private static void FillTextBoxesWithGridViewRowData(Panel panelName, DataGridView dataGridViewName, string[] wcfColumnNames)
        {
            try
            {
                var controls = from Control control in panelName.Controls
                               where control.GetType().Name.Equals("TextBox") || control.GetType().Name.Equals("ComboBox")
                               orderby control.TabIndex
                               select control;
                List <Control> orderedContolsList = controls.ToList();
                int            nextCell           = 0;
                int            colmnNamesIndex    = 0;

                while (colmnNamesIndex < wcfColumnNames.Length)
                {
                    if (dataGridViewName.SelectedRows[0].Cells[nextCell].Value == null)
                    {
                        nextCell++;
                    }
                    if (dataGridViewName.SelectedRows[0].Cells[nextCell].Value != null)
                    {
                        orderedContolsList[colmnNamesIndex].Text = dataGridViewName.SelectedRows[0].Cells[wcfColumnNames[colmnNamesIndex]].Value.ToString().Trim();
                        nextCell++;
                        colmnNamesIndex++;
                    }
                }
            }
            catch (Exception ex)
            {
                SampleMessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void login_btn_Click(object sender, EventArgs e)
        {
            try
            {
                if (Membership.ValidateUser(username_txt.Text, password_txt.Text))
                {
                    currentUser = Membership.GetUser(username_txt.Text);
                    GenericIdentity identity  = new GenericIdentity(currentUser.UserName);
                    RolePrincipal   principal = new RolePrincipal(identity);
                    System.Threading.Thread.CurrentPrincipal = principal;

                    currentUser.IsApproved = true;

                    mainForm = new MainForm();
                    mainForm.Show();
                    this.Hide();
                }
                else
                {
                    invalidLogin_label.Text      = "Invalid username or password.Try again!";
                    invalidLogin_label.ForeColor = Color.Red;
                }
            }
            catch (Exception ex)
            {
                SampleMessageBox.Show(ex.GetType().ToString() + "\n Call lazy administrator" + "\n" + ex.Message);
            }
        }
        /// <summary>
        /// Fill only TextBoxes and ComboBoxes in specific System.Windows.Forms.Panel
        /// with data from selected row of specific System.Windows.Forms.DataGridView object.
        /// Data fill according tabIndex of controls in a Panel container
        /// and index of columns in the DataGridView.Columns collection.
        /// </summary>
        /// <param name="panelName">Current Panel container that contains TextBoxes and ComboBoxes</param>
        /// <param name="dataGridViewName">Current DataGridView instance which is a source of data</param>
        public static void FillTextBoxesAndComboBoxesWithGridViewRowData(Panel panelName, DataGridView dataGridViewName)
        {
            try
            {
                var controls = from Control control in panelName.Controls
                               where control.GetType().Name.Equals("TextBox") || control.GetType().Name.Equals("ComboBox")
                               orderby control.TabIndex
                               select control;

                int nextCell = 0;
                foreach (Control control in controls)
                {
                    if (dataGridViewName.SelectedRows[0].Cells[nextCell].Value == null)
                    {
                        nextCell++;
                    }
                    if (dataGridViewName.SelectedRows[0].Cells[nextCell].Value != null)
                    {
                        control.Text = dataGridViewName.SelectedRows[0].Cells[nextCell].Value.ToString().Trim();
                        nextCell++;
                    }
                }
            }
            catch (Exception ex)
            {
                SampleMessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// Check whether the value exists in specific table in database
        /// </summary>
        /// <param name="connectionStr">Connection string to the database that contains the table</param>
        /// <param name="tableName">Table name</param>
        /// <param name="columName">Column name that contains the value</param>
        /// <param name="value">Value to check</param>
        /// <returns></returns>
        public static bool IsValueExistsInDB(string connectionStr, string tableName, string columName, string value)
        {
            SqlConnection          dbCon      = new SqlConnection(connectionStr);
            SqlCommand             cmd        = dbCon.CreateCommand();
            SqlParameterCollection parameters = cmd.Parameters;
            bool result = false;

            cmd.CommandText = "SELECT COUNT(" + columName + ") FROM " + tableName + " WHERE " + columName + "= @value";
            parameters.AddWithValue("@value", value);

            try
            {
                dbCon.Open();
                int counter = (int)cmd.ExecuteScalar();
                dbCon.Close();
                if (counter == 1 || counter > 1)
                {
                    result = true;
                    //SampleMessageBox.Show("Exist");
                }
                else
                {
                    result = false;
                    //SampleMessageBox.Show("Not exist");
                }
            }
            catch (Exception ex)
            {
                result = false;
                SampleMessageBox.Show(ex.Message);
            }
            return(result);
        }
        private void DisplayItems()
        {
            try
            {
                this.dataTable.Clear();

                GetItemsForDataGridNavigation();

                //MessageBox.Show(Thread.CurrentThread.ManagedThreadId.ToString());
                if (form.InvokeRequired)
                {
                    try
                    {
                        form.Invoke(new UpdateNavigationDelegate(UpdateNavigation), new object[] { this.dataTable, this.firstOrLastPage });
                    }
                    catch (ObjectDisposedException)
                    {
                        return;
                    }
                }
            }
            catch (ThreadInterruptedException)
            {
                SampleMessageBox.Show("ThreadInterruptedException", "Info");
                return;
            }
            catch (ThreadAbortException)
            {
                SampleMessageBox.Show("ThreadAbortException", "Info");
            }
            finally
            {
                //SampleMessageBox.Show("Finally block reached.", "Info");
            }
        }
Ejemplo n.º 6
0
        private void AddOrRemoveUserToRoles(UserToRoles addOrRemove)
        {
            try
            {
                string   username           = allUsersInUserToRole_comboBox.SelectedItem.ToString();
                string[] checkedRolesArray  = RolesHelper.GetAllCheckedItemsArray(this.userToRole_groupBox);
                string   checkedRolesString = RolesHelper.GetAllCheckedItems(this.userToRole_groupBox);

                switch (addOrRemove)
                {
                case UserToRoles.Add:
                {
                    try
                    {
                        Roles.AddUserToRoles(username, checkedRolesArray);
                        SampleMessageBox.Show(String.Format("Successfully add {0} to  {1} role(s)", username, checkedRolesString));
                    }
                    catch (ProviderException)
                    {
                        if (checkedRolesArray.Length == 1)
                        {
                            SampleMessageBox.Show(String.Format("{0} is already in {1} role", username, checkedRolesString));
                        }
                        else
                        {
                            SampleMessageBox.Show(String.Format("{0} is already in some of these roles:\n{1} ", username, checkedRolesString));
                        }
                    }
                    catch (ArgumentException)
                    {
                        SampleMessageBox.Show("Please check some of roles");
                    }
                    break;
                }

                case UserToRoles.Remove:
                {
                    try
                    {
                        Roles.RemoveUserFromRoles(username, checkedRolesArray);
                        SampleMessageBox.Show(String.Format("Successfully remove {0} from {1} role(s)", username, checkedRolesString));
                    }
                    catch (ArgumentException)
                    {
                        SampleMessageBox.Show("Please check some of roles");
                    }
                    break;
                }
                }
                DisplayUsers(Display.FirstPage);
                RolesHelper.UncheckedAllCheckboxes(this.userToRole_groupBox);
                allUsersInUserToRole_comboBox.SelectedIndex = -1;
            }
            catch (NullReferenceException)
            {
                SampleMessageBox.Show("Please, select user!");
            }
        }
Ejemplo n.º 7
0
        private void insert_btn_Click(object sender, EventArgs e)
        {
            this.categoriesData.CategoryName = this.CategoryName_txt.Text;
            this.categoriesCRUD.Insert(this.categoriesData);
            SampleMessageBox.Show(this.categoriesCRUD.GetResult());

            DisplayCategories(Display.LastPage);
            ClearAll();
        }
        private void update_btn_Click(object sender, EventArgs e)
        {
            this.vendorsData.VendorName = this.VendorName_txt.Text;
            this.vendorsCRUD.Update(this.vendorsData);
            SampleMessageBox.Show(this.vendorsCRUD.GetResult());

            DisplayVendors(Display.FirstPage);
            ClearAll();
        }
        private void insert_btn_Click(object sender, EventArgs e)
        {
            this.vendorsData.VendorName = VendorName_txt.Text;
            this.vendorsCRUD.Insert(vendorsData);
            SampleMessageBox.Show(this.vendorsCRUD.GetResult());
            SampleMessageBox.Show(this.vendorsCRUD.GetResult());

            ClearAll();
            DisplayVendors(Display.LastPage);
        }
        private void delete_btn_Click(object sender, EventArgs e)
        {
            this.productsData.ProductNewName = this.ProductName_txt.Text;
            this.productsCRUD.Delete(this.productsData);

            SampleMessageBox.Show(this.productsCRUD.GetResult());

            DisplayProducts(Display.FirstPage);
            FillAllComboBoxesWithDataBaseValues();
            ClearAll();
        }
Ejemplo n.º 11
0
 public Admin()
 {
     InitializeComponent();
     try
     {
         this.adminFormAuthorization = RolesForSpecificForm.Default.Admin;
     }
     catch (ConfigurationErrorsException ex)
     {
         SampleMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 12
0
        public Manager()
        {
            InitializeComponent();

            try
            {
                this.managerFormAuthorization = RolesForSpecificForm.Default.Manager;
            }
            catch (ConfigurationErrorsException ex)
            {
                SampleMessageBox.Show(ex.Message);
            }
            //this.managerFormAuthorization = RolesForSpecificForm.Default.Manager;
        }
        private void Manager_btn_Click(object sender, EventArgs e)
        {
            this.managerMainForm = new Manager();
            string invalidAuthorizationMessage;
            bool   isUserAuthorized = this.managerMainForm.CheckForPermission(userRoles, out invalidAuthorizationMessage);

            if (isUserAuthorized)
            {
                FormsUI.LoadChildForm(this, this.managerMainForm, ChildNastedLevel.Nasted, this.Manager_btn);
            }
            else
            {
                SampleMessageBox.Show(invalidAuthorizationMessage);
            }
        }
Ejemplo n.º 14
0
        private void show_btn_Click(object sender, EventArgs e)
        {
            object o2 = null;

            try
            {
                int i2 = (int)o2;
            }
            catch (Exception ex)
            {
                SampleMessageBox.Show(ex.Message);
                //SampleMessageBox.Show(ex.Message + "\n" + ex.Message + "\n" + ex.Message + "\n" + ex.Message + "\n" + ex.Message + "\n" + ex.Message + "\n" + ex.Message);
            }
            //SampleMessageBox.Show(shortStr);
            //SampleMessageBox.Show(longStr);
        }
Ejemplo n.º 15
0
        private void createUser_btn_Click(object sender, EventArgs e)
        {
            try
            {
                Membership.CreateUser(this.newUsername_txt.Text, this.password_txt.Text);
                SampleMessageBox.Show(String.Format("New user: {0} is successfully created", this.newUsername_txt.Text));
                Clear.AllTextBoxesAndComboBoxes(this.createUser_groupBox);
                DisplayUsers(Display.FirstPage);

                FillComboBoxWithUsers();
            }
            catch (MembershipCreateUserException ex)
            {
                SampleMessageBox.Show(GetErrorMessage(ex.StatusCode));
            }
        }
        private void update_btn_Click(object sender, EventArgs e)
        {
            this.productsData.ProductNewName = this.ProductName_txt.Text;
            this.productsData.CategoryName   = this.Categories_comboBox.Text;
            this.productsData.VendorName     = this.Vendor_comboBox.Text;
            this.productsData.ProductPrice   = decimal.Parse(this.UnitPrice_txt.Text);
            this.productsData.Quantity       = int.Parse(this.Quantity_txt.Text);
            this.productsData.StoreName      = this.Stores_comboBox.Text;
            this.productsData.TownName       = this.Towns_comboBox.Text;

            this.productsCRUD.Update(this.productsData);
            SampleMessageBox.Show(this.productsCRUD.GetResult());

            DisplayProducts(Display.FirstPage);
            FillAllComboBoxesWithDataBaseValues();
            ClearAll();
        }
 private void createRole_btn_Click(object sender, EventArgs e)
 {
     if (!Roles.RoleExists(createRole_txt.Text))
     {
         Roles.CreateRole(createRole_txt.Text);
         if (Roles.RoleExists(createRole_txt.Text))
         {
             SampleMessageBox.Show(createRole_txt.Text + " role is created!");
             Clear.AllTextBoxesAndComboBoxes(this.createRole_groupBox);
             AddCheckBoxesRolesInAllContainers();
         }
     }
     else
     {
         SampleMessageBox.Show(createRole_txt.Text + " is already exists!");
     }
 }
        private static DataTable FillDataTable(string connectionStr, string cmdStr)
        {
            SqlConnection dbCon = new SqlConnection(connectionStr);
            SqlCommand    cmd   = new SqlCommand(cmdStr, dbCon);
            DataTable     dt    = new DataTable();;

            try
            {
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
            }
            catch (Exception ex)
            {
                SampleMessageBox.Show(ex.Message);
            }

            return(dt);
        }
Ejemplo n.º 19
0
        private void deleteUser_btn_Click(object sender, EventArgs e)
        {
            try
            {
                string username = allUsersInDeleteUser_comboBox.SelectedItem.ToString();
                if (Membership.DeleteUser(username))
                {
                    SampleMessageBox.Show(String.Format("Successfully deleted {0} from membership database", username));
                    DisplayUsers(Display.FirstPage);

                    FillComboBoxWithUsers();
                    allUsersInDeleteUser_comboBox.SelectedIndex = -1;
                }
            }
            catch (NullReferenceException)
            {
                SampleMessageBox.Show("Please, first select user!");
            }
        }
        private static void DisplayRecords(string connectionStr, string cmdStr, DataGridView dataGridName)
        {
            SqlConnection dbCon = new SqlConnection(connectionStr);
            SqlCommand    cmd   = new SqlCommand(cmdStr, dbCon);

            try
            {
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                //dt.Columns.Add();
                da.Fill(dt);
                dataGridName.DataSource = dt;

                //da.Update(dt);
            }
            catch (Exception ex)
            {
                SampleMessageBox.Show(ex.Message);
            }
        }
        private static void FillTextBoxWithDBValues(TextBox textBoxName, string connectionStr, string tableName, string columnName)
        {
            AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();
            string cmdStr = @"SELECT " + columnName + " FROM " + tableName + " ";

            SqlConnection dbCon = new SqlConnection(connectionStr);
            SqlCommand    cmd   = new SqlCommand(cmdStr, dbCon);

            try
            {
                dbCon.Open();

                SqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    namesCollection.Add(dr[columnName].ToString());
                }
                dbCon.Close();

                textBoxName.AutoCompleteMode         = AutoCompleteMode.Suggest;
                textBoxName.AutoCompleteSource       = AutoCompleteSource.CustomSource;
                textBoxName.AutoCompleteCustomSource = namesCollection;

                //foreach (DataRow dr in dt.Rows)
                //{
                //    comboBoxName.Items.Add(dr[columnName].ToString().Replace(" ", ""));
                //    //comboBoxName.AutoCompleteCustomSource.Add(dr[columnName].ToString().Replace(" ", ""));
                //}

                //comboBoxName.SelectedIndex = 0;
                //for (int i = 0; i < dt.Rows.Count; i++)
                //{
                //    comboBoxName.Items.Add(dt.Rows[i][columnName].ToString().Replace(" ", ""));
                //}
            }
            catch (SqlException ex)
            {
                SampleMessageBox.Show(ex.Message);
            }
        }
        private void deleteRoles_btn_Click(object sender, EventArgs e)
        {
            string[] checkedRolesArray  = RolesHelper.GetAllCheckedItemsArray(this.deleteRoles_groupBox);
            string   checkedRolesString = RolesHelper.GetAllCheckedItems(this.deleteRoles_groupBox);
            int      counter            = 0;

            for (int i = 0; i < checkedRolesArray.Length; i++)
            {
                try
                {
                    string[] usersInRole = Roles.GetUsersInRole(checkedRolesArray[i]);

                    if (usersInRole.Length > 0)
                    {
                        Roles.RemoveUsersFromRole(usersInRole, checkedRolesArray[i]);
                    }

                    if (Roles.DeleteRole(checkedRolesArray[i], true))
                    {
                        counter++;
                    }
                }
                catch (Exception ex)
                {
                    SampleMessageBox.Show(ex.Message);
                }
            }

            if (counter != 0)
            {
                SampleMessageBox.Show(String.Format("Successfully deleted {0} role(s)", checkedRolesString));
                RolesHelper.UncheckedAllCheckboxes(this.deleteRoles_groupBox);
                AddCheckBoxesRolesInAllContainers();
                DisplayUsers(Display.FirstPage);
            }
            else
            {
                SampleMessageBox.Show("Please,check some of roles to delete it");
            }
        }
        private static void FillListWithTextBoxValues(List <string> listName, Panel panelName)
        {
            try
            {
                var controls = from Control control in panelName.Controls
                               orderby control.TabIndex
                               select control;

                //foreach (Control control in panelName.Controls.Cast<Control>().OrderBy(c => c.TabIndex))
                foreach (Control control in controls)
                {
                    if (control is TextBox)
                    {
                        listName.Add(control.Text);
                    }
                }
            }
            catch (Exception ex)
            {
                SampleMessageBox.Show(ex.Message);
            }
        }
        private static void FillComboBoxWithDBValues(ComboBox comboBoxName, string connectionStr, string tableName, string columnName)
        {
            comboBoxName.Items.Clear();
            //string cmdStr = @"SELECT " + columnName + " FROM " + tableName + " ORDER BY " + columnName + " ASC";

            string cmdStr = @"SELECT " + columnName + " FROM " + tableName + " ";

            SqlConnection dbCon = new SqlConnection(connectionStr);
            SqlCommand    cmd   = new SqlCommand(cmdStr, dbCon);

            try
            {
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();

                da.Fill(dt);

                //comboBoxName.DataSource = dt;
                //comboBoxName.DisplayMember = columnName;

                foreach (DataRow dr in dt.Rows)
                {
                    comboBoxName.Items.Add(dr[columnName].ToString().Replace(" ", ""));
                    //comboBoxName.AutoCompleteCustomSource.Add(dr[columnName].ToString().Replace(" ", ""));
                }


                //comboBoxName.SelectedIndex = 0;
                //for (int i = 0; i < dt.Rows.Count; i++)
                //{
                //    comboBoxName.Items.Add(dt.Rows[i][columnName].ToString().Replace(" ", ""));
                //}
            }
            catch (SqlException ex)
            {
                SampleMessageBox.Show(ex.Message);
            }
        }
        private void AddOrRemoveRolesToForm(RolesToForm addOrRemove)
        {
            string[] checkedRolesArray  = RolesHelper.GetAllCheckedItemsArray(this.rolesToForm_groupBox);
            string   checkedRolesString = RolesHelper.GetAllCheckedItems(this.rolesToForm_groupBox);

            int  addCounter        = 0;
            int  removeCounter     = 0;
            bool isRoleExistToForm = false;

            try
            {
                string selectedForm = this.formsRolesCollections_comboBox.SelectedItem.ToString();

                if (checkedRolesArray.Length != 0)
                {
                    foreach (SettingsProperty currentProperty in RolesForSpecificForm.Default.Properties)
                    {
                        if (currentProperty.Name.Equals(selectedForm))
                        {
                            foreach (string role in checkedRolesArray)
                            {
                                if (currentProperty.PropertyType == typeof(StringCollection))
                                {
                                    if (RolesForSpecificForm.Default[currentProperty.Name] == null)
                                    {
                                        RolesForSpecificForm.Default[currentProperty.Name] = new StringCollection();
                                    }
                                    switch (addOrRemove)
                                    {
                                    case RolesToForm.Add:
                                    {
                                        if (!(RolesForSpecificForm.Default[currentProperty.Name] as StringCollection).Contains(role))
                                        {
                                            try
                                            {
                                                (RolesForSpecificForm.Default[currentProperty.Name] as StringCollection).Add(role);
                                                RolesForSpecificForm.Default.Save();
                                                addCounter++;
                                            }
                                            catch (Exception ex)
                                            {
                                                SampleMessageBox.Show(ex.Message);
                                            }
                                        }
                                        else
                                        {
                                            isRoleExistToForm = true;
                                        }
                                        break;
                                    }

                                    case RolesToForm.Remove:
                                    {
                                        try
                                        {
                                            (RolesForSpecificForm.Default[currentProperty.Name] as StringCollection).Remove(role);
                                            RolesForSpecificForm.Default.Save();
                                            removeCounter++;
                                        }
                                        catch (Exception ex)
                                        {
                                            SampleMessageBox.Show(ex.Message);
                                        }
                                        break;
                                    }
                                    }
                                }
                            }
                        }
                    }
                    if (isRoleExistToForm)
                    {
                        SampleMessageBox.Show(String.Format("{0} role(s) already to {1} form", checkedRolesString, selectedForm));
                    }
                    if (addCounter == checkedRolesArray.Length)
                    {
                        SampleMessageBox.Show(String.Format("Successfully add {0} role(s) to {1} form", checkedRolesString, selectedForm));
                    }
                    if (removeCounter == checkedRolesArray.Length)
                    {
                        SampleMessageBox.Show(String.Format("Successfully remove {0} role(s) from {1} form", checkedRolesString, selectedForm));
                    }
                }
                else
                {
                    SampleMessageBox.Show(String.Format("Please first check some of roles"));
                }
            }
            catch (NullReferenceException)
            {
                SampleMessageBox.Show("Please first select FormsRolesCollection");
            }

            DisplayFormsRoles(Display.FirstPage);
            RolesHelper.UncheckedAllCheckboxes(this.rolesToForm_groupBox);
            this.formsRolesCollections_comboBox.SelectedIndex = -1;
        }