kostenkalk.

This commit is contained in:
2025-03-10 15:25:41 +01:00
parent c785d1eb47
commit 55c7a2f8ec
7 changed files with 166 additions and 16 deletions

View File

@@ -808,5 +808,111 @@ Public Class usrCntlOfferte
End Function
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Cursor = Cursors.WaitCursor
Try
Dim Path = ""
If True Then
Dim sqlKostenkalk = " Select OffertenNr, isnull(LeistungsNr,'') as LeistungsNr,isnull(LeistungsBez,'' ) as LeistungsBez,isnull(Preis,'') as Preis,isnull([Geändert am],[Eingegeben am]) as Datum
FROM [VERAG].[dbo].[Offertenpositionen] where KundenNr = " & kdNr & " and OffertenNr in (38, 1) and LeistungsNr in (340, 324, 348, 440)
order by cast([Eingegeben am] as date) desc, LeistungsNr, Preis desc"
Dim dtKostenkalk As DataTable = (New SQL).loadDgvBySql(sqlKostenkalk, "FMZOLL")
If dtKostenkalk.Rows.Count <= 0 Then
MsgBox("keine Daten!")
Exit Sub
End If
Dim sPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal) & "\VERAG\SDL\tmp\"
If Not My.Computer.FileSystem.DirectoryExists(sPath) Then
My.Computer.FileSystem.CreateDirectory(sPath)
End If
Dim exclApp As Object 'as Application
Dim Datei As Object 'as WorkBook
Dim Blatt As Object 'Microsoft.Office.Interop.Excel.Worksheet 'As Object 'as Worksheet
exclApp = CreateObject("Excel.Application")
With exclApp
.Visible = False
Try
Path = sPath & "Kostenkalkulation " & kdNr & " .xlsx"
While System.IO.File.Exists(Path)
Path = sPath & "Kostenkalkulation " & kdNr & "_" & Now.ToString("ddMMyyyyHHmmss") & ".xlsx"
End While
My.Computer.FileSystem.WriteAllBytes(Path, My.Resources.Kostenkalkulation, False)
Catch ex As System.Exception
' VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
Me.Cursor = Cursors.Default
Exit Sub
End Try
Datei = .Workbooks.Open(Path) 'Anpassen
Blatt = Datei.Worksheets(1) 'Anpassen
Dim KD As New VERAG_PROG_ALLGEMEIN.cKunde(kdNr)
Dim ADR As New VERAG_PROG_ALLGEMEIN.cAdressen(kdNr)
Blatt.Range("B8").Value = ADR.Name_1
Blatt.Range("B9").Value = ADR.AdressenNr
Blatt.Range("H11").Value = "Tarif für " & Today().Year
Dim currentRow As Integer = 13
For Each row In dtKostenkalk.Rows
Blatt.Range("A" & currentRow).Value = row("LeistungsBez")
Blatt.Range("B" & currentRow).Value = row("Preis")
If IsDate(row("Datum")) Then
Select Case CDate(row("Datum")).Year
Case 2018 : Blatt.Range("D" & currentRow).Value = 0.3387
Case 2019 : Blatt.Range("D" & currentRow).Value = 0.3048
Case 2020 : Blatt.Range("D" & currentRow).Value = 0.2792
Case 2021 : Blatt.Range("D" & currentRow).Value = 0.2597
Case 2022 : Blatt.Range("D" & currentRow).Value = 0.2207
Case 2023 : Blatt.Range("D" & currentRow).Value = 0.0997
Case 2024 : Blatt.Range("D" & currentRow).Value = 0.0394
Case 2025 : Blatt.Range("D" & currentRow).Value = 0
Case Else
Blatt.Range("D" & currentRow).Value = ""
End Select
Else
Blatt.Range("D" & currentRow).Value = ""
End If
currentRow = currentRow + 1
Next
Datei.Save
If False Then
Blatt.PrintOutEx()
Else
'Process.Start(Path)
.Visible = True
End If
End With
End If
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
Me.Cursor = Cursors.Default
End Sub
End Class