您目前尚未登陆,请选择【登陆】或【注册
首页->功能源码->简单的XML学生信息系统(注释清楚)>>reg.aspx.cs>>代码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:简单的XML学生信息系统(注释清楚)


当前文件路径:XmlStudentSys/reg.aspx.cs 文件类型
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.IO; 12using System.Xml; 13//该源码下载自www.51aspx.com(51aspx.com) 14 15using xmlOp;//引用自定义命名空间 16 17public partial class reg : System.Web.UI.Page 18{ 19 string xmlFile = ""; 20 protected void Page_Load(object sender, EventArgs e) 21 { 22 xmlFile = Request.PhysicalApplicationPath + @"\xml\students.xml";//配置文件的Xml文件路径 23 if (!IsPostBack) 24 { 25 XmlOp op = new XmlOp(xmlFile); //创建XmlOp类对象 26 if (op.NodeCount("//Root") == 0) //如果一个同学成员都没有,则取消姓名验证 27 this.CustomValidator1.Enabled = false; 28 } 29 } 30 //提交按钮事件 31 protected void bt1_Click(object sender, EventArgs e) 32 { 33 if (IsValid)//如果通过所有验证 34 { 35 string _username = tbusername.Text.Trim(); 36 string _pwd = tbpassword1.Text.Trim(); 37 string _sex = rdboy.Checked ? rdboy.Text : rbgirl.Text;//判断性别 38 string _email = tbemail.Text.Trim(); 39 string _dept = tbdept.Text.Trim(); 40 string _class = tbclass.Text.Trim(); 41 string _birthday = tbbirthday.Text.Trim(); 42 string _addrees = tbaddrees.Text.Trim(); 43 string _postcode = tbpostcode.Text.Trim(); 44 string _telephone = tbtelephone.Text.Trim(); 45 string _stuid = tbstuid.Text.Trim(); 46 string _sub = tbsub.Text.Trim(); 47 string _photo = ""; 48 string _time = DateTime.Now.ToString(); 49 50 //上传图片 51 string _file = this.FileUpload1.FileName.ToString().ToLower(); 52 if (_file != "") 53 { 54 string _fileType = this.FileUpload1.PostedFile.ContentType; 55 if (_fileType.Substring(0, 5) == "image") //判断是否图片文件 56 { 57 _photo = "images/" + _username + _file.Substring(_file.LastIndexOf(".")); 58 this.FileUpload1.SaveAs(Server.MapPath(_photo)); //保存图片 59 } 60 else 61 { 62 Msg("对不起!图片格式不对!"); 63 return; 64 } 65 } 66 //定义节点数组 67 string[] stu ={"Name", "Pwd", "Sex", "Email", "Dept", "Class", "Birthday", "Address", 68 "Postcode", "Tel", "Stuid", "Sub", "Photo","Time"}; 69 //定义节点值数组 70 string[] stuinfo ={_username, _pwd, _sex, _email, _dept, _class, _birthday, _addrees, 71 _postcode, _telephone, _stuid, _sub, _photo,_time }; 72 73 XmlOp op = new XmlOp(xmlFile); 74 //调用Xml操作类的InsertNode方法,插入新的同学成员记录 75 if (op.InsertNode("//Root", "Student", stu, stuinfo)) 76 { 77 op.InsertAttrib("//Root/Student[Name='" + _username + "']", "Admin", "no"); 78 op.Save(xmlFile); //保存Xml文档 79 Msg("恭喜,成功已注册!"); 80 ClearTextBox(); //清空所有文本框 81 } 82 } 83 } 84 //验证用户名是否存在 85 protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) 86 { 87 string _username = args.Value; 88 XmlOp op = new XmlOp(xmlFile); 89 if (op.SelectNode("//Root/Student", 0, _username)) //判断是否存在 90 args.IsValid = false; 91 else 92 args.IsValid = true; 93 } 94 //重置按钮事件 95 protected void bt2_Click(object sender, EventArgs e) 96 { 97 ClearTextBox();//调用清空文本框函数 98 } 99 //清空文本框 100 private void ClearTextBox() 101 { 102 tbusername.Text = ""; 103 tbpassword1.Text = ""; 104 tbpassword2.Text = ""; 105 tbemail.Text = ""; 106 tbdept.Text = ""; 107 tbclass.Text = ""; 108 tbbirthday.Text = ""; 109 tbaddrees.Text = ""; 110 tbpostcode.Text = ""; 111 tbtelephone.Text = ""; 112 tbstuid.Text = ""; 113 tbsub.Text = ""; 114 } 115 //弹出对话框 116 public void Msg(string msg) 117 { 118 Page pg = (Page)HttpContext.Current.Handler; 119 string script = "alert('" + msg + "');"; 120 pg.ClientScript.RegisterStartupScript(pg.GetType(), Guid.NewGuid().ToString(), script, true); 121 } 122} 123
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:简单的XML学生信息系统(注释清楚)

- Pizza在线订购系统源码

- AjaxPro入门实例之用户验证

- WebQuest发布系统源码及文档

- Shang Blog 1.1.0 Final免安..

- ASP.NET2.0支持多语言示例源码

- 简单文章管理系统

- 哈尔滨某大学教务系统平台源码

- 品杰电子商务购物平台系统源码

51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号