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


Imports System.Data.OleDb 
 
Public Class frmProAdd 
    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 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 txtProName As System.Windows.Forms.TextBox 
    Friend WithEvents txtProID As System.Windows.Forms.TextBox 
    Friend WithEvents Label34 As System.Windows.Forms.Label 
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox 
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox 
    Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox 
    Friend WithEvents btnAdd As System.Windows.Forms.Button 
    Friend WithEvents btnCancel As System.Windows.Forms.Button 
    Friend WithEvents btnReset As System.Windows.Forms.Button 
     Private Sub InitializeComponent() 
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmProAdd)) 
        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.txtProID = New System.Windows.Forms.TextBox 
        Me.Label34 = New System.Windows.Forms.Label 
        Me.PictureBox1 = New System.Windows.Forms.PictureBox 
        Me.btnAdd = New System.Windows.Forms.Button 
        Me.btnCancel = New System.Windows.Forms.Button 
        Me.GroupBox1 = New System.Windows.Forms.GroupBox 
        Me.PictureBox2 = New System.Windows.Forms.PictureBox 
        Me.btnReset = New System.Windows.Forms.Button 
        Me.GroupBox1.SuspendLayout() 
        Me.SuspendLayout() 
        ' 
        '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(77, 123) 
        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(13, 159) 
        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(13, 95) 
        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(13, 127) 
        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(13, 63) 
        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(77, 155) 
        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(77, 95) 
        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(77, 63) 
        Me.txtProName.MaxLength = 10 
        Me.txtProName.Name = "txtProName" 
        Me.txtProName.Size = New System.Drawing.Size(124, 20) 
        Me.txtProName.TabIndex = 70 
        Me.txtProName.Text = "" 
        ' 
        'txtProID 
        ' 
        Me.txtProID.AutoSize = False 
        Me.txtProID.Location = New System.Drawing.Point(77, 31) 
        Me.txtProID.MaxLength = 8 
        Me.txtProID.Name = "txtProID" 
        Me.txtProID.Size = New System.Drawing.Size(124, 20) 
        Me.txtProID.TabIndex = 69 
        Me.txtProID.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(13, 31) 
        Me.Label34.Name = "Label34" 
        Me.Label34.Size = New System.Drawing.Size(64, 16) 
        Me.Label34.TabIndex = 68 
        Me.Label34.Text = "成品编号:" 
        ' 
        'PictureBox1 
        ' 
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image) 
        Me.PictureBox1.Location = New System.Drawing.Point(12, 12) 
        Me.PictureBox1.Name = "PictureBox1" 
        Me.PictureBox1.Size = New System.Drawing.Size(116, 236) 
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage 
        Me.PictureBox1.TabIndex = 78 
        Me.PictureBox1.TabStop = False 
        ' 
        'btnAdd 
        ' 
        Me.btnAdd.Location = New System.Drawing.Point(212, 220) 
        Me.btnAdd.Name = "btnAdd" 
        Me.btnAdd.Size = New System.Drawing.Size(64, 24) 
        Me.btnAdd.TabIndex = 79 
        Me.btnAdd.Text = "添加(&A)" 
        ' 
        'btnCancel 
        ' 
        Me.btnCancel.Location = New System.Drawing.Point(364, 220) 
        Me.btnCancel.Name = "btnCancel" 
        Me.btnCancel.Size = New System.Drawing.Size(64, 24) 
        Me.btnCancel.TabIndex = 80 
        Me.btnCancel.Text = "关闭(&C)" 
        ' 
        'GroupBox1 
        ' 
        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.txtProID) 
        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, 188) 
        Me.GroupBox1.TabIndex = 81 
        Me.GroupBox1.TabStop = False 
        Me.GroupBox1.Text = "成品信息" 
        ' 
        'PictureBox2 
        ' 
        Me.PictureBox2.Image = CType(resources.GetObject("PictureBox2.Image"), System.Drawing.Image) 
        Me.PictureBox2.Location = New System.Drawing.Point(60, 20) 
        Me.PictureBox2.Name = "PictureBox2" 
        Me.PictureBox2.Size = New System.Drawing.Size(61, 61) 
        Me.PictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize 
        Me.PictureBox2.TabIndex = 82 
        Me.PictureBox2.TabStop = False 
        ' 
        'btnReset 
        ' 
        Me.btnReset.Location = New System.Drawing.Point(288, 220) 
        Me.btnReset.Name = "btnReset" 
        Me.btnReset.Size = New System.Drawing.Size(64, 24) 
        Me.btnReset.TabIndex = 83 
        Me.btnReset.Text = "重置(&R)" 
        ' 
        'frmProAdd 
        ' 
        Me.AcceptButton = Me.btnCancel 
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14) 
        Me.ClientSize = New System.Drawing.Size(446, 259) 
        Me.Controls.Add(Me.btnReset) 
        Me.Controls.Add(Me.PictureBox2) 
        Me.Controls.Add(Me.GroupBox1) 
        Me.Controls.Add(Me.btnCancel) 
        Me.Controls.Add(Me.btnAdd) 
        Me.Controls.Add(Me.PictureBox1) 
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog 
        Me.MaximizeBox = False 
        Me.MinimizeBox = False 
        Me.Name = "frmProAdd" 
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent 
        Me.Text = "成品信息添加" 
        Me.GroupBox1.ResumeLayout(False) 
        Me.ResumeLayout(False) 
 
    End Sub 
 
#End Region 
 
    Private Sub frmProAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        txtProID.Enabled = False 
        txtProID.Text = "自动" 
        txtProDate.Enabled = False 
        txtProDate.Text = "系统日期" 
    End Sub 
 
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.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 = "select max(id) from product" 
        Dim myReader As OleDbDataReader 
        myConn.Open() 
        Dim maxIDTemp As Long 
        Dim maxId As Object = myComm.ExecuteScalar() 
        If maxId Is System.DBNull.Value Then 
            maxIDTemp = 10000001 
        Else 
            Dim strid As String 
            strid = CStr(maxId) 
            maxIDTemp = CInt(strid) 
            maxIDTemp = maxIDTemp + 1 
        End If 
        myConn.Close() 
 
        Dim saveComm As OleDbCommand = New OleDbCommand 
        saveComm.CommandText = "insert into product (id,name,model,standard,pdate) values (@id,@name,@model,@standard,@pdate)" 
        saveComm.Connection = myConn 
        saveComm.Parameters.Add("@id", maxIDTemp) 
        saveComm.Parameters.Add("@name", txtProName.Text) 
        saveComm.Parameters.Add("@model", txtProModel.Text) 
        saveComm.Parameters.Add("@standard", cbProStandard.SelectedItem) 
        saveComm.Parameters.Add("@pdate", DateTime.Today) 
        myConn.Open() 
        Try 
            saveComm.ExecuteNonQuery() 
            MsgBox("成品信息添加成功!", MsgBoxStyle.Information, "提示信息") 
            Me.Close() 
        Catch ex As Exception 
            MsgBox(Err.Description) 
        End Try 
    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 btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click 
        txtProName.Text = "" 
        txtProModel.Text = "" 
        cbProStandard.SelectedIndex = -1 
    End Sub 
End Class