Imports System
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Partial Class P20110307
Inherits System.Web.UI.Page
Dim myds As New DataSet()
Dim lbl_item, lbl_ccn, lbl_loc, lbl_qty As Label
Dim qry, transdate As String
Public Sub search()
myds.Clear()
Dim objConn As New SqlConnection(Application("sConnStr"))
qry = ""
qry = qry & "SELECT Item_code,Item_CCN,Location_Owner,SUM(ISNULL(barcode_qty,0))-SUM(ISNULL(BALANCE_USED,0)) AS QTY "
qry = qry & "FROM T20100904 "
qry = qry & "WHERE BARCODE_NO='" & Trim(txt_bar.Text) & "' AND LOCATION_OWNER IN ('W11','W12','W12A','W12B','W12C') "
qry = qry & "AND (ISNULL(BARCODE_QTY,0)-ISNULL(BALANCE_USED,0) > 0) "
qry = qry & "GROUP BY Item_code,Item_CCN,Location_Owner "
Dim myAccessConn = New OleDbConnection(Application("Conn"))
Dim myAccessCommand = New OleDbCommand(qry, myAccessConn)
Dim myDa = New OleDbDataAdapter(myAccessCommand)
myAccessConn.Open()
myDa.Fill(myds, "list")
If myds.Tables("list").Rows.Count > 0 Then
GridView1.DataSource = myds.Tables("list")
GridView1.DataBind()
'txt_qty.Text = myds.Tables("list").Rows(0).Item("QTY")
'ScriptManager1.SetFocus(txt_qty.ClientID)
'txt_qty.Attributes.Add("onfocus", "this.select();")
'txt_qty.Text = ""
lbl_message.Text = ""
ScriptManager1.SetFocus(txt_qty.ClientID)
txt_qty.Attributes.Add("onfocus", "this.select();")
Else
lbl_message.Text = "ไม่พบข้อมูล!!"
'ScriptManager1.SetFocus(txt_bar.ClientID)
txt_bar.Text = ""
End If
End Sub
Protected Sub txt_bar_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_bar.TextChanged
search()
End Sub
Private Function IsNumber(ByVal value As String) As Boolean
Try
Integer.Parse(value)
Return True
Catch ex As Exception
Return False
End Try
End Function
Protected Sub txt_qty_TextChanged1(ByVal sender As Object, ByVal e As System.EventArgs)
If Not IsNumber(txt_qty.Text) Then Exit Sub
If GridView1.Rows.Count > 0 Then
For Each dli As GridViewRow In GridView1.Rows
lbl_ccn = DirectCast(dli.FindControl("lbl_ccn"), Label)
lbl_item = DirectCast(dli.FindControl("lbl_item"), Label)
lbl_loc = DirectCast(dli.FindControl("lbl_loc"), Label)
lbl_qty = DirectCast(dli.FindControl("lbl_qty"), Label)
If Convert.ToInt32(txt_qty.Text.Trim()) <= Convert.ToInt32(lbl_qty.Text.Trim()) Then
ListBox1.Items.Add(UCase(txt_bar.Text.Trim()) & "," & lbl_item.Text.Trim() & "," & lbl_ccn.Text.Trim() & "," & lbl_loc.Text.Trim() & "," & txt_qty.Text.Trim())
txt_bar.Text = ""
lbl_message.Text = ""
GridView1.DataSource = Nothing
GridView1.DataBind()
ScriptManager1.SetFocus(txt_bar.ClientID())
Else
lbl_message.Text = "จำนวน QTY ไม่พอจ่าย"
ScriptManager1.SetFocus(txt_qty.ClientID)
txt_qty.Attributes.Add("onfocus", "this.select();")
End If
Next
End If
'ScriptManager1.SetFocus(txt_bar.ClientID())
'txt_bar.Attributes.Add("onfocus", "this.select();")
End Sub
Protected Sub bnt_addlist_Click(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Dim aa As String = Session("emp_id").ToString()
Session("emp_id") = "0320100733"
If Session("emp_id") = "" Then
Response.Redirect("pc_login.aspx")
Else
ScriptManager1.SetFocus(txt_doc.ClientID)
End If
If Not Me.IsPostBack Then
txt_date.Text = Date.Now
End If
End Sub
Protected Sub bnt_delete_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End Sub
Protected Sub bnt_save_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim arr1() As String
Dim i As Integer
If ListBox1.Items.Count > 0 Then
Try
For i = 0 To ListBox1.Items.Count - 1
Dim str As String = ListBox1.Items(i).Text
transdate = txt_date.Text
arr1 = str.Split(",".ToCharArray())
If arr1(0).ToString <> "" And arr1(1).ToString() <> "" Then
Dim objConn As New SqlConnection(Application("sConnStr"))
Dim objCmd As New SqlCommand("S20110205", objConn)
objCmd.CommandType = CommandType.StoredProcedure
Dim objReader As SqlDataReader
objCmd.Parameters.Add(New SqlParameter("@Item", Data.SqlDbType.VarChar, 50))
objCmd.Parameters.Add(New SqlParameter("@barcode_qty", Data.SqlDbType.Decimal))
objCmd.Parameters.Add(New SqlParameter("@emp_id", Data.SqlDbType.VarChar, 10))
objCmd.Parameters.Add(New SqlParameter("@Item_CCN", Data.SqlDbType.VarChar, 20))
objCmd.Parameters.Add(New SqlParameter("@date", SqlDbType.DateTime))
objCmd.Parameters.Add(New SqlParameter("@locfrom", SqlDbType.VarChar, 50))
objCmd.Parameters.Add(New SqlParameter("@locto", SqlDbType.VarChar, 50))
objCmd.Parameters.Add(New SqlParameter("@reason", SqlDbType.VarChar, 50))
objCmd.Parameters.Add(New SqlParameter("@barcode_no", SqlDbType.VarChar, 50))
objCmd.Parameters.Add(New SqlParameter("@status", SqlDbType.VarChar, 5))
objCmd.Parameters.Add(New SqlParameter("@location_name", SqlDbType.VarChar, 20))
objCmd.Parameters("@emp_id").Value = Session("emp_id").ToString()
objCmd.Parameters("@Item_CCN").Value = UCase(arr1(2))
objCmd.Parameters("@barcode_qty").Value = UCase(arr1(4))
objCmd.Parameters("@Item").Value = UCase(arr1(1).ToString())
objCmd.Parameters("@date").Value = transdate
objCmd.Parameters("@locfrom").Value = UCase(arr1(3))
objCmd.Parameters("@locto").Value = ddl_locto.Text.ToString()
objCmd.Parameters("@location_name").Value = txt_doc.Text.ToString()
objCmd.Parameters("@barcode_no").Value = UCase(arr1(0))
'Dim loc_to As String
'loc_to = ddl_locto.Text.Trim()
'Select Case loc_to
' Case "W12", "W12A", "W12B", "W12C"
' objCmd.Parameters("@reason").Value = "2002"
' Case "W14N"
' objCmd.Parameters("@reason").Value = "2009"
' Case "W13"
' objCmd.Parameters("@reason").Value = "2008"
' Case "WSPR"
' objCmd.Parameters("@reason").Value = "2015"
' Case "1ETC", "1AIP", "1KWC", "3PCB", "3DECK", "7ETC", "7FINAL"
objCmd.Parameters("@reason").Value = "2001"
'Case Else
' objCmd.Parameters("@reason").Value = "2018"
'End Select
'If ddl_locto.Text = "W14N" Then
' objCmd.Parameters("@status").Value = "1"
'ElseIf ddl_locto.Text = "W15" Or ddl_locto.Text = "W13" Or ddl_locto.Text = "W40NG" Then
' objCmd.Parameters("@status").Value = "4"
'ElseIf ddl_locto.Text = "WSPR" Then
' objCmd.Parameters("@status").Value = "3"
'Else
objCmd.Parameters("@status").Value = "3"
'End If
objConn.Open()
objReader = objCmd.ExecuteReader()
myds.Clear()
qry = ""
qry = qry & "SELECT SEQ ,(ISNULL(BARCODE_QTY,0)-ISNULL(BALANCE_USED,0) ) "
qry = qry & "FROM T20100904 "
qry = qry & "WHERE BARCODE_NO='" & arr1(0) & "' AND LOCATION_OWNER IN ('W11','W12','W12A','W12B','W12C') "
qry = qry & "AND (ISNULL(BARCODE_QTY,0)-ISNULL(BALANCE_USED,0) > 0) "
Dim myAccessConn = New OleDbConnection(Application("Conn"))
Dim myAccessCommand = New OleDbCommand(qry, myAccessConn)
Dim myDa = New OleDbDataAdapter(myAccessCommand)
myAccessConn.Open()
myDa.Fill(myds, "update")
If myds.Tables("update").Rows.Count > 0 Then
GridView2.DataSource = myds.Tables("update")
GridView2.DataBind()
End If
Dim j As Integer
Dim moveqty As Integer
moveqty = Convert.ToInt32(arr1(4))
For j = 0 To GridView2.Rows.Count - 1
If Convert.ToInt32(GridView2.Rows(j).Cells(1).Text) < moveqty Then
Dim objConn2 As New SqlConnection(Application("sConnStr"))
Dim comProduct1 As SqlCommand = New SqlCommand
Dim sqlproduct1 As String = "update T20100904 SET Balance_used = ISNULL(Balance_used,0) + " & Convert.ToInt32(GridView2.Rows(j).Cells(1).Text) & ", update_date=getdate() WHERE seq=" & GridView2.Rows(j).Cells(0).Text & ""
objConn2.Open()
With comProduct1
.CommandType = CommandType.Text
.CommandText = sqlproduct1
.Connection = objConn2
.ExecuteNonQuery()
End With
objConn2.Close()
moveqty -= Convert.ToInt32(GridView2.Rows(j).Cells(1).Text)
Else
Dim objConn2 As New SqlConnection(Application("sConnStr"))
Dim comProduct1 As SqlCommand = New SqlCommand
Dim sqlproduct1 As String = "update T20100904 SET Balance_used = ISNULL(Balance_used,0) + " & moveqty & " , update_date=getdate() WHERE seq=" & GridView2.Rows(j).Cells(0).Text & ""
objConn2.Open()
With comProduct1
.CommandType = CommandType.Text
.CommandText = sqlproduct1
.Connection = objConn2
.ExecuteNonQuery()
End With
objConn2.Close()
Exit For
End If
Next
'Label2.Text = "Save Success"
End If
Next
txt_qty.Text = ""
ListBox1.Items.Clear()
txt_doc.Text = ""
' ScriptManager2.SetFocus(txt_doc.ClientID)
Catch ex As Exception
' Label2.Text = "Error-" & Session("error")
End Try
End If
End Sub
Protected Sub txt_doc_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_doc.TextChanged
'txt_bar.Focus()
ScriptManager1.SetFocus(txt_bar.ClientID)
End Sub
Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Response.Redirect("./mainmenu.aspx")
End Sub
End Class