protected void submit_Click(object sender, EventArgs e) { danger(this.username.Text); danger(this.password.Text); danger(this.ensure.Text); danger(this.name.Text); danger(this.company.Text); danger(this.phone.Text); danger(this.email.Text); danger(this.idcard.Text); string gender1; if (this.male.Checked) { gender1 = "男"; } else { gender1 = "女"; } try { sendmailclass smm = new sendmailclass(); smm.sendmailfunction(this.email.Text, "您以此邮箱在科研项目管理系统中申请了用户,如要修改,请联系负责人!", "申请回执"); } catch { ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(\"请检查您输入的邮箱是否正确!\")</script>"); } finally { } string connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; SqlConnection conn = new SqlConnection(connStr); conn.Open(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT * FROM main where username = '******'"; SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { conn.Close(); conn.Dispose(); ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(\"您所申请的用户名已被占用!\")</script>"); } else { /* * 首先对图片进行上传,如果图片上传失败,将不会进行写入数据库等操作 */ dr.Close(); if (shangchuan.FileName != "" && (Path.GetExtension(shangchuan.FileName) == ".jpg" || (Path.GetExtension(shangchuan.FileName) == ".png" || Path.GetExtension(shangchuan.FileName) == ".JPG" || (Path.GetExtension(shangchuan.FileName) == ".PNG")))) //上传图片文件且文本框值不为空 { if (File.Exists(Server.MapPath("./") + "\\pictures\\" + this.username.Text + "13052425.jpg")) //如果文件已存在,则删除已有文件 { File.Delete(Server.MapPath("./") + "\\pictures\\" + this.username.Text + "13052425.jpg"); } shangchuan.SaveAs(Server.MapPath("./") + "\\pictures\\" + this.username.Text + "13052425.jpg"); //将文件保存到服务器中 suolue sl = new suolue(); //进行类的实例化 string s1 = Server.MapPath("./") + "\\pictures\\" + this.username.Text + "13052425.jpg"; string s2 = Server.MapPath("./") + "\\pictures\\" + this.username.Text + ".jpg"; int s3 = 150; int s4 = 150; string s5 = "any"; sl.MakeThumbnail(s1, s2, s3, s4, s5); //调用函数进行缩略图的生成和保存 File.Delete(Server.MapPath("./") + "\\pictures\\" + this.username.Text + "13052425.jpg"); HashMethod hm = new HashMethod(); string command; command = "INSERT INTO main VALUES('" + this.username.Text + "','" + hm.Encrypto(this.password.Text) + "','" + this.name.Text + "','" + gender1 + "','" + this.company.Text + "','" + this.phone.Text + "','" + this.email.Text + "','" + this.idcard.Text + "')"; SqlCommand cmd1 = new SqlCommand(); cmd1.Connection = conn; cmd1.CommandText = command; int i = 1; i = cmd1.ExecuteNonQuery(); if (i > 0) { conn.Close(); conn.Dispose(); Session["yonghuming"] = this.username.Text; Session["xingming"] = this.name.Text; Session["emaildizhi"] = this.email.Text; Session["gongsi"] = this.company.Text; Session["xingbie"] = gender1; Session["shenfenzhenghao"] = this.idcard.Text; Response.Redirect("ui.aspx"); } else { conn.Close(); conn.Dispose(); ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(\"申请过程出现错误,请重试!\")</script>"); } } else { ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(\"图片格式不支持!\")</script>"); } } } catch { conn.Close(); conn.Dispose(); ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(\"您输入的内容不合法,请检查后重试!\")</script>"); } finally { conn.Close(); conn.Dispose(); } }
protected void submit_Click(object sender, EventArgs e) { danger(this.yuan.Text); danger(this.password.Text); danger(this.ensure.Text); danger(this.company.Text); danger(this.phone.Text); danger(this.name.Text); string connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; SqlConnection conn = new SqlConnection(connStr); conn.Open(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT password FROM main WHERE username = '******'"; SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); HashMethod hm = new HashMethod(); if (hm.Encrypto(this.yuan.Text) == dr[0].ToString().Trim()) { dr.Close(); /* * 以下为添加代码 */ string gender1; if (this.male.Checked) { gender1 = "男"; } else { gender1 = "女"; } /* * 图片一栏是否为空,如果为空则直接跳过该步骤 */ if (this.shangchuan.FileName != "") { /* * 首先对图片进行上传,如果图片上传失败,将不会进行写入数据库等操作 */ if (Path.GetExtension(shangchuan.FileName) == ".jpg") //上传图片文件且文本框值不为空 { if (File.Exists(Server.MapPath("/") + "\\pictures\\" + this.username.Text + "13052425.jpg")) //如果文件已存在,则删除已有文件 { File.Delete(Server.MapPath("/") + "\\pictures\\" + this.username.Text + "13052425.jpg"); } if (File.Exists(Server.MapPath("/") + "\\pictures\\" + this.username.Text + ".jpg")) //如果文件已存在,则删除已有文件 { File.Delete(Server.MapPath("/") + "\\pictures\\" + this.username.Text + ".jpg"); } shangchuan.SaveAs(Server.MapPath("/") + "\\pictures\\" + this.username.Text + "13052425.jpg"); //将文件保存到服务器中 suolue sl = new suolue(); //进行类的实例化 string s1 = Server.MapPath("/") + "\\pictures\\" + this.username.Text + "13052425.jpg"; string s2 = Server.MapPath("/") + "\\pictures\\" + this.username.Text + ".jpg"; int s3 = 170; int s4 = 170; string s5 = "any"; sl.MakeThumbnail(s1, s2, s3, s4, s5); //调用函数进行缩略图的生成和保存 File.Delete(Server.MapPath("/") + "\\pictures\\" + this.username.Text + "13052425.jpg"); } } string command; command = "UPDATE main SET username='******', password='******',name='" + this.name.Text + "',gender='" + gender1 + "',company='" + this.company.Text + "',phone='" + this.phone.Text + "',email='" + this.email.Text + "',idcard='" + this.idcard.Text + "' WHERE username='******'"; cmd.CommandText = command; int i; i = cmd.ExecuteNonQuery(); if (i > 0) { Session["yonghuming"] = this.username.Text; Session["xingming"] = this.name.Text; Session["emaildizhi"] = this.email.Text; Session["gongsi"] = this.company.Text; Session["xingbie"] = gender1; dr.Close(); conn.Close(); conn.Dispose(); } else { dr.Close(); conn.Close(); conn.Dispose(); ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(\"申请过程出现错误,请重试!\")</script>"); } sendmailclass smm = new sendmailclass(); smm.sendmailfunction(this.email.Text, "您在科研项目管理系统中的资料已修改成功!", "申请回执"); Response.Redirect("../ui.aspx"); } else { conn.Close(); conn.Dispose(); ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(\"请输入正确的原密码!\")</script>"); } } catch (Exception ex) { conn.Close(); conn.Dispose(); Response.Write("<script>alert(\"" + ex.Message + "\")</script>"); //Response.Redirect("../error.aspx"); } finally { conn.Close(); conn.Dispose(); } }