Understanding Code

Navigation:  Interfacing QDV > Contextual Databases >

Understanding Code

Previous pageReturn to chapter overviewNext page

The function intended to interface contextual database is named Custom_Articles and its source code is available in the \SDK directory.

You can open it using Microsoft Visual Studio 2010 or later: http://www.microsoft.com/visualstudio/eng/downloads

 

First of all, copy the complete directory to another location because \SDK folder can be updated any time QDV7 is upgraded.

Open Custom_Articles.sln which is the complete solution.

The program must at least contain three functions (mandatory) called by QDV7:

 

Public Shared Function CustomizeArticles(ByVal FullPathToDb As String, ByRef Fields As Dictionary(Of String, Object), ByVal CallingEstimateContext As Dictionary(Of String, Object)) As Integer

 

Public Shared Function GetVersions() As Integer

which returns the current version

and

 

Public Shared Sub CloseConnection()

 

FullPathToDb is the complete path, including the file name of the calling database. If the calling database is an SQL-Server one, this variable contains the server and database names. You can use this variable to identify the calling database, and behave accordingly.

The function returns an integer:

Returned value

Description

QDV7 message

Comment

0

OK

 

 

1

Error message, but the process can continue

ContinueWithOthers

if there are several articles to insert

2

Post error message, prompt user NOT to connect during the session

CannotConnect

QDV states that the contextual database cannot be reached and proposes to avoid connecting to it during the overall session. This is useful when you want users to work in disconnected mode. When they answer Yes, they can continue using their database with generic data

3

Post error message, don't prompt user not to connect during the session

ReturnGenericData

same message but you cannot cancel the connection to the contextual database

 

The function CustomizeArticles passes two dictionaries:

Fields contains the collection of fields in the calling row. Any field can be written

CallingEstimateContext contains the collection of global variables of the calling estimate. It can only be read

 

Fields passes only data requested by the estimate. For better performance when updating a row in the estimate, it doesn't contain all possible data in the selected article row of the articles viewer.

However you may need more fields; e.g., say you need the Family field to decide which rebate to return. In this context, when updating a row, the Family field may not be passed because the user doesn't want to update it.

State explicitly in the function that you need this field. In the returned dictionary, provide the mnemonic of the field to add, and a number:

0 = the field is not updated and kept as it was in the estimate

1 = the field is updated, even if the user didn't want to do this; this can be necessary to ensure consistency

When you don't want to add fields, just return Nothing.

Example: to make sure Family and Reference are available for your process even if the user don't want to update them

 

Public Shared Function GetMoreFieldsIntoFieldsDictionary()As Dictionary(Of String,Integer)

Dim AddedFields As New Dictionary(Of String, Integer)

       AddedFields.Add("Family", 1)

       AddedFields.Add("Reference", 0)

       Return AddedFields

   End Function

The family field is forcibly updated even if the user has not selected it for updates.

 

NOTE

The function ConnectToDb is called by the function Custom_Articles. It opens the database connection and keeps it open for a while using a timer; this timer is reset whenever the function Custom_Articles is invoked.

This function is needed when performance is a concern because when you attempt open and close the connection to you contextual database each time an article is queried, the operation can take long time.

If you implement a similar logic to reduce connection time, it is important that you close the connection when quitting QDV7 if timer time is not elapsed. To do this, provide a public shared function named CloseConnection. This function is mandatory meaning that even if you don't use it, you have to expose it to QDV7.

 

Public Shared Sub CloseConnection()

 

When you compile the program, you must keep in mind that it has to target any CPU and the .NET Framework 4.0. The assembly must be signed.