//Search method. private void searchCustomer() { List <int> SearchResults = new List <int>(); string selectQuery; selectQuery = "SELECT Customers.CustomerID, Categories.Category, Customers.FirstName, Customers.LastName, Customers.Address," + " Customers.Suburb, Customers.State, Customers.PostCode, Customers.Gender, Customers.BirthDate" + " FROM Customers Join Categories ON Customers.CategoryID = Categories.CategoryID" + " WHERE " + GlobalVariables.searchCretia; SqlConnection conn = ConnectionManager.DatabaseConnection(); SqlDataReader rdr = null; try { conn.Open(); SqlCommand cmd = new SqlCommand(selectQuery, conn); rdr = cmd.ExecuteReader(); //read form table and fill in to list while (rdr.Read()) { SearchResults.Add(int.Parse(rdr["CustomerID"].ToString())); } if (rdr != null) { rdr.Close(); } conn.Close(); } catch (Exception) { MessageBox.Show("Unsuccessful"); } //If list is empty. if (SearchResults.Count == 0) { MessageBox.Show("Sorry no Customer Records where found", "No Result Found", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSearchFirstName.Clear(); txtSearchLastName.Clear(); return; } //If list contains ID's and ask yser if thats what they will like to search for. else { var mbresults = MessageBox.Show("Customer Records Found at ID: " + string.Join(" , ", SearchResults) + Environment.NewLine + "Click OK to Display or Cancel", "Results Found", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); //Create a new frmsale and invoke searchSaleResults(). if (mbresults == DialogResult.OK) { frmCustomers cResults = new frmCustomers(); cResults.Show(); cResults.Focus(); cResults.BringToFront(); cResults.Text = "Returned Search from Customers"; cResults.searchCustomerResults(); this.Close(); //Close the Sale Form. frmCustomers closeCustomers = (frmCustomers)Application.OpenForms["frmCustomers"]; closeCustomers.Close(); } else { this.Close(); } } }
//Show frmCustomer form. private void customersToolStripMenuItem_Click(object sender, EventArgs e) { Form frm1 = new frmCustomers(); frm1.Show(); }