www.pudn.com > SalesManager.rar > frmStockInOut.vb


Imports System.Data.OleDb 
 
Public Class frmStockInOut 
    Inherits System.Windows.Forms.Form 
 
#Region " Windows 窗体设计器生成的代码 " 
 
    Public Sub New() 
        MyBase.New() 
 
        '该调用是 Windows 窗体设计器所必需的。 
        InitializeComponent() 
 
        '在 InitializeComponent() 调用之后添加任何初始化 
 
    End Sub 
 
    '窗体重写 dispose 以清理组件列表。 
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 
        If disposing Then 
            If Not (components Is Nothing) Then 
                components.Dispose() 
            End If 
        End If 
        MyBase.Dispose(disposing) 
    End Sub 
 
    'Windows 窗体设计器所必需的 
    Private components As System.ComponentModel.IContainer 
 
    '注意: 以下过程是 Windows 窗体设计器所必需的 
    '可以使用 Windows 窗体设计器修改此过程。 
    '不要使用代码编辑器修改它。 
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox 
    Friend WithEvents cbConID As System.Windows.Forms.ComboBox 
    Friend WithEvents dtpCon As System.Windows.Forms.DateTimePicker 
    Friend WithEvents Label50 As System.Windows.Forms.Label 
    Friend WithEvents Label58 As System.Windows.Forms.Label 
    Friend WithEvents cbConCustomer As System.Windows.Forms.ComboBox 
    Friend WithEvents cbConPaytype As System.Windows.Forms.ComboBox 
    Friend WithEvents Label47 As System.Windows.Forms.Label 
    Friend WithEvents Label48 As System.Windows.Forms.Label 
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox 
    Friend WithEvents Label1 As System.Windows.Forms.Label 
    Friend WithEvents dgCon As System.Windows.Forms.DataGrid 
    Friend WithEvents btnStock As System.Windows.Forms.Button 
    Friend WithEvents btnCancel As System.Windows.Forms.Button 
    Friend WithEvents Label2 As System.Windows.Forms.Label 
    Friend WithEvents Label3 As System.Windows.Forms.Label 
    Friend WithEvents Label4 As System.Windows.Forms.Label 
    Friend WithEvents Label5 As System.Windows.Forms.Label 
    Friend WithEvents Label6 As System.Windows.Forms.Label 
    Friend WithEvents dgStock As System.Windows.Forms.DataGridTableStyle 
    Friend WithEvents proname As System.Windows.Forms.DataGridTextBoxColumn 
    Friend WithEvents snumber As System.Windows.Forms.DataGridTextBoxColumn 
    Friend WithEvents price As System.Windows.Forms.DataGridTextBoxColumn 
    Friend WithEvents cbConInOut As System.Windows.Forms.ComboBox 
    Friend WithEvents Label49 As System.Windows.Forms.Label 
    Friend WithEvents cbConType As System.Windows.Forms.ComboBox 
    Friend WithEvents Label7 As System.Windows.Forms.Label 
    Friend WithEvents labConSum As System.Windows.Forms.Label 
     Private Sub InitializeComponent() 
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmStockInOut)) 
        Me.PictureBox1 = New System.Windows.Forms.PictureBox 
        Me.cbConID = New System.Windows.Forms.ComboBox 
        Me.dtpCon = New System.Windows.Forms.DateTimePicker 
        Me.Label50 = New System.Windows.Forms.Label 
        Me.Label58 = New System.Windows.Forms.Label 
        Me.cbConCustomer = New System.Windows.Forms.ComboBox 
        Me.cbConInOut = New System.Windows.Forms.ComboBox 
        Me.cbConPaytype = New System.Windows.Forms.ComboBox 
        Me.Label47 = New System.Windows.Forms.Label 
        Me.Label48 = New System.Windows.Forms.Label 
        Me.GroupBox2 = New System.Windows.Forms.GroupBox 
        Me.Label1 = New System.Windows.Forms.Label 
        Me.dgCon = New System.Windows.Forms.DataGrid 
        Me.dgStock = New System.Windows.Forms.DataGridTableStyle 
        Me.proname = New System.Windows.Forms.DataGridTextBoxColumn 
        Me.snumber = New System.Windows.Forms.DataGridTextBoxColumn 
        Me.price = New System.Windows.Forms.DataGridTextBoxColumn 
        Me.btnStock = New System.Windows.Forms.Button 
        Me.btnCancel = New System.Windows.Forms.Button 
        Me.Label2 = New System.Windows.Forms.Label 
        Me.Label3 = New System.Windows.Forms.Label 
        Me.Label4 = New System.Windows.Forms.Label 
        Me.Label5 = New System.Windows.Forms.Label 
        Me.Label6 = New System.Windows.Forms.Label 
        Me.Label49 = New System.Windows.Forms.Label 
        Me.cbConType = New System.Windows.Forms.ComboBox 
        Me.Label7 = New System.Windows.Forms.Label 
        Me.labConSum = New System.Windows.Forms.Label 
        Me.GroupBox2.SuspendLayout() 
        CType(Me.dgCon, System.ComponentModel.ISupportInitialize).BeginInit() 
        Me.SuspendLayout() 
        ' 
        'PictureBox1 
        ' 
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image) 
        Me.PictureBox1.Location = New System.Drawing.Point(20, 16) 
        Me.PictureBox1.Name = "PictureBox1" 
        Me.PictureBox1.Size = New System.Drawing.Size(140, 316) 
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage 
        Me.PictureBox1.TabIndex = 141 
        Me.PictureBox1.TabStop = False 
        ' 
        'cbConID 
        ' 
        Me.cbConID.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList 
        Me.cbConID.Location = New System.Drawing.Point(292, 28) 
        Me.cbConID.Name = "cbConID" 
        Me.cbConID.Size = New System.Drawing.Size(96, 20) 
        Me.cbConID.TabIndex = 135 
        ' 
        'dtpCon 
        ' 
        Me.dtpCon.Location = New System.Drawing.Point(416, 136) 
        Me.dtpCon.Name = "dtpCon" 
        Me.dtpCon.Size = New System.Drawing.Size(108, 21) 
        Me.dtpCon.TabIndex = 134 
        ' 
        'Label50 
        ' 
        Me.Label50.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label50.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label50.Location = New System.Drawing.Point(224, 32) 
        Me.Label50.Name = "Label50" 
        Me.Label50.Size = New System.Drawing.Size(64, 16) 
        Me.Label50.TabIndex = 110 
        Me.Label50.Text = "合同编号:" 
        ' 
        'Label58 
        ' 
        Me.Label58.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label58.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label58.Location = New System.Drawing.Point(356, 140) 
        Me.Label58.Name = "Label58" 
        Me.Label58.Size = New System.Drawing.Size(64, 16) 
        Me.Label58.TabIndex = 133 
        Me.Label58.Text = "签订日期:" 
        ' 
        'cbConCustomer 
        ' 
        Me.cbConCustomer.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList 
        Me.cbConCustomer.Location = New System.Drawing.Point(252, 108) 
        Me.cbConCustomer.Name = "cbConCustomer" 
        Me.cbConCustomer.Size = New System.Drawing.Size(96, 20) 
        Me.cbConCustomer.TabIndex = 129 
        ' 
        'cbConInOut 
        ' 
        Me.cbConInOut.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList 
        Me.cbConInOut.Items.AddRange(New Object() {"出库", "入库"}) 
        Me.cbConInOut.Location = New System.Drawing.Point(104, 28) 
        Me.cbConInOut.Name = "cbConInOut" 
        Me.cbConInOut.Size = New System.Drawing.Size(96, 20) 
        Me.cbConInOut.TabIndex = 128 
        ' 
        'cbConPaytype 
        ' 
        Me.cbConPaytype.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList 
        Me.cbConPaytype.Items.AddRange(New Object() {"现金支付", "银行转帐", "股权转让", "其他方式"}) 
        Me.cbConPaytype.Location = New System.Drawing.Point(252, 136) 
        Me.cbConPaytype.Name = "cbConPaytype" 
        Me.cbConPaytype.Size = New System.Drawing.Size(96, 20) 
        Me.cbConPaytype.TabIndex = 127 
        ' 
        'Label47 
        ' 
        Me.Label47.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label47.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label47.Location = New System.Drawing.Point(188, 112) 
        Me.Label47.Name = "Label47" 
        Me.Label47.Size = New System.Drawing.Size(64, 16) 
        Me.Label47.TabIndex = 118 
        Me.Label47.Text = "合同对象:" 
        ' 
        'Label48 
        ' 
        Me.Label48.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label48.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label48.Location = New System.Drawing.Point(188, 140) 
        Me.Label48.Name = "Label48" 
        Me.Label48.Size = New System.Drawing.Size(64, 16) 
        Me.Label48.TabIndex = 117 
        Me.Label48.Text = "付款方式:" 
        ' 
        'GroupBox2 
        ' 
        Me.GroupBox2.Controls.Add(Me.cbConInOut) 
        Me.GroupBox2.Controls.Add(Me.Label50) 
        Me.GroupBox2.Controls.Add(Me.cbConID) 
        Me.GroupBox2.Controls.Add(Me.Label1) 
        Me.GroupBox2.Location = New System.Drawing.Point(168, 12) 
        Me.GroupBox2.Name = "GroupBox2" 
        Me.GroupBox2.Size = New System.Drawing.Size(404, 64) 
        Me.GroupBox2.TabIndex = 146 
        Me.GroupBox2.TabStop = False 
        Me.GroupBox2.Text = "出入库处理" 
        ' 
        'Label1 
        ' 
        Me.Label1.Location = New System.Drawing.Point(8, 32) 
        Me.Label1.Name = "Label1" 
        Me.Label1.Size = New System.Drawing.Size(104, 20) 
        Me.Label1.TabIndex = 129 
        Me.Label1.Text = "请选择出入库:" 
        ' 
        'dgCon 
        ' 
        Me.dgCon.BackgroundColor = System.Drawing.Color.FromArgb(CType(239, Byte), CType(243, Byte), CType(255, Byte)) 
        Me.dgCon.CaptionVisible = False 
        Me.dgCon.DataMember = "" 
        Me.dgCon.HeaderForeColor = System.Drawing.SystemColors.ControlText 
        Me.dgCon.Location = New System.Drawing.Point(172, 196) 
        Me.dgCon.Name = "dgCon" 
        Me.dgCon.ReadOnly = True 
        Me.dgCon.Size = New System.Drawing.Size(388, 96) 
        Me.dgCon.TabIndex = 135 
        Me.dgCon.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {Me.dgStock}) 
        ' 
        'dgStock 
        ' 
        Me.dgStock.DataGrid = Me.dgCon 
        Me.dgStock.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.proname, Me.snumber, Me.price}) 
        Me.dgStock.HeaderForeColor = System.Drawing.SystemColors.ControlText 
        Me.dgStock.MappingName = "stock" 
        ' 
        'proname 
        ' 
        Me.proname.Format = "" 
        Me.proname.FormatInfo = Nothing 
        Me.proname.HeaderText = "产品名称" 
        Me.proname.MappingName = "proname" 
        ' 
        'snumber 
        ' 
        Me.snumber.Format = "" 
        Me.snumber.FormatInfo = Nothing 
        Me.snumber.HeaderText = "数量" 
        Me.snumber.MappingName = "snumber" 
        ' 
        'price 
        ' 
        Me.price.Format = "" 
        Me.price.FormatInfo = Nothing 
        Me.price.HeaderText = "单价" 
        Me.price.MappingName = "price" 
        ' 
        'btnStock 
        ' 
        Me.btnStock.Location = New System.Drawing.Point(412, 316) 
        Me.btnStock.Name = "btnStock" 
        Me.btnStock.Size = New System.Drawing.Size(72, 24) 
        Me.btnStock.TabIndex = 148 
        Me.btnStock.Text = "处理(P)" 
        ' 
        'btnCancel 
        ' 
        Me.btnCancel.Location = New System.Drawing.Point(504, 316) 
        Me.btnCancel.Name = "btnCancel" 
        Me.btnCancel.Size = New System.Drawing.Size(68, 24) 
        Me.btnCancel.TabIndex = 149 
        Me.btnCancel.Text = "关闭(&C)" 
        ' 
        'Label2 
        ' 
        Me.Label2.Location = New System.Drawing.Point(172, 160) 
        Me.Label2.Name = "Label2" 
        Me.Label2.Size = New System.Drawing.Size(60, 16) 
        Me.Label2.TabIndex = 150 
        Me.Label2.Text = "订单信息" 
        ' 
        'Label3 
        ' 
        Me.Label3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D 
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label3.Location = New System.Drawing.Point(228, 164) 
        Me.Label3.Name = "Label3" 
        Me.Label3.Size = New System.Drawing.Size(330, 2) 
        Me.Label3.TabIndex = 151 
        ' 
        'Label4 
        ' 
        Me.Label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D 
        Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label4.Location = New System.Drawing.Point(228, 92) 
        Me.Label4.Name = "Label4" 
        Me.Label4.Size = New System.Drawing.Size(330, 2) 
        Me.Label4.TabIndex = 153 
        ' 
        'Label5 
        ' 
        Me.Label5.Location = New System.Drawing.Point(172, 88) 
        Me.Label5.Name = "Label5" 
        Me.Label5.Size = New System.Drawing.Size(60, 16) 
        Me.Label5.TabIndex = 152 
        Me.Label5.Text = "合同信息" 
        ' 
        'Label6 
        ' 
        Me.Label6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D 
        Me.Label6.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label6.Location = New System.Drawing.Point(168, 300) 
        Me.Label6.Name = "Label6" 
        Me.Label6.Size = New System.Drawing.Size(400, 2) 
        Me.Label6.TabIndex = 154 
        ' 
        'Label49 
        ' 
        Me.Label49.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label49.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label49.Location = New System.Drawing.Point(356, 112) 
        Me.Label49.Name = "Label49" 
        Me.Label49.Size = New System.Drawing.Size(60, 16) 
        Me.Label49.TabIndex = 155 
        Me.Label49.Text = "合同类型:" 
        ' 
        'cbConType 
        ' 
        Me.cbConType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList 
        Me.cbConType.Items.AddRange(New Object() {"采购", "销售"}) 
        Me.cbConType.Location = New System.Drawing.Point(416, 108) 
        Me.cbConType.Name = "cbConType" 
        Me.cbConType.Size = New System.Drawing.Size(108, 20) 
        Me.cbConType.TabIndex = 156 
        ' 
        'Label7 
        ' 
        Me.Label7.Location = New System.Drawing.Point(392, 176) 
        Me.Label7.Name = "Label7" 
        Me.Label7.Size = New System.Drawing.Size(64, 16) 
        Me.Label7.TabIndex = 157 
        Me.Label7.Text = "交易金额:" 
        ' 
        'labConSum 
        ' 
        Me.labConSum.Location = New System.Drawing.Point(456, 176) 
        Me.labConSum.Name = "labConSum" 
        Me.labConSum.Size = New System.Drawing.Size(100, 16) 
        Me.labConSum.TabIndex = 158 
        Me.labConSum.TextAlign = System.Drawing.ContentAlignment.MiddleCenter 
        ' 
        'frmStockInOut 
        ' 
        Me.AcceptButton = Me.btnCancel 
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) 
        Me.ClientSize = New System.Drawing.Size(594, 351) 
        Me.Controls.Add(Me.labConSum) 
        Me.Controls.Add(Me.Label7) 
        Me.Controls.Add(Me.cbConType) 
        Me.Controls.Add(Me.Label49) 
        Me.Controls.Add(Me.Label6) 
        Me.Controls.Add(Me.Label4) 
        Me.Controls.Add(Me.Label5) 
        Me.Controls.Add(Me.Label3) 
        Me.Controls.Add(Me.btnCancel) 
        Me.Controls.Add(Me.btnStock) 
        Me.Controls.Add(Me.GroupBox2) 
        Me.Controls.Add(Me.PictureBox1) 
        Me.Controls.Add(Me.dgCon) 
        Me.Controls.Add(Me.Label2) 
        Me.Controls.Add(Me.dtpCon) 
        Me.Controls.Add(Me.Label58) 
        Me.Controls.Add(Me.cbConCustomer) 
        Me.Controls.Add(Me.cbConPaytype) 
        Me.Controls.Add(Me.Label47) 
        Me.Controls.Add(Me.Label48) 
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog 
        Me.MaximizeBox = False 
        Me.MinimizeBox = False 
        Me.Name = "frmStockInOut" 
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent 
        Me.Text = "出入库处理" 
        Me.GroupBox2.ResumeLayout(False) 
        CType(Me.dgCon, System.ComponentModel.ISupportInitialize).EndInit() 
        Me.ResumeLayout(False) 
 
    End Sub 
 
#End Region 
 
    Private Sub frmStockInOut_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        Me.cbConCustomer.Enabled = False 
        Me.cbConPaytype.Enabled = False 
        Me.cbConType.Enabled = False 
        Me.dtpCon.Enabled = False 
 
        Dim sqlStr As String = "select proname,snumber,price from stock where contract = " & "'" & Me.cbConID.SelectedItem & "'" 
        Dim conConn As New OleDbConnection(strConn) 
        Dim conComm As New OleDbCommand(sqlStr, conConn) 
        Dim myDa As New OleDbDataAdapter 
        myDa.SelectCommand = conComm 
        Dim myDs As New DataSet 
        myDa.Fill(myDs, "stock") 
        dgCon.DataSource = myDs.Tables("stock") 
 
    End Sub 
 
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click 
        Me.Close() 
    End Sub 
 
    Private Sub cbConInOut_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbConInOut.SelectedIndexChanged 
        If cbConInOut.SelectedIndex = -1 Then 
            Exit Sub 
        End If 
        Dim myType As String 
        If cbConInOut.SelectedIndex = 0 Then 
            myType = "销售" 
        Else 
            myType = "采购" 
        End If 
        Me.cbConID.Items.Clear() 
 
        '订单信息 
 
        Dim sqlStr As String = "select proname,snumber,price from stock where contract = " & "'" & Me.cbConID.SelectedItem & "'" 
        Dim conConn As New OleDbConnection(strConn) 
        Dim conComm As New OleDbCommand(sqlStr, conConn) 
        Dim myDa As New OleDbDataAdapter 
        myDa.SelectCommand = conComm 
        Dim myDs As New DataSet 
        myDa.Fill(myDs, "stock") 
        dgCon.DataSource = myDs.Tables("stock") 
        conConn.Close() 
 
        Dim myConn As OleDbConnection = New OleDbConnection(strConn) 
        Dim myComm As OleDbCommand = New OleDbCommand 
        myComm.Connection = myConn 
        myComm.CommandText = "select id from contract where factor = false and ctype = '" & myType & "'" 
        Dim myReader As OleDbDataReader 
        myConn.Open() 
        myReader = myComm.ExecuteReader() 
        While myReader.Read 
            cbConID.Items.Add(myReader.GetInt32(0)) 
        End While 
        myConn.Close() 
 
        cbConType.SelectedIndex = -1 
        cbConCustomer.SelectedIndex = -1 
        labConSum.Text = "" 
        cbConPaytype.SelectedIndex = -1 
        dtpCon.Text = DateTime.Today 
 
    End Sub 
 
    Private Sub cbConID_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbConID.SelectedIndexChanged 
        If cbConID.SelectedIndex = -1 Then 
            Exit Sub 
        End If 
 
        Dim myConn As OleDbConnection = New OleDbConnection(strConn) 
        Dim myComm As OleDbCommand = New OleDbCommand 
        myComm.Connection = myConn 
        myComm.CommandText = "select * from contract where id = " & cbConID.SelectedItem 
        Dim myReader As OleDbDataReader 
        myConn.Open() 
        myReader = myComm.ExecuteReader() 
        While myReader.Read 
            cbConType.SelectedItem = myReader.GetString(1) 
            cbConCustomer.Items.Add(myReader.GetString(2)) 
            cbConCustomer.SelectedIndex = 0 
            labConSum.Text = myReader.GetDouble(3) 
            cbConPaytype.SelectedItem = myReader.GetString(4) 
            dtpCon.Text = myReader.GetDateTime(6) 
        End While 
        myConn.Close() 
 
        '订单信息 
        Dim sqlStr As String = "select proname,snumber,price from stock where contract = " & "'" & Me.cbConID.SelectedItem & "'" 
        Dim conConn As New OleDbConnection(strConn) 
        Dim conComm As New OleDbCommand(sqlStr, conConn) 
        Dim myDa As New OleDbDataAdapter 
        myDa.SelectCommand = conComm 
        Dim myDs As New DataSet 
        myDa.Fill(myDs, "stock") 
        dgCon.DataSource = myDs.Tables("stock") 
        conConn.Close() 
 
    End Sub 
 
    Function stockUpdate() 
 
        Dim lack As String 
        Dim numTemp As Long 
        Dim proIn As Long 
        Dim t As String 
        t = cbConType.SelectedItem 
        Dim lackConn As OleDbConnection = New OleDbConnection(strConn) 
        Dim lackComm As OleDbCommand = New OleDbCommand 
        lackComm.Connection = lackConn 
        lackComm.CommandText = "select proname,snumber from stock where contract = '" & cbConID.SelectedItem & "'" 
        Dim lackReader As OleDbDataReader 
        lackConn.Open() 
        lackReader = lackComm.ExecuteReader 
        While lackReader.Read 
            lack = lackReader.GetString(0) 
            numTemp = lackReader.GetInt32(1) 
            Dim inConn As OleDbConnection = New OleDbConnection(strConn) 
            Dim inComm As OleDbCommand = New OleDbCommand 
            inComm.Connection = inConn 
            inComm.CommandText = "select lack from product where name = '" & lack & "'" 
            inConn.Open() 
            Dim inReader As OleDbDataReader 
            inReader = inComm.ExecuteReader 
            While inReader.Read 
                proIn = inReader.GetInt32(0) 
            End While 
            inConn.Close() 
            If t = "销售" Then 
                proIn = proIn - numTemp 
            ElseIf t = "采购" Then 
                proIn = proIn + numTemp 
            End If 
 
            '更新产品库存 
            Dim outConn As OleDbConnection = New OleDbConnection(strConn) 
            Dim outComm As OleDbCommand = New OleDbCommand 
            outComm.Connection = outConn 
            outComm.CommandText = "update product set lack = @lack where name = '" & lack & "'" 
            outComm.Parameters.Add("@lack", proIn) 
            outConn.Open() 
            outComm.ExecuteNonQuery() 
            outConn.Close() 
        End While 
        lackConn.Close() 
 
    End Function 
    Private Sub btnStock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStock.Click 
        If cbConID.SelectedIndex = -1 Then 
            Exit Sub 
        End If 
        Dim temp As MsgBoxResult 
        temp = MsgBox("您确定要处理此条出入库信息吗?", MsgBoxStyle.YesNo, "提示信息:") 
 
        Dim lack As String 
        Dim numTemp As Long 
        Dim proIn As Long 
 
        If temp = MsgBoxResult.Yes Then 
 
            Dim t As String 
            t = cbConType.SelectedItem 
            Dim lackConn As OleDbConnection = New OleDbConnection(strConn) 
            Dim lackComm As OleDbCommand = New OleDbCommand 
            lackComm.Connection = lackConn 
            lackComm.CommandText = "select proname,snumber from stock where contract = '" & cbConID.SelectedItem & "'" 
            Dim lackReader As OleDbDataReader 
            lackConn.Open() 
            lackReader = lackComm.ExecuteReader 
            While lackReader.Read 
                lack = lackReader.GetString(0) 
                numTemp = lackReader.GetInt32(1) 
                Dim inConn As OleDbConnection = New OleDbConnection(strConn) 
                Dim inComm As OleDbCommand = New OleDbCommand 
                inComm.Connection = inConn 
                inComm.CommandText = "select lack from product where name = '" & lack & "'" 
                inConn.Open() 
                Dim inReader As OleDbDataReader 
                inReader = inComm.ExecuteReader 
                While inReader.Read 
                    proIn = inReader.GetInt32(0) 
                End While 
                inConn.Close() 
                If t = "销售" Then 
                    '查看是否缺货 
                    If proIn - numTemp < 0 Then 
                        MsgBox("产品 < " & lack & " > 缺货,合同不能处理!", MsgBoxStyle.Information, "提示信息") 
                        lackConn.Close() 
                        Exit Sub 
                    End If 
                    proIn = proIn - numTemp 
 
                ElseIf t = "采购" Then 
                    proIn = proIn + numTemp 
                End If 
 
            End While 
            lackConn.Close() 
            Me.stockUpdate() 
 
            '更新合同信息 
            Dim myConn As OleDbConnection = New OleDbConnection(strConn) 
            Dim myComm As OleDbCommand = New OleDbCommand 
            myComm.Connection = myConn 
            myComm.CommandText = "update contract set factor = true , factdate = @factdate where id = " & cbConID.SelectedItem 
            myComm.Parameters.Add("@factdate", DateTime.Today) 
            myConn.Open() 
            myComm.ExecuteNonQuery() 
            myConn.Close() 
 
            Dim sConn As OleDbConnection = New OleDbConnection(strConn) 
            Dim sComm As OleDbCommand = New OleDbCommand 
            sComm.Connection = sConn 
            sComm.CommandText = "update stock set factor = true where contract = '" & cbConID.SelectedItem & "'" 
            sConn.Open() 
            sComm.ExecuteNonQuery() 
            sConn.Close() 
            '更新客户等级 
            Dim tt As String 
            tt = cbConCustomer.SelectedItem 
            Dim i As Double 
            Dim CusConn As OleDbConnection = New OleDbConnection(strConn) 
            Dim CusComm As OleDbCommand = New OleDbCommand 
            CusComm.Connection = CusConn 
            CusComm.CommandText = "select csum from contract where factor = true and customer = '" & tt & "'" 
            Dim myReader As OleDbDataReader 
            CusConn.Open() 
            myReader = CusComm.ExecuteReader 
            While myReader.Read 
                i = i + myReader.GetDouble(0) 
            End While 
            CusConn.Close() 
            If i < 50000 Then 
                tt = "★☆☆☆" 
            ElseIf i < 150000 Then 
                tt = "★★☆☆" 
            ElseIf i < 300000 Then 
                tt = "★★★☆" 
            ElseIf i >= 300000 Then 
                tt = "★★★★" 
            End If 
            Dim lmyConn As OleDbConnection = New OleDbConnection(strConn) 
            Dim lmyComm As OleDbCommand = New OleDbCommand 
            lmyComm.Connection = lmyConn 
            lmyComm.CommandText = "update customer set clevel = @clevel where name = '" & cbConCustomer.SelectedItem & "'" 
            lmyComm.Parameters.Add("@clevel", tt) 
            lmyConn.Open() 
            lmyComm.ExecuteNonQuery() 
            lmyConn.Close() 
 
            cbConID.Items.Remove(cbConID.SelectedItem) 
            cbConType.SelectedIndex = -1 
            cbConCustomer.SelectedIndex = -1 
            labConSum.Text = "" 
            cbConPaytype.SelectedIndex = -1 
            dtpCon.Text = DateTime.Today 
 
            '更新库存表 
            Dim sqlStr As String = "select proname,snumber,price from stock where contract = " & "'" & Me.cbConID.SelectedItem & "'" 
            Dim conConn As New OleDbConnection(strConn) 
            Dim conComm As New OleDbCommand(sqlStr, conConn) 
            Dim myDa As New OleDbDataAdapter 
            myDa.SelectCommand = conComm 
            Dim myDs As New DataSet 
            myDa.Fill(myDs, "stock") 
            dgCon.DataSource = myDs.Tables("stock") 
 
            MsgBox("处理成功!", MsgBoxStyle.Information, "提示信息") 
        Else 
            Exit Sub 
        End If 
 
    End Sub 
End Class