From1
Imports System.Data
Imports System.Data.OracleClient
Imports System.Text
Public Class Form1
#Region "定义变量"
Private ConnString As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.192.71)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=DRPDB)));Persist Security Info=True;User Id=EWM_RF; Password=RF_TEST"
Private oraCon As New OracleConnection
Private oraDApter As New OracleDataAdapter
Private oraDSet As New DataSet
#End Region
#Region "连接数据库"
'''
''' 连接ORA数据库
'''
'''
Public Sub ConnectionORA()
oraCon = New OracleConnection(ConnString) '用于打开数据库的连接
If oraCon.State = ConnectionState.Closed Then '获取连接的当前状态,链接处于关闭状态
oraCon.Open() '打开一个数据库连接
ElseIf oraCon.State = ConnectionState.Broken Then '与数据源的连接断开
oraCon.Close() '关闭
oraCon.Open() '重新打开
End If
End Sub
#End Region
Private Sub CZ1_Click(sender As Object, e As EventArgs) Handles CZ1.Click
Dim JiaoHuoDanHao As String = Nothing
Dim XiangHao As String = Nothing
Try
JiaoHuoDanHao = JHDHBox1.Text
XiangHao = XHBox1.Text
If JHDHBox1.Text.Trim.Length <= 0 Then
Throw New Exception("单据号不能为空值")
End If
Dim _sql As String = "SELECT HWK_CASE FROM HLAWVCKC WHERE HWK_DOCNO='" + JHDHBox1.Text + "'"
If oraCon.State <> ConnectionState.Open Then '连接数据库,检查单号是否存在
Me.ConnectionORA()
End If
Dim _Table As DataTable = Nothing '表示内存中一个数据表
oraDApter = New OracleDataAdapter(_sql, oraCon)
oraDSet = New DataSet()
oraDApter.Fill(oraDSet, "[HLAWVCKC]")
_Table = oraDSet.Tables(0)
If _Table IsNot Nothing AndAlso _Table.Rows.Count > 0 Then
XHBox1.Items.Clear()
For i As Integer = 0 To _Table.Rows.Count - 1
'获取单号对应的箱号的集合
XHBox1.Items.Add(_Table.Rows(i)("HWK_CASE").ToString)
Next
Else
Throw New Exception("交货单号" + JHDHBox1.Text + "对应的箱号不存在")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub QR1_Click(sender As Object, e As EventArgs) Handles QR1.Click
Dim frm As New Form2(Me.XHBox1.Text) : frm.Show()
Me.Hide()
oraCon.Close()
End Sub
End Class
---------------------------------------------------------------------------------
Form2 是想验证箱号是否为同一批,不会做~~~~(>_<)~~~~
---------------------------------------------------------------------------------
Imports System.Data
Imports System.Data.OracleClient
Imports System.Text
Public Class Form2
#Region "定义变量"
Dim ConnString As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.192.71)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=DRPDB)));Persist Security Info=True;User Id=EWM_RF; Password=RF_TEST"
Private oraCon As New OracleConnection
Private oraDApter As New OracleDataAdapter
Private oraDSet As New DataSet
#End Region
#Region "连接数据库"
'''
'''
'''
'''
Private _p1 As String
Sub New(p1 As String)
InitializeComponent()
' TODO: Complete member initialization
_p1 = p1
End Sub
''' <summary>
''' 连接ORA数据库
''' </summary>
''' <remarks></remarks>
Public Sub ConnectionORA()
oraCon = New OracleConnection(ConnString)
If oraCon.State = ConnectionState.Closed Then
oraCon.Open()
ElseIf oraCon.State = ConnectionState.Broken Then
oraCon.Close()
oraCon.Open()
End If
End Sub
#End Region
Private Sub QR2_Click(sender As Object, e As EventArgs) Handles QR2.Click
Dim JiaoHuoDanHao As String
Dim XiangHao As String
Try
JiaoHuoDanHao = XHBox2.Text
XiangHao = JHDHBox2.Text
If XHBox2.Text.Trim.Length <= 0 Then Throw New Exception("箱号不能为空值")
Dim _sql As String = "SELECT * FROM HLAWVCKC WHERE HWK_CASE='" + XHBox2.Text + "'"
If oraCon.State <> ConnectionState.Open Then '连接数据库,检查箱号是否存在
Me.ConnectionORA()
End If
Dim _Table As DataTable = Nothing
oraDApter = New OracleDataAdapter(_sql, oraCon)
oraDSet = New DataSet()
oraDApter.Fill(oraDSet, "[HLAWVCKC]")
_Table = oraDSet.Tables(0)
If _Table IsNot Nothing AndAlso _Table.Rows.Count > 0 Then
'获取箱号对应的单号的
JHDHBox2.Text = CInt(_Table.Rows(0).Item("HWK_DOCNO"))
Else
Throw New Exception("箱号" + XHBox2.Text + "对应的交货单号不存在")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub FH1_Click(sender As Object, e As EventArgs) Handles FH1.Click
Me.Close()
Form1.Show()
oraCon.Close()
End Sub