Files
AVISO/Aviso/frmDigicust.vb
2023-11-24 15:35:59 +01:00

511 lines
19 KiB
VB.net

Imports VERAG_PROG_ALLGEMEIN
Public Class frmDigicust
Dim api As cDigicustAPI
Dim dig_sendung As New cDigicustSendungen
Dim ART As String = ""
Dim FilialenNr As Integer
Dim AbfertigungsNr As Integer
Dim JAHR As Integer = Now.ToString("yy")
Public isSTAMMREF As Boolean = False
Public STAMMREF As String = ""
Public CopyFromZA_Id As Integer = -1
Dim FIRMA_DY = VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
Dim ZOLL_SYSTEM = "DAKOSY"
Public ATT As List(Of String)
Dim AVISO As New cAviso
Dim zusatz As String
Dim cDy_ART As String = If(FIRMA_DY = "ATILLA", "T2", "T1")
Dim VermerkeDAL As New cVermerkeDAL
Dim openExisting As Boolean = False
Dim id As Integer = -1
Dim dgv As DataGridView = Nothing
Property BezugsNr As String = ""
Property SENDUNG As VERAG_PROG_ALLGEMEIN.cSendungen
Sub New(AVISO As VERAG_PROG_ALLGEMEIN.cAviso, SENDUNG As VERAG_PROG_ALLGEMEIN.cSendungen, JAHR As Integer, Optional _dgv As DataGridView = Nothing)
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
If _dgv IsNot Nothing Then Me.dgv = _dgv
Me.AVISO = AVISO
Me.SENDUNG = SENDUNG
Me.JAHR = JAHR
If SENDUNG IsNot Nothing Then
Me.FilialenNr = SENDUNG.FilialenNr
Me.AbfertigungsNr = SENDUNG.AbfertigungsNr
End If
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
End Sub
Sub New(_id As Integer, AVISO As VERAG_PROG_ALLGEMEIN.cAviso, SENDUNG As VERAG_PROG_ALLGEMEIN.cSendungen, JAHR As Integer)
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
openExisting = True
id = _id
Me.AVISO = AVISO
Me.SENDUNG = SENDUNG
Me.JAHR = JAHR
If SENDUNG IsNot Nothing Then
Me.FilialenNr = SENDUNG.FilialenNr
Me.AbfertigungsNr = SENDUNG.AbfertigungsNr
End If
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
If Not checkAttachment() Then
Exit Sub
End If
If Not checkMandatoryField() Then
Exit Sub
End If
Me.Cursor = Cursors.WaitCursor
Dim settings = New cDigicustSettings(cboStammreferenz._value)
lblInfo.Text = ""
With dig_sendung
.settingsId = settings.Id
.type = settings.type
.avisoId = AVISO.AvisoID
.reference = lblBezugsnummer.Text
.consignor_eori = usrCntl_consignor.txtEORI.Text
.consignor_name = usrCntl_consignor.kdFirma.Text
.consignor_address = usrCntl_consignor.txtStrasse.Text
.consignor_city_name = usrCntl_consignor.txtOrt.Text
.consignor_country_id = usrCntl_consignor.sbLand._value
.consignor_postcode = usrCntl_consignor.txtPlz.Text
.consignee_eori = UsrCntl_Consignee.txtEORI.Text
.consignee_name = UsrCntl_Consignee.kdFirma.Text
.consignee_address = UsrCntl_Consignee.txtStrasse.Text
.consignee_city_name = UsrCntl_Consignee.txtOrt.Text
.consignee_country_id = UsrCntl_Consignee.sbLand._value
.consignee_postcode = UsrCntl_Consignee.txtPlz.Text
.prepaper = txtVorpapier.Text
.prepaper_code = txtVorpapierT.Text
.licencePlate = txtLKWId.Text
.lkwCountryId = txtLWKLand.Text
.customsOfficeNr = sbBestimmungsZollstelle._value
'.SAVE()
End With
sendDigicustData(dig_sendung, api, settings, cbxAviso.Checked)
Me.Cursor = Cursors.Default
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
Me.Cursor = Cursors.Default
End Try
End Sub
Private Sub sendDigicustData(dig As cDigicustSendungen, api As cDigicustAPI, settings As cDigicustSettings, withAvisoData As Boolean)
Dim failreDesc As String
Dim authResp = api.authenticate("")
If authResp <> "200" Then
failreDesc = "Authentifizierung fehlgeschlagen - " & authResp & vbNewLine & "Vorgang abgebrochen!"
lblInfo.Text = failreDesc
Exit Sub
End If
If api.uploadingCase(dig, settings, dgvAnhaenge, withAvisoData, cbxAbsender.Checked, cbxEmpfänger.Checked) Then
If dig.digicustId Is Nothing Then
MsgBox("Anfrage wurde erfolgreich gesendet, aber vom Digicust-Server keine Antwort erhalten." & vbNewLine & "Bitte nochmal versuchen!")
Else
dig.SAVE()
Me.Close()
End If
End If
'If Not atez.setJson(atezData) Then MsgBox("Fehler beim Erstellen der Daten" & vbNewLine & "Vorgang abgebrochen!")
'If Not atez.setJsonPDF(atezData, dgvAnhaenge) Then MsgBox("Fehler beim Erstellen der PDF-Daten, kein Anhang ausgewählt!" & vbNewLine & "Vorgang abgebrochen!")
'Dim azetId = atez.SendRequestWithAuthHeader("application/json", failreDesc)
'If failreDesc <> "" Then
' If atezData.status = "Draft" Then
' MsgBox("Fehler beim Senden" & vbNewLine & failreDesc)
' atezData.fehlerbeschreibung = failreDesc
' atezData.SAVE()
' Exit Sub
' End If
' Dim result As MsgBoxResult = MsgBox("Fehler beim Senden" & vbNewLine & failreDesc & vbNewLine & "Soll NCTS als Entwurf gespeichert werden?", vbYesNoCancel)
' If result = vbYes Then
' atezData.status = "Draft"
' atezData.fehlerbeschreibung = failreDesc
' atezData.SAVE()
' End If
' lblInfo.Text = "Fehler in der API "
'Else
' atezData.status = "Sent"
' atezData.atezId = IIf(azetId IsNot Nothing, azetId, "")
' atezData.SAVE()
' Me.Close()
'End If
End Sub
Function getBezugsnr(ByRef BezugsNr)
Dim BezugsNrTmp = ""
BezugsNrTmp = SENDUNG.FilialenNr & "/" & SENDUNG.AbfertigungsNr
BezugsNr = BezugsNrTmp
zusatz = "A"
If dgv IsNot Nothing AndAlso dgv.Rows.Count > 0 Then
BezugsNr = BezugsNrTmp & "/" & zusatz
For Each r As DataGridViewRow In dgv.Rows
If r.Cells("reference").Value = BezugsNr Then
If zusatz.Length = 1 Then
zusatz = Chr(Asc(zusatz.ToString) + 1)
Else
zusatz = zusatz.Substring(0, 1) & Chr(Asc(zusatz.Substring(0, 2).ToString) + 1)
End If
If zusatz = "Z" Then zusatz = "AA"
End If
BezugsNr = BezugsNrTmp & "/" & zusatz
Next
End If
While DAKOSY_Worker.cDakosy_Zollanmeldungen.ExistsBezugsNr(BezugsNr) 'IsNot Nothing
BezugsNr = BezugsNrTmp & "/" & zusatz
If zusatz.Length = 1 Then
zusatz = Chr(Asc(zusatz.ToString) + 1)
Else
zusatz = zusatz.Substring(0, 1) & Chr(Asc(zusatz.Substring(0, 2).ToString) + 1)
End If
If zusatz = "Z" Then zusatz = "AA"
End While
lblBezugsnummer.Text = BezugsNr
Return BezugsNr
End Function
Private Sub frmATEZNCTS_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Select Case FIRMA_DY
Case "VERAG" : txtDyMandant.Text = "VERG"
txtDyNiederlassung.Text = VERAG_PROG_ALLGEMEIN.cAllgemein.NIEDERLASSUNG
Case "ATILLA" : txtDyMandant.Text = "ATIL" : txtDyNiederlassung.Text = "SUW"
Case "UNISPED" : txtDyMandant.Text = "UNAT" : txtDyNiederlassung.Text = "ATSPED"
Case "IMEX" : txtDyMandant.Text = "IMEX" : txtDyNiederlassung.Text = "IME"
Case "AMBAR" : txtDyMandant.Text = "ATIL" : txtDyNiederlassung.Text = "AMBWO"
End Select
initAttachment()
initSeachboxes()
cboStammreferenz.fillWithSQL("SELECT [id],[description] FROM [tblDigicust_Settings] WHERE companyGroup ='" & FIRMA_DY & "' and valid =1", False, "FMZOLL", True)
cboStammreferenz.changeItem("")
If openExisting Then
' If id > 0 Then
' atez_data = New cATEZ_NCTS_DATA(id)
' If atez_data.atezId <> "" Then
' lblInfo.Text = "Atez-ID " & atez_data.atezId
' Else
' lblInfo.Text = "Status: " & atez_data.status
' End If
' lblBezugsnummer.Text = atez_data.VERAG_LRN
' cboStammreferenz.fillWithSQL("SELECT [dySr_Stammreferenz],[dySr_Bezeichnung] FROM [tblDakosy_Stammreferenzen] WHERE dySr_Land='DE' AND dySr_Verfahren='NCTS' and dySr_dy_Mandant='" & txtDyMandant.Text & "' and dySr_dy_Niederlassung IN ('','" & txtDyNiederlassung.Text & "') and dySr_visible=1", False, "FMZOLL", True)
' cboStammreferenz.changeItem(atez_data.DAKOSY_TemplateCode)
' txtLKWId.Text = atez_data.LicensePlateContainerNo
' sbBestimmungsZollstelle.SET_VALUE(atez_data.DestinationCustomsOffice)
' sbAbgangZollstelle.SET_VALUE(atez_data.DepartureCustomsOffice)
' cbxTemperatur.Checked = IIf(atez_data.CoolingTemperature <> "", True, False)
' txtTransporttemp.Text = atez_data.CoolingTemperature
' txtDat.Text = IIf(atez_data.DatDeterminationLimit IsNot DBNull.Value, atez_data.DatDeterminationLimit, "")
' usrCntl_Carrier.kdFirma.Text = atez_data.Carrier_Name
' usrCntl_Carrier.txtStrasse.Text = atez_data.Carrier_Adress_Street
' usrCntl_Carrier.txtPlz.Text = atez_data.Carrier_Adress_Postcode
' usrCntl_Carrier.txtOrt.Text = atez_data.Carrier_Adress_City
' usrCntl_Carrier.sbLand._value = atez_data.Carrier_Adress_Country
' usrCntl_Carrier.txtEORI.Text = atez_data.Carrier_EORI
' setRoute()
' If atez_data.status = "Draft" Then
' Button1.Text = "An ATEZ senden -->"
' pnlHead.Enabled = True
' Button1.Enabled = True
' initAttachment()
' Else
' Button1.Text = "JSON"
' pnlHead.Enabled = False
' Button1.Enabled = True
' End If
' Else
' Button1.Enabled = False
' End If
Else
'lblAnh.Visible = True
getBezugsnr(BezugsNr)
If AVISO.LKW_Nr.Length > 10 Then
txtLKWId.Text = AVISO.LKW_Nr.Substring(0, 10)
Else
txtLKWId.Text = AVISO.LKW_Nr
End If
txtLWKLand.Text = AVISO.LKW_Nationalitaet
If If(SENDUNG.tblSnd_Vorpapier, "") <> "" Then
txtVorpapier.Text = SENDUNG.tblSnd_Vorpapier
txtVorpapierT.Text = cDy_ART
End If
If SENDUNG.tblSnd_EmpfaengerKdNr > -1 Then
UsrCntl_Consignee.kdFirma.initKdBox(Me)
UsrCntl_Consignee.kdFirma.KdNr = SENDUNG.tblSnd_EmpfaengerKdNr
End If
If SENDUNG.tblSnd_AbsenderKdNr > -1 Then
usrCntl_consignor.kdFirma.initKdBox(Me)
usrCntl_consignor.kdFirma.KdNr = SENDUNG.tblSnd_AbsenderKdNr
End If
End If
End Sub
Sub initAttachment()
Dim hSQL As String = " SELECT [anh_id],anh_Datum,[anh_Name],[anh_docId],
case WHEN [anh_size] > 0 Then ROUND([anh_size] / 1000000,2) End as anh_size,
CASE WHEN [anh_Art] = 'ATR-EUR1' then 'EUR1'
when [anh_Art] = 'Rechnung' then 'invoice'
when [anh_Art] = 'eFatura' then 'invoice'
when [anh_Art] = 'CMR' then 'waybill'
when [anh_Art] = 'Ausfuhr' then 'exportDeclaration'
when [anh_Art] = 'Vorpapier' then 'transitDeclaration'
when [anh_Art] = 'Packliste' then 'packingList'
when [anh_Art] = 'Auftrag' then 'UserInput'
when [anh_Art] = 'Dispoliste' then 'UserInput'
when [anh_Art] = 'Vorkasse' then 'UserInput'
when [anh_Art] = 'Überweisungsbeleg' then 'UserInput'
when [anh_Art] = 'Vollmacht' then 'UserInput'
when [anh_Art] = 'ATB' then 'UserInput'
when [anh_Art] = 'ATA' then 'UserInput'
when [anh_Art] = 'Sonstiges' then 'UserInput'
when [anh_Art] ='' then 'UserInput' End
[anh_Art],[anh_Typ] FROM [tblAvisoAnhaenge]
WHERE [anh_AvisoId]='" & AVISO.AvisoID & "' AND (anh_SendungsId is null OR anh_SendungsId <=0 OR anh_SendungsId=" & SENDUNG.tblSnd_SendungID & ")
Order BY [anh_Reihenfolge], anh_Datum desc, [anh_id]"
'AND isnull(anh_SendungsId,0) <= 0
Dim dt = VermerkeDAL.Anzeigen_Vermerke(hSQL)
Dim col As DataColumn
col = dt.Columns.Add("anh_selekt", GetType(Boolean))
col.SetOrdinal(0)
dgvAnhaenge.Columns.Clear()
dgvAnhaenge.DataSource = dt
If dgvAnhaenge.RowCount = 0 Then dgvAnhaenge.Columns.Clear() : Exit Sub
With dgvAnhaenge
.Enabled = True
.ReadOnly = False
.RowTemplate.MinimumHeight = 30
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
.Columns("anh_id").Visible = False 'VermerkID nicht anzeigenconMenuVermerke
.Columns("anh_docId").Visible = False 'AvisoID nicht anzeigen
.Columns("anh_selekt").MinimumWidth = 50
.Columns("anh_selekt").HeaderText = "ausgewählt"
.Columns("anh_selekt").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns("anh_Name").MinimumWidth = 150
.Columns("anh_Name").HeaderText = "Name"
.Columns("anh_Name").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.Columns("anh_Datum").MinimumWidth = 50
.Columns("anh_Datum").HeaderText = "Datum"
.Columns("anh_Datum").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns("anh_size").MinimumWidth = 50
.Columns("anh_size").HeaderText = "Größe in MB"
.Columns("anh_size").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns("anh_Art").MinimumWidth = 50
.Columns("anh_Art").HeaderText = "Art"
.Columns("anh_Art").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns("anh_Typ").Width = 60
.Columns("anh_Typ").HeaderText = "Typ"
.Columns("anh_Typ").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
For Each doc As DataGridViewRow In dgvAnhaenge.Rows
If Not IsDBNull(doc.Cells("anh_size").Value) AndAlso doc.Cells("anh_size").Value > 0 Then
Dim size = (doc.Cells("anh_size").Value)
If size < 1 Then
doc.DefaultCellStyle.BackColor = Color.LightGreen
ElseIf size > 1 AndAlso size < 5 Then
doc.DefaultCellStyle.BackColor = Color.LightYellow
Else
doc.DefaultCellStyle.BackColor = Color.IndianRed
End If
End If
Next
End Sub
Public Function checkAttachment() As Boolean
Dim selectedDocuments As Boolean = False
For Each Row In dgvAnhaenge.Rows
selectedDocuments = IIf(DBNull.Value Is Row.Cells("anh_selekt").Value, False, Row.Cells("anh_selekt").Value)
If selectedDocuments Then Exit For
Next
If Not selectedDocuments Then
lblInfo.Text = "kein Anhang selektiert"
Cursor = Cursors.Default
Return selectedDocuments
End If
Return selectedDocuments
End Function
Public Function checkMandatoryField() As Boolean
lblInfo.Text = ""
If cboStammreferenz._value = "" Then
lblInfo.Text = "Stammref. auswählen!"
cboStammreferenz.Focus()
Return False
End If
If txtLKWId.TextLength > 10 Then
lblInfo.Text = "LKW-Kennzeichen zu lang (max 10 Stellen)."
txtLKWId.Focus()
Return False
End If
If txtVorpapierT.TextLength > 2 Then
lblInfo.Text = "Vopapier-Code zu lang (max 2 Stellen)."
txtVorpapierT.Focus()
Return False
End If
If txtVorpapier.TextLength > 30 Then
lblInfo.Text = "Vopapier zu lang (max 30 Stellen)."
txtVorpapier.Focus()
Return False
End If
'TODO
Return True
End Function
Public Sub initSeachboxes()
sbBestimmungsZollstelle.initSearchBox(Me.FindForm, "[Code] ,[Code] as Nr,Description as Dienststelle,left(Code,2) as Land,[Description] +' (' +left(Code,2)+')' as display FROM [tbl_DY_ZollDE_C0141_Zollstellen]", {" [Code]", "Description"}, " (StartDate is null OR StartDate< GETDATE()) AND (EndDate is null OR EndDate> GETDATE()) ", " left(Code,2),[Description]", "Code", "display", "FMZOLL", , 400, 200, {"display", "Code"})
End Sub
'Private Sub dgvAnhaenge_CellLeave(sender As Object, e As DataGridViewCellEventArgs) Handles dgvAnhaenge.CellLeave
' Dim countAnh As Double = 0
' If dgvAnhaenge.RowCount > 0 Then
' If dgvAnhaenge.Columns(e.ColumnIndex).Name = "anh_selekt" Then
' If Not IsDBNull(dgvAnhaenge.CurrentRow.Cells("anh_selekt").Value) AndAlso dgvAnhaenge.CurrentRow.Cells("anh_selekt").Value = True Then
' countAnh += IIf(dgvAnhaenge.CurrentRow.Cells("anh_size").Value IsNot DBNull.Value, dgvAnhaenge.CurrentRow.Cells("anh_size").Value, 0)
' End If
' For Each Row As DataGridViewRow In dgvAnhaenge.Rows
' If Row.Cells("anh_selekt").Value IsNot DBNull.Value AndAlso Row.Cells("anh_selekt").Value = True AndAlso Row.Cells("anh_size").Value IsNot DBNull.Value Then
' countAnh += IIf(Row.Cells("anh_size").Value IsNot DBNull.Value, Row.Cells("anh_size").Value, 0)
' End If
' Next
' lblAnh.Text = "Anhang in MB: " & countAnh.ToString
' End If
' End If
'End Sub
End Class