001.
Imports
System.Data
002.
Imports
System.Data.SqlClient
003.
Public
Class
MResou
004.
Inherits
System.Web.UI.Page
005.
006.
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
007.
If
Not
IsPostBack
Then
008.
TxtResou.Text =
""
009.
TxtQty.Text =
""
010.
TxtResou.Focus()
011.
End
If
012.
BRDel.Attributes.Add(
"onclick"
,
"if(!window.confirm('Are you sure delete record??'))"
&
"return false;"
)
013.
If
Not
IsPostBack
Then
014.
BindData()
015.
End
If
016.
End
Sub
017.
018.
Protected
Sub
BREdit_Click(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
BREdit.Click
019.
If
lstResou.SelectedIndex < 0
Then
020.
lblMessageR.Text =
"Please Select Resource"
021.
Return
022.
End
If
023.
Dim
strConn
As
String
=
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Rescuedb.mdf;Integrated Security=True;User Instance=True"
024.
Dim
objConn
As
New
SqlConnection(strConn)
025.
objConn.Open()
026.
Dim
cmdSQL
As
String
=
"SELECT ResouID,Resou,Qty "
&
" FROM dbo.Resource WHERE ResouID ="
& lstResou.SelectedItem.Value
027.
Dim
Cmd
As
New
SqlCommand(cmdSQL, objConn)
028.
Dim
RR
As
SqlDataReader
029.
RR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
030.
While
RR.Read()
031.
lblResouID.Text = RR(
"ResouID"
)
032.
TxtResou.Text = RR(
"Resou"
)
033.
TxtQty.Text = RR(
"Qty"
)
034.
End
While
035.
TxtResou.Enabled =
True
036.
TxtQty.Enabled =
True
037.
BRUpdate.Visible =
True
038.
BRDel.Visible =
True
039.
lblMessageR.Text =
""
040.
lblErrorResou.Visible =
False
041.
lblErrorQty.Visible =
False
042.
End
Sub
043.
044.
Protected
Sub
BRDel_Click(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
BRDel.Click
045.
046.
Dim
strConn
As
String
=
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Rescuedb.mdf;Integrated Security=True;User Instance=True"
047.
Dim
objConn
As
New
SqlConnection(strConn)
048.
objConn.Open()
049.
Dim
cmdSQL
As
String
=
"DELETE FROM dbo.Resource "
&
" WHERE ResouID=@ResouID"
050.
Dim
Cmd
As
New
SqlCommand(cmdSQL, objConn)
051.
Cmd.Parameters.Add(
"@ResouID"
, SqlDbType.Int).Value =
Me
.lblResouID.Text
052.
Cmd.ExecuteNonQuery()
053.
objConn.Close()
054.
BindData()
055.
lstResou.Focus()
056.
lblMessageR.Text =
"Successfully Delete:"
& TxtResou.Text &
" "
& TxtQty.Text
057.
TxtResou.Enabled =
False
058.
TxtQty.Enabled =
False
059.
BRUpdate.Visible =
False
060.
BRDel.Visible =
False
061.
End
Sub
062.
063.
Protected
Sub
BRAdd_Click(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
BRAdd.Click
064.
lblErrorResou.Visible =
False
065.
lblErrorQty.Visible =
False
066.
067.
If
TxtResou.Text =
""
Then
068.
lblErrorResou.Visible =
True
069.
lblErrorR.Text =
"Please Enter Name"
070.
TxtResou.Focus()
071.
Return
072.
End
If
073.
If
TxtQty.Text =
""
Then
074.
lblErrorQty.Visible =
True
075.
lblErrorR.Text =
"Please Enter age"
076.
TxtQty.Focus()
077.
Return
078.
End
If
079.
080.
081.
Dim
strConn
As
String
=
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Rescuedb.mdf;Integrated Security=True;User Instance=True"
082.
Dim
objConn
As
New
SqlConnection(strConn)
083.
objConn.Open()
084.
Dim
cmdSQL
As
String
=
"INSERT INTO dbo.Resource"
&
"(Resou,Qty)"
&
"VALUES(@Resou,@Qty)"
085.
Dim
Cmd
As
New
SqlCommand(cmdSQL, objConn)
086.
Cmd.Parameters.Add(
"@Resou"
, SqlDbType.NVarChar).Value =
Me
.TxtResou.Text
087.
Cmd.Parameters.Add(
"@Qty"
, SqlDbType.
Char
).Value =
Me
.TxtQty.Text
088.
Cmd.ExecuteNonQuery()
089.
objConn.Close()
090.
lblErrorR.Text =
"Successfully Insert:"
& TxtResou.Text &
" "
& TxtQty.Text
091.
TxtResou.Text =
""
092.
TxtQty.Text =
""
093.
TxtResou.Focus()
094.
End
Sub
095.
096.
Protected
Sub
BRUpdate_Click(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Handles
BRUpdate.Click
097.
098.
lblMessageR.Text =
""
099.
lblErrorResou.Visible =
False
100.
lblErrorQty.Visible =
False
101.
If
TxtResou.Text =
""
Then
102.
lblErrorResou.Visible =
True
103.
lblErrorR.Text =
"Please Enter Name"
104.
TxtResou.Focus()
105.
Return
106.
End
If
107.
If
TxtQty.Text =
""
Then
108.
lblErrorQty.Visible =
True
109.
lblErrorR.Text =
"Please Enter age"
110.
TxtQty.Focus()
111.
Return
112.
End
If
113.
114.
115.
Dim
strConn
As
String
=
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Rescuedb.mdf;Integrated Security=True;User Instance=True"
116.
Dim
objConn
As
New
SqlConnection(strConn)
117.
objConn.Open()
118.
Dim
cmdSQL
As
String
=
"UPDATE dbo.Resource "
&
" SET Resou=@Resou,Qty=@Qty "
&
" WHERE ResouID=@ResouID"
119.
Dim
Cmd
As
New
SqlCommand(cmdSQL, objConn)
120.
Cmd.Parameters.Add(
"@ResouID"
, SqlDbType.Int).Value =
Me
.lblResouID.Text
121.
Cmd.Parameters.Add(
"@Resou"
, SqlDbType.NVarChar).Value =
Me
.TxtResou.Text
122.
Cmd.Parameters.Add(
"@Qty"
, SqlDbType.
Char
).Value =
Me
.TxtQty.Text
123.
Cmd.ExecuteNonQuery()
124.
objConn.Close()
125.
BindData()
126.
lstResou.SelectedIndex = lstResou.Items.IndexOf(lstResou.Items.FindByValue(lblResouID.Text))
127.
lstResou.Focus()
128.
lblMessageR.Text =
"Successfully Update:"
& TxtResou.Text &
" "
& TxtQty.Text
129.
TxtResou.Enabled =
False
130.
TxtQty.Enabled =
False
131.
BRUpdate.Visible =
False
132.
BRDel.Visible =
False
133.
End
Sub
134.
135.
136.
137.
138.
Sub
BindData()
139.
Dim
strConn
As
String
=
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Rescuedb.mdf;Integrated Security=True;User Instance=True"
140.
Dim
objConn
As
New
SqlConnection(strConn)
141.
objConn.Open()
142.
Dim
cmdSQL
As
String
=
" SELECT ResouID,"
&
" Resou+''+Qty As ResourceData "
&
" FROM dbo.Resource "
143.
Dim
Cmd
As
New
SqlCommand(cmdSQL, objConn)
144.
Dim
RR
As
SqlDataReader
145.
RR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
146.
lstResou.DataSource = RR
147.
lstResou.DataValueField =
"ResouID"
148.
lstResou.DataTextField =
"ResourceData"
149.
lstResou.DataBind()
150.
If
lstResou.Rows > 0
Then
151.
lstResou.SelectedIndex = 0
152.
End
If
153.
lstResou.Focus()
154.
objConn.Close()
155.
End
Sub
156.
End
Class