MsgBox( Cannot move next since already on last contact record. ) End If populate the controls on the form with the next contact record in the datasetPopulateControlsOnForm() Exit Subhandleerror: MsgBox( An error occurred in btnMoveNext_Click: & Err.Number & - Err.Description) Exit SubEnd Sub18.Add the following btnSave_Clickevent procedure to the form so the code executes when button is clicked. Only when the user clicks the Save button are the changes that have to the local dataset saved back to the underlying Access database. Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnSave.ClickOn Error GoTo handleerror save the changes made to the local dataset back to the database update the current dataset recordUpdateDataSet() If nothing changed, do not proceedIf Not contactDS.HasChanges(DataRowState.Added) And Not _ contactDS.HasChanges(DataRowState.Modified) And Not _ contactDS.HasChanges(DataRowState.Deleted) Then Exit Sub update the database with the current values in the datasetIf contactDS.HasChanges(DataRowState.Modified) Then _ UpdateDatabaseChanges() update the database with the added valuesIf contactDS.HasChanges(DataRowState.Added) Then _ UpdateDatabaseAdds() update the database with the deleted recordsIf contactDS.HasChanges(DataRowState.Deleted) Then _ UpdateDatabaseDeletions() populate the dataset with the new values in the database (in case someone else changed records too)
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services
MsgBox( An error occured in btnMovePrevious_Click: & Err.Number & - & _ Err.Description) Exit SubEnd Sub16.Add the following btnMoveFirst_Clickevent procedure to the form so the code executeswhen the First button is clicked. Private Sub btnMoveFirst_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnMoveFirst.ClickOn Error GoTo handleerror update the current dataset record before moving to another oneUpdateDataSet() set the current record variable to point to the first recordintCurRecord = 0 populate the controls on the form with the first contact record in the datasetPopulateControlsOnForm() Exit Subhandleerror: MsgBox( An error occurred in btnMoveFirst_Click: & Err.Number & - & _ Err.Description) Exit SubEnd Sub17.Add the following btnMoveNext_Clickevent procedure to the form so the code executeswhen the Next button is clicked. Private Sub btnMoveNext_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnMoveNext.ClickOn Error GoTo handleerror set the current record variable to point to the next record after making sure not already on the last recordIf intCurRecord < (contactDS.Tables( Contacts ).Rows.Count - 1) Then update the current dataset record before moving to another oneUpdateDataSet() intCurRecord = (intCurRecord + 1) Else244Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services
14.Add the following btnMoveLast_Clickevent procedure to the form so the code will executewhen the Last button is clicked. Private Sub btnMoveLast_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnMoveLast.ClickOn Error GoTo handleerror update the current dataset record before moving to another oneUpdateDataSet() set the current record variable to point to the last recordintCurRecord = (contactDS.Tables( Contacts ).Rows.Count - 1) populate the controls on the form with the last contact record in the datasetPopulateControlsOnForm() Exit Subhandleerror: MsgBox( An error occurred in btnMoveLast_Click: & Err.Number & - Err.Description) Exit SubEnd Sub15.Add the following btnMovePrevious_Clickevent procedure to the form so the code will cute when the Previous button is clicked. Private Sub btnMovePrevious_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnMovePrevious.ClickOn Error GoTo handleerror set the current record variable to point to the previous record after making sure not already on the firest recordIf intCurRecord >= 1 Then update the current dataset record before moving to another oneUpdateDataSet() intCurRecord = (intCurRecord - 1) ElseMsgBox( Cannot move previous since already on first contact record. ) End If populate the controls on the form with the previous contact record in the datasetPopulateControlsOnForm() Exit Subhandleerror:
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services
, contactDS.Tables( Contacts ).Rows(intCurRecord)( WorkPhone )) txtHomePhone.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( HomePhone )), _ , contactDS.Tables( Contacts ).Rows(intCurRecord)( HomePhone )) txtCellPhone.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( CellPhone )), _ , contactDS.Tables( Contacts ).Rows(intCurRecord)( CellPhone )) txtWorkEmail.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( WorkEmail )), _ , contactDS.Tables( Contacts ).Rows(intCurRecord)( WorkEmail )) txtHomeEmail.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( HomeEmail )), _ , contactDS.Tables( Contacts ).Rows(intCurRecord)( HomeEmail )) txtNotes.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( Notes )), _ , contactDS.Tables( Contacts ).Rows(intCurRecord)( Notes )) BuildGoogleBar() Exit Subhandleerror: MsgBox( An error occured in PopulateControlsOnForm: & Err.Number & - _ & Err.Description) Exit SubEnd Sub13.Add the following UpdateDataSetprocedure to the form. Sub UpdateDataSet() On Error GoTo handleerrorIf blnAddMode Then add the new record to the datasetAddRecordToDataSet() Else update the data set with any changes before moving to another recordUpdateDataSetValues() End IfExit Subhandleerror: MsgBox( An error occurred in UpdateDataSet: & Err.Number & - & Err.Description) Exit SubEnd Sub242Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services
Conn) cmdbuilder = New OleDbCommandBuilder(contactDA) PopulateDataSet() set the first record to the current recordintCurRecord = 0 populate the controls on the form with the current (first) contact(record) PopulateControlsOnForm() Exit Subhandleerror: MsgBox( An error occurred in frmContacts_Load: & Err.Number & - & _ Err.Description) Exit SubEnd Sub11.Add the following PopulateDataSetprocedure to the form to populate the local dataset withvalues from the database when requested. Sub PopulateDataSet() On Error GoTo handleerror clear the dataset from prior valuescontactDS.Clear() Open the connection to the Access databaseConn.Open() Populate the dataset with the contacts tablecontactDA.Fill(contactDS, Contacts ) Close the connection to the database while we work locally with the dataConn.Close() Exit Subhandleerror: If Conn.State = ConnectionState.Open Then Conn.Close() MsgBox( An error occurred in PopulateDataSet: & Err.Number & - & _ Err.Description) Exit SubEnd Sub12.Add the following PopulateControlsOnFormprocedure to the form to populate the fields onthe form when called. 240Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
Sub PopulateControlsOnForm() On Error GoTo handleerror Populate the fields on the form with the current record in the dataset. If the value is null then set the field to an empty string (otherwise an error will be raised). txtContactId.Text = _ contactDS.Tables( Contacts ).Rows(intCurRecord)( ContactId ) txtLName.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( LastName )), , contactDS.Tables( Contacts ).Rows(intCurRecord)( LastName )) txtFName.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( FirstName )), , contactDS.Tables( Contacts ).Rows(intCurRecord)( FirstName )) txtMName.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( MiddleName )), , contactDS.Tables( Contacts ).Rows(intCurRecord)( MiddleName )) txtTitle.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( Title )), _ , contactDS.Tables( Contacts ).Rows(intCurRecord)( Title )) txtCompany.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( Company )), , contactDS.Tables( Contacts ).Rows(intCurRecord)( Company )) txtAddress1.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( Address1 )), , contactDS.Tables( Contacts ).Rows(intCurRecord)( Address1 )) txtAddress2.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( Address2 )), , contactDS.Tables( Contacts ).Rows(intCurRecord)( Address2 )) txtCity.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( City )), _ , contactDS.Tables( Contacts ).Rows(intCurRecord)( City )) txtRegion.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( Region )), _ , contactDS.Tables( Contacts ).Rows(intCurRecord)( Region )) txtPostalCode.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( PostalCode )), , contactDS.Tables( Contacts ).Rows(intCurRecord)( PostalCode )) txtWorkPhone.Text = _ IIf(IsDBNull(contactDS.Tables( Contacts ).Rows(intCurRecord)( WorkPhone )),
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
7.Click the Add Reference button to add a reference to your project. 8.Add the following importsstatements to the top of the frmContactscode segment (before so that you can refer to the various objects in the ect in shorthand mode. Imports SystemImports System.DataImports System.Data.OleDbImports CustomerRelationsManagement.MapPoint9.Add the following declarations beneath the PublicClass and Inheritsstatements. Public Class frmContactsInherits System.Windows.Forms.Form declare a database connection variableDim Conn As OleDbConnection declare a data adapter variableDim contactDA As OleDbDataAdapter declare a command builder variableDim cmdbuilder As OleDbCommandBuilder Declare a new dataset to hold the data locallyDim contactDS As DataSet = New DataSet declare a counter for storing the current recordDim intCurRecord As Integer declare a variable for tracking whether in add modeDim blnAddMode As Boolean10.Add the following frmContacts_Loadevent procedure to the form, changing the path follow- ing to point to the location of the CRM Access database you created in the prior section. Thisevent runs automatically when the form opens and loads the first contact record. It also createsa new OleDbCommandBuilderobject called cmdBuilderso that SQLstatements for updatingthe database are created automatically. Private Sub frmContacts_Load(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MyBase.LoadOn Error GoTo handleerror Create a connection to the Access database. Specify the complete path to the Access CRM database. conn = New _ OleDbConnection( Provider=Microsoft.Jet.OLEDB.4.0; & _ Data Source=C:Chapter 11CustomerRelationsManagementCRM.mdb; ) Specify the SQL statement to retrieve the contacts recordscontactDA = New _ OleDbDataAdapter( SELECT * FROM Contacts ORDER BY LastName, FirstName ,
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
2.Change the Web Reference Name to Googleso that you can use a shorter name in your project. An example of what the screen looks like at this point is shown in Figure 11-16. Figure 11-163.Click the Add Reference button to add a reference to the Google API to your project. 4.Next, let s add a reference to the Microsoft MapPoint API. (See Figure 11-17.) 5.Just as before, select Project.Add Web Reference. In the URL, specify the location of theMapPoint WSDLfile (http://staging.mappoint.net/standard-30/mappoint.wsdl)andclick the GO button. 6.Change the Web Reference Name to MapPointso that you can use a shorter name in your project. Figure 11-17238Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
Figure 11-1516.Rename the Nameproperty and the other specified Properties for each of the controls as in table: Default Name NameType of ControlOther Properties to Set from (in Figure 11-15)Properties DialogfrmMapfrmMapFormText = Results from Map- Point Label1lblTitleLabelText = Title TextBox1txtDirectionsText BoxText = [blank] Set multiline property to True. Set scrollbars to Vertical. PictureBox1picMapPicture BoxNow that you have created the user interface, let s move on to adding references to the external APIsand to coding the functionality to make the user interface work. Build the ModulesIn this section, you add the references to the Google API and the Microsoft MapPoint API and write to make the CRM application work. Let s jump right in. 1.Select Project.Add Web Reference. In the URL, specify the location of the Google WSDLfile(http://api.google.com/GoogleSearch.wsdl) and click the GO button.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
Figure 11-13Figure 11-1415.Add a label control, a text box control, and a picture box control to the new form as shown inFigure 11-15. It is difficult to see the picture box control on the figure because it has a transpar- ent background. 236Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services