Imports System.IO 'Imports DD_LIB_Standards' Imports System.Text Imports DevExpress.XtraGrid.Columns Imports DevExpress.XtraPrinting Imports Microsoft.Office.Interop.Outlook Public Class frmDoc_Links Private ENTITY_ID As Integer = 0 Private form_shown As Boolean = False Public Property Documents As New List(Of ClassDocGrid.clsWMDoc) Private Sub frmDoc_DocLinks_Load(sender As Object, e As EventArgs) Handles Me.Load Try Refresh_Grid_Data(Documents) Load_DocGrid_Layout() If USER_IS_ADMIN Then bsiSource.Visibility = DevExpress.XtraBars.BarItemVisibility.Always Else bsiSource.Visibility = DevExpress.XtraBars.BarItemVisibility.Never End If ' TODO: this does not work for the old form If Documents.Count = 0 Then Text = $"Document-Link for: NODOC-ID" ElseIf Documents.Count = 1 Then Text = $"Document-Links for: {Documents.First.DocPath}" Else Text = $"Document-Links for {Documents.Count} files" End If 'If ClassWindreamDocGrid.DT_RESULTFILES.Rows.Count = 1 Then ' Me.Text = $"Document-Links for file: {ClassWindreamDocGrid.DT_RESULTFILES.Rows(0).Item("DOC_PATH")}" 'Else ' Me.Text = $"Document-Links for file: NODOC-ID" 'End If bbtnitmdeletelink.Enabled = False Select Case CURRENT_FILE_RIGHT Case "RW" bbtnitmdeletelink.Enabled = True Case "RWA" bbtnitmdeletelink.Enabled = True End Select Catch ex As System.Exception ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error in frmDoc_DocLinks_Load", ex.Message, ex.StackTrace) End Try form_shown = True End Sub Private Function Get_Grid_Data(pDocuments As List(Of ClassDocGrid.clsWMDoc)) As DataTable Dim oTable As DataTable Dim oSql As String = "" If pDocuments.Count > 0 Then Dim oIds = String.Join(",", pDocuments.Select(Function(d) d.DocId).ToArray()) oSql = $"SELECT * FROM VWPMO_CUST_DOC_OBJECT_LINKS WHERE DocID IN ({oIds})" oTable = MYDB_ECM.GetDatatable(oSql) Else oSql = $"select * FROM VWPMO_CUST_DOC_OBJECT_LINKS WHERE DocID = {CURRENT_DOC_ID}" oTable = MYDB_ECM.GetDatatable(oSql) End If If oTable Is Nothing Then LOGGER.Error("Please check your link-object-relation: {0}", oSql) End If Return oTable End Function Sub Refresh_Grid_Data(pDocuments As List(Of ClassDocGrid.clsWMDoc)) Try Dim oTable = Get_Grid_Data(pDocuments) If Not IsNothing(oTable) Then BarStaticItemStatus.Caption = $"{oTable.Rows.Count} links for Document found!" grvwGrid.Columns.Clear() GridControlRecords.DataSource = oTable 'grvwGrid.Columns.Item("already linked").Fixed = True Try grvwGrid.Columns.Item("DocID").Visible = False grvwGrid.Columns.Item("RecordID").Visible = False 'grvwGrid.Columns.Item("FULL_FILENAME").Visible = False Try If grvwGrid.Columns.Item("VALUE") IsNot Nothing Then grvwGrid.Columns.Item("VALUE").Visible = False End If Catch ex1 As System.Exception LOGGER.Warn("Column VALUE not part of VWPMO_CUST_DOC_OBJECT_LINKS" & ex1.Message) End Try grvwGrid.OptionsView.ColumnAutoWidth = False grvwGrid.BestFitColumns() grvwGrid.Columns(0).Fixed = FixedStyle.Left Catch ex As System.Exception LOGGER.Error(ex) End Try GridControlRecords.RefreshDataSource() 'If oTable.Rows.Count > 10000 Then ' BarButtonItem2.Enabled = False 'Else ' BarButtonItem2.Enabled = True 'End If Else MsgBox($"Please check Your link-object-relation", MsgBoxStyle.Exclamation) End If Catch ex As System.Exception LOGGER.Error(ex) ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error in Sub Refresh_Grid_Data", ex.Message, ex.StackTrace) End Try End Sub Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles bbtnitmdeletelink.ItemClick Dim oSelectedRows As Integer() = grvwGrid.GetSelectedRows() If oSelectedRows.Count > 0 Then Dim result As MsgBoxResult Dim msg = String.Format("Wollen Sie die ausgewählten Links wirklich löschen?") Dim oCount As Integer = 0 If USER_LANGUAGE <> "de-DE" Then msg = String.Format("Do you really want to delete the selected links?") End If result = MessageBox.Show(msg, "Bestätigung/Commitment:", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If result = MsgBoxResult.Yes Then For Each rowhandle As Integer In oSelectedRows Try Dim oSelectedDocID = grvwGrid.GetRowCellValue(rowhandle, "DocID") Dim oSelectedRecordID = grvwGrid.GetRowCellValue(rowhandle, "RecordID") If IsNothing(oSelectedDocID) Then Continue For End If LOGGER.Debug($"RecordLink will be removed - Record: {oSelectedRecordID} - DocID: {oSelectedDocID} ") Try Dim oDEL = $"DELETE FROM TBPMO_DOC_RECORD_LINK WHERE Doc_ID = {oSelectedDocID} AND RECORD_ID = {oSelectedRecordID}" If MYDB_ECM.ExecuteNonQuery(oDEL) = True Then oCount += 1 ClassHelper.InsertEssential_Log(oSelectedDocID, "DOC-ID", $"RECORD LINK {oSelectedRecordID} REMOVED FROM DOC-SEARCH") End If Catch ex As System.Exception ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error in Removing DocRecord-Link", ex.Message, ex.StackTrace) End Try Catch ex As System.Exception ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error in Collecting DocRecord-Link", ex.Message, ex.StackTrace) End Try Next MsgBox($"Es wurden {oCount} Links erfolreich gelöscht!", MsgBoxStyle.Information) End If Refresh_Grid_Data(Documents) Else MsgBox("No links selected!", MsgBoxStyle.Information) End If End Sub Sub Save_DocGrid_Layout() If form_shown = False Then Exit Sub End If Try Dim XMLPath = Get_DocGrid_Layout_Filename() grvwGrid.SaveLayoutToXml(XMLPath) BarStaticItemStatus.Caption = "Grid-Layout saved - " + Now.ToShortTimeString Catch ex As System.Exception ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error in Save_DocGrid_Layout", ex.Message, ex.StackTrace) End Try End Sub Private Function Get_DocGrid_Layout_Filename() Dim Filename As String = String.Format("GridViewDocLinks-{0}-UserLayout.xml", CURRENT_ENTITY_ID) Return System.IO.Path.Combine(System.Windows.Forms.Application.UserAppDataPath(), Filename) End Function Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick Try Dim saveFileDialogDocSearchResult As New SaveFileDialog With { .Filter = "Excel File|*.xlsx", .Title = "Export to Excel:" } saveFileDialogDocSearchResult.ShowDialog() If saveFileDialogDocSearchResult.FileName <> "" Then Dim oOptions As New XlsxExportOptionsEx With { .ShowGridLines = True, .AllowSortingAndFiltering = DevExpress.Utils.DefaultBoolean.True, .ExportType = DevExpress.Export.ExportType.DataAware, .ExportMode = XlsxExportMode.SingleFile, .AllowFixedColumnHeaderPanel = DevExpress.Utils.DefaultBoolean.True } Cursor = Cursors.WaitCursor GridControlRecords.MainView.ExportToXlsx(saveFileDialogDocSearchResult.FileName, oOptions) Dim result As MsgBoxResult Dim msg = String.Format("Datei wurde erstellt! Wollen Sie diese nun öffnen?") If USER_LANGUAGE <> "de-DE" Then msg = String.Format("File was created. Do You want to open excel?") End If result = MessageBox.Show(msg, "Exporting result:", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If result = MsgBoxResult.Yes Then Process.Start(saveFileDialogDocSearchResult.FileName) End If End If Catch ex As System.Exception LOGGER.Error(ex) MsgBox("Unexpected Error in ExportExcel: " & ex.Message, MsgBoxStyle.Critical) End Try Cursor = Cursors.Default End Sub Private Sub frmDoc_Links_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged Try grvwGrid.OptionsView.ColumnAutoWidth = False grvwGrid.BestFitColumns() Catch ex As System.Exception LOGGER.Error(ex) End Try End Sub Private Sub OrdnerÖffnenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OrdnerÖffnenToolStripMenuItem.Click Dim oPAth = grvwGrid.GetFocusedRowCellValue(grvwGrid.Columns("FULL_FILENAME")) Dim oDocID = grvwGrid.GetFocusedRowCellValue(grvwGrid.Columns("DocID")) If Not IsNothing(oPAth) Then If Not IsNothing(oDocID) Then ClassHelper.Open_Folder(oPAth, oDocID) End If End If End Sub Private Sub BarButtonItem1_ItemClick_1(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick Save_DocGrid_Layout() End Sub Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem3.ItemClick Reset_View_layout() End Sub Sub Reset_View_layout() Me.Cursor = Cursors.WaitCursor Try Dim XMLPath = Get_DocGrid_Layout_Filename() If File.Exists(XMLPath) Then File.Delete(XMLPath) Refresh_Grid_Data(Documents) Else MsgBox("Resetting the layout was not successful - File not existing!", MsgBoxStyle.Information) End If Catch ex As System.Exception ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error", "Error in Reset_View_layout: ", ex.Message) End Try Me.Cursor = Cursors.Default End Sub Private Sub grvwGrid_ColumnPositionChanged(sender As Object, e As EventArgs) Handles grvwGrid.ColumnPositionChanged Save_DocGrid_Layout() End Sub Private Sub grvwGrid_ColumnWidthChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.ColumnEventArgs) Handles grvwGrid.ColumnWidthChanged Save_DocGrid_Layout() End Sub Private Sub grvwGrid_ColumnFilterChanged(sender As Object, e As EventArgs) Handles grvwGrid.ColumnFilterChanged Save_DocGrid_Layout() End Sub Private Sub grvwGrid_EndSorting(sender As Object, e As EventArgs) Handles grvwGrid.EndSorting Save_DocGrid_Layout() End Sub Sub Load_DocGrid_Layout() Try Dim XMLPath = Get_DocGrid_Layout_Filename() If File.Exists(XMLPath) Then grvwGrid.RestoreLayoutFromXml(XMLPath) grvwGrid.GuessAutoFilterRowValuesFromFilter() BarStaticItemStatus.Caption = "Grid-Layout loaded - " + Now.ToShortTimeString End If Catch ex As System.Exception ClassHelper.MSGBOX_Handler("ERROR", "Unexpected Error in Load_DocGrid_Layout", ex.Message, ex.StackTrace) End Try End Sub End Class