public void FillAllUsers() { // Clear out global users list, in case it's been updated. GlobalVars.uList.Clear(); // Clear out current listbox. lb_UsersList.Items.Clear(); // Setting up DB stuff. string s_ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data " + "Source=|DataDirectory|\\CloseoutApp.accdb"; string s_Query = "SELECT UserID, UserName, UserTitle, UserArea, CanEditData " + "FROM Users ORDER BY UserID;"; using (OleDbConnection AccessConn = new OleDbConnection(s_ConnString)) { using (OleDbCommand AccessCmd = AccessConn.CreateCommand()) { AccessCmd.CommandText = s_Query; try { AccessConn.Open(); OleDbDataReader rdr = AccessCmd.ExecuteReader(); while (rdr.Read()) { User u = new User(); u.UserID = rdr.GetInt32(0); u.UserName = rdr.GetString(1); u.UserTitle = rdr.GetString(2); u.UserArea = rdr.GetString(3); u.CanEditData = rdr.GetBoolean(4); GlobalVars.uList.Add(u); } rdr.Close(); AccessConn.Close(); } catch (Exception e) { MessageBox.Show("Database error:\n" + e.Message + "\nPlease take a screenshot and\nreport this to Ashton.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } foreach (User u in GlobalVars.uList) { lb_UsersList.Items.Add(u.UserName); } lb_UsersList.SelectedIndex = 0; }
private void ReadUsersIntoListBox() { // Setting up DB stuff. string s_ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data " + "Source=|DataDirectory|\\CloseoutApp.accdb"; string s_Query = "SELECT UserID, UserName, UserTitle, UserArea FROM Users " + "ORDER BY UserName;"; using (OleDbConnection AccessConn = new OleDbConnection(s_ConnString)) { using (OleDbCommand AccessCmd = AccessConn.CreateCommand()) { AccessCmd.CommandText = s_Query; try { AccessConn.Open(); OleDbDataReader rdr = AccessCmd.ExecuteReader(); while (rdr.Read()) { User newUser = new User(); newUser.UserID = rdr.GetInt32(0); newUser.UserName = rdr.GetString(1); newUser.UserTitle = rdr.GetString(2); newUser.UserArea = rdr.GetString(3); userList.Add(newUser); } rdr.Close(); } catch (Exception ex) { MessageBox.Show("Database error:\n" + ex.Message + "\nPlease take a screenshot and\nreport this to Ashton.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } // Add users to the ListBox. foreach (User u in userList) { lb_Users.Items.Add(u.UserName); } }
private void FillUsersList() { /* FillUsersList() * * 1. Clears out current listbox and global users list. * 2. Reads user's ID and Name into global users list and then into a ComboBox. * */ // Clear out global users list, in case it's been updated. GlobalVars.uList.Clear(); // Clear out current listbox. cb_AssignedTo.Items.Clear(); // Setting up DB stuff. string s_ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data " + "Source=|DataDirectory|\\CloseoutApp.accdb"; string s_Query = "SELECT UserID, UserName " + "FROM Users ORDER BY UserName;"; using (OleDbConnection AccessConn = new OleDbConnection(s_ConnString)) { using (OleDbCommand AccessCmd = AccessConn.CreateCommand()) { AccessCmd.CommandText = s_Query; try { AccessConn.Open(); OleDbDataReader rdr = AccessCmd.ExecuteReader(); while (rdr.Read()) { User u = new User(); u.UserID = rdr.GetInt32(0); u.UserName = rdr.GetString(1); GlobalVars.uList.Add(u); } rdr.Close(); AccessConn.Close(); } catch (Exception e) { MessageBox.Show("Database error:\n" + e.Message + "\nPlease take a screenshot and\nreport this to Ashton.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } foreach (User u in GlobalVars.uList) { cb_AssignedTo.Items.Add(u.UserName); } cb_AssignedTo.SelectedIndex = -1; }