示例#1
0
        public override bool DeletePhase(List <int> phaseIdCol)
        {
            if (phaseIdCol.Count <= 0)
            {
                return(true);
            }
            string ids = "";

            phaseIdCol.ForEach(t => {
                if (string.IsNullOrEmpty(ids))
                {
                    ids = t.ToString();
                }
                else
                {
                    ids += "," + t.ToString();
                }
            });
            string   strSql  = @"DELETE FROM Flow_TemplatePhaseRuleHandle WHERE PhaseId IN (" + ids + @");
                            DELETE FROM Flow_TemplatePhaseRule WHERE PhaseId IN (" + ids + @");
                            DELETE FROM Flow_TemplatePhaseLink WHERE StartPhaseId IN (" + ids + @") OR  EndPhaseId IN (" + ids + @");
                            DELETE FROM Flow_TemplatePhaseForm WHERE PhaseId IN (" + ids + @");
                            DELETE FROM Flow_TemplatePhase WHERE PhaseId IN (" + ids + @");";
            DbHelper _helper = new DbHelper("CPCommonIns", CPAppContext.CurDbType());

            _helper.ExecuteNonQuery(strSql);
            return(true);
        }
示例#2
0
        public bool UpdateTreeDataParent(int TreeDataSourceId, string sourcePKValue, string targetPKValue, ref string errorMsg)
        {
            CPTreeDataSource ds = this._CPTreeDataSourceRep.Get(TreeDataSourceId);

            if (string.IsNullOrEmpty(ds.MainTableName))
            {
                errorMsg = "数据源未配置数据表名";
                return(false);
            }
            if (string.IsNullOrEmpty(ds.PKField))
            {
                errorMsg = "数据源未配置表主键字段";
                return(false);
            }
            if (string.IsNullOrEmpty(ds.ParentIdField))
            {
                errorMsg = "数据源未配置存储父级ID的字段名";
                return(false);
            }
            DbHelper _helper = new DbHelper(ds.DbIns, CPAppContext.CurDbType());
            string   strSql2 = "UPDATE   " + ds.MainTableName + " SET " + ds.ParentIdField + "='" + targetPKValue + "'  WHERE " + ds.PKField + " in (" + sourcePKValue + ")";

            _helper.ExecuteNonQuery(strSql2);
            return(true);
        }
示例#3
0
        public override bool DeleteInstanceTask(int insId)
        {
            string   strSql  = "DELETE FROM Flow_InstanceTask WHERE InsId=" + insId;
            DbHelper _helper = new DbHelper("CPFlowIns", CPAppContext.CurDbType());

            _helper.ExecuteNonQuery(strSql);
            return(true);
        }
示例#4
0
        public override bool DeleteOverdueKey()
        {
            string strSql = "delete from CP_UserIdentity where (DATEDIFF(hour, LoginTime, GETDATE()) > 12)";
            // this._dbContext.Set<COUserIdentity>().
            DbHelper _helper = new DbHelper("CPOrganIns", CPAppContext.CurDbType());

            _helper.ExecuteNonQuery(strSql);
            return(true);
        }
示例#5
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);
        }
示例#6
0
        public bool SaveData(CPForm form, List <CPFormChildTable> childTableCol,
                             List <CPFormField> fieldCol, ref string pkValue, string formDataJSON, CPFormUseScene useScene, out string errorMsg)
        {
            bool b = this._CPFormRep.SaveData(form, childTableCol, fieldCol, ref pkValue, formDataJSON, out errorMsg);

            if (b)
            {
                dynamic formData = JsonConvert.DeserializeObject <dynamic>(formDataJSON);
                if (string.IsNullOrEmpty(useScene.FormSaveExeSql) == false)
                {
                    CPExpressionHelper.Instance.Add(CPFormExpression.DataRowKey, formData);
                    CPExpressionHelper.Instance.Add(CPFormExpression.PKValueKey, pkValue);
                    CPExpressionHelper.Instance.Add(CPFormExpression.MainTableKey, form.MainTableName);
                    CPExpressionHelper.Instance.Add(CPFormExpression.MainTablePKKey, form.PKFieldName);
                    string sql = CPExpressionHelper.Instance.RunCompile(useScene.FormSaveExeSql);
                    CPExpressionHelper.Instance.Remove(CPFormExpression.DataRowKey);
                    CPExpressionHelper.Instance.Remove(CPFormExpression.PKValueKey);
                    CPExpressionHelper.Instance.Remove(CPFormExpression.MainTableKey);
                    CPExpressionHelper.Instance.Remove(CPFormExpression.MainTablePKKey);
                    try
                    {
                        DbHelper _helper = new DbHelper(form.DbIns, CPAppContext.CurDbType());
                        _helper.ExecuteNonQuery(sql);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("表单保存后,执行扩展配置的SQL时出错,SQL语句为【" + sql + "】,错误信息如下 :" + ex.Message);
                    }
                }
                if (string.IsNullOrEmpty(useScene.FormSaveHandler) == false)
                {
                    string[] sArray = useScene.FormSaveHandler.Split(';');
                    for (int i = 0; i < sArray.Length; i++)
                    {
                        if (string.IsNullOrEmpty(sArray[i]))
                        {
                            continue;
                        }
                        try
                        {
                            ICPFormAfterSaveEventArgs e     = new ICPFormAfterSaveEventArgs(form, pkValue, formData);
                            ICPFormAfterSave          inter = Activator.CreateInstance(Type.GetType(sArray[i])) as ICPFormAfterSave;
                            inter.AfterSave(e);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("调用表单保存后扩展二次开发方法【" + sArray[i] + "】时出错,错误信息如下 :" + ex.Message);
                        }
                    }
                }
            }
            return(b);
        }
示例#7
0
        public bool DeleteTreeData(int TreeDataSourceId, string pkFieldValue, ref string errorMsg)
        {
            CPTreeDataSource ds = this._CPTreeDataSourceRep.Get(TreeDataSourceId);

            if (string.IsNullOrEmpty(ds.MainTableName))
            {
                errorMsg = "数据源未配置数据表名";
                return(false);
            }
            if (string.IsNullOrEmpty(ds.PKField))
            {
                errorMsg = "数据源未配置表主键字段";
                return(false);
            }

            List <string> pkCol = new List <string>();

            pkCol.Add(pkFieldValue);
            DbHelper _helper = new DbHelper(ds.DbIns, CPAppContext.CurDbType());

            if (string.IsNullOrEmpty(ds.ParentIdField) == false)
            {
                //递归删除数据
                string    strSql = "SELECT " + ds.PKField + " FROM " + ds.MainTableName + " WHERE " + ds.ParentIdField;
                DataTable dt     = _helper.ExecuteDataSet(strSql + "='" + pkFieldValue + "'").Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    pkCol.Add(dr[0].ToString());
                    //获取子节点
                    List <string> tCol = this.GetChildPK(strSql, dr[0].ToString(), ds.DbIns);
                    pkCol.AddRange(tCol);
                }
                dt.Dispose();
            }

            string ids = "";

            pkCol.ForEach(t => {
                if (string.IsNullOrEmpty(ids))
                {
                    ids = "'" + t + "'";
                }
                else
                {
                    ids += ",'" + t + "'";
                }
            });
            string strSql2 = "DELETE FROM " + ds.MainTableName + " WHERE " + ds.PKField + " in (" + ids + ")";

            _helper.ExecuteNonQuery(strSql2);
            return(true);
        }
示例#8
0
        private List <string> GetChildPK(string strSql, string parentId, string dbIns)
        {
            DbHelper      _helper = new DbHelper(dbIns, CPAppContext.CurDbType());
            string        tempSql = strSql += "='" + parentId + "'";
            DataTable     dt      = _helper.ExecuteDataSet(strSql).Tables[0];
            List <string> pkCol   = new List <string>();

            foreach (DataRow dr in dt.Rows)
            {
                pkCol.Add(dr[0].ToString());
                //获取子节点
                List <string> tCol = this.GetChildPK(strSql, dr[0].ToString(), dbIns);
                pkCol.AddRange(tCol);
            }
            dt.Dispose();
            return(pkCol);
        }
示例#9
0
        public override List <CPFlow> GetAllFlowMaxVer()
        {
            DbHelper   _helper = new DbHelper("CPCommonIns", CPAppContext.CurDbType());
            string     strSql  = @" SELECT FlowId,MAX(FlowVerId)  AS FlowVerId FROM dbo.Flow_Template
                GROUP BY FlowId";
            DataTable  dt      = _helper.ExecuteDataTable(strSql);
            List <int> col     = new List <int>();

            foreach (DataRow dr in dt.Rows)
            {
                col.Add(int.Parse(dr["FlowVerId"].ToString()));
            }
            CPFlowDbContext _db = this._dbContext as CPFlowDbContext;
            var             q   = (from flow in _db.CPFlowCol
                                   where col.Contains(flow.FlowVerId)
                                   select flow);

            return(q.ToList());
        }
示例#10
0
        public bool UpdateMsgReadState(List <int> msgIdCol)
        {
            DbHelper _helper = new DbHelper("CPFrameIns", CPAppContext.CurDbType());
            string   ids     = "";

            msgIdCol.ForEach(t => {
                if (string.IsNullOrEmpty(ids))
                {
                    ids = t.ToString();
                }
                else
                {
                    ids += "," + t.ToString();
                }
            });
            string strSql = "UPDATE CP_Msg SET IsRead=1 WHERE Id IN (" + ids + ")";

            _helper.ExecuteNonQuery(strSql);
            return(true);
        }
示例#11
0
        private string GetInitValue(CPFormFieldInit init, out int autoIndex, out string autoIndexField)
        {
            autoIndex      = 0;
            autoIndexField = "";
            string sValue = "";

            if (init.InitType == CPFormEnum.InitTypeEnum.StaticValue)
            {
                sValue = init.InitInfo;
            }
            else if (init.InitType == CPFormEnum.InitTypeEnum.Auto)
            {
                sValue = CPAutoNumHelper.Instance().GetNextAutoNum(init.InitInfo, out autoIndex);
                //再获取下存储索引号的字段名
                autoIndexField = CPAutoNumHelper.Instance().GetAutoNum(init.InitInfo).FormAumField;
            }
            else if (init.InitType == CPFormEnum.InitTypeEnum.Expression)
            {
                sValue = CPExpressionHelper.Instance.RunCompile(init.InitInfo);
            }
            else if (init.InitType == CPFormEnum.InitTypeEnum.Sql)
            {
                if (string.IsNullOrEmpty(init.InitSqlDbIns))
                {
                    throw new Exception("获取初始化信息时,存储数据库链接的字段值InitSqlDbIns值为空");
                }
                DbHelper _helper = new DbHelper(init.InitSqlDbIns, CPAppContext.CurDbType());
                string   sql     = init.InitInfo;
                sql = CPExpressionHelper.Instance.RunCompile(sql);
                object obj = _helper.ExecuteScalar(sql);
                if (Convert.IsDBNull(obj) == false && obj != null)
                {
                    sValue = obj.ToString();
                }
            }
            else
            {
                sValue = init.InitInfo;
            }
            return(sValue);
        }
示例#12
0
        public override DataSet GetConfigByFlowVerId(int flowVerId)
        {
            string   ids     = flowVerId.ToString();
            DbHelper _helper = new DbHelper("CPCommonIns", CPAppContext.CurDbType());
            string   strSql  = "SELECT * FROM Flow_Template WHERE FlowVerId in(" + ids + ");";

            strSql += "SELECT * FROM Flow_TemplatePhase WHERE FlowVerId in(" + ids + ");";
            strSql += "SELECT * FROM Flow_TemplatePhaseForm WHERE FlowVerId in(" + ids + ");";
            strSql += "SELECT * FROM Flow_TemplatePhaseLink WHERE FlowVerId in(" + ids + ");";
            strSql += "SELECT * FROM Flow_TemplatePhaseRule WHERE FlowVerId in(" + ids + ");";
            strSql += "SELECT * FROM Flow_TemplatePhaseRuleHandle WHERE FlowVerId in(" + ids + ")";
            DataSet ds = _helper.ExecuteDataSet(strSql);

            ds.Tables[0].TableName = "Flow_Template";
            ds.Tables[1].TableName = "Flow_TemplatePhase";
            ds.Tables[2].TableName = "Flow_TemplatePhaseForm";
            ds.Tables[3].TableName = "Flow_TemplatePhaseLink";
            ds.Tables[4].TableName = "Flow_TemplatePhaseRule";
            ds.Tables[5].TableName = "Flow_TemplatePhaseRuleHandle";

            return(ds);
        }
示例#13
0
        private int GetChildDataCount(CPTree tree, int TreeDataSourceId, DataRow parentDR)
        {
            int nCount = 0;
            List <CPTreeNode>       col       = new List <CPTreeNode>();
            List <CPTreeDataSource> SourceCol = tree.DataSourceCol.Where(c => c.Id.Equals(TreeDataSourceId)).ToList();

            SourceCol.ForEach(t => {
                string strSql = t.DataSource;
                CPExpressionHelper.Instance.Add(CPTreeExpression.DataRowKey, parentDR);
                strSql = CPExpressionHelper.Instance.RunCompile(strSql);
                CPExpressionHelper.Instance.Remove(CPTreeExpression.DataRowKey);
                DbHelper _helper = new DbHelper(t.DbIns, CPAppContext.CurDbType());
                DataTable dt     = _helper.ExecuteDataSet(strSql).Tables[0];
                if (string.IsNullOrEmpty(t.PKField) == false)
                {
                    if (dt.Columns.Contains(t.PKField) == false)
                    {
                        throw new Exception("数据源SQL中未包括主键字段【" + t.PKField + "】");
                    }
                }
                nCount = dt.Rows.Count;
            });
            return(nCount);
        }
示例#14
0
        public string GetFormDataJSON(CPForm form, List <CPFormChildTable> childTableCol, List <CPFormField> fieldCol, List <CPFormFieldInit> initValueCol,
                                      string pkValue, CPFormUseScene useScene)
        {
            string sJSON = "";
            Dictionary <string, string> col = new Dictionary <string, string>();
            DataSet ds = this.GetFormData(form, childTableCol, fieldCol, pkValue);

            if (string.IsNullOrEmpty(pkValue) == false)
            {
                #region  数据
                if (childTableCol != null && childTableCol.Count > 0)
                {
                    childTableCol.ForEach(t => {
                        if (ds.Tables[t.TableName].Rows.Count <= 0)
                        {
                            DataRow drChild = ds.Tables[t.TableName].NewRow();
                            foreach (DataColumn dc in ds.Tables[t.TableName].Columns)
                            {
                                drChild[dc.ColumnName] = DBNull.Value;
                            }
                            ds.Tables[t.TableName].Rows.Add(drChild);
                        }
                    });
                }

                #endregion
            }
            else
            {
                #region 无数据,新增 ,自动给每个表加一条空的数据
                DataRow drMain = ds.Tables[form.MainTableName].NewRow();
                foreach (DataColumn dc in  ds.Tables[form.MainTableName].Columns)
                {
                    drMain[dc.ColumnName] = DBNull.Value;
                }
                ds.Tables[form.MainTableName].Rows.Add(drMain);
                if (childTableCol != null && childTableCol.Count > 0)
                {
                    childTableCol.ForEach(t => {
                        DataRow drChild = ds.Tables[t.TableName].NewRow();
                        foreach (DataColumn dc in ds.Tables[t.TableName].Columns)
                        {
                            drChild[dc.ColumnName] = DBNull.Value;
                        }
                        ds.Tables[t.TableName].Rows.Add(drChild);
                    });
                }

                #endregion
            }
            //加入初始化的代码
            ds = this.InitFieldValue(form, childTableCol, fieldCol, initValueCol, ds, pkValue);
            if (string.IsNullOrEmpty(useScene.FormLoadHandler) == false)
            {
                string[] sArray = useScene.FormLoadHandler.Split(';');
                for (int i = 0; i < sArray.Length; i++)
                {
                    if (string.IsNullOrEmpty(sArray[i]))
                    {
                        continue;
                    }
                    try
                    {
                        ICPFormBeforeLoadEventArgs e     = new ICPFormBeforeLoadEventArgs(form, pkValue, ds);
                        ICPFormBeforeLoad          inter = Activator.CreateInstance(Type.GetType(sArray[i])) as ICPFormBeforeLoad;
                        inter.BeforeLoad(e);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("调用表单加载前扩展二次开发方法【" + sArray[i] + "】时出错,错误信息如下 :" + ex.Message);
                    }
                }
            }
            foreach (DataTable dt in ds.Tables)
            {
                col.Add(dt.TableName, CPUtils.DataTable2Json2(dt));
            }
            #region 获取所有下拉列表的数据源
            fieldCol.ForEach(t => {
                if (t.ControlType == CPFormEnum.ControlTypeEnum.DropDownList ||
                    t.ControlType == CPFormEnum.ControlTypeEnum.Radio || t.ControlType == CPFormEnum.ControlTypeEnum.CheckBox
                    )
                {
                    if (string.IsNullOrEmpty(t.ListDbIns))
                    {
                        throw new Exception("字段[" + t.FieldName + "]配置成下拉列表或复选框或单选,但未配置数据源数据库链接实例");
                    }
                    DbHelper _helper = new DbHelper(t.ListDbIns, CPAppContext.CurDbType());
                    string s         = t.ListSql;
                    s = CPExpressionHelper.Instance.RunCompile(s);
                    if (string.IsNullOrEmpty(s))
                    {
                        throw new Exception("字段[" + t.FieldName + "]配置成下拉列表或复选框或单选,但未配置数据源SQL语句");
                    }
                    DataTable dt    = _helper.ExecuteDataSet(s).Tables[0];
                    DataTable dtNew = new DataTable();
                    dtNew.Columns.Add(new DataColumn()
                    {
                        ColumnName = "textEx", DataType = typeof(string)
                    });


                    dtNew.Columns.Add(new DataColumn()
                    {
                        ColumnName = "valueEx", DataType = typeof(string)
                    });
                    dtNew.Columns.Add(new DataColumn()
                    {
                        ColumnName = "listRelateEx", DataType = typeof(string)
                    });
                    if (t.ControlType == CPFormEnum.ControlTypeEnum.DropDownList)
                    {
                        DataRow newDR0         = dtNew.NewRow();
                        newDR0["textEx"]       = "==请选择==";
                        newDR0["valueEx"]      = "";
                        newDR0["listRelateEx"] = "";
                        dtNew.Rows.Add(newDR0);
                    }
                    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];
                        }
                        newDR["listRelateEx"] = "";
                        if (string.IsNullOrEmpty(t.ListRelateTargetField) == false)
                        {
                            try
                            {
                                if (dt.Columns[2].DataType == Type.GetType("System.Boolean"))
                                {
                                    newDR["listRelateEx"] = dr[2].ToString().Trim().ToLower();
                                }
                                else
                                {
                                    newDR["listRelateEx"] = dr[2];
                                }
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("字段[" + t.FieldName + "]配置成下拉列表联动,请确保数据源第三个字段值为联动值,配置的SQL为:" + s + "详细信息如下:" + ex.Message.ToString());
                            }
                        }
                        dtNew.Rows.Add(newDR);
                    }
                    col.Add(t.TableName + "_" + t.FieldName, CPUtils.DataTable2Json2(dtNew));
                }
                else if (t.ControlType == CPFormEnum.ControlTypeEnum.Combox
                         )
                {
                    DbHelper _helper = new DbHelper(t.ListDbIns, CPAppContext.CurDbType());
                    string s         = t.ListSql;
                    s               = CPExpressionHelper.Instance.RunCompile(s);
                    DataTable dt    = _helper.ExecuteDataSet(s).Tables[0];
                    DataTable dtNew = new DataTable();
                    dtNew.Columns.Add(new DataColumn()
                    {
                        ColumnName = "textEx", DataType = typeof(string)
                    });
                    DataRow newDR0   = dtNew.NewRow();
                    newDR0["textEx"] = "";
                    dtNew.Rows.Add(newDR0);
                    foreach (DataRow dr in dt.Rows)
                    {
                        DataRow newDR = dtNew.NewRow();
                        if (dt.Columns[0].DataType == Type.GetType("System.Boolean"))
                        {
                            newDR["textEx"] = dr[0].ToString().Trim().ToLower();
                        }
                        else
                        {
                            newDR["textEx"] = dr[0];
                        }
                        dtNew.Rows.Add(newDR);
                    }
                    col.Add(t.TableName + "_" + t.FieldName, CPUtils.DataTable2Json2(dtNew));
                }
            });
            #endregion

            #region 如果没有拓展表,则自动构建一个隐藏的下拉列表,用来解决没有ng-repeat,不能执行ngRepeatFinished事件的问题
            if (form.ChildTableCol.Count <= 0)
            {
                DataTable dtNew = new DataTable();
                dtNew.Columns.Add(new DataColumn()
                {
                    ColumnName = "textEx", DataType = typeof(string)
                });


                dtNew.Columns.Add(new DataColumn()
                {
                    ColumnName = "valueEx", DataType = typeof(string)
                });

                col.Add("CPFormTmpHideSelectTable", CPUtils.DataTable2Json2(dtNew));
            }
            #endregion
            sJSON = JsonConvert.SerializeObject(col);
            return(sJSON);
        }
示例#15
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);
            }
        }
示例#16
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);
            }
        }
示例#17
0
        public override bool SyncConfigFromDataSet(DataSet ds, int targetFlowClassId, bool isCreateNew)
        {
            //isCreateNew是否是全新创建流程,创建流程版本不算全新创建,包括配置更新也不算。
            DbHelper _helper = new DbHelper("CPCommonIns", CPAppContext.CurDbType());

            bool b = true;


            #region 写入数据
            SqlCommand cmd = new SqlCommand(@"SELECT * FROM Flow_Template WHERE 1=2; 
                                    SELECT * FROM Flow_TemplatePhase WHERE 1=2;
                                    SELECT * FROM Flow_TemplatePhaseForm WHERE 1=2;
                                    SELECT * FROM Flow_TemplatePhaseLink WHERE 1=2;
                                    SELECT * FROM Flow_TemplatePhaseRule WHERE 1=2;
                                    SELECT * FROM Flow_TemplatePhaseRuleHandle WHERE 1=2",
                                            _helper.GetConnection() as SqlConnection);
            SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
            // SqlCommandBuilder builder = new SqlCommandBuilder(da);
            //AddWithKey: 自动填充数据表结构,如:主键和限制
            //预设值Add,不填充结构
            da.MissingSchemaAction = MissingSchemaAction.AddWithKey;//Default Value is: Add
            DataSet dsStruct = new DataSet();
            da.Fill(dsStruct);
            dsStruct.Tables[0].TableName = "Flow_Template";
            dsStruct.Tables[1].TableName = "Flow_TemplatePhase";
            dsStruct.Tables[2].TableName = "Flow_TemplatePhaseForm";
            dsStruct.Tables[3].TableName = "Flow_TemplatePhaseLink";
            dsStruct.Tables[4].TableName = "Flow_TemplatePhaseRule";
            dsStruct.Tables[5].TableName = "Flow_TemplatePhaseRuleHandle";
            #region Flow_Template

            Dictionary <int, int> oldNewFlowVerId = new Dictionary <int, int>();
            foreach (DataRow dr in ds.Tables["Flow_Template"].Rows)
            {
                if (isCreateNew)
                {
                    dr["FlowName"] = dr["FlowName"].ToString() + "_副本";
                    string tmpSql    = "SELECT ISNULL(MAX(flowid),1) FROM Flow_Template";
                    int    newFlowId = int.Parse(_helper.ExecuteScalar(tmpSql).ToString());
                    dr["FlowId"] = newFlowId;
                }
                dr["FlowClassId"] = targetFlowClassId;
                string insertSql = CPAppContext.GetInsertSql("Flow_Template", dsStruct.Tables["Flow_Template"].Columns, dr);
                insertSql += ";select SCOPE_IDENTITY() as Id;";
                SqlCommand cmdInsert = new SqlCommand(insertSql, _helper.GetConnection() as SqlConnection);
                foreach (DataColumn dc in dsStruct.Tables["Flow_Template"].Columns)
                {
                    if (dc.AutoIncrement)
                    {
                        continue;
                    }
                    if (dr.Table.Columns.Contains(dc.ColumnName))
                    {
                        cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, dr[dc.ColumnName]);
                    }
                    else
                    {
                        cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, DBNull.Value);
                    }
                }
                int newId = int.Parse(_helper.ExecuteScalar(cmdInsert).ToString());
                oldNewFlowVerId.Add(int.Parse(dr["FlowVerId"].ToString()), newId);
            }

            #endregion

            #region Flow_TemplatePhase
            Dictionary <int, int> oldNewPhaseId = new Dictionary <int, int>();
            if (ds.Tables["Flow_TemplatePhase"] != null)
            {
                foreach (DataRow dr in ds.Tables["Flow_TemplatePhase"].Rows)
                {
                    dr["FlowVerId"] = oldNewFlowVerId[int.Parse(dr["FlowVerId"].ToString())];
                    string insertSql = CPAppContext.GetInsertSql("Flow_TemplatePhase", dsStruct.Tables["Flow_TemplatePhase"].Columns, dr);
                    insertSql += ";select SCOPE_IDENTITY() as Id;";
                    SqlCommand cmdInsert = new SqlCommand(insertSql, _helper.GetConnection() as SqlConnection);
                    foreach (DataColumn dc in dsStruct.Tables["Flow_TemplatePhase"].Columns)
                    {
                        if (dc.AutoIncrement)
                        {
                            continue;
                        }
                        if (dr.Table.Columns.Contains(dc.ColumnName))
                        {
                            cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, dr[dc.ColumnName]);
                        }
                        else
                        {
                            cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, DBNull.Value);
                        }
                    }
                    int newId = int.Parse(_helper.ExecuteScalar(cmdInsert).ToString());
                    oldNewPhaseId.Add(int.Parse(dr["PhaseId"].ToString()), newId);
                }
            }
            #endregion

            #region Flow_TemplatePhaseForm
            if (ds.Tables["Flow_TemplatePhaseForm"] != null)
            {
                foreach (DataRow dr in ds.Tables["Flow_TemplatePhaseForm"].Rows)
                {
                    dr["FlowVerId"] = oldNewFlowVerId[int.Parse(dr["FlowVerId"].ToString())];
                    dr["PhaseId"]   = oldNewPhaseId[int.Parse(dr["PhaseId"].ToString())];
                    string insertSql = CPAppContext.GetInsertSql("Flow_TemplatePhaseForm", dsStruct.Tables["Flow_TemplatePhaseForm"].Columns, dr);

                    SqlCommand cmdInsert = new SqlCommand(insertSql, _helper.GetConnection() as SqlConnection);
                    foreach (DataColumn dc in dsStruct.Tables["Flow_TemplatePhaseForm"].Columns)
                    {
                        if (dc.AutoIncrement)
                        {
                            continue;
                        }
                        if (dr.Table.Columns.Contains(dc.ColumnName))
                        {
                            cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, dr[dc.ColumnName]);
                        }
                        else
                        {
                            cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, DBNull.Value);
                        }
                    }
                    _helper.ExecuteNonQuery(cmdInsert);
                }
            }
            #endregion

            #region Flow_TemplatePhaseLink
            if (ds.Tables["Flow_TemplatePhaseLink"] != null)
            {
                foreach (DataRow dr in ds.Tables["Flow_TemplatePhaseLink"].Rows)
                {
                    dr["FlowVerId"]    = oldNewFlowVerId[int.Parse(dr["FlowVerId"].ToString())];
                    dr["StartPhaseId"] = oldNewPhaseId[int.Parse(dr["StartPhaseId"].ToString())];
                    dr["EndPhaseId"]   = oldNewPhaseId[int.Parse(dr["EndPhaseId"].ToString())];

                    string insertSql = CPAppContext.GetInsertSql("Flow_TemplatePhaseLink", dsStruct.Tables["Flow_TemplatePhaseLink"].Columns, dr);

                    SqlCommand cmdInsert = new SqlCommand(insertSql, _helper.GetConnection() as SqlConnection);
                    foreach (DataColumn dc in dsStruct.Tables["Flow_TemplatePhaseLink"].Columns)
                    {
                        if (dc.AutoIncrement)
                        {
                            continue;
                        }
                        if (dr.Table.Columns.Contains(dc.ColumnName))
                        {
                            cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, dr[dc.ColumnName]);
                        }
                        else
                        {
                            cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, DBNull.Value);
                        }
                    }
                    _helper.ExecuteNonQuery(cmdInsert);
                }
            }
            #endregion

            #region Flow_TemplatePhaseRule
            Dictionary <int, int> oldNewRuleId = new Dictionary <int, int>();
            if (ds.Tables["Flow_TemplatePhaseRule"] != null)
            {
                foreach (DataRow dr in ds.Tables["Flow_TemplatePhaseRule"].Rows)
                {
                    dr["FlowVerId"] = oldNewFlowVerId[int.Parse(dr["FlowVerId"].ToString())];
                    dr["PhaseId"]   = oldNewPhaseId[int.Parse(dr["PhaseId"].ToString())];
                    string insertSql = CPAppContext.GetInsertSql("Flow_TemplatePhaseRule", dsStruct.Tables["Flow_TemplatePhaseRule"].Columns, dr);
                    insertSql += ";select SCOPE_IDENTITY() as Id;";
                    SqlCommand cmdInsert = new SqlCommand(insertSql, _helper.GetConnection() as SqlConnection);
                    foreach (DataColumn dc in dsStruct.Tables["Flow_TemplatePhaseRule"].Columns)
                    {
                        if (dc.AutoIncrement)
                        {
                            continue;
                        }
                        if (dr.Table.Columns.Contains(dc.ColumnName))
                        {
                            cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, dr[dc.ColumnName]);
                        }
                        else
                        {
                            cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, DBNull.Value);
                        }
                    }
                    int newId = int.Parse(_helper.ExecuteScalar(cmdInsert).ToString());
                    oldNewRuleId.Add(int.Parse(dr["RuleId"].ToString()), newId);
                }
            }
            #endregion

            #region Flow_TemplatePhaseRuleHandle
            if (ds.Tables["Flow_TemplatePhaseRuleHandle"] != null)
            {
                foreach (DataRow dr in ds.Tables["Flow_TemplatePhaseRuleHandle"].Rows)
                {
                    dr["FlowVerId"] = oldNewFlowVerId[int.Parse(dr["FlowVerId"].ToString())];
                    dr["PhaseId"]   = oldNewPhaseId[int.Parse(dr["PhaseId"].ToString())];
                    dr["RuleId"]    = oldNewRuleId[int.Parse(dr["RuleId"].ToString())];

                    string insertSql = CPAppContext.GetInsertSql("Flow_TemplatePhaseRuleHandle", dsStruct.Tables["Flow_TemplatePhaseRuleHandle"].Columns, dr);

                    SqlCommand cmdInsert = new SqlCommand(insertSql, _helper.GetConnection() as SqlConnection);
                    foreach (DataColumn dc in dsStruct.Tables["Flow_TemplatePhaseRuleHandle"].Columns)
                    {
                        if (dc.AutoIncrement)
                        {
                            continue;
                        }
                        if (dr.Table.Columns.Contains(dc.ColumnName))
                        {
                            cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, dr[dc.ColumnName]);
                        }
                        else
                        {
                            cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, DBNull.Value);
                        }
                    }
                    _helper.ExecuteNonQuery(cmdInsert);
                }
            }
            #endregion

            #endregion
            return(b);
        }
示例#18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="treeCode"></param>
        /// <param name="TreeDataSourceId"></param>
        /// <param name="parentDataRowJSON">parentDataRowJSON:父节点datarow的JSON,根节点为空,一般是逐级加载数据时用到</param>
        public List <CPTreeNode> GetTreeData(string treeCode, int TreeDataSourceId, string parentDataRowJSON)
        {
            CPTree tree = this.GetTree(treeCode, false, true);

            if (tree == null)
            {
                return(new List <CPTreeNode>());
            }
            if (string.IsNullOrEmpty(tree.ChkDefaultSelValue) == false)
            {
                tree.ChkDefaultSelValue = CPExpressionHelper.Instance.RunCompile(tree.ChkDefaultSelValue);
            }
            List <string> chkDefaultSelValue = null;

            if (string.IsNullOrEmpty(tree.ChkDefaultSelValue))
            {
                chkDefaultSelValue = new List <string>();
            }
            else
            {
                chkDefaultSelValue = tree.ChkDefaultSelValue.Split(',').ToList();
            }
            List <CPTreeNode> col = new List <CPTreeNode>();

            if (tree.DataLoadType == CPTreeEnum.DataLoadTypeEnum.AllLoad)
            {
                #region 全加载,只会调用一次  且不支持局部刷新
                //
                List <CPTreeDataSource> rootSourceCol = tree.DataSourceCol.Where(c => c.ParentSourceId.Equals(-1)).ToList();
                rootSourceCol.ForEach(t => {
                    string strSql    = t.DataSource;
                    strSql           = CPExpressionHelper.Instance.RunCompile(strSql);
                    DbHelper _helper = new DbHelper(t.DbIns, CPAppContext.CurDbType());
                    DataTable dt     = _helper.ExecuteDataSet(strSql).Tables[0];
                    if (string.IsNullOrEmpty(t.PKField) == false)
                    {
                        if (dt.Columns.Contains(t.PKField) == false)
                        {
                            throw new Exception("数据源SQL中未包括主键字段【" + t.PKField + "】");
                        }
                    }
                    foreach (DataRow dr in dt.Rows)
                    {
                        CPExpressionHelper.Instance.Add(CPTreeExpression.DataRowKey, dr);
                        CPTreeNode node       = new CPTreeNode();
                        node.NodeId           = "Node_" + Guid.NewGuid().ToString("N");
                        node.NodeTitle        = CPExpressionHelper.Instance.RunCompile(t.NodeTitle);
                        node.NodeAttrEx       = CPExpressionHelper.Instance.RunCompile(t.NodeAttrEx);
                        node.NodeIcon         = t.NodeIcon;
                        node.hasChildren      = false;
                        node.TreeDataSourceId = t.Id;
                        node.DataRowJSON      = "";
                        if (string.IsNullOrEmpty(t.PKField) == false)
                        {
                            node.DeleteFieldValue = dr[t.PKField].ToString();
                        }
                        else
                        {
                            node.DeleteFieldValue = "";
                        }
                        if (string.IsNullOrEmpty(t.ChkSelFieldName))
                        {
                            node.ChkSelFieldName = "";
                        }
                        else
                        {
                            node.ChkSelFieldName = t.ChkSelFieldName;
                            if (dt.Columns.Contains(t.ChkSelFieldName) == false)
                            {
                                throw new Exception("数据源SQL中未包括checkbox默认选中字段【" + t.ChkSelFieldName + "】");
                            }
                            node.ChkSelFieldValue = Convert.IsDBNull(dr[t.ChkSelFieldName.Trim()]) ? "" : dr[t.ChkSelFieldName.Trim()].ToString();
                            #region 处理check默认选中
                            if (chkDefaultSelValue.Count > 0)
                            {
                                if (chkDefaultSelValue.Contains(node.ChkSelFieldValue))
                                {
                                    node.Checked = true;
                                }
                                else
                                {
                                    node.Checked = false;
                                }
                            }
                            #endregion
                        }
                        node.items = new List <CPTreeNode>();
                        #region 获取子节点
                        if (t.SourceIsRecursion.Value)
                        {
                            //递归取数据
                            List <CPTreeNode> childCol = this.GetChildData(tree, t.Id, dr, chkDefaultSelValue);
                            if (childCol.Count > 0)
                            {
                                node.hasChildren = true;
                                node.items.AddRange(childCol);
                            }
                        }
                        //取下一级的数据
                        List <CPTreeDataSource> childSourceCol = tree.DataSourceCol.Where(c => c.ParentSourceId.Equals(t.Id)).ToList();
                        childSourceCol.ForEach(child => {
                            List <CPTreeNode> childCol = this.GetChildData(tree, child.Id, dr, chkDefaultSelValue);
                            if (childCol.Count > 0)
                            {
                                node.hasChildren = true;
                                node.items.AddRange(childCol);
                            }
                        });
                        #endregion
                        CPExpressionHelper.Instance.Remove(CPTreeExpression.DataRowKey);
                        col.Add(node);
                    }
                });
                #endregion
            }
            else
            {
                #region 逐级加载
                List <CPTreeDataSource> rootSourceCol = null;
                if (string.IsNullOrEmpty(parentDataRowJSON))
                {
                    rootSourceCol = tree.DataSourceCol.Where(c => c.Id.Equals(TreeDataSourceId)).ToList();
                }
                else
                {
                    rootSourceCol = tree.DataSourceCol.Where(c => c.Id.Equals(TreeDataSourceId)).ToList();
                    if (rootSourceCol[0].SourceIsRecursion.Value == false)
                    {
                        rootSourceCol = tree.DataSourceCol.Where(c => c.ParentSourceId.Equals(TreeDataSourceId)).ToList();
                    }
                    else
                    {
                        rootSourceCol.AddRange(
                            tree.DataSourceCol.Where(c => c.ParentSourceId.Equals(TreeDataSourceId)).ToList()
                            );
                    }
                }
                rootSourceCol.ForEach(t => {
                    string strSql = t.DataSource;
                    if (string.IsNullOrEmpty(parentDataRowJSON) == false)
                    {
                        dynamic formData = JsonConvert.DeserializeObject <dynamic>(parentDataRowJSON);
                        DataTable dtTmp  = new DataTable();
                        foreach (var key in formData)
                        {
                            Newtonsoft.Json.Linq.JProperty jKey = (Newtonsoft.Json.Linq.JProperty)key;
                            DataColumn dc = new DataColumn();
                            dc.ColumnName = jKey.Name;
                            dtTmp.Columns.Add(dc);
                        }
                        DataRow dr = dtTmp.NewRow();
                        foreach (var key in formData)
                        {
                            Newtonsoft.Json.Linq.JProperty jKey = (Newtonsoft.Json.Linq.JProperty)key;
                            try
                            {
                                dr[jKey.Name] = jKey.Value.ToString();
                            }
                            catch (Exception ex)
                            {
                                dr[jKey.Name] = "";
                            }
                        }
                        dtTmp.Rows.Add(dr);
                        CPExpressionHelper.Instance.Add(CPTreeExpression.DataRowKey, dtTmp.Rows[0]);
                        strSql = CPExpressionHelper.Instance.RunCompile(strSql);
                        CPExpressionHelper.Instance.Remove(CPTreeExpression.DataRowKey);
                    }
                    else
                    {
                        strSql = CPExpressionHelper.Instance.RunCompile(strSql);
                    }
                    DbHelper _helper = new DbHelper(t.DbIns, CPAppContext.CurDbType());
                    DataTable dt     = _helper.ExecuteDataSet(strSql).Tables[0];
                    if (string.IsNullOrEmpty(t.PKField) == false)
                    {
                        if (dt.Columns.Contains(t.PKField) == false)
                        {
                            throw new Exception("数据源SQL中未包括主键字段【" + t.PKField + "】");
                        }
                    }
                    foreach (DataRow dr in dt.Rows)
                    {
                        CPExpressionHelper.Instance.Add(CPTreeExpression.DataRowKey, dr);
                        CPTreeNode node       = new CPTreeNode();
                        node.NodeId           = "Node_" + Guid.NewGuid().ToString("N");
                        node.NodeTitle        = CPExpressionHelper.Instance.RunCompile(t.NodeTitle);
                        node.NodeAttrEx       = CPExpressionHelper.Instance.RunCompile(t.NodeAttrEx);
                        node.NodeIcon         = t.NodeIcon;
                        node.hasChildren      = false;
                        node.TreeDataSourceId = t.Id;
                        node.DataRowJSON      = CPUtils.DataRow2Json(dr);
                        if (string.IsNullOrEmpty(t.PKField) == false)
                        {
                            node.DeleteFieldValue = dr[t.PKField].ToString();
                        }
                        else
                        {
                            node.DeleteFieldValue = "";
                        }
                        if (string.IsNullOrEmpty(t.ChkSelFieldName))
                        {
                            node.ChkSelFieldName = "";
                        }
                        else
                        {
                            node.ChkSelFieldName = t.ChkSelFieldName;
                            if (dt.Columns.Contains(t.ChkSelFieldName) == false)
                            {
                                throw new Exception("数据源SQL中未包括checkbox默认选中字段【" + t.ChkSelFieldName + "】");
                            }
                            node.ChkSelFieldValue = Convert.IsDBNull(dr[t.ChkSelFieldName.Trim()]) ? "" : dr[t.ChkSelFieldName.Trim()].ToString();
                            #region 处理check默认选中
                            if (chkDefaultSelValue.Count > 0)
                            {
                                if (chkDefaultSelValue.Contains(node.ChkSelFieldValue))
                                {
                                    node.Checked = true;
                                }
                                else
                                {
                                    node.Checked = false;
                                }
                            }
                            #endregion
                        }
                        node.items = new List <CPTreeNode>();
                        #region 获取子节点
                        if (t.SourceIsRecursion.Value)
                        {
                            //递归取数据
                            int nCount = this.GetChildDataCount(tree, t.Id, dr);
                            if (nCount > 0)
                            {
                                node.hasChildren = true;
                            }
                        }
                        if (node.hasChildren == false)
                        {
                            //看下一级的数据
                            List <CPTreeDataSource> childSourceCol = tree.DataSourceCol.Where(c => c.ParentSourceId.Equals(t.Id)).ToList();
                            childSourceCol.ForEach(child =>
                            {
                                if (node.hasChildren)
                                {
                                    return;
                                }
                                int nCount = this.GetChildDataCount(tree, child.Id, dr);
                                if (nCount > 0)
                                {
                                    node.hasChildren = true;
                                }
                            });
                        }
                        #endregion
                        CPExpressionHelper.Instance.Remove(CPTreeExpression.DataRowKey);
                        col.Add(node);
                    }
                });


                #endregion
            }
            return(col);
        }
示例#19
0
        public CPWebApiBaseReturnEntity UpdateFormInitData([FromBody] UpdateFormInitDataInput 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
            {
                DbHelper      dbHelper = new DbHelper("CPCommonIns", CPAppContext.CurDbType());
                StringBuilder sb       = new StringBuilder();
                sb.Append("DELETE FROM Form_FieldInitValue WHERE FormId=" + input.FormId + " AND GroupID=" + input.GroupId);

                input.Items.ForEach(t =>
                {
                    string strSql      = "";
                    strSql             = "INSERT INTO Form_FieldInitValue";
                    string fieldNames  = "";
                    string fieldValues = "";
                    bool needAdd       = true;
                    for (int i = 0; i < t.FieldNamCol.Count; i++)
                    {
                        if (t.FieldNamCol[i].Equals("InitInfo", StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (string.IsNullOrEmpty(t.FieldValueCol[i].Trim()))
                            {
                                needAdd = false;
                                break;
                            }
                        }
                        string sValue = t.FieldValueCol[i];
                        if (string.IsNullOrEmpty(sValue) == false)
                        {
                            sValue = sValue.Replace("'", "''");
                        }
                        else
                        {
                            sValue = "";
                        }
                        if (i == 0)
                        {
                            fieldNames  += t.FieldNamCol[i];
                            fieldValues += "'" + sValue + "'";
                        }
                        else
                        {
                            fieldNames  += "," + t.FieldNamCol[i];
                            fieldValues += ",'" + sValue + "'";
                        }
                    }
                    if (needAdd == false)
                    {
                        return;
                    }
                    fieldNames  += ",GroupID,FieldId,FormId";
                    fieldValues += "," + input.GroupId + "," + t.DataPK + "," + input.FormId;
                    strSql      += "(" + fieldNames + ") values (" + fieldValues + ")";
                    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);
            }
        }
示例#20
0
        private List <CPTreeNode> GetChildData(CPTree tree, int TreeDataSourceId, DataRow parentDR, List <string> chkDefaultSelValue)
        {
            List <CPTreeNode>       col       = new List <CPTreeNode>();
            List <CPTreeDataSource> SourceCol = tree.DataSourceCol.Where(c => c.Id.Equals(TreeDataSourceId)).ToList();

            SourceCol.ForEach(t => {
                string strSql = t.DataSource;
                CPExpressionHelper.Instance.Add(CPTreeExpression.DataRowKey, parentDR);
                strSql = CPExpressionHelper.Instance.RunCompile(strSql);
                CPExpressionHelper.Instance.Remove(CPTreeExpression.DataRowKey);
                DbHelper _helper = new DbHelper(t.DbIns, CPAppContext.CurDbType());
                DataTable dt     = _helper.ExecuteDataSet(strSql).Tables[0];
                if (string.IsNullOrEmpty(t.PKField) == false)
                {
                    if (dt.Columns.Contains(t.PKField) == false)
                    {
                        throw new Exception("数据源SQL中未包括主键字段【" + t.PKField + "】");
                    }
                }
                foreach (DataRow dr in dt.Rows)
                {
                    CPExpressionHelper.Instance.Add(CPTreeExpression.DataRowKey, dr);
                    CPTreeNode node       = new CPTreeNode();
                    node.NodeId           = "Node_" + Guid.NewGuid().ToString("N");
                    node.NodeTitle        = CPExpressionHelper.Instance.RunCompile(t.NodeTitle);
                    node.NodeAttrEx       = CPExpressionHelper.Instance.RunCompile(t.NodeAttrEx);
                    node.NodeIcon         = t.NodeIcon;
                    node.hasChildren      = false;
                    node.TreeDataSourceId = t.Id;
                    if (string.IsNullOrEmpty(t.PKField) == false)
                    {
                        node.DeleteFieldValue = dr[t.PKField].ToString();
                    }
                    else
                    {
                        node.DeleteFieldValue = "";
                    }
                    node.DataRowJSON = "";
                    if (string.IsNullOrEmpty(t.ChkSelFieldName))
                    {
                        node.ChkSelFieldName = "";
                    }
                    else
                    {
                        node.ChkSelFieldName = t.ChkSelFieldName;
                        if (dt.Columns.Contains(t.ChkSelFieldName) == false)
                        {
                            throw new Exception("数据源SQL中未包括checkbox默认选中字段【" + t.ChkSelFieldName + "】");
                        }
                        node.ChkSelFieldValue = Convert.IsDBNull(dr[t.ChkSelFieldName.Trim()]) ? "" : dr[t.ChkSelFieldName.Trim()].ToString();
                        #region 处理check默认选中
                        if (chkDefaultSelValue.Count > 0)
                        {
                            if (chkDefaultSelValue.Contains(node.ChkSelFieldValue))
                            {
                                node.Checked = true;
                            }
                            else
                            {
                                node.Checked = false;
                            }
                        }
                        #endregion
                    }
                    node.items = new List <CPTreeNode>();
                    #region 获取子节点
                    if (t.SourceIsRecursion.Value)
                    {
                        //递归取数据
                        List <CPTreeNode> childCol = this.GetChildData(tree, t.Id, dr, chkDefaultSelValue);
                        if (childCol.Count > 0)
                        {
                            node.hasChildren = true;
                            node.items.AddRange(childCol);
                        }
                    }
                    //取下一级的数据
                    List <CPTreeDataSource> childSourceCol = tree.DataSourceCol.Where(c => c.ParentSourceId.Equals(t.Id)).ToList();
                    childSourceCol.ForEach(child => {
                        List <CPTreeNode> childCol = this.GetChildData(tree, child.Id, dr, chkDefaultSelValue);
                        if (childCol.Count > 0)
                        {
                            node.hasChildren = true;
                            node.items.AddRange(childCol);
                        }
                    });
                    #endregion
                    CPExpressionHelper.Instance.Remove(CPTreeExpression.DataRowKey);
                    col.Add(node);
                }
            });
            return(col);
        }