Exemple #1
0
        private void btnAddCustomer_Click(object sender, EventArgs e)
        {
            loadCommand = "add";        //Lines 70 - 73 loads CustomerDetailsForm, passes loadCommand value to be used in the form and closes this form
            Form form = new CustomerDetailsForm(loadCommand, customerArray);

            form.Show();
            this.Dispose();
        }
Exemple #2
0
        private void btnUpdateCustomer_Click(object sender, EventArgs e)
        {
            loadCommand = "update";                          //sets loadCommand value
            if (dgvCustomer.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 dtCustomer.Rows)                                           //runs through each row in table
            {
                if (dgvCustomer.SelectedCells[0].Value.ToString() == row["custid"].ToString()) //makes sure the custid of the selected row is equal to the custid of the current row in the foreach loop
                {
                    for (int i = 0; i < 9; i++)                                                //populates an array to be passed to customerDetailsForm, the number of indexes is equal to the number of columns in the customer table
                    {
                        customerArray[i] = dgvCustomer.SelectedCells[i].Value.ToString();
                    }
                }
            }
            Form form = new CustomerDetailsForm(loadCommand, customerArray);        //lines 97 - 99 loads new form, passes data through to the form and closes this form

            form.Show();
            this.Dispose();
        }