Imports System.Data
Imports System.Data.SqlClient
Partial Class web_Admininvent
Inherits System.Web.UI.Page
Dim conn As SqlConnection
Dim cons As String = Class1.Constr3
Dim DA As SqlDataAdapter
Dim DS As DataSet
Dim DT As DataTable
Dim DV As DataView
Dim com As SqlCommand
Public iRow As Integer
Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
If Not Page.IsPostBack Then
ViewState("Sortfiled") = "equip_id"
ViewState("Sortdirection") = "asc"
Me.ProductData()
Me.MyGridBy()
Else
DV = Session("data")
MyGridBy()
End If
End Sub
Private Sub MyGridBy()
GridView1.DataSource = DV
Dim X1() As String = {"equip_id"}
GridView1.DataKeyNames = X1
GridView1.DataBind()
End Sub
Private Sub productdata(Optional ByVal equip_name As String = "")
Dim sql2 As String = "SELECT * FROM productin"
If equip_name <> "" Then
sql2 &= " WHERE equip_name LIKE '" & equip_name & "%'"
Me.MyGridBy()
End If
DA = New SqlDataAdapter(sql2, cons)
Dim DT2 As New DataTable
DA.Fill(DT2)
'DT2.Columns.Add("Amount", GetType(Double), "Unitprice * UnitsInStock")
DV = DT2.DefaultView
'DV.Sort = "[" & ViewState("Sortfield") & "] " & ViewState("Sortdirection")
Session("data") = DV
MyGridBy()
End Sub
Public Sub dropemp()
Dim sql2 As String = "SELECT emp_name FROM employ"
DA = New SqlDataAdapter(sql2, cons)
Dim dt As New DataTable
Conn = New SqlConnection(cons)
Conn.Open()
DA.Fill(dt)
DA = Nothing
Conn.Close()
Conn = Nothing
'*** DropDownlist ***'
With Me.DDEMP
.DataSource = dt
.DataTextField = "emp_name"
.DataValueField = "emp_name"
.DataBind()
End With
'Return DropDownList4
End Sub
Public Sub droppro()
Dim sql2 As String = "SELECT code_equip FROM productstock"
DA = New SqlDataAdapter(sql2, cons)
Dim dt As New DataTable
conn = New SqlConnection(cons)
conn.Open()
DA.Fill(dt)
DA = Nothing
Conn.Close()
Conn = Nothing
'*** DropDownlist ***'
With Me.DDPRO
.DataSource = dt
.DataTextField = "code_equip"
.DataValueField = "code_equip"
.DataBind()
End With
'Return DropDownList4
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label19.Text = Date.Today
TextBox17.Visible = False
DDEMP.Visible = False
Button7.Visible = False
If Not Page.IsPostBack() Then
droppro()
dropemp()
MyGridBy()
showpro()
'checkstock()
Else
Me.MyGridBy()
End If
End Sub
Private Sub showpro()
Dim sql2 As String = "SELECT * FROM productstock WHERE code_equip = '" & DDPRO.SelectedValue & "'"
DA = New SqlDataAdapter(sql2, cons)
Dim dt As New DataTable
conn = New SqlConnection(cons)
conn.Open()
DA.Fill(dt)
DA = Nothing
conn.Close()
conn = Nothing
If dt.Rows.Count <> 0 Then
Me.TextBox11.Text = dt.Rows(0)("equip_cate")
Me.TextBox12.Text = dt.Rows(0)("equip_name")
Me.TextBox14.Text = dt.Rows(0)("Brand")
Me.TextBox15.Text = dt.Rows(0)("equip_model")
Me.TextBox2.Text = dt.Rows(0)("equip_cost")
Me.TextBox19.Text = dt.Rows(0)("amount_stock")
Me.TextBox10.Text = dt.Rows(0)("equip_detail")
Me.TextBox18.Text = dt.Rows(0)("emp_name")
MyGridBy()
End If
End Sub
'Private Sub checkstock()
' Dim Sql2 As String = "SELECT * FROM productstock WHERE code_equip = '" & DDPRO.SelectedValue & "'"
' DA = New SqlDataAdapter(sql2, cons)
' Dim dt As New DataTable
' conn = New SqlConnection(cons)
' conn.Open()
' DA.Fill(dt)
' DA = Nothing
' conn.Close()
' conn = Nothing
' If dt.Rows(0)("amount_stock") <= 2 Then
' Label29.Text = "จำนวนอุปกรณ์ไม่พอเบิก"
' Label29.ForeColor = Drawing.Color.Red
' Else
' Label29.Text = ""
' End If
'End Sub
Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
TextBox14.Text = ""
TextBox15.Text = ""
TextBox17.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox18.Text = ""
TextBox19.Text = ""
TextBox18.Visible = False
DDPRO.Visible = False
TextBox17.Visible = True
Button6.Enabled = False
Button5.Visible = True
Button7.Visible = True
DDEMP.Visible = True
TextBox19.Enabled = False
MyGridBy()
End Sub
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
'Dim num1, num2, total As Integer
'num1 = TextBox3.Text
'num2 = TextBox19.Text
'TextBox20.Text = total
'total = num1 + num2
TextBox19.Text = Val(TextBox3.Text) + Val(TextBox19.Text)
Dim Conn As New SqlConnection(cons)
If Page.IsPostBack Then
Conn.Open()
If TextBox17.Text <> "" Then
Dim Sql2 As String = "insert into productin (date_in,code_equip,equip_name,Brand,equip_cate,equip_detail,equip_model,equip_cost,amount_in,emp_name) VALUES ('" & Label19.Text & "','" & TextBox17.Text & "','" & TextBox12.Text & "','" & TextBox14.Text & "','" & TextBox11.Text & "','" & TextBox10.Text & "','" & TextBox15.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & DDEMP.SelectedValue & "')"
Dim Sql3 As String = "insert into productstock (date_in,code_equip,equip_name,Brand,equip_cate,equip_detail,equip_model,equip_cost,amount_stock,emp_name) VALUES ('" & Label19.Text & "','" & TextBox17.Text & "','" & TextBox12.Text & "','" & TextBox14.Text & "','" & TextBox11.Text & "','" & TextBox10.Text & "','" & TextBox15.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & DDEMP.SelectedValue & "')"
Dim command As New SqlCommand(Sql2)
Dim command2 As New SqlCommand(Sql3)
command.Connection = Conn
command.ExecuteNonQuery()
command2.Connection = Conn
command2.ExecuteNonQuery()
GridView1.DataBind()
Conn.Close()
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
TextBox14.Text = ""
TextBox15.Text = ""
TextBox17.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox18.Text = ""
TextBox19.Text = ""
DDPRO.Visible = True
TextBox17.Visible = False
Button6.Enabled = True
Label29.Text = "บันทึกข้อมูลเรียบร้อย"
Label29.ForeColor = Drawing.Color.Red
Response.Redirect("AdminProductin.aspx")
End If
If TextBox17.Text = "" Then
Dim DRV As DataRowView = DV(iRow)
Dim Sql2 As String = "insert into productin (date_in,code_equip,equip_name,Brand,equip_cate,equip_detail,equip_model,equip_cost,amount_in,emp_name) VALUES ('" & Label19.Text & "','" & DDPRO.SelectedValue & "','" & TextBox12.Text & "','" & TextBox14.Text & "','" & TextBox11.Text & "','" & TextBox10.Text & "','" & TextBox15.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & DDEMP.SelectedValue & "')"
Dim Sql3 As String = "update productstock set date_in = @P1,code_equip = @P2,equip_name = @P3,Brand = @P4,equip_cate = @P5,equip_detail = @P6,equip_model = @P7,equip_cost = @P8,amount_stock = @P9,emp_name = @P10"
Dim command As New SqlCommand(Sql2)
Dim command2 As New SqlCommand(Sql3)
Dim P1 As SqlParameter
P1 = New SqlParameter("@P1", Label19.Text)
command2.Parameters.Add(P1)
Dim P2 As SqlParameter
P2 = New SqlParameter("@P2", DDPRO.SelectedValue)
command2.Parameters.Add(P2)
Dim P3 As SqlParameter
P3 = New SqlParameter("@P3", TextBox12.Text)
command2.Parameters.Add(P3)
Dim P4 As SqlParameter
P4 = New SqlParameter("@P4", TextBox14.Text)
command2.Parameters.Add(P4)
Dim P5 As SqlParameter
P5 = New SqlParameter("@P5", TextBox11.Text)
command2.Parameters.Add(P5)
Dim P6 As SqlParameter
P6 = New SqlParameter("@P6", TextBox10.Text)
command2.Parameters.Add(P6)
Dim P7 As SqlParameter
P7 = New SqlParameter("@P7", TextBox15.Text)
command2.Parameters.Add(P7)
Dim P8 As SqlParameter
P8 = New SqlParameter("@P8", TextBox2.Text)
command2.Parameters.Add(P8)
Dim P9 As SqlParameter
P9 = New SqlParameter("@P9", TextBox19.Text)
command2.Parameters.Add(P9)
Dim P10 As SqlParameter
P10 = New SqlParameter("@P10", DDEMP.SelectedValue)
command2.Parameters.Add(P10)
command.Connection = Conn
command.ExecuteNonQuery()
command2.Connection = Conn
command2.ExecuteNonQuery()
GridView1.DataBind()
Conn.Close()
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
TextBox14.Text = ""
TextBox15.Text = ""
TextBox17.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox18.Text = ""
TextBox19.Text = ""
DDPRO.Visible = True
TextBox17.Visible = False
Button6.Enabled = True
Label29.Text = "บันทึกข้อมูลเรียบร้อย"
Label29.ForeColor = Drawing.Color.Red
Response.Redirect("AdminProductin.aspx")
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
TextBox14.Text = ""
TextBox15.Text = ""
TextBox17.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox18.Text = ""
TextBox19.Text = ""
DDPRO.Visible = True
TextBox17.Visible = False
Button6.Enabled = True
End If
End If
End Sub
Protected Sub DDPRO_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDPRO.SelectedIndexChanged
showpro()
'checkstock()
MyGridBy()
Label29.Text = DDPRO.SelectedValue
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
Me.MyGridBy()
End Sub
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
If ViewState("Sortfield") = e.SortExpression Then
If ViewState("Sortdirection") = "asc" Then ViewState("Sortdirection") = "desc" Else ViewState("Sortdirection") = "asc"
Else
ViewState("Sortfield") = e.SortExpression
ViewState("Sortdirection") = "asc"
End If
DV.Sort = "[" & ViewState("Sortfield") & "] " & ViewState("Sortdirection")
Me.MyGridBy()
End Sub
Protected Sub Button7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button7.Click
If Page.IsPostBack Then
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
TextBox14.Text = ""
TextBox15.Text = ""
TextBox17.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox18.Text = ""
TextBox19.Enabled = True
Button7.Visible = False
DDPRO.Visible = True
TextBox17.Visible = False
Button6.Enabled = True
showpro()
End If
End Sub
End Class
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VB.NET, VS 2010 (.NET 4.x)