//Show frmSales from. private void salesToolStripMenuItem_Click(object sender, EventArgs e) { Form frm1 = new frmSales(); frm1.Show(); }
//Search method. private void searchSales() { List <int> SearchResults = new List <int>(); string selectQuery; selectQuery = "SELECT Sales.SaleID, Sales.CustomerID, Customers.FirstName, Customers.LastName, Sales.StartDate " + "FROM Sales " + "JOIN Products ON Sales.ProductID = Products.ProductID " + "JOIN Customers ON Sales.CustomerID = Customers.CustomerID " + "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["SaleID"].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 Sale 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("Sale 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) { frmSales sResults = new frmSales(); sResults.Show(); sResults.Focus(); sResults.BringToFront(); sResults.Text = "Returned Search from Sales"; sResults.searchSaleResults(); //Close the Sale Form. frmSales closeSale = (frmSales)Application.OpenForms["frmSales"]; closeSale.Close(); this.Close(); } else { this.Close(); } } }