private void Button_AddUser_Click(object sender, RoutedEventArgs e)
        {
            if (IsEditable)
            {
                if (ListBox_Admins.SelectedIndex >= 0)
                {
                    User selectedAdmin = (User)ListBox_Admins.SelectedItem;

                    selectedAdmin.Name  = TextBox_UserName.Text;
                    selectedAdmin.Email = TextBox_UserEmail.Text;

                    ListBox_Admins.Items.Refresh();
                    UpdateInfoBox(ListBox_Admins);
                }
                else if (ListBox_Users.SelectedIndex >= 0)
                {
                    User selectedUser = (User)ListBox_Users.SelectedItem;

                    selectedUser.Name  = TextBox_UserName.Text;
                    selectedUser.Email = TextBox_UserEmail.Text;

                    ListBox_Users.Items.Refresh();
                    UpdateInfoBox(ListBox_Users);
                }
                Button_AddUser.Content = "Add User";
                IsEditable             = false;
            }
            else
            {
                ListBox_Users.Items.Add(new User(TextBox_UserName.Text, TextBox_UserEmail.Text));
            }

            TextBox_UserName.Clear();
            TextBox_UserEmail.Clear();
        }
Beispiel #2
0
 void ClearBoxes()
 {
     TextBox_UserName.Clear();
     TextBox_Password.Clear();
     //ComboBox_SelectUser.Clear();
 }
Beispiel #3
0
        private void Button_Login_Click(object sender, EventArgs e)
        {
            // These are the Text box and combobox stuffs...

            string username = TextBox_UserName.Text;
            string password = TextBox_Password.Text;
            string usertype = ComboBox_SelectUser.Text;


            // from here databse connection starts..

            DB db = new DB();

            DataTable table = new DataTable();

            MySqlDataAdapter adapter = new MySqlDataAdapter();

            MySqlCommand command = new MySqlCommand("SELECT * FROM users WHERE username = @usn and password = @pass and usertype = @type", db.getConnection());

            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value  = username;
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = password;
            command.Parameters.Add("@type", MySqlDbType.VarChar).Value = usertype;

            adapter.SelectCommand = command;

            adapter.Fill(table);
            // here ends database things.

            if (usertype == "Manager")
            {
                if (table.Rows.Count > 0)
                {
                    // MessageBox.Show("Manager Login Successful");
                    this.Hide();
                    ManagerForm managerform = new ManagerForm();
                    managerform.Show();
                    // from here we are going to manager page..
                }
                else
                {
                    MessageBox.Show("Manager Login Unsuccessful");
                    TextBox_UserName.Clear();
                    TextBox_Password.Clear();
                }
            }
            else if (usertype == "Admin")
            {
                if (table.Rows.Count > 0)
                {
                    //MessageBox.Show("Admin Login Successful");

                    this.Hide();
                    AdminForm adminform = new AdminForm();
                    adminform.Show();

                    // from here we are going to admin page..
                }
                else
                {
                    MessageBox.Show("Admin Login Unsuccessful");
                    TextBox_UserName.Clear();
                    TextBox_Password.Clear();
                }
            }
        }