Professional Documents
Culture Documents
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
Software
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+”.
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
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
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.
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).
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+
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
<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.
(We assume that we are given the task of displaying and manipulating data from
shipments)
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")
}
)
Return True
Catch ex As Exception
Common.CException.Message(ex, "LV_OnInit", Me)
Return False
Chapter 1
Finally
cols = Nothing
End Try
End Function
a. FieldName = ord_Code
b. LVLabelControl = lblOrder
c. SelectField = ost_ShipmentID
d. TableName = V_SearchOrderShipment
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
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”.
a. Condition = <=
b. FieldName = shp_ShipDate
c. LVLabelControl = lblTo
d. CustomFormatEX = DATE_FORMAT
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
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 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.
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
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.
Try
dbr = New Mantis.LVision.DBAccess.DbRoutines.Routines()
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.
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.
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
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)
iaffected += dbr.ChangeTable(
dsDeleted,
Me,
"shp_ID",
"LV_Shipment",
"shp_DomainID",
Nothing,
con,
trans,
False,
DataRowState.Deleted)
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
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
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
If you now build and run the project you should see an empty form upon clicking the
new button of the frmSearch form.
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
i. Name = lblCode
Chapter 1
i. Name = txtCode
v. Required = true
i. Name = lblDispatchMethod
i. Name = cboDispatchMethod
v. Fill_TypeName = FillCombo
i. Name = lblStatus
i. Name = cboShipmentStatus
v. Fill_TypeName = FillCombo
Chapter 1
i. Name = lblShipDate
i. Name = dtpShipDate
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
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.
Try
dbr = New DBAccess.DbRoutines.Routines()
ds.Tables(0).Rows(0).Item("shp_logisticSiteID") =
Me.LogisticSiteID
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.
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:
Try
strSQL =
"SELECT * from LV_Shipment" &
" WHERE shp_ID = " & Me.CurrentID &
" AND shp_logisticSiteID = " & Me.LogisticSiteID
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:
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.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.
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
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
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
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.
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.
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
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.
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.
Me.InitializeManageGridForm(
Me.tbrMain,
Me.grdMachineModel,
New Win32.LVMessage() {New Win32.LVMessage("MachineModels")},
"MachineModels",
True)
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
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
If CType(Me.grdMachineModel.DataSource, DataSet).Tables(0).HasErrors
Then
Media.SystemSounds.Beep.Play()
Return False
Chapter 2
End If
Return True
End Function
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
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
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
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.DisplayMember = "mnt_Code"
col.DisplayMember2 = "mnt_Description"
Our Combo will display the above fields in a "mnt_Code - mnt_Description" format.
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.
4. Add an LVListview control and name it lvwMain and set the View property to
Details.
System.Windows.Forms
Mantis.LVision
Mantis.LVision.Win32
Mantis.LVision.DBAccess
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.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
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
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.
Try
dbr = New DbRoutines.Routines()
strSQL =
"SELECT * FROM V_Machine " &
"WHERE LanguageID = " & Me.LanguageID
Finally
If dbr IsNot Nothing Then dbr.Dispose()
dbr = Nothing
End Try
End Function
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
i. Name = lblCode
i. Name = txtCode
i. Name = lblDescription
i. Name = txtDescription
i. Name = lblStatus
i. Name = cboStatus
v. Fill_TypeName = FillCombo
i. Name = lnkMachineModel
v. Info_FormNameSearch = frmMachineModel
i. Name = cboMachineModel
v. Fill_Method = MachineModels
i. Name = lnkLocation
v. Info_FormNameSearch = frmSearchLocation
i. Name = cboLocation
v. LVLinkLabelControl = lnkLocation
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.
Try
Me.Cursor = Cursors.WaitCursor
Me.DefineGridUsers()
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
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
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)
Me.grdMachineUsers.InitializeGrid(Me, ds(enmData.MachineUsers))
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
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
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))
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
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)
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
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
Catch ex As Exception
Throw
Finally
col = Nothing
End Try
End Sub
Try
If e.KeyChar <> vbCr Then Exit Sub
Me.Cursor = Cursors.WaitCursor
Catch ex As Exception
Common.CException.Message(ex, "cboLocation_KeyPress", Me)
Finally
Me.Cursor = Cursors.Default
oCb = Nothing
End Try
End Sub
Try
If columnName = "Person" Then
dbr = New DbRoutines.Routines()
cr = New Win32.ControlRoutines()
strSQL =
Chapter 3
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.
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
Catch ex As Exception
Trace.WriteLine("UpdateMachineDatasets: " & vbCrLf &
ex.Message & vbCrLf & ex.StackTrace)
Try
trans.Rollback()
Catch exTemp As Exception
End Try
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
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).
Example:
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:
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)
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
The FillListView Method in the LV_OnOpenRecords function, it will fill the listview
successfully.
Example:
Try
strSQL =
"SELECT * from LV_Shipment" &
" WHERE shp_ID = " & Me.CurrentID &
" AND shp_logisticSiteID = " & Me.LogisticSiteID
Me.Text =
Me.GetFormMessage("Shipments") & " - " &
Me.GetFormMessage("Manage") & " : " &
CType(ds(0).Tables(0).Rows(0).Item("shp_Code"), String)
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
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
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:
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)
Note: We can also call the method without the paramArray parameter if we want to
use custom buttons only.
Example:
If the LV_OnMenuClick method returns false the base class will handle the button
click according to its functionality.
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.
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.
Summary: The main Table - View that will be used in search Queries.
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.
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.
Summary: Used for Toolbar initialization. It is not mandatory to override this function.
Summary: This method is called when the user clicks the search button.
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.
Summary: This method is called when the user clicks update or delete buttons.
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.
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.
Summary: Assigns Messages and primary keys to the listview control (if specified). It is
used in LV_OnInit methods.
Events:
CLASS: LVManageForm
Constructor:
Public Sub New()
Properties:
Public Property Identity As String
Member of Mantis.LVision.Win32.LVBasicForm
Fields:
Methods:
Public Overridable Shadows Function LV_OnInit() As Boolean
Summary: This method is called when the manage form is in Insert mode (CurrentID
property is greater than zero).
Appendix
Summary: This method is called when the manage form is in Insert mode and it is using
more than one data source.
Summary: This method is called when the user click the update button.
Summary: This method is called when the user clicks the update button and there is
more than one data source that must be updated.
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.
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
Events:
CLASS: Mantis.LVision.Win32.LVToolbar
Constructor:
Public Sub New()
Fields:
Methods:
Public Sub InitToolbar(ByVal toolBarObject As System.Windows.Forms.ToolBar, ByVal
ParamArray arr As Mantis.LVision.Win32.enmLVImage( ))
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
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:
Example:
Example:
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
Example:
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
Example:
Try
If e.KeyChar = Constants.vbCr Then
If fieldName = "MyFieldName" Then
ws = New Proxy.WsLocations()
cr = New Win32.ControlRoutines()
End If
End If
Catch ex As Exception
Common.CException.Message(ex)
End Try
End Sub
Example:
Example:
Appendix
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
Example:
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
Example:
bRequired = False
If Not e.Row.IsNull("Code") Then
If e.Row.Item("Code") = "05" Then
bRequired = True
End If
End If
Example:
Appendix
Try
ds = CType(grdOrderPriority.DataSource, DataSet)
grdOrderPriority.Refresh()
Catch
Finally
ds = Nothing
r = Nothing
End Try
End Sub
Example:
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)
Events:
Appendix
CLASS: Mantis.LVision.DBAccess.DbRoutines
Constructor:
Public Sub New()
Properties:
Fields:
Methods:
Public Sub Dispose()
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
Summary: An executeNonQuery type method, which is used for INSERT, UPDATE and
DELETE Statements.
Summary: It accepts a Criteria dataset from an LV3 form and creates a where clause
according to the LVControls Field Property and values.
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 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
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
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
Summary: It calculates the date difference between to dates according to the database
type.
Example:
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:
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:
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:
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:
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:
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:
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:
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:
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
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: