protected void Button1_Click(object sender, EventArgs e) { string studentNum = TextBox1.Text; string mobile = TextBox2.Text; string newPassword = TextBox3.Text; DataSet ds = OperaterBase.GetData("select * from studentInfo where studentNum='" + studentNum + "' and mobile='" + mobile + "'"); if (ds.Tables[0].Rows.Count == 0) { Label4.Text = "信息不对,请检查"; return; } string studentId = ds.Tables[0].Rows[0]["studentID"].ToString(); int num = OperaterBase.CommandBySql("update studentInfo set password='******' where studentID=" + studentId + ""); if (num > 0) { Label4.Text = "新密码设置成功,请登录"; Response.Redirect("login.aspx"); } else { Label4.Text = "程序异常"; } }
/// <summary> /// 点击按钮上传图片 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button2_Click(object sender, EventArgs e) { string filename = avatatUpload(); int ID = Convert.ToInt32(Request["studentID"]); if (Button1.CommandName == "Update") { OperaterBase.CommandBySql("update studentInfo set avatarUrl= '" + filename + "' where studentID=" + ID + ""); } }
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { int studentID = Convert.ToInt32(((HiddenField)e.Item.FindControl("hfStudentId")).Value); if (e.CommandName == "Delete") { string sql = "update studentInfo set IsDelete=1 where studentID=" + studentID + ""; int flag = OperaterBase.CommandBySql(sql); if (flag > 0) { Response.Write("<script type='text/javascript'>alert(成功删除:'" + flag + "'条数据);</script>"); repeaterGetData(); } } else if (e.CommandName == "Edit") { Response.Redirect("/WebForm2.aspx?studentID=" + studentID + ""); } }
protected void Button1_Click(object sender, EventArgs e) { string DropDownList1Text = DropDownList1.SelectedItem.Text; string DropDownList2Text = DropDownList2.SelectedItem.Text; string DropDownList3Text = DropDownList3.SelectedItem.Text; if (DropDownList1.SelectedValue == "0") { DropDownList1Text = ""; } if (DropDownList2.SelectedValue == "0") { DropDownList2Text = ""; } if (DropDownList3.SelectedValue == "0") { DropDownList3Text = ""; } int num = OperaterBase.CommandBySql("insert into S_Address values (newid(),'" + DropDownList1Text + "','" + DropDownList2Text + "','" + DropDownList3Text + "')"); }
/// <summary> /// 提交用户 /// </summary> private void AddUser() { int ID = Convert.ToInt32(Request["studentID"]); // .Trim()去掉空格 string v1 = TextBox1.Text.Trim(); string v2 = DropDownList1.SelectedValue; // string v2 = TextBox2.Text.Trim(); string v3 = TextBox3.Text.Trim(); string v4 = TextBox4.Text.Trim(); string v5 = TextBox5.Text.Trim(); string v6 = TextBox6.Text.Trim(); string v7 = TextBox7.Text.Trim(); string v8 = TextBox8.Text.Trim(); string v9 = TextBox9.Text.Trim(); string v10 = TextBox10.Text.Trim(); string v11 = TextBox11.Text.Trim(); if (Button1.CommandName == "Insert") { //string.IsNullOrEmpty(v1) // 为null或者空 条件为true if (string.IsNullOrEmpty(v1)) { Label1.Text = "用户名不能为空"; return; } DataSet isStudentRepeat = OperaterBase.GetData("select * from studentInfo where studentNum='" + v3 + "'"); if (isStudentRepeat.Tables[0].Rows.Count > 0) { Label3.Text = "学号已经注册过,不能重复添加"; return; } DataSet isMobileRepeat = OperaterBase.GetData("select * from studentInfo where mobile='" + v5 + "'"); if (isMobileRepeat.Tables[0].Rows.Count > 0) { Label2.Text = "手机号码已经注册过,不能重复添加"; return; } string sql = "insert into studentInfo (studentName,classID,studentNum,studentSex,mobile,password,birthday,province,city,district,address) values ('" + v1 + "','" + v2 + "','" + v3 + "','" + v4 + "','" + v5 + "','" + v6 + "'," + v7 + ",'" + v8 + "','" + v9 + "','" + v10 + "','" + v11 + "')"; int flag = OperaterBase.CommandBySql(sql); if (flag > 0) { // 跳转页面 Response.Redirect("WebForm1.aspx"); } } else if (Button1.CommandName == "Update") { // 校验用户规则 if (!UpdateUserRules(ID, v1, v3, v5)) { return; } string sql = "update studentInfo set studentName='" + v1 + "',classID='" + v2 + "',studentNum='" + v3 + "',studentSex='" + v4 + "',mobile='" + v5 + "',password='******',birthday='" + v7 + "',province='" + v8 + "',city='" + v9 + "',district='" + v10 + "',address='" + v11 + "' where studentID = " + ID + ""; int flag = OperaterBase.CommandBySql(sql); if (flag > 0) { // 跳转页面 Response.Redirect("WebForm1.aspx"); } } }