MSDN Magazine Launch Issue - February 15, 2008 - (Page 58) Figure 7 Execute Search Triggered from Search Button private void executeSearch_Click(object sender, EventArgs e) { try { companiesAdapter = new SalesDataSetTableAdapters.CompaniesTableAdapter(); CompaniesBindingSource.DataSource = companiesAdapter.GetDataByCompanyAndIndustry( companyNameText.Text, industryText.Text); } catch (Exception ex) { MessageBox.Show(ex.Message, “Sales Add-in”, MessageBoxButtons.OK); } } Figure 8 Handling BindingSource Change private void CompaniesBindingSource_CurrentChanged(object sender, EventArgs e) { DataRowView company = (DataRowView)(CompaniesBindingSource.Current); try { string[] xData = new string[4]; double[] yData = new double[4]; if (company != null) { salesAdapter = new SalesDataSetTableAdapters.SalesTableAdapter(); SalesDataSet.SalesDataTable sales = salesAdapter.GetDataByCustomerID((int)(company[“ID”])); DataTableReader rdr = sales.CreateDataReader(); int i = 0; while ((rdr.Read()) && (i < xData.Length) && (i < yData.Length)) { xData[i] = String.Format(“Q{0} {1}”, rdr[“SalesQuarter”].ToString(), rdr[“SalesYear”].ToString()); yData[i] = Convert.ToDouble(rdr[“SalesAmount”]); i++; } OnSalesDataChanged(company[“CompanyName”].ToString(), xData, yData); } } catch (Exception ex) { MessageBox.Show(ex.Message, “Sales Add-in”, MessageBoxButtons.OK); } } Adapter and calls the GetDataByCompanyAndIndustry method to retrieve data according to the parameters that the user entered in the search fields (the percent sign in Figure 8 indicates a wildcard search). This data will then be used to populate the Contact and Address fields to display customer information. In the code behind this form, there are also a couple of helper functions. For example, I’ve added an event on the CompaniesBindingSource object to handle the case where a user is browsing through the sales data from within the controls (see Figure 8). Figure 9 WPF Chart Control 58 msdnmagazine Office Business Applications
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.