⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 update_photo.aspx.cs

📁 一个供大家参考的自己做的计算机等级考试网上系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
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.IO;
namespace djks.admin
{
	/// <summary>
	/// update_photo 的摘要说明。
	/// </summary>
	public class update_photo : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.HtmlControls.HtmlInputFile photo;
		protected System.Web.UI.WebControls.Image Image2;
		private static string bmh,havexp;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!this.IsPostBack)
			{
				if(Request.QueryString["bmh"]!=null&&Request.QueryString["havexp"]!=null)
				{
					bmh=Request.QueryString["bmh"].ToString();
					havexp=Request.QueryString["havexp"].ToString();
					if(havexp=="1")
					{
						this.Image2.ImageUrl="../photo/"+bmh+".jpg";
					}
					else
					{
						this.Image2.ImageUrl="../images/nopho.jpg";
					}
				}
				else
				{
					hxyy_js.jsAlert("参数在传输中出错,请重新打开!");
				}
			}

		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button2_Click(object sender, System.EventArgs e)
		{
			Random rd=new Random();
			string photoname=bmh+".jpg";			
			try
			{
				if(this.photo.PostedFile.ContentLength.ToString()=="")
				{
					hxyy_js.jsAlert("上传的文件不存在");
				}
				else
				{
					

					if(File.Exists(Server.MapPath("photo/")+bmh+".jpg"))    //判断是否存在与新报名号相同的照片,若存在则删除
					{
						File.Delete(Server.MapPath("photo/")+bmh+".jpg");
					}

					string ext=Path.GetExtension(photo.PostedFile.FileName);
					if(ext==".jpg"||ext==".JPG")
					{	
						
						photo.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("../photo/")+photoname);
				      
						this.Image2.ImageUrl="../photo/"+photoname+"?"+rd.Next(100).ToString();					
						if(havexp=="0")
						{
							string strSql="update bmk set HAVEXP=1 where BMH='"+bmh+"'";
							database.doSql(strSql);
							havexp="1";
						}
						 hxyy_js.jsAlert("上传成功!");
					}
					else
					{
						hxyy_js.jsAlert("上传文件应为(.jpg)格式,请重新上传");
					}
				}
			}
			catch
			{
				hxyy_js.jsAlert("图片上传中出错。为保证你的信息无误,请到相关部门查证!");
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -