private void btnAddUser_Click(object sender, EventArgs e) { loadCommand = "add"; //Lines 70 - 73 loads userDetailsForm, passes loadCommand value to be used in the form and closes this form Form form = new UserDetailsForm(loadCommand, userArray); form.Show(); this.Dispose(); }
private void btnUpdateUser_Click(object sender, EventArgs e) { loadCommand = "update"; //sets loadCommand value if (dgvUsers.SelectedRows.Count == 0) //validation that there is at least one row selected { MessageBox.Show("Please select a customer"); //if above statement is true, shows message box and end function execcution. Row is usually autoselected from the beginning but this is just a precaution return; } foreach (DataRow row in dtUsers.Rows) //runs through each row in users table in database { if (dgvUsers.SelectedCells[0].Value.ToString() == row["userid"].ToString()) //makes sure the userid of the selected row is equal to the userid of the current row in the foreach loop { for (int i = 0; i < 6; i++) //populates an array to be passed to UserDetailsForm, the number of indexes is equal to the number of columns in the users table { userArray[i] = dgvUsers.SelectedCells[i].Value.ToString(); } } } Form form = new UserDetailsForm(loadCommand, userArray); //lines 94 - 96 opens UserDetailsForm, passes data through, and closes this form form.Show(); this.Dispose(); }