Public Class frm_order
Public Sub refresh_orders()
sql = "select order_bill, order_date, order_salesid, order_saleslevel, order_salesname, order_locations, order_list, order_unit, order_price, order_total, order_gift, order_giftunit, order_delivery, order_total2 from orders"
datagrid_order.DataSource = cmd_excuteDataTable()
change_datagrid_column()
End Sub
Public Sub change_datagrid_column()
Dim column_text() As String = {"เลขที่บิล", "วันที่สั่ง", "รหัสตัวแทน", "ระดับตัวแทน", "ชื่อ - นามสกุล", "เขตการขาย", "รายการ", "จำนวน", "ราคา", "เป็นเงิน", "รายการแถม", "จำนวน", "ค่าจัดส่ง", "รวมทั้งสิ้น"}
For i As Integer = 0 To datagrid_order.ColumnCount - 1
datagrid_order.Columns(i).HeaderText = column_text(i)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
txt_add_salesid.Enabled = True
txt_add_saleslevel.Enabled = True
txt_add_salesname.Enabled = True
txt_add_locations.Enabled = True
txt_add_list.Enabled = True
txt_add_unit.Enabled = True
txt_add_price.Enabled = True
txt_add_total.Enabled = True
txt_add_gift.Enabled = True
txt_add_giftunit.Enabled = True
txt_add_delivery.Enabled = True
txt_add_total2.Enabled = True
txt_add_salesid.Select()
End Sub
Private Sub frm_order_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lbl_date.Text = TimeOfDay
refresh_orders()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lbl_date.Text = Date.Now
End Sub
'***********************************
Public Sub clear_form()
txt_add_salesid.Text = ""
txt_add_saleslevel.Text = ""
txt_add_salesname.Text = ""
txt_add_locations.Text = ""
txt_add_list.Text = ""
txt_add_unit.Text = ""
txt_add_price.Text = ""
txt_add_total.Text = ""
txt_add_gift.Text = ""
txt_add_giftunit.Text = ""
txt_add_delivery.Text = ""
txt_add_total2.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If txt_add_salesid.Text = "" Or txt_add_saleslevel.Text = "" Or txt_add_salesname.Text = "" Or txt_add_locations.Text = "" Or txt_add_list.Text = "" Or txt_add_unit.Text = "" Or txt_add_price.Text = "" Or txt_add_total.Text = "" Or txt_add_gift.Text = "" Or txt_add_giftunit.Text = "" Or txt_add_delivery.Text = "" Or txt_add_total2.Text = "" Then
msg_error("กรุณากรอกข้อมูลให้ครบ")
Return
If confirm("คุณยืนยันที่จะเพิ่มใบสั่งซื้อใช่หรือไม่ ?") = vbNo Then Return
End If
sql = "insert into orders (order_bill, order_salesid, order_saleslevel, order_salesname, order_locations, order_list, order_unit, order_price, order_total, order_gift, order_giftunit, order_delivery, order_total2 ) values(@bill,@id,@level,@name,@locations,@list,@unit,@price,@total,@gift,@giftunit,@delivery,@total2)"
cmd = New SqlClient.SqlCommand(sql, cn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("bill", txt_add_salesid.Text)
cmd.Parameters.AddWithValue("date", datetime1.Value)
cmd.Parameters.AddWithValue("id", txt_add_salesid.Text)
cmd.Parameters.AddWithValue("level", txt_add_saleslevel.Text)
cmd.Parameters.AddWithValue("name", txt_add_salesname.Text)
cmd.Parameters.AddWithValue("locations", txt_add_locations.Text)
cmd.Parameters.AddWithValue("list", txt_add_list.Text)
cmd.Parameters.AddWithValue("unit", txt_add_unit.Text)
cmd.Parameters.AddWithValue("price", txt_add_price.Text)
cmd.Parameters.AddWithValue("total", txt_add_total.Text)
cmd.Parameters.AddWithValue("gift", txt_add_gift.Text)
cmd.Parameters.AddWithValue("giftunit", txt_add_giftunit.Text)
cmd.Parameters.AddWithValue("delivery", txt_add_delivery.Text)
cmd.Parameters.AddWithValue("total2", txt_add_total2.Text)
If cmd.ExecuteNonQuery = 0 Then
msg_error("เพิ่มไม่สำเร็จ")
Else
msg_ok("เพิ่มสำเร็จ")
refresh_orders() 'รีเฟรชdatagrid
clear_form() 'ล้างข้อมูลการเพิ่มสินค้า
End If
End Sub
'***********************************
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If confirm("ต้องการยกเลิกใช่หรือไม่ ?") = vbNo Then
Else
txt_add_salesid.Text = ""
txt_add_saleslevel.Text = ""
txt_add_salesname.Text = ""
txt_add_locations.Text = ""
txt_add_list.Text = ""
txt_add_unit.Text = ""
txt_add_price.Text = ""
txt_add_total.Text = ""
txt_add_gift.Text = ""
txt_add_giftunit.Text = ""
txt_add_delivery.Text = ""
txt_add_total2.Text = ""
End If
End Sub
End Class
Tag : .NET, MySQL, Ms SQL Server 2008, VBScript, VB.NET, VS 2010 (.NET 4.x)