01.
Protected
Sub
btnSave_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
btnSave.Click
02.
tmpPictureName = FileUpload1.FileName
03.
tmpPathFilePicture =
"~/Mypic/"
& tmpPictureName
04.
Dim
CurrenPath
As
String
= Server.MapPath(
"~/Mypic/"
)
05.
Dim
CurrentPath
As
String
= Server.MapPath(
"~/Mypic/"
)
06.
If
FileUpload1.HasFile
Then
07.
CurrentPath += tmpPictureName
08.
FileUpload1.SaveAs(CurrentPath)
09.
tmpPathFilePicture =
"~/Mypic/"
& tmpPictureName
10.
End
If
11.
12.
Try
13.
14.
GenerateID()
15.
sb =
New
StringBuilder
16.
sb.Remove(0, sb.Length())
17.
sb.Append(
" INSERT INTO tblTool(ToolID,ToolName,CategoryID,Brand,Qty,ReceiveDate,InsuranceDate,DepartmentID,CompanyID,ToolPic)"
)
18.
sb.Append(
" VALUES (@ToolID,@ToolName,@CategoryID,@Brand,@Qty,@ReceiveDate,@InsuranceDate,@DepartmentID,@CompanyID,@ToolPic)"
)
19.
20.
Com =
New
SqlCommand
21.
With
Com
22.
.CommandType = CommandType.Text
23.
.CommandText = sb.ToString
24.
.Connection = Conn
25.
.Parameters.Clear()
26.
.Parameters.Add(
"@ToolID"
, SqlDbType.VarChar).Value = LastID
27.
.Parameters.Add(
"@ToolName"
, SqlDbType.VarChar).Value = txtToolName.Text
28.
.Parameters.Add(
"@CategoryID"
, SqlDbType.Int).Value =
CInt
(ddlCategory.SelectedValue)
29.
.Parameters.Add(
"@Brand"
, SqlDbType.VarChar).Value = txtBrand.Text
30.
.Parameters.Add(
"@Qty"
, SqlDbType.Int).Value =
CInt
(txtQtyTool.Text)
31.
.Parameters.Add(
"@ReceiveDate"
, SqlDbType.VarChar).Value =
CStr
(txtReceiveDate.Text)
32.
.Parameters.Add(
"@InsuranceDate"
, SqlDbType.VarChar).Value =
CStr
(txtInsuranceDate.Text)
33.
.Parameters.Add(
"@DepartmentID"
, SqlDbType.Int).Value =
CInt
(ddlDepartment.SelectedValue)
34.
.Parameters.Add(
"@CompanyID"
, SqlDbType.Int).Value =
CInt
(ddlCompany.SelectedValue)
35.
.Parameters.Add(
"@ToolPic"
, SqlDbType.VarChar).Value = tmpPathFilePicture
36.
.ExecuteNonQuery()
37.
38.
End
With
39.
40.
Response.Write(
"<script language=javascript>"
)
41.
Response.Write(
"alert('คุณต้องการบันทึกข้อมูล');"
)
42.
Response.Write(
"</script>"
)
43.
44.
Catch
ex
As
Exception
45.
MsgBox(ex.Message)
46.
End
Try
47.
48.
ClearData()
49.
50.
51.
End
Sub