Files
DISPO/UID/frmSearch.vb
2025-04-04 08:17:02 +02:00

160 lines
6.9 KiB
VB.net

Imports System.ComponentModel
Public Class frmSearch
Dim locZeilen As Integer
Dim Grid_aktiv As Boolean
Dim hSQL As String
Private UID As cOptionenDAL
' Public main As String
Public KD As cEntry = Nothing
Private Sub frmSearch_Load(sender As Object, e As EventArgs) Handles Me.Load
' If frmLogin.USRBER > 0 Then btnMitarb.Visible = False
' If frmLogin.USRBER > 5 Then btnNew.Enabled = False : btnDel.Enabled = False : btnChange.Enabled = False
UID = New cOptionenDAL
Grid_aktiv = True
Tabelle_anzeigen()
End Sub
Public Sub Tabelle_anzeigen()
Dim start As Long = (DateTime.Now - New DateTime(1970, 1, 1)).TotalMilliseconds
'lblMs.Image = My.Resources.sanduhr
'Paint wieder reaktivieren
locZeilen = -1
If Not Grid_aktiv Then Exit Sub
Dim top As String = "" ' "top 100"
'je nach Auswahl SQL anpassen
'je nach Auswahl SQL anpassen
hSQL = "SELECT " & top & " kd_id, kd_firma, (kd_str + ' ' + kd_strnr) as strasse, (kd_plz + ' - ' + kd_ort) as ort, kd_land,kd_firma, kd_str, kd_strnr, kd_land, kd_plz, kd_ort, (kd_anspr1_vn + ' ' + kd_anspr1_nn) as anspr,kd_isRefNr,kd_refNr FROM tblKunden "
Dim search As String = txtSuche.Text
Dim where As String = " WHERE kd_AVISOfirma='" & VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA & "'"
If txtSuche.Text <> "" Then
'where += " kd_firma LIKE '%" & search & "%'"
Dim arr() As String = Split(txtSuche.Text.Replace(" ", ","), ",")
Dim cnt As Integer = 1
If arr.Count() > 0 Then cnt = arr.Count
Dim or_txt As String = ""
For i As Integer = 0 To cnt - 1 Step 1
If arr(i) <> "" Then search = arr(i).Trim
' If i > 0 Then where += " AND "
where += " AND ( kd_firma LIKE '%" & search & "%' OR kd_str LIKE '%" & search & "%' OR kd_strnr LIKE '%" & search & "%' OR kd_plz LIKE '%" & search & "%' OR kd_ort LIKE '%" & search & "%' OR kd_land LIKE '%" & search & "%' OR kd_anspr1_vn LIKE '%" & search & "%' OR kd_anspr1_nn LIKE '%" & search & "%' OR kd_anspr2_vn LIKE '%" & search & "%' OR kd_anspr2_nn LIKE '%" & search & "%' OR kd_tel LIKE '%" & search & "%' OR kd_fax LIKE '%" & search & "%' OR kd_email LIKE '%" & search & "%' OR kd_homepage LIKE '%" & search & "%' ) "
Next
'where = " WHERE " & where
End If
' MsgBox(hSQL + where)
dgvUID.DataSource = UID.AnzeigeTabelle(hSQL + where)
'Tabelle Kommt/Geht bereinigen
If dgvUID.RowCount = 0 Then
dgvUID.DataSource = Nothing
Else
Spalten_festlegen()
' Eintraege_festlegen()
'AL: Sortierung nach Ausfahrt (Zeit)
dgvUID.Sort(dgvUID.Columns(3), ListSortDirection.Ascending)
End If
'Anzeige der Anzahl gewählter/aller Datensätze
If (dgvUID.RowCount = 100) Then
'lblAnzahl.Text = Format(dgvUID.RowCount, "#,##0") & " ausgewählt (Die Suche wurde auf 100 Ergebnisse beschränkt.)"
Else
' lblAnzahl.Text = Format(dgvUID.RowCount, "#,##0") & " ausgewählt"
End If
' lblAnzahl.Refresh()
Dim ende As Long = (DateTime.Now - New DateTime(1970, 1, 1)).TotalMilliseconds
' lblMs.Text = "Ladezeit: " & (ende - start) & " ms"
'lblMs.Image = Nothing
End Sub
Private Sub Spalten_festlegen()
With dgvUID
.RowTemplate.Height = 20
.RowTemplate.DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopLeft
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AllowUserToOrderColumns = False
.AllowUserToResizeColumns = True
.AllowUserToResizeRows = False
.RowTemplate.ReadOnly = True
.RowHeadersVisible = False
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.Columns(0).Visible = False
.Columns(1).Width = 365
.Columns(1).HeaderText = "Firma"
.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(2).Width = 250
.Columns(2).HeaderText = "Straße"
.Columns(3).Width = 250
.Columns(3).HeaderText = "Ort"
.Columns(4).Width = 200
.Columns(4).HeaderText = "Land"
For i As Integer = 5 To 13
' .Columns(i).Visible = False
Next
End With
End Sub
Private Sub dgvUID_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvUID.CellDoubleClick
Button3.PerformClick()
End Sub
Private Sub SearchChanged(sender As Object, e As EventArgs) Handles txtSuche.TextChanged
Tabelle_anzeigen()
End Sub
Function nullStr(o) As String
Try
If o IsNot DBNull.Value Then Return CStr(o)
Catch ex As Exception : End Try
Return ""
End Function
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
With dgvUID
Dim refNr As String = ""
If Not .CurrentRow.Cells(13).Value Is DBNull.Value Then refNr = .CurrentRow.Cells(13).Value
' If main = "frmAuftragNEU" Then
KD = New cEntry(.CurrentRow.Cells(0).Value)
Me.DialogResult = Windows.Forms.DialogResult.OK
' frmAuftragNEU.getDataFromSearch( nullStr(.CurrentRow.Cells(5).Value), nullStr(.CurrentRow.Cells(6).Value), nullStr(.CurrentRow.Cells(7).Value), nullStr(.CurrentRow.Cells(8).Value), nullStr(.CurrentRow.Cells(9).Value), nullStr(.CurrentRow.Cells(10).Value), "", "", nullStr(.CurrentRow.Cells(11).Value), nullStr(.CurrentRow.Cells(12).Value), refNr, nullStr(.CurrentRow.Cells(0).Value))
' ElseIf main = "frmCMR" Then
' frmCMR.getDataFromSearch(nullStr(.CurrentRow.Cells(5).Value), nullStr(.CurrentRow.Cells(6).Value), nullStr(.CurrentRow.Cells(7).Value), nullStr(.CurrentRow.Cells(8).Value), nullStr(.CurrentRow.Cells(9).Value), nullStr(.CurrentRow.Cells(10).Value), "", "", nullStr(.CurrentRow.Cells(11).Value), nullStr(.CurrentRow.Cells(12).Value), refNr, nullStr(.CurrentRow.Cells(0).Value))
' End If
Me.Close()
End With
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
frmDetails.rowId = -1 : frmDetails.mainForm = "frmSearch" : frmDetails.Show()
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
frmDetails.rowId = dgvUID.CurrentRow.Cells(0).Value : frmDetails.mainForm = "frmSearch" : frmDetails.Show()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
txtSuche.Text = ""
End Sub
Private Sub frmSearch_Shown(sender As Object, e As EventArgs) Handles Me.Shown
txtSuche.Focus()
End Sub
End Class