📄 index.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
//该源码下载自www.51aspx.com(51aspx.com)
public partial class _Default : System.Web.UI.Page
{
string name = "";
string bian = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ageBind();//绑定年龄
ViewState["imgurl"] = "";
}
}
protected void ageBind()
{
for (int i = 15; i < 35; i++)
{
this.lsbages.Items.Add(i.ToString());
}
}
protected void btnOK_Click(object sender, EventArgs e)
{//
name = this.txtname.Text;
string sex ="女";
if (this.rdosexm.Checked)
{
sex = "男";
}
else {
sex = "女";
}
int age = int.Parse(this.lsbages.Text);
string classes = this.txtClass.Text;
string phonenum = this.txtphone.Text;
//string photourl = this.FileUpphoto.FileName.ToString(); photourl,
string miaoshu = this.txtmiaoshu.Text;
if (addUser(name, sex, age, classes, phonenum, miaoshu))
{
this.lblbian.Text = this.getBiaoHao().ToString();
// Response.Write(" <script language='javascript' > alert('报名成功!');</script>");
this.lblmsg.Text = "报名成功!请您记住您的报名序号:" + this.lblbian.Text;
}
else {
//Response.Write(" <script language='javascript' > alert('报名失败!现在不能报名');</script>");
this.lblmsg.Text = "报名失败!现在不能报名,请于管理员联系";
}
}
protected Boolean addUser(string name,string sex,int age,string classes,string phen,string miaoshu)//string potourl,@poto,
{
Boolean flag = false;
string time = DateTime.Now.ToString();
String sqlstr = "insert into userinfo (uname,usex,uage,uclass,uphone,umiaoshu,uaddtime) values(@name,@sex,@age,@class,@phen,@miaoshu,@time)";
String urlsource = Server.MapPath("App_Data\\ZhuChiDB.mdb");
String constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + urlsource + ";User ID=admin";
try
{
OleDbConnection con = new OleDbConnection(constr);
con.Open();
OleDbCommand com = new OleDbCommand(sqlstr, con);
com.Parameters.AddWithValue("@name", name);
com.Parameters.AddWithValue("@sex", sex);
com.Parameters.AddWithValue("@age", age);
com.Parameters.AddWithValue("@class", classes);
com.Parameters.AddWithValue("@phen", phen);
//com.Parameters.AddWithValue("@poto", potourl);
com.Parameters.AddWithValue("@miaoshu", miaoshu);
com.Parameters.AddWithValue("@time", time);
int ors = com.ExecuteNonQuery();
if (ors > 0)
{
flag = true;
}
else
flag = false;
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return flag;
}
protected int getBiaoHao()
{
int nums = 0;
String sqlstr = "select top 1 uid from userinfo order by uid desc";
String urlsource = Server.MapPath("App_Data\\ZhuChiDB.mdb");
String constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + urlsource + ";User ID=admin";
try
{
OleDbConnection con = new OleDbConnection(constr);
con.Open();
OleDbCommand com = new OleDbCommand(sqlstr, con);
OleDbDataReader olr = com.ExecuteReader();
if (olr.Read())
{
nums = int.Parse(olr[0].ToString());
}
olr.Close();
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return nums;
}
protected void btnupload_Click(object sender, EventArgs e)
{
if (lblbian.Text == "这里显示报名序号")
{
this.lblmsg.Text = "你还没有报名,不能上传照片";
return;
}
if (this.FileUpphoto.HasFile)
{
string imgUrl = this.FileUpphoto.FileName.ToString();
ViewState["imgurl"] = imgUrl;//to save the url of the imgurl
int lastFix = imgUrl.LastIndexOf(".");
string imgType = imgUrl.Substring(lastFix+1,3).ToLower();
//Response.Write(imgType);
if (imgType != "jpg" && imgType != "png" && imgType != "gif")
{
this.lblmsg.Text = "您只能上传:JPG;PNG;GIF 格式的图片";
return;
}
string saveUrl = Server.MapPath("~/UploadImages/");
name = this.txtname.Text;//再次获取姓名,以便存放路径
//获取报名序号@"\"+
saveUrl += this.lblbian.Text+"." + imgType;
//Response.Write(saveUrl);
try
{
this.FileUpphoto.SaveAs(saveUrl);
//Response.Write(" <script language='javascript' > alert('恭喜您,上传成功了!');</script>");
this.lblmsg.Text = "恭喜您,上传成功,您已经完成了报名!";
this.images.ImageUrl = "~/UploadImages/" + this.lblbian.Text + "." + imgType;
}
catch (Exception ex)
{
Response.Write("系统可能遇到问题,请和管理员联系!sdfgfgu@126.com\\n" + ex.Message);
//
}
}
else
{
//Response.Write(" <script language='javascript' > alert('没有找到文件!');</script>");
this.lblmsg.Text = "没有找到文件!请选择图片路径";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -