Files
AVISO/Aviso/frmWarenorte.vb

326 lines
11 KiB
VB.net

Imports VERAG_PROG_ALLGEMEIN
Public Class frmWarenorte
Dim warenort As New cWarenorte
Dim writepermission As Boolean
Sub New(writepermission As Boolean)
InitializeComponent()
Me.writepermission = writepermission
End Sub
Private Sub Warenorte_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If Not writepermission Then
btnSave.Enabled = False
btnDelete.Enabled = False
btnAdd.Enabled = False
UsrcntlPDFScanList1.cntxt.Enabled = False
UsrcntlPDFScanList1.picAdd.Enabled = False
For Each c As Control In mainPanel.Controls
If TypeOf c Is MyTextBox Then
Dim mytxtb As MyTextBox = c
mytxtb.ReadOnly = True
ElseIf TypeOf c Is TextBox Then
Dim txtb As TextBox = c
txtb.ReadOnly = True
ElseIf TypeOf c Is CheckBox Then
Dim cbx As CheckBox = c
cbx.Enabled = False
ElseIf TypeOf c Is MyComboBox Then
Dim mycbx As MyComboBox = c
mycbx.Enabled = False
ElseIf TypeOf c Is GroupBox Then
Dim gb As GroupBox = c
gb.Enabled = False
End If
Next
End If
initDGVWarenort()
cbxGrenzstelle.fillWithSQL("SELECT [grz_Grenzstelle],[grz_BezeichnungCBO] FROM tblGrenzstelle where grz_Aktiv=1 order by grz_Reihenfolge, grz_Grenzstelle", False, "AVISO", True)
cbxGrenzstelle.changeItem("")
cbxFirma.fillWithSQL("SELECT [Firma_id],[Firma_Bez] FROM [tblFirma] WHERE ISNULL(Firma_Warenort,0) = 1 ", False, "FMZOLL", True)
cbxFirmaChange.Items.AddRange(cbxFirma.Items.Cast(Of VERAG_PROG_ALLGEMEIN.MyListItem).ToArray())
End Sub
Private Sub initDGVWarenort(Optional firma As String = "")
lblWarning.Text = ""
Dim SQLString As String = "SELECT [wo_id], [wo_warenort] ,[wo_bezeichnung], [wo_aktiv], [wo_firma] FROM [tblWarenorte]"
Dim SQLWHere = ""
If firma <> "" Then
SQLWHere = " WHERE wo_firma = '" & firma & "'"
End If
dgvWarenorteNew.SET_SQL(SQLString & SQLWHere, "AVISO", ,)
dgvWarenorteNew.LOAD()
If dgvWarenorteNew.Columns.Count < 1 Then Exit Sub
With dgvWarenorteNew
If .RowCount = 0 Then Me.Cursor = Cursors.Default : Exit Sub
.MultiSelect = False
.RowHeadersVisible = False
.ReadOnly = True
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.Columns("wo_id").Visible = False
.Columns("wo_warenort").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.Columns("wo_warenort").HeaderText = "Warenort"
.Columns("wo_bezeichnung").Visible = False
.Columns("wo_aktiv").Visible = False
'.Columns("wo_firma").Visible = False
.Columns("wo_firma").HeaderText = "Firma"
.Columns("wo_firma").Width = 150
End With
For Each row As DataGridViewRow In dgvWarenorteNew.Rows
If row.Cells("wo_firma").Value IsNot DBNull.Value AndAlso row.Cells("wo_firma").Value <> "" Then
If CInt(row.Cells("wo_firma").Value) > 0 Then
Dim tmpFirma = New VERAG_PROG_ALLGEMEIN.cFirmen(row.Cells("wo_firma").Value)
row.Cells("wo_firma").Value = tmpFirma.Firma_Bez.ToString
End If
End If
If Not IsDBNull(row.Cells("wo_aktiv").Value) Then
If Not row.Cells("wo_aktiv").Value Then
row.DefaultCellStyle.BackColor = Color.IndianRed
End If
End If
Next
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
If checkIfFirmaIsFilled(True) = False Then Exit Sub
Dim input = InputBox("Bitte geben Sie die Bezeichnung des neuen Warenorts ein:", "Warenort anlegen")
If input <> "" Then
If checkNameIsValid(input) Then
Dim WarenortNew As New cWarenorte(input, cbxFirma._value)
WarenortNew.wo_cluster = ""
WarenortNew.wo_aktiv = True
WarenortNew.wo_bezeichnung = ""
WarenortNew.wo_grenzstelle = DBNull.Value
WarenortNew.wo_knnr = ""
WarenortNew.wo_ort = ""
WarenortNew.wo_reihenfolge = "-1"
WarenortNew.wo_strasse = ""
If WarenortNew.SAVE() Then
initDGVWarenort(cbxFirma._value)
End If
Else
MsgBox("Es existiert bereits ein Warenort " & input & " für die Firma " & cbxFirma._value)
End If
Else
MsgBox("Keine Bezeichnung angegeben!")
End If
End Sub
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
If dgvWarenorteNew.SelectedRows.Count > 0 Then
Dim Warenort As New cWarenorte(dgvWarenorteNew.SelectedRows(0).Cells("wo_id").Value)
If vbYes = MsgBox("Möchten Sie diesen Warenort " & Warenort.wo_warenort & " in " & Warenort.wo_firma & " wirklich löschen?", vbYesNo) Then
Warenort.deleteWarenort(Warenort.wo_id)
initDGVWarenort(cbxFirma._value)
End If
End If
End Sub
Private Function checkNameIsValid(name As String) As Boolean
If dgvWarenorteNew.Rows.Count = 0 Then Return True
If checkIfFirmaIsFilled(False) = False Then Return False
For Each row As DataGridViewRow In dgvWarenorteNew.Rows
If Not IsDBNull(row.Cells("wo_warenort").Value) AndAlso Not IsDBNull(row.Cells("wo_firma").Value) Then
If row.Cells("wo_warenort").Value.ToLower = name.ToLower AndAlso row.Cells("wo_firma").Value = cbxFirma._value Then
Return False
End If
End If
Next
Return True
End Function
Private Sub dgvWarenorteNew_SelectionChanged(sender As Object, e As EventArgs) Handles dgvWarenorteNew.SelectionChanged
If dgvWarenorteNew.SelectedRows.Count < 1 Then
mainPanel.Enabled = False
If cbxFirma._value <> "" Then UsrcntlPDFScanList1.INIT(-1, "WARENORTE", New VERAG_PROG_ALLGEMEIN.cFirmen(cbxFirma._value).Firma_Bez.ToString)
Exit Sub
Else
mainPanel.Enabled = True
End If
Dim Warenort = New cWarenorte(dgvWarenorteNew.SelectedRows(0).Cells("wo_id").Value)
txtWarenort.Text = Warenort.wo_warenort
txtBezeichnung.Text = Warenort.wo_bezeichnung
cbxAktiv.Checked = Warenort.wo_aktiv
txtOrt.Text = Warenort.wo_ort
cbxGrenzstelle.changeItem(Warenort.wo_grenzstelle)
cbxFirmaChange.changeItem(Warenort.wo_firma)
txtCluster.Text = Warenort.wo_cluster
txtKennr.Text = Warenort.wo_knnr
txtReihenfolge.Text = Warenort.wo_reihenfolge
txtStrasse.Text = Warenort.wo_strasse
cxEX.Checked = IIf(IsDBNull(Warenort.wo_ex), False, Warenort.wo_ex)
cxIM.Checked = IIf(IsDBNull(Warenort.wo_im), False, Warenort.wo_im)
cxZE.Checked = IIf(IsDBNull(Warenort.wo_ze), False, Warenort.wo_ze)
cxZV.Checked = IIf(IsDBNull(Warenort.wo_zv), False, Warenort.wo_zv)
If checkIfFirmaIsFilled(False, False) = False Then
UsrcntlPDFScanList1.Enabled = False
UsrcntlPDFScanList1.INIT(-1, "WARENORTE", "")
Else
UsrcntlPDFScanList1.Enabled = True
If cbxFirma._value = "" Then
UsrcntlPDFScanList1.INIT(-1, "WARENORTE", New VERAG_PROG_ALLGEMEIN.cFirmen(Warenort.wo_firma).Firma_Bez.ToString)
End If
End If
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
checkIfFirmaIsFilled(False)
Dim WarenortNew As New cWarenorte(dgvWarenorteNew.SelectedRows(0).Cells("wo_id").Value)
If checkFields() = False Then Exit Sub
WarenortNew.wo_warenort = txtWarenort.Text
WarenortNew.wo_bezeichnung = txtBezeichnung.Text
WarenortNew.wo_aktiv = cbxAktiv.Checked
WarenortNew.wo_ort = txtOrt.Text
WarenortNew.wo_grenzstelle = IIf(cbxGrenzstelle._value = "", DBNull.Value, cbxGrenzstelle._value)
WarenortNew.wo_firma = cbxFirmaChange._value
WarenortNew.wo_cluster = txtCluster.Text
WarenortNew.wo_knnr = txtKennr.Text
WarenortNew.wo_reihenfolge = txtReihenfolge.Text
WarenortNew.wo_strasse = txtStrasse.Text
WarenortNew.wo_ex = cxEX.Checked
WarenortNew.wo_im = cxIM.Checked
WarenortNew.wo_ze = cxZE.Checked
WarenortNew.wo_zv = cxZV.Checked
WarenortNew.SAVE()
dgvWarenorteNew.GetOrder()
initDGVWarenort(cbxFirma._value)
dgvWarenorteNew.SetOrder()
End Sub
Private Sub cbxFirma_SelectedValueChanged(sender As Object, e As EventArgs) Handles cbxFirma.SelectedValueChanged
dgvWarenorteNew.GetOrder()
initDGVWarenort(cbxFirma._value)
dgvWarenorteNew.SetOrder()
End Sub
Private Function checkIfFirmaIsFilled(initialSave As Boolean, Optional setWarning As Boolean = True)
If cbxFirma._value = "" Then
If ((dgvWarenorteNew.SelectedRows(0).Cells("wo_firma").Value Is DBNull.Value Or dgvWarenorteNew.SelectedRows(0).Cells("wo_firma").Value Is Nothing Or dgvWarenorteNew.SelectedRows(0).Cells("wo_firma").Value = "") Or initialSave = True) Then 'And initialSave = False ???
If setWarning Then
lblWarning.Text = "Bitte Firma auswählen!"
Else
lblWarning.Text = ""
End If
Return False
End If
lblWarning.Text = ""
Return True
Else
lblWarning.Text = ""
Return True
End If
Return False
End Function
Private Function checkFields() As Boolean
If txtWarenort.TextLength > 50 Then
lblWarning.Text = "Warenort darf max 50 Zeichen besitzen!"
Return False
ElseIf txtBezeichnung.TextLength > 50 Then
lblWarning.Text = "Bezeichnung darf max 50 Zeichen besitzen!"
Return False
ElseIf txtStrasse.TextLength > 60 Then
lblWarning.Text = "Strasse darf max 60 Zeichen besitzen!"
Return False
ElseIf txtOrt.TextLength > 50 Then
lblWarning.Text = "Ort darf max 50 Zeichen besitzen!"
Return False
ElseIf txtKennr.TextLength > 20 Then
lblWarning.Text = "Kennnummer darf max 20 Zeichen besitzen!"
Return False
End If
lblWarning.Text = ""
Return True
End Function
End Class