Imports System.Data.oledb Imports System.Data Imports System.IO Imports System.Drawing Public Class input Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents dpdbigtype As System.Web.UI.WebControls.DropDownList Protected WithEvents dpdsubtype As System.Web.UI.WebControls.DropDownList Protected WithEvents txtproID As System.Web.UI.WebControls.TextBox Protected WithEvents txtshiprice As System.Web.UI.WebControls.TextBox Protected WithEvents txthuiprice As System.Web.UI.WebControls.TextBox Protected WithEvents txtmemo As System.Web.UI.WebControls.TextBox Protected WithEvents txtcu As System.Web.UI.WebControls.TextBox Protected WithEvents Fileup As System.Web.UI.HtmlControls.HtmlInputFile Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
'注意: 以下占位符声明是 Web 窗体设计器所必需的。 '不要删除或移动它。 Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: 此方法调用是 Web 窗体设计器所必需的 '不要使用代码编辑器修改它。 InitializeComponent() End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '在此处放置初始化页的用户代码 If Not IsPostBack Then dpdbigtype_bind() End If End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If IsValid And dpdbigtype.SelectedItem.Text <> "请选择" And dpdsubtype.SelectedItem.Text <> "请选择" Then Dim smallpath, bigpath As String Dim connstr As String connstr = System.Configuration.ConfigurationSettings.AppSettings("Provider") & "data source=" & Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings("Data Source")) Dim cn As New OleDbConnection(connstr) Try If Fileup.PostedFile.ContentLength = 0 Then smallpath = "" bigpath = "" Else Dim filesplit() As String = Split(Fileup.PostedFile.FileName, "\") If (filesplit(filesplit.Length - 1).Substring(Len(filesplit(filesplit.Length - 1)) - 3, 3)) = "jpg" Or (filesplit(filesplit.Length - 1).Substring(Len(filesplit(filesplit.Length - 1)) - 3, 3)) = "gif" Then
'保存图片 Dim ff As String = Now.Year.ToString & Now.Month.ToString & Now.Day.ToString & Now.Hour.ToString & Now.Minute.ToString & Now.Second.ToString & "." & (filesplit(filesplit.Length - 1).Substring(Len(filesplit(filesplit.Length - 1)) - 3, 3)) Fileup.PostedFile.SaveAs(Server.MapPath("big/" & ff))
smallpath = "/chanpin/small/" & ff bigpath = "/chanpin/big/" & ff
'存入略缩图 Dim image As Image, width, height As Single, newwidth, newheight As Single Dim callb As System.Drawing.Image.GetThumbnailImageAbort image = System.Drawing.Image.FromFile(Server.MapPath("big/" & ff)) width = image.Width height = image.Height If width > height Then newwidth = 160 newheight = image.Height / image.Width * newwidth Else newheight = 160 newwidth = image.Width / image.Height * newheight End If
Dim size As System.Drawing.Size size = New System.Drawing.Size(newwidth, newheight) '新建一个图片() Dim ibitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(size.Width, size.Height)
'新建一个画版 Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(ibitmap) '设置高质量插值法 g.InterpolationMode = Drawing.Drawing2D.InterpolationMode.High '设置高质量,低速度呈现平滑程度 g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality g.Clear(Color.Blue) '在指定位置画图片 g.DrawImage(image, New System.Drawing.Rectangle(0, 0, ibitmap.Width, ibitmap.Height), _ New System.Drawing.Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel) If (filesplit(filesplit.Length - 1).Substring(Len(filesplit(filesplit.Length - 1)) - 3, 3)) = "jpg" Then ibitmap.Save(Server.MapPath("small/" & ff), System.Drawing.Imaging.ImageFormat.Jpeg) Else ibitmap.Save(Server.MapPath("small/" & ff), System.Drawing.Imaging.ImageFormat.Gif) End If g.Dispose() End If End If
cn.Open() Dim sql4 As String = "insert into product(bigtype,subtype,productID,shiprice,huiprice,smallimg,bigimg,cu,m) values('" & dpdbigtype.SelectedItem.Text & "','" & dpdsubtype.SelectedItem.Text & "','" & txtproID.Text & "'," & CSng(txtshiprice.Text) & "," & CSng(txthuiprice.Text) & ",'" & smallpath & "','" & bigpath & "','" & txtcu.Text & "','" & txtmemo.Text & "')" Dim comm4 As New OleDbCommand(sql4, cn) comm4.ExecuteNonQuery()
comm4 = Nothing cn.Close() Catch ex As Exception Response.Write(ex.Message) End Try Else Response.Write("<script language= javascript>alert('请选择种类!');</script>") End If End Sub
Private Sub dpdbigtype_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dpdbigtype.SelectedIndexChanged Dim connstr As String connstr = System.Configuration.ConfigurationSettings.AppSettings("Provider") & "data source=" & Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings("Data Source")) Dim cn As New OleDbConnection(connstr) Try cn.Open() Dim comm As OleDbCommand cn = New OleDbConnection(connstr) cn.Open() Dim sql As String = "select distinct subtype from protype where bigtype='" & dpdbigtype.SelectedItem.Text & "'" comm = New OleDbCommand(sql, cn) Dim read As OleDbDataReader read = comm.ExecuteReader dpdsubtype.Items.Clear() dpdsubtype.Items.Add("请选择") While read.Read dpdsubtype.Items.Add(read.Item("subtype")) End While comm.Dispose() read.Close() cn.Close() Catch ex As Exception
End Try End Sub Sub dpdbigtype_bind() Dim connstr As String connstr = System.Configuration.ConfigurationSettings.AppSettings("Provider") & "data source=" & Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings("Data Source")) Dim cn As New OleDbConnection(connstr) Try cn.Open() Dim comm As OleDbCommand cn = New OleDbConnection(connstr) cn.Open() Dim sql As String = "select distinct bigtype from protype" comm = New OleDbCommand(sql, cn) Dim read As OleDbDataReader read = comm.ExecuteReader dpdbigtype.Items.Clear() dpdbigtype.Items.Add("请选择") While read.Read dpdbigtype.Items.Add(read.Item("bigtype")) End While comm.Dispose() read.Close() cn.Close() Catch ex As Exception
End Try End Sub End Class