Image uploaded database section (automatically generated)
Www.chinacs.net 2002-2-15 Chinese C # Technology Station
Public Int FepicDataSet (String String String String String String StrPicintro, String Strthumbnail, int OPID)
{
// string strPicTitle, // string strPicDate, // string strPicName, // int intPicType, // string strPicIntro, // string strPicName, // string strThumbnail, // int opIDSqlConnection myConnection = new SqlConnection (ConfigurationSettings.AppSettings [ "ConnectionString "]); Sqlcommand mycommand = new sqlcommand (" MAG_FEPICDATASET ", MyConnection); // Mark the command as a sprocmycommand.commandtype = commandType.StoredProcedure;
// add parameters to sprocsqlparameter parameterUserid = New SqlParameter ("@ OPID", SqldbType.InT); parameterUserId.value = OPID; mycommand.parameters.add (parameterUserid);
SQLParameter ParameterPictitle = New SqlParameter ("@ pictitle", sqldbtype.char, 30); parameterPictitle.Value = strpictitle; mycommand.parameters.add (parameterPictitle);
Sqlparameter parameterpicdate = new sqlparameter ("@ picdate", sqldbtype.char, 10); parameterpicdate.value = strpicdate; mycommand.parameters.add (parameterpicdate);
Sqlparameter parameterpicname = new sqlparameter ("@ picname", sqldbtype.char, 50); parameterpicName.Value = strpicname; mycommand.Parameters.add (parameterpicname);
Sqlparameter parameterpictype = new sqlparameter ("@ Pictype", sqldbtype.int); parameterPictype.Value = intPictype; mycommand.Parameters.add (parameterpictype);
SqlParameter parameterPicIntro = new SqlParameter ( "@ picIntro", SqlDbType.Char, 255); parameterPicIntro.Value = strPicIntro; myCommand.Parameters.Add (parameterPicIntro); SqlParameter parameterThumbnail = new SqlParameter ( "@ thumbnail", SqlDbType.Char, 50) Parameterthumbnail.value = strand.Parameters.Add (parameterthumbnail);
SqlParameter parameterHostAddress = new SqlParameter ( "@ opIP", SqlDbType.Char, 15); parameterHostAddress.Value = Context.Request.UserHostAddress; myCommand.Parameters.Add (parameterHostAddress);
// SqlParameter parameterRID = new SqlParameter ( "@ returnID", SqlDbType.Int); // parameterReturnUserID.Value = -1; // parameterRID.Direction = ParameterDirection.Output; // myCommand.Parameters.Add (parameterRID);
// Execute the command in a try / catch to catch duplicate username errorstry {// open the connection and execute the commandmyConnection.Open (); mycommand.executenon query ();} catch {
// failed to create a new userreturn -1;} finally {
// Close the connectionif (myConnection.State == ConnectionsState.Open) myconnection.close ();}
Return 1;
}
Image uploaded codeBehind (自动 自动)
Www.chinacs.net 2002-2-15 Chinese C # Technology Station
Using system;
Using system.collections;
Using system.componentmodel;
Using system.configuration;
Using system.data;
Using system.drawing;
Using system.Web;
Using system.Web.SessionState;
Using system.Web.ui;
Using system.Web.ui.webcontrols;
Using system.Web.ui.htmlcontrols;
Using system.text;
Using cj168.util;
Namespace CJ168.Web.mag.admins.Fedata {///
IF (! page.ispostback) {bind2dropdownlistPictype ();
// for (int i = 0; i } public void Bind2DropDownListPicType () {cj168.DataAccess.Admins admins = new cj168.DataAccess.Admins (); DataSet ds = admins.FePicTypeGet (); // ddlPicType.DataSource =; DataView dv = new DataView (ds.Tables [ "PicType "]); DATAROWVIEW DRV = DV.AddNew (); // DatacolumnView DCV = DV.AddNew (); DRV [" Title "] =" Please select "; DRV [" fepictypeid "=" 0 "; drv.endedit (); Dv.Sort = "fepictypeid"; DDLPICTYPE.DASOURCE = DV; DDLPICTYPE.DATABIND (); Public void UploadFile (Object Sender, System.EventArgs E) { string imgNameOnly, imgNameNoExt, imgExt; string imgThumbnail; int erroNumber = 0; System.Drawing.Image oriImg, newImg; string strFePicSavePath = ConfigurationSettings.AppSettings [ "FePicSavePath"] ToString ();. string strFePicThumbFormat = ConfigurationSettings.AppSettings [ "FePicThumbFormat" .] .ToString () ToLower (); int intFeThumbWidth = Int32.Parse (ConfigurationSettings.AppSettings [ "FePicThumbWidth"]); string fileExt; string strPicTitle = txtboxPicTitle.Text; string strPicIntro = txtboxPicIntro.Text; string strPicDate = txtboxPicDate.Text ; int intPicType = Int32.Parse (ddlPicType.SelectedItem.Value); string strPicType = intPicType.ToString () "_" DateTime.Now.Date.ToShortDateString () "_"; string strFePicWebPath = ConfigurationSettings.AppSettings [ "FePicWebPath "]; CJ168.DataAccess.admins admins = new cj168.dataaccess.admins (); //if(admins.Fepictypesett (TEXTBOXTILE.TEXT, 0) <0) // lbladdpicinfo.text = "Operation failed: There is already the same name type, please modify"; // else // lbladdpicinfo.text = "successful" ; Stringbuilder Picinfo = New StringBuilder (); IF (page.isvalid) { For (int i = 0; i } IF (Erronumber> 0) {picinfo.append (" all the operations are not completed, please modify the error, then perform font> Hlkoripic.imageurl = ""; hlkoripic.tooltip = ""; hlknewpic.imageURL = "; hlknewpic.tooltip =";} else {for (int i = 0; i HttpPostedFile PostedFile = Request.Files [i]; imgNameOnly = strPicType System.IO.Path.GetFileName (PostedFile.FileName); imgNameNoExt = System.IO.Path.GetFileNameWithoutExtension (PostedFile.FileName); imgExt = System.IO.Path. GetExtension (postedfile.filename) .tostring (). TOLOWER (); oriImg = System.Drawing.Image.FromStream (PostedFile.InputStream); newImg = oriImg.GetThumbnailImage (intFeThumbWidth, intFeThumbWidth * oriImg.Height / oriImg.Width, null, new System.IntPtr (0)); switch (imgExt) {/ / case ".jpeg": case ".jpg": oriImg.Save (strFePicSavePath imgNameOnly, System.Drawing.Imaging.ImageFormat.Jpeg); break; case ".gif": oriImg.Save (strFePicSavePath imgNameOnly, System. Drawing.Imaging.ImageFormat.Gif); break; case ".png": oriImg.Save (strFePicSavePath imgNameOnly, System.Drawing.Imaging.ImageFormat.Png); break;} // oriImg.Save (ConfigurationSettings.AppSettings [ " FepicsavePath "] IMGNAMENOEXT " .jpg ", System.drawing.Imaging.ImageFormat.jpeg); switch (strFePicThumbFormat) {// jpeg format can get the smallest file size, and the png is the largest size // case "jpeg": case "jpg": newImg.Save (strFePicSavePath imgNameOnly "_thumb.jpg", System .Drawing.Imaging.ImageFormat.Jpeg); imgThumbnail = imgNameOnly "_thumb.jpg"; break; case "gif": newImg.Save (strFePicSavePath imgNameOnly "_thumb.gif", System.Drawing.Imaging.ImageFormat.Gif ); imgThumbnail = imgNameOnly "_thumb.gif"; break; case "png": newImg.Save (strFePicSavePath imgNameOnly "_thumb.png", System.Drawing.Imaging.ImageFormat.Png); imgThumbnail = imgNameOnly "_thumb .png "; break; default: newImg.Save (strFePicSavePath imgNameOnly " _thumb.jpg ", System.Drawing.Imaging.ImageFormat.Jpeg); imgThumbnail = imgNameOnly " _thumb.jpg "; break; } // switch Picinfo.append (" file name: b>" ImgnameOnly "(" Oriimg.Width ")" PostedFile.ContentLength / 1024 "KB Oriimg.dispose (); newimg.dispose (); picinfo.append (" image upload success font> } // for picinfo.append (" all operations" "" ""); } // if erronumber = 0 } else {picinfo.append (" has an error, please check. Operation is not successful font> Hlkoripic.imageurl = ""; hlkoripic.tooltip = ""; hlknewpic.imageURL = ""; hlknewpic.tooltip = " } For (int i = 0; i } Public void caldateselected (object sender, system.eventargs e) {txtboxpicdate.text = CalpicDate.selectedDate.toshortdateString (); } public void ServerValidateCheckDate (object sender, System.Web.UI.WebControls.ServerValidateEventArgs value) {cj168.util.iUtil iUtils = new cj168.util.iUtil (); if (! iUtils.IsDate (value.Value)) value.IsValid = false; elsevalue.issalid = true; } #Region Web Form Designer Generated CodeOverride Protected Void OnNit (Eventargs E) {//// Codegen: This Call is Required by The ASP.NET Web Form Designer./initializationComponent ();Base.onInit (E); /// } #endregion}}} Image uploaded WebForm (自动 自动) Www.chinacs.net 2002-2-15 Chinese C # Technology Station <% @ Page language = "c #" codebehind = "feuploadpic.aspx.cs" autoeventwireup = "false" inherits = "cj168.web.mag.admins.Fedata.FeuploadPic"%> <% @ Register tagprefix = "cj168" tagname = "header" src = "Modules / Headerfe.ascx"%>
");}}}} else {erronumber = erronumber 1; if (fileext == "") Picinfo.append (" error: b> Please select file
"); elsePicinfo.append (" error: b> file (" (i 1) ")" IMGNAMEONLY "extension" fileext "Not licensed
");
");
"); picInfo.Append (" thumbnail name: b> " imgThumbnail " ( " newImg.Width " x " newImg.Height ")
"); HLKORIPIC.IMAGEURL = STRFEPICWEBPATH IMGNAMEOMEONLY : " PostedFile.ContentLength / 1024 " KB "; hlkNewPic.ImageUrl = strFePicWebPath imgThumbnail; hlkNewPic.ToolTip =" ◆ thumbnail ◆ / n filename: " imgThumbnail " / n size: " newImg.Width "x" newimg.height;
"); if (Admins.FepicDataSet (StrPictitle, Strpicdate, ImgnameOnly, IntPictype, Strpicintro, imgthumbnail, 0) <0) Picinfo.append (" save information to database failed font>
"); ElsePicinfo.append (" saving information to database Success font>
");
);