132
ภาคผนวก

ภาคผนวก - bc.msu.ac.th356).pdf · การติดตั้งโปรแกรม Microsoft SQL Server 2005 1.ท าการ Run File ติดต้ัง Microsoft

Embed Size (px)

Citation preview

ภาคผนวก

ภาคผนวก ก

การตดตงโปรแกรม

การตดตงโปรแกรม Microsoft SQL Server 2005 1.ท าการ Run File ตดตง Microsoft SQL Server 2005 Express Edition.exe จากนนให Click ท Check Box “ I accept the licensing terms and conditions “ จากนนกดปม Next

2. กดปม Install โปรแกรมจะเรมท าการตดตง Support Files

3. โปรแกรมจะแสดงหนาจอตอนรบใหท าการกดปม Next

4. จากนนโปรแกรมจะแสดงขนตอนการตดตงใหท าการกดปม Next อกครง

5. ท าการปอนชอ ในชอง Name และ ชอกจการในชอง Company จากนนกดปม Next

6. ใหท าการเลอก Feature ของโปรแกรม และเลอก ทตงของโปรแกรม ดงรป แลวกดปม Next

7. ใหท าการเลอก Instance name ดงรปแลวกดปม Next

8. จากนนท าการ Click ท Radio Button “Mixed Mode” แลวท าการปอน Password (ตองจ าใหได เพอเปนรหสผานในการจดการฐานขอมล )จากนนกดปม Next

9. เมอเสรจสนการตดตงใหท าการ Config Service ของ SQL Server โดย เขาไปท Start ->Microsoft SQL Server 2005 -> Configuration Tools และ เลอก SQL Server Configuration Manager

โปรแกรม Visual Basic.Net ขนตอนการตดตงโปรแกรมVisual Basic.Net (Visual Studio.net 2008) 1. ใสแผนโปรแกรม Visual Studio.net 2008 ลงใน CD-Rom Drive 2. รอใหโปรแกรมท าการตดตงโดยอตโนมต (Auto Run) แตถาโปรแกรมอตโนมตไมท างานกใหดบเบลคลกไฟล Setup.exe จากแผน CD 3. คลกท Install Visual Studio 2008 โปรแกรมจะเรมตดตงเมอมาถงหนาจอ Product Number and User ID ใหใสรหสลงทะเบยน CD-Key ลงไปใหถกตอง

4. ใหคลก Change or Remove Visual Studio 2008

5. เมอเรากด Change or Remove Visual Studio 2008 จะขนดงรป ใหเรากด Next >

6. ใหเราเลอก I have read and accept the license terms. จากนนใหเราเลอก Next >

7. ใหเราเลอก Full แลว คลกท Install

8. จากนนใหเรารอจนกวาโปรแกรมจะลงเสรจ

ภาคผนวก ข SOURCE CODE

Source Code ชอ Module1

Imports System.Data Imports System.Data.SqlClient Imports CrystalDecisions.Shared Imports CrystalDecisions.CrystalReports.Engine Imports System.IO Imports System.Data.OleDb Imports System.Text Imports System.ComponentModel.Win32Exception Module Module1 Public Conn As SqlClient.SqlConnection Public ActionFlag As String Public SickerName As String Public SickerID As String Public CheckID As String Public OrderID As String Public strConn As String Public AppointID As String Public Sub DbConn() 'setDATABASE() strConn = "Data Source=Asus-pc;Initial Catalog=supod;User ID=java;Password=java@kkh" Conn = New SqlClient.SqlConnection(strConn) With Conn 'เรมตนการเชอมตอกบฐานขอมล If .State = ConnectionState.Open Then .Close() .ConnectionString = strconn .Open() 'เชอมตอกบฐานขอมล

End With End Sub End Module Source Code ชอ addUser

Imports System.Data '("Data Source=asus-pc;Initial Catalog=supod;Integrated Security=True;") Imports System.Data.SqlClient 'Data Source=ASUS-PC;Initial Catalog=supod;User ID=doctor;Password=12345 Public Class frm_addUser 'Data Source=202.28.32.173;Initial Catalog=51010912014db;User ID=51010912014;Password=*********** 'Dim conn As New SqlClient.SqlConnection("Data Source=asus-pc;Initial Catalog=supod;Integrated Security=True;") Private Sub frm_addUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Me.WindowState = FormWindowState.Maximized DbConn() Displaydata() conn.Close() End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick If e.RowIndex = -1 Then Exit Sub With DataGridView1() txtUser.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtuser_names.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtpass.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() txtUser_Phone.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() txtUser_Adress.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() End With

End Sub Sub Displaydata() 'Refresh ขอมลในตารางเจาหนาท Dim da As New SqlClient.SqlDataAdapter("select User_name as ชอเขาใชงาน,user_names as ชอเจาหนาท,password as รหสผาน,User_Phone as เบอรโทรศพท,User_Address as ทอย from AdminUser", conn) Dim ds As New DataSet da.Fill(ds, "AdminUser") DataGridView1.DataSource = ds DataGridView1.DataMember = "AdminUser" End Sub Sub ClearData() ' เคลยรขอมล txtUser.Text = "" txtpass.Text = "" txtuser_names.Text = "" txtUser_Phone.Text = "" txtUser_Adress.Text = "" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click conn.Open() Dim y As New SqlCommand("update AdminUser set User_name ='" & _ txtUser.Text & "',password ='" & _ txtpass.Text & "',user_names ='" & _ txtuser_names.Text & "',User_Phone ='" & _ txtUser_Phone.Text & "',User_Address ='" & _ txtUser_Adress.Text & "'", conn) Try y.ExecuteNonQuery() ' MsgBox("แกไขขอมลส าเรจ") Displaydata()

ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try ClearData() conn.Close() End Sub Private Sub bSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bSave.Click conn.Open() Dim y As New SqlCommand("insert into AdminUser values( '" & _ txtUser.Text & "','" & txtpass.Text & "','" & txtuser_names.Text & "','" & _ txtUser_Phone.Text & "','" & txtUser_Adress.Text & "')", conn) Try y.ExecuteNonQuery() ' MsgBox("บนทกขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try conn.Close() End Sub Private Sub bde_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bde.Click conn.Open() Dim y As New SqlCommand("delete from AdminUser where User_Name='" & txtUser.Text & "'", conn) Try

y.ExecuteNonQuery() ' MsgBox("ลบขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try conn.Close() End Sub Private Sub bend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bend.Click ' Dim result As DialogResult ' result = MessageBox.Show("คณตองการยกเลกหรอไมหรอ", "ยนยน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ' If result = Windows.Forms.DialogResult.Yes Then Me.Close() ' End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ClearData() End Sub End Class Source Code ชอ AgentData

Imports System.Data

Imports System.Data.SqlClient 'Data Source=ASUS-PC;Initial Catalog=supod;User ID=doctor;Password=12345 Public Class frm_AgentData ' Dim conn As New SqlClient.SqlConnection("Data Source=asus-pc;Initial Catalog=supod;Integrated Security=True;") Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick If e.RowIndex = -1 Then Exit Sub With DataGridView1() TxtAgent_Id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtAgent_Name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtagent_Idcard.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() txtAgent_Address.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() txtAgent_Tel.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() txtAgent_Fax.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString() End With End Sub Sub Displaydata() Dim da As New SqlClient.SqlDataAdapter("select Agent_Id as รหสตวแทนจ าหนาย,Agent_Name as ชอ,agent_Idcard as เลขบตรประชาชน,Agent_Address as ทอย,Agent_Tel as เบอรโทรศพท ,Agent_Fax as เบอรแฟกซ from Agent", conn) Dim ds As New DataSet da.Fill(ds, "Agent") DataGridView1.DataSource = ds DataGridView1.DataMember = "Agent" End Sub

Private Sub frm_AgentData_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Maximized DbConn() Displaydata() conn.Close() End Sub Sub ClearData() TxtAgent_Id.Text = "" txtAgent_Name.Text = "" txtagent_Idcard.Text = "" txtAgent_Address.Text = "" txtAgent_Tel.Text = "" txtAgent_Fax.Text = "" txtsearch.Text = "" End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click ' Dim result As DialogResult ' result = MessageBox.Show("คณตองการปดหนาตางนจรงหรอ", "ยนยน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ' If result = Windows.Forms.DialogResult.Yes Then Me.Close() ' End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

If Me.TxtAgent_Id.Text = "" Or txtAgent_Name.Text = "" Or txtAgent_Address.Text = "" Or txtAgent_Tel.Text = "" Or txtAgent_Fax.Text = "" Then MsgBox("กรณากรอกขอมลใหครบทกชองคะ") Else If conn.State <> ConnectionState.Open Then ' conn.Open() End If Dim y As New SqlCommand("insert into Agent values('" & _ TxtAgent_Id.Text & "','" & txtAgent_Name.Text & "','" & txtagent_Idcard.Text & "','" & _ txtAgent_Address.Text & "','" & txtAgent_Tel.Text & "','" & txtAgent_Fax.Text & "')", conn) Try y.ExecuteNonQuery() ' MsgBox("บนทกขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox("เกดความผดพลาด เนองจาก " & Err.Description) End Try End If conn.Close() End Sub Private Sub edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles edit.Click conn.Open() Dim y As New SqlCommand("update Agent set Agent_Name ='" & _ txtAgent_Name.Text & "',agent_Idcard = '" & _ txtagent_Idcard.Text & "',Agent_Address = '" & _ txtAgent_Address.Text & "',Agent_Tel = '" & _

txtAgent_Tel.Text & "',Agent_Fax = '" & _ txtAgent_Fax.Text & "',Agent_Id = '" & TxtAgent_Id.Text & "'", conn) Try y.ExecuteNonQuery() ' MsgBox("แกไขขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try ClearData() conn.Close() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click conn.Open() Dim y As New SqlCommand("delete from Agent where Agent_Id='" & TxtAgent_Id.Text & "'", conn) 'Dim Result As DialogResult ' Result = MessageBox.Show("คณตองการลบขอมลใชหรอไม", "คณตองการลบขอมลใชหรอไม !", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Try y.ExecuteNonQuery() 'MsgBox("ลบขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try

conn.Close() End Sub Private Sub add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles add.Click ClearData() End Sub Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged If conn.State <> ConnectionState.Open Then conn.Open() End If Dim SQL As String If (txtsearch.Text <> "") Then 'การทางานเมอTextbox ไมเปนคาวาง SQL = "select Agent_Id as รหสตวแทนจ าหนาย,Agent_Name as ชอตวแทนจ าหนาย,Agent_Address as ทอย,Agent_Tel as โทรศพท,Agent_Fax as เบอรแฟกซ from Agent WHERE Agent_id LIKE '%" & txtsearch.Text & "%'" & " OR Agent_name LIKE '%" & Me.txtsearch.Text & "%' ORDER BY Agent_id" Else SQL = "select Agent_Id as รหสตวแทนจ าหนาย,Agent_Name as ชอตวแทนจ าหนาย,Agent_Address as ทอย,Agent_Tel as โทรศพท,Agent_Fax as เบอรแฟกซ from Agent ORDER BY Agent_id " End If Dim objDA As New SqlDataAdapter(SQL, conn) Dim objDS As New DataSet() objDA.Fill(objDS, "Agent") DataGridView1.DataSource = objDS

DataGridView1.DataMember = "Agent" End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click conn.Open() TxtAgent_Id.Text = S() TxtAgent_Id.Enabled = False conn.Close() End Sub Function S() Dim y As New SqlCommand("select max(Agent_Id) from Agent ", conn) Try Dim Sic As String = y.ExecuteScalar() Sic = Mid(Sic, 1, 1) & (Mid(Sic, 6, 6) + 1).ToString("000000") Return Sic Catch Return "A000001" End Try End Function End Class

Source Code ชอ frm_appoint

Imports System.Data Imports System.Data.SqlClient '("data source=ASUS-PC ;initial catalog=supod ;user id=doctor ;password=12345;") Public Class frm_appoint

Private Sub frm_appoint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Maximized DbConn() Displaydata2() conn.Close() End Sub Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click If conn.State <> ConnectionState.Open Then conn.Open() End If If txtSicker_Idd.Text.Trim = "" Then MessageBox.Show("ไมมขอมลผปวย ", "ผดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error) Else r_Appointment.Show() End If End Sub Private Sub DataGridView4_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView4.CellContentClick End Sub

Sub Displaydata2() Dim da As New SqlClient.SqlDataAdapter("select Appointment_Id as รหสการนดหมาย,Sicker_Id as รหสผปวย ,Sicker_name as ชอผปวย,Appoint_Date as วนทนดหมาย,Appoint_Detail as รายละเอยดการนดหมาย,Appoint_time as เวลานดหมาย from Appointment", conn) Dim ds As New DataSet da.Fill(ds, "Appointment") DataGridView4.DataSource = ds DataGridView4.DataMember = "Appointment" End Sub Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click If conn.State <> ConnectionState.Open Then conn.Open() End If Dim y As New SqlCommand("insert into Appointment values('" & _ txtAppointment.Text & "','" & txtSicker_Idd.Text & "','" & TextBox2.Text & "','" & txtAppointment_Date.Text & "','" & _ txtAppointment_Detail.Text & "','" & txtAppointment_time.Text & "')", conn) Try y.ExecuteNonQuery() ' MsgBox("บนทกขอมลส าเรจ") Displaydata2() ClearData() Catch MsgBox("เกดความผดพลาด เนองจาก " & Err.Description) End Try ClearData() conn.Close()

End Sub Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click If conn.State <> ConnectionState.Open Then conn.Open() '.Text End If Dim y As New SqlCommand("update Appointment set Appointment_Id='" & _ txtAppointment.Text & "',Sicker_name = '" & _ TextBox2.Text & "',Appoint_Date = '" & _ txtAppointment_Date.Text & "',Appoint_time = '" & _ txtAppointment_time.Text & "',Appoint_Detail = '" & _ txtAppointment_Detail.Text & "'where Appointment_Id = '" & txtAppointment.Text.Trim() & "'", Conn) Try y.ExecuteNonQuery() ' MsgBox("แกไขขอมลส าเรจ") Displaydata2() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try conn.Close() End Sub Sub ClearData() txtAppointment.Text = "" txtAppointment_Date.Text = "" txtAppointment_time.Text = ""

txtAppointment_Detail.Text = "" txtSicker_Idd.Text = SickerID txtSearch.Text = "" TextBox2.Text = SickerName End Sub Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged If conn.State <> ConnectionState.Open Then conn.Open() End If Dim SQL As String If (txtSearch.Text <> "") Then 'การทางานเมอTextbox ไมเปนคาวาง SQL = "select Appointment_Id as รหสการนดหมาย,Sicker_Id as รหสผปวย,sicker_Name as ชอ,Appoint_Date as วนทนดหมาย,Appoint_Detail as รายละเอยดการนดหมาย,Appoint_time as เวลานดหมาย from Appointment WHERE Appointment_id LIKE '%" & txtSearch.Text & "%'" & " OR Appointment_id LIKE '%" & Me.txtSearch.Text & "%' ORDER BY Appointment_id" Else SQL = "select Appointment_Id as รหสการนดหมาย,Sicker_Id as รหสผปวย,sicker_Name as ชอ,Appoint_Date as วนทนดหมาย,Appoint_Detail as รายละเอยดการนดหมาย,Appoint_time as เวลานดหมาย from Appointment ORDER BY Appointment_id " End If Dim objDA As New SqlDataAdapter(SQL, conn) Dim objDS As New DataSet() objDA.Fill(objDS, "Appointment") DataGridView2.DataSource = objDS DataGridView2.DataMember = "Appointment" End Sub Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click If conn.State <> ConnectionState.Open Then

conn.Open() End If Dim y As New SqlCommand("delete from Appointment where Appointment_Id ='" & txtAppointment.Text & "'", conn) 'Dim Result As DialogResult ' Result = MessageBox.Show("คณตองการลบขอมลใชหรอไม", "คณตองการลบขอมลใชหรอไม !", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Try y.ExecuteNonQuery() ' MsgBox("ลบขอมลส าเรจ") Displaydata2() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try conn.Close() End Sub Function Ss() Dim y As New SqlCommand("select max(Appointment_Id) from Appointment ", conn) Try Dim Sic As String = y.ExecuteScalar() Sic = Mid(Sic, 1, 1) & (Mid(Sic, 6, 6) + 1).ToString("000000") Return Sic Catch Return "P000001" End Try End Function Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click

If conn.State <> ConnectionState.Open Then conn.Open() End If txtAppointment.Text = Ss() txtAppointment.Enabled = False conn.Close() End Sub Private Sub Button21_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click ClearData() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) txtSicker_Idd.Text = frm_Check.txtSicker_Id.Text End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Close() orderdispes.Close() frm_Check.Close() End Sub Private Sub txtSicker_Idd_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSicker_Idd.TextChanged 'txtSicker_Idd.Text = frm_Check.txtSicker_Id.Text

End Sub Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged ' TextBox2.Text = frm_Check.txtsicker_name.Text End Sub Private Sub DataGridView4_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView4.CellMouseUp If e.RowIndex = -1 Then Exit Sub With DataGridView4() txtAppointment.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() AppointID = txtAppointment.Text.Trim() txtSicker_Idd.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() SickerID = txtSicker_Idd.Text.Trim() TextBox2.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() txtAppointment_Date.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() txtAppointment_Detail.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() txtAppointment_time.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString() End With End Sub End Class Source Code ชอ frm_Check

Imports System.Data Imports System.Data.SqlClient 'Data Source=ASUS-PC;Initial Catalog=supod;Integrated Security=True Imports System.Globalization

Public Class frm_Check ' Dim conn As New SqlClient.SqlConnection("Data Source=asus-pc;Initial Catalog=supod;Integrated Security=True;") Dim Today As Date Dim dtfInfo As DateTimeFormatInfo Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If txtCheck_Id.Text = S() txtCheck_Id.Enabled = False Conn.Close() End Sub Sub Displaydata1() Dim da As New SqlClient.SqlDataAdapter("select Check_Id as รหสการตรวจรกษา,sicker_Id as รหสผปวย,sicker_Name as ชอ,Check_Date as วนทตรวจรกษา,check_order as รายการการตรวจรกษา,conclude as ผลการตรวจรกษา,check_price As คาบรการ from Checkk ", Conn) Dim ds As New DataSet da.Fill(ds, "Checkk") DataGridView3.DataSource = ds DataGridView3.DataMember = "Checkk" End Sub Function S() Dim y As New SqlCommand("select max(Check_Id) from checkk ", Conn) Try Dim Sic As String = y.ExecuteScalar() Sic = Mid(Sic, 1, 1) & (Mid(Sic, 6, 6) + 1).ToString("000000") Return Sic

Catch Return "C000001" End Try End Function Sub ClearData2() txtCheck_Id.Text = "" txtSicker_Id.Text = "" txtCheck_Date.Value = Today txtconclude.Text = "" txtcheck_order.Text = "" txtCheck_Price.Text = "0" End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If Dim y As New SqlCommand("insert into Checkk(check_id,sicker_id,sicker_name,check_date,check_order,conclude,check_price) values('" & txtCheck_Id.Text & "','" & _ txtSicker_Id.Text & "','" & txtsicker_name.Text & "','" & txtCheck_Date.Value.ToString("d", dtfInfo) & "','" & _ txtcheck_order.Text & "','" & _ txtconclude.Text & "'," & Convert.ToDouble(txtCheck_Price.Text) & ")", Conn) Try y.ExecuteNonQuery() MsgBox("บนทกขอมลส าเรจ", MsgBoxStyle.Information, "แจงผลการบนทก")

Displaydata1() Catch MsgBox("เกดความผดพลาด เนองจาก " & Err.Description) End Try Conn.Close() 'ClearData2() End Sub Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click Conn.Open() Dim y As New SqlCommand("update Checkk set Check_Id ='" & _ txtCheck_Id.Text & "',Sicker_Id = '" & _ txtSicker_Id.Text & "',Check_Date = '" & _ txtCheck_Date.Value.ToString("d", dtfInfo) & "',sicker_name = '" & _ txtsicker_name.Text & "',check_order = '" & _ txtcheck_order.Text & "',conclude = '" & _ txtconclude.Text & "' ,check_price=" & _ Convert.ToDouble(txtCheck_Price.Text) & " Where check_id='" & txtCheck_Id.Text.Trim() & "'", Conn) Try y.ExecuteNonQuery() MsgBox("แกไขขอมลส าเรจ", MsgBoxStyle.Information, "แจงผลการท างาน") Displaydata1() ClearData2() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try

Conn.Close() End Sub Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click Conn.Open() Dim y As New SqlCommand("delete from checkk where Check_Id='" & txtCheck_Id.Text & "'", Conn) ' Dim Result As DialogResult 'Result = MessageBox.Show("คณตองการลบขอมลใชหรอไม", "คณตองการลบขอมลใชหรอไม !", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Try y.ExecuteNonQuery() ' MsgBox("ลบขอมลส าเรจ") Displaydata1() ClearData2() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try Conn.Close() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Me.Close() End Sub Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click

ClearData2() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If CheckID = "" Then MsgBox("คณยงไมเลอกรายการตรวจทตองการจายยา", MsgBoxStyle.Exclamation, "แจงเตอน") Exit Sub End If orderdispes.MdiParent = Me.MdiParent orderdispes.Show() End Sub Private Sub DataGridView3_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellContentClick If e.RowIndex = -1 Then Exit Sub With DataGridView3 txtCheck_Id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtSicker_Id.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtsicker_name.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() txtCheck_Date.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() txtcheck_order.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() txtconclude.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString() txtCheck_Price.Text = .Rows.Item(e.RowIndex).Cells(6).Value.ToString() CheckID = txtCheck_Id.Text.Trim() : SickerID = txtSicker_Id.Text.Trim() : SickerName = txtsicker_name.Text.Trim() 'เกบไวในตวแแปร Public เพอสงไปตรางจายยา

End With End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged If Conn.State <> ConnectionState.Open Then Conn.Open() End If ' Dim SQL As String If (TextBox1.Text <> "") Then SQL = " select sicker_Id as รหสผปวย,sicker_Name as ชอ,Sicker_DateTimePicker1 as วนทใชบรการ,Sicker_Weight as น าหนก,Sicker_High as สวนสง,sicker_lowpressure as SYS,sicker_highpressure as DIA,Sicker_Pulse as Pulse,Sicker_behavior as อาการเบองตน,sicker_Diseased as โรคประจ าตว,sicker_DrugAllergy as แพยา from Sicker WHERE sicker_IDCard LIKE '%" & TextBox1.Text & "%'" & " OR Sicker_name LIKE '%" & Me.TextBox1.Text & "%' ORDER BY sicker_IDCard" Else SQL = " select sicker_Id as รหสผปวย,sicker_Name as ชอ,Sicker_DateTimePicker1 as วนทใชบรการ,Sicker_Weight as น าหนก,Sicker_High as สวนสง,sicker_lowpressure as SYS,sicker_highpressure as DIA,Sicker_Pulse as Pulse,Sicker_behavior as อาการเบองตน,sicker_Diseased as โรคประจ าตว,sicker_DrugAllergy as แพยา from Sicker ORDER BY sicker_IDCard " End If Dim objDA As New SqlDataAdapter(SQL, Conn) Dim objDS As New DataSet() objDA.Fill(objDS, "Sicker") DataGridView1.DataSource = objDS DataGridView1.DataMember = "Sicker" Conn.Close() End Sub

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick If e.RowIndex = -1 Then Exit Sub With DataGridView1() '.Rows.Item(e.RowIndex).Cells(4).Value.ToString() txysicker_Id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txysicker_name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtSicker_Weight.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() txtSicker_High.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() txtsicker_highpressure.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString() txtsicker_Pressure.Text = .Rows.Item(e.RowIndex).Cells(6).Value.ToString() txtSicker_Pulse.Text = .Rows.Item(e.RowIndex).Cells(7).Value.ToString() txtbehavior.Text = .Rows.Item(e.RowIndex).Cells(8).Value.ToString() txtsicker_Diseased.Text = .Rows.Item(e.RowIndex).Cells(9).Value.ToString() txtsicker_DrugAllergy.Text = .Rows.Item(e.RowIndex).Cells(10).Value.ToString() txtSicker_Id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtsicker_name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() End With Dim da As New SqlClient.SqlDataAdapter("select Check_Id as รหสการตรวจรกษา,sicker_Id as รหสผปวย,sicker_Name as ชอ,Check_Date as วนทตรวจรกษา,check_order as รายการการตรวจรกษา,conclude as ผลการตรวจรกษา,check_price As คาบรการ from Checkk Where sicker_Id='" & txtSicker_Id.Text.Trim() & "' ", Conn) Dim ds As New DataSet da.Fill(ds, "Checkk") DataGridView3.DataSource = ds DataGridView3.DataMember = "Checkk" End Sub

Private Sub frm_Check_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Maximized Today = DateTime.Today dtfInfo = DateTimeFormatInfo.InvariantInfo DbConn() TextBox1.Focus() End Sub Private Sub txtSicker_Id_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSicker_Id.TextChanged ' txysicker_Id.Text = txtSicker_Id.Text End Sub Private Sub txtsicker_name_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsicker_name.TextChanged ' txysicker_name.Text = txysicker_name.Text End Sub Private Sub txtCheck_Price_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCheck_Price.KeyPress If e.KeyChar < "0" Or e.KeyChar > "9" Then e.Handled = True End If End Sub

Private Sub DataGridView3_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView3.CellFormatting If (e.ColumnIndex = -1) Then Exit Sub End If If (DataGridView3.Columns(e.ColumnIndex).Name = "วนทตรวจรกษา") Then e.CellStyle.Format = "d MMM yyyy" End If End Sub Private Sub DataGridView3_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView3.CellMouseUp If e.RowIndex = -1 Then Exit Sub With DataGridView3 txtCheck_Id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtSicker_Id.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtsicker_name.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() txtCheck_Date.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() txtcheck_order.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() txtconclude.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString() txtCheck_Price.Text = .Rows.Item(e.RowIndex).Cells(6).Value.ToString() CheckID = txtCheck_Id.Text.Trim() : SickerID = txtSicker_Id.Text.Trim() : SickerName = txtsicker_name.Text.Trim() 'เกบไวในตวแแปร Public เพอสงไปตรางจายยา End With End Sub

Private Sub DataGridView1_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseUp If e.RowIndex = -1 Then Exit Sub With DataGridView1() '.Rows.Item(e.RowIndex).Cells(4).Value.ToString() txysicker_Id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txysicker_name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtSicker_Weight.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() txtSicker_High.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() txtsicker_highpressure.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString() txtsicker_Pressure.Text = .Rows.Item(e.RowIndex).Cells(6).Value.ToString() txtSicker_Pulse.Text = .Rows.Item(e.RowIndex).Cells(7).Value.ToString() txtbehavior.Text = .Rows.Item(e.RowIndex).Cells(8).Value.ToString() txtsicker_Diseased.Text = .Rows.Item(e.RowIndex).Cells(9).Value.ToString() txtsicker_DrugAllergy.Text = .Rows.Item(e.RowIndex).Cells(10).Value.ToString() txtSicker_Id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtsicker_name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() End With Dim da As New SqlClient.SqlDataAdapter("select Check_Id as รหสการตรวจรกษา,sicker_Id as รหสผปวย,sicker_Name as ชอ,Check_Date as วนทตรวจรกษา,check_order as รายการการตรวจรกษา,conclude as ผลการตรวจรกษา,check_price As คาบรการ from Checkk Where sicker_Id='" & txtSicker_Id.Text.Trim() & "' ", Conn) Dim ds As New DataSet da.Fill(ds, "Checkk") DataGridView3.DataSource = ds DataGridView3.DataMember = "Checkk" End Sub End Class

Source Code ชอ frm_DrugData

Imports System.Data Imports System.Data.SqlClient 'Data Source=ASUS-PC;Initial Catalog=supod;User ID=doctor;Password=12345 Public Class frm_DrugData ' Dim conn As New SqlClient.SqlConnection("Data Source=asus-pc;Initial Catalog=supod;Integrated Security=True;") Private Sub frm_DrugData_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Maximized DbConn() Displaydata() conn.Close() End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick If e.RowIndex = -1 Then Exit Sub With DataGridView1() txDrug_Id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txDrug_Name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txunit.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() txtdrug_t.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() txDrug_Price.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() txLimit.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString() txDrug_Detail.Text = .Rows.Item(e.RowIndex).Cells(6).Value.ToString() End With End Sub

Sub Displaydata() Dim da As New SqlClient.SqlDataAdapter("select Drug_Id as รหสยา,Drug_Name as ชอยา,Unit as จ านวน,drug_t as หนวยนบ,Drug_Price as ราคาตอหนวย,Limit as จดสงซอ,Drug_Detail as รายละเอยดยา from Drug", conn) Dim ds As New DataSet da.Fill(ds, "Drug") DataGridView1.DataSource = ds DataGridView1.DataMember = "Drug" End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click ' Dim result As DialogResult ' result = MessageBox.Show("คณตองการปดหนาตางนจรงหรอ", "ยนยน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ' If result = Windows.Forms.DialogResult.Yes Then Me.Close() ' End If End Sub Sub ClearData() txDrug_Id.Text = "" txDrug_Name.Text = "" txunit.Text = "" txtdrug_t.Text = "" txDrug_Price.Text = "" txLimit.Text = "" txDrug_Detail.Text = "" End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

conn.Open() Dim y As New SqlCommand("delete from Drug where Drug_Id='" & txDrug_Id.Text & "'", conn) Dim Result As DialogResult Result = MessageBox.Show("คณตองการลบขอมลใชหรอไม", "คณตองการลบขอมลใชหรอไม !", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Try y.ExecuteNonQuery() ' MsgBox("ลบขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try conn.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click conn.Open() If Me.txDrug_Id.Text = "" Or txDrug_Name.Text = "" Or txunit.Text = "" Or txDrug_Price.Text = "" Or txLimit.Text = "" Or txDrug_Detail.Text = "" Or txDrug_Price.Text = "" Then MsgBox("กรณากรอกขอมลใหครบทกชองคะ") Else Dim y As New SqlCommand("insert into Drug values('" & _ txDrug_Id.Text & "','" & txDrug_Name.Text & "','" & txunit.Text & "','" & _ txtdrug_t.Text & "','" & txDrug_Price.Text & "','" & _ txLimit.Text & "','" & txDrug_Detail.Text & "')", conn) Try

y.ExecuteNonQuery() ' MsgBox("บนทกขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox("เกดความผดพลาด เนองจาก " & Err.Description) End Try End If conn.Close() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click conn.Open() Dim y As New SqlCommand("update Drug set Drug_name='" & _ txDrug_Name.Text & "',Unit = '" & _ txunit.Text & "',drug_t = '" & _ txtdrug_t.Text & "',Drug_Price = '" & _ txDrug_Price.Text & "',Limit= '" & _ txLimit.Text & "',Drug_Detail = '" & _ txDrug_Detail.Text & "' where Drug_Id = '" & txDrug_Id.Text & "'", conn) Try y.ExecuteNonQuery() ' MsgBox("แกไขขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try ClearData()

conn.Close() End Sub Private Sub add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles add.Click ClearData() End Sub Private Sub txtseach_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtseach.TextChanged If conn.State <> ConnectionState.Open Then conn.Open() End If Dim SQL As String If (txtseach.Text <> "") Then 'การทางานเมอTextbox ไมเปนคาวาง SQL = "select Drug_Id as รหสยา,Drug_Name as ชอยา,Unit as จ านวน,drug_t as หนวยนบ,Drug_Price as ราคาตอหนวย,Limit as จดสงซอ,Drug_Detail as รายละเอยดยา FROM Drug WHERE Drug_name LIKE '%" & txtseach.Text & "%'" & " OR Drug_Id LIKE '%" & Me.txtseach.Text & "%' ORDER BY Drug_name" Else SQL = "select Drug_Id as รหสยา,Drug_Name as ชอยา,Unit as จ านวน,drug_t as หนวยนบ,Drug_Price as ราคาตอหนวย,Limit as จดสงซอ,Drug_Detail as รายละเอยดยา FROM Drug ORDER BY Drug_name " End If Dim objDA As New SqlDataAdapter(SQL, conn) Dim objDS As New DataSet()

objDA.Fill(objDS, "Drug") DataGridView1.DataSource = objDS DataGridView1.DataMember = "Drug" conn.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click conn.Open() txDrug_Id.Text = S() txDrug_Id.Enabled = False conn.Close() End Sub Function S() Dim y As New SqlCommand("select max(Drug_Id) from Drug ", conn) Try Dim Sic As String = y.ExecuteScalar() Sic = Mid(Sic, 1, 1) & (Mid(Sic, 6, 6) + 1).ToString("000000") Return Sic Catch Return "D000001" End Try End Function End Class Source Code ชอ frm_login Imports System.Data Imports System.Data.SqlClient 'Data Source=ASUS-PC;Initial Catalog=supod;User ID=doctor;Password=12345 Public Class frm_login

Private Sub Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ok.Click DbConn() Dim c As New SqlCommand("select * from AdminUser where User_Name ='" & txtUser_Name.Text & "' and password ='" & txPassword.Text & "'", conn) Dim d As SqlDataReader = c.ExecuteReader If d.HasRows Then Me.Hide() frm_main.Show() ElseIf txtUser_Name.Text.Trim = "User_Name" And txPassword.Text.Trim = "Password" Then MsgBox("ยนดตอนรบเขาสระบบคะ", MsgBoxStyle.Information, "Welcome") txtUser_Name.Clear() txPassword.Clear() Else MsgBox("กรอกขอมลไมถกตองคะ", MsgBoxStyle.Information, "แจงเตอน") txtUser_Name.Focus() txPassword.Focus() txtUser_Name.Clear() txPassword.Clear() End If d.Close() conn.Close() End Sub Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click If MessageBox.Show("คณตองการจบการท างาน ใชหรอไม?", "ค ายนยน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then End End If

End Sub Private Sub frm_login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub txtUser_Name_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUser_Name.KeyPress End Sub Private Sub txtUser_Name_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtUser_Name.KeyDown If e.KeyCode = Keys.Enter Then txtPassword.Focus() End Sub End Class Source Code ชอ frm_main Public Class frm_main Private Sub ขอมลตวแทนจ าหนายToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ขอมลตวแทนจ าหนายToolStripMenuItem.Click frm_AgentData.MdiParent = Me.MdiParent frm_AgentData.Show() End Sub Private Sub ขอมลยาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ขอมลยาToolStripMenuItem.Click frm_DrugData.MdiParent = Me.MdiParent frm_DrugData.Show() End Sub

Private Sub ตรวจรกษาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ตรวจรกษาToolStripMenuItem.Click frm_Check.MdiParent = Me.MdiParent frm_Check.Show() End Sub Private Sub ท าบตรผปวยToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ท าบตรผปวยToolStripMenuItem.Click frm_sicker.MdiParent = Me.MdiParent frm_sicker.Show() End Sub Private Sub รบช าระคารกษาพยาบาลToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles รบช าระคารกษาพยาบาลToolStripMenuItem.Click Payment.MdiParent = Me.MdiParent Payment.Show() End Sub Private Sub เพมAdminUserToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles เพมAdminUserToolStripMenuItem.Click frm_addUser.MdiParent = Me.MdiParent frm_addUser.ShowDialog() End Sub Private Sub สงซอยาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles สงซอยาToolStripMenuItem.Click order1.MdiParent = Me.MdiParent order1.Show() End Sub

Private Sub ขอมลผปวยToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ขอมลผปวยToolStripMenuItem.Click Dim f As New frm_sicker() f.MdiParent = Me.MdiParent f.Show() f.Focus() End Sub Private Sub รบยาและเวชภณฑToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles รบยาและเวชภณฑToolStripMenuItem.Click frm_Receive.MdiParent = Me.MdiParent frm_Receive.Show() End Sub Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Maximized 156: Dim CurrentWidth As Integer = Screen.PrimaryScreen.Bounds.Width Dim CurrentHeight As Integer = Screen.PrimaryScreen.Bounds.Height End Sub Private Sub รายงานขอมลผปวยToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles รายงานขอมลผปวยToolStripMenuItem.Click RE_Sicker.MdiParent = Me.MdiParent RE_Sicker.Show() End Sub Private Sub รายงานขอมลยาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles รายงานขอมลยาToolStripMenuItem.Click r_drug.MdiParent = Me.MdiParent r_drug.Show() End Sub

Private Sub รายงานการตรวจรกษาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles รายงานการตรวจรกษาToolStripMenuItem.Click r_check.MdiParent = Me.MdiParent r_check.Show() End Sub Private Sub รายงานการสงจายยาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles รายงานการสงจายยาToolStripMenuItem.Click r__orderdispenseorder.MdiParent = Me.MdiParent r__orderdispenseorder.Show() End Sub Private Sub ออกจากโปรแกรมToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ออกจากโปรแกรมToolStripMenuItem.Click ' Dim Result As DialogResult ' Result = MessageBox.Show("คณตองการออกจากระบบหรอไม", "ออกจากระบบ", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) 'If Result = Windows.Forms.DialogResult.Yes Then End ' End If End Sub Private Sub รายงานขอมลตวแทนจ าหนายToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles รายงานขอมลตวแทนจ าหนายToolStripMenuItem.Click r_agent.MdiParent = Me.MdiParent r_agent.Show() End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub Private Sub พมพใบนดหมายToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles พมพใบนดหมายToolStripMenuItem.Click frm_appoint.MdiParent = Me.MdiParent frm_appoint.Show() End Sub End Class

Source Code ชอ frm_Pay

Imports System.Data Imports System.Data.SqlClient 'Data Source=ASUS-PC;Initial Catalog=supod;User ID=doctor;Password=12345 Public Class frm_Pay Private Sub frm_Pay_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Maximized DbConn() Displaydata() conn.Close() End Sub Sub Displaydata() Dim da As New SqlClient.SqlDataAdapter("select Pay_Id as รหสจายช าระ,Receive_Id as รหสรบยา,User_Id as รหสพนกงาน,Pay_NetTotal as ราคารวมสทธ,Pay_Date as วนทจายช าระ from Pay", conn) Dim ds As New DataSet da.Fill(ds, "Pay")

DataGridView1.DataSource = ds DataGridView1.DataMember = "Pay" End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick If e.RowIndex = -1 Then Exit Sub With DataGridView1() txtPay_Id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtReceive_Id.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtUser_Name.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() txtPay_NetTotal.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() txtPay_Dayy.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() End With End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click conn.Open() Dim y As New SqlCommand("delete from Pay where Pay_Id ='" & txtPay_Id.Text & "'", conn) ' Dim Result As DialogResult ' Result = MessageBox.Show("คณตองการลบขอมลใชหรอไม", "คณตองการลบขอมลใชหรอไม !", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Try y.ExecuteNonQuery() ' MsgBox("ลบขอมลส าเรจ") Displaydata() ClearData() Catch

MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try conn.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ClearData() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click ' Dim result As DialogResult ' result = MessageBox.Show("คณตองการปดหนาตางนจรงหรอ", "ยนยน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) 'If result = Windows.Forms.DialogResult.Yes Then Me.Close() frm_Receive.Close() ' End If End Sub Sub ClearData() txtPay_Id.Text = "" txtReceive_Id.Text = "" txtUser_Name.Text = "" txtPay_Dayy.Text = "" txtPay_NetTotal.Text = "" End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

If conn.State <> ConnectionState.Open Then conn.Open() End If Dim y As New SqlCommand("insert into Pay values('" & _ txtPay_Id.Text & "','" & txtReceive_Id.Text & "','" & _ txtUser_Name.Text & "','" & txtPay_Dayy.Text & "','" & txtPay_NetTotal.Text & "')", conn) Try y.ExecuteNonQuery() ' MsgBox("บนทกขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox("เกดความผดพลาด เนองจาก " & Err.Description) End Try conn.Close() End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click conn.Open() Dim y As New SqlCommand("update Pay set Pay_Id='" & _ txtPay_Id.Text & "', Receive_Id= '" & _ txtReceive_Id.Text & "',User_Id = '" & _ txtUser_Name.Text & "',Pay_NetTotal= '" & _ txtPay_NetTotal.Text & "' where Pay_Date = '" & txtPay_Dayy.Text & "'", conn) Try y.ExecuteNonQuery()

' MsgBox("แกไขขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try ClearData() conn.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click conn.Open() txtPay_Id.Text = S() txtPay_Id.Enabled = False conn.Close() End Sub Function S() Dim y As New SqlCommand("select max(Pay_Id) from Pay ", conn) Try Dim Sic As String = y.ExecuteScalar() Sic = Mid(Sic, 1, 1) & (Mid(Sic, 6, 6) + 1).ToString("000000") Return Sic Catch Return "P000001" End Try End Function

Private Sub txtsearh_Pay_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearh_Pay.TextChanged If conn.State <> ConnectionState.Open Then conn.Open() End If Dim SQL As String If (txtsearh_Pay.Text <> "") Then 'การทางานเมอTextbox ไมเปนคาวาง SQL = "select Pay_Id as รหสจายช าระ,Receive_Id as รหสรบยา,User_Id as รหสพนกงาน,Pay_NetTotal as ราคารวมสทธ,Pay_Date as วนทจายช าระ from Pay WHERE Pay_id LIKE '%" & txtsearh_Pay.Text & "%'" & " OR Pay_Id LIKE '%" & Me.txtsearh_Pay.Text & "%' ORDER BY Pay_id" Else SQL = "select Pay_Id as รหสจายช าระ,Receive_Id as รหสรบยา,User_Id as รหสพนกงาน,Pay_NetTotal as ราคารวมสทธ,Pay_Date as วนทจายช าระ from Pay ORDER BY Pay_id " End If Dim objDA As New SqlDataAdapter(SQL, conn) Dim objDS As New DataSet() objDA.Fill(objDS, "Pay") DataGridView2.DataSource = objDS DataGridView2.DataMember = "Pay" End Sub Private Sub txtReceive_Id_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtReceive_Id.TextChanged txtReceive_Id.Text = frm_Receive.txtReceive_Id.Text End Sub End Class Source Code ชอ Payment

Imports System.Data Imports System.Data.SqlClient 'Data Source=ASUS-PC;Initial Catalog=supod;User ID=doctor;Password=12345 Public Class Payment Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Maximized DbConn() Displaydata2() conn.Close() End Sub Sub Displaydata2() Dim da As New SqlClient.SqlDataAdapter("select OrderDispenseorder_Id as เลขทใบเสรจ,Sicker_name as ผปวย ,OrderDate as วนทจายช าระ,NetTotal as ยอดสทธ from OrderDispenseorder where status=0", Conn) Dim ds As New DataSet da.Fill(ds, "Payment") DataGridView2.DataSource = ds DataGridView2.DataMember = "Payment" End Sub Sub Displaydata() Dim da As New SqlClient.SqlDataAdapter("select payment_Id as รหสการจายช าระ,Sicker_ID as รหสผปวย ,Payment_Date as วนทจายช าระ,check_order as รายการตรวจรกษา,Payment_Ser as คารกษา,drug_name as ชอยา,Limit_order as จ านวนยา,order_Price as ราคาตอหนวย,Payment_Drug as คายา,Payment_Total as ราคารวมสทธ ,payment_accept as จ านวนเงนทรบ ,payment_Moneydown as เงนทอน from Payment ", conn) Dim ds As New DataSet da.Fill(ds, "Payment")

DataGridView1.DataSource = ds DataGridView1.DataMember = "Payment" End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If conn.State <> ConnectionState.Open Then conn.Open() End If ' Dim y As New SqlCommand("delete from Payment where Payment_id ='" & txtPayment_Id.Text & "'", conn) ' Dim Result As DialogResult ' Result = MessageBox.Show("คณตองการลบขอมลใชหรอไม", "คณตองการลบขอมลใชหรอไม ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Try ' y.ExecuteNonQuery() ' MsgBox("ลบขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try conn.Close() End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If Dim y As New SqlCommand("Update OrderDispenseorder Set status=1,money_re=" & CDbl(txtpayment_accept.Text) & ",money_chg=" & CDbl(txtpayment_Moneydown.Text) & " where status=0 and OrderDispenseorder_Id='" & OrderID & "'", Conn) Try y.ExecuteNonQuery() MsgBox("บนทกขอมลส าเรจ", MsgBoxStyle.Information, "แจงผลการบนทก") Displaydata() ClearData() Catch MsgBox("เกดความผดพลาด เนองจาก " & Err.Description) End Try Conn.Close() End Sub Sub ClearData() txtpayment_Total.Text = "" txtpayment_accept.Text = "" txtpayment_Moneydown.Text = "" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Close() End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click If conn.State <> ConnectionState.Open Then conn.Open() End If If OrderID = "" Then ' MessageBox.Show("ยงไมเลอกรายการทตองการพมพ ", "ผดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error) DataGridView2.Focus() Exit Sub Else r_slip.Show() End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If Conn.State <> ConnectionState.Open Then Conn.Open() End If 'txtPayment_Id.Text = S() 'txtPayment_Id.Enabled = False Conn.Close() End Sub Function S() Dim y As New SqlCommand("select max(Payment_Id) from Payment ", conn) Try

Dim Sic As String = y.ExecuteScalar() Sic = Mid(Sic, 1, 1) & (Mid(Sic, 6, 6) + 1).ToString("000000") Return Sic Catch Return "P000001" End Try End Function Private Sub txtSeachCheck_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSeachCheck.TextChanged If conn.State <> ConnectionState.Open Then conn.Open() End If Dim SQL As String If (txtSeachCheck.Text <> "") Then 'การทางานเมอTextbox ไมเปนคาวาง SQL = "select OrderDispenseorder_Id as เลขทใบเสรจ,Sicker_name as ผปวย ,OrderDate as วนทจายช าระ,NetTotal as ยอดสทธ,check_id from OrderDispenseorder WHERE sicker_name LIKE '%" & txtSeachCheck.Text & "%'" & " OR Sicker_Id LIKE '%" & Me.txtSeachCheck.Text & "%' ORDER BY OrderDispenseorder_Id" Else SQL = "select OrderDispenseorder_Id as เลขทใบเสรจ,Sicker_name as ผปวย ,OrderDate as วนทจายช าระ,NetTotal as ยอดสทธ,check_id from OrderDispenseorder ORDER BY OrderDispenseorder_Id " End If Dim objDA As New SqlDataAdapter(SQL, conn) Dim objDS As New DataSet() objDA.Fill(objDS, "OrderDispenseorder") DataGridView2.DataSource = objDS DataGridView2.DataMember = "OrderDispenseorder" DataGridView2.Columns(4).Visible = False

conn.Close() End Sub 'OrderDispenseorder_Id as รหสสงจายยา,sicker_Id as รหสผปวย,drug_Id as รหสยา,Drug_name as ชอยา,Limit as จ านวน,order_Price as ราคาตอหนวย,Order_TotalPrice as ราคารวมสทธ from OrderDispenseorder Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim q As Decimal Dim r As Decimal 'q = txtPayment_Ser.Text 'r = txtPayment_Drug.Text Dim Total As Decimal Total = q + r txtpayment_Total.Text = Total End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Dim qq As Decimal Dim rr As Decimal qq = txtpayment_Total.Text rr = txtpayment_accept.Text Dim Moneydown As Decimal Moneydown = rr - qq txtpayment_Moneydown.Text = Moneydown End Sub Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click If conn.State <> ConnectionState.Open Then conn.Open() End If Try Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try conn.Close() End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub DataGridView2_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView2.CellFormatting If DataGridView2.Columns(e.ColumnIndex).Name = "ยอดสทธ" Then e.CellStyle.Format = "#,##0.00" e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight End If If DataGridView2.Columns(e.ColumnIndex).Name = "วนทจายช าระ" Then e.CellStyle.Format = "d MMM yyyy" End If End Sub

Private Sub DataGridView2_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView2.CellMouseUp On Error Resume Next If e.RowIndex = -1 Then Exit Sub With DataGridView2() OrderID = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() CheckID = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() Dim da As New SqlClient.SqlDataAdapter("select OrderDispenseorder_Id as เลขทใบเสรจ,drug_id as รหสยา,drug_name as ชอยา,drug_price as ราคา,qty as จ านวน,drug_t as หนวย,total as จ านวนเงน from orderdispenseorder__detail where OrderDispenseorder_Id='" & .Rows.Item(e.RowIndex).Cells(0).Value.ToString() & "'", Conn) Dim ds As New DataSet da.Fill(ds, "OrderDispenseorder_detail") DataGridView1.DataSource = ds DataGridView1.DataMember = "OrderDispenseorder_detail" txtpayment_Total.Text = Convert.ToDouble(.Rows.Item(e.RowIndex).Cells(3).Value).ToString("#,##0.00") txtpayment_accept.Text = "0" txtpayment_Moneydown.Text = "0" End With End Sub Private Sub DataGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting If DataGridView1.Columns(e.ColumnIndex).Name = "จ านวนเงน" Then e.CellStyle.Format = "#,##0.00" e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

End If End Sub Private Sub txtpayment_accept_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpayment_accept.TextChanged On Error Resume Next Button7_Click(txtpayment_Total, e) End Sub End Class Source Code ชอ frm_Receive

Imports System.Data Imports System.Data.SqlClient 'Data Source=ASUS-PC;Initial Catalog=supod;User ID=doctor;Password=12345 Imports System.Text Public Class frm_Receive Dim Total As Double = 0.0 Dim com As SqlCommand Dim dr As SqlDataReader Dim dtBranch As DataTable Dim dtSupplier As DataTable Dim tr As SqlTransaction Dim COrderID As String Dim sb As New StringBuilder() Dim UserName As String Dim IsShowDetails As Boolean = False

Dim QuantityPerUnit As Integer = 0 Private Sub frm_sicker_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Me.WindowState = FormWindowState.Maximized DbConn() ' Displaydata() 'Conn.Close() With lsvProductList .Columns.Add("รหสยา", 90, HorizontalAlignment.Left) .Columns.Add("ชอยา", 275, HorizontalAlignment.Left) .Columns.Add("รบ", 50, HorizontalAlignment.Right) .Columns.Add("คางรบ", 50, HorizontalAlignment.Right) .Columns.Add("รวมเปนเงน", 105, HorizontalAlignment.Right) .Columns.Add("", 0, HorizontalAlignment.Right) .Columns.Add("", 0, HorizontalAlignment.Right) .Columns.Add("", 0, HorizontalAlignment.Right) .View = View.Details .GridLines = True End With com = New SqlCommand() com.Connection = Conn End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bdelete.Click Conn.Open() Dim y As New SqlCommand("delete from Receive_detail where Order_Id ='" & txtOrder_Id.Text & "'", Conn) Dim Result As DialogResult

Result = MessageBox.Show("คณตองการลบขอมลใชหรอไม", "คณตองการลบขอมลใชหรอไม !", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Try y.ExecuteNonQuery() ' MsgBox("ลบขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try Conn.Close() End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If Dim y As New SqlCommand("update Receive_detail set Order_Id = '" & _ txtOrder_Id.Text & "', detail= '" & _ txtdetail.Text & "',User_Id = '" & _ txtUser_Id.Text & "',Receive_Date = '" & _ txtPay_Date.Text & "',status = '" & _ txtstatus.Text & "',Receive_Nettotal = '" & _ txtPay_NetTotal.Text & "',Receive_Accept = '" & _ txtReceive_Qty.Text & "' where Receive_Id = '" & txtReceive_Id.Text & "'", Conn) Try y.ExecuteNonQuery() ' MsgBox("แกไขขอมลส าเรจ") Displaydata()

ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try ClearData() Conn.Close() End Sub Sub Displaydata() Dim da As New SqlClient.SqlDataAdapter("select Order_Id as รหสการสงซอ,Receive_Id as รหสการรบยา,User_Id as รหสพนกงาน,Receive_Date as วนทรบยา,Receive_Nettotal as จ านวนเงนสทธ,Receive_Accept as จ านวนยาทรบ,status as สถานะ,detail as หมายเหต from Receive_detail", Conn) Dim ds As New DataSet da.Fill(ds, "Receive_detail") DataGridView1.DataSource = ds DataGridView1.DataMember = "Receive_detail" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Close() End Sub Sub ClearData() txtOrder_Id.Text = "" txtReceive_Id.Text = "" txtUser_Id.Text = "" txtPay_Date.Text = "" txtPay_NetTotal.Text = ""

txtReceive_Qty.Text = "" txtdetail.Text = "" txtstatus.Text = "" End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ClearData() End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If Dim y As New SqlCommand("insert Receive_detail values('" & _ txtOrder_Id.Text & "','" & txtReceive_Id.Text & "','" & _ txtUser_Id.Text & "','" & txtPay_Date.Text & "','" & _ txtPay_NetTotal.Text & "','" & txtReceive_Qty.Text & "','" & _ txtdetail.Text & "','" & txtstatus.Text & "')", Conn) Try y.ExecuteNonQuery() ' ' MsgBox("บนทกขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox("เกดความผดพลาด เนองจาก " & Err.Description)

End Try Conn.Close() End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Conn.Open() txtReceive_Id.Text = S() txtReceive_Id.Enabled = False Conn.Close() End Sub Function S() Dim y As New SqlCommand("select max(Receive_Id) from Receive_detail ", Conn) Try Dim Sic As String = y.ExecuteScalar() Sic = Mid(Sic, 1, 1) & (Mid(Sic, 6, 6) + 1).ToString("0000000") Return Sic Catch Return "R000001" End Try End Function Private Sub txtserchorder_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtserchorder.TextChanged

If Conn.State <> ConnectionState.Open Then Conn.Open() End If Dim SQL As String If (txtserchorder.Text <> "") Then SQL = "select Order_Id as เลขทใบสงซอ,User_name as ชอพนกงาน,Agent_Id as ตวแทนจ าหนาย,OrderDate as วนทสงซอ,NetTotal as ยอดรวมสทธ,status as สถานะ from Orderr WHERE Order_Id LIKE '%" & txtserchorder.Text & "%'" & " OR Order_Id LIKE '%" & Me.txtserchorder.Text & "%' ORDER BY Order_Id" Else SQL = "select Order_Id as เลขทใบสงซอ,User_name as ชอพนกงาน,Agent_Id as ตวแทนจ าหนาย,OrderDate as วนทสงซอ,NetTotal as ยอดรวมสทธ,status as สถานะ from Orderr ORDER BY Order_Id " End If Dim objDA As New SqlDataAdapter(SQL, Conn) Dim objDS As New DataSet() objDA.Fill(objDS, "orderr") DataGridView2.DataSource = objDS DataGridView2.DataMember = "orderr" DataGridView2.Columns(2).Width = 200 Conn.Close() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click frm_Pay.MdiParent = Me.MdiParent frm_Pay.Show() End Sub

Private Sub DataGridView2_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellContentClick End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick End Sub Private Sub DataGridView2_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView2.CellMouseUp Dim Sql As String If e.RowIndex = -1 Then Exit Sub With DataGridView2() OrderID = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() End With Sql = "select Order_Id as เลขทใบสงซอ,Drug_ID as รหสยา,drug_name as ชอยา,order_price as ราคา,order_qty as จ านวนสงซอ,UnitName as หนวยนบ,NumberToReceived As รบแลว,total as จ านวนเงน from Orderr_detail Where Order_id='" & OrderID & "' ORDER BY Order_Id " Dim objDA As New SqlDataAdapter(Sql, Conn) Dim objDS As New DataSet() objDA.Fill(objDS, "orderr_detail") DataGridView1.DataSource = objDS DataGridView1.DataMember = "orderr_detail" DataGridView1.Columns(0).Width = 98 DataGridView1.Columns(3).Width = 60 DataGridView1.Columns(4).Width = 90

DataGridView1.Columns(6).Width = 70 DataGridView1.Columns(7).Width = 90 End Sub Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click If (lblProductID.Text.Trim() = "") OrElse (lblProductName.Text.Trim() = "") Then cmdAdd.Focus() Exit Sub End If If (CInt(txtAccept.Text) = 0) Then txtAccept.Focus() txtAccept.SelectAll() Exit Sub End If If CInt(txtAccept.Text) > CInt(lblNetReceived.Text) Then MessageBox.Show("คณใสจ านวนยามากกวา จ านวนยาทคางรบ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information) txtAccept.Focus() txtAccept.SelectAll() Exit Sub End If Dim i As Integer = 0 Dim lvi As ListViewItem Dim ProductID As String = "" For i = 0 To lsvProductList.Items.Count - 1 ProductID = lsvProductList.Items(i).SubItems(0).Text If lblProductID.Text.Trim() = ProductID Then

MessageBox.Show("คณเลอกรายการยา ซ ากน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information) RemoveHandler txtAccept.TextChanged, AddressOf txtAccept_TextChanged ClearProductDetails() AddHandler txtAccept.TextChanged, AddressOf txtAccept_TextChanged cmdAdd.Focus() Exit Sub End If Next Dim anyData() As String Dim DCDecrease As Double = 0.0 Dim NewDiscount As Double = 0.0 Dim TotalDecrease As Double = 0.0 Dim NewTotal As Double = 0.0 Dim NoReceived As Integer = 0 NewTotal = Total NoReceived = CInt(lblNetReceived.Text) - CInt(txtAccept.Text) anyData = New String() { _ lblProductID.Text, _ lblProductName.Text, _ txtAccept.Text, _ NoReceived.ToString(), _ NewTotal.ToString("#,##0.00"), _ OrderID, _

lblCost.Text _ } lvi = New ListViewItem(anyData) lsvProductList.Items.Add(lvi) CalculateNet() RemoveHandler txtAccept.TextChanged, AddressOf txtAccept_TextChanged ClearProductDetails() AddHandler txtAccept.TextChanged, AddressOf txtAccept_TextChanged End Sub Private Sub CalculateNet() Dim i As Integer = 0 Dim NetTotal As Single = 0.0 For i = 0 To lsvProductList.Items.Count - 1 NetTotal = NetTotal + CSng(lsvProductList.Items(i).SubItems(4).Text) Next lblNetTotal.Text = NetTotal.ToString("#,##0.00") End Sub Private Sub ClearProductDetails() lblProductID.Text = "" lblProductName.Text = "" lblCost.Text = "0" lblNumberToOrder.Text = "0" lblUnitName.Text = ""

lblNumberToReceived.Text = "0" lblNetReceived.Text = "0" txtAccept.Text = "0" End Sub Private Sub DataGridView2_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView2.CellFormatting If e.ColumnIndex = -1 Then Exit Sub If DataGridView2.Columns(e.ColumnIndex).Name = "ยอดรวมสทธ" Then e.CellStyle.Format = "#,##0.00" e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight End If If DataGridView2.Columns(e.ColumnIndex).Name = "วนทสงซอ" Then e.CellStyle.Format = "d MMM yyyy" e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter End If End Sub Private Sub DataGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting If e.ColumnIndex = -1 Then Exit Sub If DataGridView1.Columns(e.ColumnIndex).Name = "รบแลว" Then e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight End If If DataGridView1.Columns(e.ColumnIndex).Name = "จ านวนสงซอ" Then

e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight End If If DataGridView1.Columns(e.ColumnIndex).Name = "ราคา" Then e.CellStyle.Format = "#,##0.00" e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight End If If DataGridView1.Columns(e.ColumnIndex).Name = "จ านวนเงน" Then e.CellStyle.Format = "#,##0.00" e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight End If End Sub Private Sub DataGridView1_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseUp On Error Resume Next If e.RowIndex = -1 Then Exit Sub With DataGridView1 ' select Order_Id as เลขทใบสงซอ,Drug_ID as รหสยา,drug_name as ชอยา,order_price as ราคา,order_qty as จ านวนสงซอ,UnitName as หนวยนบ,0 As รบแลว,total as จ านวนเงน lblProductID.Text = CStr(.Rows.Item(e.RowIndex).Cells(1).Value) lblProductName.Text = CStr(.Rows.Item(e.RowIndex).Cells(2).Value) lblNumberToOrder.Text = CStr(.Rows.Item(e.RowIndex).Cells(4).Value) lblUnitName.Text = CStr(.Rows.Item(e.RowIndex).Cells(5).Value) lblCost.Text = CStr(.Rows.Item(e.RowIndex).Cells(3).Value) lblNumberToReceived.Text = CStr(.Rows.Item(e.RowIndex).Cells(6).Value) lblNetReceived.Text = CStr(CInt(lblNumberToOrder.Text) - CInt(lblNumberToReceived.Text))

OrderID = CStr(.Rows.Item(e.RowIndex).Cells(0).Value) Total = CDbl(.Rows.Item(e.RowIndex).Cells(7).Value) End With txtAccept.Focus() txtAccept.SelectAll() End Sub Private Sub txtAccept_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAccept.KeyPress If e.KeyChar < "0" Or e.KeyChar > "9" Then e.Handled = True End Sub Private Sub txtAccept_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAccept.TextChanged If txtAccept.Text.Trim() = "" Then txtAccept.Text = "0" End If CheckAmount() End Sub Private Sub CheckAmount() If lblNetReceived.Text.Trim() = "" Then lblNetReceived.Text = "0" Exit Sub End If If txtAccept.Text.Trim() = "" Then txtAccept.Text = "0" Exit Sub

End If If CInt(txtAccept.Text) > CInt(lblNetReceived.Text) Then MessageBox.Show("คณใสจ านวนรบยามากกวา จ านวนยาทคางรบ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information) txtAccept.Focus() txtAccept.SelectAll() End If End Sub Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click If (lsvProductList.Items.Count = 0) Then Exit Sub DbConn() com.Connection = Conn If MessageBox.Show("คณตองการบนทกรบ รายการยา ใชหรอไม?", "ค ายนยน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then tr = Conn.BeginTransaction() Dim i As Integer Dim sqlSave As String Dim OldNumberToOrder As Integer Dim OldNumberToReceived As Integer Dim COrderID As String = lsvProductList.Items(i).SubItems(5).Text Dim CProductID As String Dim IsComplete As Boolean = False Dim IsReceivedAll As String = ""

Dim OldQuantityPerUnit As Integer = 0 Dim OldQuantityWithUnit As Double = 0.0 Dim OldRealQuantity As Integer = 0 Dim OldProductInOrder As Integer = 0 Dim NewQuantityWithUnit As Double = 0.0 Dim NewRealQuantity As Integer = 0 Dim NewProductInOrder As Integer = 0 Dim AcceptProduct As Integer = 0 Dim CancelProduct As Integer = 0 Dim CQuantityPerUnit As Integer = 0 Dim CCost As Double = 0.0 Dim CCostAvg As Double = 0.0 Try For i = 0 To lsvProductList.Items.Count - 1 CProductID = lsvProductList.Items(i).SubItems(0).Text AcceptProduct = CInt(lsvProductList.Items(i).SubItems(2).Text) CCost = CDbl(lsvProductList.Items(i).SubItems(6).Text) If CInt(lsvProductList.Items(i).SubItems(3).Text) > 0 Then IsComplete = False Else IsComplete = True End If If IsComplete = True Then IsReceivedAll = "รบครบ" Else IsReceivedAll = "คางรบ" End If

sb = New StringBuilder() sb.Remove(0, sb.Length) sb.Append("SELECT Order_ID,Drug_ID,Order_qty,NumberToReceived") sb.Append(" FROM Orderr_Detail") sb.Append(" WHERE (Order_ID=@OrderID)") sb.Append(" AND (Drug_ID=@DrugID)") sqlSave = sb.ToString() With com .Parameters.Clear() .Parameters.Add("@OrderID", SqlDbType.NVarChar).Value = COrderID .Parameters.Add("@DrugID", SqlDbType.NVarChar).Value = CProductID .Transaction = tr .CommandText = sqlSave dr = .ExecuteReader() If dr.HasRows Then dr.Read() OldNumberToOrder = dr.GetInt32(2) OldNumberToReceived = dr.GetInt32(3) End If dr.Close() ' If CInt(lsvProductList.Items(i).SubItems(3).Text) <> 0 Then sb.Remove(0, sb.Length) sb.Append("UPDATE Orderr_Detail") sb.Append(" SET NumberToReceived=@NumberToReceived,") sb.Append(" Total=@Total,") sb.Append(" Status=@IsReceivedAll") sb.Append(" WHERE (Order_ID=@OrderID)") sb.Append(" AND (Drug_ID=@DrugID)")

.Parameters.Clear() .Parameters.Add("@NumberToReceived", SqlDbType.Int).Value = OldNumberToReceived + CInt(lsvProductList.Items(i).SubItems(2).Text) .Parameters.Add("@Total", SqlDbType.Float).Value = CDbl(lsvProductList.Items(i).SubItems(6).Text) .Parameters.Add("@IsReceivedAll", SqlDbType.NVarChar).Value = IsReceivedAll .Parameters.Add("@OrderID", SqlDbType.NVarChar).Value = COrderID .Parameters.Add("@DrugID", SqlDbType.NVarChar).Value = CProductID ' End If sqlSave = sb.ToString() .CommandText = sqlSave .ExecuteNonQuery() sb.Remove(0, sb.Length) sb.Append("SELECT Drug_ID,Unit") sb.Append(" FROM Drug") sb.Append(" WHERE (Drug_Id =@DrugID)") sqlSave = sb.ToString() .CommandText = sqlSave .Parameters.Clear() .Parameters.Add("@DrugID", SqlDbType.NVarChar).Value = CProductID dr = .ExecuteReader() Dim OldStockUnit As Integer = 0 Dim dtProduct As DataTable dtProduct = New DataTable If dr.HasRows Then dr.Read() OldStockUnit = dr.GetInt32(1) 'ยอดสตอกเดม

End If dr.Close() NewRealQuantity = OldRealQuantity + (AcceptProduct) + OldStockUnit 'NewProductInOrder = OldProductInOrder - ((AcceptProduct + CancelProduct) * CQuantityPerUnit) 'NewQuantityWithUnit = CDbl(NewRealQuantity / OldQuantityPerUnit) sb.Remove(0, sb.Length) sb.Append("UPDATE Drug") sb.Append(" SET Unit=@RealQuantity") sb.Append(" WHERE (Drug_ID=@DrugID)") sqlSave = sb.ToString() .CommandText = sqlSave .Parameters.Clear() .Parameters.Add("@RealQuantity", SqlDbType.Int).Value = NewRealQuantity .Parameters.Add("@DrugID", SqlDbType.NVarChar).Value = CProductID .ExecuteNonQuery() End With Next Dim IsZero As Boolean = False Dim IsOne As Boolean = False Dim IsTwo As Boolean = False Dim dtCheck As DataTable Dim drw As DataRow Dim OrdersStatus As String = "0"

Dim sqlCheck As String sb.Remove(0, sb.Length) sb.Append("SELECT Order_ID,status FROM Orderr_Detail") sb.Append(" WHERE (Order_ID=@OrderID)") sqlCheck = sb.ToString() With com .CommandText = sqlCheck .Parameters.Clear() .Parameters.Add("@OrderID", SqlDbType.NVarChar).Value = COrderID dr = .ExecuteReader() If dr.HasRows Then dtCheck = New DataTable dtCheck.Load(dr) IsZero = False IsOne = False IsTwo = False OrdersStatus = "0" For Each drw In dtCheck.Rows If drw.Item("Status").ToString() = "0" Then IsZero = True End If If drw.Item("Status").ToString() = "รบครบ" Then IsOne = True End If If drw.Item("Status").ToString() = "คางรบ" Then

IsTwo = True End If Next End If dr.Close() End With If ((IsZero = True) AndAlso (IsOne = True)) OrElse (IsTwo = True) Then OrdersStatus = "คางรบ" ElseIf (IsZero = False) AndAlso (IsOne = True) AndAlso (IsTwo = False) Then OrdersStatus = "รบครบ" End If Dim SumDC As Double = 0.0 Dim SumTotal As Double = 0.0 sb.Remove(0, sb.Length()) sb.Append("SELECT Order_ID,SUM(Total) AS SumTotal") sb.Append(" FROM Orderr_Detail") sb.Append(" GROUP BY Order_ID") sb.Append(" HAVING (Order_ID=@OrderID)") sqlSave = sb.ToString() With com .CommandText = sqlSave .Parameters.Clear() .Parameters.Add("@OrderID", SqlDbType.NVarChar).Value = COrderID dr = .ExecuteReader() If dr.HasRows Then dr.Read() SumTotal = dr.GetDouble(1)

End If End With dr.Close() sb.Remove(0, sb.Length()) sb.Append("SELECT Order_ID FROM Orderr") sb.Append(" WHERE (Order_ID=@OrderID)") sqlSave = sb.ToString() With com .CommandText = sqlSave .Parameters.Clear() .Parameters.Add("@OrderID", SqlDbType.NVarChar).Value = COrderID dr = .ExecuteReader() If dr.HasRows Then dr.Read() ' VATRate = dr.GetDouble(1) dr.Close() End If End With dr.Close() Dim NewNet As Double = 0.0 NewNet = SumTotal sb.Remove(0, sb.Length) sb.Append("UPDATE Orderr") sb.Append(" SET Status='" & OrdersStatus & "',") sb.Append(" NetTotal=@Net") sb.Append(" WHERE (Order_ID=@OrderID)") sqlSave = sb.ToString()

With com .CommandText = sqlSave .Parameters.Clear() .Parameters.Add("@Net", SqlDbType.Float).Value = NewNet .Parameters.Add("@OrderID", SqlDbType.NVarChar).Value = COrderID .ExecuteNonQuery() End With tr.Commit() lblNetTotal.Text = "0.00" RemoveHandler txtAccept.TextChanged, AddressOf txtAccept_TextChanged ClearProductDetails() AddHandler txtAccept.TextChanged, AddressOf txtAccept_TextChanged lsvProductList.Items.Clear() MessageBox.Show("บนทกรายการรบ รายการยา เรยบรอยแลว !!!", "ผลการท างาน", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As Exception tr.Rollback() MessageBox.Show("ไมสามารถบนทกรายการสงซอได เนองจาก " & ex.Message, "ขอผดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning) cmdSave.Focus() End Try End If End Sub End Class

Source Code ชอ frm_sicker

Imports System.Data Imports System.Data.SqlClient 'Data Source=ASUS-PC;Initial Catalog=supod;User ID=doctor;Password=12345 Public Class frm_sicker 'Dim conn As New SqlClient.SqlConnection("Data Source=asus-pc;Initial Catalog=supod;Integrated Security=True;") Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick If e.RowIndex = -1 Then Exit Sub With DataGridView1() txtsicker_id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtsicker_Name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() cmbsex.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() cmbsicker_blood.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() txtsicker_IDCard.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() masksicker_Birthday.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString() txtsicker_Address.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString() maskSicker_tel.Text = .Rows.Item(e.RowIndex).Cells(6).Value.ToString() End With End Sub Sub Displaydata() Dim da As New SqlClient.SqlDataAdapter(" select sicker_ID as รหสผปวย,sicker_Name as ชอ,sicker_Sex as เพศ,sicker_Blood as กรปเลอด,sicker_IDCard as เลขบตรประชาชน,sicker_Birthday as วนเกด,sicker_Address as ทอย,sicker_Tel as เบอรโทรศพท ,Sicker_DateTimePicker1 as วนทใชบรการ,Sicker_Weight as น าหนก,Sicker_High as สวนสง

,sicker_lowpressure as SYS,sicker_highpressure as DIA,Sicker_Pulse as Pulse,Sicker_behavior as อาการเบองตน,sicker_Diseased as โรคประจ าตว,sicker_DrugAllergy as แพยา from Sicker", conn) Dim ds As New DataSet da.Fill(ds, "Sicker") DataGridView1.DataSource = ds DataGridView1.DataMember = "Sicker" End Sub Private Sub savesicker_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles savesicker.Click If conn.State <> ConnectionState.Open Then conn.Open() End If Dim y As New SqlCommand(" insert into Sicker values('" & _ txtsicker_id.Text & "','" & txtsicker_Name.Text & "','" & cmbsex.Text & "','" & _ cmbsicker_blood.Text & "','" & txtsicker_IDCard.Text & "','" & masksicker_Birthday.Text & "','" & _ txtsicker_Address.Text & "','" & maskSicker_tel.Text & "','" & txtSicker_Date.Text & "','" & txtSicker_Weight.Text & "','" & _ txtSicker_High.Text & "','" & txtsicker_highpressure.Text & "','" & txtsicker_Pressure.Text & "','" & txtSicker_Pulse.Text & "','" & _ txtbehavior.Text & "','" & txtsicker_Diseased.Text & "','" & _ txtsicker_DrugAllergy.Text & "')", conn) Try y.ExecuteNonQuery() ' MsgBox("บนทกขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox("เกดความผดพลาด เนองจาก " & Err.Description) End Try

conn.Close() End Sub Sub ClearData() txtsicker_Name.Text = "" cmbsex.Text = "" cmbsicker_blood.Text = "" txtsicker_Diseased.Text = "" txtsicker_DrugAllergy.Text = "" txtsicker_IDCard.Text = "" masksicker_Birthday.Text = "" txtsicker_Address.Text = "" maskSicker_tel.Text = "" txtsicker_id.Text = "" txtSicker_Weight.Text = "" txtSicker_High.Text = "" txtsicker_Pressure.Text = "" txtsicker_highpressure.Text = " " txtbehavior.Text = "" txtSicker_Pulse.Text = "" End Sub Private Sub frm_sicker_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Maximized DbConn() Displaydata() Conn.Close() End Sub

Private Sub AddSicker_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddSicker.Click ClearData() End Sub Private Sub bend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bend.Click Me.Close() End Sub Private Sub delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delete.Click If conn.State <> ConnectionState.Open Then conn.Open() End If Dim y As New SqlCommand(" delete from Sicker where sicker_Name ='" & txtsicker_Name.Text & "'", conn) Try y.ExecuteNonQuery() Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try conn.Close() End Sub

Private Sub edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles edit.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If Dim y As New SqlCommand(" update Sicker set Sicker_name ='" & _ txtsicker_Name.Text & "',sicker_Sex = '" & _ cmbsex.Text & "',sicker_Blood = '" & _ cmbsicker_blood.Text & "',sicker_IDCard = '" & _ txtsicker_IDCard.Text & "',sicker_Birthday = '" & _ masksicker_Birthday.Text & "',sicker_Address = '" & _ txtsicker_Address.Text & "',sicker_Tel = '" & _ maskSicker_tel.Text & "',Sicker_DateTimePicker1 = '" & _ txtSicker_Date.Text & "',Sicker_Weight = '" & _ txtSicker_Weight.Text & "',Sicker_High = '" & _ txtSicker_High.Text & "',sicker_lowpressure = '" & _ txtsicker_highpressure.Text & "',sicker_highpressure = '" & _ txtsicker_Pressure.Text & "',Sicker_Pulse = '" & _ txtSicker_Pulse.Text & "',sicker_behavior = '" & _ txtbehavior.Text & "',sicker_Diseased = '" & _ txtsicker_Diseased.Text & "',sicker_DrugAllergy = '" & _ txtsicker_DrugAllergy.Text & "' where Sicker_Id = '" & txtsicker_id.Text & "'", Conn) Try y.ExecuteNonQuery() ' MsgBox("แกไขขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try

ClearData() Conn.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If conn.State <> ConnectionState.Open Then conn.Open() End If txtsicker_id.Text = S() txtsicker_id.Enabled = False conn.Close() End Sub Function S() Dim y As New SqlCommand("select max(Sicker_id) from Sicker ", conn) Try Dim Sic As String = y.ExecuteScalar() Sic = Mid(Sic, 1, 1) & (Mid(Sic, 6, 6) + 1).ToString("000000") Return Sic Catch Return "S000001" End Try End Function Private Sub txtfindsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtfindsearch.TextChanged If conn.State <> ConnectionState.Open Then conn.Open() End If

Dim SQL As String If (txtfindsearch.Text <> "") Then SQL = " select sicker_id as รหสผปวย,sicker_Name as ชอ,sicker_Sex as เพศ,sicker_Blood as กรปเลอด,sicker_IDCard as เลขบตรประชาชน,sicker_Birthday as วนเกด,sicker_Address as ทอย,sicker_Tel as เบอรโทรศพท ,Sicker_DateTimePicker1 as วนทตรวจรกษา,Sicker_Weight as น าหนก,Sicker_High as สวนสง,sicker_lowpressure as SYS,sicker_highpressure as DIA,Sicker_Pulse as Pulse,Sicker_behavior as อาการเบองตน,sicker_Diseased as โรคประจ าตว,sicker_DrugAllergy as แพยา from Sicker WHERE sicker_IDCard LIKE '%" & txtfindsearch.Text & "%'" & " OR Sicker_name LIKE '%" & Me.txtfindsearch.Text & "%' ORDER BY sicker_IDCard" Else SQL = " select sicker_id as รหสผปวย,sicker_Name as ชอ,sicker_Sex as เพศ,sicker_Blood as กรปเลอด,sicker_IDCard as เลขบตรประชาชน,sicker_Birthday as วนเกด,sicker_Address as ทอย,sicker_Tel as เบอรโทรศพท ,Sicker_DateTimePicker1 as วนทตรวจรกษา,Sicker_Weight as น าหนก,Sicker_High as สวนสง,sicker_lowpressure as SYS,sicker_highpressure as DIA,Sicker_Pulse as Pulse,Sicker_behavior as อาการเบองตน,sicker_Diseased as โรคประจ าตว,sicker_DrugAllergy as แพยา from Sicker ORDER BY sicker_IDCard " End If Dim objDA As New SqlDataAdapter(SQL, conn) Dim objDS As New DataSet() objDA.Fill(objDS, "Sicker") DataGridView1.DataSource = objDS DataGridView1.DataMember = "Sicker" conn.Close() End Sub Private Sub Label18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label18.Click

End Sub Private Sub Label23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label23.Click End Sub End Class Source Code ชอ order1 Imports System.Data Imports System.Data.SqlClient 'Data Source=ASUS-PC;Initial Catalog=supod;User ID=doctor;Password=12345 Imports System.Globalization Imports System.Text Public Class order1 Dim dtfInfo As DateTimeFormatInfo Dim Today As Date Dim tr As SqlTransaction Dim sb As StringBuilder Dim com As SqlCommand Dim dr As SqlDataReader Dim sqlSave As String Private Sub order1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Maximized DbConn() Displaydata() Conn.Close()

Today = DateTime.Today dtfInfo = DateTimeFormatInfo.InvariantInfo With lsvProductList .Columns.Add("รหสยา", 70, HorizontalAlignment.Left) .Columns.Add("ชอยา", 180, HorizontalAlignment.Left) .Columns.Add("ราคา/หนวย", 75, HorizontalAlignment.Right) .Columns.Add("จ านวน", 50, HorizontalAlignment.Right) .Columns.Add("หนวย", 90, HorizontalAlignment.Left) .Columns.Add("รวมเปนเงน", 75, HorizontalAlignment.Right) .Columns.Add("", 0, HorizontalAlignment.Right) .Columns.Add("", 0, HorizontalAlignment.Right) .Columns.Add("", 0, HorizontalAlignment.Right) .View = View.Details .GridLines = True End With com = New SqlCommand() With com .Connection = Conn End With End Sub Private Sub DataGridView1_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick Sub Displaydata() Dim da As New SqlClient.SqlDataAdapter("select Order_Id as เลขทใบสงซอ,OrderDate as วนทสงซอ,Agent_ID as บรษท,NetTotal as ยอดสทธ from Orderr", Conn) Dim ds As New DataSet

da.Fill(ds, "Orderr") DataGridView1.DataSource = ds DataGridView1.DataMember = "Orderr" End Sub Sub Displaydata1() Dim da As New SqlClient.SqlDataAdapter("select drug_Id as รหสยา,drug_name as ชอยา,Order_Qty as จ านวนทส งซอ,Order_Price as ราคาตอหนวย,Order_Sum as ราคารวม from Orderr_detail", Conn) Dim ds As New DataSet da.Fill(ds, "Orderr_detail") DataGridView1.DataSource = ds DataGridView1.DataMember = "Orderr_detail" End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click If (lsvProductList.Items.Count = 0) Then MessageBox.Show("ไมมรายการยา !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information) Exit Sub End If If txtOrder_Id.Text = "" Then MsgBox("ยงไมสรางเลขทใบสงซอ", MsgBoxStyle.Exclamation, "แจงเตอน") Exit Sub End If DbConn() sb = New StringBuilder() If MessageBox.Show("คณตองการบนทกรายการสงซอยา ใชหรอไม?", "ค ายนยน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then tr = Conn.BeginTransaction()

Try With com .Connection = Conn .Parameters.Clear() .Transaction = tr End With sb.Remove(0, sb.Length) sb.Append("INSERT INTO Orderr(Order_ID,user_name,Agent_Id,OrderDate,NetTotal)") sb.Append(" VALUES(@OrderID,@UserName,@AgentID,@OrderDate,@NetTotal)") sqlSave = sb.ToString() With com .Parameters.Clear() .CommandText = sqlSave .Parameters.Add("@OrderID", SqlDbType.NVarChar).Value = txtOrder_Id.Text.Trim() .Parameters.Add("@UserName", SqlDbType.NVarChar).Value = txtUser_Name.Text.Trim() .Parameters.Add("@AgentID", SqlDbType.NVarChar).Value = txtAgent_Name.Text.Trim() .Parameters.Add("@OrderDate", SqlDbType.DateTime).Value = txtOrder_Date.Value '.ToString("d", dtfInfo) .Parameters.Add("@NetTotal", SqlDbType.Float).Value = CDbl(lblTotal.Text) .ExecuteNonQuery() End With Dim i As Integer Dim CDrugID As String Dim CMode As String = ""

Dim Stock As Integer = 0 Dim NewQty As Integer = 0 For i = 0 To lsvProductList.Items.Count - 1 CDrugID = lsvProductList.Items(i).SubItems(0).Text sb.Remove(0, sb.Length()) sb.Append("INSERT INTO orderr_detail (Order_Id,Drug_ID,Drug_Name,Order_Qty,") sb.Append(" Order_Price,UnitName,Total)") sb.Append(" VALUES (@OrderID,@DrugID,@DrugName,@Qty,") sb.Append(" @Cost,@UnitName,@Total)") sqlSave = sb.ToString() With com .Parameters.Clear() .CommandText = sqlSave .Parameters.Add("@OrderID", SqlDbType.NVarChar).Value = txtOrder_Id.Text.Trim() .Parameters.Add("@DrugID", SqlDbType.NVarChar).Value = CDrugID .Parameters.Add("@DrugName", SqlDbType.NVarChar).Value = lsvProductList.Items(i).SubItems(1).Text .Parameters.Add("@Cost", SqlDbType.Float).Value = CDbl(lsvProductList.Items(i).SubItems(2).Text) .Parameters.Add("@Qty", SqlDbType.Int).Value = CInt(lsvProductList.Items(i).SubItems(3).Text) .Parameters.Add("@UnitName", SqlDbType.NVarChar).Value = lsvProductList.Items(i).SubItems(4).Text .Parameters.Add("@Total", SqlDbType.Float).Value = CDbl(lsvProductList.Items(i).SubItems(5).Text) .ExecuteNonQuery()

End With sqlSave = sb.ToString() Next tr.Commit() lblTotal.Text = "0" ClearProductDetails() lsvProductList.Items.Clear() Displaydata() MessageBox.Show("บนทกรายการสงซอยา เรยบรอยแลว !!!", "ผลการท างาน", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As Exception tr.Rollback() MessageBox.Show("ไมสามารถบนทกรายการสงซอยาได เนองจาก " & ex.Message, "ขอผดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning) End Try End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Close() End Sub Sub ClearData() txtOrder_Id.Text = "" txtUser_Name.Text = "" txtAgent_Name.Text = "" txtDrug_Name.Text = "" txtDrug_ID.Text = "" txtQty.Text = ""

txtOrder_Date.Text = "" txtUnitName.Text = "" txtPrice.Text = "" ' txtTotal.Text = "0.00" End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If Dim y As New SqlCommand("update Orderr set User_name ='" & _ txtUser_Name.Text & "', Order_Id = '" & _ txtOrder_Id.Text & "',Agent_Id= '" & _ txtAgent_Name.Text & "',Drug_Id = '" & _ txtDrug_Name.Text & "',Drug_name = '" & _ txtDrug_ID.Text & "',Order_Qty = '" & _ txtQty.Text & "',Order_Date = '" & _ txtOrder_Date.Text & "',Order_Price = '" & _ txtUnitName.Text & "', Order_Sum = '" & _ txtPrice.Text & "' where order_total = '" & lblTotal.Text & "'", Conn) Try y.ExecuteNonQuery() 'MsgBox("แกไขขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try

ClearData() Conn.Close() End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Conn.Open() Dim y As New SqlCommand("delete from Orderr where drug_name ='" & txtAgent_Name.Text & "'", Conn) 'Dim Result As DialogResult 'Result = MessageBox.Show("คณตองการลบขอมลใชหรอไม", "คณตองการลบขอมลใชหรอไม !", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Try y.ExecuteNonQuery() ' MsgBox("ลบขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try Conn.Close() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If txtOrder_Id.Text = S() txtOrder_Id.Enabled = False Conn.Close()

End Sub Function S() Dim y As New SqlCommand("select max(Order_Id) from Orderr ", Conn) Try Dim Sic As String = y.ExecuteScalar() Sic = Mid(Sic, 1, 2) & (Mid(Sic, 3, 5) + 1).ToString("00000") Return Sic Catch Return "OR00001" End Try End Function Private Sub txtagent_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtagent.TextChanged If Conn.State <> ConnectionState.Open Then Conn.Open() End If Dim SQL As String 'Agent_Id as รหสตวแทนจ าหนาย, If (txtagent.Text <> "") Then 'การทางานเมอTextbox ไมเปนคาวาง SQL = "select Agent_Name as ชอตวแทนจ าหนาย,Agent_Tel as โทรศพท,Agent_Fax as เบอรแฟกซ from Agent WHERE Agent_id LIKE '%" & txtagent.Text & "%'" & " OR Agent_name LIKE '%" & Me.txtagent.Text & "%' ORDER BY Agent_id" Else SQL = "select Agent_Name as ชอตวแทนจ าหนาย,Agent_Tel as โทรศพท,Agent_Fax as เบอรแฟกซ from Agent ORDER BY Agent_id " End If Dim objDA As New SqlDataAdapter(SQL, Conn) Dim objDS As New DataSet()

objDA.Fill(objDS, "Agent") DataGridView2.DataSource = objDS DataGridView2.DataMember = "Agent" Conn.Close() End Sub Private Sub txtdrugs_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtdrugs.TextChanged If Conn.State <> ConnectionState.Open Then Conn.Open() End If Dim SQL As String If (txtdrugs.Text <> "") Then 'การทางานเมอTextbox ไมเปนคาวาง SQL = "select Drug_Id as รหสยา,Drug_Name as ชอยา,Unit as จ านวน,drug_t as หนวยนบ,Drug_Price as ราคาตอหนวย,Limit as จดสงซอ,Drug_Detail as รายละเอยดยา FROM Drug WHERE Drug_name LIKE '%" & txtdrugs.Text & "%'" & " OR Drug_Id LIKE '%" & Me.txtdrugs.Text & "%' ORDER BY Drug_name" Else SQL = "select Drug_Id as รหสยา,Drug_Name as ชอยา,Unit as จ านวน,drug_t as หนวยนบ,Drug_Price as ราคาตอหนวย,Limit as จดสงซอ,Drug_Detail as รายละเอยดยา FROM Drug ORDER BY Drug_name " End If Dim objDA As New SqlDataAdapter(SQL, Conn) Dim objDS As New DataSet() objDA.Fill(objDS, "Drug") DataGridView3.DataSource = objDS DataGridView3.DataMember = "Drug" Conn.Close() End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim q As Decimal Dim r As Decimal q = txtQty.Text r = txtUnitName.Text Dim Total As Decimal Total = q * r txtPrice.Text = Total End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If If OrderID = "" Then MessageBox.Show("ไมมขอมลการสงซอ ", "ผดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error) Else r_order.Show() End If End Sub Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If

If (txtDrug_ID.Text.Trim() = "") OrElse (txtDrug_Name.Text.Trim() = "") Then Exit Sub End If If CDbl(txtPrice.Text) = 0 Then Exit Sub End If If CInt(txtQty.Text) = 0 Then Exit Sub End If Dim i As Integer = 0 Dim lvi As ListViewItem Dim DrugID As String = "" For i = 0 To lsvProductList.Items.Count - 1 DrugID = lsvProductList.Items(i).SubItems(0).Text If txtDrug_Name.Text.Trim() = DrugID Then MessageBox.Show("คณเลอกรายการยา ซ ากน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information) ClearProductDetails() Exit Sub End If Next Dim anyData() As String Dim LastCost As Double = 0.0 Dim Total As Double = 0.0 LastCost = CSng(txtPrice.Text) Total = CInt(txtQty.Text) * LastCost

anyData = New String() { _ txtDrug_ID.Text.Trim(), _ txtDrug_Name.Text, _ LastCost.ToString("#,##0.00"), _ txtQty.Text, _ txtUnitName.Text, _ Total.ToString("#,##0.00") _ } lvi = New ListViewItem(anyData) lsvProductList.Items.Add(lvi) ClearProductDetails() CalculateNet() DataGridView2.Focus() End Sub Private Sub ClearProductDetails() txtDrug_ID.Text = "" txtDrug_Name.Text = "" txtPrice.Text = "0" txtQty.Text = "0" lblTotal.Text = "0.00" txtUnitName.Text = "" End Sub Private Sub CalculateNet() Dim i As Integer = 0 Dim Net As Double = 0.0 For i = 0 To lsvProductList.Items.Count - 1

Net = Net + CDbl(lsvProductList.Items(i).SubItems(5).Text) Next lblTotal.Text = CDbl(Net).ToString("#,##0.00") End Sub Private Sub DataGridView2_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellContentClick End Sub Private Sub DataGridView3_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellContentClick If e.RowIndex = -1 Then Exit Sub With DataGridView3() txtDrug_ID.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtDrug_Name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtUnitName.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() End With ' End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Conn.Open() Dim y As New SqlCommand("delete from Orderr_detail where Drug_name ='" & txtDrug_ID.Text & "'", Conn) 'Dim Result As DialogResult

'Result = MessageBox.Show("คณตองการลบขอมลใชหรอไม", "คณตองการลบขอมลใชหรอไม !", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Try y.ExecuteNonQuery() ' MsgBox("ลบขอมลส าเรจ") Displaydata() ClearData() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try Conn.Close() End Sub Private Sub txtTotal_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lblTotal.KeyDown If e.KeyCode = Keys.Enter Then Dim q As Decimal Dim r As Decimal q = txtUnitName.Text r = txtQty.Text Dim Total As Decimal Total = q * r txtPrice.Text = Total End If End Sub 'txtOrder_Nettotal_TextChanged 'Changed Private Sub txtPrice_Text_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPrice.KeyDown If e.KeyCode = Keys.Enter Then

Dim q As Decimal Dim r As Decimal q = txtUnitName.Text r = txtQty.Text Dim Total As Decimal Total = q * r txtPrice.Text = Total End If End Sub Private Sub DataGridView2_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView2.CellMouseUp If e.RowIndex = -1 Then Exit Sub With DataGridView2() txtAgent_Name.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() 'txtOrder_Id.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() End With ' End Sub Private Sub DataGridView3_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView3.CellMouseUp If e.RowIndex = -1 Then Exit Sub With DataGridView3() txtDrug_ID.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtDrug_Name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString()

txtUnitName.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString() End With ' End Sub Private Sub lsvProductList_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lsvProductList.MouseDoubleClick Dim i As Integer = 0 For i = 0 To lsvProductList.SelectedItems.Count - 1 Dim lvi As ListViewItem lvi = lsvProductList.SelectedItems(i) lsvProductList.Items.Remove(lvi) Next If (lsvProductList.Items.Count = 0) Then Button7.Enabled = True Else Button7.Enabled = True End If CalculateNet() End Sub Private Sub DataGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting If DataGridView1.Columns(e.ColumnIndex).Name = "ยอดสทธ" Then e.CellStyle.Format = "#,##0.00" e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight End If

If DataGridView1.Columns(e.ColumnIndex).Name = "วนทสงซอ" Then e.CellStyle.Format = "d MMM yyyy" End If End Sub Private Sub DataGridView1_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseUp OrderID = DataGridView1.Rows.Item(e.RowIndex).Cells(0).Value.ToString() End Sub Private Sub txtPrice_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPrice.TextChanged End Sub End Class

Source Code ชอ orderdispes Imports System.Data Imports System.Data.SqlClient 'Data Source=ASUS-PC;Initial Catalog=supod;User ID=doctor;Password=12345 Imports System.Globalization Imports System.Text Public Class orderdispes Dim dtfInfo As DateTimeFormatInfo Dim Today As Date Dim tr As SqlTransaction Dim sb As StringBuilder Dim com As SqlCommand

Dim dr As SqlDataReader Dim sqlSave As String Dim ID As Integer Private Sub orderdispes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Maximized DbConn() Today = DateTime.Today dtfInfo = DateTimeFormatInfo.InvariantInfo With lsvProductList .Columns.Add("รหสยา", 70, HorizontalAlignment.Left) .Columns.Add("ชอยา", 150, HorizontalAlignment.Left) .Columns.Add("ราคา/หนวย", 55, HorizontalAlignment.Right) .Columns.Add("จ านวน", 50, HorizontalAlignment.Right) .Columns.Add("หนวย", 90, HorizontalAlignment.Left) .Columns.Add("รวมเปนเงน", 75, HorizontalAlignment.Right) .Columns.Add("", 0, HorizontalAlignment.Right) .Columns.Add("", 0, HorizontalAlignment.Right) .Columns.Add("", 0, HorizontalAlignment.Right) .View = View.Details .GridLines = True End With com = New SqlCommand() With com .Connection = Conn End With txtCheck_Qty.Text = "0"

End Sub Private Sub Button8_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If txtDispenDrug_Id.Text = OCc() txtDispenDrug_Id.Enabled = False Conn.Close() TextBox5.Text = CheckID txtSicker.Text = SickerID txtsicker_name.Text = SickerName End Sub Function OCc() Dim y As New SqlCommand("select max(OrderDispenseorder_Id) from OrderDispenseorder ", Conn) Try Dim Sic As String = y.ExecuteScalar() Sic = Mid(Sic, 1, 1) & (Mid(Sic, 7, 7) + 1).ToString("0000000") Return Sic Catch Return "00000001" End Try End Function Sub ClearData1() ' txtDispenseorder_Id.Text = "" ' txtSicker.Text = ""

'TextBox5.Text = "" ' txtDrug_Id.Text = "" txtDrud_name.Text = "" txtCheck_Qty.Text = "" txtDrug_ID.Text = "" txtdrug_Price.Text = "" lblTotal.Text = "" End Sub ' Private Sub Button6_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim y As New SqlCommand("delete from orderdispenseorder__detail where Id=" & ID & "", Conn) Dim h As New SqlCommand("update OrderDispenseorder set nettotal =nettotal-" & _ Convert.ToDouble(lblStock.Text) & " WHERE OrderDispenseorder_Id='" & txtDispenDrug_Id.Text.Trim() & "'", Conn) Try y.ExecuteNonQuery() h.ExecuteNonQuery() MsgBox("ลบขอมลส าเรจ", MsgBoxStyle.Information, "แจงผลการบนทก") Displaydata1() ClearData1() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try Conn.Close() End Sub Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

End Sub Sub Displaydata1() Dim da As New SqlClient.SqlDataAdapter("select OrderDispenseorder_Id as รหสสงจายยา,drug_id as รหสยา,drug_name as ชอยา,drug_price as ราคา,qty as จ านวน,drug_t as หนวย,total as จ านวนเงน,ID from orderdispenseorder__detail where OrderDispenseorder_Id='" & txtDispenDrug_Id.Text.Trim() & "'", Conn) Dim ds As New DataSet da.Fill(ds, "OrderDispenseorder") DataGridView1.DataSource = ds DataGridView1.DataMember = "OrderDispenseorder" End Sub Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If (lsvProductList.Items.Count = 0) Then MessageBox.Show("ไมมรายการยา !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information) Exit Sub End If DbConn() sb = New StringBuilder() If MessageBox.Show("คณตองการบนทกรายการจายยา ใชหรอไม?", "ค ายนยน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then tr = Conn.BeginTransaction() Try With com

.Connection = Conn .Parameters.Clear() .Transaction = tr End With sb.Remove(0, sb.Length) sb.Append("INSERT INTO OrderDispenseorder(OrderDispenseorder_Id,Check_ID,Sicker_ID,Sicker_Name,") sb.Append("OrderDate,NetTotal)") sb.Append(" VALUES(@OrderID,@CheckID,@SickerID,@SickerName,@OrderDate,@NetTotal)") sqlSave = sb.ToString() With com .Parameters.Clear() .CommandText = sqlSave .Parameters.Add("@OrderID", SqlDbType.NVarChar).Value = txtDispenDrug_Id.Text.Trim() .Parameters.Add("@CheckID", SqlDbType.NVarChar).Value = TextBox5.Text.Trim() .Parameters.Add("@SickerID", SqlDbType.NVarChar).Value = txtSicker.Text.Trim() .Parameters.Add("@SickerName", SqlDbType.NVarChar).Value = txtsicker_name.Text.Trim() .Parameters.Add("@OrderDate", SqlDbType.DateTime).Value = Today .Parameters.Add("@NetTotal", SqlDbType.Float).Value = CDbl(lblTotal.Text) .ExecuteNonQuery() End With Dim i As Integer Dim CDrugID As String Dim CMode As String = ""

Dim Stock As Integer = 0 Dim NewQty As Integer = 0 For i = 0 To lsvProductList.Items.Count - 1 CDrugID = lsvProductList.Items(i).SubItems(0).Text sb.Remove(0, sb.Length()) sb.Append("INSERT INTO orderdispenseorder__detail (OrderDispenseorder_Id,Drug_ID,Drug_Name,Qty,") sb.Append(" Drug_Price,Drug_t,Total)") sb.Append(" VALUES (@OrderID,@DrugID,@DrugName,@Qty,") sb.Append(" @Cost,@DrugT,@Total)") sqlSave = sb.ToString() With com .Parameters.Clear() .CommandText = sqlSave .Parameters.Add("@OrderID", SqlDbType.NVarChar).Value = txtDispenDrug_Id.Text.Trim() .Parameters.Add("@DrugID", SqlDbType.NVarChar).Value = CDrugID .Parameters.Add("@DrugName", SqlDbType.NVarChar).Value = lsvProductList.Items(i).SubItems(1).Text .Parameters.Add("@Cost", SqlDbType.Float).Value = CDbl(lsvProductList.Items(i).SubItems(2).Text) .Parameters.Add("@Qty", SqlDbType.Int).Value = CInt(lsvProductList.Items(i).SubItems(3).Text) .Parameters.Add("@DrugT", SqlDbType.NVarChar).Value = lsvProductList.Items(i).SubItems(4).Text .Parameters.Add("@Total", SqlDbType.Float).Value = CDbl(lsvProductList.Items(i).SubItems(5).Text) .ExecuteNonQuery()

End With sb.Remove(0, sb.Length()) sb.Append("SELECT Drug_ID,Unit") sb.Append(" FROM Drug") sb.Append(" WHERE (Drug_ID=@DrugID)") sqlSave = sb.ToString() With com .Parameters.Clear() .CommandText = sqlSave .Parameters.Add("@DrugID", SqlDbType.NVarChar).Value = CDrugID dr = .ExecuteReader() If dr.HasRows Then dr.Read() Stock = CInt(dr(1)) sb.Remove(0, sb.Length()) sb.Append("UPDATE Drug") sb.Append(" SET Unit=@Qty") sb.Append(" WHERE (Drug_ID=@DrugID)") End If End With dr.Close() sqlSave = sb.ToString() With com .Parameters.Clear() .CommandText = sqlSave .Parameters.Add("@DrugID", SqlDbType.NVarChar).Value = CDrugID NewQty = CInt(lsvProductList.Items(i).SubItems(3).Text)

.Parameters.Add("@Qty", SqlDbType.Int).Value = Stock - NewQty .ExecuteNonQuery() End With Next tr.Commit() lblTotal.Text = "0" ClearProductDetails() lsvProductList.Items.Clear() MessageBox.Show("บนทกรายการจายยา เรยบรอยแลว !!!", "ผลการท างาน", MessageBoxButtons.OK, MessageBoxIcon.Information) txyDrug.Focus() Displaydata1() Catch ex As Exception tr.Rollback() MessageBox.Show("ไมสามารถบนทกรายการจายยาได เนองจาก " & ex.Message, "ขอผดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning) End Try End If End Sub Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim NewNetTotal As Double = 0 If Conn.State <> ConnectionState.Open Then Conn.Open()

End If NewNetTotal = Convert.ToDouble(txtdrug_Price.Text) * Convert.ToInt32(txtCheck_Qty.Text) Dim y As New SqlCommand("update orderdispenseorder__detail set qty = " & _ Convert.ToInt32(txtCheck_Qty.Text) & ",Total = " & _ (Convert.ToDouble(txtdrug_Price.Text) * Convert.ToInt32(txtCheck_Qty.Text)) & " WHERE id=" & ID & "", Conn) Dim h1 As New SqlCommand("update OrderDispenseorder set nettotal =nettotal-" & _ Convert.ToDouble(lblStock.Text) & " WHERE OrderDispenseorder_Id='" & txtDispenDrug_Id.Text.Trim() & "'", Conn) Dim h2 As New SqlCommand("update OrderDispenseorder set nettotal =nettotal+" & _ NewNetTotal & " WHERE OrderDispenseorder_Id='" & txtDispenDrug_Id.Text.Trim() & "'", Conn) Try y.ExecuteNonQuery() h1.ExecuteNonQuery() h2.ExecuteNonQuery() MsgBox("แกไขขอมลส าเรจ", MsgBoxStyle.Information, "แจงผลการแกไข") Displaydata1() ClearData1() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try Conn.Close() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

frm_appoint.MdiParent = Me.MdiParent frm_appoint.Show() End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Me.Close() frm_Check.Close() End Sub Private Sub txyDrug_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txyDrug.TextChanged If Conn.State <> ConnectionState.Open Then Conn.Open() End If Dim SQL As String If (txyDrug.Text <> "") Then 'การทางานเมอTextbox ไมเปนคาวาง SQL = "select Drug_Id as รหสยา,Drug_Name as ชอยา,Unit as จ านวน,drug_t as หนวยนบ,Drug_Price as ราคาตอหนวย,Limit as จดสงซอ,Drug_Detail as รายละเอยดยา FROM Drug WHERE Drug_name LIKE '%" & txyDrug.Text & "%'" & " OR Drug_Id LIKE '%" & Me.txyDrug.Text & "%' ORDER BY Drug_name" Else SQL = "select Drug_Id as รหสยา,Drug_Name as ชอยา,Unit as จ านวน,drug_t as หนวยนบ,Drug_Price as ราคาตอหนวย,Limit as จดสงซอ,Drug_Detail as รายละเอยดยา FROM Drug ORDER BY Drug_name " End If Dim objDA As New SqlDataAdapter(SQL, Conn) Dim objDS As New DataSet()

objDA.Fill(objDS, "Drug") DataGridView2.DataSource = objDS DataGridView2.DataMember = "Drug" Conn.Close() End Sub Sub Displaydata2() 'select Drug_name as ชอยา,Limit_order as จ านวนทจาย,unit as จ านวนยาในสตอก,Drug_Price as ราคาตอหนวย,sum_money as ราคารวม from OrderDispenseorder ", conn) Dim da As New SqlClient.SqlDataAdapter("select Drug_name as ชอยา,Limit_order as จ านวนทจาย,unit as จ านวนยาในสตอก,Drug_Price as ราคาตอหนวย,sum_money as ราคารวม from OrderDispenseorder__detail ", Conn) Dim ds As New DataSet da.Fill(ds, "OrderDispenseorder__detail") DataGridView3.DataSource = ds DataGridView3.DataMember = "OrderDispenseorder__detail" End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click If (txtDrug_ID.Text.Trim() = "") OrElse (txtDrud_name.Text.Trim() = "") Then Exit Sub End If If CDbl(txtdrug_Price.Text) = 0 Then Exit Sub End If If CInt(txtCheck_Qty.Text) = 0 Then Exit Sub End If

If CInt(lblStock.Text) < CInt(txtCheck_Qty.Text) Then MessageBox.Show("จ านวนจายยามากกวา ยาในสตอก !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Stop) txtCheck_Qty.Text = "0" txtCheck_Qty.Focus() Exit Sub End If Dim i As Integer = 0 Dim lvi As ListViewItem Dim DrugID As String = "" For i = 0 To lsvProductList.Items.Count - 1 DrugID = lsvProductList.Items(i).SubItems(0).Text If txtDrug_ID.Text.Trim() = DrugID Then MessageBox.Show("คณเลอกรายการยา ซ ากน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information) ClearProductDetails() Exit Sub End If Next Dim anyData() As String Dim LastCost As Double = 0.0 Dim Total As Double = 0.0 LastCost = CSng(txtdrug_Price.Text) Total = CInt(txtCheck_Qty.Text) * LastCost anyData = New String() { _ txtDrug_ID.Text.Trim(), _ txtDrud_name.Text, _ LastCost.ToString("#,##0.00"), _

txtCheck_Qty.Text, _ txtUnitName.Text, _ Total.ToString("#,##0.00") _ } lvi = New ListViewItem(anyData) lsvProductList.Items.Add(lvi) ClearProductDetails() CalculateNet() DataGridView2.Focus() End Sub Private Sub ClearProductDetails() txtDrug_ID.Text = "" txtDrud_name.Text = "" txtdrug_Price.Text = "0" txtCheck_Qty.Text = "0" lblTotal.Text = "0.00" txtUnitName.Text = "" End Sub Private Sub CalculateNet() Dim i As Integer = 0 Dim Net As Double = 0.0 For i = 0 To lsvProductList.Items.Count - 1 Net = Net + CDbl(lsvProductList.Items(i).SubItems(5).Text) Next lblTotal.Text = CDbl(Net).ToString("#,##0.00") End Sub

'------------------------โคดเพม Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Conn.State <> ConnectionState.Open Then Conn.Open() End If Dim tmpNetTotal As Double = 0 Dim i As Integer = 0 For i = 0 To DataGridView1.Rows.Count - 1 tmpNetTotal += CDbl(DataGridView1.Rows(i).Cells(8).Value) Next lblTotal.Text = tmpNetTotal.ToString("#,###.##") '####.## Dim y As New SqlCommand("update OrderDispenseorder set sum_money = '" & lblTotal.Text & "'", Conn) Try y.ExecuteNonQuery() MsgBox("เพมขอมลส าเรจ") Catch MsgBox("เกดความผดพลาด เนองจาก " & Err.Description) End Try Conn.Close() End Sub '--------ลบรายการยา 'Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click 'conn.Open() 'Dim y As New SqlCommand("delete from orderdispenseorder__detail where Drug_name='" & txtDrud_name.Text & "'", conn) 'Try ' y.ExecuteNonQuery()

'Displaydata2() 'ClearData1() ' Catch ' MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) ' End Try ' conn.Close() 'End Sub Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged TextBox5.Text = frm_Check.txtCheck_Id.Text End Sub Private Sub txtSicker_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSicker.TextChanged txtSicker.Text = frm_Check.txtSicker_Id.Text End Sub Private Sub DataGridView2_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellContentClick If e.RowIndex = -1 Then Exit Sub With DataGridView2() txtDrud_name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtDrug_ID.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtUnitName.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() lblStock.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() txtdrug_Price.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() End With End Sub

' Private Sub lblTotal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTotal.TextChanged '(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown '--------------- Private Sub lblTotal_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lblTotal.KeyDown If e.KeyCode = Keys.Enter Then Dim q As Decimal Dim r As Decimal q = txtCheck_Qty.Text r = txtdrug_Price.Text Dim Total As Decimal Total = q * r lblTotal.Text = Total End If End Sub Private Sub txtsicker_name_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsicker_name.TextChanged txtsicker_name.Text = frm_Check.txtsicker_name.Text End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click Conn.Open() Dim y As New SqlCommand("delete from OrderDispenseorder__detail where Drug_Name ='" & txtDrud_name.Text & "'", Conn) 'Dim Result As DialogResult

' Result = MessageBox.Show("คณตองการลบขอมลใชหรอไม", "คณตองการลบขอมลใชหรอไม !", MessageBoxButtons.YesNo, MessageBoxIcon.Question) Try y.ExecuteNonQuery() ' MsgBox("ลบขอมลส าเรจ") Displaydata2() ClearData1() Catch MsgBox(" เกดความผดพลาด เนองจาก " & Err.Description) End Try Conn.Close() End Sub Private Sub DataGridView3_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellContentClick If e.RowIndex = -1 Then Exit Sub With DataGridView3() txtDrud_name.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtCheck_Qty.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtDrug_ID.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() txtdrug_Price.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() lblTotal.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() End With End Sub Private Sub txtCheck_Qty_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCheck_Qty.KeyPress

If e.KeyChar < "0" Or e.KeyChar > "9" Then e.Handled = True End If End Sub Private Sub lsvProductList_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lsvProductList.DoubleClick Dim i As Integer = 0 For i = 0 To lsvProductList.SelectedItems.Count - 1 Dim lvi As ListViewItem lvi = lsvProductList.SelectedItems(i) lsvProductList.Items.Remove(lvi) Next If (lsvProductList.Items.Count = 0) Then Button2.Enabled = True Else Button2.Enabled = True End If CalculateNet() End Sub Private Sub lsvProductList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lsvProductList.SelectedIndexChanged End Sub

Private Sub DataGridView2_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView2.CellMouseUp If e.RowIndex = -1 Then Exit Sub With DataGridView2() txtDrud_name.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtDrug_ID.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString() txtUnitName.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() lblStock.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() txtdrug_Price.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() End With End Sub Private Sub DataGridView1_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseUp If e.RowIndex = -1 Then Exit Sub With DataGridView1() txtDrug_ID.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString() txtDrud_name.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString() txtdrug_Price.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() txtCheck_Qty.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString() txtUnitName.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString() lblStock.Text = .Rows.Item(e.RowIndex).Cells(6).Value.ToString() ID = Convert.ToInt32(.Rows.Item(e.RowIndex).Cells(7).Value) 'txtDrug_Id.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString() 'txtorder_Price.Text = .Rows.Item(e.RowIndex).Cells(6).Value.ToString()

' txtOrder_TotalPrice.Text = .Rows.Item(e.RowIndex).Cells(7).Value.ToString() ' txtOrder_TotalPricee.Text = .Rows.Item(e.RowIndex).Cells(8).Value.ToString() ,Unit as จ านวนยาในสตอก End With End Sub End Class