usingSystem; usingSystemIO; usingSystemCollections; usingSystemComponentModel; usingSystemData; usingSystemDrawing; usingSystemDrawingImaging; usingSystemWeb; usingSystemWebSessionState; usingSystemWebUI; usingSystemWebUIWebControls; usingSystemWebUIHtmlControls; usingSystemDataSqlClient; usingKunslyNetDllCommon; usingHunMSMinclude; namespaceHunMSMphoto { /**////<summary> ///图片上传 ///</summary> publicpartialclass_upphoto:SystemWebUIPage { publicstringsPath=; publicstringextension; publicstringpath; publicstringfileName; publicstringsmobile; protectedvoidPage_Load(objectsenderSystemEventArgse) { //在此处放置用户代码以初始化页面 AddControl(); if(Session[UserMobile]==null) ResponseWrite(<scriptlanguage=javascript>alert(请先登录才允许上传图片);historyback()</script>); else smobile=Session[UserMobile]ToString()Trim(); if(!thisIsPostBack) { DropDownPhotoType(); DropDownPhotoColl(); } } voidAddControl()#regionvoidAddControl() /**////<summary> ///添加控件 ///</summary> privatevoidAddControl() { Controlctrl; sPath=KunslyWebPageGetRelativeRootPath(this); //头 ctrl=LoadControl(sPath+CtrlHeadascx); HolderHeadControlsAdd(ctrl); //左边框 ctrl=LoadControl(sPath+CtrlLeftascx); HolderLeftControlsAdd(ctrl); //底部 ctrl=LoadControl(sPath+CtrlBottomascx); HolderBottomControlsAdd(ctrl); } #endregion Web窗体设计器生成的代码#regionWeb窗体设计器生成的代码 overrideprotectedvoidOnInit(EventArgse) { // //CODEGEN:该调用是ASPNETWeb窗体设计器所必需的 // InitializeComponent(); baseOnInit(e); } /**////<summary> ///设计器支持所需的方法不要使用代码编辑器修改 ///此方法的内容 ///</summary> privatevoidInitializeComponent() { } #endregion protectedvoidButton_Click(objectsenderSystemEventArgse) { intncount=GetRecordCount(); if(ncount==) { KunslyWebPageShowMessage(this请先创建相册才允许上传图片); return; } //ResponseWrite(<scriptlanguage=javascript>alert(请先创建相册才允许上传图片);historyback()</script>); //else //{ if(UploadFilePostedFileFileNameTrim()==) { //ResponseWrite(<scriptlanguage=javascript>alert(老大没文件怎么传啊);historyback()</script>); KunslyWebPageShowMessage(this请选择文件); return; } //else //{ if(txtMessageTextTrim()==) { KunslyWebPageShowMessage(this请输入简介); return; } //ResponseWrite(<scriptlanguage=javascript>alert(老大请输入简介);historyback()</script>); extension=PathGetExtension(UploadFilePostedFileFileName)ToUpper(); if(extension!=JPG&&extension!=GIF) { KunslyWebPageShowMessage(this非法文件不允许上传只允许上传jpg或gif文件); return; } //ResponseWrite(<scriptlanguage=javascript>alert(非法文件不允许上传);historyback()</script>); if(UploadFilePostedFileContentLength>=)//大于M不允许上传 { KunslyWebPageShowMessage(this文件过大不能上传单个文件最大不超过M); return; } fileName=DateTimeNowToString(yyyyMMddhhmmss); path=ServerMapPath()+/upfile/+fileName+extension; updata(); } voidupdata()#regionvoidupdata() voidupdata() { //这个过程可以更新的数据库把图片地址插入到数据库 UploadFilePostedFileSaveAs(path); intwidthheightnewwidth=newheight; SystemDrawingImageimage; image=SystemDrawingImageFromFile(path); width=imageWidth; height=imageHeight; newheight=height*newwidth/width; Bitmapbm=newBitmap(imagenewwidthnewheight); bmSave(ServerMapPath()+/upfile/+fileName+_s+extensionImageFormatJpeg); image=SystemDrawingImageFromFile(path); LblShowPhotoText=照片已经成功上传文件名为+fileName+extension+占用空间; LblShowPhotoText+=UploadFilePostedFileContentLength/+k; stringstrtxtMessage=txtMessageText; strtxtMessage=strtxtMessageReplace('); strtxtMessage=strtxtMessageReplace("); strtxtMessage=strtxtMessageReplace( <br>); stringstrSql=insertintophotourl; strSql+=(PhotoUrlPhotoUrl_sPhotoWidthPhotoHeightPhotoSizePuttimePhotoIntro; strSql+=PhotoCollMobilePhotoColl); strSql+=values; strSql+=(+fileName+extension++fileName+_s+extension++imageWidth++imageHeight; strSql+=+UploadFilePostedFileContentLength+getdate()+strtxtMessage; strSql+=+DdlPhotoTypeSelectedValueToString()Trim()++smobile+; strSql+=DdlPhotoCollSelectedValueToString()Trim()+); SqlConnectiondbConn=DbConnectionGetSqlConn(); SqlCommanddbCmd=newSqlCommand(strSqldbConn); dbCmdExecuteNonQuery(); dbCmdDispose(); dbConnClose(); imageDispose(); bmDispose(); } #endregion voidDropDownPhotoType()#regionvoidDropDownPhotoType() voidDropDownPhotoType() { //这个过程是将照片类型绑定 stringstrSql=select*fromphotocolltype; SqlConnectiondbConn=DbConnectionGetSqlConn(); SqlCommanddbCmd=newSqlCommand(strSqldbConn); SqlDataReaderdbReader=dbCmdExecuteReader(); DdlPhotoTypeItemsClear(); while(dbReaderRead()) { DdlPhotoTypeItemsAdd(newListItem(dbReader[CollType]ToString()dbReader[PhotoID]ToString())); } dbReaderClose(); dbConnClose(); } #endregion voidDropDownPhotoColl()#regionvoidDropDownPhotoColl() voidDropDownPhotoColl() { //这个过程是将相册类型绑定 stringstrSql=select*fromPhotoCollwheremobile=++smobile+; SqlConnectiondbConn=DbConnectionGetSqlConn(); SqlCommanddbCmd=newSqlCommand(strSqldbConn); SqlDataReaderdbReader=dbCmdExecuteReader(); DdlPhotoCollItemsClear(); while(dbReaderRead()) { DdlPhotoCollItemsAdd(newListItem(dbReader[PhotoColl]ToString()dbReader[PhotoID]ToString())); } dbReaderClose(); dbConnClose(); } #endregion intGetRecordCount()#regionintGetRecordCount() /**////<summary> ///取得记录数 ///</summary> ///<returns></returns> privateintGetRecordCount() { stringstrSql=selectcount(*)astt; strSql+=fromphotocoll; strSql+=wheremobile=+smobile; SqlConnectiondbConn=DbConnectionGetSqlConn(); SqlCommanddbCmd=newSqlCommand(strSqldbConn); SqlDataReaderdbReader=dbCmdExecuteReader(); intnCount=; if(dbReaderRead()) nCount=ConvertToInt(dbReader[tt]); dbReaderClose(); dbConnClose(); returnnCount; } #endregion } } |