示例#1
0
文件: UserDAL.cs 项目: zhouchm/School
 public static User ToUser(DataRow row)
 {
     User user = new User();
     user.UserName = (string)row["UserName"];
     user.Password = (string)row["Password"];
     user.RealName = (string)row["RealName"];
     user.Gender = (string)row["Gender"];
     user.Email = (string)row["Email"];
     return user;
 }
示例#2
0
文件: UserDAL.cs 项目: zhouchm/School
 public static void Insert(User user)
 {
     //bit类型,在sql语句中要写0、1
     //在.net中要用bool表示
     string time = DateTime.Now.ToLocalTime().ToString();
     SqlHelper.ExecuteNonQuery(@"insert into T_Users(
         UserName,Password,RealName,Gender,Email,updatetime) values(@UserName,@Password,@RealName,@Gender,@Email,@updatetime)",
             new SqlParameter("@UserName", user.UserName),
             new SqlParameter("@Password", user.Password),
             new SqlParameter("@RealName", user.RealName),
     new SqlParameter("@Gender", user.Gender),
             new SqlParameter("@Email", user.Email),
             new SqlParameter("@updatetime",time));
 }
示例#3
0
 public void ProcessRequest(HttpContext context)
 {
     context.Response.ContentType = "text/html";
     string AdminName = (string)context.Session["LoginAdminName"];
     if (AdminName == null)
     {
         var data = new { Title = "现代科技体验中心" };
         string html = CommonHelper.RenderHtml("../html/AdminLogin.htm", data);
         context.Response.Write(html);
     }
     else
     {
         string action = context.Request["Action"];
         if (action == "Adm_edit")
         {
             string username = context.Request["UserName"];
             DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Users where UserName=@Username", new SqlParameter("@Username", username));
             User user = new User();
             user = UserDAL.ToUser(dt.Rows[0]);
             var data = new { Title = "现代科技体验中心", Action = "Adm_update", Name = AdminName, user };
             string html = CommonHelper.RenderHtml("../html/UserEditAtAdmin.htm", data);
             context.Response.Write(html);
         }
         else if (action == "Adm_update")
         {
             string UserName = context.Request["UserName"];
             string Email = context.Request["Email"];
             string Gender = context.Request["Gender"];
             string RealName = context.Request["RealName"];
             UserDAL.Update(UserName, RealName, Gender, Email);
             context.Response.Redirect("UserList.ashx");
         }
         else if (action == "Delete")
         {
             string username = context.Request["UserName"];
             SqlHelper.ExecuteNonQuery("Delete from T_Users where UserName=@UserName", new SqlParameter("@UserName", username));
             context.Response.Redirect("UserList.ashx");
         }
     }
 }
示例#4
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            string UserReg = context.Request["UserReg"];
            if (UserReg == "0")
            {
                User user = new User();
                user.UserName = context.Request["userName"];
                user.Password = context.Request["userpwd"];
                user.Email = context.Request["email"];
                user.Gender = context.Request["sex"];
                user.RealName = context.Request["RealName"];

                string url = "http://tyzx.sesedu.cn/UserRegister.ashx?UserReg=1&userName="******"&userpwd=";
                url = url + user.Password + "&email=";
                url = url + user.Email + "&sex=";
                url = url + user.Gender + "&RealName=";
                url = url + HttpUtility.UrlEncode(user.RealName) + "&time=";
                url = url + DateTime.Now;
                var data = new { Email = user.Email, url };
                string html = CommonHelper.RenderHtml("../html/RegisterEmail.htm", data);
                string from = "*****@*****.**";//发件人邮箱
                string fromer = "上海市实验学校";
                string to = user.Email;
                string toer = user.Email;//收件人
                string Subject = "实验学校注册";
                string file = "";
                string Body = html;
                string SMTPHost = "smtp.163.com";//发件人邮箱服务器
                string SMTPuser = "******";//发件人邮箱账户
                string SMTPpass = "******";//发件人邮箱密码
                sendmail(from, fromer, to, toer, Subject, Body, file, SMTPHost, SMTPuser, SMTPpass);
                string str = @"<a href=""/UserLogin.ashx?Action=Log"">登入</a>&nbsp;|&nbsp;<a href=""/UserRegister.ashx?UserReg=Reg"">注册</a>";
                String msg = "恭喜,现在只差一步,登录邮箱激活账号便可以完成注册!";
                var data1 = new { Title = "用户注册", Msg = msg, str };
                string html1 = CommonHelper.RenderHtml("../html/RegistPreSuccess.htm", data1);
                context.Response.Write(html1);
            }
            else if (UserReg == "1")
            {

                User user = new User();

                string userName = context.Request["UserName"];
                int count = (int)SqlHelper.ExecuteScalar("select count(*) from T_Users where UserName=@UserName", new SqlParameter("@UserName", userName));
                if (count <= 0)
                {
                    user.UserName = context.Request["userName"];
                    user.Password = context.Request["userpwd"];
                    user.Email = context.Request["email"];
                    user.Gender = context.Request["sex"];
                    user.RealName = HttpUtility.UrlDecode(context.Request["RealName"]);
                    DateTime old = Convert.ToDateTime(context.Request["time"]);
                    System.TimeSpan NowValue = new TimeSpan(DateTime.Now.Ticks);
                    System.TimeSpan TimeValue = new TimeSpan(old.Ticks);
                    System.TimeSpan DateDiff = TimeSpan.Zero;
                    DateDiff = TimeValue.Subtract(NowValue);
                    int hours = DateDiff.Hours;
                    int minutes = DateDiff.Minutes;
                    int seconds = DateDiff.Seconds;
                    int lReturn = hours * 3600 * 1000
                        + minutes * 60 * 1000
                        + seconds;
                    if (lReturn <= 1800)
                    {
                        UserDAL.Insert(user);
                        //context.Session["LoginUserName"] = context.Request["userName"];
                        CreateQRCode(context.Request["userName"]);
                        string url = "RegistSuccess.ashx?username="******"<a href=""/UserLogin.ashx?Action=Log"">登入</a>&nbsp;|&nbsp;<a href=""/UserRegister.ashx?UserReg=Reg"">注册</a>";
                        var data = new { Title = "用户注册", Msg = "此链接已经失效,请重新注册!", str };
                        string html = CommonHelper.RenderHtml("../html/UserRegister.htm", data);
                        context.Response.Write(html);
                    }

                }
                else
                {
                    string str = @"<a href=""/UserLogin.ashx?Action=Log"">登入</a>&nbsp;|&nbsp;<a href=""/UserRegister.ashx?UserReg=Reg"">注册</a>";
                    var data = new { Title = "用户注册", Msg = "此账号已经存在,请勿重复点击!", str };
                    string html = CommonHelper.RenderHtml("../html/UserRegister.htm", data);
                    context.Response.Write(html);
                }

            }
            else if (UserReg == "Reg")
            {
                string str = @"<a href=""/UserLogin.ashx?Action=Log"">登入</a>&nbsp;|&nbsp;<a href=""/UserRegister.ashx?UserReg=Reg"">注册</a>";
                var data = new { Title = "用户注册", Msg = "", str };
                string html = CommonHelper.RenderHtml("../html/UserRegister.htm", data);
                context.Response.Write(html);
            }
        }
示例#5
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            string username = (string)context.Session["LoginUserName"];
            string str;
            if (username == null)
            {
                context.Response.Redirect("UserLogin.ashx?Action=Log");
            }
            else
            {
                string action = context.Request["Action"];
                str = "用户:&nbsp;" + username + "&nbsp;欢迎您";
                if (action == "user_edit")
                {
                    username = (string)context.Session["LoginUserName"];
                    DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Users where UserName=@Username", new SqlParameter("@Username", username));
                    User user = new User();
                    user = UserDAL.ToUser(dt.Rows[0]);
                    var data = new { Title = "用户信息", Action = "user_update", user, str, Msg = "" };
                    string html = CommonHelper.RenderHtml("../html/UserEdit.htm", data);
                    context.Response.Write(html);
                }
                else if (action == "Adm_edit")
                {
                    username = context.Request["UserName"];
                    DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Users where UserName=@Username", new SqlParameter("@Username", username));
                    User user = new User();
                    user = UserDAL.ToUser(dt.Rows[0]);
                    var data = new { Title = "用户信息", Action = "Adm_update", user, str };
                    string html = CommonHelper.RenderHtml("../html/UserEdit.htm", data);
                    context.Response.Write(html);

                }
                else if (action == "Adm_update")
                {
                    username = context.Request["userName"];
                    DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Users where UserName=@username", new SqlParameter("@username", username));
                    if (dt.Rows.Count <= 0)
                    {
                        context.Response.Write("找不到用户名" + username + "用户");
                    }
                    else if (dt.Rows.Count > 1)
                    {
                        context.Response.Write("错误!出现重名用户!");
                    }
                    else
                    {
                        string realName = context.Request["RealName"];
                        string Email = context.Request["email"];
                        string Gender = context.Request["sex"];
                        UserDAL.Update(username, realName, Gender, Email);
                        context.Response.Redirect("UserList.ashx");
                    }
                }
                else if (action == "user_update")
                {
                    username = context.Request["userName"];
                    DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Users where UserName=@username", new SqlParameter("@username", username));
                    if (dt.Rows.Count <= 0)
                    {
                        context.Response.Write("找不到用户名" + username + "用户");
                    }
                    else if (dt.Rows.Count > 1)
                    {
                        context.Response.Write("错误!出现重名用户!");
                    }
                    else
                    {
                        string RealName = context.Request["RealName"];
                        string email = context.Request["email"];
                        string sex = context.Request["sex"];
                        UserDAL.Update(username, RealName, sex, email);

                        username = (string)context.Session["LoginUserName"];
                        DataTable dt1 = SqlHelper.ExecuteDataTable("select * from T_Users where UserName=@Username", new SqlParameter("@Username", username));
                        User user = new User();
                        user = UserDAL.ToUser(dt1.Rows[0]);
                        var data = new { Title = "用户信息", Action = "user_update", user, str, Msg = "update" };
                        string html = CommonHelper.RenderHtml("../html/UserEdit.htm", data);
                        context.Response.Write(html);
                    }
                }
                else if (action == "User_pwd")
                {
                    string password = context.Request["userNewpwd"];
                    DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Users where UserName=@username", new SqlParameter("@username", username));
                    if (dt.Rows.Count <= 0)
                    {
                        context.Response.Write("找不到用户名" + username + "用户");
                    }
                    else if (dt.Rows.Count > 1)
                    {
                        context.Response.Write("错误!出现重名用户!");
                    }
                    else
                    {
                        UserDAL.Update_Pwd(username, password);

                        context.Session.Remove("LoginUserName");
                        context.Response.Redirect("UserLogin.ashx?Action=Log");
                    }
                }
                else if (action == "Delete")
                {
                    username = context.Request["UserName"];
                    SqlHelper.ExecuteNonQuery("Delete from T_Users where UserName=@UserName", new SqlParameter("@UserName", username));
                }
            }
        }
示例#6
0
文件: UserDAL.cs 项目: zhouchm/School
 public User[] ListAll()
 {
     DataTable dt = SqlHelper.ExecuteDataTable("select * from T_Users");
     User[] users = new User[dt.Rows.Count];
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         users[i] = ToUser(dt.Rows[i]);
     }
     return users;
 }