Public Class modHost
Private SelType As String = ""
Private PrintOption As Boolean
Public hdb As nbfDB.HDBC
Public DefaultPrefix As String = ""
Public MenuForm As System.Windows.Forms.Form
Public Sub New(ByVal hd As nbfDB.HDBC, ByVal mf As System.Windows.Forms.Form)
MyBase.new()
hdb = hd
MenuForm = mf
End Sub
Private Function SelectReport() As String
Try
Dim ql As New nbfUserReportList()
ql.SetGrid()
ql.BuildList()
ql.ShowDialog()
If ql.Abandoned Then
Return ""
End If
Dim tplName As String = ql.grdQryList.GetCellText()
Return tplName
Catch ex As Exception
Return ""
End Try
End Function
Public Sub EditReport(Optional ByVal ReportName As String = "")
Try
If ReportName = "" Then
ReportName = InputBox("Please Enter the Name for the Report:", "Create or Edit User Report")
If ReportName = "" Then
MsgBox("Operation Cancelled")
Exit Sub
End If
End If
Dim ap As String = System.Windows.Forms.Application.StartupPath & "\UserReports"
If ap.Length = 0 Then
MsgBox("Invalid Directory Setting")
Exit Sub
End If
Dim nb As New nbfBrowser.nbfBrowseHost(hdb, ap)
If Not String.IsNullOrEmpty(DefaultPrefix) Then
nb.SetDefaultPrefix(DefaultPrefix)
End If
If MenuForm.IsMdiContainer Then
nb.MdiParentForm = MenuForm
End If
nb.EditReportTemplate(ReportName)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub OpenReport()
Dim tplName As String = SelectReport()
If Not String.IsNullOrEmpty(tplName) Then
EditReport(tplName)
End If
End Sub
Public Sub PrintReport()
Dim tplName As String = SelectReport()
If Not String.IsNullOrEmpty(tplName) Then
PrintReport(tplName)
End If
End Sub
Public Sub PrintReport(ByVal ReportName As String)
If Not String.IsNullOrEmpty(ReportName) Then
DoReport(ReportName$, True)
End If
End Sub
Public Sub DeleteReport()
Dim tplName As String = SelectReport()
If Not String.IsNullOrEmpty(tplName) Then
DelRep(tplName)
End If
End Sub
Public Sub RunReport()
Dim tplName As String = SelectReport()
DoReport(tplName)
End Sub
Public Sub RunReport(ByVal ReportName As String)
Dim tplName As String = SelectReport()
If ReportName = "" Then
ReportName = SelectReport()
End If
If Not String.IsNullOrEmpty(ReportName) Then
DoReport(ReportName)
End If
End Sub
Private Sub DoReport(ByVal ReportName As String, Optional ByVal Print As Boolean = False)
Dim brep As nbfSqlReporter.nbfBrowseRep = Nothing
Try
Dim ap As String = ""
Dim pcnt As Integer = 0
Dim runopt As String = ""
PrintOption = Print
ap = System.Windows.Forms.Application.StartupPath & "\UserReports"
If ap.Length = 0 Then
MsgBox("Invalid Directory Setting")
Exit Sub
End If
brep = New nbfSqlReporter.nbfBrowseRep(hdb, ap, ReportName)
If brep.BFInfo.RepParams.count > 0 Then
Dim lpos% = 10
Dim l2pos% = 203
Dim vpos% = 70
Dim lht% = 36
Dim cwid% = 150
Dim cht% = 18
Dim fpl As New nbfUserParamList()
fpl.SuspendLayout()
For Each rp As nbfSqlReporter.nbfRepParam In brep.BFInfo.RepParams
pcnt% += 1
Dim nbl As New System.Windows.Forms.Label
nbl.Text = rp.ParamDescription
nbl.Left = lpos%
nbl.AutoSize = False
nbl.Width = 190
nbl.Top = vpos%
fpl.Controls.Add(nbl)
Select Case rp.ParamType.Trim().ToUpper()
Case "NUMBER"
Dim nb As New System.Windows.Forms.NumericUpDown
nb.Name = "p" & pcnt%.ToString()
nb.Width = cwid
nb.Height = cht
If IsNumeric(rp.ParamDefaultValue) Then
nb.Text = rp.ParamDefaultValue
End If
nb.Left = l2pos%
nb.Top = vpos%
fpl.Controls.Add(nb)
Case "DATE"
Dim db As New System.Windows.Forms.DateTimePicker
db.Name = "p" & pcnt%.ToString()
db.Width = cwid
db.Height = cht
'db.Text = rp.ParamDescription
db.Left = l2pos%
db.Top = vpos%
fpl.Controls.Add(db)
Case Else
Dim tb As New System.Windows.Forms.TextBox
tb.Name = "p" & pcnt%.ToString()
tb.Width = cwid
tb.Height = cht
tb.Text = rp.ParamDefaultValue
tb.Left = l2pos%
tb.Top = vpos%
fpl.Controls.Add(tb)
End Select
vpos% += lht%
Next
Dim sz As New System.Drawing.Size
sz.Width = fpl.ClientSize.Width
sz.Height = vpos + cht + 20
fpl.ClientSize = sz
fpl.ResumeLayout()
fpl.RepName = ReportName
fpl.NumParams = brep.BFInfo.RepParams.count
fpl.ShowDialog()
pcnt = 0
For Each rp As nbfSqlReporter.nbfRepParam In brep.BFInfo.RepParams
pcnt% += 1
If pcnt <= brep.BFInfo.RepParams.count Then
Select Case rp.ParamType.Trim().ToUpper()
Case "NUMBER"
For Each c As System.Windows.Forms.Control In fpl.Controls
If c.Name = "p" & pcnt.ToString() Then
rp.ParamCurrentValue = CType(c, System.Windows.Forms.NumericUpDown).Value.ToString()
End If
Next
Case "DATE"
For Each c As System.Windows.Forms.Control In fpl.Controls
If c.Name = "p" & pcnt.ToString() Then
rp.ParamCurrentValue = CType(c, System.Windows.Forms.DateTimePicker).Value.ToString()
End If
Next
Case Else
For Each c As System.Windows.Forms.Control In fpl.Controls
If c.Name = "p" & pcnt.ToString() Then
rp.ParamCurrentValue = CType(c, System.Windows.Forms.TextBox).Text.ToString()
End If
Next
End Select
End If
Next
End If
brep.SetDefaultPrefix(DefaultPrefix)
brep.CurrentDate = Now
Dim ssz As New System.Drawing.Size
If Not Print Then
Dim scr As System.Windows.Forms.Screen = System.Windows.Forms.Screen.PrimaryScreen
Dim spt As New System.Drawing.Point
spt.X = 1
spt.Y = 1
Dim r As System.Drawing.Rectangle = System.Windows.Forms.Screen.GetWorkingArea(spt)
ssz.Width = CInt(r.Width * 0.95)
ssz.Height = CInt(r.Height * 0.95)
brep.PrintForm(ssz, True, True)
Do While brep.Printing
'loop until print finishes
System.Windows.Forms.Application.DoEvents()
Loop
Else
brep.PrintForm(ssz, False, True)
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
If Not brep Is Nothing Then
brep.Dispose()
End If
End Try
End Sub
Sub DelRep(ByVal ReportName As String)
Try
Dim fn$
Dim ap As String = ""
ap = System.Windows.Forms.Application.StartupPath & "\UserReports"
fn$ = ap & "\" & ReportName
If InStr(fn$, ".sqz", CompareMethod.Text) <= 0 Then
fn$ &= ".sqz"
End If
If Not System.IO.File.Exists(fn$) Then
MsgBox("Report not found")
Exit Sub
End If
If MsgBox("Report " & ReportName & " will be deleted. Are you sure you wish to continue?", MsgBoxStyle.OkCancel Or MsgBoxStyle.DefaultButton2, "Delete Report") = MsgBoxResult.Cancel Then
MsgBox("Operation Cancelled", MsgBoxStyle.OkOnly, "Delete Report")
Exit Sub
End If
If MsgBox("Delete Report " & ReportName & " now?", MsgBoxStyle.OkCancel Or MsgBoxStyle.DefaultButton2, "Delete Report") = MsgBoxResult.Cancel Then
MsgBox("Operation Cancelled", MsgBoxStyle.OkOnly, "Delete Report")
Exit Sub
End If
System.IO.File.Delete(fn$)
MsgBox("Report " & ReportName & " has been deleted.", MsgBoxStyle.OkOnly, "Delete Report")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub AddGridRow(ByVal g As odGridControls.nbfGrid, ByVal txt As String)
Try
Dim ncd As New odGridControls.nbfGridCellData
ncd.CellValue = txt
Dim gr As New odGridControls.nbfGridRow
gr.RowHeight = 18
gr.RowData.Add(ncd)
g.AddGridAddItemRow(gr)
Catch ex As Exception
End Try
End Sub
End Class