Imports System.Security.Cryptography Imports Microsoft.Data.SqlClient Imports System.Data.DataTable Public Class Form6 'setari pentru server Dim DataString As String = My.Settings.subnet Dim surce As String = My.Settings.serverName Dim catalog As String = My.Settings.serverdatabase Dim user As String = My.Settings.serverUser Dim pass As String = My.Settings.serverUserpass Dim timeout As String = My.Settings.timeout Dim encrypt As String = My.Settings.encrypt Dim trust As String = My.Settings.cert Dim reason As String = My.Settings.reason Dim subnet As String = My.Settings.subnet Dim rowIdval As String ' gasirea randului din datagrid Private Sub updateTable() ' updateul tabelului din datagrid care se face dupa fiecare conexiune la server Dim con As New SqlConnection("Data Source=" & surce & "; Initial Catalog=" & catalog & "; User ID=" & user & "; Password=" & pass & "; Connect Timeout=" & timeout & "; Encrypt=" & encrypt & "; TrustServerCertificate=" & trust & "; ApplicationIntent=" & reason & "; MultiSubnetFailover=" & subnet & "") con.Open() Dim command As New SqlCommand("select top 14 * from dbo.pregatit order by id desc", con) Dim sda As New SqlDataAdapter(command) Dim dt As New DataTable sda.Fill(dt) DataGridView1.DataSource = dt con.Close() End Sub Private Sub UserForm2_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' text box1 incarcare valoare, set text box 2 pentru scan TextBox1.Text = variable.userp updateTable() TextBox2.Focus() End Sub Private Sub TextBox1_TextChangeed(sender As Object, e As EventArgs) Handles TextBox1.TextChanged ' validare text box 1 cu OQ If TextBox1.Text.Length < 4 Then ElseIf TextBox1.Text.Length = 4 Then Dim val As String val = TextBox1.Text If InStr(1, val, "OP") > 0 Then TextBox2.Focus() Else MsgBox("Introdu cod Operator") TextBox1.Focus() End If Else End If End Sub Private Sub TextBox2_TextChangeed(sender As Object, e As EventArgs) Handles TextBox2.TextChanged ' validare CP text box 2 If TextBox2.Text.Length < 10 Then ElseIf TextBox2.Text.Length = 10 Then Dim val As String val = TextBox2.Text If InStr(1, val, "CP") > 0 Then TextBox3.Focus() Else MsgBox("Introdu CP Corect") TextBox2.Clear() TextBox2.Focus() End If Else End If End Sub Private Sub TextBox3_TextChangeed(sender As Object, e As EventArgs) Handles TextBox3.TextChanged ' validare oc text box 3 If TextBox3.Text.Length < 4 Then ElseIf TextBox3.Text.Length = 4 Then Dim val As String val = TextBox3.Text If InStr(1, val, "00") > 0 Then TextBox4.Focus() ElseIf InStr(1, val, "ct") > 0 Then TextBox4.Focus() ElseIf InStr(1, val, "CT") > 0 Then TextBox4.Focus() Else MsgBox("Introdu cod Operator Taiere corect") TextBox3.Clear() TextBox3.Focus() End If Else End If End Sub Private Sub TextBox4_TextChangeed(sender As Object, e As EventArgs) Handles TextBox4.TextChanged ' validare oc text box 4 If TextBox4.Text.Length < 4 Then ElseIf TextBox4.Text.Length = 4 Then Dim val As String val = TextBox4.Text If InStr(1, val, "00") > 0 Then TextBox5.Focus() ElseIf InStr(1, val, "mn") > 0 Then TextBox5.Focus() ElseIf InStr(1, val, "MN") > 0 Then TextBox5.Focus() ElseIf InStr(1, val, "sn") > 0 Then TextBox5.Focus() ElseIf InStr(1, val, "SN") > 0 Then TextBox5.Focus() Else MsgBox("Introdu cod Matlasor Corect") TextBox4.Clear() TextBox4.Focus() End If Else End If End Sub Private Sub TextBox5_TextChangeed(sender As Object, e As EventArgs) Handles TextBox5.TextChanged ' validare sp text box 4 If TextBox5.Text.Length < 4 Then ElseIf TextBox5.Text.Length = 4 Then Dim val As String val = TextBox5.Text If InStr(1, val, "00") > 0 Then TextBox6.Focus() ElseIf InStr(1, val, "sp") > 0 Then TextBox6.Focus() ElseIf InStr(1, val, "SP") > 0 Then TextBox6.Focus() Else MsgBox("Introdu cod Matlasor Corect") TextBox5.Clear() TextBox5.Focus() End If Else End If End Sub Private Sub TextBox6_TextChangeed(sender As Object, e As EventArgs) Handles TextBox6.TextChanged ' validare Calitate text box5 If TextBox6.Text.Length < 4 Then ElseIf TextBox6.Text.Length = 4 Then Dim val As String val = TextBox6.Text If InStr(1, val, "0000") > 0 Then Dim oq As String = TextBox1.Text 'string pentru SQL oq Dim cp As String = TextBox2.Text 'string pentru SQL cp Dim oc1 As String = TextBox3.Text 'string pentru SQL oc1 Dim oc2 As String = TextBox4.Text 'string pentru SQL oc2 Dim quality As String = TextBox4.Text 'string pentru SQL calitate Dim dta As String 'string pentru SQL data dta = Date.Now.ToString("yyyy.MM.dd") ' format string Label6.Text = dta 'Update in Label Dim dTime As String 'string pentru SQL time dTime = Date.Now.ToString("hh: mm") 'Format time Label7.Text = dTime ' update in label Dim cant As Integer 'cantitate 1 intodeauna cant = 1 Dim con As New SqlConnection("Data Source=" & surce & "; Initial Catalog=" & catalog & "; User ID=" & user & "; Password=" & pass & "; Connect Timeout=" & timeout & "; Encrypt=" & encrypt & "; TrustServerCertificate=" & trust & "; ApplicationIntent=" & reason & "; MultiSubnetFailover=" & subnet & "") con.Open() Dim command As New SqlCommand("Insert into calitate.dbo.pregatit values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & dta & "','" & dTime & "')", con) command.ExecuteNonQuery() con.Close() updateTable() TextBox2.Clear() TextBox3.Clear() TextBox4.Clear() TextBox5.Clear() TextBox6.Clear() TextBox2.Focus() ElseIf InStr(1, val, "sp") > 0 Then Dim oq As String = TextBox1.Text 'string pentru SQL oq Dim cp As String = TextBox2.Text 'string pentru SQL cp Dim oc1 As String = TextBox3.Text 'string pentru SQL oc1 Dim oc2 As String = TextBox4.Text 'string pentru SQL oc2 Dim quality As String = TextBox4.Text 'string pentru SQL calitate Dim dta As String 'string pentru SQL data dta = Date.Now.ToString("yyyy.MM.dd") ' format string Label6.Text = dta 'Update in Label Dim dTime As String 'string pentru SQL time dTime = Date.Now.ToString("hh: mm") 'Format time Label7.Text = dTime ' update in label Dim cant As Integer 'cantitate 1 intodeauna cant = 1 Dim con As New SqlConnection("Data Source=" & surce & "; Initial Catalog=" & catalog & "; User ID=" & user & "; Password=" & pass & "; Connect Timeout=" & timeout & "; Encrypt=" & encrypt & "; TrustServerCertificate=" & trust & "; ApplicationIntent=" & reason & "; MultiSubnetFailover=" & subnet & "") con.Open() Dim command As New SqlCommand("Insert into calitate.dbo.pregatit values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & dta & "','" & dTime & "')", con) command.ExecuteNonQuery() con.Close() updateTable() TextBox2.Clear() TextBox3.Clear() TextBox4.Clear() TextBox5.Clear() TextBox6.Clear() TextBox2.Focus() ElseIf InStr(1, val, "SP") > 0 Then Dim oq As String = TextBox1.Text 'string pentru SQL oq Dim cp As String = TextBox2.Text 'string pentru SQL cp Dim oc1 As String = TextBox3.Text 'string pentru SQL oc1 Dim oc2 As String = TextBox4.Text 'string pentru SQL oc2 Dim quality As String = TextBox4.Text 'string pentru SQL calitate Dim dta As String 'string pentru SQL data dta = Date.Now.ToString("yyyy.MM.dd") ' format string Label6.Text = dta 'Update in Label Dim dTime As String 'string pentru SQL time dTime = Date.Now.ToString("hh: mm") 'Format time Label7.Text = dTime ' update in label Dim cant As Integer 'cantitate 1 intodeauna cant = 1 Dim con As New SqlConnection("Data Source=" & surce & "; Initial Catalog=" & catalog & "; User ID=" & user & "; Password=" & pass & "; Connect Timeout=" & timeout & "; Encrypt=" & encrypt & "; TrustServerCertificate=" & trust & "; ApplicationIntent=" & reason & "; MultiSubnetFailover=" & subnet & "") con.Open() Dim command As New SqlCommand("Insert into calitate.dbo.pregatit values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & dta & "','" & dTime & "')", con) command.ExecuteNonQuery() con.Close() updateTable() TextBox2.Clear() TextBox3.Clear() TextBox4.Clear() TextBox5.Clear() TextBox6.Clear() TextBox2.Focus() Else MsgBox("Introdu cod Defect Corect") TextBox6.Clear() TextBox6.Focus() End If Else End If End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ' inchidere forma scanare articole Form1.Show() Me.Close() End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click ' stergere rand din datagrid Dim result1 As DialogResult = MsgBox("Sigur Vrei sa strigi linia selectata ?", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "Confirmare stergere Linie") If DialogResult.OK Then 'confirmare MsgBox ' cod stergere din SQL If rowIdval >= 0 Then ' id row datagrid din sub datagrid Dim id As Integer = rowIdval Dim con As New SqlConnection("Data Source=" & surce & "; Initial Catalog=" & catalog & "; User ID=" & user & "; Password=" & pass & "; Connect Timeout=" & timeout & "; Encrypt=" & encrypt & "; TrustServerCertificate=" & trust & "; ApplicationIntent=" & reason & "; MultiSubnetFailover=" & subnet & "") con.Open() Dim command As New SqlCommand("Delete calitate.dbo.pregatit where id = '" & id & "'", con) command.ExecuteNonQuery() con.Close() updateTable() MsgBox(" Linia a fost stearsa") TextBox2.Focus() End If Else MsgBox(" Ai anulat stergerea liniei") End If End Sub Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick Dim selectRow As Integer = e.RowIndex ' gasirea indezului din datagrid If selectRow >= 0 Then 'gasirea id din randul selectat din datagrid Dim selectedCellValue As String = DataGridView1.Rows(selectRow).Cells("id").Value.ToString() rowIdval = selectedCellValue ' devinirea valorii lui rowIdVal pe baza selectarii din datagrid End If End Sub End Class