Exemplo n.º 1
0
 public DataTable ReadData(CPGrid gridObj, int currentPage,
                           int pageSize, string otherCondition, string orderBy, out int recordSize)
 {
     if (string.IsNullOrEmpty(orderBy))
     {
         orderBy = gridObj.DataOrder;
     }
     return(this._CPGridRep.ReadData(gridObj, currentPage, pageSize, otherCondition, orderBy, out recordSize));
 }
Exemplo n.º 2
0
        /// <summary>
        /// 如果列表有编辑列,获取编辑列类型是下拉列表的数据源
        /// </summary>
        /// <param name="gridObj"></param>
        /// <returns></returns>
        public Dictionary <string, string> ReadListDataAndFormat(CPGrid gridObj)
        {
            Dictionary <string, string> col = new Dictionary <string, string>();

            gridObj.ColumnCol.ForEach(t => {
                if (t.ColumnType == CPGridEnum.ColumnTypeEnum.DropDownListEditor)
                {
                    if (string.IsNullOrEmpty(t.FieldEnumDataIns))
                    {
                        throw new Exception("字段" + t.FieldName + "配置成下拉列表编辑列,但未配置下拉列表数据源数据库实例");
                    }
                    if (string.IsNullOrEmpty(t.FieldEnumDataSource))
                    {
                        throw new Exception("字段" + t.FieldName + "配置成下拉列表编辑列,但未配置下拉列表数据源");
                    }
                    DbHelper dbHelper = new DbHelper(t.FieldEnumDataIns, CPAppContext.CurDbType());
                    string strSql     = t.FieldEnumDataSource;
                    try
                    {
                        strSql          = CPExpressionHelper.Instance.RunCompile(strSql);
                        DataTable dt    = dbHelper.ExecuteDataTable(strSql);
                        DataTable dtNew = new DataTable();
                        dtNew.Columns.Add(new DataColumn()
                        {
                            ColumnName = "textEx", DataType = typeof(string)
                        });


                        dtNew.Columns.Add(new DataColumn()
                        {
                            ColumnName = "valueEx", DataType = typeof(string)
                        });
                        foreach (DataRow dr in dt.Rows)
                        {
                            DataRow newDR   = dtNew.NewRow();
                            newDR["textEx"] = dr[0];
                            if (dt.Columns[1].DataType == Type.GetType("System.Boolean"))
                            {
                                newDR["valueEx"] = dr[1].ToString().Trim().ToLower();
                            }
                            else
                            {
                                newDR["valueEx"] = dr[1];
                            }
                            dtNew.Rows.Add(newDR);
                        }
                        col.Add("Column" + t.Id.ToString(), CPUtils.DataTable2Json(dtNew));
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("执行sql语句:" + strSql + "出错,详细信息为:" + ex.Message);
                    }
                }
            });
            return(col);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 统计列表列的统计值
 /// </summary>
 /// <param name="gridObj"></param>
 /// <returns></returns>
 public bool StatisticsColumnSum(CPGrid gridObj, string otherCondition)
 {
     gridObj.ColumnCol.ForEach(t => {
         if (t.IsShowSum.Value)
         {
             t.TempSumValue = this._CPGridRep.StatisticsColumnSum(gridObj, t, otherCondition);
             if (string.IsNullOrEmpty(t.NumberFormat) == false)
             {
                 try
                 {
                     t.TempSumValue = Convert.ToDecimal(t.TempSumValue).ToString(t.NumberFormat);
                 }
                 catch (Exception ex) { ex.ToString(); }
             }
         }
     });
     return(true);
 }
Exemplo n.º 4
0
        public CPWebApiBaseReturnEntity DeleteGridData(int CurUserId, string CurUserIden, string GridCode, string DataPks)
        {
            base.SetHeader();
            CPWebApiBaseReturnEntity re = new CPWebApiBaseReturnEntity();

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

                string[] dataPKValueArray = DataPks.Split('@');
                if (string.IsNullOrEmpty(grid.DelDataSql))
                {
                    string[] pkArray = grid.PKFieldName.Split(',');
                    for (int m = 0; m < dataPKValueArray.Length; m++)
                    {
                        string strSql = "";
                        strSql = "DELETE FROM  " + grid.MainTableName + " WHERE  ";
                        string[] vArray = dataPKValueArray[m].Split(',');
                        for (int i = 0; i < pkArray.Length; i++)
                        {
                            if (i == 0)
                            {
                                strSql += pkArray[i] + "='" + vArray[i] + "'";
                            }
                            else
                            {
                                strSql += " AND " + pkArray[i] + "='" + vArray[i] + "'";
                            }
                        }
                        sb.Append(strSql);
                    }
                }
                else
                {
                    //自己配置了查询条件
                    string strSql = grid.DelDataSql;
                    DataPks = "'" + DataPks.Replace("@", "','") + "'";
                    strSql  = strSql.Replace("{@PKValues@}", DataPks);
                    strSql  = CPExpressionHelper.Instance.RunCompile(strSql);
                    sb.Append(strSql);
                }
                if (sb.Length > 0)
                {
                    dbHelper.ExecuteNonQuery(sb.ToString());
                }
                re.Result = true;
                return(re);
            }
            catch (Exception ex)
            {
                re.Result   = false;
                re.ErrorMsg = ex.Message.ToString();
                return(re);
            }
        }
Exemplo n.º 5
0
        public CPWebApiBaseReturnEntity UpdateGridData([FromBody] UpdateGridDataInput input)
        {
            base.SetHeader();

            CPWebApiBaseReturnEntity re = new CPWebApiBaseReturnEntity();

            if (this.CheckUserIden(input.CurUserId, input.CurUserIden) == false)
            {
                re.Result   = false;
                re.ErrorMsg = "系统检测到非法获取数据,请传入正确的用户会话Key与用户Id参数!";
                return(re);
            }
            try
            {
                CPGrid        grid     = CPGridEngine.Instance(input.CurUserId).GetGrid(input.GridCode, false, false);
                DbHelper      dbHelper = new DbHelper(grid.DbIns, CPAppContext.CurDbType());
                StringBuilder sb       = new StringBuilder();
                string[]      pkArray  = grid.PKFieldName.Split(',');
                input.Items.ForEach(t =>
                {
                    string strSql = "";
                    strSql        = "UPDATE " + grid.MainTableName + " SET ";
                    for (int i = 0; i < t.FieldNamCol.Count; i++)
                    {
                        string sValue = t.FieldValueCol[i];
                        if (string.IsNullOrEmpty(sValue) == false)
                        {
                            sValue = sValue.Replace("'", "''");
                        }
                        else
                        {
                            sValue = "";
                        }
                        if (i == 0)
                        {
                            strSql += t.FieldNamCol[i] + "='" + sValue + "'";
                        }
                        else
                        {
                            strSql += "," + t.FieldNamCol[i] + "='" + sValue + "'";
                        }
                    }
                    string[] dataPKArray = t.DataPK.Split(',');
                    for (int i = 0; i < pkArray.Length; i++)
                    {
                        if (i == 0)
                        {
                            strSql += " WHERE " + pkArray[i] + "='" + dataPKArray[i] + "'";
                        }
                        else
                        {
                            strSql += " AND " + pkArray[i] + "='" + dataPKArray[i] + "'";
                        }
                    }
                    if (sb.Length > 0)
                    {
                        sb.Append(";");
                    }
                    sb.Append(strSql);
                });
                if (sb.Length > 0)
                {
                    dbHelper.ExecuteNonQuery(sb.ToString());
                }
                re.Result = true;
                return(re);
            }
            catch (Exception ex)
            {
                re.Result   = false;
                re.ErrorMsg = ex.Message.ToString();
                return(re);
            }
        }
Exemplo n.º 6
0
        public GetGridDataReturn GetGridData(string GridCode, int CurUserId, string CurUserIden,
                                             int page, int pageSize, string OtherCondition)
        {
            base.SetHeader();
            GridCode    = CPAppContext.FormatSqlPara(GridCode);
            CurUserIden = CPAppContext.FormatSqlPara(CurUserIden);
            //OtherCondition = CPAppContext.FormatSqlPara(OtherCondition);
            if (OtherCondition != null)
            {
                OtherCondition = System.Web.HttpUtility.UrlDecode(OtherCondition);
                OtherCondition = OtherCondition.Replace("@", "%");
            }
            GetGridDataReturn re = new GetGridDataReturn();

            try
            {
                CPGrid Grid    = CPGridEngine.Instance(CurUserId).GetGrid(GridCode, true, true);
                string orderBy = "";
                #region 获取排序字段
                List <string> querys     = CPAppContext.GetHttpContext().Request.Query.Keys.Where(t => t.StartsWith("sort[")).ToList();
                var           queryCount = querys.Count(m => m.EndsWith("[field]"));
                for (int i = 0; i < queryCount; i++)
                {
                    //请查询字段和对应的值存储在一个字典中
                    string field = CPAppContext.QueryString <string>("sort[" + i + "][field]");
                    field = field.Replace("Column", "");
                    List <CPGridColumn> colTmp = Grid.ColumnCol.Where(c => c.Id.Equals(int.Parse(field))).ToList();
                    if (colTmp.Count > 0)
                    {
                        field = colTmp[0].FieldName;
                    }
                    string fieldValue = CPAppContext.QueryString <string>("sort[" + i + "][dir]");
                    if (string.IsNullOrEmpty(orderBy))
                    {
                        orderBy = field + " " + fieldValue;
                    }
                    else
                    {
                        orderBy += "," + field + " " + fieldValue;
                    }
                }
                #endregion


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

                try
                {
                    int       recordSize = 0;
                    DataTable dt         = CPGridEngine.Instance(CurUserId).ReadDataAndFormat(Grid, page, pageSize, OtherCondition, orderBy, out recordSize);
                    re.RecordSize = recordSize;
                    re.DataJson   = CPUtils.DataTable2Json(dt);
                    re.Result     = true;
                }
                catch (Exception ex)
                {
                    re.Result   = false;
                    re.ErrorMsg = ex.Message.ToString();
                }

                return(re);
            }
            catch (Exception ex)
            {
                re.Result   = false;
                re.ErrorMsg = ex.Message.ToString();
                return(re);
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        public bool SyncFieldInfo(int gridId)
        {
            CPGrid    grid       = this.GetGrid(gridId, true, false);
            int       recordSize = 0;
            DataTable dt         = this.ReadData(grid, 1, 10, "1=2", "", out recordSize);
            //记录需要删除的字段
            List <CPGridColumn> deleteColumns = new List <CPGridColumn>();
            List <CPGridColumn> addColumns    = new List <CPGridColumn>();
            int nIndex = 10;

            if (grid.ColumnCol.Count > 0)
            {
                grid.ColumnCol = grid.ColumnCol.OrderBy(t => t.ShowOrder.Value).ToList();
                nIndex         = grid.ColumnCol[grid.ColumnCol.Count - 1].ShowOrder.Value + 10;
            }

            foreach (DataColumn dc in dt.Columns)
            {
                if (dc.ColumnName.Equals("ROWSTAT", StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }
                List <CPGridColumn> col = grid.ColumnCol.Where(c => c.FieldName.Equals(dc.ColumnName)).ToList();
                if (col.Count <= 0)
                {
                    #region 创建新的列

                    CPGridColumn column = new CPGridColumn();
                    column.GridId      = grid.Id;
                    column.ColumnTitle = dc.ColumnName;
                    column.FieldName   = dc.ColumnName;
                    if (dc.DataType.Equals(Type.GetType("System.DateTime")))
                    {
                        column.ColumnType = CPGridEnum.ColumnTypeEnum.DateTime;
                    }

                    else
                    {
                        column.ColumnType = CPGridEnum.ColumnTypeEnum.Normal;
                    }
                    column.IsSearchShow        = true;
                    column.SearchShowType      = CPGridEnum.SearchShowTypeEnum.Textbox;
                    column.SearchShowOrder     = nIndex;
                    column.IsShow              = true;
                    column.ShowOrder           = nIndex;
                    column.ShowPosition        = CPGridEnum.ShowPositionEnum.Left;
                    column.ShowWidth           = 10;
                    column.MaxString           = 0;
                    column.IsCanOrder          = true;
                    column.IsMergeRow          = false;
                    column.TimeFormat          = "yyyy-MM-dd";
                    column.TargetContent       = "";
                    column.OpenWinWidth        = 1000;
                    column.OpenWinHeight       = 700;
                    column.IsCanExport         = true;
                    column.IsShowSum           = false;
                    column.TargetType          = CPGridEnum.TargetTypeEnum.TopOpenNewModelAndRefresh;
                    column.ShowMethod          = CPGridEnum.ShowMethodEnum.Contains;
                    column.IsUseExpressionShow = false;
                    column.IsShowByExpression  = true;
                    #endregion
                    addColumns.Add(column);
                    nIndex = nIndex + 10;
                }
            }
            //记录要删除的列

            foreach (CPGridColumn column in grid.ColumnCol)
            {
                if (dt.Columns.Contains(column.FieldName) == false && column.ColumnType != CPGridEnum.ColumnTypeEnum.Number)
                {
                    deleteColumns.Add(column);
                }
            }
            bool b = true;
            //由于ef core批量写入数据时,采用了批处理方法,但这种方式会导致写入顺序错,暂时没有找到什么方法,所以改成一条条写。
            this._CPGridColumnRep.AddOneByOne(addColumns);
            this._CPGridColumnRep.Delete(deleteColumns);
            return(b);
        }
Exemplo n.º 9
0
        public DataTable ReadDataAndFormat(CPGrid gridObj, int currentPage,
                                           int pageSize, string otherCondition, string orderBy, out int recordSize)
        {
            DataTable dt = this.ReadData(gridObj, currentPage, pageSize, otherCondition, orderBy, out recordSize);

            #region 重新生成新的DT
            DataTable  dtNew   = new DataTable();
            DataColumn dcItem0 = new DataColumn();
            dcItem0.ColumnName = "ColumnCPGridPK";
            dcItem0.DataType   = Type.GetType("System.String");
            dtNew.Columns.Add(dcItem0);
            foreach (CPGridColumn item in gridObj.ColumnCol)
            {
                if (item.IsShow == false)
                {
                    continue;
                }
                DataColumn dcItem = new DataColumn();
                dcItem.ColumnName = "Column" + item.Id.ToString();
                dcItem.DataType   = Type.GetType("System.String");
                dtNew.Columns.Add(dcItem);
                if (item.ColumnType == CPGridEnum.ColumnTypeEnum.TextHref || item.ColumnType == CPGridEnum.ColumnTypeEnum.PicHref)
                {
                    DataColumn dcItem2 = new DataColumn();
                    dcItem2.ColumnName = "ColumnTargetContent" + item.Id.ToString();
                    dcItem2.DataType   = Type.GetType("System.String");
                    dtNew.Columns.Add(dcItem2);
                }
                if (item.ColumnType == CPGridEnum.ColumnTypeEnum.TextBoxEditor ||
                    item.ColumnType == CPGridEnum.ColumnTypeEnum.DropDownListEditor ||
                    item.ColumnType == CPGridEnum.ColumnTypeEnum.TimeSelectEditor
                    )
                {
                    if (string.IsNullOrEmpty(item.EventMethod) == false && string.IsNullOrEmpty(item.EventName) == false)
                    {
                        DataColumn dcItem3 = new DataColumn();
                        dcItem3.ColumnName = "ColumnEventMethod" + item.Id.ToString();
                        dcItem3.DataType   = Type.GetType("System.String");
                        dtNew.Columns.Add(dcItem3);

                        DataColumn dcItem4 = new DataColumn();
                        dcItem4.ColumnName = "ColumnEventName" + item.Id.ToString();
                        dcItem4.DataType   = Type.GetType("System.String");
                        dtNew.Columns.Add(dcItem4);
                    }
                }
            }
            if (gridObj.IsGroup.Value && string.IsNullOrEmpty(gridObj.GroupField) == false)
            {
                //启用了分组
                string[] gArray = gridObj.GroupField.Split(',');
                for (int i = 0; i < gArray.Length; i++)
                {
                    if (string.IsNullOrEmpty(gArray[i]))
                    {
                        continue;
                    }
                    DataColumn Group = new DataColumn();
                    Group.ColumnName = gArray[i].Trim() + "_CPGroup";
                    Group.DataType   = Type.GetType("System.String");
                    dtNew.Columns.Add(Group);
                }
            }
            #endregion
            int nIndex = (currentPage - 1) * pageSize + 1;
            foreach (DataRow dr in dt.Rows)
            {
                DataRow newRow = dtNew.NewRow();
                string  dataPK = "";
                #region 主键值
                if (string.IsNullOrEmpty(gridObj.PKFieldName) == false)
                {
                    string[] pkArray = gridObj.PKFieldName.Split(',');
                    string   sValue  = "";
                    for (int i = 0; i < pkArray.Length; i++)
                    {
                        object obj = dr[pkArray[i].Trim()];
                        if (Convert.IsDBNull(obj) || obj == null)
                        {
                            if (i == 0)
                            {
                                sValue = "";
                            }
                            else
                            {
                                sValue += ",";
                            }
                        }
                        else
                        {
                            if (i == 0)
                            {
                                sValue = obj.ToString();
                            }
                            else
                            {
                                sValue += "," + obj.ToString();
                            }
                        }
                    }
                    dataPK = sValue;
                }
                else
                {
                    dataPK = "";
                }
                #endregion
                newRow["ColumnCPGridPK"] = dataPK;

                #region 循环列
                foreach (CPGridColumn item in gridObj.ColumnCol)
                {
                    if (item.IsShow == false)
                    {
                        continue;
                    }
                    object objValue = null;
                    #region 处理列值
                    if (item.ColumnType == CPGridEnum.ColumnTypeEnum.Number)
                    {//序号
                        objValue = nIndex;
                    }
                    else if (item.ColumnType == CPGridEnum.ColumnTypeEnum.CheckBox)
                    {
                        //复选
                        objValue = dataPK;
                    }
                    else if (item.ColumnType == CPGridEnum.ColumnTypeEnum.Radio)
                    {
                        //单选
                        objValue = dataPK;
                    }
                    else if (item.ColumnType == CPGridEnum.ColumnTypeEnum.Normal)
                    {
                        //普通
                        if (string.IsNullOrEmpty(item.FieldName))
                        {
                            objValue = "";
                        }
                        else
                        {
                            objValue = dr[item.FieldName.Trim()];
                            if (string.IsNullOrEmpty(item.NumberFormat) == false)
                            {
                                try
                                {
                                    objValue = Convert.ToDecimal(objValue).ToString(item.NumberFormat);
                                }
                                catch (Exception ex) { ex.ToString(); }
                            }
                        }
                    }
                    else if (item.ColumnType == CPGridEnum.ColumnTypeEnum.DateTime)
                    {
                        #region 日期
                        if (string.IsNullOrEmpty(item.FieldName))
                        {
                            objValue = "";
                        }
                        else
                        {
                            objValue = dr[item.FieldName.Trim()];
                            try
                            {
                                DateTime dtTime = Convert.ToDateTime(objValue);
                                objValue = dtTime.ToString(item.TimeFormat);
                            }
                            catch (Exception et) { et.ToString(); }
                        }
                        #endregion
                    }
                    else if (item.ColumnType == CPGridEnum.ColumnTypeEnum.ListInnerDel)
                    {
                        #region 内置删除列
                        if (string.IsNullOrEmpty(item.FieldName))
                        {
                            objValue = "";
                        }
                        else
                        {
                            objValue = dr[item.FieldName.Trim()];
                        }
                        #endregion
                    }
                    else if (item.ColumnType == CPGridEnum.ColumnTypeEnum.Template)
                    {
                        #region 模板列
                        if (string.IsNullOrEmpty(item.TemplateContent))
                        {
                            if (string.IsNullOrEmpty(item.FieldName))
                            {
                                objValue = "";
                            }
                            else
                            {
                                objValue = dr[item.FieldName.Trim()];
                            }
                        }
                        else
                        {
                            string sTemp = item.TemplateContent;
                            CPExpressionHelper.Instance.Add(CPGridExpression.DataRowKey, dr);
                            sTemp = CPExpressionHelper.Instance.RunCompile(sTemp);
                            CPExpressionHelper.Instance.Remove(CPGridExpression.DataRowKey);
                            objValue = sTemp;
                        }
                        #endregion
                    }
                    else if (item.ColumnType == CPGridEnum.ColumnTypeEnum.PicHref)
                    {
                        #region 图片超链接列
                        string sTemp = item.TargetContent;
                        CPExpressionHelper.Instance.Add(CPGridExpression.DataRowKey, dr);
                        sTemp = CPExpressionHelper.Instance.RunCompile(sTemp);
                        CPExpressionHelper.Instance.Remove(CPGridExpression.DataRowKey);
                        newRow["ColumnTargetContent" + item.Id] = sTemp;
                        if (string.IsNullOrEmpty(item.ColumnIconOrText))
                        {
                            objValue = Convert.IsDBNull(dr[item.FieldName]) ? "" : dr[item.FieldName].ToString();
                        }
                        else
                        {
                            objValue = item.ColumnIconOrText;
                        }
                        #endregion
                    }
                    else if (item.ColumnType == CPGridEnum.ColumnTypeEnum.TextHref)
                    {
                        #region 文字超链接列
                        string sTemp = item.TargetContent;
                        CPExpressionHelper.Instance.Add(CPGridExpression.DataRowKey, dr);
                        sTemp = CPExpressionHelper.Instance.RunCompile(sTemp);
                        CPExpressionHelper.Instance.Remove(CPGridExpression.DataRowKey);
                        newRow["ColumnTargetContent" + item.Id] = sTemp.Replace("\"", "'");
                        if (string.IsNullOrEmpty(item.ColumnIconOrText))
                        {
                            objValue = Convert.IsDBNull(dr[item.FieldName]) ? "" : dr[item.FieldName].ToString();
                        }
                        else
                        {
                            objValue = item.ColumnIconOrText;
                        }
                        #endregion
                    }
                    else if (item.ColumnType == CPGridEnum.ColumnTypeEnum.TextBoxEditor ||
                             item.ColumnType == CPGridEnum.ColumnTypeEnum.DropDownListEditor
                             )
                    {
                        #region 文本框编辑列,下拉 列表编辑列,时间编辑列
                        if (string.IsNullOrEmpty(item.FieldName))
                        {
                            objValue = "";
                        }
                        else
                        {
                            if (dt.Columns[item.FieldName].DataType == Type.GetType("System.Boolean"))
                            {
                                objValue = dr[item.FieldName.Trim()].ToString().ToLower();
                            }
                            else
                            {
                                objValue = dr[item.FieldName.Trim()];
                                if (string.IsNullOrEmpty(item.NumberFormat) == false)
                                {
                                    try
                                    {
                                        objValue = Convert.ToDecimal(objValue).ToString(item.NumberFormat);
                                    }
                                    catch (Exception ex) { ex.ToString(); }
                                }
                            }
                        }
                        if (string.IsNullOrEmpty(item.EventMethod) == false && string.IsNullOrEmpty(item.EventName) == false)
                        {
                            string EventMethod = item.EventMethod;
                            CPExpressionHelper.Instance.Add(CPGridExpression.DataRowKey, dr);
                            EventMethod = CPExpressionHelper.Instance.RunCompile(EventMethod);
                            CPExpressionHelper.Instance.Remove(CPGridExpression.DataRowKey);
                            newRow["ColumnEventMethod" + item.Id] = EventMethod.Replace("\"", "'");
                            newRow["ColumnEventName" + item.Id]   = item.EventName;
                        }
                        #endregion
                    }
                    else if (
                        item.ColumnType == CPGridEnum.ColumnTypeEnum.TimeSelectEditor
                        )
                    {
                        #region 时间编辑列
                        if (string.IsNullOrEmpty(item.FieldName))
                        {
                            objValue = "";
                        }
                        else
                        {
                            objValue = dr[item.FieldName.Trim()];
                            try
                            {
                                DateTime dtTime = Convert.ToDateTime(objValue);
                                objValue = dtTime.ToString(item.TimeFormat);
                            }
                            catch (Exception et) { et.ToString(); }
                        }
                        if (string.IsNullOrEmpty(item.EventMethod) == false && string.IsNullOrEmpty(item.EventName) == false)
                        {
                            string EventMethod = item.EventMethod;
                            CPExpressionHelper.Instance.Add(CPGridExpression.DataRowKey, dr);
                            EventMethod = CPExpressionHelper.Instance.RunCompile(EventMethod);
                            CPExpressionHelper.Instance.Remove(CPGridExpression.DataRowKey);
                            newRow["ColumnEventMethod" + item.Id] = EventMethod.Replace("\"", "'");
                            newRow["ColumnEventName" + item.Id]   = item.EventName;
                        }
                        #endregion
                    }
                    #endregion
                    if (Convert.IsDBNull(objValue) || objValue == null)
                    {
                        newRow["Column" + item.Id.ToString()] = "";
                    }
                    else
                    {
                        newRow["Column" + item.Id.ToString()] = objValue.ToString().Trim();
                    }
                }
                #endregion
                if (gridObj.IsGroup.Value && string.IsNullOrEmpty(gridObj.GroupField) == false)
                {
                    //启用了分组
                    string[] gArray = gridObj.GroupField.Split(',');
                    for (int i = 0; i < gArray.Length; i++)
                    {
                        if (string.IsNullOrEmpty(gArray[i]))
                        {
                            continue;
                        }
                        newRow[gArray[i].Trim() + "_CPGroup"] = dr[gArray[i].Trim()].ToString();;
                    }
                }

                nIndex++;
                dtNew.Rows.Add(newRow);
            }
            return(dtNew);
        }
Exemplo n.º 10
0
 public CPBeforeReadDataFromDbEventArgs(CPGrid grid, string strSql)
 {
     this.GridObj = grid;
     this.StrSql  = strSql;
 }
Exemplo n.º 11
0
 public CPAfterReadDataFromDbEventArgs(CPGrid grid, DataTable realData)
 {
     this.GridObj  = grid;
     this.RealData = RealData;
 }