Private Sub btn_find_Click(sender As Object, e As EventArgs) Handles btn_find.Click
If txt_find.Text.Trim() = "" Then Exit Sub
' Dim CurrentdoctorID = doctors.SelectedValue.ToString()
Dim ps = From p In dbDokmai.customers
Where (p.cus_name.Contains(txt_find.Text.Trim()) OrElse (p.cus_sur.Contains(txt_find.Text.Trim())))
Select New With {
.cus_id = p.cus_id,
.cus_title = p.cus_title,
.cus_name = p.cus_name,
.cus_sur = p.cus_sur,
.cus_age = p.cus_age,
.cus_address = p.cus_address,
.cus_phone = p.cus_phone,
.cus_lost = p.cus_lost,
.cus_type = p.cus_type,
.cus_roc = p.cus_roc
}
If ps.Count() > 0 Then
dgv_cus.DataSource = ps.ToList() << เออเร่อบรรทัดนี้อ่ะครับ (เอเร่อเวลารันนะครับ)
formready()
Else
dgv_cus.DataSource = Nothing
MessageBox.Show("ชื่อที่คุณค้นหา ไม่ตรงกับข้อมูลผู้ป่วยที่มีอยู่ !!!", "ผลการค้นหา", MessageBoxButtons.OK)
txt_find.Focus()
txt_find.SelectAll()
ShowCustomers()
FormatDgv_customers()
End If
End Sub
Option Explicit On
Option Strict On
Public Class frm_customer02
Dim dbDokmai As New dbdokmaiDataContext()
Dim dt As db_dokmaiDataSet.customerDataTable
Dim da As db_dokmaiDataSetTableAdapters.customerTableAdapter
Private Sub frm_customer02_Load(sender As Object, e As EventArgs) Handles MyBase.Load
da = New db_dokmaiDataSetTableAdapters.customerTableAdapter()
dt = New db_dokmaiDataSet.customerDataTable()
ShowCustomers()
FormatDgv_customers()
formready()
cbbadd()
End Sub
Private Sub ShowCustomers()
da.Fill(dt)
dgv_cus.DataSource = dt
End Sub
Private Sub FormatDgv_customers()
With dgv_cus
If .RowCount > 0 Then
.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(0).Width = 50
.Columns(1).Width = 50
.Columns(2).Width = 50
.Columns(3).Width = 90
.Columns(4).Width = 90
.Columns(5).Width = 90
.Columns(6).Width = 90
.Columns(7).Width = 90
.Columns(8).Width = 90
.Columns(9).Width = 100
End If
End With
End Sub
Private Sub formready()
cbb_type.Enabled = False
txt_id.ReadOnly = True
cbb_title.Enabled = False
txt_name.ReadOnly = True
txt_sur.ReadOnly = True
txt_age.ReadOnly = True
txt_phone.ReadOnly = True
txt_address.ReadOnly = True
txt_roc.ReadOnly = True
cbb_lost.Enabled = False
btn_saveadd.Enabled = False
btn_edit.Enabled = False
End Sub
Private Sub formnone()
cbb_type.Enabled = True
txt_id.ReadOnly = True
cbb_title.Enabled = True
txt_name.ReadOnly = False
txt_sur.ReadOnly = False
txt_age.ReadOnly = False
txt_phone.ReadOnly = False
txt_address.ReadOnly = False
txt_roc.ReadOnly = False
cbb_lost.Enabled = True
btn_saveadd.Enabled = False
btn_edit.Enabled = False
End Sub
Private Sub cbbadd()
cbb_type.Items.Add("ทั่วไป")
cbb_type.Items.Add("บัตรทอง(หลักประกันสุขภาพถ้วนหน้า)")
cbb_type.Items.Add("ประกันสังคมโรงพยาบาล1")
cbb_type.Items.Add("ประกันสังคมโรงพยาบาล2")
cbb_type.Items.Add("ประกันสังคมโรงพยาบาล3")
cbb_type.Items.Add("ประกันสังคมโรงพยาบาล4")
cbb_type.SelectedIndex = 0
cbb_lost.AutoCompleteMode = AutoCompleteMode.SuggestAppend
cbb_lost.AutoCompleteSource = AutoCompleteSource.ListItems
cbb_lost.Items.Clear()
cbb_lost.Items.Add("phenotiazine")
cbb_lost.Items.Add("sulfonamide")
cbb_lost.Items.Add("halathane")
cbb_lost.Items.Add("phenyltoin")
cbb_lost.Items.Add("Isoniazid")
cbb_lost.Items.Add("nitrofurantoin ")
cbb_title.AutoCompleteMode = AutoCompleteMode.SuggestAppend
cbb_title.AutoCompleteSource = AutoCompleteSource.ListItems
cbb_title.Items.Clear()
cbb_title.Items.Add("ด.ช.")
cbb_title.Items.Add("ด.ญ.")
cbb_title.Items.Add("นาย.")
cbb_title.Items.Add("นางสาว.")
cbb_title.Items.Add("นาง")
End Sub
Private Sub dgv_cus_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgv_cus.CellMouseUp
If e.RowIndex = -1 Then Exit Sub
With dgv_cus
txt_id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString()
cbb_title.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString()
txt_name.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString()
txt_sur.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString()
txt_age.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString()
txt_address.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString()
txt_phone.Text = .Rows.Item(e.RowIndex).Cells(6).Value.ToString()
cbb_lost.Text = .Rows.Item(e.RowIndex).Cells(7).Value.ToString()
cbb_type.Text = .Rows.Item(e.RowIndex).Cells(8).Value.ToString()
txt_roc.Text = .Rows.Item(e.RowIndex).Cells(9).Value.ToString()
txt_id.Focus()
txt_id.SelectAll()
End With
End Sub
Private Sub ClearAllData()
cbb_type.Text = ""
txt_id.Text = ""
cbb_title.Text = ""
txt_name.Text = ""
txt_sur.Text = ""
txt_age.Text = ""
txt_phone.Text = ""
txt_address.Text = ""
txt_roc.Text = ""
cbb_lost.Text = ""
End Sub
Private Function CheckcustomersData() As Boolean
CheckcustomersData = False
If (cbb_title.Text.Trim() = "") Or (txt_name.Text.Trim() = "") Or (txt_sur.Text.Trim() = "") Then
'(txt_id.Text.Trim() = "") Or
MessageBox.Show("กรุณาป้อนข้อมูลลูกค้าให้ครบ !!!", "ข้อผิดพลาด")
cbb_title.Focus()
Return False
Else
Return True
End If
End Function
Private Sub Label12_Click(sender As Object, e As EventArgs) Handles Label12.Click
Me.Hide()
frm_doctor.Show()
End Sub
Private Sub btn_saveadd_Click(sender As Object, e As EventArgs) Handles btn_saveadd.Click
Dim result = CheckcustomersData()
If result = True Then
Dim c As New customer()
'c.cus_id = CInt(txt_id.Text.Trim())
c.cus_title = cbb_title.Text()
c.cus_name = txt_name.Text()
c.cus_sur = txt_sur.Text()
c.cus_age = CInt(txt_age.Text())
c.cus_address = txt_address.Text()
c.cus_phone = txt_phone.Text()
c.cus_lost = cbb_lost.Text()
c.cus_type = cbb_type.Text()
c.cus_roc = txt_roc.Text()
If MessageBox.Show("คุณต้องการเพิ่มข้อมูลผู้ป่วย ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
txt_id.Text = ""
dbDokmai.customers.InsertOnSubmit(c)
dbDokmai.SubmitChanges()
ClearAllData()
ShowCustomers()
btn_add.Enabled = True
btn_fedit.Enabled = True
btn_edit.Enabled = False
btn_del.Enabled = True
btn_showall.Enabled = True
txt_find.Enabled = True
btn_saveadd.Enabled = False
MessageBox.Show("เพิ่มข้อมูลผู้ป่วย เรียบร้อยแล้ว", "ผลการทำงาน")
End If
End If
End Sub
Private Sub btn_add_Click(sender As Object, e As EventArgs) Handles btn_add.Click
formnone()
btn_add.Enabled = False
btn_saveadd.Enabled = True
btn_fedit.Enabled = False
btn_del.Enabled = False
End Sub
Private Sub btn_del_Click(sender As Object, e As EventArgs) Handles btn_del.Click
If txt_id.Text = "" Then
MessageBox.Show("คุณยังไม่ได้เลือกรายชื่อที่ต้องการลบ !!!", "ข้อผิดพลาด")
Exit Sub
End If
If MessageBox.Show("คุณต้องการลบข้อมูลผู้ป่วย ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
da.DeleteQuery(CInt(txt_id.Text()))
ClearAllData()
ShowCustomers()
formready()
MessageBox.Show("เพิ่มข้อมูลผู้ป่วย เรียบร้อยแล้ว", "ผลการทำงาน")
End If
End Sub
Private Sub btn_edit_Click(sender As Object, e As EventArgs) Handles btn_edit.Click
Dim result = CheckcustomersData()
If result = True Then
Dim cs = (From c In dbDokmai.customers
Where c.cus_id = CInt(txt_id.Text.Trim())
Select c).FirstOrDefault()
If cs Is Nothing Then
MessageBox.Show("คุณยังไม่ได้เลือกรายชื่อที่ต้องการแก้ไข !!!", "ข้อผิดพลาด")
Exit Sub
End If
cs.cus_title = cbb_title.Text.Trim()
cs.cus_name = txt_name.Text.Trim()
cs.cus_sur = txt_sur.Text.Trim()
cs.cus_age = CInt(txt_age.Text.Trim())
cs.cus_address = txt_address.Text.Trim()
cs.cus_phone = txt_phone.Text.Trim()
cs.cus_lost = cbb_lost.Text.Trim()
cs.cus_type = cbb_type.Text.Trim()
cs.cus_roc = txt_roc.Text.Trim()
If MessageBox.Show("คุณต้องการแก้ไขข้อมูลลูกค้า ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
dbDokmai.SubmitChanges()
ClearAllData()
ShowCustomers()
btn_add.Enabled = True
btn_fedit.Enabled = True
btn_edit.Enabled = False
btn_del.Enabled = True
btn_showall.Enabled = True
txt_find.Enabled = True
btn_saveadd.Enabled = False
MessageBox.Show("แก้ไขข้อมูลลูกค้า เรียบร้อยแล้ว", "ผลการทำงาน")
End If
End If
End Sub
Private Sub btn_fedit_Click(sender As Object, e As EventArgs) Handles btn_fedit.Click
formnone()
btn_fedit.Enabled = False
btn_edit.Enabled = True
End Sub
Private Sub btn_showall_Click(sender As Object, e As EventArgs) Handles btn_showall.Click
ShowCustomers()
End Sub
Private Sub showstart()
btn_add.Enabled = True
btn_fedit.Enabled = True
btn_edit.Enabled = False
btn_del.Enabled = True
btn_showall.Enabled = True
txt_find.Enabled = True
btn_saveadd.Enabled = False
End Sub
Private Sub btn_cancel_Click(sender As Object, e As EventArgs) Handles btn_cancel.Click
showstart()
End Sub
Private Sub btn_find_Click(sender As Object, e As EventArgs) Handles btn_find.Click
If txt_find.Text.Trim() = "" Then Exit Sub
' Dim CurrentdoctorID = doctors.SelectedValue.ToString()
Dim ps = From p In dbDokmai.customers
Where (p.cus_name.Contains(txt_find.Text.Trim()) OrElse (p.cus_sur.Contains(txt_find.Text.Trim())))
Select New With {
.cus_id = p.cus_id,
.cus_title = p.cus_title,
.cus_name = p.cus_name,
.cus_sur = p.cus_sur,
.cus_age = p.cus_age,
.cus_address = p.cus_address,
.cus_phone = p.cus_phone,
.cus_lost = p.cus_lost,
.cus_type = p.cus_type,
.cus_roc = p.cus_roc
}
If ps.Count() > 0 Then
dgv_cus.DataSource = ps.ToList()
formready()
Else
dgv_cus.DataSource = Nothing
MessageBox.Show("ชื่อที่คุณค้นหา ไม่ตรงกับข้อมูลผู้ป่วยที่มีอยู่ !!!", "ผลการค้นหา", MessageBoxButtons.OK)
txt_find.Focus()
txt_find.SelectAll()
ShowCustomers()
FormatDgv_customers()
End If
End Sub
End Class
Tag : .NET, Ms SQL Server 2012, LINQ, VS 2012 (.NET 4.x)