Ejemplo n.º 1
0
        /// <summary>
        /// 获取所有分组表的记录。
        /// </summary>
        /// <returns></returns>
        public IActionResult GetAllGroup()
        {
            SpeedDataTable dt = AppServices.GetService <DataGroupService>().GetAllGroup();

            if (dt == null)
            {
                return(new JsonResult(new ResultMessage {
                    ResultCode = WebAPIStatus.DATABASE_EXCEPTION, Message = "获取分组信息错误"
                }));
            }
            ResultMessage ResultMsg = new ResultMessage();

            if (dt.Count < 1)
            {
                ResultMsg.ResultCode = WebAPIStatus.STATE_NO_DATA;
                ResultMsg.Message    = "没有数据。";
            }
            else
            {
                ResultMsg.ResultCode = WebAPIStatus.STATE_OK;
                ResultMsg.DataFormat = "encode:base64;charset:utf-8;text/json";
                ResultMsg.Data       = dt.SerializeJson();
                ResultMsg.Data       = Convert.ToBase64String(Encoding.UTF8.GetBytes(ResultMsg.Data));
            }
            return(new JsonResult(ResultMsg));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取指定分组下的数据。
        /// </summary>
        /// <returns></returns>
        public IActionResult GetDataByGroup()
        {
            Dictionary <string, object> data = GetPostData((string Key, string Value) => string.IsNullOrEmpty(Value) ? -1 : Convert.ToInt32(Value));

            if (data == null)
            {
                return(new JsonResult(new ResultMessage {
                    ResultCode = WebAPIStatus.STATE_FAIL, Message = "请求方式错误。"
                }));
            }
            if (!(data.ContainsKey("pageSize")))
            {
                return(new JsonResult(new ResultMessage {
                    ResultCode = WebAPIStatus.STATE_FAIL, Message = "缺少 pageSize 参数。"
                }));
            }
            if (!(data.ContainsKey("page")))
            {
                return(new JsonResult(new ResultMessage {
                    ResultCode = WebAPIStatus.STATE_FAIL, Message = "缺少 page 参数。"
                }));
            }
            if (!(data.ContainsKey("GID")))
            {
                return(new JsonResult(new ResultMessage {
                    ResultCode = WebAPIStatus.STATE_FAIL, Message = "缺少 GID 参数。"
                }));
            }
            try
            {
                int            Total = AppServices.GetService <DataService>().GetTotalCount((int)data["GID"]);
                SpeedDataTable dt    = AppServices.GetService <DataService>().GetGroupData((int)data["GID"], (int)data["pageSize"], (int)data["page"]);
                if (Total > 0 && dt.Count > 0)
                {
                    StringBuilder buff = new StringBuilder("{");
                    buff.AppendFormat("\"total\": {0}", Total);
                    buff.AppendFormat(", \"rows\": {0}", dt.SerializeJson());
                    buff.Append("}");
                    ResultMessage ResultMsg = new ResultMessage();
                    ResultMsg.ResultCode = WebAPIStatus.STATE_OK;
                    ResultMsg.DataFormat = "encode:base64;charset:utf-8;text/json";
                    ResultMsg.Data       = Convert.ToBase64String(Encoding.UTF8.GetBytes(buff.ToString()));
                    return(new JsonResult(ResultMsg));
                }
                else
                {
                    return(new JsonResult(new ResultMessage {
                        ResultCode = WebAPIStatus.STATE_NO_DATA, Message = "没有数据。"
                    }));
                }
            }
            catch (Exception Ex)
            {
                return(new JsonResult(new ResultMessage {
                    ResultCode = WebAPIStatus.INTERNAL_SERVER_ERROR, Message = Ex.Message
                }));
            }
        }