MSDN Magazine Launch Issue - February 15, 2008 - (Page 56) RecentSales.cs The primary class file for the form region. RecentSales.Designer.cs The designer file that contains some default code for the form region. RecentSales.rexs The XML file that is required to display the form region. Now let’s begin customization. After creating the form region, the default view in Visual Studio should be the designer mode of the form region. If not, right-click on RecentSales.cs and select View Designer. You can now begin to add controls to your form. To keep things simple, I’m going to add three primary things to my custom Replacement form region: a search control that lists customer information, a WPF control that displays updated sales data, and a checkbox for controlling whether the user control is displayed or hidden. Figure 4 illustrates the controls that I’ve added to my project in the context of my Visual Studio IDE. Show Sales Data and Customer Search The form region represents the design surface and supports the dragging and dropping of controls from the Toolbox to the design surface. So drag a checkbox to the design surface and set its Name property to showChart and its Text property to “Show Sales Data.” Then double-click the checkbox control and add the following code to call the UpdateChart method—this method will update both the data and the visibility of the WPF sales chart: private void checkBox1_CheckedChanged(object sender, EventArgs e) { UpdateChart(); } I’ll return to this method a little later on in the article. The Sales Search user control allows you to enter some search criteria and browse a small database of customer information that is dynamically updated within the control. To enable this search functionality, I’ve added a new project called SalesControlLibrary (a Windows Forms Control Library project) to the CustomOFR solution and then added the search control from the Toolbox onto the form region. There are two main parts to the SalesControlLibrary project in my solution: a connection to the data source and the user control that I’ll use in the custom Replacement form region. Connecting the Data Source Figure 3 Entering Custom Message Class Type Figure 4 Form Region Designer With the new project added to the solution, you can now add a data source by clicking Data and Add New Data Source. As you might expect, this sets off the Add New Data Source Wizard, which first prompts you to define and configure a simple connection to a data source (database). For this sample I’m using an Access database called Sales.mdb (which is included in the code download) with the following four schema elements (as you can see in Figure 5): CustomerID is the unique ID for a customer, SalesQuarter represents the fiscal quarter for sales, SalesYear represents the fiscal year in which sales were recorded, and SalesAmount is the dollar amount of a sale. If you were to integrate this add-in with a line-of-business (LOB) system, thus classifying this application as an Office Business Application (OBA), then you’d likely use a Windows Communication Foundation (WCF) service proxy to manage the connection and communication with your LOB system. Using services as proxies to LOB systems is a great way to circumnavigate difficult system interfaces or to pull specific business data directly into the context of your customer’s common office applications. 56 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.