⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 管理模块_帐户管理.aspx.cs

📁 学生管理系统 功能不是很强大 但是很实用
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
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;

public partial class _Default : System.Web.UI.Page
{
    public string CID;
    public string sqlconn;
    DataRow dtr;
    SqlDataAdapter myadapter;
    SqlCommandBuilder scb;
    DataSet myDataSet;
    SqlConnection mysqlconnection;
    int returnValue;
    protected void Page_Load(object sender, EventArgs e)
    {
        CID = Session["name"].ToString();
        sqlconn = "data source=.;database=学生成绩智能管理系统;user id=sa;password=sa;";
        mysqlconnection = new SqlConnection(sqlconn);
        SqlCommand mysqlcommand = mysqlconnection.CreateCommand();
        mysqlcommand.CommandText = "select 用户名,密码,备注 from 用户表 where 用户名=" + "'" + CID + "'";
        myadapter = new SqlDataAdapter();
        myadapter.SelectCommand = mysqlcommand;
        myDataSet = new DataSet();
        mysqlconnection.Open();
        int numberOfRow = myadapter.Fill(myDataSet, "用户表");
        mysqlconnection.Close();
        DataTable tb = myDataSet.Tables["用户表"];
        dtr = tb.Rows[0];
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.ReadOnly = false;
        TextBox4.Visible = true;
        TextBox4.ReadOnly = false;
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox2.ReadOnly = false;
        TextBox3.Text = "请记住新的密码以免造成不必要的麻烦!";
        Label1.Text = "原始密码";
        Label2.Text = "新密码";
        Label3.Text = "小提示";
        Label4.Visible = true;
        Button4.Visible = true;
        Button5.Visible = true;
        Button5.Text = "取消";
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        SqlCommand coutsqlcommand = mysqlconnection.CreateCommand();
        mysqlconnection.Open();
        if (TextBox1.Text != "" && TextBox2.Text != "")
        {

            if (TextBox4.Visible == true)
            {
                coutsqlcommand.CommandText = "select count(*) as 数目 from 用户表 where 用户名=" + "'" + CID + "'" + " and 密码=" + "'" + Convert.ToString(TextBox1.Text) + "'";
                returnValue = (Int32)coutsqlcommand.ExecuteScalar();
                if (returnValue == 1)
                {
                    if (TextBox2.Text == TextBox4.Text)
                    {
                        Response.Write("<script>alert('密码修改成功!');</script>");
                        scb = new SqlCommandBuilder(myadapter);
                        myDataSet.Tables["用户表"].Rows[0]["密码"] = (String)(TextBox4.Text);
                        myadapter.Update(myDataSet.Tables["用户表"]);
                    }
                    else
                        Response.Write("<script>alert('密码重复确认错误!');</script>");
                }
                else
                    Response.Write("<script>alert('密码错误!');</script>");
            }
            else
                if (TextBox4.Visible != true)
                {
                    if (Label1.Text == "用户名")
                    {
                        myDataSet.Tables["用户表"].Rows[0]["备注"] = (String)(TextBox3.Text);
                        scb = new SqlCommandBuilder(myadapter);
                        myadapter.Update(myDataSet.Tables["用户表"]);
                        Response.Write("<script>alert('备注修改成功!');</script>");
                    }
                    if (Label1.Text == "新用户名")
                    {
                        coutsqlcommand.CommandText = "select count(*) as 数目 from 用户表 where 用户名=" + "'" + TextBox1.Text + "'";
                        returnValue = (int)coutsqlcommand.ExecuteScalar();
                        if (returnValue != 0)
                        {
                            Response.Write("<script>alert('用户名已存在!');</script>");
                        }
                        else
                        {
                            DataRow dbr = myDataSet.Tables["用户表"].NewRow();
                            dbr["用户名"] = (String)(TextBox1.Text);
                            dbr["密码"] = (String)(TextBox2.Text);
                            dbr["备注"] = (String)(TextBox3.Text);
                            myDataSet.Tables["用户表"].Rows.Add(dbr);
                            scb = new SqlCommandBuilder(myadapter);
                            myadapter.Update(myDataSet.Tables["用户表"]);
                            Response.Write("<script>alert('添加用户成功!');</script>");
                        }
                    }
                    if (Label1.Text == "删除用户")
                    {
                        coutsqlcommand.CommandText = "select count(*) as 数目 from 用户表 where 用户名=" + "'" + Convert.ToString(TextBox1.Text) + "'" + " and 密码=" + "'" + Convert.ToString(TextBox2.Text) + "'";
                        returnValue = (int)coutsqlcommand.ExecuteScalar();
                        if (returnValue == 1)
                        {
                            Response.Write("<script>alert('输入正确,可以删除');</script>");
                            Button5.Enabled = true;
                            Button4.Enabled = false;
                        }
                        else
                        {
                            Response.Write("<script>alert('密码或用户名错误!');</script>");
                            Button5.Enabled = false;
                        }
                    }
                }

        }
        else
            Response.Write("<script>alert('请完善信息!');</script>");
        mysqlconnection.Close();
    }
    protected void Button6_Click(object sender, EventArgs e)
    {
        TextBox1.Text = (String)(dtr["用户名"]);
        TextBox2.Text = "**********";
        TextBox3.Text = (String)(dtr["备注"]);
        Label1.Text = "用户名";
        Label2.Text = "密码";
        Label3.Text = "备注";
        Label4.Visible = false;
        TextBox4.Visible = false;
        Button4.Visible = false;
        Button5.Visible = false;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Button4.Visible = true;
        Button5.Visible = false;
        TextBox4.Visible = false;
        TextBox3.ReadOnly = false;
        Label1.Text = "用户名";
        Label2.Text = "密码";
        Label3.Text = "备注";
        Label4.Visible = false;
        TextBox1.Text = (String)(dtr["用户名"]);
        TextBox2.Text = "**********";
        TextBox3.Text = (String)(dtr["备注"]);
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Button4.Visible = true;
        Button5.Visible = false;
        Button4.Enabled = true;
        Button5.Enabled = true;
        TextBox4.Visible = false;
        TextBox1.ReadOnly = false;
        TextBox2.ReadOnly = false;
        TextBox3.ReadOnly = false;
        Label1.Text = "新用户名";
        Label2.Text = "密码";
        Label3.Text = "备注";
        Label4.Visible = false;
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
    }
    protected void Button7_Click(object sender, EventArgs e)
    {
        Label1.Text = "删除用户";
        Button4.Visible = true;
        Button5.Visible = true;
        Button5.Enabled = false;
        TextBox4.Visible = false;
        TextBox1.ReadOnly = false;
        TextBox2.ReadOnly = false;
        TextBox3.ReadOnly = true;
        Label2.Text = "密码";
        Label3.Text = "备注";
        Label4.Visible = false;
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        Button4.Text = "确定";
        Button5.Text = "提交删除";
        TextBox3.Text = "请输入要删除的用户名和密码!";
    }
    protected void Button5_Click1(object sender, EventArgs e)
    {
        if (Label1.Text == "删除用户")
        {
            SqlCommand coutsqlcommand = mysqlconnection.CreateCommand();
            mysqlconnection.Open();
            coutsqlcommand.CommandText = "delete  from 用户表 where 用户名=" + "'" + Convert.ToString(TextBox1.Text) + "'" + " and 密码=" + "'" + Convert.ToString(TextBox2.Text) + "'";
            returnValue = coutsqlcommand.ExecuteNonQuery();
            if (returnValue == 1)
            {
                Response.Write("<script>alert('删除成功');</script>");
            }
            else
            {
                Response.Write("<script>alert('未知错误!');</script>");
            }
            Button5.Enabled = false;
            Button4.Enabled = true;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -