strSQL = "SELECT COUNT(*) FROM article_tbl WHERE article_no = '" & articleNo & "'"
objCmd = New OleDbCommand(strSQL, objConn)
num = objCmd.ExecuteScalar()
If num > 0 Then
Response.Write("<script>alert('This article already existing,please check again');</script>")
Response.Write("<script>window.location='add_art.aspx'</script>")
Else
Try
' ***first process
strSQL = "INSERT INTO article_tbl (article_no,article_name,article_model,article_size, vender_id,maker,subcate_id,cate_id ,packing_unit,price,moq,leadtime,purchasing_by,certified_report,incoming_report,product_spec, fac_audit,date_modify,status,esd_control,show,art_comment,area)" & _
" VALUES('" & articleNo & "','" & articleName & "','" & articleModel & "','" & articleSize & "', " & venderID & ",'" & selectMaker & "'," & subcategory_id & "," & category_id & ",'" & packingUnit & "','" & price2 & "','" & moq2 & "','" & leadTime & "', '" & purchasing2 & "','" & certified2 & "','" & incoming2 & "','" & specSheet & "','" & facAudit & "','" & dateTime & "'," & status & " ,'" & type & "',0,'" & comment.Text & "'," & select_area.Text & ")"
objCmd = New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
Catch ex As Exception
'**** ตอนนี้ฟ้อง Error ที่ตรงนี้
Response.Write("<script> alert('ERROR 001:" & ex.Message & "');</script>")
'*** ฟ้อง Error เสร็จ ก็ให้ลิงค์ไปที่ชื่อไฟล์ add_art.aspx (ไฟล์เดิม เหมือนกับ รีเฟลชธรรมดา)
Response.Write("<script>window.location='add_art.aspx';</script>")
End Try
'***next process แต่พอมาดูผลมันจริงๆ ปรากฎว่า สคริปข้างล่างนี้ยังทำงานปกติ
strSQL = "SELECT MAX(article_id) FROM article_tbl"
objCmd = New OleDbCommand(strSQL, objConn)
lastart = objCmd.ExecuteScalar()
strSQL = "SELECT * FROM article_tbl WHERE article_id = " & lastart & ""
objCmd = New OleDbCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
dtReader.Read()
'File Upload
Dim objGraphic As System.Drawing.Image
Dim objBitmap As Bitmap
Dim intWidth As Integer = 100
Dim intHeight As Integer = 0
Dim bigWidth As Integer = 550
Dim bigHeight As Integer = 0
Dim i As Integer
For i = 1 To 5
Dim picture As FileUpload = FindControl("picture_" & i)
Dim pictureName As String = dtReader.GetValue(1) & i & GetExtension(picture.FileName)
If picture.HasFile Then
Try
strSQL = "INSERT INTO image_tbl (img_name,refarticle_id) VALUES ('" & pictureName & "'," & lastart & ")"
objCmd = New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
Catch ex As Exception
Response.Write("<script> alert('ERROR 002:" & ex.Message & "');</script>")
Response.Write("<script>window.location='add_art.aspx'</script>")
End Try
picture.PostedFile.SaveAs(Server.MapPath("../tempPic/" & pictureName))
'Start Resize Big
objGraphic = System.Drawing.Image.FromFile(Server.MapPath("../tempPic/" & pictureName))
If bigHeight > 0 Then
objBitmap = New Bitmap(objGraphic, bigWidth, bigHeight)
Else
If objGraphic.Width > objGraphic.Height Then
If objGraphic.Width > bigWidth Then
Dim radio As Double = objGraphic.Height / objGraphic.Width
bigHeight = radio * bigWidth
objBitmap = New Bitmap(objGraphic, bigWidth, bigHeight)
Else
objBitmap = New Bitmap(objGraphic)
End If
Else
If objGraphic.Height > bigWidth Then
Dim radio As Double = objGraphic.Width / objGraphic.Height
bigHeight = radio * bigWidth
objBitmap = New Bitmap(objGraphic, bigHeight, bigWidth)
Else
objBitmap = New Bitmap(objGraphic)
End If
End If
End If
'Add ESD logo
If type = 1 Then
Dim picGraph As Graphics = Graphics.FromImage(objBitmap)
Dim overlay As Bitmap = New System.Drawing.Bitmap(Server.MapPath("../ESDlogo/ESDsign.gif"))
picGraph.DrawImage(overlay, (objBitmap.Width - (overlay.Width + 5)), 5)
overlay = Nothing
picGraph = Nothing
End If
objBitmap.Save(Server.MapPath("../BigPicture/" & pictureName))
objGraphic.Dispose()
objBitmap = Nothing
objGraphic = Nothing
'End Resize Big Pic
'Start Resize Thumpnail
objGraphic = System.Drawing.Image.FromFile(Server.MapPath("../BigPicture/" & pictureName))
''---->crop picture
'Dim Lpoint As Integer = (objGraphic.Width / 2) - (objGraphic.Height / 2)
'Dim Rpoint As Integer = (objGraphic.Width / 2) + (objGraphic.Height / 2)
'objGraphic = CropImage(objGraphic, New Point(Lpoint, 0), New Point(Rpoint, objGraphic.Height))
''---> end crop
If intHeight > 0 Then
objBitmap = New Bitmap(objGraphic, intWidth, intHeight)
Else
If objGraphic.Width > objGraphic.Height Then
If objGraphic.Width > intWidth Then
Dim radio As Double = objGraphic.Height / objGraphic.Width
intHeight = radio * intWidth
objBitmap = New Bitmap(objGraphic, intWidth, intHeight)
Else
objBitmap = New Bitmap(objGraphic)
End If
Else
If objGraphic.Height > intWidth Then
Dim radio As Double = objGraphic.Width / objGraphic.Height
intHeight = radio * intWidth
objBitmap = New Bitmap(objGraphic, intHeight, intWidth)
Else
objBitmap = New Bitmap(objGraphic)
End If
End If
End If
If type = 1 Then
Dim picGraph As Graphics = Graphics.FromImage(objBitmap)
Dim overlay As Bitmap = New System.Drawing.Bitmap(Server.MapPath("../ESDlogo/ESDsign_s.gif"))
picGraph.DrawImage(overlay, (objBitmap.Width - (overlay.Width + 5)), 5)
overlay = Nothing
picGraph = Nothing
End If
objBitmap.Save(Server.MapPath("../Thumpnail/" & pictureName))
objGraphic.Dispose()
objBitmap = Nothing
objGraphic = Nothing
Dim fileIn As New FileInfo(Server.MapPath("../tempPic/" & pictureName))
If fileIn.Exists Then
fileIn.Delete()
End If
End If
Next