\'============================== The Beginning of the Copyright Notice =================================
\' THE AULIX.COMMON7 LIBRARY SOFTWARE PRODUCT
\' The AUTHOR of this file is Alexander Borisovich Prokopyev, Kurgan, Russia
\' More info can be found at the AUTHOR\'s website: http://www.aulix.com/resume
\' Contact: alexander.prokopyev at aulix dot com
\'
\' Copyright (c) Alexander Prokopyev, 2006-2013
\'
\' All materials contained in this file are protected by copyright law.
\' Nobody except the AUTHOR may alter or remove this copyright notice from copies of the content.
\'
\' The AUTHOR explicitly prohibits to use this content by any method without a prior
\' written hand-signed permission of the AUTHOR.
\'================================= The End of the Copyright Notice ====================================
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Imports Microsoft.Reporting.WinForms
Imports System.Reflection
<Obfuscation(Feature:="Apply to member * when method: virtualization", Exclude:=False)> _
Public Class AdvancedForm
Inherits DevExpress.XtraEditors.XtraForm
Private Sub AdvancedForm_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
EnsureDataIsSaved()
End Sub
Public Overridable Sub EnsureDataIsSaved()
Dim F As Form
For Each F In MdiChildren
Try
CType(F, AdvancedForm).EnsureDataIsSaved()
Catch ex As System.Exception
End Try
Next
For Each C As Windows.Forms.Control In Me.Controls
If TypeOf C Is AdvancedGrid Then
CType(C, AdvancedGrid).EnsureDataIsSaved()
End If
Next
End Sub
Function TryToOpenChildForm(ByVal FormName As String, ByVal AssemblyName As String) As Form
Try
TryToOpenChildForm = CType(DotNetBridge.CreateObject(AssemblyName, AssemblyName & "." & FormName), Form)
Catch ex As System.Exception
End Try
End Function
\'Function OpenChildForm(ByVal FormName As String) As Form \', Optional ByVal Modal As Boolean = False
\' OpenChildForm = TryToOpenChildForm(FormName, My.Application.Info.AssemblyName)
\' If IsNothing(OpenChildForm) Then
\' OpenChildForm = TryToOpenChildForm(FormName, "Aulix.Common7.WinForms")
\' End If
\' If IsNothing(OpenChildForm) Then
\' OpenChildForm = TryToOpenChildForm(FormName, "Aulix.Common7.BL")
\' End If
\' If IsNothing(OpenChildForm) Then
\' MsgBox("Cannot find a form: " & FormName)
\' Else
\' OpenChildForm.MdiParent = Me
\' OpenChildForm.Show()
\' End If
\'End Function
Function OpenChildForm(ByVal FormType As Type, ByVal ParamArray PA() As Object) As Form \', Optional ByVal Modal As Boolean = False
OpenChildForm = CType(Activator.CreateInstance(FormType, PA), Form)
With OpenChildForm
.MdiParent = Me
.Show()
End With
End Function
Function FindChildFormByName(ByVal FormName As String) As Windows.Forms.Form
For Each F As Windows.Forms.Form In MdiChildren
If F.Name = FormName Then
FindChildFormByName = F
Exit Function
End If
Next
End Function
End Class
<Obfuscation(Feature:="Apply to member * when method: virtualization", Exclude:=False)> _
Public Class AdvancedGrid
Inherits DevExpress.XtraGrid.GridControl
Private WithEvents CN As DevExpress.XtraEditors.ControlNavigator
Event DeleteRowBtnClicked(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs)
Event AddRowBtnClicked(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs)
Private Sub AdvancedGrid_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not DesignMode Then
UseEmbeddedNavigator = True
CN = EmbeddedNavigator
End If
End Sub
Sub EnsureDataIsSaved()
CloseEditors()
If CType(DS, AdvancedDataSet).HasChanges Then
If MsgBox(Messages.GetMessage("DataNotSaved"), MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
SaveData()
End If
End If
End Sub
Sub CloseEditors()
For Each V As DevExpress.XtraGrid.Views.Base.BaseView In ViewCollection
V.CloseEditor()
V.UpdateCurrentRow()
Next
End Sub
Sub SaveData()
CloseEditors()
If DS IsNot Nothing AndAlso TypeOf DS Is DataSet Then
With CType(DS, AdvancedDataSet)
Dim Ch = .GetChanges(DataRowState.Deleted)
.Save()
End With
End If
End Sub
Private Sub CN_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs) Handles CN.ButtonClick
If e.Button.ButtonType = DevExpress.XtraEditors.NavigatorButtonType.Append Then
RaiseEvent AddRowBtnClicked(sender, e)
End If
If e.Button.ButtonType = DevExpress.XtraEditors.NavigatorButtonType.Remove Then
If MsgBox(Messages.GetMessage("AreYouSureToDelete"), MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
Dim V As Aulix.Common7.WinForms.AdvancedGridView = CType(FocusedView, AdvancedGridView) \'Dim V As DevExpress.XtraGrid.Views.BandedGrid.AdvBandedGridView = FocusedView
V.EnsureAtLeastOneFocusedRowIsSelected()
RaiseEvent DeleteRowBtnClicked(sender, e)
If Not e.Handled Then
V.DeleteSelectedRows()
If DS IsNot Nothing AndAlso TypeOf DS Is DataSet Then
With CType(DS, AdvancedDataSet)
Dim Ch = .GetChanges(DataRowState.Deleted)
.Save()
End With
\'ElseIf TypeOf DS Is DataTable Then
\'!!!ElseIf TypeOf DS Is AdvancedBindingSource Then
\' CType(DS, AdvancedBindingSource).Flush()
End If
e.Handled = True
End If
Else
e.Handled = True
End If
End If
End Sub
Public ReadOnly Property DS() As Object
Get
\'If TypeOf DataSource Is AdvancedDataSet Then
\'DS = CType(DataSource, AdvancedDataSet)
DS = DataSource
\'End If
End Get
End Property
Public ReadOnly Property ADS() As AdvancedDataSet
Get
\'If TypeOf DataSource Is AdvancedDataSet Then
\'DS = CType(DataSource, AdvancedDataSet)
ADS = CType(DataSource, AdvancedDataSet)
\'End If
End Get
End Property
Protected Overrides Sub RegisterAvailableViewsCore(ByVal C As DevExpress.XtraGrid.Registrator.InfoCollection)
MyBase.RegisterAvailableViewsCore(C)
C.Add(New AdvancedGridViewInfoRegistrator)
End Sub
Protected Overrides Function CreateDefaultView() As DevExpress.XtraGrid.Views.Base.BaseView
Return CreateView("AdvancedGridView")
End Function
Public Sub SwitchMainView(ByVal NewView As AdvancedGridView)
MainView = NewView
End Sub
End Class
<Obfuscation(Feature:="Apply to member * when method: virtualization", Exclude:=False)> _
Public Class AdvancedGridViewInfoRegistrator
Inherits DevExpress.XtraGrid.Registrator.AdvBandedGridInfoRegistrator
Public Overrides ReadOnly Property ViewName() As String
Get
Return "AdvancedGridView"
End Get
End Property
Public Overrides Function CreateView(ByVal Grid As DevExpress.XtraGrid.GridControl) As DevExpress.XtraGrid.Views.Base.BaseView
Return New AdvancedGridView(Grid)
End Function
End Class
<Obfuscation(Feature:="Apply to member * when method: virtualization", Exclude:=False)> _
Public Class AdvancedGridView
Inherits DevExpress.XtraGrid.Views.BandedGrid.AdvBandedGridView
\'!!!Public UpdatedRowState As System.Data.DataRowState
Public ReadOnly Property T() As AdvancedDataTable
Get
If TypeOf Grid.DataSource Is AdvancedDataSet Then
T = CType(Grid.DataSource, AdvancedDataSet).T(Name)
ElseIf TypeOf Grid.DataSource Is AdvancedDataTable Then
T = CType(Grid.DataSource, AdvancedDataTable)
End If
End Get
End Property
Public Sub New()
MyClass.New(Nothing)
Init_()
End Sub
Public Sub New(ByVal Grid As DevExpress.XtraGrid.GridControl)
MyBase.New(Grid)
Init_()
End Sub
Public Sub New(ByVal Grid As AdvancedGrid)
MyBase.New(Grid)
Init_()
End Sub
Function OpenMasterTable(ByVal SQLTextOrCmd As Object) As AdvancedDataTable
With Grid()
.DataSource = Nothing
.RefreshDataSource()
.DataSource = SharedCon.CreateDataSet()
OpenMasterTable = .ADS.OpenTable(SQLTextOrCmd, , Name)
.DataMember = Name
End With
End Function
Function OpenDetailTable(ByVal SQLTextOrCmd As Object, ByVal DetailForeignKeyName As String, Optional ByVal MasterPrimaryKeyName As String = "Id") As AdvancedDataTable
With Grid.ADS
OpenDetailTable = .OpenTable(SQLTextOrCmd, , Name)
End With
Dim LevelName2 = LevelNode.Parent.LevelTemplate.Name
Dim C1 = Grid.ADS.Tables(LevelName2).Columns(MasterPrimaryKeyName)
Dim C2 = Grid.ADS.Tables(Name).Columns(DetailForeignKeyName)
Grid.ADS.Relations.Add(LevelName, C1, C2)
End Function
\'PEVerify error!
\'Function OpenDetailTable2(ByVal SQLTextOrCmd As Object, ByVal DetailForeignKeyName As String, Optional ByVal MasterPrimaryKeyName As String = "Id") As AdvancedDataTable
\' With Grid.DS
\' OpenDetailTable2 = .OpenTable(SQLTextOrCmd, , Name)
\' .Relations.Add(LevelName, .Tables(LevelNode.Parent.LevelTemplate.Name).Columns(MasterPrimaryKeyName), .Tables(Name).Columns(DetailForeignKeyName))
\' End With
\'End Function
Private Sub Init_()
If Not DesignMode Then
OptionsSelection.MultiSelect = True
OptionsDetail.AllowExpandEmptyDetails = True
With OptionsView
.EnableAppearanceEvenRow = True
.EnableAppearanceOddRow = True
End With
End If
End Sub
Protected Overrides ReadOnly Property ViewName() As String
Get
Return "AdvancedGridView"
End Get
End Property
Public ReadOnly Property Grid() As AdvancedGrid
Get
Grid = CType(GridControl, AdvancedGrid)
End Get
End Property
Private Sub AdvancedGridView_RowUpdated(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowObjectEventArgs) Handles MyBase.RowUpdated
\'!!!UpdatedRowState = e.Row.row.RowState
Grid.SaveData()
End Sub
\'Private Function EnsureAtLeastFocusedRowIsSelected(ByVal V As DevExpress.XtraGrid.Views.BandedGrid.AdvBandedGridView)
Friend Sub EnsureAtLeastOneFocusedRowIsSelected()
If SelectedRowsCount = 0 Then
SelectRow(FocusedRowHandle)
End If
End Sub
Function GetFocusedRowEx() As Object \'DataRow or List item; similar to the GetFocusedRow
If RowCount > 0 Then
EnsureAtLeastOneFocusedRowIsSelected()
GetFocusedRowEx = GetRow(GetSelectedRows()(0))
End If
End Function
Function GetFocusedRowId() As Long
If RowCount > 0 Then
GetFocusedRowId = CLng(CType(GetFocusedRowEx(), DataRowView).Item("Id"))
End If
End Function
Function GetRowHandleById(ByVal Id As Long) As Integer
Dim Row As DataRow
For I As Integer = 0 To RowCount - 1
Row = CType(GetRow(I), DataRow)
If Not IsNothing(Row) Then
If CLng(Row.Item("Id")) = Id Then
GetRowHandleById = I
Exit For
End If
End If
Next
End Function
Sub FocusRowById(ByVal Id As Long)
FocusedRowHandle = GetRowHandleById(Id)
End Sub
Function GetSelectedRowsTable() As DataTable
EnsureAtLeastOneFocusedRowIsSelected()
\'GetSelectedRowsTable = New DataTable(Name & "_SelectedRows")
\'For Each C As DataColumn In T.Columns
\' GetSelectedRowsTable.Columns.Add(C.ColumnName, C.DataType)
\'Next
GetSelectedRowsTable = T.Clone()
For Each RowHandle As Integer In GetSelectedRows()
Dim R As DataRow = CType(GetRow(RowHandle), DataRowView).Row
Dim NewR = GetSelectedRowsTable.Rows.Add()
For I As Integer = 0 To T.Columns.Count - 1
NewR.Item(I) = R.Item(I)
Next
Next
End Function
Sub FillRow(ByVal ForId As Long)
Dim PV As AdvancedGridView
If IsNothing(SourceView) Then \'If it is already a root or pattern view then use it
PV = Me \'This view
Else
PV = CType(SourceView, AdvancedGridView) \'Pattern view which is a design time template
End If
Dim SavedCmd As System.Data.Common.DbCommand = CType(PV.T.Adapter.SelectCommand, System.Data.Common.DbCommand) \' Save the command
\'Reload a single row
PV.T.Adapter.SelectCommand = PV.T.Con.CreateCommand("select * from (" & PV.T.Adapter.SelectCommand.CommandText & ") LoadNewRowTable where Id=" & ForId)
CType(PV.T.Adapter, System.Data.SqlClient.SqlDataAdapter).Fill(PV.T)
PV.T.Adapter.SelectCommand = SavedCmd \' restore old command
FocusRowById(ForId)
End Sub
Function FindColumnByFieldName(ByVal FieldName As String) As DevExpress.XtraGrid.Columns.GridColumn
For Each C As DevExpress.XtraGrid.Columns.GridColumn In Columns
If C.FieldName = FieldName Then
FindColumnByFieldName = C
Exit Function
End If
Next
End Function
Public Function SpecifyLookupEdit(ByVal ForFieldName As String, ByVal DisplayMember As String, Optional ByVal ValueMember As String = "Id", Optional ByVal TableName As String = "") As DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit
If TableName = "" Then
TableName = ForFieldName.Substring(0, Len(ForFieldName) - 2)
End If
SpecifyLookupEdit = CType(Grid.RepositoryItems.Add("LookUpEdit"), DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit)
SpecifyLookupEdit.Name = ForFieldName & "Lookup"
AdvancedLookupEdit.FillLookupEdit(Grid.ADS.Con, SpecifyLookupEdit, DisplayMember, ValueMember, TableName)
FindColumnByFieldName(ForFieldName).ColumnEdit = SpecifyLookupEdit
End Function
Public Function SpecifyLookupEdit(ByVal ForFieldName As String, ByVal EnumType As Type) As DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit
SpecifyLookupEdit = CType(Grid.RepositoryItems.Add("LookUpEdit"), DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit)
SpecifyLookupEdit.Name = ForFieldName & "Lookup"
AdvancedLookupEdit.FillLookupEdit(SpecifyLookupEdit, EnumType)
FindColumnByFieldName(ForFieldName).ColumnEdit = SpecifyLookupEdit
End Function
Public Function SpecifyComboBox(ByVal ForFieldName As String, ByVal Items As Object()) As DevExpress.XtraEditors.Repository.RepositoryItemComboBox
SpecifyComboBox = New Repository.RepositoryItemComboBox
Grid.RepositoryItems.Add(SpecifyComboBox)
SpecifyComboBox.Name = ForFieldName & "ComboBox"
SpecifyComboBox.Items.AddRange(Items)
AdvancedLookupEdit.SetDefaultProperties(SpecifyComboBox)
SpecifyComboBox.PopupFormWidth = 200
FindColumnByFieldName(ForFieldName).ColumnEdit = SpecifyComboBox
End Function
\'Fills a combobox in a detail view, SQLText shall have a @MasterId formal parameter replaced within MasterId
Function SpecifyRelatedLookupEdit(ByVal MasterId As Long, ByVal ForFieldName As String, _
ByVal DisplayMember As String, Optional ByVal ValueMember As String = "Id", _
Optional ByVal SQLText As String = "") As DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit
\' MasterId of a master record substituted instead of the @MasterId in the SpecifyLookupEdit SQLText
If MasterId <> 0 Then
SpecifyLookupEdit(ForFieldName, DisplayMember, ValueMember, _
"(" & Replace(SQLText, "@MasterId", MasterId.ToString) & ") " & CreateTempName())
End If
\'Static MasterId As Long = 0
\'If NewMasterId <> MasterId Then
\' MasterId = NewMasterId
\' SpecifyLookupEdit(ForFieldName, DisplayMember, ValueMember, _
\' "(" & Replace(SQLText, "@MasterId", MasterId) & ") " & CreateTempName())
\'End If
End Function
End Class
<Obfuscation(Feature:="Apply to member * when method: virtualization", Exclude:=False)> _
Public Class AdvancedLookupEdit
Inherits DevExpress.XtraEditors.LookUpEdit
Sub Specify(ByVal TableName As String, Optional ByVal DisplayMember As String = "Name", Optional ByVal ValueMember As String = "Id")
FillLookupEdit(SharedCon, Me.Properties, DisplayMember, ValueMember, TableName)
End Sub
Sub Specify(ByVal EnumType As Type)
FillLookupEdit(Properties, EnumType)
End Sub
Shared Sub FillLookupEdit(ByVal Con As AdvancedConnection, ByVal RILE As DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit, ByVal DisplayMember As String, Optional ByVal ValueMember As String = "Id", Optional ByVal TableName As String = "")
With RILE
RILE.ValueMember = ValueMember
RILE.DisplayMember = DisplayMember
RILE.DataSource = Con.OpenTable("select " & ValueMember & ", " & DisplayMember & " from " & TableName & " order by " & DisplayMember)
End With
End Sub
Public Shared Function FillLookupEdit(ByVal RILE As DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit, ByVal EnumType As Type) As DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit
With RILE
.ValueMember = "Id"
.DisplayMember = "Name"
.DataSource = Enum2BindableArray(EnumType)
End With
End Function
Public Shared Sub SetDefaultProperties(ByVal RI As DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit)
With RI
.AllowNullInput = DevExpress.Utils.DefaultBoolean.True
.DropDownRows = 20
End With
End Sub
Public Shared Sub SetDefaultProperties(ByVal RI As DevExpress.XtraEditors.Repository.RepositoryItemComboBox)
With RI
.AllowNullInput = DevExpress.Utils.DefaultBoolean.True
.DropDownRows = 20
End With
End Sub
Public Sub New()
SetDefaultProperties(Properties)
Properties.PopupFormWidth = 300
End Sub
End Class
<Obfuscation(Feature:="Apply to member * when method: virtualization", Exclude:=False)> _
Public Class AdvancedReport
Public LR As New LocalReport
Public RDS As Microsoft.Reporting.WinForms.ReportDataSource
Public Parameters As ReportParameter()
Public Form As AdvancedReportForm
Public Sub New(ByVal RDLCFileName As String, ByVal T As Aulix.Common7.Data.AdvancedDataTable, ByVal ReportParameters As ReportParameter())
With LR
If Not IO.File.Exists(RDLCFileName) Then
RDLCFileName = IO.Path.Combine(IO.Directory.GetParent(RDLCFileName).Parent.FullName, IO.Path.GetFileName(RDLCFileName))
End If
.ReportPath = RDLCFileName \'.ReportEmbeddedResource = RDLCName
RDS = New Microsoft.Reporting.WinForms.ReportDataSource("RDS", T)
.DataSources.Add(RDS)
If Not IsNothing(ReportParameters) Then
Me.Parameters = ReportParameters
.SetParameters(ReportParameters)
End If
End With
End Sub
Public Sub New(ByVal RDLCFileName As String, ByVal T As Aulix.Common7.Data.AdvancedDataTable)
MyClass.New(RDLCFileName, T, Nothing)
End Sub
Public Sub InitAnotherLocalReport(ByVal ALR As LocalReport)
ALR.ReportPath = LR.ReportPath
ALR.DataSources.Add(RDS)
If Not IsNothing(Parameters) Then
ALR.SetParameters(Parameters)
End If
End Sub
Public Sub SaveToPDF(ByVal PDFFileName As String)
Dim mimeType, encoding, filenameExtension, streamids() As String
Dim warnings As Microsoft.Reporting.WinForms.Warning()
Dim ReportResult() As Byte = LR.Render("PDF", Nothing, mimeType, encoding, filenameExtension, streamids, warnings)
Using FS As New IO.FileStream(PDFFileName, IO.FileMode.Create)
FS.Write(ReportResult, 0, ReportResult.Length)
End Using
End Sub
Public Function OpenForm() As AdvancedReportForm
Form = New AdvancedReportForm
With Form.RV
InitAnotherLocalReport(.LocalReport)
.RefreshReport()
End With
Form.Text = Form.RV.LocalReport.ReportPath
OpenForm = Form
Form.ShowDialog() \'Form.Visible = True
End Function
End Class
<Obfuscation(Feature:="Apply to member * when method: virtualization", Exclude:=False)> _
Public Module Declarations
Sub SetDERILocale(ByVal DERI As DevExpress.XtraEditors.Repository.RepositoryItemDateEdit, Optional ByVal C As System.Globalization.CultureInfo = Nothing)
If IsNothing(C) Then
C = System.Threading.Thread.CurrentThread.CurrentCulture
End If
DERI.Mask.Culture = C
DERI.Mask.UseMaskAsDisplayFormat = True
End Sub
Sub FillComboBoxFromEnum(ByVal CB As DevExpress.XtraEditors.ComboBoxEdit, ByVal E As [Enum])
Dim Names As System.Array = E.GetNames(E.GetType)
Dim Values As System.Array = E.GetValues(E.GetType)
For I As Integer = 0 To Names.Length - 1
CB.Properties.Items.Add(Names.GetValue(I).ToString)
Next
End Sub
Sub RunMainForm(ByVal AppGUID As String, ByVal MainForm As System.Windows.Forms.Form)
Dim M As New System.Threading.Mutex(False, "Global\\" & AppGUID)
If (Not M.WaitOne(0, False)) Then
MsgBox(Messages.GetMessage("AppIsAlreadyRunning"))
Exit Sub
End If
Try
System.Windows.Forms.Application.Run(MainForm)
GC.Collect()
Catch ex As System.Exception
MsgBox(ex.ToString)
End Try
If Not M Is Nothing Then
M.Close()
CType(M, IDisposable).Dispose()
End If
End Sub
End Module