public IActionResult SelectPage(int pageIndex, int pageSize, [FromBody] List <FilterStr> filter, string order, bool isAsc)
        {
            try
            {
                string _order = string.Empty;
                Expression <Func <AircTypeTable, string> > orderby    = null;
                Expression <Func <AircTypeTable, int> >    orderbyint = null;
                Expression <Func <AircTypeTable, bool> > where = null;

                GetOrder(order, ref _order, ref orderby, ref orderbyint);
                if (filter != null && filter.Count > 0)
                {
                    string _filter = string.Empty;
                    foreach (FilterStr item in filter)
                    {
                        _filter += "p." + item.FieldName;
                        _filter  = SwitchOper.SwitchOperation(_filter, item);
                        switch (item.Value.GetType().Name.ToString())
                        {
                        case "String":
                        case "string":
                            if (item.Operation == OperationStr.Like)
                            {
                                _filter += item.Value;
                                _filter += "\")";
                            }
                            else if (item.Operation == OperationStr.Equal || item.Operation == OperationStr.NotEqual)
                            {
                                _filter += "\"";
                                _filter += item.Value;
                                _filter += "\"";
                            }
                            else
                            {
                                return(Json(new
                                {
                                    state = "-1",
                                    msg = "条件无效!"
                                }));
                            }
                            break;

                        case "Int32":
                        case "Int64":
                        case "Int":
                        case "Double":
                            if (item.Operation == OperationStr.Like)
                            {
                                return(Json(new
                                {
                                    state = "-1",
                                    msg = "条件无效!"
                                }));
                            }
                            else
                            {
                                _filter += item.Value;
                            }
                            break;

                        case "DateTime":
                            if (item.Operation == OperationStr.Like)
                            {
                                return(Json(new
                                {
                                    state = "-1",
                                    msg = "条件无效!"
                                }));
                            }
                            else
                            {
                                _filter += "DateTime.Parse(\"";
                                _filter += item.Value;
                                _filter += "\")";
                            }
                            break;

                        default:
                            break;
                        }
                        _filter += "&&";
                    }
                    _filter = _filter.Substring(0, _filter.Length - 2);
                    where   = new Interpreter().ParseAsExpression <Func <AircTypeTable, bool> >(_filter, "p");
                }

                if (orderbyint == null)
                {
                    return(Json(new
                    {
                        table = _repository.Query <AircTypeTable, string>(pageIndex, pageSize, where, orderby, null, isAsc),
                        state = "0",
                        msg = "操作成功!"
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        table = _repository.Query <AircTypeTable, int>(pageIndex, pageSize, where, orderbyint, null, isAsc),
                        state = "0",
                        msg = "操作成功!"
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    state = "-1",
                    msg = "非法操作!"
                }));
            }
        }
Beispiel #2
0
        public IActionResult GetTask(int userid, int pageIndex, int pageSize, [FromBody] List <FilterStr> filter, string order, bool isAsc)
        {
            if (userid != -1)
            {
                if (filter is null)
                {
                    filter = new List <FilterStr>();
                }
                FilterStr _f = new FilterStr
                {
                    FieldName = "UserId",
                    Operation = OperationStr.Equal,
                    Value     = userid
                };
                filter.Add(_f);
            }
            try
            {
                string _order = string.Empty;
                Expression <Func <TaskView, string> > orderby    = null;
                Expression <Func <TaskView, int> >    orderbyint = null;
                Expression <Func <TaskView, bool> > where = null;

                GetOrder(order, ref _order, ref orderby, ref orderbyint);
                if (filter != null && filter.Count > 0)
                {
                    string _filter = string.Empty;
                    foreach (FilterStr item in filter)
                    {
                        _filter += "p." + item.FieldName;
                        _filter  = SwitchOper.SwitchOperation(_filter, item);
                        switch (item.Value.GetType().Name.ToString())
                        {
                        case "String":
                        case "string":
                            if (item.Operation == OperationStr.Like)
                            {
                                _filter += item.Value;
                                _filter += "\")";
                            }
                            else if (item.Operation == OperationStr.Equal || item.Operation == OperationStr.NotEqual)
                            {
                                _filter += "\"";
                                _filter += item.Value;
                                _filter += "\"";
                            }
                            else
                            {
                                return(Json(new
                                {
                                    state = "-1",
                                    msg = "条件无效!"
                                }));
                            }
                            break;

                        case "Int32":
                        case "Int64":
                        case "Int":
                        case "Double":
                            if (item.Operation == OperationStr.Like)
                            {
                                return(Json(new
                                {
                                    state = "-1",
                                    msg = "条件无效!"
                                }));
                            }
                            else
                            {
                                _filter += item.Value;
                            }
                            break;

                        case "DateTime":
                            if (item.Operation == OperationStr.Like)
                            {
                                return(Json(new
                                {
                                    state = "-1",
                                    msg = "条件无效!"
                                }));
                            }
                            else
                            {
                                _filter += "DateTime.Parse(\"";
                                _filter += item.Value;
                                _filter += "\")";
                            }
                            break;

                        default:
                            break;
                        }
                        _filter += "&&";
                    }
                    _filter = _filter.Substring(0, _filter.Length - 2);
                    where   = new Interpreter().ParseAsExpression <Func <TaskView, bool> >(_filter, "p");
                }

                if (orderbyint == null)
                {
                    return(Json(new
                    {
                        table = _repository.Query <TaskView, string>(pageIndex, pageSize, where, orderby, null, isAsc),
                        state = "0",
                        msg = "操作成功!"
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        table = _repository.Query <TaskView, int>(pageIndex, pageSize, where, orderbyint, null, isAsc),
                        state = "0",
                        msg = "操作成功!"
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    state = "-1",
                    msg = "非法操作!"
                }));
            }

            //return Json(new
            //{
            //    table = _repository.GetTask(id),
            //    state = "0",
            //    msg = "操作成功!"
            //});
            //return Ok();
        }