Option Explicit On
Option Strict On
Public Class frm_customer
Dim db As New dbdokmaiDataContext()
Private Sub frm_customer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ShowCustomers()
FormatDgv_customers()
formready()
cbbadd()
End Sub
Private Sub ShowCustomers()
Dim cs = From c In db.customers
Order By c.cus_id
Select New With {
.cus_id = c.cus_id,
.cus_type = c.cus_type,
.cus_title = c.cus_title,
.cus_name = c.cus_name,
.cus_sur = c.cus_sur,
.cus_age = c.cus_age,
.cus_phone = c.cus_phone}
dgv_cus.DataSource = cs.ToList()
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(0).Width = 50
.Columns(1).Width = 70
.Columns(2).Width = 50
.Columns(3).Width = 90
.Columns(4).Width = 90
.Columns(5).Width = 90
.Columns(6).Width = 90
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 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 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 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()
txt_name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString()
txt_phone.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString()
txt_id.Focus()
txt_id.SelectAll()
End With
End Sub
Option Explicit On
Option Strict On
Public Class frm_doctor
Dim db As New dbdokmaiDataContext()
Private Sub frm_doctor_Load(sender As Object, e As EventArgs) Handles MyBase.Load
btn_saveadd.Enabled = False
btn_edit.Enabled = False
txt_id.ReadOnly = True
txt_name.ReadOnly = True
txt_phone.ReadOnly = True
ShowCustomers()
FormatDgv_doctor()
End Sub
Private Sub ShowCustomers()
Dim cs = From c In db.doctors
Order By c.doc_id
Select New With {
.doc_id = c.doc_id,
.doc_name = c.doc_name,
.doc_phone = c.doc_phone
}
dgv_doc.DataSource = cs.ToList()
End Sub
Private Sub FormatDgv_doctor()
With dgv_doc
If .RowCount > 0 Then
.Columns(0).HeaderText = "รหัสแพทย์"
.Columns(1).HeaderText = "ชื่อ-สกุล"
.Columns(2).HeaderText = "เบอร์โทรศัพท์"
.Columns(0).Width = 70
.Columns(1).Width = 200
.Columns(2).Width = 90
End If
End With
End Sub
Private Sub btn_saveadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_saveadd.Click
Dim result = CheckdoctorsData()
If result = True Then
Dim c As New doctor()
'c.doc_id = CInt(txt_id.Text.Trim())
c.doc_name = txt_name.Text.Trim()
c.doc_phone = txt_phone.Text()
If MessageBox.Show("คุณต้องการเพิ่มข้อมูลแพทย์ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
txt_id.Text = ""
db.doctors.InsertOnSubmit(c)
db.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 dgv_doc_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgv_doc.CellMouseUp
If e.RowIndex = -1 Then Exit Sub
With dgv_doc
txt_id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString()
txt_name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString()
txt_phone.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString()
txt_id.Focus()
txt_id.SelectAll()
End With
End Sub
ขอบคุณทุกท่านที่ช่วยชี้แนะนำครับ
Tag : .NET, Ms SQL Server 2012, LINQ, VS 2012 (.NET 4.x)