You are on page 1of 82

Mantis SA

Designing Custom
Forms for Logistics
Vision 3+

Version 3.0.0
PREREQUISITES..........................................................................................................................................3
SOFTWARE...................................................................................................................................................3
CHAPTER 1: MANAGING A SINGLE DATA SOURCE........................................................................4
CREATING A SEARCH FORM..........................................................................................................................4
Create a DLL............................................................................................................................................4
Define Project Properties.........................................................................................................................6
Overriding Base Class Functionality and Displaying the Form through LV3.......................................10
ADDING LV3 CONTROLS............................................................................................................................12
ADDING SEARCH CRITERIA.........................................................................................................................14
ADDING GROUPED CRITERIA......................................................................................................................16
ADDING LINKED LABELS AND COMBOS.....................................................................................................17
DISPLAYING DATA IN A SEARCH FORM......................................................................................................19
CLEARING DATA.........................................................................................................................................20
DELETING RECORDS....................................................................................................................................20
DISPLAYING A MANAGE FORM...................................................................................................................23
EDITING RECORDS......................................................................................................................................28
CHAPTER 2: DISPLAYING A MANAGE GRID FORM......................................................................30
CHAPTER 3: MANAGING MULTIPLE DATA SOURCES..................................................................40
CREATE A SEARCH FORM............................................................................................................................40
CREATE A MANAGE FORM..........................................................................................................................43
Manipulating a ListView in a manage form...........................................................................................52
Additional Toolbars................................................................................................................................55
CHAPTER 4: ADDING SECURITY.........................................................................................................57
APPENDIX: CLASS REFERENCE...........................................................................................................58
LV3+ Forms...............................................................................................................................................58
Designing Custom
Forms for Logistics
Vision 3+
Prerequisites

 Good knowledge of the .NET Framework v.4.0.

 Good knowledge of any programming language that supports the .NET


framework.

 Have a basic understanding of basic Structured Query Language


(SQL) syntax in MSSQL and Oracle Databases.

 Have a good understanding of ADO .NET.

 Good knowledge of Logistics Vision III Database Schema.

Software

 Microsoft Visual Studio .NET 2010.

Note: later versions of Microsoft Visual Studio .NET and the .NET framework are not
supported.
Chapter 1: Managing a single data source
Creating a Search Form
Create a DLL
1. Start Visual Studio and create a new Class Library Project named “Custom
Forms”. We Assume that the LV3+ (Logistics Vision 3+) executable files are
located in the folder “C:\Program Files\LVision3+”.

2. Add references to the following assemblies:

A. Mantis.Lvision.Interfaces

B. Mantis.Lvision.Win32

C. Mantis.Lvision.LVForms

D. Mantis.Lvision.Combo

E. Mantis.Lvision.Common

F. Mantis.LVision.WinControls
Chapter 1

Important: Ensure that each reference added has the Copy Local Field set to
false.
Chapter 1

Define Project Properties


1. Open the CustomForms project Property pages, Click the Application tab
and modify the Assembly name and Root namespace fields according to
your needs.

2. Click the references tab, then click the Reference Paths… button and
ensure that it contains the Lvision executables path, in our example “C:\
Program Files\LVision3+\”,
Chapter 1

3. Click the Debug tab under the configuration properties folder and click the
Start External Program radio button, adding “C:\Program Files\LVision3+\
LVMain.exe” as the external debugging program.
Under Start Options, set the Working directory to “C:\Program Files\
LVision3+”

4. Click the Compile tab and set the output path relative to “C:\Program Files\
Logistic Vision III\” by typing “..\”. Also make sure that in “Advance Compile
Options…” the selected target framework is .NET Framework 4 (not 3.5, 3.0
or 2.0 and not any of the Client Profile frameworks).
Chapter 1
Chapter 1

5. Click OK and press ctrl + shift + s to save all files.

6. Delete the Class1.vb file that was created with the project.

7. Add a windows form to the project, name it frmSearch and click Add.

8. On solution explorer panel, press the Show All Files button

After showing all files, click the plus sign next to frmSearch form and open
the studio generated file frmSearch.Designer.vb (View Code right click
selection).

9. Change the inheritance of this form from


System.Windows.Forms.Form to
Mantis.LVision.LVForms.LVSearchForm.
Chapter 1

10. Double click the frmsearch form in the Solution Explorer to ensure that the
form designer reflects the changes. You should see a form with a StatusBar
control at its bottom.

A few deserialization errors will popup due to the inability of Visual Studio to
understand search inside Mantis.LVision.WinControls.dll assembly and find
correct references for Telerik controls that our forms in the new version
depend upon. This is expected and should not create any other problems.
Those warnings will show the first time each form is shown, after opening
Visual Studio 2010.
Visualy the form appears broken but it will show correctly once opened by
our program.
Chapter 1

Overriding Base Class Functionality and Displaying the Form through LV3+

1. Override the base class LV_OnInit function by writing inside the


frmSearch.vb form the following code snippet.

2. Build the project.

3. Start LV3+, go to Administrator menu and add a new item to the


module designer, according to the example below. A new menu item
should appear and by clicking it you should be able to view an empty
search form. You may want to add a message record to the
LV_Messages table if there is no existing message for the string you
want displayed.

Note: When adding your own message records, you should use
message codes with a characteristic prefix of your own (eg ANT_) in
order to avoid confusion with message codes inserted by Mantis.

You can also insert a form into the menu using the Design Module
Menu form; provided that you have already added the form to the
LV_Actions table (see Chapter 4).
Chapter 1

The form now is accessible from LVision 3+ by selecting the


appropriate menu item. By default the form will show as a docked
document in TDI or Ribbon mode of LVision 3+.

You can change this behaviour using a form attribute. To do so, go to


frmSearch.vb code window and insert the following code just before
the “Public Class frmSearch” definition.

<Mantis.LVision.Win32.FormType(…)>
FormType attribute has three parameters:

 FormDockState
This parameter controls the initial dock state of the form,
possible values are

 Docked
Docked as tool window on LVision 3+ application
edges

 Floating
Form will appear as floating on top of main LVision
3+ application

 TabbedDocument (default)

 FormImageFileName
An image file to be used as icon for this form (full path).
Chapter 1

 FormPosition
Used with FormDockState Docked or TabbedDocument to
specify the docking position (Bottom, Top, Left, Right or Fill).
Fill option is used only when FormDockState is
TabbedDocument.

example:
if you specify FormDockState as TabbedDocument and
FormPosition as Bottom, when this form opens and other
forms also are active, this form will appear as a tabbed
document at bottom of the already opened forms.

Adding LV3 Controls


1. Add a new tab in the IDE’s toolbox.

2. Select browse in .NET Framework Components tab and select


Mantis.Lvision.Win32.dll and click OK.

(We assume that we are given the task of displaying and manipulating data from
shipments)

3. Add an LVToolbarControl on the form and name it tbrMain. Import the


Mantis.Lvision namespace (Imports Mantis.LVision),
Mantis.Lvision.Win32 and System.Windows.Forms namespace.

4. Override the LV_OnInitToolbar Function and write the following code:


Chapter 1

Public Overrides Function LV_OnInitToolbar() As Boolean


Dim TB As Win32.LVToolbar

Try
TB = New Win32.LVToolbar()
TB.InitToolbar(tbrMain, _
Win32.enmLVImage.lvSearch, _
Win32.enmLVImage.lvReset, _
Win32.enmLVImage.lvSeparator, _
Win32.enmLVImage.lvNew, _
Win32.enmLVImage.lvEdit, _
Win32.enmLVImage.lvDelete, _
Win32.enmLVImage.lvSeparator, _
Win32.enmLVImage.lvHelp, _
Win32.enmLVImage.lvExit)
Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInitToolBar", Me)
Return False
Finally
TB = Nothing
End Try
End Function

5. Add a LVListView control on the form and name it lvwMain. Change the View
property to Details.

6. Write code in the lv_OnInit Function to initialize the form with multilingual
messages, listview display fields and captions.
Public Overrides Function LV_OnInit() As Boolean
Dim cols() As Mantis.LVision.Win32.lvColumnsInfo
Dim ha As HorizontalAlignment = HorizontalAlignment.Left

Try
' Initialize Listview Columns
cols = New Mantis.LVision.Win32.lvColumnsInfo() {
New lvColumnsInfo(1, "Code", "shp_Code", 100, ha),
New lvColumnsInfo(2, "ShipDate", "shp_ShipDate", 100, ha),
New lvColumnsInfo(3, "Status", "MessageName", 150, ha),
New lvColumnsInfo(4, "Location", "loc_Code", 140, ha),
New lvColumnsInfo(5, "Truck", "TruckCodePlate", 120, ha),
New lvColumnsInfo(6, "Driver", "DriverCodeName", 90, ha),
New lvColumnsInfo(7, "Agency", "AgencyCodeName", 140, ha),
New lvColumnsInfo(8, "RouteCode", "rte_Code", 140, ha),
New lvColumnsInfo(9, "DispatchMethod",
"DispatchMethodCodeName", 140, ha),
New lvColumnsInfo(10, "LogisticSite", "LogisticSite", 140, ha)
}

Me.InitializeForm(
lvwMain,
cols,
"shp_ID",
"ManageShipment",
New LVMessage() {
New LVMessage("Shipments"),
New LVMessage("Search")
}
)

Me.Text = Me.GetFormMessage("Shipments") & " - " &


Me.GetFormMessage("Search")

Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInit", Me)
Return False
Chapter 1

Finally
cols = Nothing
End Try
End Function

Adding Search Criteria


1. Set the Form’s Identity property to shp_ID from the form’s property pages. The
Identity Property is used to define the primary key of the View or table from
which data will be displayed to the user.
In previous version of Logistics Vision, the identiy property was accessible in
design time as form property. In this version this property is now available in
design time. To set its value, you will have to write it in code either in LV_OnInit
or after the InitializeComponent call in New function of this form.

2. Set the form’s MasterTable Property to V_SearchShipment. This informs the


base class that all the added control operations will use this table to manipulate
data.
In previous version of Logistics Vision, the MasterTable property was accessible
in design time as form property. In this version this property is now available in
design time. To set its value, you will have to write it in code either in LV_OnInit
or after the InitializeComponent call in New function of this form.

3. Add an LVPanelControl control, docked as top, to hold search controls, name it


pnlControls.

4. Add an LVLabel Control to pnlControls and name it lblShipCode. Set the


AutoSize property to false if you want to set its size manually.
As a general rule, you could use the message code or the name of the code as
the text property of the label control in order to know, in desing time, the purpose
of the label control.

5. Set the Label’s Messagecode property to “code” (without the Quotes).

IMPORTANT: The MessageCode property translates any control’s caption to the


language that the user selects when he logs in LV3.

6. Add an LVTextBox to pnlControls and name it txtShipCode.

7. Set the Textbox’s FieldName Property to shp_Code. The FieldName Property


will assign textbox values to the field shp_Code at run time to filter data.
Chapter 1

8. You don’t have to assign the txtShipCode’s TableName property to


V_SearchShipment. This is already done from the frmSearch’s MasterTable
Property. You will only have to assign a different TableName property if you want
to combine your search with fields from different tables that don’t belong to the
V_SearchShipment View.

9. Set the txtShipCode’s LVLabelControl property to lblShipCode. This action


binds the textbox’s behavior to the label. For example if the textbox’s Required
property is set to true then the label’s caption will appear in bold letters. This
functionality is mostly common in manage forms and it will be discussed later.

10. Add an LVLabel control and name it lblOrder.

11. Set the control’s Messagecode Property to OrderCode.

12. Add an LVTextbox control and name it txtOrder.

13. Set the following properties as follows:

a. FieldName = ord_Code

b. LVLabelControl = lblOrder

c. SelectField = ost_ShipmentID

d. TableName = V_SearchOrderShipment

In this case, the control’s TableName property points to another table


because we want to display shipments filtered by a specific Order Code.
However the V_SearchShipment view does not have any links to Order but it
links to V_SearchOrderShipment view using the shipment ID field.
(ost_ShipmentID = shp_ID). Using the functionality of the SelectField and
TableName property we are able to achieve joins between tables without the
need to write extra SQL statements.

Adding Grouped Criteria

It is very common to query databases using values between specific ranges. You can
achieve this functionality in LV3+ by using the LVGroupBox control.

1. Add an LVGrouBox control in the form and set it’s properties as follows:

a. Name = grpShipDate

b. Condition = Between

c. FieldName = shp_ShipDate

d. MessageCode = ShipDate

e. Operant = And

2. Add an LVLabel Control, name it lblFrom and set its MessageCode property to
“From”.
Chapter 1

3. Add An LVDateTimePicker Control, name it dtpInputDateFrom and set its


properties as follows:

a. Condition = >=

b. FieldName = shp_ShipDate

c. LVLabelControl = lblFrom

d. CustomFormatEX = DATE_FORMAT

4. Add an LVLabel Control, name it lblTo and set its MessageCode property to
“To”.

5. Add An LVDateTimePicker Control, name it dtpInputDateTo and set its


properties as follows:

a. Condition = <=

b. FieldName = shp_ShipDate

c. LVLabelControl = lblTo

d. CustomFormatEX = DATE_FORMAT

Adding Linked Labels and Combos

1. Add an LVLinkLabel Control to the form and set its properties as follows:

a. Name = lnkAgency

b. Info_AssemblyName = Mantis.LVision.Depositors

c. Info_FormName = frmManageAgency

d. Info_FormNameSearch = frmSearchAgency

e. MessageCode = Agency

2. Add an LVComboBox control to the form and set its properties as follows:

a. Name = cboAgency

b. FieldName = shp_AgencyID

c. Fill_AssemblyName = Mantis.LVision.Combo

d. Fill_DataChanged = Agencies

e. Fill_Form = frmSearchShipment

f. Fill_Method = Agency

g. Fill_TypeName = FillCombo
Chapter 1

h. LV_LinkLabelControl = lnkAgency

3. Set the lnkAgency Info_DataCombo property to cboAgency.

This Functionality allows us to display the search or the manage form of any
assembly (in our case the Agency). When you click on the link control it checks if the
related combo has a SelectedValue Property <> 0. If it does, the manage Agency
form will be displayed to the user. If it is zero then the search form will be displayed.

Every LV3+ form can have a Data Changed event. In our case the combo “listens” to
the “Agencies” event fired by the Search Agency or the manage Agency Form and it
reflects additions, deletions and edits to Agency data. If for example you choose an
agency from the combo and click the link label, any changes to the record through its
update form will change the combo values automatically.

The event’s name can be set in the InitializeForm or


InitializeManageForm (for manage forms) methods and it is the
DataChangedString parameter.

The Class Mantis.LVision.Combo contains many ready to use functions. Just Set the
Fill_Method property to the name of the appropriate method and the
Fill_Assemblyname property to the desired Namespace.

However the only methods that the Fill_Method property accepts must have only 2
specific parameters. An ILVisionForm Interface and an LVComboBox control.

Public Function MyFunc(ByVal pFrm As Interfaces.ILVisionForm, _


ByVal cboCombo As Win32.LVCombobox) As DataSet

If you need to fill a combo with data that are not contained in the
Mantis.LVision.Combo Class or with custom datasets then you must obtain a
reference to the Win32.ControlRoutines class and call the FillCombo Method.
Example:
Dim cr As Win32.ControlRoutines = New Win32.ControlRoutines()

cr.FillCombo( _
LVComboObject, _
dsDataset, _
"Code", _
"ID", _
"Data", _
, _
, _
"Code" _
)

cr.Dispose()
cr = Nothing
Chapter 1

Displaying Data in a Search Form


When the user clicks the search button, the Search form calls the overridable
LV_OnOpenRecord method.

If we override this method we can return a dataset to the base form which will fill the
Listview (in our case the lvwMain listview) with the search Data.

When we initialized the Search form we provided a listview object and an


lvColumnsInfo array as parameters to the InitializeForm method. The base
class will handle the returned dataset from the LV_OnOpenRecord method and will
display shipment data to the user using as primary key the field which is passed with
the tag parameter. In our case the shp_ID primary key will not be visible to the user.

1. Add reference to Mantis.LVision.DBAccess.DbRoutines.Dll assembly.

2. Override the LV_OnOpenRecord method and write the following code:

Public Overrides Function LV_OnOpenRecord() As System.Data.DataSet


Dim dbr As Mantis.LVision.DBAccess.DbRoutines.Routines
Dim cr As Mantis.LVision.Win32.ControlRoutines
Dim strSQL As String
Dim strWhere As String
Dim dsCriteria As DataSet
Dim dsShipment As DataSet
Dim dsOrderShipment As DataSet
Dim dsReturn As DataSet

Try
dbr = New Mantis.LVision.DBAccess.DbRoutines.Routines()

' Open Schemas


dsShipment = dbr.OpenSchema("V_SearchShipment", Me)
dsOrderShipment = dbr.OpenSchema("V_SearchOrderShipment", Me)
dsCriteria = dbr.OpenSchema("V_SQLCriteria", Me)

' Merge Datasets


dsShipment.Merge(dsOrderShipment)

' Assign Criteria


cr = New Mantis.LVision.Win32.ControlRoutines()
cr.AssignCriteriaFromFormData(Me, dsShipment, dsCriteria)

' Prepare SQL Statement


strSQL = "Select * from V_SearchShipment"
strWhere = dbr.GetSearchSQL(dsCriteria, Me.Identity, Me)

If strWhere <> String.Empty Then


strSQL &= " WHERE " & strWhere & " AND "
Else
strSQL &= " WHERE "
End If

' Ensure that we show records in the User's Language


strSQL &=
" (LanguageID = " & Me.LanguageID &
" OR LanguageID IS NULL ) " & " AND " &
" (LanguageID1 = " & Me.LanguageID &
" OR LanguageID1 IS NULL ) "

dsReturn = dbr.SelectTable("V_searchShipment", strSQL, Me)


Return dsReturn
Catch ex As Exception
Common.CException.Message(ex, "LV_OnOpenRecord", Me)
Return Nothing
End Try
End Function
Chapter 1

a. The OpenSchema function reads XML Schema Definition Files stored in


the Datasets Path of LV3+ and obtains an empty dataset that has the
structure of the view or table stored in the database. In our Example we
used 2 views. V_SearchShipment and V_SearchOrderShipment so it
is necessary to include these schemas in the dataset that we will pass as
parameter in the AssignCriteriaFromFormData function.

b. The Control Routines Assembly AssignCriteriaFromFormData


function gets these datasets and returns a user criteria dataset which
contains a formatted version of user’s criteria.

c. The DBRoutines GetSearchSQL function Reads the dsCriteria and


returns a portion of an SQL statement which automatically translates
user input into an SQL query.

d. The overloaded SelectTable function accepts the final sql String and it
queries the database for records that much the SQL string. You don’t
have to pass the connection or transaction parameters since we need to
connect only one time with the database. Providing the table name as
parameter ensures that the query will not return double primary key
(shp_ID) values ensuring data integrity but it is not mandatory.

Clearing Data
By overriding the LV_OnResetRecord function we are able to customize how the
controls’ data are cleared.

1. Override the LV_OnResetRecord function and write the following code:

Public Overrides Function LV_OnResetRecord() As Boolean


Me.lvwMain.Items.Clear()
Return MyBase.LV_OnResetRecord
End Function

Now after the user presses the reset button, The Listview control will be also cleared
from records. If we don’t call the base method LV_OnResetRecord the reset button
will not empty criteria controls.

Deleting Records
1. Override the LV_OnUpdateRecord function.

2. Import Mantis.LVision.DBAccess namespace.

3. Open a database connection using the open Method of the DBConnection


class.

4. Begin a transaction using the BeginTransaction method.

5. In our case before deleting the shipment we must remove its references from the
LV_OrderShipment and LV_ShipContainer tables. We achieve that using the
Chapter 1

Execute method. The Execute Method is used for Insert, Update and Delete
SQL Statements.

6. The ChangeTable method checks the row states of a dataset’s datarows and
updates the database accordingly without the need to write SQL Statements.

7. Note that all of the above methods accept the same connection and transaction
parameters.
Public Overrides Function LV_OnUpdateRecord(ByRef ds As System.Data.DataSet)
As Long
Dim dsDeleted As DataSet = ds.Clone
Dim con As System.Data.IDbConnection = Nothing
Dim trans As System.Data.IDbTransaction = Nothing
Dim dbr As New Mantis.LVision.DBAccess.DbRoutines.Routines()
Dim iaffected As Integer
Dim r As DataRow
Dim strUpdate As String

' Get deleted only


dsDeleted.Merge(ds.GetChanges(DataRowState.Deleted))
If dsDeleted.Tables(0).Rows.Count = 0 Then Return 0

Try
' Open a connection
con = DbRoutines.DBConnection.Open(Me)
Catch ex As Exception
Common.CException.Message(ex, "LV_OnUpdateRecord")
Return 0
End Try

Try
' Begin transaction
trans = DbRoutines.DBConnection.BeginTransaction(con)

For Each r In dsDeleted.Tables(0).Rows


strUpdate =
"UPDATE LV_OrderShipment " &
"SET ost_ShipmentID = NULL " &
"WHERE ost_ShipmentID = " &
r.Item("shp_ID", DataRowVersion.Original)

iaffected += dbr.Execute(strUpdate, con, trans, Me)


Next

iaffected += dbr.ChangeTable(
dsDeleted,
Me,
"shp_ID",
"LV_Shipment",
"shp_DomainID",
Nothing,
con,
trans,
False,
DataRowState.Deleted)

For Each r In dsDeleted.Tables(0).Rows


strUpdate =
"DELETE from lv_ShipContainer WHERE shc_ID IN" &
"(" &
"SELECT shc_ID from LV_ShipContainer WHERE shc_ID NOT
IN (" &
"SELECT shs_ContainerID from LV_ShipStock " &
"WHERE shs_ContainerID is NOT NULL)" &
" AND shc_ShipmentID = " & r.Item("shp_ID",
DataRowVersion.Original) &
")"
Chapter 1

iaffected += dbr.Execute(strUpdate, con, trans, Me)


Next

trans.Commit()

Return iaffected
Catch ex As Exception
Try
trans.Rollback()
Catch exTemp As Exception
End Try
Common.CException.Message(ex, "LV_OnUpdateRecord")
Return 0
Finally
If Not con Is Nothing Then
con.Close()
con.Dispose()
con = Nothing
End If
If Not trans Is Nothing Then
trans.Dispose()
trans = Nothing
End If
If Not dbr Is Nothing Then
dbr.Dispose()
dbr = Nothing
End If
End Try
End Function

Displaying a Manage Form


1. Add a new form to the project and name it frmManage.

2. Inherit from Mantis.LVision.LVForms.LVManageForm.

3. Override the LV_OnInit method and return true.

4. Add an LVToolbarControl control on the form and name it tbrMain.

5. Override the LV_onInitToolBar method and write the following code:

Public Overrides Function LV_OnInitToolBar() As Boolean


Dim TB As LVToolbar

Try
TB = New LVToolbar()
TB.InitToolbar(
Me.tbrMain,
enmLVImage.lvSave,
enmLVImage.lvReset,
enmLVImage.lvSeparator,
enmLVImage.lvPrint,
enmLVImage.lvHelp,
enmLVImage.lvExit)

Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInitToolBar", Me)
Return False
Finally
TB = Nothing
End Try
End Function

6. View the frmSearch’s code, override the LV_OnDisplayRecord method and


write the following code:
Chapter 1

Public Overrides Function LV_OnDisplayRecord(ByVal RowId As Integer) As


Boolean
Dim CR As Win32.ControlRoutines

Try
CR = New Win32.ControlRoutines()
Return CR.ShowFormFromAssembly(
Me,
"Pilot.LVision.CustomForms",
"frmManage",
RowId,
Nothing,
False,
Me.ConstructParam)
Catch ex As Exception
Common.CException.Message(ex, "LV_OnDisplayRecord", Me)
Return False
Finally
CR = Nothing
End Try
End Function

The ShowFormFromAssembly method can display any LVSearchForm or


LVManageForm, by simply accepting the form’s namespace and assembly name as
parameters. It has options to allow modal, single instance forms and also a
ContructParam parameter which allows the programmer to pass any kind of data
from one form to another. One important parameter is the id parameter which if is
zero the form start in insert mode, if it is not equal to zero in update mode.

If you now build and run the project you should see an empty form upon clicking the
new button of the frmSearch form.

7. Write the following code in the LV_OnInit function of frmManage form:

Public Overrides Function LV_OnInit() As Boolean


Dim CR As Win32.ControlRoutines

Try
CR = New Win32.ControlRoutines()

Me.InitializeManageForm(
Me.tbrMain,
New Win32.LVMessage() {
New Win32.LVMessage("Shipments")
},
"ManageShipment",
True)

Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInit", Me)
Return False
Finally
CR = Nothing
End Try
End Function

8. Add The Following LVControls on the manage form:

a. Add an LVLabel control and set its properties as follows:

i. Name = lblCode
Chapter 1

ii. MessageCode = Code.

b. Add an LVTextBox control and set its properties as follows:

i. Name = txtCode

ii. FieldName = shp_Code

iii. LVLabelCotrol = lblCode

iv. TableName = LV_Shipment

v. Required = true

c. Add an LVLabel control and set its properties as follows:

i. Name = lblDispatchMethod

ii. MessageCode = DispatchMethod.

d. Add an LVCombobox control and set its properties as follows:

i. Name = cboDispatchMethod

ii. FieldName = shp_DispatchMethodID

iii. Fill_AssemblyName = Mantis.LVision.Combo

iv. Fill_Method = DispatchMethod

v. Fill_TypeName = FillCombo

vi. LVLabelControl = lblDispatchMethod

vii. Required = True

viii. TableName = LV_Shipment

e. Add an LVLabel control and set its properties as follows:

i. Name = lblStatus

ii. MessageCode = Status

f. Add an LVCombobox control and set its properties as follows:

i. Name = cboShipmentStatus

ii. FieldName = shp_StatusID

iii. Fill_AssemblyName = Mantis.LVision.Combo

iv. Fill_Method = ShipmentStatus

v. Fill_TypeName = FillCombo
Chapter 1

vi. LVLabelControl = lblStatus

vii. Required = True

viii. TableName = LV_Shipment

g. Add an LVLabel control and set its properties as follows:

i. Name = lblShipDate

ii. MessageCode = ShipDate

h. Add an LVDateTimePicker control and set its properties as follows:

i. Name = dtpShipDate

ii. FieldName = shp_ShipDate

iii. LVLabelControl = lblShipDate

iv. TableName = LV_Shipment

9. Override the LV_onInitToolbar Method and write the following code:

Public Overrides Function LV_OnInitToolBar() As Boolean


Dim TB As LVToolbar

Try
TB = New LVToolbar()
TB.InitToolbar(
Me.tbrMain,
enmLVImage.lvSave,
enmLVImage.lvReset,
enmLVImage.lvSeparator,
enmLVImage.lvPrint,
enmLVImage.lvHelp,
enmLVImage.lvExit)

Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInitToolBar", Me)
Return False
Finally
TB = Nothing
End Try
End Function

10. Override LV_OnEmptyRecord method and write the following code:

Public Overrides Function LV_OnEmptyRecord() As System.Data.DataSet


Dim dbr As New Mantis.LVision.DBAccess.DbRoutines.Routines()
Dim r As DataRow
Dim ds As DataSet

Try
ds = dbr.OpenSchema("LV_Shipment", Me)
r = ds.Tables(0).NewRow
r.Item("shp_ID") = Me.CurrentID
ds.Tables(0).Rows.Add(r)
Me.Text = Me.GetFormMessage("Shipments") & " - " &
Me.GetFormMessage("Manage")
Chapter 1

Return ds
Catch ex As Exception
Common.CException.Message(ex, "LV_OnEmptyRecord", Me)
Return Nothing
Finally
If Not dbr Is Nothing Then
dbr.Dispose()
dbr = Nothing
End If
End Try
End Function

This Function must return a dataset that has the same schema with the dataset that
will be updated (in our case the LV_Shipment table). We must add an empty row to
the datatable and fill fields that don’t accept NULL values. The LV_Shipment table
has one primary key (the shp_ID) so it is necessary to assign a value to it and then
add the row to the datatable.

11. Override the LV_OnUpdateRecord method and write the following


code:
Public Overloads Overrides Function LV_OnUpdateRecord(
ByRef ds As System.Data.DataSet,
ByRef id As Integer) As Long
Dim dbr As DBAccess.DbRoutines.Routines = Nothing
Dim iaffected As Integer

Try
dbr = New DBAccess.DbRoutines.Routines()

ds.Tables(0).Rows(0).Item("shp_logisticSiteID") =
Me.LogisticSiteID

iaffected = dbr.UpdateTable(ds, Me, "shp_ID", "LV_Shipment")

If iaffected > 0 Then


id = ds.Tables(0).Rows(0).Item("shp_ID")
End If

Return iaffected
Catch ex As Exception
Common.CException.Message(ex, "", Me)
Return 0
Finally
If Not dbr Is Nothing Then
dbr.Dispose()
dbr = Nothing
End If
End Try
End Function

We use the UpdateTable function to insert update and delete data from a dataset. A
dataset can contain rows with different row states. The updatetable function
automatically splits the data into 3 categories and executes Update, Insert and Delete
statements in the database.

It is very important to assign the primary key value returned from the database to the
id parameter of the LV_OnUpdateRecord method after a successful insert. If we
don’t assign the database value, the form will not change its mode from Insert to
Update.
Chapter 1

After the Insert we notice that the search Form queries the database. This happens
because we set the DataChanged parameter to the same value
(“ManageShipment”) in InitializeForm and InitializeManageForm
methods of the search and manage form.

12. View the search form’s code and override the OnDataChanged
method.

Public Overrides Sub OnDataChanged(ByVal data As String)

End Sub

Now the search form will stop listening to events. We can write conditions though to
achieve more functionality and handle events from different forms that the user
operates.

Note: Overriding this method accepts all fired events from all open forms and not just
the “ManageShipment” event from frmManage.

Editing Records

1. View the frmManage’s code, override the LV_OnOpenRecord method and write
the following code:

Public Overrides Function LV_OnOpenRecord() As System.Data.DataSet


Dim dbr As New DBAccess.DbRoutines.Routines()
Dim ds As DataSet
Dim strSQL As String

Try
strSQL =
"SELECT * from LV_Shipment" &
" WHERE shp_ID = " & Me.CurrentID &
" AND shp_logisticSiteID = " & Me.LogisticSiteID

ds = dbr.SelectTable("LV_Shipment", strSQL, Me)

Me.Text =
Me.GetFormMessage("Shipments") & " - " &
Me.GetFormMessage("Manage") & " : " &
ds.Tables(0).Rows(0).Item("shp_Code")

Return ds
Catch ex As Exception
Common.CException.Message(ex, "LV_OnOpenRecord", Me)
Return Nothing
Finally
If Not dbr Is Nothing Then
dbr.Dispose()
dbr = Nothing
End If
End Try
End Function

This method is executed when the manage form’s CurrentID property has a value <>
0. It is necessary to query the database for matching records and return the dataset
to the base class.
Chapter 1

The base class will handle all operations, from storing our original data for
comparisons, to assigning them to the form’s controls.

Any unsaved changes, initializations e.t.c will cause a comparison of the displayed
data to the data originally stored when the LV_OnOpenRecord method was first
called.
Chapter 2: Displaying a Manage Grid Form
It is often convenient to display series of related data for mass inserts, update and
delete operations. The LVManageGrid form offers this functionality without the need
to create 2 separate forms (search and manage).

We assume that we are given a task to display and manage data from:

1. Machine types and

2. Assign Machine types to Machine Models.

We must first create The Machine type form.

1. Add a new form to the project and name it frmMachineType.

2. Change the inheritance of the new form from System.Windows.Forms.Form to


Mantis.LVision.LVForm. LVManageGridForm.

3. Add an import for Mantis.LVision in form’s code.

4. Add an LVToolbarControl on the form and name it tbrMain.

5. Add an LVDatagrid Control on the form and name it grdMachineTypes.

6. Override the LV_onInit function and write the following code:


Public Overrides Function LV_OnInit() As Boolean
Dim TB As Win32.LVToolbar

Try
Me.CurrentID = 1

TB = New Win32.LVToolbar()
TB.InitToolbar(
Me.tbrMain,
Win32.enmLVImage.lvSave,
Win32.enmLVImage.lvReset,
Win32.enmLVImage.lvSeparator,
Win32.enmLVImage.lvPrint,
Win32.enmLVImage.lvHelp,
Win32.enmLVImage.lvExit)

Me.InitializeManageGridForm(
Me.tbrMain,
Me.grdMachineTypes,
New Win32.LVMessage() {
New Win32.LVMessage("MachineTypes")},
"MachineTypes",
True)

Me.Text = Me.GetFormMessage("MachineTypes") & " - " &


Me.GetFormMessage("Manage")

Me.grdMachineTypes.CaptionText = Me.GetFormMessage("MachineTypes")

Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInit", Me)
Return False
Finally
TB = Nothing
End Try
Chapter 2

End Function

Notice that there is not overridable function for the toolbar initialization and we set the
forms currentid property to 1.

7. Override the LV_OnOpenRecord method and write the following code:

Public Overrides Function LV_OnOpenRecord() As System.Data.DataSet


Dim dbr As DBAccess.DbRoutines.Routines = Nothing

Try
dbr = New DBAccess.DbRoutines.Routines()

Return dbr.SelectTable(
"V_MachineType",
"SELECT * FROM V_MachineType",
Me)
Catch ex As Exception
Throw
Finally
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
End Try
End Function

5. Override the LV_OnDefineGrid() function and write the following code:


Public Overrides Sub LV_OnDefineGrid()
Dim col As Win32.LVDataGridColumnInfo

Try
' id
col = Me.grdMachineTypes.ColumnInfos.Add("mnt_ID")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_Identity
col.IncrementSeed = -1
col.IncrementStep = -1
col.IsVisible = False

' code
col = Me.grdMachineTypes.ColumnInfos.Add("mnt_Code")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_TextBox
col.Width = 100
col.MessageCode = "Code"
col.Validation.Required = True
col.Validation.MissingMessageCode = "ValueRequired"
col.IsVisible = True

' description
col = Me.grdMachineTypes.ColumnInfos.Add("mnt_Description")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_TextBox
col.Width = 180
col.MessageCode = "Description"
col.Validation.Required = True
col.Validation.MissingMessageCode = "ValueRequired"
col.IsVisible = True

' DomainID
col = Me.grdMachineTypes.ColumnInfos.Add("mnt_DomainID")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_TextBox
col.DefaultValue = Me.DomainID
col.IsVisible = False

' key = desription


Me.grdMachineTypes.UniqueValues = New Object() {"mnt_Code"}
Me.grdMachineTypes.UniqueViolationField = "mnt_Code"
Chapter 2

Me.grdMachineTypes.UniqueViolationMessageCode =
"ValueAlreadyExists"

Catch ex As Exception
Throw 'break in lvmanagegridform
Finally
col = Nothing
End Try
End Sub

In every kind of LV3 form, the LVDataGrid must be defined before use. The main object
is an object of LVDataGridColumnInfo type which is used to assign all properties to
an LVDataGrid control.

We declare the fist column () as an Identity column of the datagrid which is our primary
key and it will get values from the database. We also set its style property using the
Mantis.LVision.Win32.LVDataGridColumnStyles enumeration which can be any of the
following values:

ColumnStyle_CheckBox
ColumnStyle_ComboBoxDropDown
ColumnStyle_ComboBoxList
ColumnStyle_DatePicker
ColumnStyle_Identity
ColumnStyle_LinkLabel
ColumnStyle_TextBox

When the column is an identity type:


1. The IncrementSeed property is the initial value of the first new record
2. The IncrementStep property adds a value to the initial seed for every
new record.

The following properties apply to all column types and they are self explanatory:
IsVisible
Width
MessageCode
Validation.Required
Validation.MissingMessageCode

The DefaultValue Property assigns the same value specified for every new
record and it can of any kind depending on the style property.

The LVDatagrid UniqueValues property accepts a string object or an array


of objects as a parameter and it does not allow duplicate values for the specified
field, or a unique combination of fields passed as an array of objects. For
example:

Me.grdMachineTypes.UniqueValues = New Object() {"mnt_Code", "mnt_Description"}


Chapter 2

In this case the grid will not set a column error unless both mnt_Code and
mnt_Description values are the same in different rows.

In the previous example we notice that the LVdatagrid does not display an error
because even the mnt_Code fields are the same, the description fields are
different.

The LVDatagrid UniqueViolationField property displays the error


provider component next to the specified field.

The LVDatagrid UniqueViolationMessageCode displays an error message


by accepting a messageCode string as parameter. You don’t have to specify
these message codes as parameters in the InitializeManageGridForm
method.

8. Override the LV_OnValidateRecord method and write the following code:

Public Overloads Overrides Function LV_OnValidateRecord(ByVal ds As


System.Data.DataSet) As Boolean

If CType(Me.grdMachineTypes.DataSource, DataSet).Tables(0).HasErrors
Then
Media.SystemSounds.Beep.Play()
Return False
End If

Return True
End Function

We always override this method when at least one of our data sources is a list of values
and we must manually check data integrity before passing them to LV_OnUpdate
Method.

If we don’t override this function the the LV_OnUpdate method will be called from the
base class without checking the LVdatagrid for errors.
Chapter 2

9. Override the LV_OnUpdateRecord Method and write the following Code:

Public Overloads Overrides Function LV_OnUpdateRecord( _


ByRef ds As System.Data.DataSet, _
ByRef id As Integer) As Long

Dim dbr As DBAccess.DbRoutines.Routines = Nothing


Dim strSQL As String

Try
id = 1
dbr = New DBAccess.DbRoutines.Routines()
strSQL = "SELECT mnt_ID FROM LV_MachineType WHERE " &
DBAccess.DbRoutines.DBFunctions.SQLUpper(Me, "mnt_Code") & " =
'{0}'"
dbr.IsCodeExists(
ds,
"mnt_Code",
"mnt_ID",
strSQL,
Me)

Return dbr.UpdateTable(
ds,
Me,
"mnt_ID",
"LV_MachineType",
"mnt_DomainID")
Catch ex As Exception
Common.CException.Message(ex, "LV_OnUpdateRecord", Me)
Return 0
Finally
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
End Try
End Function

The DBFunctions Class contains methods that are mainly responsible for
translating SQL statetements to various database formats according to the
DataBaseType forms property.

The databasetype property is a DbRoutines.DBDatabaseTypes enumerator and it


is mainly used from the DBroutines assembly for SQL translations.

In our case the SQLUpper function will convert the code to an upper case which is
important if you work in an Oracle Database server which is case sensitive.

The IsCodeExists method will check the database for duplicate values, even
ones that may not be displayed to the user using a "myCode = '{0}'" format and
will throw an exception if a duplicate value is found and cancel the update
operation.

Now we will create the Machine Models Datagrid form.

1. Add a new form to the project and name it frmMachineModel.

2. Add an LVToolbarControl on the form and name it tbrMain.

3. Add an LVDatagrid Control on the form and name it grdMachineModel.

4. Override the LV_OnInit function and write the following code:


Chapter 2

Public Overrides Function LV_OnInit() As Boolean


Dim TB As Win32.LVToolbar
Try
Me.CurrentID = 1
TB = New Win32.LVToolbar()
TB.InitToolbar(
Me.tbrMain,
Win32.enmLVImage.lvSave,
Win32.enmLVImage.lvReset,
Win32.enmLVImage.lvSeparator,
Win32.enmLVImage.lvPrint,
Win32.enmLVImage.lvHelp,
Win32.enmLVImage.lvExit)

Me.InitializeManageGridForm(
Me.tbrMain,
Me.grdMachineModel,
New Win32.LVMessage() {New Win32.LVMessage("MachineModels")},
"MachineModels",
True)

Me.Text = Me.GetFormMessage("MachineModels") & " - " &


Me.GetFormMessage("Manage")

Me.grdMachineModel.CaptionText =
Me.GetFormMessage("MachineModels")

Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInit", Me)
Return False
Finally
TB = Nothing
End Try
End Function

5. Override the LV_OnOpenRecord and write the following code:


Public Overrides Function LV_OnOpenRecord() As System.Data.DataSet
Dim dbr As DbRoutines.Routines = Nothing

Try
dbr = New DbRoutines.Routines()

Return dbr.SelectTable(
"V_MachineModel",
"SELECT * FROM V_MachineModel",
Me)
Catch ex As Exception
Throw
Finally
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
End Try
End Function

6. Override the LV_OnValidateRecord method and write the following Code:


Public Overloads Overrides Function LV_OnValidateRecord(
ByVal ds As System.Data.DataSet) As Boolean

If CType(Me.grdMachineModel.DataSource, DataSet).Tables(0).HasErrors
Then
Media.SystemSounds.Beep.Play()
Return False
Chapter 2

End If

Return True
End Function

7. Override the LV_OnUpdateRecord method and write the following code:

Public Overloads Overrides Function LV_OnUpdateRecord(


ByRef ds As System.Data.DataSet, ByRef id As Integer) As Long

Dim dbr As DbRoutines.Routines = Nothing


Dim strSQL As String
Try
id = 1

dbr = New DbRoutines.Routines()

strSQL =
"SELECT mnm_ID from LV_MachineModel WHERE " &
DbRoutines.DBFunctions.SQLUpper(Me, "mnm_Code") &
" = '{0}'"

dbr.IsCodeExists(
ds,
"mnm_Code",
"mnm_ID",
strSQL,
Me)

Return dbr.UpdateTable(
ds,
Me,
"mnm_ID",
"LV_MachineModel",
"mnm_DomainID")

Catch ex As Exception
Common.CException.Message(ex, "LV_OnUpdateRecord", Me)
Return 0
Finally
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
End Try
End Function

8. Override the LV_OnDefineGrid method and write the following code:

Public Overrides Sub LV_OnDefineGrid()


Dim col As Win32.LVDataGridColumnInfo
Dim dbr As DbRoutines.Routines = Nothing
Dim dsMachineType As DataSet

Try
'ID
col = Me.grdMachineModel.ColumnInfos.Add("mnm_ID")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_Identity
col.IncrementSeed = -1
col.Increment = -1
col.IncrementStep = -1
col.IsVisible = False

'code
col = Me.grdMachineModel.ColumnInfos.Add("mnm_Code")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_TextBox
col.Width = 100
col.MessageCode = "Code"
col.Validation.Required = True
col.Validation.MissingMessageCode = "ValueRequired"
Chapter 2

col.IsVisible = True

'description
col = Me.grdMachineModel.ColumnInfos.Add("mnm_Description")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_TextBox
col.Width = 180
col.MessageCode = "Description"
col.Validation.Required = True
col.Validation.MissingMessageCode = "ValueRequired"
col.IsVisible = True

'mnm_TypeID
col = Me.grdMachineModel.ColumnInfos.Add("mnm_TypeID")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_TextBox
col.IsVisible = False

dbr = New DbRoutines.Routines()


dsMachineType = dbr.SelectTable(
"V_MachineType",
"SELECT * FROM V_MachineType",
Me)

col = Me.grdMachineModel.ColumnInfos.Add("CodeDescription")
col.style =
Win32.LVDataGridColumnStyles.ColumnStyle_ComboBoxDropDown
col.Width = 160
col.MessageCode = "MachineType"
col.comboDataSource = dsMachineType
col.ValueMember = "mnt_ID"
col.DisplayMember = "mnt_Code"
col.DisplayMember2 = "mnt_Description"
col.ValueColumnName = "mnm_TypeID"
col.Validation.Required = True
col.Validation.MissingMessageCode = "ValueRequired"
col.IsVisible = True

'DomainID
col = Me.grdMachineModel.ColumnInfos.Add("mnm_DomainID")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_TextBox
col.DefaultValue = Me.DomainID
col.IsVisible = False

'key = desription
Me.grdMachineModel.UniqueValues = "mnm_Code"
Me.grdMachineModel.UniqueViolationField = "mnm_Code"
Me.grdMachineModel.UniqueViolationMessageCode =
"ValueAlreadyExists"

Catch ex As Exception
Throw
Finally
col = Nothing
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
End Try
End Sub

In this grid definition we declared a ComboBoxDropDown column style. This


combo must be filled with values from the V_MachineType View and when the user
selects a combo item, the V_MachineModel view must bind the user’s selection with
the mnm_TypeID field since the mnm_TypedID field stores the value of the machine
type.
Chapter 2

col = Me.grdMachineModel.ColumnInfos.Add("CodeDescription")

It is very important to understand that the View V_MachineModel must contain a field
which must match the combo’s display format. If you examine the V_MachineModel
view you will notice that there is a field named CodeDescription which is displayed in
a
“Code – Description” manner.

This is the exact format in which the combo must display these values to the user. It
is important to set these values to the combo as shown below:

col.comboDataSource = dsMachineType. The combo’s data source must be


a V_MachineType view.

col.ValueMember = "mnt_ID". We must declare the primary key of the


V_MachineType View. When the combo item changes, the field mnm_TypeID gets
the value of mnt_ID.

col.DisplayMember = "mnt_Code"
col.DisplayMember2 = "mnt_Description"
Our Combo will display the above fields in a "mnt_Code - mnt_Description" format.

col.ValueColumnName = "mnm_TypeID". The ValueColumnName property


matches the mnt_ID field of the V_MachineType to the mnm_TypeID field of the
V_MachineModel.

NOTE: We can pass multiple fields as array of objects to achieve more complex
functionality, since the values of a grid’s combo may need to be matched with more
than one values of the grid’s table.

Example:
col.ValueMember = New Object() {"ors_Code", "ors_ID"}
col.ValueColumnName = New Object() {"ors_Code", "osi_StatusID"}
Chapter 3: Managing multiple data sources
In all previous examples we managed one data source at a time. Now we shall see
how to create a form that manages data in a master – detail manner.

We assume that we are given a task to create a manage machine form. The manage
machine form will bind machines to machine users. One machine may have many
users that operate it.

Create a search form.

1. Add a new form to the project and name it frmSearchMachine.

2. Inherit from LVSearchForm.

3. Add an LVToolbarControl control and name it tbrMain.

4. Add an LVListview control and name it lvwMain and set the View property to
Details.

5. Import the following namespaces:

System.Windows.Forms
Mantis.LVision
Mantis.LVision.Win32
Mantis.LVision.DBAccess

6. Override the LV_Oninit Method and write the following code:


Public Overrides Function LV_OnInit() As Boolean
Dim col() As Win32.lvColumnsInfo
Dim ha As HorizontalAlignment = HorizontalAlignment.Left

Try
col = New Win32.lvColumnsInfo() {
New Win32.lvColumnsInfo(1, "Code", "mchCode", 100, ha),
New Win32.lvColumnsInfo(2, "LogisticUnit",
"LogisticUnitCodeDescription", 150, ha),
New Win32.lvColumnsInfo(3, "Description", "mchDescription",
150, ha),
New Win32.lvColumnsInfo(4, "MachineModel",
"ModelCodeDescription", 150, ha),
New Win32.lvColumnsInfo(5, "Location", "locCode", 150, ha),
New Win32.lvColumnsInfo(6, "Status", "StatusCodeDescription",
150, ha)
}

Me.InitializeForm(
Me.lvwMain,
col,
"mchID",
"Machines",
New Win32.LVMessage() {
New Win32.LVMessage("Machines")
}
)

Me.Text = Me.GetFormMessage("Machines") & " - " &


Me.GetFormMessage("Search")

Me.lvwMain.Caption = Me.GetFormMessage("Machines")
Chapter 3

Return True
Catch ex As Exception
Me.Cursor = Cursors.Default
Common.CException.Message(ex, "LVOnInit", Me)
Return False
Finally
Me.Cursor = Cursors.Default
col = Nothing
End Try
End Function

7. Override the LV_OnInitToolbar Method and write the following code:


Public Overrides Function LV_OnInitToolBar() As Boolean
Dim TB As Win32.LVToolbar

Try
TB = New Win32.LVToolbar()
TB.InitToolbar(Me.tbrMain,
Win32.enmLVImage.lvSearch,
Win32.enmLVImage.lvSeparator,
Win32.enmLVImage.lvNew,
Win32.enmLVImage.lvEdit,
Win32.enmLVImage.lvDelete,
Win32.enmLVImage.lvSeparator,
Win32.enmLVImage.lvPrint,
Win32.enmLVImage.lvHelp,
Win32.enmLVImage.lvExit)
Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInitToolBar", Me)
Return False
End Try
End Function

8. Override the LV_OnEndInit Method and write the following code:

Public Overrides Sub LV_OnEndInit()


Me.DoSearch()
End Sub

After a successful LV_onInit the base class calls the LV_OnEndInit method. In this
method we execute a search query on the form by using the DoSearch() method.
The doSearch method can also append search results into existing ones by using
the optional bappend Boolean as a parameter.

9. Override the LV_OnOpenRecord method and write the following code:


Public Overrides Function LV_OnOpenRecord() As System.Data.DataSet
Dim dbr As DbRoutines.Routines = Nothing
Dim strSQL As String

Try
dbr = New DbRoutines.Routines()

strSQL =
"SELECT * FROM V_Machine " &
"WHERE LanguageID = " & Me.LanguageID

Return dbr.SelectTable("V_Machine", strSQL, Me)


Catch ex As Exception
Common.CException.Message(ex, "LV_OnOpenRecord", Me)
Return Nothing
Chapter 3

Finally
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
End Try
End Function

10. Override the LV_OnUpdateMethod And write the following code:


Public Overrides Function LV_OnUpdateRecord(ByRef ds As
System.Data.DataSet) As Long
Dim dbr As DbRoutines.Routines = Nothing

Try
dbr = New DbRoutines.Routines()
Return dbr.ChangeTable(ds,
Me,
"mch_ID",
"LV_Machine",
"mch_DomainID",
action:=DataRowState.Deleted)
Catch ex As Exception
Common.CException.Message(ex, "LV_OnUpdateRecord", Me)
Return 0
Finally
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
End Try
End Function

11. Override the LV_OnDisplay Method and write the following code:
Public Overrides Function LV_OnDisplayRecord(ByVal RowId As Integer)
As Boolean
Dim CR As Win32.ControlRoutines

Try
CR = New Win32.ControlRoutines()
CR.ShowFormFromAssembly(
Me,
"Pilot.LVision.CustomForms",
"frmManageMachine",
RowId)
Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnDisplayRecord", Me)
Return False
Finally
CR = Nothing
End Try
End Function

Create a Manage form.

1. Add a form to the project and name it frmManageMachine.

2. Inherits from LVManageForm.

3. Add an LVToolbarControl and name it tbrMain.

4. Add The Following LVControls on the manage form:


Chapter 3

a. Add an LVPanelControl with top docking to hold the following controls,


name this panel as pnlControl.

b. Add an LVLabel control and set its properties as follows:

i. Name = lblCode

ii. MessageCode = Code.

c. Add an LVTextBox control and set its properties as follows:

i. Name = txtCode

ii. FieldName = mch_Code

iii. LVLabelCotrol = lblCode

iv. TableName = V_Machine

d. Add an LVLabel control and set its properties as follows:

i. Name = lblDescription

ii. MessageCode = Description

e. Add an LVTextBox control and set its properties as follows:

i. Name = txtDescription

ii. FieldName = mch_Description

iii. LVLabelCotrol = = lblDescription

iv. TableName = V_Machine

f. Add an LVLabel control and set its properties as follows:

i. Name = lblStatus

ii. MessageCode = Status

g. Add an LVCombobox control and set its properties as follows:

i. Name = cboStatus

ii. FieldName = mch_StatusID

iii. Fill_AssemblyName = Mantis.LVision.Combo

iv. Fill_Method = MachineStatus

v. Fill_TypeName = FillCombo

vi. LVLabelControl = lblStatus

vii. Required = True


Chapter 3

viii. TableName = V_Machine

h. Add an LVLinkLabel control and set its properties as follows:

i. Name = lnkMachineModel

ii. Info_AssemblyName = Pilot.Lvision.CustomForms

iii. Info_DataCombo = cboMachineModel

iv. Info_FormName = frmMachineModel

v. Info_FormNameSearch = frmMachineModel

vi. MessageCode = MachineModel

i. Add an LVCombobox control and set its properties as follows:

i. Name = cboMachineModel

ii. FieldName = mch_ModelID

iii. Fill_AssemblyName = Mantis.LVision.Combo

iv. Fill_DataChanged = MachineModels

v. Fill_Method = MachineModels

vi. Fill_TypeName = FillCombo

vii. LVLinkLabelControl = lnkMachineModel

viii. Required = True

ix. TableName = V_Machine

j. Add an LVLinkLabel control and set its properties as follows:

i. Name = lnkLocation

ii. Info_AssemblyName = Mantis.LVision.Storage

iii. Info_DataCombo = cboLocation

iv. Info_FormName = frmManageLocation

v. Info_FormNameSearch = frmSearchLocation

vi. MessageCode = Location

k. Add an LVCombobox control and set its properties as follows:

i. Name = cboLocation

ii. DropDownStyle = DropDown

iii. FieldName = mch_LocationID


Chapter 3

iv. FieldValue = loc_Code

v. LVLinkLabelControl = lnkLocation

vi. TableName = V_Machine

Note: The Loc_Code field exists in the V_MachineView. If you don’t provide
this value to the Fieldname property, the cblocation combo will appear empty
when you manage a machine record.

l. Add an LVDatagrid Control on the form and name it grdMachineUsers.


Set the dock property to fill.

5. Import the following namespaces inside frmManageMachine.vb class


Mantis.LVision.DBAccess
Mantis.LVision
Mantis.LVision.Win32
System.Windows.Forms

6. Add a private enumerator.

Private Enum enmData


Machine = 0
MachineUsers = 1
End Enum

7. Override the LV_OnInit method and write the following Code:

Public Overrides Function LV_OnInit() As Boolean


Dim dbr As DbRoutines.Routines

Try
Me.Cursor = Cursors.WaitCursor

Me.DefineGridUsers()

dbr = New DbRoutines.Routines()


Me.grdMachineUsers.InitializeGrid(
Me,
dbr.OpenSchema("V_MachineUser", Me))

Me.InitializeManageForm(
Me.tbrMain,
New Win32.LVMessage() {
New Win32.LVMessage("Users"),
New Win32.LVMessage("Machines")
},
"Machines"
)

Me.grdMachineUsers.CaptionText = Me.GetFormMessage("Users")

Return True
Catch ex As Exception
Me.Cursor = Cursors.Default
Common.CException.Message(ex, "LV_OnInit", Me)
Return False
Finally
dbr.Dispose()
dbr = Nothing
Me.Cursor = Cursors.Default
Chapter 3

End Try
End Function

8. Override the LV_OnInitToolbar Method and write the following code:


Public Overrides Function LV_OnInitToolBar() As Boolean
Dim tb As Win32.LVToolbar

Try
tb = New Win32.LVToolbar()
tb.InitToolbar(Me.tbrMain,
Win32.enmLVImage.lvSave,
Win32.enmLVImage.lvReset,
Win32.enmLVImage.lvSeparator,
Win32.enmLVImage.lvHelp,
Win32.enmLVImage.lvExit)
Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInitToolBar", Me)
Return False
End Try
End Function

9. Override The LV_OnEmptyRecords method and write the following code:

Public Overrides Function LV_OnEmptyRecords() As System.Data.DataSet()


Dim dbr As DbRoutines.Routines = Nothing
Dim ds(1) As DataSet
Dim r As DataRow

Try
dbr = New DbRoutines.Routines()
ds(enmData.Machine) = dbr.OpenSchema("V_Machine", Me)

r = ds(enmData.Machine).Tables(0).NewRow
r.Item("mch_ID") = 0
r.Item("mch_DomainID") = Me.DomainID
r.Item("mch_LogisticUnitID") = Me.LogisticUnitID
ds(enmData.Machine).Tables(0).Rows.Add(r)

ds(enmData.MachineUsers) = dbr.OpenSchema("V_MachineUser", Me)

Me.grdMachineUsers.InitializeGrid(Me, ds(enmData.MachineUsers))

Me.Text = Me.GetFormMessage("Machines") & " - " &


Me.GetFormMessage("Manage")

Return ds
Catch ex As Exception
Common.CException.Message(ex, "LV_OnEmptyRecords", Me)
Return Nothing
Finally
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
End Try
End Function

Note: We override the LV_OnEmptyRecords method which returns an array of


datasets and not the LV_OnEmptyRecord Method.

10. Override the LV_OnOpenRecords Method and write the following code:
Public Overrides Function LV_OnOpenRecords() As System.Data.DataSet()
Dim dbr As DbRoutines.Routines = Nothing
Dim ds(1) As DataSet
Dim strSQL As String
Chapter 3

Try
dbr = New DbRoutines.Routines()

strSQL =
"SELECT * FROM V_Machine " &
"WHERE LanguageID = " & Me.LanguageID &
" AND mch_ID = " & Me.CurrentID

ds(enmData.Machine) = dbr.SelectTable("V_Machine", strSQL, Me)

strSQL =
"SELECT * FROM V_MachineUser " &
"WHERE mnu_MachineID = " & Me.CurrentID

ds(enmData.MachineUsers) = dbr.SelectTable("V_MachineUser",
strSQL, Me)

Me.grdMachineUsers.InitializeGrid(Me, ds(enmData.MachineUsers))

Me.Text = Me.GetFormMessage("Machines") & " - " &


Me.GetFormMessage("Manage") &
" : " &
ds(enmData.Machine).Tables(0).Rows(0).Item("mch_Code")
Return ds
Catch ex As Exception
Common.CException.Message(ex, "", Me)
Return Nothing
Finally
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
End Try
End Function

11. Override the LV_OnValidateRecord Method and write the following code:
Public Overloads Overrides Function LV_OnValidateRecord(
ByVal ds() As System.Data.DataSet) As Boolean

If ds(enmData.Machine).HasErrors Or ds(enmData.MachineUsers).HasErrors
Then
Media.SystemSounds.Beep.Play()
Return False
End If
Return True
End Function

Note: We override the LV_OnValidateRecord which accepts an array of datasets as a


parameter.

12. Override the LV_OnGetDatasetFromControls method and write following


code:
Public Overloads Overrides Function LV_OnGetDatasetFromControls(
ByVal ds As System.Data.DataSet,
ByVal index As Integer) As System.Data.DataSet
Select Case index
Case enmData.Machine
Return Nothing
Case enmData.MachineUsers
If Not Me.grdMachineUsers.DataSource Is Nothing Then
Return CType(Me.grdMachineUsers.DataSource, DataSet).Copy
Else
Return Nothing
End If
Case Else
Chapter 3

Return Nothing
End Select
End Function

Note: this method will be called as many times as the count of the elements of the
dataset array.

13. Override the LV_OnUpdateRecord method and write the following Code:
Public Overloads Overrides Function LV_OnUpdateRecord(
ByRef ds() As System.Data.DataSet,
ByRef id As Integer) As Long
Dim Affected As Long

Try
Affected = Me.UpdateMachineDatasets(
ds(enmData.Machine),
ds(enmData.MachineUsers),
Me)

If Affected > 0 Then


id = ds(enmData.Machine).Tables(0).Rows(0).Item("mch_ID")

Me.grdMachineUsers.ColumnInfos.Item("mnu_MachineID").DefaultValue = id
End If

Return Affected
Catch ex As Exception
Common.CException.Message(ex, "LV_OnUpdateRecord", Me)
End Try
End Function

Note: We Override the LV_OnUpdateRecord which takes as a parameter an array


of datasets.

14. Write a DefineGridUsers Function.


Private Sub DefineGridUsers()
Dim col As Win32.LVDataGridColumnInfo

Try
'mnu_ID
col = Me.grdMachineUsers.ColumnInfos.Add("mnu_ID")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_Identity
col.IncrementSeed = -1
col.IncrementStep = -1
col.IsVisible = False

'mnu_MachineID
col = Me.grdMachineUsers.ColumnInfos.Add("mnu_MachineID")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_TextBox
col.DefaultValue = Me.CurrentID
col.IsVisible = False

'mnu_UserID
col = Me.grdMachineUsers.ColumnInfos.Add("mnu_UserID")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_TextBox
col.IsVisible = False

'Users
col = Me.grdMachineUsers.ColumnInfos.Add("Person")
col.style =
Win32.LVDataGridColumnStyles.ColumnStyle_ComboBoxDropDown
col.Width = 200
col.MessageCode = "User"
col.ValueColumnName = "mnu_UserID"
col.IsVisible = True
Chapter 3

'DomainID
col = Me.grdMachineUsers.ColumnInfos.Add("mnu_DomainID")
col.style = Win32.LVDataGridColumnStyles.ColumnStyle_TextBox
col.DefaultValue = Me.DomainID
col.IsVisible = False

'don't allow duplicate


Me.grdMachineUsers.UniqueValues = "Person"
Me.grdMachineUsers.UniqueViolationField = "Person"
Me.grdMachineUsers.UniqueViolationMessageCode =
"ValueAlreadyExists"

Catch ex As Exception
Throw
Finally
col = Nothing
End Try
End Sub

15. Handle the cboLocation keypress event.


Private Sub cboLocation_KeyPress(
ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles
cboLocation.KeyPress
Dim oCb As Combo.FillCombo

Try
If e.KeyChar <> vbCr Then Exit Sub

Me.Cursor = Cursors.WaitCursor

oCb = New Combo.FillCombo()


oCb.LocationCodes(Me, Me.cboLocation, Me.cboLocation.Text)
Me.cboLocation.OpenCombo()

Catch ex As Exception
Common.CException.Message(ex, "cboLocation_KeyPress", Me)
Finally
Me.Cursor = Cursors.Default
oCb = Nothing
End Try
End Sub

16. Handle the Grid’s DataGridComboFill Event.


Private Sub grdMachineUsers_DataGridComboFill(
ByVal sender As Mantis.LVision.Win32.DataGridComboBoxColumnStyle,
ByVal combo As Mantis.LVision.Win32.DataGridComboBox,
ByVal row As System.Data.DataRow,
ByVal columnName As String,
ByVal source As System.Windows.Forms.CurrencyManager) Handles
grdMachineUsers.DataGridComboFill

Dim dbr As DbRoutines.Routines = Nothing


Dim ds As DataSet
Dim cr As Win32.ControlRoutines
Dim strSQL As String

Try
If columnName = "Person" Then
dbr = New DbRoutines.Routines()
cr = New Win32.ControlRoutines()

strSQL =
Chapter 3

"SELECT * FROM V_UserByType WHERE " &


"skt_Code = '2' AND " &
"emp_LogisticUnitID = " & Me.LogisticUnitID

ds = dbr.SelectTable("V_UserByType", strSQL, Me)

cr.FillCombo(combo, ds, "per_Code", "emp_ID", "Name")


Else
'Check other combos
End If
Catch ex As Exception
Common.CException.Message(ex, "grdUsers_DataGridComboFill", Me)
Finally
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
cr = Nothing
End Try
End Sub

This event is fired when the user clicks any combo of a datagrid. It is a useful way to
fill and filter combo items depending on business logic conditions. In our case it
simply demonstrates how to fill a combo dynamically without the need to write code
in the datagrid definition.

17. Write the following Function:


Private Function UpdateMachineDatasets(
ByVal dsMachine As DataSet,
ByVal dsMachineUser As DataSet,
ByVal args As
Mantis.LVision.Interfaces.ILVisionForm) As Integer
Dim con As System.Data.IDbConnection = Nothing
Dim trans As System.Data.IDbTransaction = Nothing
Dim intAffected As Integer
Dim _dsMachine As DataSet = Nothing
Dim _dsMachineUser As DataSet = Nothing
Dim dbr As DbRoutines.Routines = Nothing
Dim strSQL As String

If Not dsMachine Is Nothing Then _dsMachine = dsMachine.Copy


If Not dsMachineUser Is Nothing Then _dsMachineUser =
dsMachineUser.Copy

Do
Try
con = DbRoutines.DBConnection.Open(args)
Catch ex As Exception
Throw ex
End Try

Try
trans = DbRoutines.DBConnection.BeginTransaction(con)
dbr = New DbRoutines.Routines()
strSQL =
"SELECT mch_ID FROM LV_Machine WHERE " &
DbRoutines.DBFunctions.SQLUpper(Me, "mch_Code") & " =
'{0}'"

dbr.IsCodeExists(
dsMachine,
"mch_Code",
"mch_ID",
strSQL,
args,
con,
Chapter 3

trans)

dbr.RelateDatasets(
args,
dsMachine,
dsMachineUser,
"mch_ID",
"mnu_MachineID",
Nothing,
con,
trans)

intAffected = dbr.UpdateTable(dsMachine,
args,
"mch_ID",
"LV_Machine",
"mch_DomainID",
Nothing,
con,
trans,
False)

intAffected += dbr.UpdateTable(dsMachineUser,
args,
"mnu_ID",
"LV_MachineUser",
"mnu_DomainID",
Nothing,
con,
trans)

trans.Commit()

Return intAffected
Catch ex As Mantis.LVision.DBAccess.DbRoutines.DbDeadLockException
Trace.WriteLine("UpdateMachineDatasets: " & vbCrLf &
ex.Message & vbCrLf & ex.StackTrace)
Try
trans.Rollback()
Catch exTemp As Exception
End Try

If Not _dsMachine Is Nothing Then dsMachine = _dsMachine.Copy


If Not _dsMachineUser Is Nothing Then dsMachineUser =
_dsMachineUser.Copy

Catch ex As Exception
Trace.WriteLine("UpdateMachineDatasets: " & vbCrLf &
ex.Message & vbCrLf & ex.StackTrace)

Try
trans.Rollback()
Catch exTemp As Exception
End Try

If Not _dsMachine Is Nothing Then dsMachine = _dsMachine.Copy


If Not _dsMachineUser Is Nothing Then dsMachineUser =
_dsMachineUser.Copy

Throw New Exception(ex.Message, ex)

Return 0
Finally
If Not trans Is Nothing Then trans.Dispose()
trans = Nothing
con.Close()
con.Dispose()
con = Nothing
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
End Try
Chapter 3

Loop
End Function

Notice that we created a loop to handle a DbRoutines.DbDeadLockException


error. If the transaction fails to acquire all necessary locks, an exception of this type is
created and then the function tries again until data are successfully committed in the
database.

The RelateDatasets function assigns master IDs to children IDs. In our example it
relates the mch_ID field with the mnu_MachineID field. It first queries the
LV_Sequences table to get an ID and then it assigns it to the mnu_MachineID field of
the “slave” table(s).

IMPORTANT: After the RelateDatasets method, we must set the


blnGetNextRow parameter to false of the LV_Machine’s UpdateTable method,
since it has already acquired IDs from the LV_Sequences table. Failure to that
will result in a referential integrity error.
intAffected = dbr.UpdateTable(
dsMachine,
args,
"mch_ID",
"LV_Machine",
"mch_DomainID",
nothing,
con,
trans,
False)

Manipulating a ListView in a manage form

Example:

Add an LVListview Control in the frmManage form.

Name the LVListview Control lvOrderShipment.

Write the following Function:

Private Function DefineListViewColumns() As Win32.lvColumnsInfo()


Return New Mantis.LVision.Win32.lvColumnsInfo() {
New Win32.lvColumnsInfo(1, "Code", "ost_Code", 110,
HorizontalAlignment.Left),
New Win32.lvColumnsInfo(2, "ExecuteDate", "ost_ExecuteDate",
110, HorizontalAlignment.Left),
New Win32.lvColumnsInfo(3, "ShipDate", "ost_ShipDate", 110,
HorizontalAlignment.Left),
New Win32.lvColumnsInfo(4, "DeliveryDate", "ost_DeliveryDate",
110, HorizontalAlignment.Left)
}
End Function
 
Chapter 3

The text Parameter of the constructor of the lvColumnsInfo class is actually a


messagecode that can be translated into the user’s login language.

To achieve this functionality we can define the Listview columns before the
InitializeManageForm method.

If we want to define the listview in another part of our code we can replace the text
parameter with the GetFormMessage method.

Example:

                … New Win32.lvColumnsInfo(1, Me.GetFormMessage("Code"), "ost_Code", 110,


HorizontalAlignment.Left) ...

Note: It is not mandatory to use messagecodes; we can simply use any text that we
want.

After defining a listview we can call the filllistview method from any part of our code.

If we want to call the method from the LV_OnOpenRecord(s) function (Which is the
correct approach)

We must define the listview before the filllistview function call.

This can be done before the InitializeManageForm method call or into the
LV_OnOpenRecord(s) method itself.

Example:
Public Overrides Function LV_OnInit() As Boolean
Dim CR As Win32.ControlRoutines
Dim dbr As New DbRoutines.Routines()

Try
CR = New Win32.ControlRoutines()

Me.lvOrderShipment.View = View.Details
CR.DefineListView(lvOrderShipment, DefineListViewColumns)

Me.InitializeManageForm(
Me.tbrMain,
New Win32.LVMessage() {
New Win32.LVMessage("Shipments"),
New Win32.LVMessage("ValueAlreadyExists"),
New Win32.LVMessage("ValueRequired"),
New Win32.LVMessage("OrderShipments"),
New Win32.LVMessage("Code")
},
"ManageShipment",
True)

Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInit", Me)
Return False
Finally
CR = Nothing
End Try
End Function
Chapter 3

In the previous example the defineListView method is called before the


InitializeManageForm method thus if we call

The FillListView Method in the LV_OnOpenRecords function, it will fill the listview
successfully.

Example:

Private m_dsOrderShipment As DataSet

Public Overrides Function LV_OnOpenRecords() As


System.Data.DataSet()
Dim dbr As New DbRoutines.Routines()
Dim ds(1) As DataSet
Dim strSQL As String
Dim CR As Win32.ControlRoutines = Nothing

Try
strSQL =
"SELECT * from LV_Shipment" &
" WHERE shp_ID = " & Me.CurrentID &
" AND shp_logisticSiteID = " & Me.LogisticSiteID

ds(0) = dbr.SelectTable("LV_Shipment", strSQL, Me)

Me.Text =
Me.GetFormMessage("Shipments") & " - " &
Me.GetFormMessage("Manage") & " : " &
CType(ds(0).Tables(0).Rows(0).Item("shp_Code"), String)

strSQL = "Select * FROM LV_OrderShipment " & "WHERE


ost_ShipmentID = " & Me.CurrentID

ds(1) = dbr.SelectTable("LV_OrderShipment", strSQL, Me)

m_dsOrderShipment = ds(1).Copy

CR = New Win32.ControlRoutines()
CR.FillListview(lvOrderShipment, ds(1), "ost_ID")

Return ds
Catch ex As Exception
Common.CException.Message(ex, "LV_OnOpenRecord", Me)
Return Nothing
Finally
If Not dbr Is Nothing Then
dbr.Dispose()
dbr = Nothing
End If
If Not CR Is Nothing Then
CR.Dispose()
CR = Nothing
End If
End Try
End Function
Chapter 3

Note: To access a listView’s Dataset, we can declare a private variable of Dataset


type and then copy the dataset from the LV_OnOpenRecords Method,

Before returning the array of datasets to the base class.

Then we must return the private dataset to the base class in the
LV_OnGetDatasetFromControls method.

Example:
Public Overloads Overrides Function LV_OnGetDatasetFromControls(
ByVal ds As System.Data.DataSet,
ByVal index As Integer) As
System.Data.DataSet
Select Case index
Case 0 ' Shipment
Return Nothing
Case 1 ' OrderShipment
If Not m_dsOrderShipment Is Nothing Then
Return m_dsOrderShipment.Copy
Else
Return Nothing
End If
Case Else
Return Nothing
End Select
End Function

Note: This functionality applies to both search and manage forms.

Additional Toolbars

It is valid to use the normal toolbar functionality and handle the events of any
additional toolbar.

However it may be easier to define an extra toolbar and handle the click event by
overriding the LV_OnMenuClick Method.

Example:

Add an LVToolbarControl and name it tbrOrderShipment.

Write the following code:

Public Overrides Function LV_OnInitToolBar() As Boolean


Dim TB As Win32.LVToolbar
Dim TBOS As Win32.LVToolbar

Try
TB = New Win32.LVToolbar()
TB.InitToolbar(Me.tbrMain,
Win32.enmLVImage.lvSave,
Win32.enmLVImage.lvReset,
Win32.enmLVImage.lvSeparator,
Win32.enmLVImage.lvPrint,
Win32.enmLVImage.lvHelp,
Chapter 3

Win32.enmLVImage.lvExit)

TBOS = New Win32.LVToolbar()


TBOS.InitToolbar(
Me.tbrOrderShipment,
Win32.enmLVImage.lvNew,
Win32.enmLVImage.lvEdit,
Win32.enmLVImage.lvDelete)
Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInitToolBar", Me)
Return False
Finally
TB = Nothing
TBOS = Nothing
End Try
End Function

Note: We can also call the method without the paramArray parameter if we want to
use custom buttons only.

Example:

            TBOS.InitToolbar(Me.tbrOrderShipment, Me)

Override the LV_OnMenuClick Method and write the following Code:


Public Overrides Function LV_OnMenuClick(
ByVal sender As Object,
ByVal tag As Object) As Boolean

Select Case CType(sender, Control).Name


Case "tbrmain"
Return False
Case "tbrOrderShipment"
Select Case tag
Case "New"
Case "Edit"
Case "Delete"
End Select
Return True
End Select
Return False
End Function

If the LV_OnMenuClick method returns false the base class will handle the button
click according to its functionality.

In our Case we want the extra toolbar (tbrOrderShipment) to behave differently so we


can just call any function we need

And finally return True, informing the base class not to call any additional functions.
Chapter 4: Adding Security
We need to assign our created forms to a specific user category. To do that we must
insert values into the LV_form and the lV_actions tables.

1. Set the SecurityCode property of the frmSearchMachine and


frmManageMachine to TestSecurity.

2. Execute the following SQL statements:

INSERT INTO lV_form (


frm_id,
frm_securitycode,
frm_Messagecode,
frm_groupMessageCode,
frm_DomainID)
VALUES (
10001,
'TestSecurity',
'Machines',
'Machines',
1)

INSERT INTO LV_Actions (


act_ID,
act_MessageCode,
act_AssemblyName,
act_ClassName,
act_Parameter,
act_FormID,
act_Modules,
act_DomainID,
act_AssemblyNameManage,
act_ClassNameManage)

Values (
10001,
'Machines',
'Pilot.Lvision.CustomForms',
'frmSearchMachine',
NULL,
10001,
NULL,
1,
'Pilot.Lvision.CustomForms',
'frmManageMachine')

Note: Values from 0 - 10000, for the fields frm_ID and act_ID, are reserved by Mantis SA.
Appendix: Class Reference
This section is a quick reference of LV3 classes and members used in the tutorials.
There are also examples which describe other functionalities that were not
discussed, but they are useful for various tasks.

LV3 Forms

CLASS: LVSearchForm

Constructor
Public Sub New()
Properties:
Public Property Identity As String
Member of Mantis.LVision.Win32.LVBasicForm

Summary: The primary key of the Table - View that will be used in search Queries.

Public Property MasterTable As String


Member of Mantis.LVision.Win32.LVBasicForm

Summary: The main Table - View that will be used in search Queries.

Public Property ConstructParam As Object


Member of Mantis.LVision.Win32.LVBasicForm

Summary: We can transfer data from one form to another by using this property.
Note: This parameter can be also set in The Module Designer in the Parameter field.

Public NotOverridable Property LanguageID As Integer


Member of Mantis.LVision.Win32.LVBasicForm

Summary: The ID of the language selected in the login form.


Appendix

Public NotOverridable Property LogisticSiteID As Integer


Member of Mantis.LVision.Win32.LVBasicForm

Summary: The Logistic Site ID selected in the login form.

Public NotOverridable Property LogisticUnitID As Integer


Member of Mantis.LVision.Win32.LVBasicForm

Summary: The Logistic Unit of the current installation.

Fields:

Methods:
Public Overridable Shadows Function LV_OnInit() As Boolean

Summary: The first function called from the base class in all LV3 forms.
If this function returns false the form will not be displayed.

Public Overridable Shadows Function LV_OnInitToolBar() As Boolean

Summary: Used for Toolbar initialization. It is not mandatory to override this function.

Public Overridable Shadows Function LV_OnOpenRecord() As System.Data.DataSet

Summary: This method is called when the user clicks the search button.

Public Overridable Shadows Function LV_OnResetRecord() As Boolean

Summary: this method is called when the user clicks the reset button. You must
override this
Method when the form contains list type controls like Listviews or LVDatagrids.

Public Overridable Shadows Function LV_OnUpdateRecord(ByRef ds As System.Data.DataSet)


As Long

Summary: This method is called when the user clicks update or delete buttons.

Public Overridable Shadows Function LV_OnDisplayRecord(ByVal RowId As Integer) As


Boolean

Summary: This method is called when the user double clicks the item of a listview
contained in a search form. It passes the row ID as parameter and may be used to
display a manage form.

Public Overridable Sub OnDataChanged(ByVal data As String)

Summary: If it is not overridden, it “Listens” to events fired by forms that contain the
same DataChangedString parameter, of its InitializeForm method. If it is, it “Listens” to all
events from all forms.

Public Sub DoSearch(Optional ByVal bAppend As Boolean = False)

Summary: Forces an LV_OnOpenRecord method call. If the bAppend parameter is set


to true it does not clear existing listview records.
Appendix

Public Sub InitializeForm(ByVal lvwSearch As System.Windows.Forms.ListView, ByVal


arrColumns As Mantis.LVision.Win32.lvColumnsInfo, ByVal tag As Object, ByVal
DataChangedString As String, ByVal arrMessagesIN As Mantis.LVision.Win32.LVMessage( ))

Summary: Assigns Messages and primary keys to the listview control (if specified). It is
used in LV_OnInit methods.

Public Function GetFormMessage(ByVal code As String) As String

Summary: It translates a message into user’s language. Before retrieving a message,


ensure that its message code is contained in the Mantis.LVision.Win32.LVMessage( )
parameter of the InitializeForm method.

Events:

CLASS: LVManageForm

Constructor:
Public Sub New()

Properties:
Public Property Identity As String
Member of Mantis.LVision.Win32.LVBasicForm

Public Property MasterTable As String


Member of Mantis.LVision.Win32.LVBasicForm

Public Property ConstructParam As Object


Member of Mantis.LVision.Win32.LVBasicForm

Public NotOverridable Property LanguageID As Integer


Member of Mantis.LVision.Win32.LVBasicForm

Public NotOverridable Property LogisticSiteID As Integer


Member of Mantis.LVision.Win32.LVBasicForm

Public NotOverridable Property LogisticUnitID As Integer


Member of Mantis.LVision.Win32.LVBasicForm

Fields:

Methods:
Public Overridable Shadows Function LV_OnInit() As Boolean

Public Function InitializeManageForm(ByVal tbrMain As System.Windows.Forms.ToolBar,


ByVal arrMessagesIN As Mantis.LVision.Win32.LVMessage( ), ByVal strDataChanged As
String, Optional ByVal bDisplayData As Boolean = True) As Boolean

Public Overridable Shadows Function LV_OnEmptyRecord() As System.Data.DataSet

Summary: This method is called when the manage form is in Insert mode (CurrentID
property is greater than zero).
Appendix

Public Overridable Shadows Function LV_OnEmptyRecords() As System.Data.DataSet( )

Summary: This method is called when the manage form is in Insert mode and it is using
more than one data source.

Public Overridable Function LV_OnUpdateRecord(ByRef ds As System.Data.DataSet, ByRef id


As Integer) As Long

Summary: This method is called when the user click the update button.

Public Overridable Function LV_OnUpdateRecord(ByRef ds As System.Data.DataSet( ), ByRef


id As Integer) As Long

Summary: This method is called when the user clicks the update button and there is
more than one data source that must be updated.

Public Overridable Shadows Function LV_OnOpenRecord() As System.Data.DataSet

Summary: This method is called when the manage form is in Update mode. It will be
called only if the CurrentID property is greater than zero.

Public Overridable Shadows Function LV_OnOpenRecords() As System.Data.DataSet( )

Summary: This method is called when the manage form is in Update mode and it is
using more than one data source. It will be called only if the CurrentID property is greater
than zero.

Events:
Appendix

CLASS: LVManageGridForm

Constructor:
Public Sub New()
Properties:
Public NotOverridable Property CurrentID As Integer
Member of Mantis.LVision.Win32.LVBasicForm
Fields:

Methods:
Public Overridable Shadows Function LV_OnInit() As Boolean

Public Overridable Shadows Sub LV_OnDefineGrid()

Public Overridable Shadows Function LV_OnOpenRecord() As System.Data.DataSet

Public Overridable Shadows Function LV_OnValidateRecord(ByVal ds As


System.Data.DataSet) As Boolean

Summary: This method is called before an LV_OnUpdateRecord method. If the form


contains list type datasources it must be overridden.

Public Overridable Shadows Function LV_OnUpdateRecord(ByRef ds As System.Data.DataSet,


ByRef id As Integer) As Long

Public Function InitializeManageGridForm(ByVal tbrMain As


System.Windows.Forms.ToolBar, ByVal grid As Mantis.LVision.Win32.LVDataGrid, ByVal
arrMessagesIN As Mantis.LVision.Win32.LVMessage( ), ByVal strDataChanged As String,
Optional ByVal displayData As Boolean = True) As Boolean

Events:

CLASS: Mantis.LVision.Win32.LVToolbar

Constructor:
Public Sub New()

Public Sub New(ByVal Container As System.ComponentModel.IContainer)


Properties:

Fields:

Methods:
Public Sub InitToolbar(ByVal toolBarObject As System.Windows.Forms.ToolBar, ByVal
ParamArray arr As Mantis.LVision.Win32.enmLVImage( ))

Public Sub InitToolbar(ByVal toolBarObject As System.Windows.Forms.ToolBar, ByVal frm As


Mantis.LVision.Win32.LVBasicForm, ByVal ParamArray arr As
Mantis.LVision.Win32.enmLVImage( ))
Events:
Appendix

CLASS: Mantis.LVision.Common.CException

Constructor:
Public Sub New()
Properties:

Fields:

Methods:
Public Shared Sub Message(ByVal pex As System.Exception, Optional ByVal pMessage As
String = Nothing, Optional ByVal frm As Mantis.LVision.Win32.LVBasicForm)

Events:

CLASS: lvColumnsInfo

Constructor:
Public Sub New()

Public Sub New(ByVal index As Integer, ByVal text As String, ByVal field As String, ByVal width
As Integer, ByVal align As System.Windows.Forms.HorizontalAlignment)

Public Sub New(ByVal index As Integer, ByVal text As String, ByVal field As String, ByVal width
As Integer, ByVal align As System.Windows.Forms.HorizontalAlignment, ByVal psortOrder
As System.Windows.Forms.SortOrder, ByVal psortPriority As Integer)

Public Sub New(ByVal index As Integer, ByVal text As String, ByVal field As String, ByVal width
As Integer, ByVal align As System.Windows.Forms.HorizontalAlignment, ByVal psortOrder
As System.Windows.Forms.SortOrder, ByVal psortPriority As Integer, ByVal visible As
Boolean)

Properties:

Fields:

Methods:

Events:

CLASS: LVLabel

Constructor:
Public Sub New()

Properties:
Public Property FieldName As String
Public Property MessageCode As String
Public Property TableName As String

Fields:

Methods:
Appendix

Events:

CLASS: LVLinkLabel

Constructor:
Public Sub New()

Properties:
Public Property FieldName As String
Public Property Info_AssemblyName As String
Public Property Info_DataCombo As Mantis.LVision.Win32.LVCombobox
Public Property Info_FormName As String
Public Property Info_FormNameSearch As String
Public Property MessageCode As String
Public Property TableName As String
Fields:

Methods:

Events:

CLASS: LVTextBox

Constructor:
Public Sub New()

Properties:
Public Property FieldName As String
Public Property LVLabelControl As Mantis.LVision.Win32.LVLabel
Public Property LVLinkLabelControl As Mantis.LVision.Win32.LVLinklabel
Public Property MessageCode As String
Public Property Required As Boolean
Public Property SelectField As String
Public Property TableName As String
Fields:

Methods:

Events:
Appendix

CLASS: LVCombobox

Constructor:
Public Sub New()

Properties:
Public Property Condition() As String
Public Property FieldName() As String
Public Property FieldValue() As String
Public Property Fill_AssemblyName() As String
Public Property Fill_DataChanged() As String
Public Property Fill_Method() As String
Public Property LVLabelControl() As Mantis.LVision.Win32.LVLabel
Public Property LVLinkLabelControl() As Mantis.LVision.Win32.LVLinklabel
Public Property MessageCode() As String
Public Property Required() As Boolean
Public Property SelectedValue() As Object
Public Property SelectField() As String
Public Property TableName() As String
Fields:

Methods:

Events:
Public Event SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

CLASS: LVDateTimePicker
Constructor:
Public Sub New()

Properties:
Public Property Condition() As String
Public Property CustomFormatEx() As
Mantis.LVision.Win32.LVDateTimePicker.DateTimeFormat
Public Property FieldName() As String
Public Property LVLabelControl() As Mantis.LVision.Win32.LVLabel
Public Property LVLinkLabelControl() As Mantis.LVision.Win32.LVLinklabel
Public Property MessageCode() As String
Public Property Required() As Boolean
Public Property SelectField() As String
Public Property TableName() As String

Fields:

Methods:

Events:
Appendix

CLASS: LVListView

Constructor:
Public Sub New()

Properties:
Public Property AllowEdit() As Boolean
Public Property ShowAdd() As Boolean
Public Property ShowCustomizeListView() As Boolean
Public Property ShowDelete() As Boolean
Public Property ShowDelete() As Boolean
Public Property ShowReset() As Boolean
Public Property ShowSearch() As Boolean
Public Property ShowSelectAll() As Boolean

Fields:

Methods:

Events:
Public Event GetMenuOptions(ByVal sender As Object, ByVal e As
Mantis.LVision.Win32.ListViewMenuEventArgs)

Remarks: Occurs when the user right clicks an LVListView Control. The
e.ContextMenuStrip field contains the menu items collection and it is used to add and
remove items to the listview’s popup context menu strip.

Example:
Private Sub lvwMain_GetMenuOptions(ByVal sender As System.Object, _
ByVal e As Mantis.Lvision.Win32.ListViewMenuEventArgs) _
Handles lvwMain.GetMenuOptions
Dim ctxMenu As ContextMenuStrip

Try

If lvwMain.Items.Count = 0 Then Exit Sub

ctxMenu = New ContextMenuStrip()


ctxMenu.Items.Add(Me.GetFormMessage("Execute"), AddressOf Sub1)
ctxMenu.Items.Add(Me.GetFormMessage("Copy"), AddressOf Sub2)

e.ContextMenuStrip = ctxMenu
Catch ex As Exception
Common.CException.Message(ex, "", Me)
End Try
End Sub
Appendix

CLASS: LVDatagrid

Constructor:
Public Sub New()

Properties:
Public Property ColumnInfos() As Mantis.LVision.Win32.LVDataGridColumnInfos
Public Property Required() As Boolean
Public Property UniqueValues() As Object
Public Property UniqueViolationField() As String
Public Property UniqueViolationMessage() As String
Public Property UniqueViolationMessageCode() As String

Fields:

Methods:
Public Sub InitializeGrid(ByVal objForm As System.Windows.Forms.Form, ByVal dsDataIn As
System.Data.DataSet)
Public Sub InitializeGrid(ByVal objForm As System.Windows.Forms.Form, ByVal dsDataIn As
System.Data.DataSet, ByVal clear As Boolean)

Events:
Public Event CellChanged(ByVal fieldName As String, ByVal e As
Mantis.LVision.Win32.EventArgsCellChanged)

Example:

Private Sub Grid_CellChanged(ByVal fieldName As String, ByVal e As


Mantis.Lvision.Win32.EventArgsCellChanged) Handles grd.CellChanged
Try
e.ReadOnly = True
If fieldName = "MyField" AndAlso Not e.row.IsNull("ID") Then
e.ReadOnly = False
Exit Sub
End If
Catch ex As Exception
Common.CException.Message(ex, "Grid_CellChanged", Me)
End Try
End Sub

Public Event ColumnChanged(ByVal sender As Object, ByVal e As


System.Data.DataColumnChangeEventArgs)

Example:

Private Sub grd_ColumnChanged(ByVal sender As Object, ByVal e As


System.Data.DataColumnChangeEventArgs) Handles grdDetail.ColumnChanged
If Not e.Row.IsNull(e.Column.ColumnName) Then
If e.Row.GetColumnError(e.Column) <> String.Empty Then
e.Row.SetColumnError(e.Column, "")
End If
End If
End Sub
Appendix

Public Event ColumnChanging(ByVal sender As Object, ByVal e As


System.Data.DataColumnChangeEventArgs)

Example:

Private Sub grd_ColumnChanging(ByVal sender As System.Object, ByVal e As


System.Data.DataColumnChangeEventArgs) Handles grd.ColumnChanging
Try
Select Case e.Column.ColumnName
Case "CanRead"
If e.ProposedValue = 0 Then
e.Row.Item("CanAdd") = 0
End If

Case "CanAdd"
If e.ProposedValue = 1 Then
e.Row.Item("CanRead") = 1
End If
End Select
Catch ex As Exception
Common.CException.Message(ex, "grd_ColumnChanging", Me)
End Try
End Sub

Public Event DataGridComboFill(ByVal sender As


Mantis.LVision.Win32.DataGridComboBoxColumnStyle, ByVal combo As
Mantis.LVision.Win32.DataGridComboBox, ByVal row As System.Data.DataRow, ByVal
columnName As String, ByVal source As System.Windows.Forms.CurrencyManager)

Example:

Private Sub grd_DataGridComboFill(ByVal sender As


Mantis.LVision.Win32.DataGridComboBoxColumnStyle, ByVal combo As
Mantis.LVision.Win32.DataGridComboBox, ByVal row As System.Data.DataRow, ByVal columnName
As String, ByVal source As System.Windows.Forms.CurrencyManager)
Dim ds As DataSet
Dim cr As Win32.ControlRoutines

Try
If columnName = "MyColumnName" Then
ds = GetDatasource
cr.FillCombo(combo, ds, " Code", " ID", "Name")
End If
Catch ex As Exception
Common.CException.Message(ex, "grd_DataGridComboFill", m_frm)
Finally
cr = Nothing
End Try
End Sub

Public Event DataGridComboKeyPress(ByVal combo As Mantis.LVision.Win32.LVCombobox,


ByVal fieldName As String, ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs)
Appendix

Example:

Private Sub grd_DataGridComboKeyPress(ByVal combo As Mantis.LVision.Win32.LVCombobox,


ByVal fieldName As String, ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles grd.DataGridComboKeyPress
Dim cr As Win32.ControlRoutines

Try
If e.KeyChar = Constants.vbCr Then
If fieldName = "MyFieldName" Then

ws = New Proxy.WsLocations()
cr = New Win32.ControlRoutines()

cr.FillCombo(combo, MyDataset, "Code", " ID")

End If
End If
Catch ex As Exception
Common.CException.Message(ex)
End Try
End Sub

Public Event DataGridComboKeyPressEx(ByVal sender As Object, ByVal e As


Mantis.LVision.Win32.LVDataGrid.DataGridComboKeyPressExEventArgs)

Example:

Private Sub grd_DataGridComboKeyPressEx(ByVal sender As Object, _


ByVal e As Mantis.LVision.Win32.LVDataGrid.DataGridComboKeyPressExEventArgs) _
Handles grd.DataGridComboKeyPressEx
Try
Dim cr As Mantis.LVision.Win32.ControlRoutines
Dim index As Integer

If e.KeyChar = vbCr Then


If e.combo.Text <> String.Empty Then
cr = New Mantis.LVision.Win32.ControlRoutines()
index = cr.AppendToCombo(e.combo, e.combo.Text, e.combo.Text, True)
e.combo.SelectedIndex = index
End If
End If
Catch ex As Exception
Common.CException.Message(ex, , Me)
End Try
End Sub

Public Event DataGridLinkLabelClick(ByVal sender As Object, ByRef e As


Mantis.LVision.Win32.LinkLabelEventArgs)

Example:
Appendix

Private Sub grd_DataGridLinkLabelClick(ByVal sender As Object, ByRef e As


Mantis.LVision.Win32.LinkLabelEventArgs) _
Handles grd.DataGridLinkLabelClick
Dim CR As Mantis.LVision.Win32.ControlRoutines

Try
CR = New Mantis.LVision.Win32.ControlRoutines()
CR.ShowFormFromAssembly(Me, "MyNamespace", "Myclass", , Nothing, , e,True)
Catch ex As Exception
Throw
Finally
CR = Nothing
End Try
End Sub

Public Event RowChanged(ByVal sender As Object, ByVal e As


System.Data.DataRowChangeEventArgs)

Example:

Private Sub grd_RowChanged(ByVal sender As Object, ByVal e As


System.Data.DataRowChangeEventArgs) Handles grd.RowChanged

If e.Row.IsNull("tls_ResetDays") Then
If Not e.Row.IsNull("tls_ResetValue") Then
e.Row.SetColumnError("tls_ResetDays", Me.GetFormMessage("ValueRequired"))
End If
Else
If e.Row.IsNull("tls_ResetValue") Then
e.Row.SetColumnError("tls_ResetValue", Me.GetFormMessage("ValueRequired"))
End If
End If
End Sub

Public Event RowChanging(ByVal sender As Object, ByVal e As


System.Data.DataRowChangeEventArgs)

Example:

Private Sub grd_RowChanging(ByVal sender As Object, ByVal e As


System.Data.DataRowChangeEventArgs) Handles grd.RowChanging
Dim bRequired As Boolean

bRequired = False
If Not e.Row.IsNull("Code") Then
If e.Row.Item("Code") = "05" Then
bRequired = True
End If
End If

If bRequired = False Then


e.Row.SetColumnError("MyColumn", "")
Else
If e.Row.IsNull("MyColumn") Then
e.Row.SetColumnError("MyColumn ", Me.GetFormMessage("ValueRequired"))
End If
End If
End Sub

Public Event RowDeleted(ByVal sender As Object, ByVal e As


System.Data.DataRowChangeEventArgs)

Example:
Appendix

Private Sub grdOrderPriority_RowDeleted(ByVal sender As Object, ByVal e As


System.Data.DataRowChangeEventArgs) Handles grdOrderPriority.RowDeleted
Dim i As Long = 0
Dim r As DataRow
Dim ds As DataSet

Try
ds = CType(grdOrderPriority.DataSource, DataSet)

For Each r In ds.Tables(0).Rows


If r.RowState <> DataRowState.Deleted _
And r.RowState <> DataRowState.Detached Then
r.Item("opy_Order") = i
i += 1
End If
Next

grdOrderPriority.Refresh()
Catch
Finally
ds = Nothing
r = Nothing
End Try
End Sub

Public Event RowDeleting(ByVal sender As Object, ByVal e As


Mantis.LVision.Win32.DataRowDeleteEventArgs)

Example:

Private Sub grd_RowDeleting(ByVal sender As Object, _


ByVal e As Mantis.Lvision.Win32.DataRowDeleteEventArgs) _
Handles grd.RowDeleting
Dim Qty As Double = 0

Try
Qty = CalcQuantity
If Qty > 0 Then
Beep()
MessageBox.Show("Can’t Delete Quantity")
e.Cancel = True
End If

Catch ex As Exception
Mantis.Lvision.Common.CException.Message(ex, "grd_RowDeleting", Me)
End Try
End Sub
Appendix

CLASS: ControlRoutines

Constructor:
Public Sub New()
Properties:

Fields:

Methods:
Public Sub FillCombo(ByVal cboCombo As Mantis.LVision.Win32.LVCombobox, ByVal dsFill As
System.Data.DataSet, ByVal FieldDisplay1 As String, Optional ByVal FieldValue As Object =
Nothing, Optional ByVal FieldDisplay2 As Object = Nothing, Optional ByVal addEmpty As Boolean
= False, Optional ByVal clearItems As Boolean = True, Optional ByVal FieldOrderBy As Object =
Nothing)

Public Function ShowFormFromAssembly(ByVal frmParent As


Mantis.LVision.Win32.LVBasicForm, ByVal assemblyName As String, ByVal typeName As
String, Optional ByVal id As Integer = 0, Optional ByVal pTreeNode As
Mantis.LVision.Win32.LVTreeNode = Nothing, Optional ByVal AllowMultiple As Boolean =
False, Optional ByVal constructParam As Object = Nothing, Optional ByVal executeAction As
Mantis.LVision.Win32.enmExecuteAction = Fill, Optional ByVal modal As Boolean = False,
Optional ByVal MultipleIDs() As Integer = Nothing) As Boolean

Public Sub AssignCriteriaFromFormData(ByVal frm As Object, ByVal dsData As


System.Data.DataSet, ByRef dsCriteria As System.Data.DataSet, Optional ByRef dsHaving As
System.Data.DataSet = Nothing, Optional ByVal tableindex As Integer = 0)

Events:
Appendix

CLASS: Mantis.LVision.DBAccess.DbRoutines

Constructor:
Public Sub New()
Properties:

Fields:

Methods:
Public Sub Dispose()

Public Sub RelateDatasets(ByVal args As Mantis.LVision.Interfaces.ILVisionForm, ByVal


MasterDataset As System.Data.DataSet, ByVal SlaveDatasets() As System.Data.DataSet,
ByVal MasterFieldName As String, ByVal SlaveFieldNames() As String, Optional ByVal
SequencesFieldName As String = Nothing, Optional ByVal Con As System.Data.IDbConnection
= Nothing, Optional ByVal tran As System.Data.IDbTransaction = Nothing, Optional ByVal
seqInfo As Mantis.LVision.DBAccess.DbRoutines.SequencesField = Nothing)

Public Sub RelateDatasets(ByVal args As Mantis.LVision.Interfaces.ILVisionForm, ByVal


MasterDataset As System.Data.DataSet, ByVal SlaveDataset As System.Data.DataSet, ByVal
MasterFieldName As String, ByVal SlaveFieldName() As String, Optional ByVal
SequencesFieldName As String = Nothing, Optional ByVal Con As System.Data.IDbConnection
= Nothing, Optional ByVal tran As System.Data.IDbTransaction = Nothing, Optional ByVal
seqInfo As Mantis.LVision.DBAccess.DbRoutines.SequencesField = Nothing)

Public Sub RelateDatasets(ByVal args As Mantis.LVision.Interfaces.ILVisionForm, ByVal


MasterDataset As System.Data.DataSet, ByVal SlaveDataset As System.Data.DataSet, ByVal
MasterFieldName As String, ByVal SlaveFieldName() As String, Optional ByVal
SequencesFieldName As String = Nothing, Optional ByVal Con As System.Data.IDbConnection
= Nothing, Optional ByVal tran As System.Data.IDbTransaction = Nothing, Optional ByVal
seqInfo As Mantis.LVision.DBAccess.DbRoutines.SequencesField = Nothing)

Public Sub RelateDatatables(ByVal args As Mantis.LVision.Interfaces.ILVisionForm, ByVal


MasterDataset As System.Data.DataTable, ByVal SlaveDatasets() As System.Data.DataTable,
ByVal MasterFieldName As String, ByVal SlaveFieldNames() As String, Optional ByVal
SequencesFieldName As String = Nothing, Optional ByVal Con As System.Data.IDbConnection
= Nothing, Optional ByVal tran As System.Data.IDbTransaction = Nothing)

Public Function ChangeTable(ByRef dsData As System.Data.DataSet, ByVal args As


Mantis.LVision.Interfaces.ILVisionForm, ByVal primaryKey As String, Optional ByVal
tableName As String = Nothing, Optional ByVal DomainField As String = Nothing, Optional ByVal
sequenceField As String = Nothing, Optional ByVal connection As System.Data.IDbConnection
= Nothing, Optional ByVal trans As System.Data.IDbTransaction = Nothing, Optional ByVal
blnGetNextRow As Boolean = True, Optional ByVal action As System.Data.DataRowState = -
1) As Integer

Public Function CheckQuote(ByVal Text As String) As String

Summary: It checks for additional Single Quote characters (‘) usually supplied by the
user and replaces them with double quotes to prevent SQL errors.

Example:
CheckQuote("'A1") Produces "''A1"
Appendix

Public Function Execute(ByVal SQL As String, ByVal con As System.Data.IDbConnection,


ByVal trans As System.Data.IDbTransaction, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm) As Integer

Summary: An executeNonQuery type method, which is used for INSERT, UPDATE and
DELETE Statements.

Public Function GetSearchSQL(ByVal DsCriteria As System.Data.DataSet, ByVal Identity As


String, ByVal args As Mantis.LVision.Interfaces.ILVisionForm) As String

Summary: It accepts a Criteria dataset from an LV3 form and creates a where clause
according to the LVControls Field Property and values.

Public Function IsCodeExists(ByVal ds As System.Data.DataSet, ByVal fieldCode As String,


ByVal fieldID As String, ByVal strSelect As String, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm, Optional ByVal Connection As
System.Data.IDbConnection = Nothing, Optional ByVal Transaction As
System.Data.IDbTransaction = Nothing, Optional ByVal strExceptionMessageCode As String =
Nothing, Optional ByVal bAllData As Boolean = False) As Boolean

Summary: It checks for the existence of a code type field against the datarows of the
current dataset and the database. If a duplicate value is found it raises an exception.

Public Function SelectTable(ByVal SQL As String, ByVal args As


Mantis.LVision.Interfaces.ILVisionForm, Optional ByVal Connection As
System.Data.IDbConnection = Nothing) As System.Data.DataSet

Public Function SelectTable(ByVal SQL As String, ByVal args As


Mantis.LVision.Interfaces.ILVisionForm, ByVal Connection As
System.Data.IDbConnection, ByVal trans As System.Data.IDbTransaction) As
System.Data.DataSet

Public Function SelectTable(ByVal SchemaName As String, ByVal SQL As String, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm, Optional ByVal Connection As
System.Data.IDbConnection = Nothing) As System.Data.DataSet

Public Function SelectTable(ByVal SchemaName As String, ByVal SQL As String, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm, ByVal ds As System.Data.DataSet, Optional ByVal
Connection As System.Data.IDbConnection = Nothing) As System.Data.DataSet

Public Function SelectTable(ByVal SchemaName As String, ByVal SQL As String, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm, ByVal ds As System.Data.DataSet, ByVal
Connection As System.Data.IDbConnection, ByVal trans As System.Data.IDbTransaction)
As System.Data.DataSet

Public Function SelectTable(ByVal SchemaName As String, ByVal SQL As String, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm, ByVal Connection As
System.Data.IDbConnection, ByVal trans As System.Data.IDbTransaction) As
System.Data.DataSet

Summary: It executes a Query statement specified by the SQL parameter. If the


SchemaName parameter is provided, it will read the Dataset schema (xsd) from the
Datasets Path and it will force primary key rules.
Appendix

Public Function UpdateTable(ByRef dsData As System.Data.DataSet, ByVal args As


Mantis.LVision.Interfaces.ILVisionForm, ByVal primaryKey As String, Optional ByVal
tableName As String = Nothing, Optional ByVal DomainField As String = Nothing, Optional ByVal
sequenceField As String = Nothing, Optional ByVal connection As System.Data.IDbConnection
= Nothing, Optional ByVal trans As System.Data.IDbTransaction = Nothing, Optional ByVal
blnGetNextRow As Boolean = True) As Integer

Remarks: It executes INSERT, UPDATE and DELETE statements by categorising the


dsData parameter’s datarow states. If you need to update specific datarow states, like
deleted only, you can use the ChangeTable Function.

Events:
Appendix

CLASS: Mantis.LVision.DBAccess.DbRoutines.DBConnection

Constructor:
Public Sub New()
Properties:

Fields:

Methods:
Public Shared Function Open(ByVal args As Mantis.LVision.Interfaces.ILVisionForm) As
System.Data.IDbConnection

Public Shared Function BeginTransaction(ByVal con As System.Data.IDbConnection) As


System.Data.IDbTransaction

Events:
Appendix

CLASS: Mantis.LVision.DBAccess.DbRoutines.DBFunctions

Remarks: Converts SQL statements according to the database type. The database type is a
property of the IlVisionForm Interface and it can get the following values which are defined in the
DBDatabaseTypes enumerator.

GENERIC = 0
ORACLE_SERVER = 2
SQL_SERVER = 1

Constructor:
Public Sub New()

Properties:

Fields:

Methods:

DateDiffference

Public Shared Function DateDiffference(ByVal args As


Mantis.LVision.Interfaces.ILVisionForm, ByVal DateFirst As String, ByVal DateSecond As
String, Optional ByVal SQLServerDatePart As String = "", Optional ByVal Alias As String =
Nothing) As String

Summary: It calculates the date difference between to dates according to the database
type.

Example:

DateDiffference(Me, "'1/1/2007'", "'11/12/2007'", "'mm'","MyDATE")

Produces:

SQL Server
"DateDIFF('mm','1/1/2007','11/12/2007') MyDATE"

Oracle
"('1/1/2007' - '11/12/2007') MyDATE"

FieldNull
Public Shared Function FieldNull(ByVal args As Mantis.LVision.Interfaces.ILVisionForm,
ByVal fieldName As String, ByVal Value As Object, Optional ByVal Alias As String = Nothing) As
String

Example:

FieldNull(Me, "MyField", 1, "MyAlias")

Produces:
Appendix

SQL Server
"ISNULL(MyField,1) MyAlias"

Oracle
"NVL(MyField,1) MyAlias"

FieldWithCase
Public Shared Function FieldWithCase(ByVal args As
Mantis.LVision.Interfaces.ILVisionForm, ByVal value As String, ByVal condition As String,
ByVal truepart As String, ByVal falsepart As String) As String

Example:

FieldWithCase(Me, "MyQuantityField", "0", "1", "MyQuantityField")

Produces:

SQL Server
"CASE MyQuantityField WHEN 0 THEN 1 ELSE MyQuantityField END"

Oracle
"DECODE(MyQuantityField, 0, 1, MyQuantityField)"

GetFieldDate
Public Shared Function GetFieldDate(ByVal args As Mantis.LVision.Interfaces.ILVisionForm,
ByVal fldName As String, Optional ByVal Alias As String = Nothing) As String

Example:

GetFieldDate(Me, "MydateField", "MyDate")

Produces:

SQL Server
"CONVERT(DATETIME,MydateField) MyDate"

Oracle
"TO_DATE(MydateField,'DD-MM-YYYY HH24:MI:SS') MyAlias"

GetFieldNumeric
Public Shared Function GetFieldNumeric(ByVal args As
Mantis.LVision.Interfaces.ILVisionForm, ByVal fieldname As String, Optional ByVal Alias As
String = Nothing, Optional ByVal prec As Integer = -1, Optional ByVal scale As Integer = -1,
Optional ByVal ConvertToChar As Boolean = True) As String

Example:

GetFieldNumeric(Me, "MyField", "MyAlias", 10, 2, True)


Appendix

SQL Server
Produces "CONVERT(real, CONVERT(NUMERIC(10,2),MyField)) MyAlias"

Oracle
"TO_NUMBER(ROUND(REPLACE(TO_CHAR(MyField, '9999999999D99') , '.',
','), 2)) MyAlias"

GetFieldShortDate
Public Shared Function GetFieldShortDate(ByVal args As
Mantis.LVision.Interfaces.ILVisionForm, ByVal fldName As String, Optional ByVal Alias As
String = Nothing, Optional ByVal SQLCode As String = Nothing) As String

Example:

GetFieldShortDate(Me, "MyFieldName", "MyAlias", "102")

Produces:

SQL Server
"CONVERT(varchar(10),MyFieldName, 102) MyAlias"

Oracle
"TO_CHAR(MyFieldName,'YYYY-MM-DD') MyAlias"

InsertDate
Public Shared Function InsertDate(ByVal strDate As String, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm) As String

Example:

InsertDate("11/10/2007", Me)

Produces:

SQL Server
"CONVERT(datetime,'10/11/2007',103) "

Oracle
"TO_DATE( '15/10/2007','DD-MM-YYYY HH24:MI:SS') "

InsertDateTime
Public Shared Function InsertDateTime(ByVal strDate As String, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm) As String

Example:

InsertDateTime(Date.Now, Me)
Appendix

Produces:

SQL Server
"CONVERT(datetime,'14/10/2007 21:46:33',103) "

Oracle
"TO_DATE( '15/10/2007 01:48:08','DD-MM-YYYY HH24:MI:SS') "

SeekWithDate
Public Shared Function SeekWithDate(ByRef fldDATE As String, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm, Optional ByVal Date1 As String = Nothing, Optional
ByVal Date2 As String = Nothing) As String

Example:

SeekWithDate("MyDateField", Me, "10/11/2007", "12/23/2007")

Produces:

SQL Server
" MyDateField >= CONVERT(datetime,'10/11/2007 00:00:00') AND
MyDateField <= CONVERT(datetime,'12/23/2007 23:59:59.998')"

Oracle
" MyDateField >= TO_DATE('10/11/2007 00:00:00','MM-DD-YYYY
HH24:MI:SS') AND MyDateField <= TO_DATE('12/23/2007 23:59:59','MM-
DD-YYYY HH24:MI:SS')"

SeekWithDateLessThan
Public Shared Function SeekWithDateLessThan(ByRef fldDATE As String, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm, ByVal Date1 As String) As String

Example:

SeekWithDateLessThan("MyDateField", Me, "12/23/2007")

Produces

SQL Server
" MyDateField < CONVERT(datetime,'12/23/2007 00:00:00')"

Oracle
" MyDateField < TO_DATE('12/23/2007 00:00:00','MM-DD-YYYY
HH24:MI:SS')"
Appendix

SeekWithDateTime
Public Shared Function SeekWithDateTime(ByRef fldDATE As String, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm, Optional ByVal Date1 As String = Nothing, Optional
ByVal Date2 As String = Nothing) As String

Example:

SeekWithDateTime("MyDateField", Me, "10/11/2007", "12/23/2007")

Produces

SQL Server
" MyDateField >= CONVERT(datetime,'10/11/2007 00:00:00') AND
MyDateField <= CONVERT(datetime,'12/23/2007 00:00:00')"

Oracle
" MyDateField >= TO_DATE('10/11/2007 00:00:00','MM-DD-YYYY
HH24:MI:SS') AND MyDateField <= TO_DATE('12/23/2007 00:00:00','MM-
DD-YYYY HH24:MI:SS')"

ServerDate
Public Shared Function ServerDate(ByVal args As Mantis.LVision.Interfaces.ILVisionForm)
As String

Example:

ServerDate(Me)

Produces:

SQL Server
"select GetDate()"

Oracle
"select sysdate from dual"

SQLAdd
Public Shared Function SQLAdd(ByVal args As Mantis.LVision.Interfaces.ILVisionForm) As
String

Remarks: Concatenates Fields

Example:

"MyCodeField " & SQLAdd(Me) & " ' - ' " & SQLAdd(Me) &
"MyDescField"
Appendix

Produces:

SQL Server
"MyCodeField + ' - ' + MyDescField"

Oracle
"MyCodeField || ' - ' || MyDescField"

SQLDate
Public Shared Function SQLDate(ByVal args As Mantis.LVision.Interfaces.ILVisionForm) As
String

Example:

SQLDate(Me)

Produces:

SQL Server
"GetDate()"

Oracle
"sysdate"

SQLDay
Public Shared Function SQLDay(ByVal strDate As String, ByVal args As

Example:

SQLDay(SQLDate(Me), Me)

Produces:

SQL Server
"DAY(GetDate())"

Oracle
"TO_NUMBER(TO_CHAR(sysdate, 'DD'))"

SQLMonth
Public Shared Function SQLMonth(ByVal strDate As String, ByVal args As
Mantis.LVision.Interfaces.ILVisionForm) As String

Example:

SQLMonth("10/22/2007", Me)

Produces:
Appendix

SQL Server
"MONTH(10/22/2007)"

Oracle
"TO_NUMBER(TO_CHAR(10/22/2007, 'MM'))"
SQLUpper
Public Shared Function SQLUpper(ByVal args As Mantis.LVision.Interfaces.ILVisionForm,
ByVal field As String) As String

Example:

SQLUpper(Me, "MyField")

Produces

SQL Server
"MyField"

Oracle
"upper(MyField)"

Events:

You might also like