コード例 #1
0
 private void btnDeleteCustomer_Click(object sender, EventArgs e)
 {
     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;
     }
     DialogResult = MessageBox.Show("Are you sure you wish to delete the selected customer?", "Delete?", MessageBoxButtons.YesNo);  //Dialogresult function to allow for check before deleting selected record
     if (DialogResult == DialogResult.Yes)
     {
         foreach (DataRow row in dtCustomer.Rows)                                           //if statement above is true, loops through each row of table
         {
             if (dgvCustomer.SelectedCells[0].Value.ToString() == row["custid"].ToString()) //check to see if selected dgvCustomer userid is the same as the table userid
             {
                 using (SQLiteCommand cmd = conn.CreateCommand())                           //if above is true, sets SQL query based on custid of table row in loop, opens connection, runs the query, closes the connection
                 {
                     cmd.CommandText = @"DELETE FROM customer Where custid = @custID";
                     cmd.Parameters.AddWithValue("custID", row["custid"].ToString());
                     conn.Open();
                     cmd.ExecuteNonQuery();
                     conn.Close();
                 }
             }
         }
         Form form = new AllCustomers();      //refresh() not working, using new form load
         form.Show();
         this.Dispose();
     }
     else     //if the statement is false, return without deleting
     {
         return;
     }
 }
コード例 #2
0
        private void btnCustomers_Click(object sender, EventArgs e)     //lines 81 - 109 use buttons to open specific forms
        {
            Form NewForm = new AllCustomers();

            NewForm.Show();
        }