Exemplo n.º 1
0
 protected void lbtnSubmit_Click(object sender, EventArgs e)
 {
     String loginName = txtLoginName.Text.Trim();
     String userPwd = txtUserPwd.Text.Trim();
     //MD5
     userPwd = Util.MyUtil.MD5(userPwd);
     String strSql = "select id from tbUser where loginname=@loginname and userpwd=@userpwd";
     bool b= DbHelperSQL.Exists(strSql,new SqlParameter("@loginname",loginName),new SqlParameter("@userpwd",userPwd));
     if (b)
     {
         //登陆成功
         int id = (int)DbHelperSQL.GetSingle(strSql, new SqlParameter("@loginname", loginName), new SqlParameter("@userpwd", userPwd));
         tbUser user = new tbUserDAL().GetModel(id);
         Session[Constant.User] = user;
         Server.Transfer("~/Menu.aspx");
     }
     else
     {
         lblTip.Text = "用户名或者密码错误";
         lblTip.Visible = true;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 导入到数据库
        /// </summary>
        /// <param name="dt"></param>
        /// <returns>返回插入不成功的学号</returns>
        public static List<String> ExportToDB(DataTable dt)
        {
            List<String> list = new List<string>();
            tbUserDAL userDAL = new tbUserDAL();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                tbUser user = new tbUser();
                String loginname = dt.Rows[i][0].ToString();
                String realname = dt.Rows[i][1].ToString();
                String userpwd = dt.Rows[i][2].ToString();
                String classname = dt.Rows[i][3].ToString();
                String usertype = dt.Rows[i][4].ToString();

                user.loginname = loginname;//登陆名
                user.realname = realname;//真实名

                if (usertype.Trim() == "学生")
                {
                    if (IsNum(loginname))
                    {
                        //班级
                        try
                        {
                            int classid = (int)DbHelperSQL.GetSingle("select top 1 id from tbClass where classname=@classname", new SqlParameter("@classname", classname));
                            user.classid = classid;
                        }
                        catch (Exception)
                        {
                            list.Add("行" + (i + 2) + "的班级不存在!");
                            continue;
                        }
                    }
                    else
                    {
                        list.Add("行" + (i + 2) + "的学号格式不正确!");
                        continue;
                    }
                    user.usertype = 3;
                }
                else
                    if (usertype.Trim() == "教师")
                    {
                        user.usertype = 2;
                    }
                    else
                    {
                        list.Add("行" + (i + 2) + "的身份格式不正确!");
                        continue;
                    }
                //密码
                try
                {
                    user.userpwd = MyUtil.MD5(GetPwdByCard(userpwd));
                }
                catch (Exception)
                {
                    list.Add("行" + (i + 2) + "的密码格式不正确!");
                    continue;
                }

                //判断登陆名是否存在
                if (DbHelperSQL.Exists("select * from tbUser where loginname=@loginname", new SqlParameter("@loginname", loginname)))
                {
                    list.Add("行" + (i + 2) + "的登陆名已经存在!");
                    continue;
                }

                userDAL.Add(user);
            }
            return list;
        }