任务2.3 系统登录界面的制作

2018-05-23  本文已影响0人  一条大大咸鱼

1.登录界面最终效果图

库管员登录失败
收银员登录失败
库管员登录成功
收银员登录成功

2.登录界面中涉及到的控件以及控件的重要属性,方法

控件 重要属性 方法
Lable Text 修改显示的文本
Button Text 修改显示的文本
TextBox MaxLength、MultiLine、PasswordChar、ReadOnly、ScrollBars 可输入最大字符数、是否可以多行显示、输入密码显示字符、是否为只读、是否显示滚动条
LinkLable Text 修改显示的文本
PictureBox Image、SizeMode 图片框中显示的图片、控制图片框显示图片的位置

3.登录界面版本更迭

4.重要代码片段

{
                        // 显示收银员主界面
                        MainFormUser formUser = new MainFormUser();
                        formUser.Show();
                        // 隐藏登录界面
                        this.Hide();
}
{
                    MessageBox.Show("商品信息修改成功");
                    this.Close();
}
//显示消息对话框
MessageBox.Show
(
   string text,  //要显示的文本
   string caption, //要显示的标题栏文本,可选
   MessageBoxButtons buttons, //要显示哪些按钮,可选
   MessageBoxIcon icon //要显示哪个图标,可选
)
            String connStr = ConfigurationManager.ConnectionStrings["SuperMarketSales"].ConnectionString;
            SqlConnection sqlConn = new SqlConnection(connStr);
            try
            {
                // 连接数据库
                sqlConn.Open();
            }   
                String sqlStr = "select * from EMPLOYEE where ID=@id and PASSWORD=@pwd";
                SqlCommand cmd = new SqlCommand(sqlStr, sqlConn);
                cmd.Parameters.Add(new SqlParameter("@id", this.tb_User.Text.Trim()));
                cmd.Parameters.Add(new SqlParameter("@pwd", this.tb_Password.Text.Trim()));
                SqlDataReader dr = cmd.ExecuteReader();
// 如果从数据库中查询到记录,则表示可以登录
                if (dr.HasRows)
                {
                    dr.Read();
                    UserInfo.userId = int.Parse(dr["ID"].ToString());
                    UserInfo.userName = dr["NAME"].ToString();
                    UserInfo.userPwd = dr["PASSWORD"].ToString();
                    UserInfo.userType = dr["TYPE"].ToString();
                    UserInfo.userPhone = dr["PHONE"].ToString();

                    MessageBox.Show(UserInfo.userType + "登录成功");

                    if (UserInfo.userType == "收银员")
                    {
                        // 显示收银员主界面
                        MainFormUser formUser = new MainFormUser();
                        formUser.Show();

                        // 隐藏登录界面
                        this.Hide();
                    }

                    if (UserInfo.userType == "库管员")
                    {
                        // 显示库管员主界面
                        MainFormAdmin formAdmin = new MainFormAdmin();
                        formAdmin.Show();

                        // 隐藏登录界面
                        this.Hide();
                    }
                }
                else
                {
                    MessageBox.Show("用户名或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
上一篇 下一篇

猜你喜欢

热点阅读