Urlaubsplaner Updatefunktion eingebaut.

This commit is contained in:
2023-01-25 16:59:23 +01:00
parent 514c470565
commit d9680713ee
5 changed files with 265 additions and 87 deletions

View File

@@ -1,4 +1,5 @@
Imports System.Reflection
Imports ClosedXML.Excel
Public Class frmUrlaubsplaner
Dim DP As New cDienstplan
@@ -334,7 +335,98 @@ Public Class frmUrlaubsplaner
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
cProgramFunctions.genExcelFromDT_NEW(saveToDt())
saveToDt()
Try
Dim dt1 As New DataTable()
Dim dt2 As New DataTable()
Dim halfOfYearWeek As Integer = 28
For Each column As DataGridViewColumn In dgvUrlaub.Columns
If column.ValueType Is Nothing Then
If column.Index < 2 Then
dt1.Columns.Add(column.HeaderText, System.Type.GetType("System.String"))
dt2.Columns.Add(column.HeaderText, System.Type.GetType("System.String"))
ElseIf column.Index < halfOfYearWeek Then
dt1.Columns.Add(column.HeaderText, System.Type.GetType("System.String"))
Else
dt2.Columns.Add(column.HeaderText, System.Type.GetType("System.String"))
End If
Else
If column.Index < 2 Then
dt1.Columns.Add(column.HeaderText, column.ValueType)
dt2.Columns.Add(column.HeaderText, column.ValueType)
ElseIf column.Index < halfOfYearWeek Then
dt1.Columns.Add(column.HeaderText, column.ValueType)
Else
dt2.Columns.Add(column.HeaderText, column.ValueType)
End If
End If
Next
For Each row As DataGridViewRow In dgvUrlaub.Rows
dt1.Rows.Add()
dt2.Rows.Add()
For Each cell As DataGridViewCell In row.Cells
If cell.Value Is Nothing Then
If cell.ColumnIndex < 2 Then
dt1.Rows(dt1.Rows.Count - 1)(cell.ColumnIndex) = ""
dt2.Rows(dt2.Rows.Count - 1)(cell.ColumnIndex) = ""
ElseIf cell.ColumnIndex < halfOfYearWeek Then
dt1.Rows(dt1.Rows.Count - 1)(cell.ColumnIndex) = ""
Else
dt2.Rows(dt2.Rows.Count - 1)(cell.ColumnIndex - (halfOfYearWeek - 2)) = ""
End If
Else
If cell.ColumnIndex < 2 Then
dt1.Rows(dt1.Rows.Count - 1)(cell.ColumnIndex) = cell.Value.ToString()
dt2.Rows(dt2.Rows.Count - 1)(cell.ColumnIndex) = cell.Value.ToString()
ElseIf cell.ColumnIndex < halfOfYearWeek Then
dt1.Rows(dt1.Rows.Count - 1)(cell.ColumnIndex) = cell.Value.ToString()
Else
dt2.Rows(dt2.Rows.Count - 1)(cell.ColumnIndex - (halfOfYearWeek - 2)) = cell.Value.ToString()
End If
End If
Next
Next
Dim sPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal) & "\VERAG\SDL\tmp\" ' My.Computer.FileSystem.GetTempFileName
If Not My.Computer.FileSystem.DirectoryExists(sPath) Then
My.Computer.FileSystem.CreateDirectory(sPath)
End If
Dim wb As New XLWorkbook
' Dim dt As DataTable = (dgv.DataSource)
' Dim dt As DataTable = TryCast(dgv., DataTable)
wb.Worksheets.Add(dt1, "URLAUB JH 1")
wb.Worksheets.Add(dt2, "URLAUB JH 2")
Dim filename As String = sPath & "Urlaubsplan_" & Now.ToString("ddMMyyyyHHmmss") & ".xlsx"
wb.SaveAs(filename)
Process.Start(filename)
Catch ex As Exception
MsgBox(ex.Message & ex.StackTrace)
End Try
End Sub
@@ -342,6 +434,7 @@ Public Class frmUrlaubsplaner
If loaded Then aktJahr = cboJahr._value : initDGV() :
End Sub
Private Function saveToDt() As DataTable
Dim dt As New DataTable()