Beispiel #1
0
        public ActionResult Index()
        {
            ViewBag.Title = "注册";

            if (Session["user"] != null)
                return Content("已经登录不能操作");

            if (Request.HttpMethod == "POST")
            {
                var tel = Request.Form["tel"];
                var password = Request.Form["password"];

                try
                {
                    var userid = DB.SInsert("insert into " + DBTables.User + " (tel,password) values (?,?)", tel, password.SHA256());
                    var user = new DBC.User(userid);
                    Session["user"] = user;

                    return Content("注册成功");
                }
                catch
                {
                    return Content("改用户名已经被注册");
                }
            }
            return View();
        }
Beispiel #2
0
        public ActionResult UserRecharge(int id, int count)
        {
            try
            {
                var current = GetCurrentUser();
                var user    = new DBC.User(id);
                if (user.Parent != current.ID)
                {
                    return(Content("未找到该用户"));
                }

                if (count >= 0)
                {
                    if (current.Points < count)
                    {
                        return(Content("余额不足,无法完成充值"));
                    }

                    current.Points -= (uint)count;
                    user.Points    += (uint)count;
                }
                else
                {
                    count = -1 * count;
                    if (user.Points < count)
                    {
                        return(Content("提现额大于积分,提现失败"));
                    }

                    user.Points -= (uint)count;
                }
            }
            catch { }
            return(Redirect("~/home/users"));
        }
Beispiel #3
0
        public ActionResult Users(int p = 0)
        {
            ViewBag.Title = "用户";
            ViewBag.Title2 = "用户";
            ViewBag.Page = "用户";

            var currentUser = Session["user"] as DBC.User;
            var pages = 1;

            var sql1 = string.Format("select count(*) from {0} where parent=?", DBTables.User);
            var totalCount = Convert.ToInt32(DB.SExecuteScalar(sql1, currentUser.ID));
            pages = (int)Math.Ceiling(totalCount * 1.0 / _itemsPerPage);

            var sql2 = string.Format("select id from {0} where parent=? limit ?,?", DBTables.User);
            var res = DB.SExecuteReader(sql2, currentUser.ID, p * _itemsPerPage, _itemsPerPage);

            var userList = new List<DBC.User>();
            foreach (var item in res)
            {
                var id = Convert.ToInt32(item[0]);
                var u = new DBC.User(id);
                userList.Add(u);
            }

            ViewBag.list = GetUserOverviewList(userList);

            var pagination = new Pagination();
            pagination.Pages = pages;
            pagination.Current = p;
            pagination.BaseUrl = "/home/users";
            ViewBag.pagination = pagination;

            return View();
        }
Beispiel #4
0
        public ActionResult BettingFind(int id)
        {
            try
            {
                ViewBag.Title  = "投注记录";
                ViewBag.Title2 = "投注记录";
                ViewBag.Page   = "投注";

                var betting = new DBC.Betting(id);
                var user    = new DBC.User(betting.UserID);
                var current = GetCurrentUser();

                if (user.ID == current.ID || user.Parent == current.ID)
                {
                    var bettingList = new List <DBC.Betting>()
                    {
                        betting
                    };
                    ViewBag.list = GetBettingOverviewList(bettingList);
                }
                else
                {
                    throw new Exception("无权查看");
                }
            }
            catch
            {
                ViewBag.errorText = "未查询到任何记录";
            }

            return(View("betting"));
        }
Beispiel #5
0
        public ActionResult UserFind(int id)
        {
            var currentUser = Session["user"] as DBC.User;

            ViewBag.Title  = "查找用户";
            ViewBag.Title2 = "查找用户";
            ViewBag.Page   = "用户";
            try
            {
                var user = new DBC.User(id);
                if (user.Parent != currentUser.ID)
                {
                    throw new Exception("无权查看该用户资料");
                }
                ViewBag.list = GetUserOverviewList(new List <DBC.User>()
                {
                    user
                });
            }
            catch
            {
                ViewBag.errorText = "该用户id不存在";
            }
            return(View("users"));
        }
Beispiel #6
0
        //删除用户,功能暂时不实现,问题多多
        //public ActionResult UserDelete(int id)
        //{
        //    try
        //    {
        //        var user = new DBC.User(id);
        //        if (user.Parent == _currentUser.ID)
        //            user.Delete();
        //    }
        //    catch { }
        //    return Redirect("~/home/users");
        //}



        //重置用户密码
        public ActionResult UserResetPw(int id)
        {
            var user = new DBC.User(id);
            if (user.Parent == GetCurrentUser().ID)
                user.Password = "******".ToSHA256String();

            return Redirect("~/home/users");
        }
Beispiel #7
0
 protected void Session_Start()
 {
     var cookie = Request.Cookies["login"];
     if (cookie != null)
     {
         var val = cookie.Value;
         var sql = "select userid from " + DBTables.UserLoginCookie + " where value=? and expire>?";
         var res = DB.SExecuteScalar(sql, val, DateTime.Now);
         if (res != null)
         {
             var userid = Convert.ToInt32(res);
             Session["user"] = new DBC.User(userid);
         }
     }
 }
Beispiel #8
0
        protected void Session_Start()
        {
            var cookie = Request.Cookies["login"];

            if (cookie != null)
            {
                var val = cookie.Value;
                var sql = "select userid from " + DBTables.UserLoginCookie + " where value=? and expire>?";
                var res = DB.SExecuteScalar(sql, val, DateTime.Now);
                if (res != null)
                {
                    var userid = Convert.ToInt32(res);
                    Session["user"] = new DBC.User(userid);
                }
            }
        }
Beispiel #9
0
        //充值
        public ActionResult UserRecharge(int id)
        {
            try
            {
                var currentUser = Session["user"] as DBC.User;
                ViewBag.Title = "用户充值";
                ViewBag.Title2 = "用户充值";
                ViewBag.Page = "用户";

                var user = new DBC.User(id);
                if (user.Parent != GetCurrentUser().ID)
                    throw new Exception("无权充值");

                ViewBag.user = user;
            }
            catch
            {
                ViewBag.errorText = "找不到该用户";
            }
            return View();
        }
Beispiel #10
0
        public ActionResult Index(int id, string password, string remember)
        {
            try
            {
                var user = new DBC.User(id);

                if (user.Role != Enums.Roles.Administrator)
                {
                    throw new Exception("权限不足");
                }

                if (user.Password != password.ToSHA256String())
                {
                    throw new Exception("密码错误");
                }

                Session["user"] = user;

                if (string.IsNullOrEmpty(remember) == false)
                {
                    HttpCookie cookie = new HttpCookie("login");
                    var        val    = Guid.NewGuid().ToString("d");
                    var        expire = DateTime.Now.AddDays(15);

                    DB.SExecuteNonQuery("insert into " + DBTables.UserLoginCookie + "(userid,value,expire) values (?,?,?)", user.ID, val, expire);

                    cookie.Value    = val;
                    cookie.Expires  = expire;
                    cookie.HttpOnly = true;

                    Response.SetCookie(cookie);
                }
                return(Redirect("~/"));
            }
            catch
            {
                ViewBag.loginFail = true;
                return(View());
            }
        }
Beispiel #11
0
        public ActionResult Index()
        {
            if (Session["user"] != null)
                return Content("已经登录过了,请不要重复登录");

            if (Request.HttpMethod == "POST")
            {
                var tel = Request.Form["tel"];
                var password = Request.Form["password"];

                var sql = "select id from " + DBTables.User + " where tel=? and password=?";
                var pw = password.SHA256();
                var res = DB.SExecuteScalar(sql, tel, password.SHA256());

                if (res == null)
                    return Content("帐号或密码错误");

                var userid = Convert.ToInt32(res);
                Session["user"] = new DBC.User(userid);

                if (string.IsNullOrEmpty(Request.Form["remember"]) == false)
                {
                    HttpCookie cookie = new HttpCookie("login");
                    var val = Guid.NewGuid().ToString("d");
                    var expire = DateTime.Now.AddDays(15);

                    DB.SExecuteNonQuery("insert into "+DBTables.UserLoginCookie +"(userid,value,expire) values (?,?,?)" ,userid,val,expire);

                    cookie.Value = val;
                    cookie.Expires = expire;
                    cookie.HttpOnly = true;

                    Response.SetCookie(cookie);
                }
                return Redirect("~/account");
            }
            return View();
        }
Beispiel #12
0
        public ActionResult Index(int id, string password, string remember)
        {
            try
            {
                var user = new DBC.User(id);

                if (user.Role != Enums.Roles.Administrator)
                    throw new Exception("权限不足");

                if (user.Password != password.ToSHA256String())
                    throw new Exception("密码错误");

                Session["user"] = user;

                if (string.IsNullOrEmpty(remember) == false)
                {
                    HttpCookie cookie = new HttpCookie("login");
                    var val = Guid.NewGuid().ToString("d");
                    var expire = DateTime.Now.AddDays(15);

                    DB.SExecuteNonQuery("insert into " + DBTables.UserLoginCookie + "(userid,value,expire) values (?,?,?)", user.ID, val, expire);

                    cookie.Value = val;
                    cookie.Expires = expire;
                    cookie.HttpOnly = true;

                    Response.SetCookie(cookie);
                }
                return Redirect("~/");
            }
            catch
            {
                ViewBag.loginFail = true;
                return View();
            }
        }
Beispiel #13
0
        public ActionResult Users(int p = 0)
        {
            ViewBag.Title = "用户";
            ViewBag.Title2 = "用户";
            ViewBag.Page = "用户";

            var user = Session["user"] as DBC.User;
            var itemsPerPage = 20;
            var pages = 1;

            var sql1 = string.Format("select count(*) from {0}", DBTables.User);
            var totalCount = Convert.ToInt32(DB.SExecuteScalar(sql1));
            pages = (int)Math.Ceiling(totalCount * 1.0 / itemsPerPage);

            var sql2 = string.Format("select id from {0} where parent=? limit ?,?", DBTables.User);
            var res = DB.SExecuteReader(sql2, user.ID, p * itemsPerPage, itemsPerPage);

            var userList = new List<DBC.User>();
            foreach (var item in res)
            {
                var id = Convert.ToInt32(item[0]);
                var u = new DBC.User(id);
                userList.Add(u);
            }

            ViewBag.list = GetUserOverviewList(userList);

            var pagination = new Pagination();
            pagination.Pages = pages;
            pagination.Current = p;
            pagination.BaseUrl = "/home/users";
            ViewBag.pagination = pagination;

            return View();
        }
Beispiel #14
0
        //重置密码
        public ActionResult UserResetPw(int id)
        {
            var user = new DBC.User(id);
            if (user.Parent == GetCurrentUser().ID)
                user.Password = "******".ToSHA256String();

            return Redirect("~/home/users");
        }
Beispiel #15
0
        public ActionResult UserRecharge(int id, int count)
        {
            try
            {
                var current = GetCurrentUser();
                var user = new DBC.User(id);
                if (user.Parent != current.ID)
                    return Content("未找到该用户");

                if (count >= 0)
                {
                    if (current.Points < count)
                        return Content("余额不足,无法完成充值");

                    current.Points -=(uint) count;
                    user.Points +=(uint) count;
                }
                else
                {
                    count = -1 * count;
                    if(user.Points<count)
                    {
                        return Content("提现额大于积分,提现失败");
                    }

                    user.Points -=(uint) count;
                }
            }
            catch { }
            return Redirect("~/home/users");
        }
Beispiel #16
0
        //充值
        public ActionResult UserRecharge(int id)
        {
            try
            {
                var current = GetCurrentUser();
                ViewBag.Title = "用户充值";
                ViewBag.Title2 = "用户充值";
                ViewBag.Page = "用户";

                var user = new DBC.User(id);
                if (user.Parent != current.ID)
                    throw new Exception("无权充值");

                ViewBag.user = user;
            }
            catch
            {
                ViewBag.errorText = "找不到该用户";
            }
            return View();
        }
Beispiel #17
0
        public ActionResult UserFind(int id)
        {
            var currentUser = Session["user"] as DBC.User;

            ViewBag.Title = "查找用户";
            ViewBag.Title2 = "查找用户";
            ViewBag.Page = "用户";
            try
            {
                var user = new DBC.User(id);
                if (user.Parent != currentUser.ID)
                    throw new Exception("无权查看该用户资料");
                ViewBag.list = GetUserOverviewList(new List<DBC.User>() { user });
            }
            catch
            {
                ViewBag.errorText = "该用户id不存在";
            }
            return View("users");
        }
Beispiel #18
0
        public ActionResult Betting(int? userid, DateTime? beginDate, DateTime? endDate, int p = 0)
        {
            try
            {
                ViewBag.Title = "投注记录";
                ViewBag.Title2 = "投注记录";
                ViewBag.Page = "投注";

                if (beginDate == null)
                    beginDate = DateTime.Today.AddDays(-7);
                if (endDate == null)
                    endDate = DateTime.Today;

                var currentUser = Session["user"] as DBC.User;
                var pages = 1;
                var sqlCount = "";
                var sqlList = "";
                var sqlSum = "";
                var sqlCountArgs = new List<object>();
                var sqlListArgs = new List<object>();
                var sqlSumArgs = new List<object>();

                //查看指定用户的投注记录
                if (userid != null)
                {
                    var user = new DBC.User(userid.Value);
                    if (user.Parent != GetCurrentUser().ID)
                        throw new Exception("无权查看");

                    sqlCount = string.Format("select count(*) from {0} where {0}.userid=? and time>? and time<?", DBTables.Betting);
                    sqlCountArgs.Add(user.ID);
                    sqlCountArgs.Add(beginDate.Value);
                    sqlCountArgs.Add(endDate.Value.AddDays(1));

                    sqlList = string.Format("select id from {0} where {0}.userid=? and time>? and time<? order by time desc limit ?,?", DBTables.Betting, DBTables.User);
                    sqlListArgs.Add(user.ID);
                    sqlListArgs.Add(beginDate.Value);
                    sqlListArgs.Add(endDate.Value.AddDays(1));

                    sqlSum = string.Format("select sum(total),sum(winning) from {0} where userid=? and time>? and time<?", DBTables.Betting);
                    sqlSumArgs.Add(user.ID);
                    sqlSumArgs.Add(beginDate.Value);
                    sqlSumArgs.Add(endDate.Value.AddDays(1));
                }
                //查看全部投注记录
                else
                {
                    var current = GetCurrentUser();
                    sqlCount = string.Format("select count(*) from {0},{1} where {0}.userid={1}.id and ({1}.id=? or {1}.parent=?) and time>? and time<?", DBTables.Betting, DBTables.User);
                    sqlCountArgs.Add(current.ID);
                    sqlCountArgs.Add(current.ID);
                    sqlCountArgs.Add(beginDate.Value);
                    sqlCountArgs.Add(endDate.Value.AddDays(1));

                    sqlList = string.Format("select {0}.id from {0},{1} where {0}.userid={1}.id and ({1}.id=? or {1}.parent=?) and time>? and time<? order by time desc limit ?,?", DBTables.Betting, DBTables.User);
                    sqlListArgs.Add(current.ID);
                    sqlListArgs.Add(current.ID);
                    sqlListArgs.Add(beginDate.Value);
                    sqlListArgs.Add(endDate.Value.AddDays(1));

                    sqlSum = string.Format("select sum(total),sum(winning) from {0},{1} where {0}.userid={1}.id and ({1}.id=? or {1}.parent=?) and time>? and time<?", DBTables.Betting, DBTables.User);
                    sqlSumArgs.Add(current.ID);
                    sqlSumArgs.Add(current.ID);
                    sqlSumArgs.Add(beginDate.Value);
                    sqlSumArgs.Add(endDate.Value.AddDays(1));
                }

                //添加分页参数
                sqlListArgs.Add(p * _itemsPerPage);
                sqlListArgs.Add(_itemsPerPage);
                //获取总记录数
                var totalCount = Convert.ToInt32(DB.SExecuteScalar(sqlCount, sqlCountArgs.ToArray()));
                //计算分页数
                pages = (int)Math.Ceiling(totalCount * 1.0 / _itemsPerPage);
                //获取下注记录
                var res = DB.SExecuteReader(sqlList, sqlListArgs.ToArray());
                var bettingList = new List<DBC.Betting>();
                foreach (var item in res)
                {
                    //数据记录不完整时跳过
                    try
                    {
                        var id = Convert.ToInt32(item[0]);
                        var betting = new DBC.Betting(id);
                        bettingList.Add(betting);
                    }
                    catch { }
                }

                //获取总投注和总中奖
                var res2 = DB.SExecuteReader(sqlSum, sqlSumArgs.ToArray());
                var totalBetting = Utility.ToInt32(res2[0][0]);
                var totalWinning = Utility.ToInt32(res2[0][1]);

                var pagination = new Pagination();
                pagination.Pages = pages;
                pagination.Current = p;
                pagination.BaseUrl = string.Format("/home/betting?userid={0}&beginDate={1}&endDate={2}", userid, beginDate.Value.ToString("yyyy-MM-dd"), endDate.Value.ToString("yyyy-MM-dd"));

                ViewBag.list = GetBettingOverviewList(bettingList);
                ViewBag.pagination = pagination;
                ViewBag.totalBetting = totalBetting;
                ViewBag.totalWinning = totalWinning;
                ViewBag.beginDate = beginDate.Value;
                ViewBag.endDate = endDate.Value;
                ViewBag.userid = userid;
            }
            catch
            {
                ViewBag.errorText = "未查询到任何记录";
            }

            return View();
        }
Beispiel #19
0
        public ActionResult BettingFind(int id)
        {
            try
            {
                ViewBag.Title = "投注记录";
                ViewBag.Title2 = "投注记录";
                ViewBag.Page = "投注";

                var betting = new DBC.Betting(id);
                var user = new DBC.User(betting.UserID);
                var current = GetCurrentUser();

                if (user.ID == current.ID || user.Parent == current.ID)
                {
                    var bettingList = new List<DBC.Betting>() { betting };
                    ViewBag.list = GetBettingOverviewList(bettingList);
                }
                else
                {
                    throw new Exception("无权查看");
                }
            }
            catch
            {
                ViewBag.errorText = "未查询到任何记录";
            }

            return View("betting");
        }
Beispiel #20
0
        public ActionResult Betting(int?userid, DateTime?beginDate, DateTime?endDate, int p = 0)
        {
            try
            {
                ViewBag.Title  = "投注记录";
                ViewBag.Title2 = "投注记录";
                ViewBag.Page   = "投注";

                if (beginDate == null)
                {
                    beginDate = DateTime.Today.AddDays(-7);
                }
                if (endDate == null)
                {
                    endDate = DateTime.Today;
                }

                var currentUser  = Session["user"] as DBC.User;
                var pages        = 1;
                var sqlCount     = "";
                var sqlList      = "";
                var sqlSum       = "";
                var sqlCountArgs = new List <object>();
                var sqlListArgs  = new List <object>();
                var sqlSumArgs   = new List <object>();

                //查看指定用户的投注记录
                if (userid != null)
                {
                    var user = new DBC.User(userid.Value);
                    if (user.Parent != GetCurrentUser().ID)
                    {
                        throw new Exception("无权查看");
                    }

                    sqlCount = string.Format("select count(*) from {0} where {0}.userid=? and time>? and time<?", DBTables.Betting);
                    sqlCountArgs.Add(user.ID);
                    sqlCountArgs.Add(beginDate.Value);
                    sqlCountArgs.Add(endDate.Value.AddDays(1));

                    sqlList = string.Format("select id from {0} where {0}.userid=? and time>? and time<? order by time desc limit ?,?", DBTables.Betting, DBTables.User);
                    sqlListArgs.Add(user.ID);
                    sqlListArgs.Add(beginDate.Value);
                    sqlListArgs.Add(endDate.Value.AddDays(1));

                    sqlSum = string.Format("select sum(total),sum(winning) from {0} where userid=? and time>? and time<?", DBTables.Betting);
                    sqlSumArgs.Add(user.ID);
                    sqlSumArgs.Add(beginDate.Value);
                    sqlSumArgs.Add(endDate.Value.AddDays(1));
                }
                //查看全部投注记录
                else
                {
                    var current = GetCurrentUser();
                    sqlCount = string.Format("select count(*) from {0},{1} where {0}.userid={1}.id and ({1}.id=? or {1}.parent=?) and time>? and time<?", DBTables.Betting, DBTables.User);
                    sqlCountArgs.Add(current.ID);
                    sqlCountArgs.Add(current.ID);
                    sqlCountArgs.Add(beginDate.Value);
                    sqlCountArgs.Add(endDate.Value.AddDays(1));

                    sqlList = string.Format("select {0}.id from {0},{1} where {0}.userid={1}.id and ({1}.id=? or {1}.parent=?) and time>? and time<? order by time desc limit ?,?", DBTables.Betting, DBTables.User);
                    sqlListArgs.Add(current.ID);
                    sqlListArgs.Add(current.ID);
                    sqlListArgs.Add(beginDate.Value);
                    sqlListArgs.Add(endDate.Value.AddDays(1));

                    sqlSum = string.Format("select sum(total),sum(winning) from {0},{1} where {0}.userid={1}.id and ({1}.id=? or {1}.parent=?) and time>? and time<?", DBTables.Betting, DBTables.User);
                    sqlSumArgs.Add(current.ID);
                    sqlSumArgs.Add(current.ID);
                    sqlSumArgs.Add(beginDate.Value);
                    sqlSumArgs.Add(endDate.Value.AddDays(1));
                }

                //添加分页参数
                sqlListArgs.Add(p * _itemsPerPage);
                sqlListArgs.Add(_itemsPerPage);
                //获取总记录数
                var totalCount = Convert.ToInt32(DB.SExecuteScalar(sqlCount, sqlCountArgs.ToArray()));
                //计算分页数
                pages = (int)Math.Ceiling(totalCount * 1.0 / _itemsPerPage);
                //获取下注记录
                var res         = DB.SExecuteReader(sqlList, sqlListArgs.ToArray());
                var bettingList = new List <DBC.Betting>();
                foreach (var item in res)
                {
                    //数据记录不完整时跳过
                    try
                    {
                        var id      = Convert.ToInt32(item[0]);
                        var betting = new DBC.Betting(id);
                        bettingList.Add(betting);
                    }
                    catch { }
                }

                //获取总投注和总中奖
                var res2         = DB.SExecuteReader(sqlSum, sqlSumArgs.ToArray());
                var totalBetting = Utility.ToInt32(res2[0][0]);
                var totalWinning = Utility.ToInt32(res2[0][1]);

                var pagination = new Pagination();
                pagination.Pages   = pages;
                pagination.Current = p;
                pagination.BaseUrl = string.Format("/home/betting?userid={0}&beginDate={1}&endDate={2}", userid, beginDate.Value.ToString("yyyy-MM-dd"), endDate.Value.ToString("yyyy-MM-dd"));

                ViewBag.list         = GetBettingOverviewList(bettingList);
                ViewBag.pagination   = pagination;
                ViewBag.totalBetting = totalBetting;
                ViewBag.totalWinning = totalWinning;
                ViewBag.beginDate    = beginDate.Value;
                ViewBag.endDate      = endDate.Value;
                ViewBag.userid       = userid;
            }
            catch
            {
                ViewBag.errorText = "未查询到任何记录";
            }

            return(View());
        }