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


Imports System.Data.OleDb 
 
Public Class frmProModify 
    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 PictureBox2 As System.Windows.Forms.PictureBox 
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox 
    Friend WithEvents cbProStandard As System.Windows.Forms.ComboBox 
    Friend WithEvents Label30 As System.Windows.Forms.Label 
    Friend WithEvents Label31 As System.Windows.Forms.Label 
    Friend WithEvents Label32 As System.Windows.Forms.Label 
    Friend WithEvents Label33 As System.Windows.Forms.Label 
    Friend WithEvents txtProDate As System.Windows.Forms.TextBox 
    Friend WithEvents txtProModel As System.Windows.Forms.TextBox 
    Friend WithEvents Label34 As System.Windows.Forms.Label 
    Friend WithEvents btnModify As System.Windows.Forms.Button 
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox 
    Friend WithEvents txtProName As System.Windows.Forms.TextBox 
    Friend WithEvents cbProID As System.Windows.Forms.ComboBox 
    Friend WithEvents btnCancel As System.Windows.Forms.Button 
    Friend WithEvents btnDelete As System.Windows.Forms.Button 
     Private Sub InitializeComponent() 
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmProModify)) 
        Me.PictureBox2 = New System.Windows.Forms.PictureBox 
        Me.GroupBox1 = New System.Windows.Forms.GroupBox 
        Me.cbProID = New System.Windows.Forms.ComboBox 
        Me.cbProStandard = New System.Windows.Forms.ComboBox 
        Me.Label30 = New System.Windows.Forms.Label 
        Me.Label31 = New System.Windows.Forms.Label 
        Me.Label32 = New System.Windows.Forms.Label 
        Me.Label33 = New System.Windows.Forms.Label 
        Me.txtProDate = New System.Windows.Forms.TextBox 
        Me.txtProModel = New System.Windows.Forms.TextBox 
        Me.txtProName = New System.Windows.Forms.TextBox 
        Me.Label34 = New System.Windows.Forms.Label 
        Me.btnCancel = New System.Windows.Forms.Button 
        Me.btnModify = New System.Windows.Forms.Button 
        Me.PictureBox1 = New System.Windows.Forms.PictureBox 
        Me.btnDelete = New System.Windows.Forms.Button 
        Me.GroupBox1.SuspendLayout() 
        Me.SuspendLayout() 
        ' 
        'PictureBox2 
        ' 
        Me.PictureBox2.Image = CType(resources.GetObject("PictureBox2.Image"), System.Drawing.Image) 
        Me.PictureBox2.Location = New System.Drawing.Point(60, 24) 
        Me.PictureBox2.Name = "PictureBox2" 
        Me.PictureBox2.Size = New System.Drawing.Size(61, 61) 
        Me.PictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize 
        Me.PictureBox2.TabIndex = 87 
        Me.PictureBox2.TabStop = False 
        ' 
        'GroupBox1 
        ' 
        Me.GroupBox1.Controls.Add(Me.cbProID) 
        Me.GroupBox1.Controls.Add(Me.cbProStandard) 
        Me.GroupBox1.Controls.Add(Me.Label30) 
        Me.GroupBox1.Controls.Add(Me.Label31) 
        Me.GroupBox1.Controls.Add(Me.Label32) 
        Me.GroupBox1.Controls.Add(Me.Label33) 
        Me.GroupBox1.Controls.Add(Me.txtProDate) 
        Me.GroupBox1.Controls.Add(Me.txtProModel) 
        Me.GroupBox1.Controls.Add(Me.txtProName) 
        Me.GroupBox1.Controls.Add(Me.Label34) 
        Me.GroupBox1.Location = New System.Drawing.Point(144, 12) 
        Me.GroupBox1.Name = "GroupBox1" 
        Me.GroupBox1.Size = New System.Drawing.Size(288, 216) 
        Me.GroupBox1.TabIndex = 86 
        Me.GroupBox1.TabStop = False 
        Me.GroupBox1.Text = "成品信息" 
        ' 
        'cbProID 
        ' 
        Me.cbProID.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList 
        Me.cbProID.Location = New System.Drawing.Point(76, 36) 
        Me.cbProID.Name = "cbProID" 
        Me.cbProID.Size = New System.Drawing.Size(124, 20) 
        Me.cbProID.TabIndex = 78 
        ' 
        'cbProStandard 
        ' 
        Me.cbProStandard.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList 
        Me.cbProStandard.Items.AddRange(New Object() {"ISO9000", "GB-T2632", "行业标准", "其他标准"}) 
        Me.cbProStandard.Location = New System.Drawing.Point(76, 136) 
        Me.cbProStandard.Name = "cbProStandard" 
        Me.cbProStandard.Size = New System.Drawing.Size(124, 20) 
        Me.cbProStandard.TabIndex = 77 
        ' 
        'Label30 
        ' 
        Me.Label30.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label30.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label30.Location = New System.Drawing.Point(12, 172) 
        Me.Label30.Name = "Label30" 
        Me.Label30.Size = New System.Drawing.Size(64, 16) 
        Me.Label30.TabIndex = 76 
        Me.Label30.Text = "添加日期:" 
        ' 
        'Label31 
        ' 
        Me.Label31.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label31.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label31.Location = New System.Drawing.Point(12, 104) 
        Me.Label31.Name = "Label31" 
        Me.Label31.Size = New System.Drawing.Size(64, 16) 
        Me.Label31.TabIndex = 75 
        Me.Label31.Text = "成品型号:" 
        ' 
        'Label32 
        ' 
        Me.Label32.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label32.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label32.Location = New System.Drawing.Point(12, 140) 
        Me.Label32.Name = "Label32" 
        Me.Label32.Size = New System.Drawing.Size(64, 16) 
        Me.Label32.TabIndex = 74 
        Me.Label32.Text = "成品标准:" 
        ' 
        'Label33 
        ' 
        Me.Label33.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label33.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label33.Location = New System.Drawing.Point(12, 72) 
        Me.Label33.Name = "Label33" 
        Me.Label33.Size = New System.Drawing.Size(64, 16) 
        Me.Label33.TabIndex = 73 
        Me.Label33.Text = "成品名称:" 
        ' 
        'txtProDate 
        ' 
        Me.txtProDate.AutoSize = False 
        Me.txtProDate.Location = New System.Drawing.Point(76, 168) 
        Me.txtProDate.MaxLength = 10 
        Me.txtProDate.Name = "txtProDate" 
        Me.txtProDate.Size = New System.Drawing.Size(124, 20) 
        Me.txtProDate.TabIndex = 72 
        Me.txtProDate.Text = "" 
        ' 
        'txtProModel 
        ' 
        Me.txtProModel.AutoSize = False 
        Me.txtProModel.Location = New System.Drawing.Point(76, 104) 
        Me.txtProModel.MaxLength = 10 
        Me.txtProModel.Name = "txtProModel" 
        Me.txtProModel.Size = New System.Drawing.Size(192, 20) 
        Me.txtProModel.TabIndex = 71 
        Me.txtProModel.Text = "" 
        ' 
        'txtProName 
        ' 
        Me.txtProName.AutoSize = False 
        Me.txtProName.Location = New System.Drawing.Point(76, 72) 
        Me.txtProName.MaxLength = 10 
        Me.txtProName.Name = "txtProName" 
        Me.txtProName.Size = New System.Drawing.Size(124, 20) 
        Me.txtProName.TabIndex = 70 
        Me.txtProName.Text = "" 
        ' 
        'Label34 
        ' 
        Me.Label34.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) 
        Me.Label34.ForeColor = System.Drawing.SystemColors.ControlText 
        Me.Label34.Location = New System.Drawing.Point(12, 40) 
        Me.Label34.Name = "Label34" 
        Me.Label34.Size = New System.Drawing.Size(64, 16) 
        Me.Label34.TabIndex = 68 
        Me.Label34.Text = "成品编号:" 
        ' 
        'btnCancel 
        ' 
        Me.btnCancel.Location = New System.Drawing.Point(360, 240) 
        Me.btnCancel.Name = "btnCancel" 
        Me.btnCancel.Size = New System.Drawing.Size(72, 24) 
        Me.btnCancel.TabIndex = 85 
        Me.btnCancel.Text = "关闭(&C)" 
        ' 
        'btnModify 
        ' 
        Me.btnModify.Location = New System.Drawing.Point(276, 240) 
        Me.btnModify.Name = "btnModify" 
        Me.btnModify.Size = New System.Drawing.Size(72, 24) 
        Me.btnModify.TabIndex = 84 
        Me.btnModify.Text = "修改(&M)" 
        ' 
        'PictureBox1 
        ' 
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image) 
        Me.PictureBox1.Location = New System.Drawing.Point(15, 12) 
        Me.PictureBox1.Name = "PictureBox1" 
        Me.PictureBox1.Size = New System.Drawing.Size(116, 251) 
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage 
        Me.PictureBox1.TabIndex = 83 
        Me.PictureBox1.TabStop = False 
        ' 
        'btnDelete 
        ' 
        Me.btnDelete.Location = New System.Drawing.Point(192, 240) 
        Me.btnDelete.Name = "btnDelete" 
        Me.btnDelete.Size = New System.Drawing.Size(72, 24) 
        Me.btnDelete.TabIndex = 88 
        Me.btnDelete.Text = "删除(&D)" 
        ' 
        'frmProModify 
        ' 
        Me.AcceptButton = Me.btnCancel 
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) 
        Me.ClientSize = New System.Drawing.Size(444, 275) 
        Me.Controls.Add(Me.btnDelete) 
        Me.Controls.Add(Me.PictureBox2) 
        Me.Controls.Add(Me.GroupBox1) 
        Me.Controls.Add(Me.btnCancel) 
        Me.Controls.Add(Me.btnModify) 
        Me.Controls.Add(Me.PictureBox1) 
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog 
        Me.MaximizeBox = False 
        Me.MinimizeBox = False 
        Me.Name = "frmProModify" 
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent 
        Me.Text = "成品信息管理" 
        Me.GroupBox1.ResumeLayout(False) 
        Me.ResumeLayout(False) 
 
    End Sub 
 
#End Region 
 
    Private Sub frmProModify_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        txtProDate.Enabled = False 
        Dim myConn As OleDbConnection = New OleDbConnection(strConn) 
        Dim myComm As OleDbCommand = New OleDbCommand 
        myComm.Connection = myConn 
        myComm.CommandText = "select id from product" 
        Dim myReader As OleDbDataReader 
        myConn.Open() 
        myReader = myComm.ExecuteReader() 
        While myReader.Read 
            cbProID.Items.Add(myReader.GetInt32(0)) 
        End While 
        myConn.Close() 
    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 cbProID_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbProID.SelectedIndexChanged 
        If cbProID.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 product where id = " & cbProID.SelectedItem 
        Dim myReader As OleDbDataReader 
        myConn.Open() 
        myReader = myComm.ExecuteReader() 
        While myReader.Read 
            txtProName.Text = myReader.GetString(1) 
            txtProModel.Text = myReader.GetString(2) 
            cbProStandard.Text = myReader.GetString(3) 
            txtProDate.Text = myReader.GetDateTime(4) 
        End While 
        myConn.Close() 
    End Sub 
 
    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click 
        If cbProID.SelectedIndex = -1 Then 
            MsgBox("成品ID为空!", MsgBoxStyle.Information, "提示信息") 
            Exit Sub 
        End If 
        Dim temp As MsgBoxResult 
        temp = MsgBox("确实要删除此条记录吗?", MsgBoxStyle.YesNo, "提示信息:") 
        If temp = MsgBoxResult.Yes Then 
            Dim myConn As OleDbConnection = New OleDbConnection(strConn) 
            Dim myComm As OleDbCommand = New OleDbCommand 
            myComm.Connection = myConn 
            myComm.CommandText = "delete from product where id = @id" 
            myComm.Parameters.Add("@id", CLng(cbProID.SelectedItem)) 
            Dim myReader As OleDbDataReader 
            myConn.Open() 
            myComm.ExecuteNonQuery() 
            myConn.Close() 
            cbProID.Items.Remove(cbProID.SelectedItem) 
            txtProName.Text = "" 
            txtProModel.Text = "" 
            cbProStandard.SelectedIndex = -1 
            txtProDate.Text = "" 
            MsgBox("成品记录已删除!", MsgBoxStyle.Information, "提示信息") 
        Else 
            Exit Sub 
        End If 
    End Sub 
 
    Private Sub btnModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModify.Click 
        If txtProName.Text = "" Then 
            MsgBox("产品名称不可为空!", MsgBoxStyle.Information, "提示信息:") 
            Exit Sub 
        End If 
        If txtProModel.Text = "" Then 
            MsgBox("产品型号不可为空!", MsgBoxStyle.Information, "提示信息:") 
            Exit Sub 
        End If 
        If cbProStandard.SelectedItem = "" Then 
            MsgBox("产品标准不可为空!", MsgBoxStyle.Information, "提示信息:") 
            Exit Sub 
        End If 
 
        Dim myConn As OleDbConnection = New OleDbConnection(strConn) 
        Dim myComm As OleDbCommand = New OleDbCommand 
        myComm.Connection = myConn 
        myComm.CommandText = "update product set name=@name,model=@model,standard=@standard where id=" & cbProID.SelectedItem 
        myComm.Parameters.Add("@name", txtProName.Text) 
        myComm.Parameters.Add("@model", txtProModel.Text) 
        myComm.Parameters.Add("@standard", cbProStandard.SelectedItem) 
        myConn.Open() 
        myComm.ExecuteNonQuery() 
        myConn.Close() 
        MsgBox("成品信息修改成功!", MsgBoxStyle.Information, "提示信息") 
    End Sub 
End Class