• 基于C#开发web网页管理系统模板流程-主界面密码维护功能完善


     点击返回目录->

    基于C#开发web网页管理系统模板流程-总集篇-CSDN博客


    前言

    紧接上篇->基于C#开发web网页管理系统模板流程-主界面统计功能完善-CSDN博客

    一个合格的管理系统,至少一定存在一个功能——用户能够自己修改密码,理论上来说密码只能有用户自己一个人知道,就算是数据库中存储的密码记录,在实际开发应用中也应是严格加密后的密文(即开发人员也无法查看用户的密码)

    本篇就来实现用户修改密码的功能,其实现本质其实很简单:接收用户输入的新密码->判断新密码合法性->使用update语句更新数据库中的密码记录


    一,新建wh(维护的拼音)文件夹

    希望你养成这个好习惯,将不同功能的脚本分门别类的放在不同的文件夹中

    创建一个【包含母版页的Web窗体】,将其命名为mmwh.aspx(密码维护)

    点击添加后再弹出的【选择母版页】窗口中选择唯一一个母版页Site.Master


    二,添加控件并配置控件

    密码维护的界面算得上是十分简单的了,两种很熟悉的控件,而且不需要做什么设置


    三,控件脚本

    打开【mmwh.aspx.cs】文件,将下面的代码复制到该文件中,即可实现所有控件的功能,实现思路见代码注释!

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Web;
    5. using System.Web.UI;
    6. using System.Web.UI.WebControls;
    7. using System.Data.Odbc; //ODBC命名空间
    8. namespace ckgl.admin.wh
    9. {
    10. public partial class mmwh : System.Web.UI.Page
    11. {
    12. protected void Page_Load(object sender, EventArgs e)
    13. {
    14. }
    15. protected void Button1_Click(object sender, EventArgs e)
    16. {
    17. if(TextBox1.Text==""||TextBox2.Text=="")
    18. {
    19. Response.Write("");
    20. return;
    21. }
    22. if (TextBox3.Text == "" || TextBox4.Text == "")
    23. {
    24. Response.Write("");
    25. return;
    26. }
    27. if (TextBox3.Text != TextBox4.Text )
    28. {
    29. Response.Write("");
    30. return;
    31. }
    32. OdbcConnection con = DB.Lianjie();
    33. con.Open();
    34. string sql1 = "select * from glyb where gno='" + TextBox1.Text + "' and gpass='" + TextBox2.Text + "' ";
    35. OdbcCommand mycommand1 = new OdbcCommand(sql1, con);
    36. OdbcDataReader sdr = mycommand1.ExecuteReader();
    37. if(sdr.Read())
    38. {
    39. string sql2 = " update glyb set gpass='" + TextBox3.Text + "' where gno='" + TextBox1.Text + "'";//根据用户输入的新密码修改密码
    40. OdbcCommand mycommand2 = new OdbcCommand(sql2, con);
    41. mycommand2.ExecuteNonQuery();
    42. Response.Write("");
    43. }
    44. else
    45. {
    46. Response.Write("");
    47. return;
    48. }
    49. con.Close();
    50. }
    51. protected void Button2_Click(object sender, EventArgs e)
    52. {
    53. TextBox1.Text = "";
    54. TextBox2.Text = "";
    55. TextBox3.Text = "";
    56. TextBox4.Text = "";
    57. }
    58. }
    59. }


    四,添加菜单

    在母版页【Site.Master】中添加相应的修改密码菜单,这一步博主偷懒一下罢~你一定会的!

  • 相关阅读:
    垂直分表为什么能够加快查询效率?
    像你这么优秀的测试工程师,怎么就约不到面试呢?
    单例模式的介绍和五种写法
    AlphaCode:程序员的另类“内卷”?
    还在为sql注入眼花缭乱的过滤而烦恼?一文教您快速找出所有过滤内容
    LQ0143 砍竹子【序列处理】
    第28篇 Spring Boot简介
    Oracle OCM考试(史上最详细的介绍,需要19c OCP的证书)
    为Linux初学者答疑解惑
    用于标记蛋白质和抗体的Biotin-LC-Sulfo-NHS|CAS:191671-46-2
  • 原文地址:https://blog.csdn.net/liKeQing1027520/article/details/139634582