Beispiel #1
0
        public GetGridInfoReturn GetGridInfo(string GridCode, string OtherCondition, int CurUserId, string CurUserIden)
        {
            base.SetHeader();
            GridCode    = CPAppContext.FormatSqlPara(GridCode);
            CurUserIden = CPAppContext.FormatSqlPara(CurUserIden);
            if (OtherCondition != null)
            {
                OtherCondition = System.Web.HttpUtility.UrlDecode(OtherCondition);
                OtherCondition = OtherCondition.Replace("@", "%");
            }
            GetGridInfoReturn re = new GetGridInfoReturn();

            if (this.CheckUserIden(CurUserId, CurUserIden) == false)
            {
                re.Result   = false;
                re.ErrorMsg = "系统检测到非法获取数据,请传入正确的用户会话Key与用户Id参数!";
                return(re);
            }
            try
            {
                CPGrid Grid = CPGridEngine.Instance(CurUserId).GetGrid(GridCode, true, true);

                #region 处理列表列有统计值时,计算统计值结果
                CPGridEngine.Instance(CurUserId).StatisticsColumnSum(Grid, OtherCondition);
                #endregion

                #region 处理列是否显示
                Grid.ColumnCol.ForEach(t =>
                {
                    if (t.IsUseExpressionShow.Value)
                    {
                        string leftValue  = CPExpressionHelper.Instance.RunCompile(t.LeftExpression);
                        string rightValue = CPExpressionHelper.Instance.RunCompile(t.RightExpression);
                        bool bResult      = false;
                        if (t.ShowMethod == CPGridEnum.ShowMethodEnum.EqualTo)
                        {
                            if (leftValue.Equals(rightValue, StringComparison.CurrentCultureIgnoreCase))
                            {
                                bResult = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    bResult = false;
                                }
                                else
                                {
                                    bResult = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.NotEqualTo)
                        {
                            if (leftValue.Equals(rightValue, StringComparison.CurrentCultureIgnoreCase) == false)
                            {
                                bResult = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    bResult = false;
                                }
                                else
                                {
                                    bResult = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.GreaterThanOrEqualTo)
                        {
                            double dLeft  = 0;
                            double dRight = 0;
                            try
                            {
                                dLeft = Convert.ToDouble(leftValue);
                            }
                            catch (Exception ex) { }
                            try
                            {
                                dRight = Convert.ToDouble(rightValue);
                            }
                            catch (Exception ex) { }
                            if (dLeft >= dRight)
                            {
                                bResult = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    bResult = false;
                                }
                                else
                                {
                                    bResult = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.GreaterThan)
                        {
                            double dLeft  = 0;
                            double dRight = 0;
                            try
                            {
                                dLeft = Convert.ToDouble(leftValue);
                            }
                            catch (Exception ex) { }
                            try
                            {
                                dRight = Convert.ToDouble(rightValue);
                            }
                            catch (Exception ex) { }
                            if (dLeft > dRight)
                            {
                                bResult = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    bResult = false;
                                }
                                else
                                {
                                    bResult = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.LessThanOrEqualTo)
                        {
                            double dLeft  = 0;
                            double dRight = 0;
                            try
                            {
                                dLeft = Convert.ToDouble(leftValue);
                            }
                            catch (Exception ex) { }
                            try
                            {
                                dRight = Convert.ToDouble(rightValue);
                            }
                            catch (Exception ex) { }
                            if (dLeft <= dRight)
                            {
                                bResult = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    bResult = false;
                                }
                                else
                                {
                                    bResult = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.LessThan)
                        {
                            double dLeft  = 0;
                            double dRight = 0;
                            try
                            {
                                dLeft = Convert.ToDouble(leftValue);
                            }
                            catch (Exception ex) { }
                            try
                            {
                                dRight = Convert.ToDouble(rightValue);
                            }
                            catch (Exception ex) { }
                            if (dLeft < dRight)
                            {
                                bResult = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    bResult = false;
                                }
                                else
                                {
                                    bResult = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.Contains)
                        {
                            if (leftValue.IndexOf(rightValue, StringComparison.CurrentCultureIgnoreCase) != -1)
                            {
                                bResult = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    bResult = false;
                                }
                                else
                                {
                                    bResult = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.DoesNotContain)
                        {
                            if (leftValue.IndexOf(rightValue, StringComparison.CurrentCultureIgnoreCase) == -1)
                            {
                                bResult = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    bResult = false;
                                }
                                else
                                {
                                    bResult = true;
                                }
                            }
                        }
                        if (bResult == false)
                        {
                            t.IsShow = false;
                        }
                    }
                });
                #endregion
                AutoMapper.Mapper.Initialize(cfg =>
                {
                    cfg.CreateMap <CPGrid, CPGridClient>();
                });
                re.Grid = AutoMapper.Mapper.Map <CPGridClient>(Grid);

                #region 处理按钮
                List <CPGridFunc> tCol = new List <CPGridFunc>();
                re.Grid.FuncCol.ForEach(t =>
                {
                    bool isShow = true;
                    if (t.IsUseExpressionShow.Value)
                    {
                        string leftValue  = CPExpressionHelper.Instance.RunCompile(t.LeftExpression);
                        string rightValue = CPExpressionHelper.Instance.RunCompile(t.RightExpression);

                        if (t.ShowMethod == CPGridEnum.ShowMethodEnum.EqualTo)
                        {
                            if (leftValue.Equals(rightValue, StringComparison.CurrentCultureIgnoreCase))
                            {
                                isShow = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    isShow = false;
                                }
                                else
                                {
                                    isShow = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.NotEqualTo)
                        {
                            if (leftValue.Equals(rightValue, StringComparison.CurrentCultureIgnoreCase) == false)
                            {
                                isShow = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    isShow = false;
                                }
                                else
                                {
                                    isShow = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.GreaterThanOrEqualTo)
                        {
                            double dLeft  = 0;
                            double dRight = 0;
                            try
                            {
                                dLeft = Convert.ToDouble(leftValue);
                            }
                            catch (Exception ex) { }
                            try
                            {
                                dRight = Convert.ToDouble(rightValue);
                            }
                            catch (Exception ex) { }
                            if (dLeft >= dRight)
                            {
                                isShow = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    isShow = false;
                                }
                                else
                                {
                                    isShow = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.GreaterThan)
                        {
                            double dLeft  = 0;
                            double dRight = 0;
                            try
                            {
                                dLeft = Convert.ToDouble(leftValue);
                            }
                            catch (Exception ex) { }
                            try
                            {
                                dRight = Convert.ToDouble(rightValue);
                            }
                            catch (Exception ex) { }
                            if (dLeft > dRight)
                            {
                                isShow = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    isShow = false;
                                }
                                else
                                {
                                    isShow = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.LessThanOrEqualTo)
                        {
                            double dLeft  = 0;
                            double dRight = 0;
                            try
                            {
                                dLeft = Convert.ToDouble(leftValue);
                            }
                            catch (Exception ex) { }
                            try
                            {
                                dRight = Convert.ToDouble(rightValue);
                            }
                            catch (Exception ex) { }
                            if (dLeft <= dRight)
                            {
                                isShow = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    isShow = false;
                                }
                                else
                                {
                                    isShow = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.LessThan)
                        {
                            double dLeft  = 0;
                            double dRight = 0;
                            try
                            {
                                dLeft = Convert.ToDouble(leftValue);
                            }
                            catch (Exception ex) { }
                            try
                            {
                                dRight = Convert.ToDouble(rightValue);
                            }
                            catch (Exception ex) { }
                            if (dLeft < dRight)
                            {
                                isShow = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    isShow = false;
                                }
                                else
                                {
                                    isShow = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.Contains)
                        {
                            if (leftValue.IndexOf(rightValue, StringComparison.CurrentCultureIgnoreCase) != -1)
                            {
                                isShow = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    isShow = false;
                                }
                                else
                                {
                                    isShow = true;
                                }
                            }
                        }
                        else if (t.ShowMethod == CPGridEnum.ShowMethodEnum.DoesNotContain)
                        {
                            if (leftValue.IndexOf(rightValue, StringComparison.CurrentCultureIgnoreCase) == -1)
                            {
                                isShow = t.IsShowByExpression.Value;
                            }
                            else
                            {
                                if (t.IsShowByExpression.Value)
                                {
                                    isShow = false;
                                }
                                else
                                {
                                    isShow = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        isShow = true;
                    }
                    if (isShow)
                    {
                        t.FuncContext = CPExpressionHelper.Instance.RunCompile(t.FuncContext);
                        tCol.Add(t);
                    }
                });
                #region 添加修改配置按钮
                if (re.Grid.SysId.HasValue && re.Grid.SysId.Value.Equals(CPAppContext.InnerSysId) == false)
                {
                    string UserAdminSysIds = CPExpressionHelper.Instance.RunCompile("${CPUser.UserAdminSysIds()}");
                    if (UserAdminSysIds.Split(',').ToList().Contains(re.Grid.SysId.ToString()))
                    {
                        CPGridFunc func1 = new CPGridFunc();
                        func1.FuncTitle           = "修改配置";
                        func1.FuncOrder           = 999999;
                        func1.FuncType            = CPGridEnum.FuncTypeEnum.ExecuteJs;
                        func1.FuncOpenWinTitle    = func1.FuncTitle;
                        func1.FuncIcon            = "icon-shezhi1";
                        func1.IsUseExpressionShow = false;
                        func1.OpenWinHeight       = 768;
                        func1.OpenWinWidth        = 1024;
                        func1.FuncContext         = "CPGridUpdateConfig(" + re.Grid.Id + ")";
                        tCol.Add(func1);
                    }
                }
                #endregion
                re.Grid.FuncCol = tCol;
                #endregion

                #region 处理多表头
                re.Grid.HeaderGroup = new List <GetGridInfoHeaderGroup>();
                List <string> addedHeader = new List <string>();
                re.Grid.ColumnCol.ForEach(t =>
                {
                    if (addedHeader.Contains(t.ColumnTitleGroup1) == false)
                    {
                        GetGridInfoHeaderGroup group1 = new GetGridInfoHeaderGroup();
                        group1.GroupTitle             = t.ColumnTitleGroup1;
                        group1.ChildColumnId          = new List <int>();
                        group1.ChildGroupCol          = new List <GetGridInfoHeaderGroup>();
                        #region 找出所有的子列
                        List <CPGridColumn> tmpCol = re.Grid.ColumnCol.Where(c => c.ColumnTitleGroup1.Equals(t.ColumnTitleGroup1)).ToList();
                        if (string.IsNullOrEmpty(t.ColumnTitleGroup1))
                        {
                            tmpCol.ForEach(c =>
                            {
                                group1.ChildColumnId.Add(c.Id);
                            });
                        }
                        else
                        {
                            List <string> added2 = new List <string>();
                            tmpCol.ForEach(c =>
                            {
                                //如果一级不为空,则看看有没有二级子表头
                                if (added2.Contains(c.ColumnTitleGroup2) == false)
                                {
                                    List <CPGridColumn> tmpCol2       = re.Grid.ColumnCol.Where(f => f.ColumnTitleGroup1.Equals(t.ColumnTitleGroup1) && f.ColumnTitleGroup2.Equals(c.ColumnTitleGroup2)).ToList();
                                    GetGridInfoHeaderGroup groupChild = new GetGridInfoHeaderGroup();
                                    groupChild.GroupTitle             = c.ColumnTitleGroup2;
                                    groupChild.ChildColumnId          = new List <int>();
                                    groupChild.ChildGroupCol          = new List <GetGridInfoHeaderGroup>();
                                    tmpCol2.ForEach(f =>
                                    {
                                        groupChild.ChildColumnId.Add(f.Id);
                                    });
                                    added2.Add(c.ColumnTitleGroup2);
                                    group1.ChildGroupCol.Add(groupChild);
                                }
                            });
                        }
                        #endregion
                        re.Grid.HeaderGroup.Add(group1);
                        addedHeader.Add(t.ColumnTitleGroup1);
                    }
                });
                #endregion
                re.Result = true;
                #region 处理编辑列表,下拉 列表数据源
                re.ListDataJson = "";
                try
                {
                    re.ListDataJson = JsonConvert.SerializeObject(CPGridEngine.Instance(CurUserId).ReadListDataAndFormat(re.Grid));
                }
                catch (Exception ex)
                {
                    re.Result   = false;
                    re.ErrorMsg = ex.Message;
                }
                #endregion

                return(re);
            }
            catch (Exception ex)
            {
                re.Result   = false;
                re.ErrorMsg = ex.Message.ToString();
                return(re);
            }
        }
Beispiel #2
0
        public bool ImportInnerFunc(int gridId)
        {
            List <CPGridFunc> col = new List <CPGridFunc>();

            #region 新增
            CPGridFunc f1 = new CPGridFunc();
            f1.GridId              = gridId;
            f1.FuncOrder           = 10;
            f1.FuncIcon            = "icon-add";
            f1.FuncTitle           = "新增";
            f1.FuncType            = CPGridEnum.FuncTypeEnum.TopOpenNewModelAndRefresh;
            f1.OpenWinWidth        = 1024;
            f1.OpenWinHeight       = 760;
            f1.FuncOpenWinTitle    = "新增";
            f1.IsUseExpressionShow = false;
            f1.ShowMethod          = CPGridEnum.ShowMethodEnum.Contains;
            col.Add(f1);
            #endregion

            #region 修改
            CPGridFunc f2 = new CPGridFunc();
            f2.GridId              = gridId;
            f2.FuncOrder           = 20;
            f2.FuncIcon            = "icon-fankui";
            f2.FuncTitle           = "修改";
            f2.FuncType            = CPGridEnum.FuncTypeEnum.Save;
            f2.OpenWinWidth        = 1024;
            f2.OpenWinHeight       = 760;
            f2.FuncOpenWinTitle    = "修改";
            f2.IsUseExpressionShow = false;
            f2.ShowMethod          = CPGridEnum.ShowMethodEnum.Contains;
            col.Add(f2);
            #endregion

            #region  除
            CPGridFunc f3 = new CPGridFunc();
            f3.GridId              = gridId;
            f3.FuncOrder           = 30;
            f3.FuncTitle           = "删除";
            f3.FuncIcon            = "icon-guanbi1";
            f3.FuncType            = CPGridEnum.FuncTypeEnum.Delete;
            f3.OpenWinWidth        = 1024;
            f3.OpenWinHeight       = 760;
            f3.FuncOpenWinTitle    = "删除";
            f3.IsUseExpressionShow = false;
            f3.ShowMethod          = CPGridEnum.ShowMethodEnum.Contains;
            col.Add(f3);
            #endregion

            #region 导出Excel
            CPGridFunc f4 = new CPGridFunc();
            f4.GridId              = gridId;
            f4.FuncOrder           = 40;
            f4.FuncTitle           = "导出Excel";
            f4.FuncIcon            = "icon-activity";
            f4.FuncType            = CPGridEnum.FuncTypeEnum.ExportExcel;
            f4.OpenWinWidth        = 1024;
            f4.OpenWinHeight       = 760;
            f4.FuncOpenWinTitle    = "导出Excel";
            f4.IsUseExpressionShow = false;
            f4.ShowMethod          = CPGridEnum.ShowMethodEnum.Contains;
            col.Add(f4);
            #endregion
            this._CPGridFuncRep.Add(col);
            return(true);
        }