Imports System.Data.SqlClient
Public Class Form1
Public employee_ID As String
Dim AddItemValue As New List(Of keypair)
Dim AddItemDate As New List(Of keypair)
Dim gender As String 'แปลงเพศเป็นข้อมูลตัวอักษร
'Dim dy As Integer = DateTimePicker1.Value.Day
'Dim mn As Integer = DateTimePicker1.Value.Month
'Dim yr As Integer = DateTimePicker1.Value.Year
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
setddgender()
End Sub
Private Sub setddGender()
AddItemValue.Add(New keypair("ชาย", "M"))
AddItemValue.Add(New keypair("หญิง", "F"))
For Each AddItemValues As keypair In AddItemValue
ComboBox1.Items.Add(AddItemValues.Name)
Next
End Sub
Private Sub ctrecord_Click(sender As Object, e As EventArgs) Handles ctrecord.Click
Dim Con As New conn()
Dim strCon As New SqlConnection(Con.strConn)
strCon.Open()
Dim start_Date As String
If Len(DateTimePicker1.Text.Trim) > 0 Then
start_Date = DateTimePicker1.Value.ToString().Substring(6, 4) + "/" + DateTimePicker1.Value.ToString().Substring(3, 2) + "/" + DateTimePicker1.Value.ToString().Substring(0, 2)
Else
start_Date = DBNull.Value.ToString
End If
Dim Conm As New SqlCommand("insemployee_data", strCon)
Conm.CommandType = CommandType.StoredProcedure
Conm.Parameters.Add("@employee", SqlDbType.VarChar, 50).Value = TextBox1.Text.Trim
Conm.Parameters.Add("@name", SqlDbType.VarChar, 100).Value = TextBox2.Text.Trim
Conm.Parameters.Add("@startdate", SqlDbType.VarChar).Value = DateTimePicker1
Conm.Parameters.Add("@department", SqlDbType.VarChar, 50).Value = TextBox3.Text.Trim
Conm.Parameters.Add("@sex", SqlDbType.VarChar, 50).Value = ComboBox1
Conm.Parameters.Add("@phon", SqlDbType.VarChar, 50).Value = TextBox4.Text.Trim
Conm.ExecuteNonQuery()
strCon.Close()
clear_text()
viewemployee.Show()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim SelectedText As String = ComboBox1.Items(ComboBox1.SelectedIndex).ToString
For Each AddItemValues As keypair In AddItemValue
If SelectedText = AddItemValues.Name Then
gender = AddItemValues.KeyName
End If
Next
End Sub
Private Sub clear_text()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
DateTimePicker1.Text = ""
ComboBox1.Text = ""
End Sub
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
viewemployee.Show()
End Sub
Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
End Sub
End Class