📄 adddepartment.vb
字号:
Imports System.Data
Imports System.Data.sqlClient
Public Class AddDepartment
Inherits System.Windows.Forms.Form
Dim i As Integer
#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 Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("宋体", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.Location = New System.Drawing.Point(168, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(112, 24)
Me.Label1.TabIndex = 0
Me.Label1.Text = "添加部门"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(64, 64)
Me.Label2.Name = "Label2"
Me.Label2.TabIndex = 1
Me.Label2.Text = "部门名称:"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(64, 104)
Me.Label3.Name = "Label3"
Me.Label3.TabIndex = 2
Me.Label3.Text = "部门代号:"
'
'TextBox1
'
Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.TextBox1.Location = New System.Drawing.Point(168, 64)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(112, 21)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.TextBox2.Location = New System.Drawing.Point(168, 104)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(112, 21)
Me.TextBox2.TabIndex = 4
Me.TextBox2.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(304, 104)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 23)
Me.Button1.TabIndex = 5
Me.Button1.Text = "检测"
'
'Button2
'
Me.Button2.Enabled = False
Me.Button2.Location = New System.Drawing.Point(96, 152)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(64, 23)
Me.Button2.TabIndex = 6
Me.Button2.Text = "确 定"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(296, 152)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(56, 23)
Me.Button3.TabIndex = 7
Me.Button3.Text = "关 闭"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(200, 152)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(56, 23)
Me.Button4.TabIndex = 8
Me.Button4.Text = "清 空"
'
'ComboBox1
'
Me.ComboBox1.Location = New System.Drawing.Point(288, 104)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(0, 20)
Me.ComboBox1.TabIndex = 9
Me.ComboBox1.Text = "ComboBox1"
'
'AddDepartment
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(408, 214)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.MaximizeBox = False
Me.Name = "AddDepartment"
Me.Text = "----------添加部门"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Clear()
TextBox2.Clear()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Close()
End Sub
Private Sub AddDepartment_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
falg = 0
End Sub
Private Sub AddDepartment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each DepartementRow In DepartementDataSet.Tables("T_DEPARTMENT").Rows
Me.ComboBox1.Items.Add(DepartementRow("DEP_CODE"))
Next
Me.ComboBox1.Text = Me.ComboBox1.Items.Item(0)
If TextBox1.Text.Length <> 0 Or TextBox2.Text.Length <> 0 Then
Me.Button4.Enabled = True
Else
Me.Button4.Enabled = False
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
myConnStr = connstr()
myConnetion = New SqlConnection(myConnStr)
myConnetion.Open()
myCommand = New SqlCommand("INSERT INTO T_DEPARTMENT VALUES(@DEP_CODE,@TYPE_NAME)", myConnetion)
myCommand.Parameters.Add(New SqlParameter("@DEP_CODE", SqlDbType.Char, 1))
myCommand.Parameters("@DEP_CODE").Value = TextBox2.Text
myCommand.Parameters.Add(New SqlParameter("@TYPE_NAME", SqlDbType.Char, 20))
myCommand.Parameters("@TYPE_NAME").Value = TextBox1.Text
Dim im As Integer
myCommand.ExecuteNonQuery()
MsgBox("新部门创建成功!!!")
TextBox1.Clear()
TextBox2.Clear()
Catch ex As Exception
MsgBox("对不起!!! " & Chr(10) & "您新创建的部门失败.....")
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text.Length <> 0 And TextBox2.Text.Length <> 0 Then
For i = 0 To ComboBox1.Items.Count - 1
'MsgBox(TextBox2.Text.Trim())
'MsgBox(ComboBox1.Items.Item(i))
If TextBox2.Text.Trim() = ComboBox1.Items.Item(i) Then
MsgBox("对不起!!!" & Chr(10) & TextBox2.Text & "已经被创建" & "请从新创建一个代号....")
Me.Button2.Enabled = False
Exit Sub
Else
End If
Next
MsgBox("恭喜您!!! " & Chr(10) & TextBox2.Text & "还没有被占用,你可以用" & TextBox2.Text & "做为" & TextBox1.Text & "的代号")
Me.Button2.Enabled = True
Else
Me.Button2.Enabled = False
MsgBox("资产名称和代号不能为空......")
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text.Length <> 0 Or TextBox2.Text.Length <> 0 Then
Me.Button4.Enabled = True
Else
Me.Button4.Enabled = False
End If
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
If TextBox1.Text.Length <> 0 Or TextBox2.Text.Length <> 0 Then
Me.Button4.Enabled = True
Else
Me.Button4.Enabled = False
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -