sb = New StringBuilder()
sb.Append("SELECT * FROM tbl_preT;")
sb.Append("SELECT * FROM tbl_preE;")
sb.Append("SELECT * FROM tbl_type;")
sb.Append("SELECT * FROM tbl_campus;")
sb.Append("SELECT * FROM tbl_dep1 ORDER BY dep1Name;")
sb.Append("SELECT * FROM tbl_dep2 ORDER BY dep2Name;")
Dim sqlIni As String
sqlIni = sb.ToString()
RemoveHandler cboPreT.SelectedValueChanged, AddressOf cboPreT_SelectedValueChanged
RemoveHandler cboPreE.SelectedValueChanged, AddressOf cboPreE_SelectedValueChanged
RemoveHandler cboCampus.SelectedValueChanged, AddressOf cboCampus_SelectedValueChanged
RemoveHandler cboDep1.SelectedValueChanged, AddressOf cboDep1_SelectedValueChanged
RemoveHandler cboDep2.SelectedValueChanged, AddressOf cboDep2_SelectedValueChanged
RemoveHandler cboType.SelectedValueChanged, AddressOf cboType_SelectedValueChanged
com = New SqlCommand()
With com
.CommandText = sqlIni
.CommandType = CommandType.Text
.Connection = Conn
dr = .ExecuteReader()
If dr.HasRows Then
dtPreT = New DataTable
dtPreT.Load(dr)
With cboPreT
.BeginUpdate()
.DisplayMember = "preTNameS"
.ValueMember = "preTID"
.DataSource = dtPreT
.EndUpdate()
End With
dtPreE = New DataTable
dtPreE.Load(dr)
With cboPreE
.BeginUpdate()
.DisplayMember = "preENameS"
.ValueMember = "preEID"
.DataSource = dtPreE
.EndUpdate()
End With
dtType = New DataTable
dtType.Load(dr)
With cboType
.BeginUpdate()
.DisplayMember = "typeName"
.ValueMember = "typeID"
.DataSource = dtType
.EndUpdate()
End With
dtCampus = New DataTable
dtCampus.Load(dr)
With cboCampus
.BeginUpdate()
.DisplayMember = "CampusNameS"
.ValueMember = "campusID"
.DataSource = dtCampus
.EndUpdate()
End With
dtDep1 = New DataTable
dtDep1.Load(dr)
With cboDep1
.BeginUpdate()
.DisplayMember = "dep1Name"
.ValueMember = "dep1ID"
.DataSource = dtDep1
.EndUpdate()
End With
dtDep2 = New DataTable
dtDep2.Load(dr)
da = New SqlDataAdapter(sqlIni, Conn)
da.Fill(ds, "tbl_dep1")
With cboDep2
.BeginUpdate()
.DisplayMember = "dep2Name"
.ValueMember = "dep2ID"
' .DataSource = dtDep2
.DataSource = ds.Tables("tbl_dep1")
.EndUpdate()
End With
Private Subh cboDep1_SelectedValueCanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboDep1.SelectedValueChanged
Dim strConn As String
strConn = DBConnString.strConn
Conn = New SqlConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
sb = New StringBuilder()
sb.Append("SELECT * FROM tbl_dep1;")
sb.Append("WHERE dep1ID ='" & cboDep2.SelectedValue.ToString & "'")
Dim sqlIni As String
sqlIni = sb.ToString()
Dim sqlSelect As String = ""
If isFind2 = True Then
ds.Tables("tbl_dep1").Clear()
End If
da = New SqlDataAdapter(sqlSelect, Conn)
da.Fill(ds, "tbl_dep1")
With cboCampus
.DataSource = ds.Tables("tbl_dep1")
.DisplayMember = "dep1Name"
.ValueMember = "dep1ID"
End With
isFind2 = True
iDep1.SelectedValue = cboDep1.SelectedValue
End Sub
Tag : .NET, MySQL, Ms SQL Server 2005, VS 2005 (.NET 2.x)
dtDep2 = New DataTable
dtDep2.Load(dr)
da = New SqlDataAdapter(sqlIni, Conn)
da.Fill(ds, "tbl_dep1")
With cboDep2
.BeginUpdate()
.DisplayMember = "dep2Name"
.ValueMember = "dep2ID"
.DataSource = dtDep2
'.DataSource = ds.Tables("tbl_dep1")
.EndUpdate()
End With
sb.Append("SELECT * FROM tbl_dep1;") ให้เปลี่ยนเป็น sb.Append("SELECT * FROM tbl_dep1 ")
(บรรทัดที่ 13 ของ Code ชุด 2)
แต่ก็ยังเหมือนเดิมค่ะ
อันนี้
โค้ดทั้งหมดค่ะ
Code (VB.NET)
Option Explicit On
Option Strict On
Imports System.IO
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing.Drawing2D
Imports System.Drawing.Printing
Public Class frmPeople
Dim Conn As SqlConnection
Dim com As SqlCommand
Dim dr As SqlDataReader
Dim dtPreT As DataTable
Dim dtPreE As DataTable
Dim dtType As DataTable
Dim dtCampus As DataTable
Dim dtDep1 As DataTable
Dim dtDep2 As DataTable
' Dim dtPrivilege As DataTable
Dim dtPeople As DataTable
Dim bs As BindingSource = New BindingSource()
Dim tr As SqlTransaction
Dim sb As StringBuilder
Dim AllPeople As Integer = 0
Dim TeacherPeople As Integer = 0
Dim StaffPeople As Integer = 0
Dim OtherPeople As Integer = 0
Dim ActionFlag As String
Dim Duration As Integer = 0
Dim SearchPeople As String = "0"
Dim SubjectDetail As String = "0"
Dim fs As FileStream
Dim CurrentImage() As Byte
Dim peoplePicture As String
Dim IsPictureChange As Boolean = False
Dim UseFont As New Font("MS Sans Serif", 10)
' Dim prDoc As PrintDocument = New PrintDocument
Dim prDlg As PrintDialog = New PrintDialog
Dim CustomerTypeName As String
Dim sw As New Stopwatch()
Dim ProcessTime As Double
Dim _ToolStripLabel As New ToolStripLabel
Dim iCustomerID As New TextBox
Dim iFnameT As New TextBox
Dim iFnameE As New TextBox
Dim iLnameT As New TextBox
Dim iLnameE As New TextBox
Dim iSname As New TextBox
Dim itel As New TextBox
Dim imobile As New TextBox
Dim iposition As New TextBox
Dim iemailU1 As New TextBox
Dim iemailU2 As New TextBox
Dim iemailP1 As New TextBox
Dim iemailP2 As New TextBox
Dim itoStudy As New TextBox
Dim itoWork As New TextBox
Dim itoPortfolio As New TextBox
Dim iRemark As New TextBox
Dim iPreT As New ComboBox
Dim iPreE As New ComboBox
Dim iSex As New ComboBox
Dim iCampus As New ComboBox
Dim iDep1 As New ComboBox
Dim iDep2 As New ComboBox
Dim iType As New ComboBox
Dim iMale As New RadioButton
Dim iFemale As New RadioButton
' Dim iSearchPeople As Boolean = False
Dim iSubjectDetail As Boolean = False
' Dim iFrmSearchPeople As frmSearchPeople
Dim iFrmSubjectDetail As frmSubjectDetail
Dim isFind2 As Boolean = False
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
Public Sub New(ByRef refToolStripLabel As ToolStripLabel)
InitializeComponent()
_ToolStripLabel = refToolStripLabel
End Sub
Public Sub New(ByRef _SubjectDetail As Boolean, ByRef _Male As RadioButton, ByRef _Female As RadioButton, ByRef _CustomerID As TextBox, ByRef _FnameT As TextBox, ByRef _FnameE As TextBox, ByRef _LnameT As TextBox, ByRef _LnameE As TextBox, ByRef _Sname As TextBox, ByRef _mobile As TextBox, ByRef _tel As TextBox, ByRef _position As TextBox, ByRef _Remark As TextBox, ByRef _toStudy As TextBox, ByRef _toWork As TextBox, ByRef _toPortfolio As TextBox, ByRef _emailP1 As TextBox, ByRef _emailP2 As TextBox, ByRef _emailU1 As TextBox, ByRef _emailU2 As TextBox, ByRef _PreT As ComboBox, ByRef _Type As ComboBox, ByRef _PreE As ComboBox, ByRef _Dep1 As ComboBox, ByRef _Dep2 As ComboBox, ByRef _Dep4 As ComboBox, ByRef _Campus As ComboBox, ByRef value As frmSubjectDetail)
InitializeComponent()
iSubjectDetail = _SubjectDetail
iFrmSubjectDetail = value
iCustomerID = _CustomerID
iFnameT = _FnameT
iFnameE = _FnameE
iLnameT = _LnameT
iLnameE = _LnameE
iSname = _Sname
imobile = _mobile
itel = _tel
iemailU1 = _emailU1
iemailU2 = _emailU2
iemailP1 = _emailP1
iemailP2 = _emailP2
iPreT = _PreT
iPreE = _PreE
iDep1 = _Dep1
iDep2 = _Dep2
iType = _Type
iMale = _Male
iFemale = _Female
iposition = _position
iCampus = _Campus
iRemark = _Remark
itoStudy = _toStudy
itoWork = _toWork
itoPortfolio = _toPortfolio
End Sub
Private Sub txtCustomerID_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCustomerID.TextChanged
iCustomerID.Text = lblPeopleID.Text()
End Sub
Private Sub cboPreT_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPreT.SelectedValueChanged
iPreT.SelectedValue = cboPreT.SelectedValue
End Sub
Private Sub cboPreE_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPreE.SelectedValueChanged
iPreE.SelectedValue = cboPreE.SelectedValue
End Sub
Private Sub cboDep1_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboDep1.SelectedValueChanged
Dim strConn As String
strConn = DBConnString.strConn
Conn = New SqlConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
sb = New StringBuilder()
sb.Append("SELECT * FROM tbl_dep1")
sb.Append("WHERE dep1ID ='" & cboDep2.SelectedValue.ToString & "'")
Dim sqlIni As String
sqlIni = sb.ToString()
Dim sqlSelect As String = ""
If isFind2 = True Then
ds.Tables("tbl_dep1").Clear()
End If
da = New SqlDataAdapter(sqlSelect, Conn)
da.Fill(ds, "tbl_dep1")
With cboCampus
.DataSource = ds.Tables("tbl_dep1")
.DisplayMember = "dep1Name"
.ValueMember = "dep1ID"
End With
isFind2 = True
iDep1.SelectedValue = cboDep1.SelectedValue
End Sub
Private Sub cboDep2_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboDep2.SelectedValueChanged
iDep2.SelectedValue = cboDep2.SelectedValue
End Sub
Private Sub cboType_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
iType.SelectedValue = cboType.SelectedValue
End Sub
Private Sub txtFnameT_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFnameT.TextChanged
iFnameT.Text = txtFnameT.Text
End Sub
Private Sub txtLnameT_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLnameT.TextChanged
iLnameT.Text = txtLnameT.Text
End Sub
Private Sub txtFnameE_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFnameE.TextChanged
iFnameE.Text = txtFnameE.Text
End Sub
Private Sub txtLnameE_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLnameE.TextChanged
iLnameE.Text = txtLnameE.Text
End Sub
Private Sub txtSname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSname.TextChanged
iSname.Text = txtSname.Text
End Sub
Private Sub txtemailU1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtemailU1.TextChanged
iemailU1.Text = txtemailU1.Text
End Sub
Private Sub txtemailU2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtemailU2.TextChanged
iemailU2.Text = txtemailU2.Text
End Sub
Private Sub txtemailP1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtemailP1.TextChanged
iemailP1.Text = txtemailP1.Text
End Sub
Private Sub txtemailP2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtemailP2.TextChanged
iemailP2.Text = txtemailP2.Text
End Sub
Private Sub optMale_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optMale.CheckedChanged
iMale.Checked = optMale.Checked
End Sub
Private Sub optFemale_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optFemale.CheckedChanged
iFemale.Checked = optFemale.Checked
End Sub
Private Sub frmPeople_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblPeopleID.BackColor = Color.FromArgb(0, 0, 0, 0)
Dim FD As New FormFader
FD.FadeIn(Me, 0.25)
sw.Reset()
sw.Start()
Dim strConn As String
strConn = DBConnString.strConn
Conn = New SqlConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
sb = New StringBuilder()
sb.Append("SELECT * FROM tbl_preT;")
sb.Append("SELECT * FROM tbl_preE;")
sb.Append("SELECT * FROM tbl_type;")
sb.Append("SELECT * FROM tbl_campus;")
sb.Append("SELECT * FROM tbl_dep1 ORDER BY dep1Name;")
sb.Append("SELECT * FROM tbl_dep2 ORDER BY dep2Name;")
Dim sqlIni As String
sqlIni = sb.ToString()
RemoveHandler cboPreT.SelectedValueChanged, AddressOf cboPreT_SelectedValueChanged
RemoveHandler cboPreE.SelectedValueChanged, AddressOf cboPreE_SelectedValueChanged
RemoveHandler cboCampus.SelectedValueChanged, AddressOf cboCampus_SelectedValueChanged
RemoveHandler cboDep1.SelectedValueChanged, AddressOf cboDep1_SelectedValueChanged
RemoveHandler cboDep2.SelectedValueChanged, AddressOf cboDep2_SelectedValueChanged
RemoveHandler cboType.SelectedValueChanged, AddressOf cboType_SelectedValueChanged
com = New SqlCommand()
With com
.CommandText = sqlIni
.CommandType = CommandType.Text
.Connection = Conn
dr = .ExecuteReader()
If dr.HasRows Then
dtPreT = New DataTable
dtPreT.Load(dr)
With cboPreT
.BeginUpdate()
.DisplayMember = "preTNameS"
.ValueMember = "preTID"
.DataSource = dtPreT
.EndUpdate()
End With
dtPreE = New DataTable
dtPreE.Load(dr)
With cboPreE
.BeginUpdate()
.DisplayMember = "preENameS"
.ValueMember = "preEID"
.DataSource = dtPreE
.EndUpdate()
End With
dtType = New DataTable
dtType.Load(dr)
With cboType
.BeginUpdate()
.DisplayMember = "typeName"
.ValueMember = "typeID"
.DataSource = dtType
.EndUpdate()
End With
dtCampus = New DataTable
dtCampus.Load(dr)
With cboCampus
.BeginUpdate()
.DisplayMember = "CampusNameS"
.ValueMember = "campusID"
.DataSource = dtCampus
.EndUpdate()
End With
dtDep1 = New DataTable
dtDep1.Load(dr)
With cboDep1
.BeginUpdate()
.DisplayMember = "dep1Name"
.ValueMember = "dep1ID"
.DataSource = dtDep1
.EndUpdate()
End With
dtDep2 = New DataTable
dtDep2.Load(dr)
da = New SqlDataAdapter(sqlIni, Conn)
da.Fill(ds, "tbl_dep1")
With cboDep2
.BeginUpdate()
.DisplayMember = "dep2Name"
.ValueMember = "dep2ID"
.DataSource = dtDep2
'.DataSource = ds.Tables("tbl_dep1")
.EndUpdate()
End With
End If
End With
dr.Close()
AddHandler cboPreT.SelectedValueChanged, AddressOf cboPreT_SelectedValueChanged
AddHandler cboPreE.SelectedValueChanged, AddressOf cboPreE_SelectedValueChanged
AddHandler cboCampus.SelectedValueChanged, AddressOf cboCampus_SelectedValueChanged
AddHandler cboDep1.SelectedValueChanged, AddressOf cboDep1_SelectedValueChanged
AddHandler cboDep2.SelectedValueChanged, AddressOf cboDep2_SelectedValueChanged
AddHandler cboType.SelectedValueChanged, AddressOf cboType_SelectedValueChanged
iPreT.SelectedValue = cboPreT.SelectedValue
iPreE.SelectedValue = cboPreE.SelectedValue
iCampus.SelectedValue = cboCampus.SelectedValue
iDep1.SelectedValue = cboDep1.SelectedValue
iDep2.SelectedValue = cboDep2.SelectedValue
iType.SelectedValue = cboType.SelectedValue
With cboSearch
.Items.Add("รหัสบุคคล")
.Items.Add("ชื่อบุคคล(ภาษาไทย)")
.Items.Add("ชื่อบุคคล(ภาษาอังกฤษ)")
' .Items.Add("คณะ")
' .Items.Add("ภาควิชา")
.Items.Add("เบอร์โทรศัพท์มือถือ")
.SelectedIndex = 1
End With
cboPreT.ContextMenu = New ContextMenu()
cboPreE.ContextMenu = New ContextMenu()
cboCampus.ContextMenu = New ContextMenu()
cboDep1.ContextMenu = New ContextMenu()
cboDep2.ContextMenu = New ContextMenu()
cboType.ContextMenu = New ContextMenu()
picPeople.Image = picPeople.ErrorImage
' dtpAdmitDate.Value = DateTime.Today()
ClearCustomer()
tsAdd.Enabled = True
tsOK.Enabled = False
' tsCancel.Enabled = False
sw.Stop()
ProcessTime = sw.ElapsedMilliseconds / 1000
_ToolStripLabel.Text = "เวลาที่ใช้ : " & ProcessTime.ToString("0.0000") & "วินาที"
If (iSubjectDetail = False) Then
bgwPeople.RunWorkerAsync()
End If
End Sub
Private Sub ClearCustomer()
lblPeopleID.Text = ""
txtCustomerID.Text = ""
txtFnameT.Text = ""
txtFnameE.Text = ""
txtLnameT.Text = ""
txtLnameE.Text = ""
txtSname.Text = ""
txtposition.Text = ""
txttoStudy.Text = ""
txttoWork.Text = ""
txttoPortfolio.Text = ""
optMale.Checked = True
txttel.Text = ""
txtRemark.Text = ""
txtmobile.Text = ""
txtemailP1.Text = ""
txtemailP2.Text = ""
txtemailU1.Text = ""
txtemailU2.Text = ""
'dtpAdmitDate.Value = DateTime.Today()
peoplePicture = ""
picPeople.Image = picPeople.ErrorImage
CurrentImage = Nothing
End Sub
Private Sub bgwPeople_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwPeople.DoWork
Dim comCount As SqlCommand
comCount = New SqlCommand()
With comCount
.CommandType = CommandType.Text
.Connection = Conn
End With
sb.Remove(0, sb.Length())
sb.Append("SELECT typeID,COUNT(peopleID) AS NumberPeople")
sb.Append(" FROM tbl_people")
sb.Append(" GROUP BY typeID")
sb.Append(" ORDER BY typeID")
Dim sqlPeople As String
sqlPeople = sb.ToString()
AllPeople = 0 'สมาชิกทั้งหมด AllCustomer
TeacherPeople = 0 'อาจารย์ NormalCustomer
StaffPeople = 0 'บุคลากร MemberCustomer
OtherPeople = 0 'บุคคลภายนอก / วิทยากร VIPCustomer
Dim drCount As SqlDataReader
With comCount
.CommandText = sqlPeople
drCount = .ExecuteReader()
With drCount
If .HasRows Then
Do While .Read()
If .GetString(0) = "0000" Then
TeacherPeople = .GetInt32(1)
End If
If .GetString(0) = "0001" Then
StaffPeople = .GetInt32(1)
End If
If .GetString(0) = "0002" Then
OtherPeople = .GetInt32(1)
End If
Loop
Else
AllPeople = 0 'สมาชิกทั้งหมด AllCustomer
TeacherPeople = 0 'อาจารย์ NormalCustomer
StaffPeople = 0 'บุคลากร MemberCustomer
OtherPeople = 0 'บุคคลภายนอก / วิทยากร VIPCustomer
End If
End With
End With
AllPeople = TeacherPeople + StaffPeople + OtherPeople
bgwPeople.ReportProgress(100)
drCount.Close()
End Sub
Private Sub bgwPeople_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles bgwPeople.ProgressChanged
tsPgbProcess.Value = e.ProgressPercentage()
End Sub
Private Sub bgwPeople_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgwPeople.RunWorkerCompleted
If e.Error Is Nothing Then
tsAllPeople.Text = "บุคคลทั้งหมด : " & AllPeople.ToString("#,##0") & "คน (คณาจารย์มจธ. : " & TeacherPeople.ToString("#,##0") & ") " & "(บุคลากรภายใน : " & StaffPeople.ToString("#,##0") & ") " & "(บุคคลภายนอก/วิทยากร : " & OtherPeople.ToString("#,##0") & ") "
Else
tsAllPeople.Text = "บุคคลทั้งหมด 0 คน(ปกติ : 0 คน) (คณาจารย์มจธ. : 0 คน) (บุคคลภายนอก/วิทยากร : 0 คน)"
End If
End Sub
Private Sub tsSearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tsSearch.KeyDown
If e.KeyCode = Keys.Enter Then
If tsSearch.Text.Trim() = "" Then Exit Sub
sw.Reset()
sw.Start()
sb.Remove(0, sb.Length())
sb.Append("SELECT * FROM tbl_people")
Select Case cboSearch.SelectedIndex
Case 0
sb.Append(" WHERE (peopleID=@peopleID)")
Case 1
sb.Append(" WHERE (FnameT LIKE @FnameT)")
Case 2
sb.Append(" WHERE (FnameE LIKE @FnameE)")
Case 3
sb.Append(" WHERE (mobile LIKE @mobile)")
End Select
sb.Append("ORDER BY FnameT")
Dim sqlSearch As String
sqlSearch = sb.ToString()
dtPeople = New DataTable()
With com
.Parameters.Clear()
Select Case cboSearch.SelectedIndex
Case 0
.Parameters.Add("@peopleID", SqlDbType.NVarChar).Value = tsSearch.Text.Trim()
Case 1
.Parameters.Add("@FnameT", SqlDbType.NVarChar).Value = "%" & tsSearch.Text.Trim() & "%"
Case 2
.Parameters.Add("@FnameE", SqlDbType.NVarChar).Value = "%" & tsSearch.Text.Trim() & "%"
Case 3
.Parameters.Add("@mobile", SqlDbType.NVarChar).Value = "%" & tsSearch.Text.Trim() & "%"
End Select
.CommandText = sqlSearch
.CommandType = CommandType.Text
.Connection = Conn
dr = .ExecuteReader
If dr.HasRows Then
ClearBinding()
ActionFlag = "EDIT"
dtPeople.Load(dr)
bs.DataSource = dtPeople
bn.BindingSource = bs
lblPeopleID.DataBindings.Add("Text", bs, "peopleID")
txtCustomerID.DataBindings.Add("Text", bs, "peopleID")
ShowPosition()
With cboPreT
.DisplayMember = "preTNameS"
.ValueMember = "preTID"
.DataBindings.Add("SelectedValue", bs, "preTID")
.DataSource = dtPreT
End With
With cboPreE
.DisplayMember = "preENameS"
.ValueMember = "preEID"
.DataBindings.Add("SelectedValue", bs, "preEID")
.DataSource = dtPreE
End With
With cboDep1
.DisplayMember = "dep1Name"
.ValueMember = "dep1ID"
.DataBindings.Add("SelectedValue", bs, "dep1ID")
.DataSource = dtDep1
End With
With cboDep2
.DisplayMember = "dep2Name"
.ValueMember = "dep2ID"
.DataBindings.Add("SelectedValue", bs, "dep2ID")
.DataSource = dtDep2
End With
With cboType
.DisplayMember = "typeName"
.ValueMember = "typeID"
.DataBindings.Add("SelectedValue", bs, "typeID")
.DataSource = dtType
End With
With cboCampus
.DisplayMember = "campusNameS"
.ValueMember = "campusID"
.DataBindings.Add("SelectedValue", bs, "campusID")
.DataSource = dtCampus
End With
txtFnameT.DataBindings.Add("Text", bs, "FnameT")
txtFnameE.DataBindings.Add("Text", bs, "FnameE")
txtLnameT.DataBindings.Add("Text", bs, "LnameT")
txtLnameE.DataBindings.Add("Text", bs, "LnameE")
txtSname.DataBindings.Add("Text", bs, "Sname")
txttel.DataBindings.Add("Text", bs, "tel")
txtRemark.DataBindings.Add("Text", bs, "Remark")
txtmobile.DataBindings.Add("Text", bs, "mobile")
txtemailP1.DataBindings.Add("Text", bs, "emailP1")
txtemailP2.DataBindings.Add("Text", bs, "emailP2")
txtemailU1.DataBindings.Add("Text", bs, "emailU1")
txtemailU2.DataBindings.Add("Text", bs, "emailU2")
txtposition.DataBindings.Add("Text", bs, "position")
txttoStudy.DataBindings.Add("Text", bs, "toStudy")
txttoWork.DataBindings.Add("Text", bs, "toWork")
txttoPortfolio.DataBindings.Add("Text", bs, "toPortfolio")
picPeople.DataBindings.Add("Image", bs, "peoplePicture", True, DataSourceUpdateMode.Never, picPeople.ErrorImage)
bn.Enabled = True
tsAdd.Enabled = True
tsOK.Enabled = True
'tsCancel.Enabled = True
Else
ClearCustomer()
tsAdd.Enabled = True
tsOK.Enabled = False
' tsCancel.Enabled = False
bn.BindingSource = Nothing
bn.Enabled = False
bnRecord.Text = "0"
bnCount.Text = "0"
MessageBox.Show("เงื่อนไขที่คุณป้อน ไม่มี", "ผลการค้นหา", MessageBoxButtons.OK, MessageBoxIcon.Information)
tsSearch.Focus()
tsSearch.SelectAll()
End If
End With
sw.Stop()
ProcessTime = sw.ElapsedMilliseconds / 1000
_ToolStripLabel.Text = "เวลาที่ใช้ : " & ProcessTime.ToString("0.0000") & "วินาที"
dr.Close()
End If
End Sub
Private Sub ClearBinding()
lblPeopleID.DataBindings.Clear()
txtCustomerID.DataBindings.Clear()
cboPreT.DataBindings.Clear()
cboPreE.DataBindings.Clear()
txtFnameT.DataBindings.Clear()
txtFnameE.DataBindings.Clear()
txtLnameT.DataBindings.Clear()
txtLnameE.DataBindings.Clear()
txtSname.DataBindings.Clear()
cboType.DataBindings.Clear()
cboCampus.DataBindings.Clear()
cboDep1.DataBindings.Clear()
cboDep2.DataBindings.Clear()
txtposition.DataBindings.Clear()
txttel.DataBindings.Clear()
txtmobile.DataBindings.Clear()
txtRemark.DataBindings.Clear()
txtemailU1.DataBindings.Clear()
txtemailU2.DataBindings.Clear()
txtemailP1.DataBindings.Clear()
txtemailP2.DataBindings.Clear()
txttoStudy.DataBindings.Clear()
txttoWork.DataBindings.Clear()
txttoPortfolio.DataBindings.Clear()
picPeople.DataBindings.Clear()
End Sub
Private Sub bnMoveFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnMoveFirst.Click
ShowPosition()
End Sub
Private Sub bnMovePrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnMovePrevious.Click
ShowPosition()
End Sub
Private Sub bnMoveNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnMoveNext.Click
ShowPosition()
End Sub
Private Sub bnMoveLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnMoveLast.Click
ShowPosition()
End Sub
Private Sub ShowPosition()
Dim CurrentRecord As Integer
If bs.Count > 0 Then
CurrentRecord = bs.Position + 1
bnRecord.Text = CStr(CurrentRecord)
If CStr(dtPeople.Rows(CurrentRecord - 1).Item("Sex")) = "M" Then
optMale.Checked = True
ElseIf CStr(dtPeople.Rows(CurrentRecord - 1).Item("Sex")) = "F" Then
optFemale.Checked = True
End If
Else
CurrentRecord = 0
bnRecord.Text = "0"
bnCount.Text = "0"
End If
End Sub
Private Sub picPeople_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picPeople.Click
With ofDlg
.Title = "เลือกไฟล์รูปภาพ"
.Filter = "Bitmap (*.bmp)|*.bmp"
.FileName = ""
.Multiselect = False
.FilterIndex = 0
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
peoplePicture = .FileName
picPeople.Image = Image.FromFile(peoplePicture)
Else
peoplePicture = ""
picPeople.Image = picPeople.ErrorImage
End If
End With
End Sub
Private Sub cmdDeleteImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDeleteImage.Click
peoplePicture = ""
picPeople.Image = picPeople.ErrorImage
End Sub
Private Sub tsAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsAdd.Click
ActionFlag = "ADD"
ClearCustomer()
tsAdd.Enabled = False
tsOK.Enabled = True
' tsCancel.Enabled = True
bn.Enabled = False
bnRecord.Text = "0"
bnCount.Text = "0"
tsSearch.Enabled = False
txtFnameT.Focus()
End Sub
Private Sub tsOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsOK.Click
If (txtFnameT.Text.Trim() = "") OrElse (txtFnameE.Text.Trim() = "") Then
MessageBox.Show("กรุณาป้อนข้อมูลให้ครบ", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtFnameT.Focus()
Exit Sub
End If
If MessageBox.Show("คุณต้องการบันทึกข้อมูลใหม่ ใช่หรือไม่", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
sw.Reset()
sw.Start()
tr = Conn.BeginTransaction()
If peoplePicture <> "" Then
fs = New FileStream(peoplePicture, FileMode.Open, FileAccess.Read)
ReDim CurrentImage(CInt(fs.Length))
fs.Read(CurrentImage, 0, CInt(fs.Length - 1))
fs.Close()
End If
Dim sqlOK As String
Dim NewID As String
Dim FirstID As String
Dim LastID As Long
Try
Select Case ActionFlag
Case "ADD"
sb.Remove(0, sb.Length())
sb.Append("SELECT TOP 1 peopleID FROM tbl_people")
sb.Append(" WHERE (typeID=@typeID)")
sb.Append(" ORDER BY peopleID DESC")
sqlOK = sb.ToString()
With com
.Parameters.Clear()
.Parameters.Add("@typeID", SqlDbType.NVarChar).Value = cboType.SelectedValue.ToString()
.CommandText = sqlOK
.Transaction = tr
dr = .ExecuteReader()
If dr.HasRows Then
With dr
.Read()
NewID = .GetString(.GetOrdinal("peopleID"))
End With
FirstID = StringExt.StringFromLeft(NewID, 4)
LastID = CLng(StringExt.StringFromRight(NewID, 6))
LastID += 1
lblPeopleID.Text = String.Format(FirstID, "0000") & LastID.ToString("000000")
txtCustomerID.Text = lblPeopleID.Text
Else
lblPeopleID.Text = CStr(cboType.SelectedValue) & "003400"
txtCustomerID.Text = lblPeopleID.Text
End If
dr.Close()
sb.Remove(0, sb.Length())
sb.Append("INSERT INTO tbl_people (peopleID,FnameT,LnameT,preTID,preEID,")
sb.Append(" FnameE,LnameE,Sname,Sex,dep1ID,dep2ID,CampusID,tel,position,mobile,Remark,toStudy,toWork,toPortfolio,emailU1,emailU2,emailP1,emailP2,")
If peoplePicture <> "" Then
sb.Append("peoplePicture,")
End If
sb.Append(" typeID)")
sb.Append(" VALUES (@peopleID,@FnameT,@LnameT,@preTID,@preEID,")
sb.Append(" @FnameE,@LnameE,@Sname,@Sex,@dep1ID,@dep2ID,@CampusID,@tel,@position,@mobile,@Remark,@toStudy,@toWork,@toPortfolio,@emailU1,@emailU2,@emailP1,@emailP2,")
If peoplePicture <> "" Then
sb.Append(" @peoplePicture,")
End If
sb.Append(" @typeID)")
sqlOK = sb.ToString
.CommandText = sqlOK
.Parameters.Clear()
.Parameters.Add("@peopleID", SqlDbType.NVarChar).Value = lblPeopleID.Text
.Parameters.Add("@preTID", SqlDbType.NVarChar).Value = CStr(cboPreT.SelectedValue)
.Parameters.Add("@preEID", SqlDbType.NVarChar).Value = CStr(cboPreE.SelectedValue)
.Parameters.Add("@typeID", SqlDbType.NVarChar).Value = CStr(cboType.SelectedValue)
.Parameters.Add("@campusID", SqlDbType.NVarChar).Value = CStr(cboCampus.SelectedValue)
.Parameters.Add("@dep1ID", SqlDbType.NVarChar).Value = CStr(cboDep1.SelectedValue)
.Parameters.Add("@dep2ID", SqlDbType.NVarChar).Value = CStr(cboDep2.SelectedValue)
.Parameters.Add("@FnameT", SqlDbType.NVarChar).Value = txtFnameT.Text.Trim()
.Parameters.Add("@FnameE", SqlDbType.NVarChar).Value = txtFnameE.Text.Trim()
.Parameters.Add("@LnameT", SqlDbType.NVarChar).Value = txtLnameT.Text.Trim()
.Parameters.Add("@LnameE", SqlDbType.NVarChar).Value = txtLnameE.Text.Trim()
.Parameters.Add("@Sname", SqlDbType.NVarChar).Value = txtSname.Text.Trim()
.Parameters.Add("@tel", SqlDbType.NVarChar).Value = txttel.Text.Trim()
.Parameters.Add("@Remark", SqlDbType.NVarChar).Value = txtRemark.Text.Trim()
.Parameters.Add("@mobile", SqlDbType.NVarChar).Value = txtmobile.Text.Trim()
.Parameters.Add("@emailU1", SqlDbType.NVarChar).Value = txtemailU1.Text.Trim()
.Parameters.Add("@emailU2", SqlDbType.NVarChar).Value = txtemailU2.Text.Trim()
.Parameters.Add("@emailP1", SqlDbType.NVarChar).Value = txtemailP1.Text.Trim()
.Parameters.Add("@emailP2", SqlDbType.NVarChar).Value = txtemailP2.Text.Trim()
.Parameters.Add("@position", SqlDbType.NVarChar).Value = txtposition.Text.Trim()
.Parameters.Add("@toStudy", SqlDbType.NVarChar).Value = txttoStudy.Text.Trim()
.Parameters.Add("@toWork", SqlDbType.NVarChar).Value = txttoWork.Text.Trim()
.Parameters.Add("@toPortfolio", SqlDbType.NVarChar).Value = txttoPortfolio.Text.Trim()
If optMale.Checked = True Then
.Parameters.Add("@Sex", SqlDbType.NVarChar).Value = "F"
Else
.Parameters.Add("@Sex", SqlDbType.NVarChar).Value = "M"
End If
If peoplePicture <> "" Then
.Parameters.Add("@peoplePicture", SqlDbType.Image).Value = CurrentImage
End If
.ExecuteNonQuery()
End With
Case "EDIT"
sb.Remove(0, sb.Length())
sb.Append("UPDATE tbl_people")
sb.Append(" SET preTID=@preTID,")
sb.Append(" preEID=@preEID,")
sb.Append(" FnameT=@FnameT,")
sb.Append(" LnameT=@LnameT,")
sb.Append(" FnameE=@FnameE,")
sb.Append(" LnameE=@LnameE,")
sb.Append(" Sname=@Sname,")
sb.Append(" Sex=@Sex,")
sb.Append(" typeID=@typeID,")
sb.Append(" campusID=@campusID,")
sb.Append(" dep1ID=@dep1ID,")
sb.Append(" dep2ID=@dep2ID,")
sb.Append(" tel=@tel,")
sb.Append(" mobile=@mobile,")
sb.Append(" emailU1=@emailU1,")
sb.Append(" emailU2=@emailU2,")
sb.Append(" emailP1=@emailP1,")
sb.Append(" emailP2=@emailP2,")
sb.Append(" position=@position,")
sb.Append(" Remark=@Remark,")
sb.Append(" toStudy=@toStudy,")
sb.Append(" toWork=@toWork,")
sb.Append(" toPortfolio=@toPortfolio")
sb.Append(" WHERE (peopleID=@peopleID)")
'Dim sqlOK As String
sqlOK = sb.ToString
With com
.CommandText = sqlOK
.Transaction = tr
.Parameters.Clear()
' .Parameters.Add("@peopleID", SqlDbType.NVarChar).Value = lblPeopleID.Text
.Parameters.Add("@preTID", SqlDbType.NVarChar).Value = CStr(cboPreT.SelectedValue)
.Parameters.Add("@preEID", SqlDbType.NVarChar).Value = CStr(cboPreE.SelectedValue)
.Parameters.Add("@typeID", SqlDbType.NVarChar).Value = CStr(cboType.SelectedValue)
.Parameters.Add("@dep1ID", SqlDbType.NVarChar).Value = CStr(cboDep1.SelectedValue)
.Parameters.Add("@dep2ID", SqlDbType.NVarChar).Value = CStr(cboDep2.SelectedValue)
.Parameters.Add("@campusID", SqlDbType.NVarChar).Value = CStr(cboCampus.SelectedValue)
.Parameters.Add("@FnameT", SqlDbType.NVarChar).Value = txtFnameT.Text.Trim()
.Parameters.Add("@FnameE", SqlDbType.NVarChar).Value = txtFnameE.Text.Trim()
.Parameters.Add("@LnameT", SqlDbType.NVarChar).Value = txtLnameT.Text.Trim()
.Parameters.Add("@LnameE", SqlDbType.NVarChar).Value = txtLnameE.Text.Trim()
.Parameters.Add("@Sname", SqlDbType.NVarChar).Value = txtSname.Text.Trim()
.Parameters.Add("@tel", SqlDbType.NVarChar).Value = txttel.Text.Trim()
.Parameters.Add("@Remark", SqlDbType.NVarChar).Value = txtRemark.Text.Trim()
.Parameters.Add("@mobile", SqlDbType.NVarChar).Value = txtmobile.Text.Trim()
.Parameters.Add("@emailU1", SqlDbType.NVarChar).Value = txtemailU1.Text.Trim()
.Parameters.Add("@emailU2", SqlDbType.NVarChar).Value = txtemailU2.Text.Trim()
.Parameters.Add("@emailP1", SqlDbType.NVarChar).Value = txtemailP1.Text.Trim()
.Parameters.Add("@emailP2", SqlDbType.NVarChar).Value = txtemailP2.Text.Trim()
.Parameters.Add("@position", SqlDbType.NVarChar).Value = txtposition.Text.Trim()
.Parameters.Add("@toStudy", SqlDbType.NVarChar).Value = txttoStudy.Text.Trim()
.Parameters.Add("@toWork", SqlDbType.NVarChar).Value = txttoWork.Text.Trim()
.Parameters.Add("@toPortfolio", SqlDbType.NVarChar).Value = txttoPortfolio.Text.Trim()
If optMale.Checked = True Then
.Parameters.Add("@Sex", SqlDbType.NVarChar).Value = "F"
Else
.Parameters.Add("@Sex", SqlDbType.NVarChar).Value = "M"
End If
If (IsPictureChange = True) AndAlso (peoplePicture <> "") Then
.Parameters.Add("@peoplePicture", SqlDbType.Image).Value = CurrentImage
End If
.Parameters.Add("@peopleID", SqlDbType.NVarChar).Value = lblPeopleID.Text
.ExecuteNonQuery()
End With
End Select
tr.Commit()
sw.Stop()
ProcessTime = sw.ElapsedMilliseconds / 1000
_ToolStripLabel.Text = "เวลาที่ใช้ : " & ProcessTime.ToString("0.0000") & " วินาที"
MessageBox.Show("บันทึกข้อมูลสมาชิกใหม่ เรียบร้อยแล้ว", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
If (iSubjectDetail = False) Then
ClearCustomer()
End If
If (iSubjectDetail = True) Then
Me.Close()
End If
bn.BindingSource = Nothing
bnRecord.Text = "0"
bnCount.Text = "0"
tsAdd.Enabled = True
tsOK.Enabled = False
' tsCancel.Enabled = False
bn.Enabled = True
tsSearch.Focus()
tsSearch.SelectAll()
If (iSubjectDetail = False) Then
bgwPeople.RunWorkerAsync()
End If
Catch ex As Exception
tr.Rollback()
MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก " & ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
tsSearch.Enabled = True
End If
End Sub
Private Sub tsCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
tsAdd.Enabled = True
If ActionFlag = "ADD" Then
tsOK.Enabled = False
' tsCancel.Enabled = False
Else
tsOK.Enabled = True
' tsCancel.Enabled = True
End If
bn.Enabled = False
tsOK.Enabled = False
' tsCancel.Enabled = False
ClearCustomer()
If (iSubjectDetail = True) Then
Me.Close()
End If
tsSearch.Enabled = True
tsSearch.Focus()
tsSearch.SelectAll()
End Sub
Private Sub cboPreT_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cboPreT.KeyPress
e.Handled = True
End Sub
Private Sub cboPreE_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cboPreE.KeyPress
e.Handled = True
End Sub
Private Sub cboType_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cboType.KeyPress
e.Handled = True
End Sub
Private Sub cboDep1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cboDep1.KeyPress
e.Handled = True
End Sub
Private Sub cboDep2_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cboDep2.KeyPress
e.Handled = True
End Sub
Private Sub frmPeople_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
If Conn IsNot Nothing Then
Conn.Close()
End If
End Sub
Private Sub tsEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If (txtFnameT.Text.Trim() = "") OrElse (txtFnameE.Text.Trim() = "") Then
MessageBox.Show("กรุณาป้อนข้อมูลให้ครบ", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtFnameT.Focus()
Exit Sub
End If
If MessageBox.Show("คุณต้องการแก้ไขข้อมูลลูกค้า ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
sw.Reset()
sw.Start()
tr = Conn.BeginTransaction()
Try
If (IsPictureChange = True) AndAlso (peoplePicture <> "") Then
fs = New FileStream(peoplePicture, FileMode.Open, FileAccess.Read)
ReDim CurrentImage(CInt(fs.Length))
fs.Read(CurrentImage, 0, CInt(fs.Length - 1))
fs.Close()
Else
CurrentImage = New Byte() {}
End If
sb.Remove(0, sb.Length())
sb.Append("UPDATE tbl_people")
sb.Append(" SET preTID=@preTID,")
sb.Append(" preEID=@preEID,")
sb.Append(" FnameT=@FnameT,")
sb.Append(" LnameT=@LnameT,")
sb.Append(" FnameE=@FnameE,")
sb.Append(" LnameE=@LnameE,")
sb.Append(" Sname=@Sname,")
sb.Append(" Sex=@Sex,")
sb.Append(" typeID=@typeID,")
sb.Append(" campusID=@campusID,")
sb.Append(" dep1ID=@dep1ID,")
sb.Append(" dep2ID=@dep2ID,")
sb.Append(" tel=@tel,")
sb.Append(" mobile=@mobile,")
sb.Append(" emailU1=@emailU1,")
sb.Append(" emailU2=@emailU2,")
sb.Append(" emailP1=@emailP1,")
sb.Append(" emailP2=@emailP2")
sb.Append(" position=@position,")
sb.Append(" Remark=@Remark,")
sb.Append(" toStudy=@toStudy,")
sb.Append(" toWork=@toWork,")
sb.Append(" toPortfolio=@toPortfolio,")
sb.Append(" WHERE (peopleID=@peopleID)")
Dim sqlOK As String
sqlOK = sb.ToString
With com
.CommandText = sqlOK
.Transaction = tr
.Parameters.Clear()
.Parameters.Add("@peopleID", SqlDbType.NVarChar).Value = lblPeopleID.Text
.Parameters.Add("@preTID", SqlDbType.NVarChar).Value = CStr(cboPreT.SelectedValue)
.Parameters.Add("@preEID", SqlDbType.NVarChar).Value = CStr(cboPreE.SelectedValue)
.Parameters.Add("@typeID", SqlDbType.NVarChar).Value = CStr(cboType.SelectedValue)
.Parameters.Add("@dep1ID", SqlDbType.NVarChar).Value = CStr(cboDep1.SelectedValue)
.Parameters.Add("@dep2ID", SqlDbType.NVarChar).Value = CStr(cboDep2.SelectedValue)
.Parameters.Add("@campusID", SqlDbType.NVarChar).Value = CStr(cboCampus.SelectedValue)
.Parameters.Add("@FnameT", SqlDbType.NVarChar).Value = txtFnameT.Text.Trim()
.Parameters.Add("@FnameE", SqlDbType.NVarChar).Value = txtFnameE.Text.Trim()
.Parameters.Add("@LnameT", SqlDbType.NVarChar).Value = txtLnameT.Text.Trim()
.Parameters.Add("@LnameE", SqlDbType.NVarChar).Value = txtLnameE.Text.Trim()
.Parameters.Add("@Sname", SqlDbType.NVarChar).Value = txtSname.Text.Trim()
.Parameters.Add("@tel", SqlDbType.NVarChar).Value = txttel.Text.Trim()
.Parameters.Add("@Remark", SqlDbType.NVarChar).Value = txtRemark.Text.Trim()
.Parameters.Add("@mobile", SqlDbType.NVarChar).Value = txtmobile.Text.Trim()
.Parameters.Add("@emailU1", SqlDbType.NVarChar).Value = txtemailU1.Text.Trim()
.Parameters.Add("@emailU2", SqlDbType.NVarChar).Value = txtemailU2.Text.Trim()
.Parameters.Add("@emailP1", SqlDbType.NVarChar).Value = txtemailP1.Text.Trim()
.Parameters.Add("@emailP2", SqlDbType.NVarChar).Value = txtemailP2.Text.Trim()
.Parameters.Add("@position", SqlDbType.NVarChar).Value = txtposition.Text.Trim()
.Parameters.Add("@toStudy", SqlDbType.NVarChar).Value = txttoStudy.Text.Trim()
.Parameters.Add("@toWork", SqlDbType.NVarChar).Value = txttoWork.Text.Trim()
.Parameters.Add("@toPortfolio", SqlDbType.NVarChar).Value = txttoPortfolio.Text.Trim()
If optMale.Checked = True Then
.Parameters.Add("@Sex", SqlDbType.NVarChar).Value = "F"
Else
.Parameters.Add("@Sex", SqlDbType.NVarChar).Value = "M"
End If
If (IsPictureChange = True) AndAlso (peoplePicture <> "") Then
.Parameters.Add("@peoplePicture", SqlDbType.Image).Value = CurrentImage
Else
.Parameters.Add("@peoplePicture", SqlDbType.Image).Value = CurrentImage
End If
.ExecuteNonQuery()
End With
tr.Commit()
sw.Stop()
ProcessTime = sw.ElapsedMilliseconds / 1000
_ToolStripLabel.Text = "เวลาที่ใช้ : " & ProcessTime.ToString("0.0000") & " วินาที"
MessageBox.Show("แก้ไขข้อมูลบุคคล เรียบร้อยแล้ว", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
' tsEdit.Enabled = False
' tsCancel.Enabled = False
bn.Enabled = True
IsPictureChange = False
tsSearch.Focus()
tsSearch.SelectAll()
Catch ex As Exception
tr.Rollback()
MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก" & ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End If
End Sub
Private Sub cboCampus_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCampus.SelectedValueChanged
iCampus.SelectedValue = cboCampus.SelectedValue
End Sub
Private Sub txtposition_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtposition.TextChanged
iposition.Text = txtposition.Text()
End Sub
Private Sub txtRemark_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRemark.TextChanged
iRemark.Text = txtRemark.Text()
End Sub
Private Sub txttoStudy_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txttoStudy.TextChanged
itoStudy.Text = txttoStudy.Text()
End Sub
Private Sub txttoWork_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txttoWork.TextChanged
itoWork.Text = txttoWork.Text()
End Sub
Private Sub txttoPortfolio_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txttoPortfolio.TextChanged
itoPortfolio.Text = txttoPortfolio.Text()
End Sub
End Class
dtDep1 = New DataTable
dtDep1.Load(dr)
da = New SqlDataAdapter(sqlIni, Conn)
da.Fill(ds, "tbl_dep1")
With cboDep1
.BeginUpdate()
.DisplayMember = "dep1Name"
.ValueMember = "dep1ID"
.DataSource = dtDep1
.EndUpdate()
End With
dtDep2 = New DataTable
dtDep2.Load(dr)
With cboDep2
.BeginUpdate()
.DisplayMember = "dep2Name"
.ValueMember = "dep2ID"
.DataSource = dtDep2
'.DataSource = ds.Tables("tbl_dep1")
.EndUpdate()
End With