protected void btnOk_Click(object sender, System.EventArgs e) { string strAnnounce = CleanString.htmlInputText(txtAnnounce.Text); string mySql = "update [Append] set [text]='" + strAnnounce + "' where [id]='3'"; DBConn myDB = new DBConn(); int iNum = myDB.ExecuteNonQuery(mySql); myDB.Close(); if (iNum == 1) { Response.Write("<script>"); Response.Write("alert('[公告栏] 修改成功!!!');"); Response.Write("</script>"); } }
protected void btnAdd_Click(object sender, System.EventArgs e) { string strName = txtName.Text.Trim(); string strCID = ddlCategory.SelectedValue; string strCPrice = txtCPrice.Text.Trim(); string strFPrice = txtFPrice.Text.Trim(); string strNPrice = txtNPrice.Text.Trim(); string strBewrite = txtBewrite.Text.Trim(); string strUseMode = txtUseMode.Text.Trim(); string strValidity = txtValidity.Text.Trim(); if (strName == String.Empty || strCPrice == String.Empty || strCID == String.Empty || strFPrice == String.Empty || strNPrice == String.Empty) { Response.Write("<script>"); Response.Write("alert('必选项不能为空!!!');"); Response.Write("</script>"); return; } else if (strName.Length > 35) { Response.Write("<script>"); Response.Write("alert('输入鲜花名称太长了!!!');"); Response.Write("</script>"); return; } try { double.Parse(strCPrice); } catch { Response.Write("<script>"); Response.Write("alert('请检查 成本价 的格式!!!');"); Response.Write("</script>"); return; } try { double.Parse(strFPrice); } catch { Response.Write("<script>"); Response.Write("alert('请检查 原价 的格式!!!');"); Response.Write("</script>"); return; } try { double.Parse(strNPrice); } catch { Response.Write("<script>"); Response.Write("alert('请检查 现价 的格式!!!');"); Response.Write("</script>"); return; } if (uploadFile.PostedFile.FileName.Trim() != String.Empty && (Path.GetExtension(uploadFile.PostedFile.FileName) != ".gif" && Path.GetExtension(uploadFile.PostedFile.FileName) != ".jpg")) { Response.Write("<Script>alert('上传的图片格式必须为.gif或.jpg!!')</Script>"); return; } strBewrite = CleanString.htmlInputText(strBewrite); strUseMode = CleanString.htmlInputText(strUseMode); strValidity = CleanString.htmlInputText(strValidity); string sql = "insert into Products(PName,CID,PCPrice,PFPrice,PNPrice,PBewrite,PUseMode,PValidity) values('" + strName + "'," + strCID + "," + strCPrice + "," + strFPrice + "," + strNPrice + ",'" + strBewrite + "','" + strUseMode + "','" + strValidity + "')"; DBConn myDB = new DBConn(); myDB.ExecuteNonQuery(sql); myDB.Close(); if (uploadFile.PostedFile.FileName.Trim() != String.Empty) { Stream imagedatastream; string DBPath = ConfigurationManager.AppSettings["DataBasePath"]; string connStr = (DBPath); SqlConnection myConn = new SqlConnection(connStr); imagedatastream = Request.Files["uploadFile"].InputStream; int imagedatalen = Request.Files["uploadFile"].ContentLength; string imagedatatype = Request.Files["uploadFile"].ContentType; byte[] image = new byte[imagedatalen]; imagedatastream.Read(image, 0, imagedatalen); String Psql = "update Products set PPicture=@imgdata where PID=(select MAX(PID) from products)"; SqlCommand Pcommand = new SqlCommand(Psql, myConn); SqlParameter imgdata = new SqlParameter("@imgdata", SqlDbType.Image); imgdata.Value = image; Pcommand.Parameters.Add(imgdata); myConn.Open(); Pcommand.ExecuteNonQuery(); myConn.Close(); } txtName.Text = ""; txtCPrice.Text = ""; txtFPrice.Text = ""; txtNPrice.Text = ""; txtBewrite.Text = ""; txtUseMode.Text = ""; txtValidity.Text = ""; ddlCategory.SelectedIndex = 0; Response.Write("<script>"); Response.Write("alert('成功添加!!!');"); Response.Write("</script>"); }