Private Sub Patient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ClinicDataSet.Patient' table. You can move, or remove it, as needed.
Me.PatientTableAdapter.Fill(Me.ClinicDataSet.Patient)
'TODO: This line of code loads data into the 'ThailandDataSet.province' table. You can move, or remove it, as needed.
Me.ProvinceTableAdapter.Fill(Me.ThailandDataSet.province)
'TODO: This line of code loads data into the 'ThailandDataSet.amphur' table. You can move, or remove it, as needed.
Me.AmphurTableAdapter.Fill(Me.ThailandDataSet.amphur)
'TODO: This line of code loads data into the 'ThailandDataSet.district' table. You can move, or remove it, as needed.
Me.DistrictTableAdapter.Fill(Me.ThailandDataSet.district)
cmbpa_search.SelectedIndex = 0
showdata()
closetxt()
autoid()
End Sub
Sub autoid()
Try
Dim drTmp As OleDbDataReader
Dim sqlTmp As String
sqlTmp = "SELECT P_id from Patient order by P_id DESC"
connect()
With da
.SelectCommand = New OleDbCommand(sqlTmp, conn)
.Fill(ds, "P_id")
End With
Dim sql As New OleDbCommand
With sql
.CommandType = CommandType.Text
.CommandText = sqlTmp
.Connection = conn
drTmp = .ExecuteReader
End With
If drTmp.HasRows Then
drTmp.Read()
Dim i As Integer = 0
Dim strTmp As String
strTmp = drTmp(0)
i = strTmp.Substring(1)
i += 1
txtpa_id.Text = "P" & i.ToString("0000")
Else
txtpa_id.Text = "P" & "0001"
End If
Catch ex As Exception
MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก " & ex.Message, "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information) 'โชว์ messagebox เเจ้งผู้ใช้
conn.Close()
End Try
pa_mradio.Checked = False
pa_fradio.Checked = False
txtpa_idcard.Clear()
txtpa_symptom.Clear()
End Sub
Sub search()
Dim strselect As String = ""
dtg_show.DataSource = dt
Try
If cmbpa_search.SelectedIndex = 0 Then
MessageBox.Show("กรุณาเลือกเงื่อนไขการค้นหา", "กรุณาตรวจสอบ")
showdata()
Exit Sub
ElseIf cmbpa_search.SelectedIndex = 1 Then
strselect &= "select * from Patient where P_id like '%" & txtpa_search.Text & "%'"
ElseIf cmbpa_search.SelectedIndex = 2 Then
strselect &= "select * from Patient where P_fname like '%" & txtpa_search.Text & "%'"
ElseIf cmbpa_search.SelectedIndex = 3 Then
strselect &= "select * from Patient where P_id_card like '%" & txtpa_search.Text & "%'"
ElseIf cmbpa_search.SelectedIndex = 4 Then
strselect &= "select * from Patient "
End If
Dim ds As New DataSet
With da
.SelectCommand = New OleDbCommand(strselect, conn)
.Fill(ds, "P_id")
End With
If ds.Tables("P_id").Rows.Count = 0 Then
MessageBox.Show("ไม่พบข้อมูลที่ค้นหา", "กรุณาตรวจสอบ")
Exit Sub
Else
With dtg_show
.DataSource = ds.Tables("P_id")
.Columns(0).HeaderText = "รหัสผู้ป่วย"
.Columns(1).HeaderText = "ชื่อ"
.Columns(2).HeaderText = "นามสกุล"
.Columns(3).HeaderText = "ที่อยู่"
.Columns(4).HeaderText = "แขวง/ตำบล"
.Columns(5).HeaderText = "เขต/อำเภอ"
.Columns(6).HeaderText = "จังหวัด"
.Columns(7).HeaderText = "เลขที่ไปรษณีย์"
.Columns(8).HeaderText = "เบอร์โทรศัพท์"
.Columns(9).HeaderText = "วันเกิด"
.Columns(10).HeaderText = "เพศ"
.Columns(11).HeaderText = "เลขบัตรประชาชน"
.Columns(12).HeaderText = "อาการเบื้องต้น"
.AllowUserToAddRows = False
.AllowUserToResizeColumns = False
End With
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "กรุณาตรวจสอบ")
End Try
End Sub
Sub showdata()
Dim strselect As String = ""
Try
strselect = "select * from Patient"
connect()
Dim ds As New DataSet
With da
.SelectCommand = New OleDbCommand(strselect, conn)
.Fill(ds, "Patient")
End With
With dtg_show
.DataSource = ds.Tables("Patient")
.Columns(0).HeaderText = "รหัสผู้ป่วย"
.Columns(1).HeaderText = "ชื่อ"
.Columns(2).HeaderText = "นามสกุล"
.Columns(3).HeaderText = "ที่อยู่"
.Columns(4).HeaderText = "แขวง/ตำบล"
.Columns(5).HeaderText = "เขต/อำเภอ"
.Columns(6).HeaderText = "จังหวัด"
.Columns(7).HeaderText = "เลขที่ไปรษณีย์"
.Columns(8).HeaderText = "เบอร์โทรศัพท์"
.Columns(9).HeaderText = "วันเกิด"
.Columns(10).HeaderText = "เพศ"
.Columns(11).HeaderText = "เลขบัตรประชาชน"
.Columns(12).HeaderText = "อาการเบื้องต้น"
.AllowUserToAddRows = False
.AllowUserToResizeColumns = False
End With
Catch ex As Exception
MessageBox.Show("เกิดข้อผิดพลาด :" & ex.Message & "กรุณาตรวจสอบ" & strselect)
Exit Sub
End Try
dtg_show.AlternatingRowsDefaultCellStyle.BackColor = Drawing.Color.Salmon
End Sub
Sub edit()
Dim strUpdate As String = ""
Dim sex As String
Try
strUpdate = "update Patient set P_id ='"
strUpdate &= txtpa_id.Text & "',P_fname ='"
strUpdate &= txtpa_fname.Text & "',P_lname ='"
strUpdate &= txtpa_lname.Text & "',P_address ='"
strUpdate &= txtpa_address.Text & "',P_district ='"
strUpdate &= cmb_district.Text & "',P_amphur ='"
strUpdate &= cmb_amphur.Text & "',P_province ='"
strUpdate &= cmb_province.Text & "',P_code ='"
strUpdate &= cmb_code.Text & "',P_tele ='"
strUpdate &= txtpa_tele.Text & "',P_birth ='"
strUpdate &= txtpa_birth.Text & "',P_sex ='"
If pa_mradio.Checked = True Then
sex = "ชาย"
Else
sex = "หญิง"
End If
strUpdate &= sex & "',P_id_card ='"
strUpdate &= txtpa_idcard.Text & "',P_symptom ='"
strUpdate &= txtpa_symptom.Text & "'where P_id ='"
strUpdate &= txtpa_id.Text & "'"
connect()
Dim cm As New OleDbCommand
With cm
.Connection = conn
.CommandType = CommandType.Text
.CommandText = strUpdate
.ExecuteNonQuery()
End With
showdata()
cleartxt()
closetxt()
status = 0
flag = 0
MessageBox.Show("แก้ไขข้อมูลแล้ว !!", "ยืนยัน")
btnpa_add.Enabled = True
btnpa_edit.Enabled = False
btnpa_delete.Enabled = False
btnpa_save1.Enabled = False
Catch ex As Exception
MessageBox.Show("เกิดข้อผิดพลาด :" & ex.Message & "กรุณาตรวจสอบ" & strUpdate)
Exit Sub
End Try
End Sub
Sub save()
Dim strinsert As String = ""
Dim sex As String
With cm
.Connection = conn
.CommandType = CommandType.Text
.CommandText = strinsert
.ExecuteNonQuery()
End With
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "ยืนยัน")
cleartxt()
closetxt()
status = 0
flag = 0
showdata()
btnpa_add.Enabled = True
btnpa_clear.Enabled = True
btnpa_edit.Enabled = False
btnpa_delete.Enabled = False
btnpa_save1.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message & strinsert)
Exit Sub
End Try
End Sub
Sub delete()
Dim strDelete As String = ""
Try
If MsgBox("คุณต้องการลบข้อมูล ชื่อ:: " & txtpa_fname.Text & " นามสกุล:: " & txtpa_lname.Text, vbYesNo + vbQuestion, "คำเตือน") = vbYes Then
MessageBox.Show("ลบข้อมูลเรียบร้อยแล้ว", "ยืนยัน")
strDelete = "delete from Patient where P_id = '" & txtpa_id.Text & "'"
connect()
Dim cm As New OleDbCommand
With cm
.Connection = conn
.CommandType = CommandType.Text
.CommandText = strDelete
.ExecuteNonQuery()
End With
cleartxt()
showdata()
status = 0
flag = 0
Else
cleartxt()
status = 0
flag = 0
MessageBox.Show("ยกเลิกการลบข้อมูลแล้ว", "ทำการยืนยัน")
End If
btnpa_add.Enabled = True
btnpa_clear.Enabled = True
btnpa_edit.Enabled = False
btnpa_save1.Enabled = False
btnpa_delete.Enabled = False
Catch ex As Exception
MessageBox.Show("เกิดข้อผิดพลาด :" & ex.Message & "กรุณาตรวจสอบ" & strDelete)
Exit Sub
End Try
End Sub[/glow]
Private Sub dtg_Show_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dtg_show.MouseClick
If dtg_show.Rows.Count = 0 Then
Exit Sub
Else
flag = 1
status = 0
closetxt()
End If
If (dtg_show.Item(0, dtg_show.CurrentRow.Index).Value) = "P0001" Then
closetxt()
autoid()
cleartxt()
status = 0
flag = 0
btnpa_add.Enabled = True
btnpa_edit.Enabled = False
btnpa_clear.Enabled = False
btnpa_delete.Enabled = True
btnpa_save1.Enabled = False
btnpa_add.Enabled = False
btnpa_edit.Enabled = True
btnpa_clear.Enabled = False
btnpa_delete.Enabled = True
btnpa_save1.Enabled = False
End If
End Sub
Private Sub btnpa_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpa_add.Click
opentext()
autoid()
cleartxt()
status = 1
txtpa_fname.Focus()
btnpa_add.Enabled = False
btnpa_save1.Enabled = True
btnpa_clear.Enabled = True
btnpa_edit.Enabled = False
End Sub
Private Sub btnpa_edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpa_edit.Click
If flag = 1 Then
If txtpa_id.Text = "P0001" Then
MessageBox.Show("ไม่สามารถแก้ไขได้", "ห้ามนะ!")
Exit Sub
End If
opentext()
status = 2
btnpa_add.Enabled = False
btnpa_clear.Enabled = False
btnpa_edit.Enabled = False
btnpa_save1.Enabled = True
btnpa_delete.Enabled = False
End If
End Sub
Private Sub btnpa_clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpa_clear.Click
cleartxt()
End Sub
Private Sub btnpa_delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpa_delete.Click
If Not flag = 1 Then
Exit Sub
End If
If txtpa_id.Text = "P0001" Then
MessageBox.Show("ไม่สามารถลบได้", "ห้ามลบ!")
Exit Sub
End If
Dim strselect As String = ""
Try
strselect &= "select P_id from Patient where P_id = '" & txtpa_id.Text & "'"
Catch ex As Exception
MessageBox.Show("เกิดข้อผิดพลาด :" & ex.Message & "กรุณาตรวจสอบ" & strselect)
End Try
End Sub
Private Sub btnpa_save1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpa_save1.Click
If txtpa_fname.Text = "" Then
MessageBox.Show("กรุณากรอกชื่อผู้ป่วย", "กรุณาตรวจสอบ")
Exit Sub
ElseIf txtpa_lname.Text = "" Then
MessageBox.Show("กรุณากรอกนามสกุลผู้ป่วย", "กรุณาตรวจสอบ")
Exit Sub
ElseIf txtpa_address.Text = "" Then
MessageBox.Show("กรุณาระบุที่อยู่ผู้ป่วย", "กรุณาตรวจสอบ")
Exit Sub
ElseIf cmb_district.ValueMember = "" Then
MessageBox.Show("กรุณาระบุ แขวง/ตำบล", "กรุณาตรวจสอบ")
Exit Sub
ElseIf cmb_amphur.ValueMember = "" Then
MessageBox.Show("กรุณาระบุ เขต/อำเภอ", "กรุณาตรวจสอบ")
Exit Sub
ElseIf cmb_province.ValueMember = "" Then
MessageBox.Show("กรุณาระบุ จังหวัด", "กรุณาตรวจสอบ")
Exit Sub
ElseIf cmb_code.ValueMember = "" Then
MessageBox.Show("กรุณาระบุ เลขที่ไปรษณีย์", "กรุณาตรวจสอบ")
Exit Sub
ElseIf Not txtpa_tele.Text = "" Then
If txtpa_tele.TextLength < 9 Then
MessageBox.Show("ข้อมูลเบอร์โทรศัพท์ไม่สมบูรณ์", "กรุณาตรวจสอบ")
Exit Sub
End If
ElseIf txtpa_birth.Text = "" Then
MessageBox.Show("กรุณากรอกวันเกิดผู้ป่วย", "กรุณาตรวจสอบ")
Exit Sub
End If
If pa_mradio.Checked = False And pa_fradio.Checked = False Then
MessageBox.Show("กรุณาระบุเพศผู้ป่วยด้วย", "กรุณาตรวจสอบ")
Exit Sub
ElseIf Not txtpa_idcard.TextLength = 17 Then
MessageBox.Show("ข้อมูลรหัสบัตรประชาชนไม่สมบูรณ์", "กรุณาตรวจสอบ")
Exit Sub
ElseIf txtpa_idcard.Text = "" Then
MessageBox.Show("กรุณากรอกข้อมูลบัตรประชาชน", "กรุณาตรวจสอบ")
Exit Sub
End If
If status = 1 Then
save()
showdata()
ElseIf status = 2 Then
edit()
End If
autoid()
End Sub
Private Sub TabPage2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage2.Click
End Sub
Private Sub btnpa_search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpa_search.Click
search()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.OpenFileDialog1.FileName = Nothing
Me.OpenFileDialog1.ShowDialog()
If Not Me.OpenFileDialog1.FileName = Nothing Then
Me.PictureBox1.ImageLocation = Me.OpenFileDialog1.FileName
End If
End Sub
Public Function ConvertImage(ByVal myImage As Image) As Byte()
Dim mstream As New MemoryStream()
myImage.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim myBytes(mstream.Length - 1) As Byte
mstream.Position = 0
mstream.Read(myBytes, 0, mstream.Length)
Return myBytes
End Function
End Class
Tag : .NET, Ms SQL Server 2005, VBScript, Win (Windows App), VB.NET, VS 2005 (.NET 2.x)