其他分享
首页 > 其他分享> > 机房重构之学生端显示个人信息

机房重构之学生端显示个人信息

作者:互联网

先来张效果图:
在这里插入图片描述
这样的效果是用lblbox显示出从表中读取到的信息,并且随窗体加载出来,效果比较简洁美观。当实现这个功能之后,还觉得少点什么。这时候想到了腾讯QQ,QQ号就好比卡号,是不可变的固定值,当然变也不现实,维护成本太高。而昵称(用户名)是可变的,因此我也给它加了一个修改用户名的功能
U层代码:

private void MineForm_Load(object sender, EventArgs e)
        {
            StudentInfo student = new StudentInfo();
            Facade.MainFormFacade mineFacade = new Facade.MainFormFacade();
            //student.UserName = LoginUser.UserID;
            student.CardNo= LoginUser.UserID;
            DataTable table = mineFacade.SelectMain(student);
            lblCardNo.Text = table.Rows[0][1].ToString();
            textBox2.Text = table.Rows[0][0].ToString();
            lblCash.Text = table.Rows[0][6].ToString();
            lblType.Text=table.Rows[0][8].ToString();
            lblDate.Text = table.Rows[0][9].ToString();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Facade.MainFormFacade Facade = new Facade.MainFormFacade();
            Entity.StudentInfo user = new Entity.StudentInfo();
            user.UserName = textBox2.Text;
            user.CardNo = lblCardNo.Text;
            Boolean result = false;
            result = Convert.ToBoolean(Facade.UpdateUserName(user));
            if (result != false)
            {
                MessageBox.Show("用户名修改成功");
            }
        }

D层代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//引用空间
using System.Data;
using System.Data.SqlClient;
using IDAL;
using Entity;

namespace DAL
{
    public class MainFormDAL: IDAL.MainFormIDAL
    {
        //实例化一个SQHelp层,用于连接数据库进行查询。
        SQLHelper sqlHelper = new SQLHelper();
        /// <summary>
        /// 查询管理者信息
        /// </summary>
        /// <param name="">管理者信息实体</param>
        /// <returns>整个管理者信息实体</returns>
        public DataTable SelectMain(Entity.StudentInfo student)
        {
            //定义查询参数
            SqlParameter[] sqlapms = { new SqlParameter("@CardNo", student.CardNo) };
            //定义SQL语句
            string sql = @"select * from [Student] where CardNo=@CardNo";
            //接受查询结果
            DataTable table = sqlHelper.ExecuteQuery(sql, sqlapms, CommandType.Text);
            return table;//返回查询结果
        }
        public int UpdateUserName(StudentInfo username)
        {
            SqlParameter[] sqlparams = {new SqlParameter("@CardNo", username.CardNo), new SqlParameter("@UserName", username.UserName) };
            string sql = "UPDATE [Student] SET UserName = @UserName WHERE CardNo =@CardNo";
            int result = sqlHelper.ExecuteNonQuery(sql, sqlparams, CommandType.Text);
            return result;//返回受影响行数
        }
    }
}

标签:重构,CardNo,个人信息,System,new,机房,Text,using,table
来源: https://blog.csdn.net/qq_44685392/article/details/119281184