Imports System.Data.SqlClient
Public Class frm_return
Private Sub frm_return_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txt_return.Text = frm_main.lbl_admin_name.Text
refresh_data_return()
End Sub
Private Sub get_auto_num_char()
sql = "select max(return_id) from tb_return"
Try
Dim numchar As String = "RET-" & (cmd_excuteScalar() + 1).ToString.PadLeft(6, "0")
txt_return_id.Text = numchar
Catch ex As Exception
txt_return_id.Text = "RET-000001"
End Try
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lbl_borrow_day.Text = DateTime.Today
End Sub
Private Sub txt_return_borrow_id_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt_return_borrow_id.KeyDown
If e.KeyData = Keys.Enter Then
sql = "select borrow_device_id,borrow_device_name,borrow_user_id,borrow_user_name,borrow_admin,borrow_date_checkout,borrow_date_checkin from tb_borrow where borrow_full_id_2 = '" & txt_return_borrow_id.Text & "'"
Dim dts As DataTable = cmd_excuteToDataTable()
If dts.Rows.Count <= 0 Then
error_message("ไม่พบรหัสอุปกรณ์")
Else
txt_return_device_id.Text = dts.Rows(0)("borrow_device_id")
txt_return_device_name.Text = dts.Rows(0)("borrow_device_name")
txt_return_user_id.Text = dts.Rows(0)("borrow_user_id")
txt_return_user_name.Text = dts.Rows(0)("borrow_user_name")
txt_return_admin_name.Text = dts.Rows(0)("borrow_admin")
txt_dayoff.Text = dts.Rows(0)("borrow_date_checkin")
txt_return.Select()
End If
End If
End Sub
Private Sub refresh_data_return()
sql = "select return_full_id,return_borrow_full_id,return_device_id,return_device_name,return_user_id,return_user_name,return_admin_recieve,return_dayoff,return_day,return_status from tb_return"
dtg_return.DataSource = cmd_excuteToDataTable()
get_auto_num_char()
chang_all_column()
End Sub
Private Sub chang_all_column()
Dim header() As String = {"รหัสการคืน", "รหัสการยืม", "รหัสอุปกรณ์", "ชื่ออุปกรณ์", "รหัสพนักงาน", "ชื่อพนักงาน", "ผู้รับคืนอุปกรณ์", "กำหนดวันคืน", "วันที่คืน", "สถานะ"}
chang_name_datagrid(dtg_return, header)
End Sub
Private Sub update_data_device()
sql = "update tb_device set device_amount = device_amount + 1 where device_id = '" & txt_return_device_id.Text & "'"
If cmd_excuteNonquery() = 0 Then
error_message("ทำรายการไม่สำเร็จ")
Else
ok_message("ทำรายการสำเร็จ")
End If
End Sub
Private Sub bt_return_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_return.Click
If confirm("คุณต้องการคืนอุปกรณ์") = vbNo Then Return
sql = String.Format("insert into tb_return values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')",
txt_return_id.Text,
txt_return_borrow_id.Text,
txt_return_device_id.Text,
txt_return_device_name.Text,
txt_return_user_id.Text,
txt_return_user_name.Text,
txt_return.Text,
txt_dayoff.Text,
lbl_borrow_day.Text,
"คืน", "1")
If cmd_excuteNonquery() = 0 Then
error_message("ทำรายการไม่สำเร็จ")
Else
update_data_device()
refresh_data_return()
End If
End Sub
End Class
Tag : ASP, Ms SQL Server 2008, Win (Windows App), Windows