コード例 #1
0
        /// <summary>
        /// 插入用户信息
        /// </summary>
        /// <param name="UserNmae"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public static int CreateUser(String UserNmae, String Password, int RoleId, String Enable)
        {
            Boolean enable;

            #region 检查输入的合法性
            if (string.IsNullOrEmpty(UserNmae) || string.IsNullOrEmpty(Password))
            {
                return(0);
            }

            try
            {
                enable = Convert.ToBoolean(Enable);
            }
            catch
            {
                return(0);
            }
            #endregion

            #region 把数据组装成一个对象
            Models.DB.User user = new Models.DB.User();
            user.Name     = UserNmae;
            user.Password = Password;
            user.RoleId   = RoleId;
            user.Enable   = enable;
            #endregion

            return(DAL.Create.CreateOne(user));
        }
コード例 #2
0
        /// <summary>
        /// 根据用户名获取记录
        /// </summary>
        /// <param name="UserName"></param>
        /// <returns></returns>
        public static Models.DB.User Find(String UserName)
        {
            #region 检查输入的合法性
            if (string.IsNullOrEmpty(UserName))
            {
                return(null);
            }
            #endregion

            #region 把得到数据组装成类的实例
            DataTable dt = DAL.User.QueryOne(UserName);
            if (dt.Rows.Count > 0)
            {
                Models.DB.User user = new Models.DB.User();
                user.ID       = Convert.ToInt32(dt.Rows[0]["ID"]);
                user.Name     = dt.Rows[0]["Name"].ToString();
                user.Password = dt.Rows[0]["Password"].ToString();
                user.RoleId   = Convert.ToInt32(dt.Rows[0]["RoleID"]);
                user.Enable   = Convert.ToBoolean(dt.Rows[0]["Enable"]);

                return(user);
            }
            #endregion
            return(null);
        }
コード例 #3
0
        public static int Insert(Models.DB.User user)
        {
            string sql = string.Format("insert into Tb_User(Name,Password,RoleID,Enable) values(@Name,@Password,@RoleID,@Enable);select @id=SCOPE_IDENTITY()");

            SqlParameter[] parameters =
            {
                new SqlParameter("Name",     SqlDbType.NVarChar, 255),
                new SqlParameter("Password", user.Password),
                new SqlParameter("RoleID",   SqlDbType.Int),
                new SqlParameter("Enable",   SqlDbType.Bit),
                new SqlParameter("id",       SqlDbType.Int)
            };

            parameters[0].Value     = user.Name;
            parameters[1].Value     = user.Password;
            parameters[2].Value     = user.RoleId;
            parameters[3].Value     = user.Enable;
            parameters[4].Direction = ParameterDirection.Output;

            //   int temp = Convert.ToInt32(parameters[4].Value);

            Utility.SQLHelper db = new Utility.SQLHelper();
            db.ExecuteNonQuery(sql, parameters, CommandType.Text);
            int id = Convert.ToInt32(parameters[4].Value);

            return(id);
        }
コード例 #4
0
 /// <summary>
 /// 根据ID获取一条记录
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 public static Models.DB.User SelectUserOne(int Id)
 {
     Models.DB.User        User = new Models.DB.User();
     System.Data.DataTable dt   = DAL.Select.GetOne("Tb_User", Id);
     if (dt.Rows.Count > 0)
     {
         User.ID       = Convert.ToInt32(dt.Rows[0]["ID"]);
         User.Name     = dt.Rows[0]["Name"].ToString();
         User.Password = dt.Rows[0]["Password"].ToString();
         User.RoleId   = Convert.ToInt32(dt.Rows[0]["RoleID"]);
         User.Enable   = Convert.ToBoolean(dt.Rows[0]["Enable"]);
     }
     return(User);
 }
コード例 #5
0
        private Models.DB.User GetOrCreateUser(string email)
        {
            var user = _linebotContext.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();

            if (user == null)
            {
                user = new Models.DB.User()
                {
                    GId   = 1,
                    Email = User.Identity.Name,
                };
                _linebotContext.Users.Add(user);
                _linebotContext.SaveChanges();
            }

            return(user);
        }
コード例 #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     accessControl();
     if (Request["edit"] == null)
     {
         Response.Redirect("Default.aspx");
         return;
     }
     try
     {
         int Id = Convert.ToInt32(Request["edit"]);
         Judge = BLL.JudgeInfoModel.SelectOne(Id);
         user  = BLL.User.SelectUserOne(Judge.UserId);
     }
     catch
     {
         Response.Redirect("Default.aspx");
     }
 }
コード例 #7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     accessControl();
     if (Request["edit"] == null)
     {
         Response.Redirect("Default.aspx");
         return;
     }
     try
     {
         int Id = Convert.ToInt32(Request["edit"]);
         Admin = BLL.AdminModel.SelectAdminModelOne(Id);
         user  = BLL.User.SelectUserOne(Admin.UserId);
         Role  = BLL.Role.SelectRoleOne(user.RoleId);
         initRoles();
     }
     catch {
         Response.Redirect("Default.aspx");
     }
 }
コード例 #8
0
        public static double CountByEnable(string Enable)
        {
            bool enable = true;

            if (string.IsNullOrEmpty(Enable))
            {
                return(0);
            }
            try
            {
                enable = Convert.ToBoolean(Enable);
            }
            catch
            {
                return(0);
            }
            Models.DB.StudentInfoModel Student = new Models.DB.StudentInfoModel();
            Models.DB.User             User    = new Models.DB.User();
            User.Enable = enable;
            return(DAL.Select.GetCount(Student, User, "Tb_StudentInfoModel.UserId=Tb_User.ID", "Enable"));
        }
コード例 #9
0
        /// <summary>
        /// 更新密码
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public static int UpdateUserPassword(string Id, string Password)
        {
            int id = 0;

            if (string.IsNullOrEmpty(Id) || string.IsNullOrEmpty(Password))
            {
                return(0);
            }
            try
            {
                id = Convert.ToInt32(Id);
            }
            catch { return(0); }
            #region 把输入组装成类的实例
            Models.DB.User User = BLL.User.SelectUserOne(id);
            User.ID       = id;
            User.Password = Password;
            #endregion

            return(DAL.Update.ChangeSome(User, "ID"));
        }
コード例 #10
0
        /// <summary>
        /// 根据Enable获取数据
        /// </summary>
        /// <param name="Enable"></param>
        /// <param name="pagesize"></param>
        /// <param name="currentPage"></param>
        /// <returns></returns>
        public static List <Models.DB.StudentInfoModel> SelectByEnable(string Enable, int pagesize, int currentPage)
        {
            List <Models.DB.StudentInfoModel> Students = new List <Models.DB.StudentInfoModel>();
            bool enable = true;

            if (string.IsNullOrEmpty(Enable))
            {
                return(Students);
            }
            try
            {
                enable = Convert.ToBoolean(Enable);
            }
            catch
            {
                return(Students);
            }
            Models.DB.StudentInfoModel Student = new Models.DB.StudentInfoModel();
            Models.DB.User             User    = new Models.DB.User();
            Models.DB.RoleInfoModel    Model   = BLL.RoleInfoModel.SelectRoleInfoModel("Tb_StudentInfoModel");
            List <Models.DB.Role>      Roles   = BLL.Role.SelectRole(Model.Id);

            if (Roles.Count <= 0)
            {
                return(Students);
            }
            User.Enable = enable;
            User.RoleId = Roles[0].ID;
            string[] targets         = { "RoleId", "Enable" };
            System.Data.DataTable dt = DAL.Select.GetSome(User, targets, pagesize, currentPage, "ID", "");
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Student = BLL.StudentInfoModel.SelectOneByUserId(dt.Rows[i]["Id"].ToString());
                    Students.Add(Student);
                }
            }
            return(Students);
        }
コード例 #11
0
        /// <summary>
        /// 更改Enable
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="Enable"></param>
        /// <returns></returns>
        public static int UpdateUserEnable(string UserId, string Enable)
        {
            int  userId = 0;
            bool enable = true;

            if (string.IsNullOrEmpty(UserId) || string.IsNullOrEmpty(Enable))
            {
                return(0);
            }
            try
            {
                userId = Convert.ToInt32(UserId);
                enable = Convert.ToBoolean(Enable);
            }
            catch
            {
                return(0);
            }
            Models.DB.User User = BLL.User.SelectUserOne(userId);
            User.Enable = enable;
            return(DAL.Update.ChangeSome(User, "ID"));
        }
コード例 #12
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string dowhat = context.Request["dowhat"];

            if (dowhat == null)
            {
                dowhat = "";
            }


            #region 登录
            if (dowhat == "login")
            {
                string UserName = context.Request["UserName"];
                string Password = context.Request["Password"];
                Password = Utility.Tool.MD5(Password);

                Models.DB.User user = BLL.User.Find(UserName, Password);
                if (user.Enable == false)
                {
                    context.Response.Write("EnableFalse");
                    context.Response.End();
                    return;
                }
                if (user != null)
                {
                    context.Session["user"] = user.ID;
                    context.Session["role"] = user.RoleId;
                    Models.DB.Role role = BLL.Role.SelectRoleOne(user.RoleId);

                    if (role != null)
                    {
                        context.Response.Write(role.Name);
                        context.Response.End();
                        return;
                    }
                    else
                    {
                        context.Response.Write("faild");
                        context.Response.End();
                        return;
                    }
                    //    context.Response.Write("success");
                }
                else
                {
                    context.Response.Write("faild");
                }
                context.Response.End();
                return;
            }
            #endregion


            #region 注册
            if (dowhat == "register")
            {
                String UserName = context.Request["UserName"];
                String Password = context.Request["Password"];
                Password = Utility.Tool.MD5(Password);
                String StudentID  = context.Request["StudentID"];
                String Name       = context.Request["Name"];
                String Sex        = context.Request["Sex"];
                String InTimeYear = context.Request["InTimeYear"];
                String School     = context.Request["School"];
                String College    = context.Request["College"];
                String Major      = context.Request["Major"];
                String Mail       = context.Request["Mail"];


                int RoleID = BLL.Role.Find("Student");
                if (RoleID == 0)
                {
                    return;
                }

                if (BLL.User.Find(UserName) != null)
                {
                    context.Response.Write("USEREXIST");
                    context.Response.End();
                    return;
                }
                if (BLL.StudentInfoModel.FindByString(StudentID, "StudentID").Count > 0)
                {
                    context.Response.Write("STUDENTEXIST");
                    context.Response.End();
                    return;
                }

                int UserID = BLL.User.CreateUser(UserName, Password, RoleID, "False");


                if (UserID > 0)
                {
                    if (BLL.Create.CreateStudentModelInfo(StudentID, Name, Sex, Major, InTimeYear, School, College, Mail, UserID) > 0)
                    {
                        context.Response.Write("success");
                    }
                    else
                    {
                        BLL.Delete.Word("Tb_User", UserID.ToString());
                        context.Response.Write("faild");
                    }
                }
                else
                {
                    context.Response.Write("faild");
                }
                context.Response.End();
                return;
            }
            #endregion
        }