Exemplo n.º 1
0
        /// <summary>
        /// 添加用户选择的游戏
        /// </summary>
        /// <param name="gameid"></param>
        /// <returns></returns>
        private string addGame(HttpContext context)
        {
            string gameid     = context.Request["TypeIdss"];
            string username   = context.Request["username"];    //这个变量获取openid
            string machineid  = context.Request["machineids"];
            string jieBiaoNum = context.Request["jieBiaoNum"];
            string nickname   = context.Request["nickname"];    //这个变量获取微信昵称
            Json   jsonResult = new Json();

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(nickname))
            {
                jsonResult.Success = false;
                jsonResult.Msg     = "用户昵称或id不能为空";

                string json = JsonConvert.SerializeObject(jsonResult);
                return(json);
            }

            //首先判断是否有这个用户,如果没有,则创建一个
            int count = ms.checkUser(username, nickname);

            if (count <= 0)
            {
                //jsonResult.Success = false;
                //jsonResult.Msg = "有异常";
                //return JsonConvert.SerializeObject(jsonResult);
            }


            string time   = DateTime.Now.ToString();
            int    result = ms.addUserChooseGames(gameid, username, time, "0", machineid, jieBiaoNum);

            if (result > 0)
            {
                jsonResult.Success = true;
                jsonResult.Msg     = "添加成功";
            }
            else if (result == -2)
            {
                jsonResult.Success = false;
                jsonResult.Msg     = "当前还有游戏没有完成,不能添加";
            }
            else if (result == -3)
            {
                jsonResult.Success = false;
                jsonResult.Msg     = "设备异常,请等待维护";
            }
            else
            {
                jsonResult.Success = false;
                jsonResult.Msg     = "未知错误";
            }
            string strJson = JsonConvert.SerializeObject(jsonResult);

            return(strJson);
        }