Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim res As Short = MsgBox("ท่านต้องการรับสินค้า !!", MsgBoxStyle.YesNo + MsgBoxStyle.Information + MsgBoxStyle.ApplicationModal, "ยืนยัน")
If res = 7 Then
Exit Sub
End If
Dim che As CheckBox
For i = 0 To GridView2.Rows.Count - 1
che = GridView2.Rows(i).Cells(8).FindControl("CheckBox1")
If (che.Checked = True) Then
com()
strSql2 = "INSERT INTO Stock(stock_qty,D_id,date1,stock_status,CT_id) VALUES(" & GridView2.Rows(i).Cells(4).Text & "," & GridView2.Rows(i).Cells(2).Text & ",CONVERT(datetime,'" & Date.Now & "',103),'Y'," & GridView2.Rows(i).Cells(7).Text & ")"
With cmd2
.Parameters.Clear()
.CommandText = strSql2
.CommandType = CommandType.Text
.Connection = Conn
.ExecuteNonQuery()
End With
com()
strSql = "Update Order_buydetail set OD_status=@OD_status where OD_number =" & GridView2.Rows(i).Cells(1).Text
With cmd
.Parameters.Clear()
.Parameters.Add("@OD_status", SqlDbType.VarChar).Value = "Y"
.CommandText = strSql
.CommandType = CommandType.Text
.Connection = Conn
.ExecuteNonQuery()
End With
End If
Next
If (Page.IsPostBack) Then
GridView2.DataBind()
DropDownList1.DataBind()
End If
End Sub
End Class
For i = 0 To GridView2.Rows.Count - 1
strSql = "INSERT INTO Order_sale(Sale_date,Std_id,E_id,Sale_qty,Sale_price,D_id,Sale_number,Sale_priceUnit) VALUES (@Sale_date,@Std_id,@E_id,@Sale_qty,@Sale_price,@D_id,@Sale_number,@Sale_priceUnit)"
MsgBox(CInt(GridView2.Rows(i).Cells(2).Text))
With cmd
.Parameters.Clear()
.Parameters.Add("@Sale_date", SqlDbType.DateTime).Value = TextBox16.Text
.Parameters.Add("@Std_id", SqlDbType.Int).Value = CInt(id_phar.SelectedValue.Trim())
.Parameters.Add("@E_id", SqlDbType.Int).Value = CInt(Name_Emp.SelectedValue)
.Parameters.Add("@Sale_qty", SqlDbType.Int).Value = CInt(GridView2.Rows(i).Cells(2).Text)
.Parameters.Add("@Sale_price", SqlDbType.Money).Value = GridView2.Rows(i).Cells(5).Text
.Parameters.Add("@Sale_number", SqlDbType.Int).Value = CInt(TextBox17.Text)
.Parameters.Add("@D_id", SqlDbType.Int).Value = CInt(GridView2.Rows(i).Cells(0).Text)
.Parameters.Add("@Sale_priceUnit", SqlDbType.Money).Value = GridView2.Rows(i).Cells(3).Text
.CommandText = strSql
.CommandType = CommandType.Text
.Connection = conn
.ExecuteNonQuery()
End With
Next
com()
For i = 0 To GridView2.Rows.Count - 1
strSql3 = "select Drug.D_Name, sum(stock_qty)as stock1 from Stock,Drug where stock.CT_id=" & GridView2.Rows(i).Cells(6).Text & " and stock.D_id=Drug.D_id and Stock.D_id=" & GridView2.Rows(i).Cells(0).Text & " AND stock.stock_status='Y' GROUP BY Drug.D_Name"
With cmd3
.CommandText = strSql3
.CommandType = CommandType.Text
.Connection = conn
crm = .ExecuteReader()
End With
If crm.Read = True Then
j = 1
sttmp1 = crm.Item("stock_qty")
stid1 = crm.Item("stock_id")
If crm.Item("stock_qty") > GridView2.Rows(i).Cells(2).Text Then
stqty1 = (crm.Item("stock_qty") - GridView2.Rows(i).Cells(2).Text)
Else
stqty1 = (crm.Item("stock_qty") - GridView2.Rows(i).Cells(2).Text) * -1
If crm.Read = True Then
k = 1
sttmp2 = crm.Item("stock_qty")
stid2 = crm.Item("stock_id")
If crm.Item("stock_qty") > stqty1 Then
stqty2 = (crm.Item("stock_qty") - stqty1)
Else
stqty2 = (crm.Item("stock_qty") - stqty1) * -1
If crm.Read = True Then
l = 1
sttmp3 = crm.Item("stock_qty")
stid3 = crm.Item("stock_id")
If crm.Item("stock_qty") > stqty2 Then
stqty3 = (crm.Item("stock_qty") - stqty2)
Else
stqty3 = (crm.Item("stock_qty") - stqty2) * -1
End If
End If
End If
End If
End If
End If
For i = 0 To GridView2.Rows.Count - 1
strSql = "INSERT INTO Order_sale(Sale_date,Std_id,E_id,Sale_qty,Sale_price,D_id,Sale_number,Sale_priceUnit) VALUES (@Sale_date,@Std_id,@E_id,@Sale_qty,@Sale_price,@D_id,@Sale_number,@Sale_priceUnit)"
MsgBox(CInt(GridView2.Rows(i).Cells(2).Text))
With cmd
.Parameters.Clear()
.Parameters.Add("@Sale_date", SqlDbType.DateTime).Value = TextBox16.Text
.Parameters.Add("@Std_id", SqlDbType.Int).Value = CInt(id_phar.SelectedValue.Trim())
.Parameters.Add("@E_id", SqlDbType.Int).Value = CInt(Name_Emp.SelectedValue)
.Parameters.Add("@Sale_qty", SqlDbType.Int).Value = CInt(GridView2.Rows(i).Cells(2).Text)
.Parameters.Add("@Sale_price", SqlDbType.Money).Value = GridView2.Rows(i).Cells(5).Text
.Parameters.Add("@Sale_number", SqlDbType.Int).Value = CInt(TextBox17.Text)
.Parameters.Add("@D_id", SqlDbType.Int).Value = CInt(GridView2.Rows(i).Cells(0).Text)
.Parameters.Add("@Sale_priceUnit", SqlDbType.Money).Value = GridView2.Rows(i).Cells(3).Text
.CommandText = strSql
.CommandType = CommandType.Text
.Connection = conn
.ExecuteNonQuery()
End With
Next
com()
For i = 0 To GridView2.Rows.Count - 1
strSql3 = "select Drug.D_Name, sum(stock_qty)as stock1 from Stock,Drug where stock.CT_id=" & GridView2.Rows(i).Cells(6).Text & " and stock.D_id=Drug.D_id and Stock.D_id=" & GridView2.Rows(i).Cells(0).Text & " AND stock.stock_status='Y' GROUP BY Drug.D_Name"
With cmd3
.CommandText = strSql3
.CommandType = CommandType.Text
.Connection = conn
crm = .ExecuteReader()
End With
If crm.Read = True Then
j = 1
sttmp1 = crm.Item("stock_qty")
stid1 = crm.Item("stock_id")
If crm.Item("stock_qty") > GridView2.Rows(i).Cells(2).Text Then
stqty1 = (crm.Item("stock_qty") - GridView2.Rows(i).Cells(2).Text)
Else
stqty1 = (crm.Item("stock_qty") - GridView2.Rows(i).Cells(2).Text) * -1
If crm.Read = True Then
k = 1
sttmp2 = crm.Item("stock_qty")
stid2 = crm.Item("stock_id")
If crm.Item("stock_qty") > stqty1 Then
stqty2 = (crm.Item("stock_qty") - stqty1)
Else
stqty2 = (crm.Item("stock_qty") - stqty1) * -1
If crm.Read = True Then
l = 1
sttmp3 = crm.Item("stock_qty")
stid3 = crm.Item("stock_id")
If crm.Item("stock_qty") > stqty2 Then
stqty3 = (crm.Item("stock_qty") - stqty2)
Else
stqty3 = (crm.Item("stock_qty") - stqty2) * -1
End If
End If
End If
End If
End If
End If