Example #1
0
        public bool AddDefaultScene(int formId)
        {
            CPForm form = this._CPFormRep.Get(formId);

            if (form == null)
            {
                return(false);
            }
            CPFormUseScene scene = new CPFormUseScene();
            int            autoIndex;

            scene.FormId          = formId;
            scene.SceneCode       = CPAutoNumHelper.Instance().GetNextAutoNum("FormSceneCodeAuto", out autoIndex);
            scene.AutoIndex       = autoIndex;
            scene.FormSavedAction = CPFormEnum.FormSavedActionEnum.ReturnEditPage;
            scene.SceneName       = "默认";
            scene.FuncCol         = new List <CPFormUseSceneFunc>();
            CPFormUseSceneFunc func = new CPFormUseSceneFunc();

            func.FuncTitle        = "保存";
            func.ShowOrder        = 10;
            func.FuncExeJS        = "CPFormSaveFormData()";
            func.FuncIsShowInView = CPFormEnum.FuncIsShowInViewEnum.OnlyWriteShow;
            func.IsControlByRight = false;
            func.FormId           = formId;
            scene.FuncCol.Add(func);
            this._CPFormUseSceneRep.Add(scene);
            return(true);
        }
Example #2
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);
        }
Example #3
0
        public bool InitFormDefaultView(int formId)
        {
            CPForm form = this._CPFormRep.Get(formId);

            if (form == null)
            {
                return(false);
            }
            CPFormView view = new Form.CPFormView();
            int        autoIndex;

            view.ViewCode       = CPAutoNumHelper.Instance().GetNextAutoNum("FormViewCodeAuto", out autoIndex);
            view.AutoIndex      = autoIndex;
            view.ViewName       = "默认一行两列式视图";
            view.FormId         = form.Id;
            view.ViewType       = CPFormEnum.ViewTypeEnum.TwoColumn;
            view.ViewDeviceType = CPFormEnum.ViewDeviceTypeEnum.PCIphoneIpad;
            view.IsDefault      = true;
            view.ViewFieldCol   = new List <CPFormViewField>();
            #region 获取所有的字段
            List <CPFormField> fieldCol = this.GetFormFieldCol(formId);
            int nOrder = 10;
            fieldCol.ForEach(t => {
                CPFormViewField vT = new CPFormViewField();
                vT.FormId          = form.Id;
                vT.FieldId         = t.Id;
                vT.ShowOrder       = nOrder;
                nOrder             = nOrder + 10;
                vT.ViewBlockIndex  = 0;
                //  vT.FieldStatus = CPFormEnum.FieldStatusEnum.Edit;
                vT.IsSpanAll = false;
                //vT.FieldTitleShowWidth = 20;
                //vT.ShowWidth = "98%";
                //vT.MultiRows = 5;
                //vT.ShowHeight = 100;

                view.ViewFieldCol.Add(vT);
            });
            #endregion
            this._CPFormViewRep.Add(view);
            return(true);
        }
Example #4
0
        private string GetControlHtml(string tableField, CPForm form, List <CPFormField> fieldCol, CPFormView view,
                                      List <CPFormFieldRight> fieldRightCol, CPEnum.DeviceTypeEnum curDeviceType
                                      , bool isView)
        {
            tableField = tableField.Replace("{@", "").Replace("@}", "");
            string[]    fArray   = tableField.Split('.');
            CPFormField curField = null;

            fieldCol.ForEach(t => {
                if (t.TableName.Equals(fArray[0], StringComparison.CurrentCultureIgnoreCase) &&
                    t.FieldName.Equals(fArray[1], StringComparison.CurrentCultureIgnoreCase))
                {
                    curField = t;
                    return;
                }
            });
            if (curField == null)
            {
                return("未找到字段【" + tableField + "】");
            }
            CPFormFieldRight         fieldRight = null;
            IList <CPFormFieldRight> rCol       = fieldRightCol.Where(c => c.FieldId.Equals(curField.Id)).ToList();

            if (rCol.Count > 0)
            {
                fieldRight = rCol[0];
            }
            bool isMainTable = true;

            if (fArray[0].Equals(form.MainTableName, StringComparison.CurrentCultureIgnoreCase) == false)
            {
                isMainTable = false;
            }
            if (isView)
            {
                if (curField.FieldStatus == CPFormEnum.FieldStatusEnum.Edit)
                {
                    curField.FieldStatus = CPFormEnum.FieldStatusEnum.Read;
                }
            }
            return(ICPFormControlManager.GetControlInstance(curField).FormatHtml(curField, fieldRight, isMainTable ? false : true));
        }
Example #5
0
        public SaveFormDataReturn SaveFormData([FromBody] SaveFormDataInput input)
        {
            base.SetHeader();
            SaveFormDataReturn re = new SaveFormDataReturn();

            if (this.CheckUserIden(input.CurUserId, input.CurUserIden) == false)
            {
                re.Result   = false;
                re.ErrorMsg = "系统检测到非法获取数据,请传入正确的用户会话Key与用户Id参数!";
                return(re);
            }
            try
            {
                CPForm         form = CPFormTemplate.Instance(input.CurUserId).GetForm(input.FormCode, true, true, false, false, false, false);
                string         errormsg;
                string         pkValues = input.PKValue;
                CPFormUseScene useScene = CPFormTemplate.Instance(input.CurUserId).GetFormUseScene(input.SceneCode, false);
                re.Result = CPFormEngine.Instance(input.CurUserId).SaveData(form, form.ChildTableCol, form.FieldCol,
                                                                            ref pkValues, input.FormDataJSON, useScene, out errormsg);
                if (re.Result == false)
                {
                    re.ErrorMsg = errormsg;
                }
                else
                {
                    re.PKValues = pkValues;
                }
                return(re);
            }
            catch (Exception ex)
            {
                re.Result   = false;
                re.ErrorMsg = ex.Message.ToString();
                return(re);
            }
        }
Example #6
0
        public GetFormInfoReturn GetFormInfo(string FormCode, string SceneCode, string ViewCode, string InitGroupCode,
                                             string RightGroupCode, string PKValues
                                             , int CurUserId, string CurUserIden, string DeviceType = "1",
                                             bool IsView = false
                                             )
        {
            GetFormInfoReturn re = new GetFormInfoReturn();

            try
            {
                base.SetHeader();
                FormCode       = CPAppContext.FormatSqlPara(FormCode);
                SceneCode      = CPAppContext.FormatSqlPara(SceneCode);
                ViewCode       = CPAppContext.FormatSqlPara(ViewCode);
                InitGroupCode  = CPAppContext.FormatSqlPara(InitGroupCode);
                RightGroupCode = CPAppContext.FormatSqlPara(RightGroupCode);
                PKValues       = CPAppContext.FormatSqlPara(PKValues);
                CurUserIden    = CPAppContext.FormatSqlPara(CurUserIden);
                DeviceType     = CPAppContext.FormatSqlPara(DeviceType);

                if (this.CheckUserIden(CurUserId, CurUserIden) == false)
                {
                    re.Result   = false;
                    re.ErrorMsg = "系统检测到非法获取数据,请传入正确的用户会话Key与用户Id参数!";
                    return(re);
                }
                CPForm form = CPFormTemplate.Instance(CurUserId).GetForm(FormCode, true, true, false, false, false, true);
                form.ViewCol = new List <CPFormView>();
                form.ViewCol.Add(CPFormTemplate.Instance(CurUserId).GetFormView(ViewCode, true));
                //re.Form = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<CPForm, CPFormClient>()
                //                                  .Map(form);
                Mapper.Initialize(cfg =>
                {
                    cfg.CreateMap <CPForm, CPFormClient>();
                });

                re.Form = AutoMapper.Mapper.Map <CPFormClient>(form);
                CPFormGroup rightGroup = CPFormTemplate.Instance(CurUserId).GetFormRightGroup(RightGroupCode, true);
                // re.FieldRightCol = (rightGroup == null ? null : rightGroup.FieldRightCol);
                CPFormGroup initGroup = CPFormTemplate.Instance(CurUserId).GetFormInitGroup(InitGroupCode, true);
                re.Form.FieldInitCol = (initGroup == null ? null : initGroup.FieldInitCol);
                re.ViewHTML          = CPFormTemplate.Instance(CurUserId).FormatFormViewHtml(form, form.FieldCol, form.ViewCol[0],
                                                                                             (rightGroup == null ? null : rightGroup.FieldRightCol),
                                                                                             CPEnum.ConvertDeviceTypeEnum(int.Parse(DeviceType)), true, IsView);
                //获取应用场景
                re.Form.UseSceneCol = new List <CPFormUseScene>();
                re.Form.UseSceneCol.Add(CPFormTemplate.Instance(CurUserId).GetFormUseScene(SceneCode, true));
                re.Form.UseSceneCol.ForEach(t =>
                {
                    t.FormSavedInfo = CPExpressionHelper.Instance.RunCompile(t.FormSavedInfo);

                    //处理按钮是否显示
                    List <CPFormUseSceneFunc> funcCol = new List <CPFormUseSceneFunc>();
                    t.FuncCol.ForEach(func => {
                        if (func.FuncIsShowInView == CPFormEnum.FuncIsShowInViewEnum.ShowAll)
                        {
                            funcCol.Add(func);
                        }
                        else if (func.FuncIsShowInView == CPFormEnum.FuncIsShowInViewEnum.OnlyWriteShow)
                        {
                            if (IsView == false)
                            {
                                funcCol.Add(func);
                            }
                        }
                        else if (func.FuncIsShowInView == CPFormEnum.FuncIsShowInViewEnum.OnlyReadShow)
                        {
                            if (IsView == true)
                            {
                                funcCol.Add(func);
                            }
                        }
                    });
                    #region 添加修改配置按钮
                    if (re.Form.SysId.HasValue && re.Form.SysId.Value.Equals(CPAppContext.InnerSysId) == false)
                    {
                        string UserAdminSysIds = CPExpressionHelper.Instance.RunCompile("${CPUser.UserAdminSysIds()}");
                        if (UserAdminSysIds.Split(',').ToList().Contains(re.Form.SysId.ToString()))
                        {
                            CPFormUseSceneFunc func1 = new CPFormUseSceneFunc();
                            func1.FuncTitle          = "修改配置";
                            func1.ShowOrder          = 999999;
                            func1.FuncIcon           = "icon-shezhi1";
                            func1.IsControlByRight   = false;
                            func1.FuncIsShowInView   = CPFormEnum.FuncIsShowInViewEnum.ShowAll;
                            func1.FuncExeJS          = "CPFormUpdateConfig(" + re.Form.Id + ")";
                            func1.SceneID            = t.Id;
                            funcCol.Add(func1);
                        }
                    }
                    #endregion
                    t.FuncCol = funcCol;
                    t.FuncCol = t.FuncCol.OrderBy(c => c.ShowOrder).ToList();
                });

                //读取真实数据
                re.FormDataJSON = CPFormEngine.Instance(CurUserId).GetFormDataJSON(form, form.ChildTableCol,
                                                                                   form.FieldCol, re.Form.FieldInitCol, PKValues, re.Form.UseSceneCol[0]);
                re.Result = true;
                return(re);
            }
            catch (Exception ex)
            {
                re.Result   = false;
                re.ErrorMsg = ex.Message.ToString();
                return(re);
            }
        }
Example #7
0
 public ICPFormBeforeLoadEventArgs(CPForm form, string pkValue, DataSet formData)
 {
     this.Form     = form;
     this.PKValue  = PKValue;
     this.FormData = formData;
 }
Example #8
0
 public ICPFormAfterSaveEventArgs(CPForm form, string pkValue, dynamic formData)
 {
     this.Form     = form;
     this.PKValue  = pkValue;
     this.FormData = formData;
 }
Example #9
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);
        }
Example #10
0
 public DataSet GetFormData(CPForm form, List <CPFormChildTable> childTableCol, List <CPFormField> fieldCol, string pkValue)
 {
     return(this._CPFormRep.ReadRealData(form, childTableCol, fieldCol, pkValue));
 }
Example #11
0
        public DataSet InitFieldValue(CPForm form, List <CPFormChildTable> childTableCol, List <CPFormField> fieldCol, List <CPFormFieldInit> initValueCol, DataSet ds, string pkValue)
        {
            if (initValueCol == null || initValueCol.Count <= 0)
            {
                return(ds);
            }
            #region  先看看有没有子表的初始化,如果有,针对每个子表再搞一个新的表来,用来存储初始化字段的值,便于在JS里加新行时,再次初始化
            childTableCol.ForEach(cTable => {
                List <CPFormField> fCol = fieldCol.Where(c => c.TableName.Equals(cTable.TableName)).ToList();
                List <int> aFieldIdCol  = new List <int>();
                fCol.ForEach(f => {
                    aFieldIdCol.Add(f.Id);
                });
                List <CPFormFieldInit> tmpInitCol = initValueCol.Where(c => aFieldIdCol.Contains(c.FieldId.Value)).ToList();
                if (tmpInitCol.Count > 0)
                {
                    DataTable dtNew = new DataTable();
                    dtNew.TableName = cTable.TableName + "_ExtendTableInitValue";
                    tmpInitCol.ForEach(t => {
                        List <CPFormField> tF = fCol.Where(c => c.Id.Equals(t.FieldId.Value)).ToList();
                        DataColumn dc         = new DataColumn();
                        dc.DataType           = typeof(string);
                        dc.ColumnName         = tF[0].FieldName;
                        dtNew.Columns.Add(dc);
                    });
                    DataRow dr = dtNew.NewRow();
                    foreach (DataColumn dc in dtNew.Columns)
                    {
                        dr[dc.ColumnName] = DBNull.Value;
                    }
                    dtNew.Rows.Add(dr);
                    ds.Tables.Add(dtNew);
                }
            });
            #endregion
            initValueCol.ForEach(t =>
            {
                //查找字段
                List <CPFormField> tmpFCol = fieldCol.Where(c => c.Id.Equals(t.FieldId)).ToList();
                if (tmpFCol.Count <= 0)
                {
                    return;
                }

                if (t.InitTimeType == CPFormEnum.InitTimeTypeEnum.Add)
                {
                    #region 新增时初始化
                    if (string.IsNullOrEmpty(pkValue))
                    {
                        #region 新增
                        //看看是不是拓展表的
                        bool isExtendTable = false;
                        if (childTableCol.Where(c => c.TableName.Equals(tmpFCol[0].TableName)).Count() > 0)
                        {
                            isExtendTable = true;
                        }
                        int autoIndex         = 0;
                        string autoIndexField = "";
                        string sValue         = this.GetInitValue(t, out autoIndex, out autoIndexField);
                        ds.Tables[tmpFCol[0].TableName].Rows[0][tmpFCol[0].FieldName] = sValue;
                        if (t.InitType == CPFormEnum.InitTypeEnum.Auto)
                        {
                            ds.Tables[tmpFCol[0].TableName].Rows[0][autoIndexField] = autoIndex;
                        }
                        if (isExtendTable)
                        {
                            ds.Tables[tmpFCol[0].TableName + "_ExtendTableInitValue"].Rows[0][tmpFCol[0].FieldName] = sValue;
                        }
                        #endregion
                    }
                    #endregion
                }
                else if (t.InitTimeType == CPFormEnum.InitTimeTypeEnum.NoValue)
                {
                    #region 无值时初始化
                    //看下是主表字段还是子表字段
                    List <CPFormChildTable> cTCol = childTableCol.Where(c => c.TableName.Equals(tmpFCol[0].TableName)).ToList();
                    if (cTCol.Count <= 0)
                    {
                        //主表
                        int autoIndex         = 0;
                        string autoIndexField = "";
                        string sValue         = this.GetInitValue(t, out autoIndex, out autoIndexField);
                        object obj            = ds.Tables[tmpFCol[0].TableName].Rows[0][tmpFCol[0].FieldName];
                        if (Convert.IsDBNull(obj) || obj == null || string.IsNullOrEmpty(obj.ToString().Trim()))
                        {
                            ds.Tables[tmpFCol[0].TableName].Rows[0][tmpFCol[0].FieldName] = sValue;
                            if (t.InitType == CPFormEnum.InitTypeEnum.Auto)
                            {
                                ds.Tables[tmpFCol[0].TableName].Rows[0][autoIndexField] = autoIndex;
                            }
                        }
                    }
                    else
                    {
                        //子表
                        foreach (DataRow dr in ds.Tables[tmpFCol[0].TableName].Rows)
                        {
                            object obj            = dr[tmpFCol[0].FieldName];
                            int autoIndex         = 0;
                            string autoIndexField = "";
                            string sValue         = this.GetInitValue(t, out autoIndex, out autoIndexField);
                            ds.Tables[tmpFCol[0].TableName + "_ExtendTableInitValue"].Rows[0][tmpFCol[0].FieldName] = sValue;
                            if (Convert.IsDBNull(obj) || obj == null || string.IsNullOrEmpty(obj.ToString().Trim()))
                            {
                                dr[tmpFCol[0].FieldName] = sValue;

                                if (t.InitType == CPFormEnum.InitTypeEnum.Auto)
                                {
                                    //感觉自动编号的初始化在拓展表里会有问题
                                    dr[autoIndexField] = autoIndex;
                                }
                            }
                        }
                    }
                    #endregion
                }
                else if (t.InitTimeType == CPFormEnum.InitTimeTypeEnum.All)
                {
                    #region 总是初始化
                    //看下是主表字段还是子表字段
                    List <CPFormChildTable> cTCol = childTableCol.Where(c => c.TableName.Equals(tmpFCol[0].TableName)).ToList();
                    if (cTCol.Count <= 0)
                    {
                        //主表
                        int autoIndex         = 0;
                        string autoIndexField = "";
                        string sValue         = this.GetInitValue(t, out autoIndex, out autoIndexField);
                        ds.Tables[tmpFCol[0].TableName].Rows[0][tmpFCol[0].FieldName] = sValue;
                        if (t.InitType == CPFormEnum.InitTypeEnum.Auto)
                        {
                            ds.Tables[tmpFCol[0].TableName].Rows[0][autoIndexField] = autoIndex;
                        }
                    }
                    else
                    {
                        //子表
                        foreach (DataRow dr in ds.Tables[tmpFCol[0].TableName].Rows)
                        {
                            object obj               = dr[tmpFCol[0].FieldName];
                            int autoIndex            = 0;
                            string autoIndexField    = "";
                            string sValue            = this.GetInitValue(t, out autoIndex, out autoIndexField);
                            dr[tmpFCol[0].FieldName] = sValue;
                            ds.Tables[tmpFCol[0].TableName + "_ExtendTableInitValue"].Rows[0][tmpFCol[0].FieldName] = sValue;
                            if (t.InitType == CPFormEnum.InitTypeEnum.Auto)
                            {
                                //感觉自动编号的初始化在拓展表里会有问题
                                dr[autoIndexField] = autoIndex;
                            }
                        }
                    }
                    #endregion
                }
            });
            return(ds);
        }
Example #12
0
        public string FormatFormViewHtml(CPForm form, List <CPFormField> fieldCol, CPFormView view,
                                         List <CPFormFieldRight> fieldRightCol, CPEnum.DeviceTypeEnum curDeviceType, bool isRealCreateControlHtml
                                         , bool isView)
        {
            StringBuilder sbHTML = new StringBuilder();

            if (fieldRightCol == null)
            {
                fieldRightCol = new List <CPFormFieldRight>();
            }
            if (view.ViewType == CPFormEnum.ViewTypeEnum.TwoColumn ||
                view.ViewType == CPFormEnum.ViewTypeEnum.OneColumn)
            {
                #region 内置布局,一行四列式或一行两列式
                if (view.ViewType == CPFormEnum.ViewTypeEnum.OneColumn)
                {
                    //改成通栏展现,即变成 一行两列式
                    view.ViewFieldCol.ForEach(t => {
                        t.IsSpanAll = true;
                    });
                }
                //先取出主表的和包括子拓展表的字段
                List <CPFormField> mainTableField = fieldCol.Where(t => t.TableName.Equals(form.MainTableName) || t.IsChildTable.Value).ToList();
                List <int>         fieidCol       = new List <int>();
                mainTableField.ForEach(t => { fieidCol.Add(t.Id); });
                //转化成视图中的字段
                List <CPFormViewField> mainTableFormViewField = view.ViewFieldCol.Where(c => fieidCol.Contains(c.FieldId)).ToList();
                string mainHTML = this.FormatOneTableHTML(form, fieldCol, view, mainTableFormViewField,
                                                          fieldRightCol, curDeviceType, 4, true, isRealCreateControlHtml, isView);
                //再看看子表的
                if (form.ChildTableCol != null && form.ChildTableCol.Count > 0)
                {
                    form.ChildTableCol.ForEach(cTable => {
                        List <CPFormField> cTableField = fieldCol.Where(t => t.TableName.Equals(cTable.TableName) && t.IsChildTable.Value == false).ToList();
                        fieidCol.Clear();
                        cTableField.ForEach(t => { fieidCol.Add(t.Id); });
                        //转化成视图中的字段
                        List <CPFormViewField> cTableFormViewField = view.ViewFieldCol.Where(c => fieidCol.Contains(c.FieldId)).ToList();
                        string cHTML = this.FormatOneTableHTML(form, fieldCol, view, cTableFormViewField,
                                                               fieldRightCol, curDeviceType, 4, false, isRealCreateControlHtml, isView);
                        mainHTML = mainHTML.Replace("{@" + cTable.TableName + "@}", cHTML);
                    });
                }
                sbHTML.Append(mainHTML);
                #endregion
            }

            else if (view.ViewType == CPFormEnum.ViewTypeEnum.TextEditor)
            {
                #region 编辑器布局
                string          sHtml      = view.FormViewHTML;
                string          regexConst = @"{\@[\s\S]*?\@}";
                Regex           re         = new Regex(regexConst, RegexOptions.IgnoreCase);
                MatchCollection matches    = re.Matches(sHtml);
                foreach (Match match in matches)
                {
                    sHtml = sHtml.Replace(match.Value, this.GetControlHtml(match.Value, form, fieldCol, view, fieldRightCol,
                                                                           curDeviceType, isView));
                }
                sbHTML.Append(sHtml);
                if (form.ChildTableCol.Count <= 0)
                {
                    string sHtml2 = @"<select   id='CPForm_TmpHideSelect'     style='width:0px;display:none;' ";
                    sHtml2 += @"<option value='{{selectItem.valueEx}}' ng-repeat='selectItem in FormObj.Data.CPFormTmpHideSelectTable track by $index'  on-Repeat-Finished-Render >{{selectItem.textEx}}</option>";
                    sHtml2 += " />";

                    sbHTML.Append("<div>" + sHtml2 + "</div>");
                }
                #endregion
            }
            return(sbHTML.ToString());
        }
Example #13
0
        private string FormatOneTableHTML(CPForm form, List <CPFormField> fieldCol, CPFormView view, List <CPFormViewField> viewFieldCol,
                                          List <CPFormFieldRight> fieldRightCol,
                                          CPEnum.DeviceTypeEnum curDeviceType, int oneRowColumn, bool isMainTable, bool isRealCreateControlHtml, bool isView)
        {
            StringBuilder          sbHTML      = new StringBuilder();
            List <CPFormViewField> tmpFieldCol = viewFieldCol.OrderBy(t => t.ShowOrder).ToList();

            #region 内置布局,按table方式
            if (curDeviceType == CPEnum.DeviceTypeEnum.PCBrowser)
            {
                StringBuilder sbHidden = new StringBuilder();
                sbHTML.Append("<table  border=\"0\" style='width:99%;' align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tbody>");
                if (isMainTable)
                {
                    //如果没有拓展表,则自动构建一个隐藏的下拉列表,用来解决没有ng-repeat,不能执行ngRepeatFinished事件的问题
                    if (form.ChildTableCol.Count <= 0)
                    {
                        if (isRealCreateControlHtml)
                        {
                            string sHtml = @"<select   id='CPForm_TmpHideSelect'     style='width:0px;display:none;' ";
                            sHtml += @"<option value='{{selectItem.valueEx}}' ng-repeat='selectItem in FormObj.Data.CPFormTmpHideSelectTable track by $index'  on-Repeat-Finished-Render >{{selectItem.textEx}}</option>";
                            sHtml += " />";

                            sbHTML.Append("<tr><td colspan='" + oneRowColumn + "' class='trHeader'>" + form.FormTitle + sHtml + "</td></tr>");
                        }
                    }
                    else
                    {
                        sbHTML.Append("<tr><td colspan='" + oneRowColumn + "' class='trHeader'>" + form.FormTitle + "</td></tr>");
                    }
                }
                int  curRowIndex = 0;
                bool lastIsTrEnd = false;
                tmpFieldCol.ForEach(t => {
                    IList <CPFormField> tmpCol = fieldCol.Where(c => c.Id.Equals(t.FieldId)).ToList();
                    if (tmpCol.Count <= 0)
                    {
                        return;
                    }
                    CPFormFieldRight fieldRight   = null;
                    IList <CPFormFieldRight> rCol = fieldRightCol.Where(c => c.FieldId.Equals(t.FieldId)).ToList();
                    if (rCol.Count > 0)
                    {
                        fieldRight = rCol[0];
                    }
                    if (tmpCol[0].FieldStatus == CPFormEnum.FieldStatusEnum.Hidden)
                    {
                        string controlHtml = "";
                        if (isRealCreateControlHtml)
                        {
                            if (isView)
                            {
                                if (tmpCol[0].FieldStatus == CPFormEnum.FieldStatusEnum.Edit)
                                {
                                    tmpCol[0].FieldStatus = CPFormEnum.FieldStatusEnum.Read;
                                }
                            }
                            controlHtml = ICPFormControlManager.GetControlInstance(tmpCol[0]).FormatHtml(tmpCol[0], fieldRight, isMainTable ? false : true);
                        }
                        else
                        {
                            controlHtml = "{@" + tmpCol[0].TableName + "." + tmpCol[0].FieldName + "@}";
                        }
                        sbHidden.Append(controlHtml);
                        return;
                    }
                    if (tmpCol[0].ControlType == CPFormEnum.ControlTypeEnum.ChildTableExtend)
                    {
                        #region 子表
                        if (lastIsTrEnd == false)
                        {
                            sbHTML.Append("<td class='tdLeft'></td><td class='tdRight'></td></tr>");
                        }
                        sbHTML.Append("<tr><td colspan='" + oneRowColumn + "' class='trHeader'><div class='ChildTableHeaderLeft'>" + tmpCol[0].FieldTitle + "</div><div  class='ChildTableHeaderRight'><input type='button' id='btnCPFormAddChildRow_" + tmpCol[0].TableName + "'  class='btnExtendTableAdd'  ng-click=\"CPFormAddChildRow('btnCPFormAddChildRow_" + tmpCol[0].TableName + "',true)\"  data-TableName='" + tmpCol[0].TableName + "'  value='添加'/></div></td></tr>");
                        sbHTML.Append("<tr   ng-repeat='item in FormObj.Data." + tmpCol[0].TableName + "' on-Repeat-Finished-Render  id=\"trCPFormExtendTable_" + tmpCol[0].TableName + "\"  ><td colspan='" + oneRowColumn + "' class='CPFormExtendTableTdCss' >");
                        sbHTML.Append("{@" + tmpCol[0].FieldName + "@}");//最后统一替换
                        sbHTML.Append("</td></tr>");
                        curRowIndex = 0;
                        lastIsTrEnd = true;
                        #endregion
                    }
                    else
                    {
                        #region 非子表
                        string notNull = "";
                        if (tmpCol[0].IsAllowNull.Value == false)
                        {
                            notNull = "<span  class='NotAllowNullCss'>*</span>";
                        }
                        if (t.IsSpanAll.Value)
                        {
                            #region 通栏展现
                            if (lastIsTrEnd == false && curRowIndex != 0)
                            {
                                sbHTML.Append("<td class='tdLeft' style='width:" + tmpCol[0].FieldTitleShowWidth + "%'></td>");
                                sbHTML.Append("<td class='tdRight' style='width:" + (50 - tmpCol[0].FieldTitleShowWidth) + "%;' ></td>");
                                sbHTML.Append("</tr>");
                            }
                            sbHTML.Append("<tr>");
                            sbHTML.Append("<td class='tdLeft' style='width:" + tmpCol[0].FieldTitleShowWidth + "%'>" + tmpCol[0].FieldTitle + ":" + notNull + "</td>");
                            string controlHtml = "";
                            if (isRealCreateControlHtml)
                            {
                                if (isView)
                                {
                                    if (tmpCol[0].FieldStatus == CPFormEnum.FieldStatusEnum.Edit)
                                    {
                                        tmpCol[0].FieldStatus = CPFormEnum.FieldStatusEnum.Read;
                                    }
                                }
                                controlHtml = ICPFormControlManager.GetControlInstance(tmpCol[0]).FormatHtml(tmpCol[0], fieldRight, isMainTable ? false : true);
                            }
                            else
                            {
                                controlHtml = "{@" + tmpCol[0].TableName + "." + tmpCol[0].FieldName + "@}";
                            }
                            sbHTML.Append("<td class='tdRight' style='width:" + (100 - tmpCol[0].FieldTitleShowWidth) + "%;'  colspan='" + (oneRowColumn - 1) + "'>" + controlHtml + "</td>");
                            sbHTML.Append("</tr>");
                            curRowIndex = 0;
                            lastIsTrEnd = true;
                            #endregion
                        }
                        else
                        {
                            #region 非通栏展现
                            if (curRowIndex == 0)
                            {
                                sbHTML.Append("<tr>");
                                lastIsTrEnd = false;
                            }

                            sbHTML.Append("<td class='tdLeft' style='width:" + tmpCol[0].FieldTitleShowWidth + "%'>" + tmpCol[0].FieldTitle + ":" + notNull + "</td>");
                            string controlHtml = "";
                            if (isRealCreateControlHtml)
                            {
                                if (isView)
                                {
                                    if (tmpCol[0].FieldStatus == CPFormEnum.FieldStatusEnum.Edit)
                                    {
                                        tmpCol[0].FieldStatus = CPFormEnum.FieldStatusEnum.Read;
                                    }
                                }
                                controlHtml = ICPFormControlManager.GetControlInstance(tmpCol[0]).FormatHtml(tmpCol[0], fieldRight, isMainTable ? false : true);
                            }
                            else
                            {
                                controlHtml = "{@" + tmpCol[0].TableName + "." + tmpCol[0].FieldName + "@}";
                            }
                            sbHTML.Append("<td class='tdRight' style='width:" + (50 - tmpCol[0].FieldTitleShowWidth) + "%;' >" + controlHtml + "</td>");
                            curRowIndex++;
                            if (curRowIndex >= 2)
                            {
                                sbHTML.Append("</tr>");
                                curRowIndex = 0;
                                lastIsTrEnd = true;
                            }
                            #endregion
                        }
                        #endregion
                    }
                });
                if (lastIsTrEnd == false)
                {
                    sbHTML.Append("<td class='tdLeft'></td><td class='tdRight'></td></tr>");
                }
                if (sbHidden.Length > 0)
                {
                    sbHTML.Append("<tr ><td colspan='" + oneRowColumn + "' >");
                    sbHTML.Append(sbHidden);
                    sbHTML.Append("</td></tr>");
                }
                if (isMainTable == false)
                {//拓展表,最后加一行空白作为分隔
                    sbHTML.Append("<tr ><td colspan='" + oneRowColumn + "' class='trExtendTableLastRow' >");
                    sbHTML.Append("</td></tr>");
                }

                sbHTML.Append("</tbody></table>");
            }

            #endregion
            return(sbHTML.ToString());
        }
Example #14
0
        public bool InitFormDefaultViewForEditor(int formId)
        {
            CPForm form = this.GetForm(formId, true, true, false, false, false, true);

            if (form == null)
            {
                return(false);
            }
            CPFormView view = new Form.CPFormView();
            int        autoIndex;

            view.ViewCode       = CPAutoNumHelper.Instance().GetNextAutoNum("FormViewCodeAuto", out autoIndex);
            view.AutoIndex      = autoIndex;
            view.ViewName       = "使用编辑器排版视图";
            view.FormId         = form.Id;
            view.ViewType       = CPFormEnum.ViewTypeEnum.TextEditor;
            view.ViewDeviceType = CPFormEnum.ViewDeviceTypeEnum.PCIphoneIpad;
            view.IsDefault      = false;
            view.FormViewHTML   = "";
            view.ViewFieldCol   = new List <CPFormViewField>();
            #region 默认组一个一行四列的排版
            List <CPFormField>     fieldCol     = this.GetFormFieldCol(form.Id);
            List <CPFormViewField> viewFieldCol = new List <CPFormViewField>();
            int nIndex = 10;
            fieldCol.ForEach(t => {
                CPFormViewField vF = new CPFormViewField();
                vF.FieldId         = t.Id;
                vF.FormId          = t.FormId;
                vF.IsSpanAll       = false;
                vF.ShowOrder       = nIndex;
                nIndex++;
                vF.ViewBlockIndex = 0;
                vF.ViewId         = 0;
                viewFieldCol.Add(vF);
            });
            view.ViewFieldCol = viewFieldCol;
            //先取出主表的和包括子拓展表的字段
            List <CPFormField> mainTableField = fieldCol.Where(t => t.TableName.Equals(form.MainTableName) || t.IsChildTable.Value).ToList();
            List <int>         fieidCol       = new List <int>();
            mainTableField.ForEach(t => { fieidCol.Add(t.Id); });
            //转化成视图中的字段
            List <CPFormViewField> mainTableFormViewField = view.ViewFieldCol.Where(c => fieidCol.Contains(c.FieldId)).ToList();
            string mainHTML = this.FormatOneTableHTML(form, fieldCol, view, mainTableFormViewField,
                                                      new List <CPFormFieldRight>(), CPEnum.DeviceTypeEnum.PCBrowser, 4, true, false, false);
            //再看看子表的
            if (form.ChildTableCol != null && form.ChildTableCol.Count > 0)
            {
                form.ChildTableCol.ForEach(cTable => {
                    List <CPFormField> cTableField = fieldCol.Where(t => t.TableName.Equals(cTable.TableName) && t.IsChildTable.Value == false).ToList();
                    fieidCol.Clear();
                    cTableField.ForEach(t => { fieidCol.Add(t.Id); });
                    //转化成视图中的字段
                    List <CPFormViewField> cTableFormViewField = view.ViewFieldCol.Where(c => fieidCol.Contains(c.FieldId)).ToList();
                    string cHTML = this.FormatOneTableHTML(form, fieldCol, view, cTableFormViewField,
                                                           new List <CPFormFieldRight>(), CPEnum.DeviceTypeEnum.PCBrowser, 4, false, false, false);
                    mainHTML = mainHTML.Replace("{@" + cTable.TableName + "@}", cHTML);
                });
            }
            // sbHTML.Append(mainHTML);
            view.FormViewHTML = mainHTML;
            #endregion
            this._CPFormViewRep.Add(view);
            return(true);
        }
Example #15
0
        public bool SynFieldFromDb(int formId)
        {
            CPForm form = this._CPFormRep.Get(formId);

            if (form == null)
            {
                return(false);
            }
            List <CPFormChildTable> tableCol = this.GetFormChildTable(formId);
            List <CPFormField>      fieldCol = this.GetFormFieldCol(formId);
            List <CPFormField>      add      = new List <Form.CPFormField>();
            List <CPFormField>      edit     = new List <Form.CPFormField>();
            List <CPFormField>      del      = new List <Form.CPFormField>();

            List <CPDbField> tmpAllDbField = new List <CPDbField>();

            #region 先获取主表的字段
            List <CPDbField> mainTableFieldCol = CPAppContext.GetTableField(form.DbIns, form.MainTableName);
            if (mainTableFieldCol.Count > 0)
            {
                tmpAllDbField.AddRange(mainTableFieldCol);
            }
            mainTableFieldCol.ForEach(t => {
                List <CPFormField> q = fieldCol.Where(c => c.TableName.Equals(t.TableName, StringComparison.CurrentCultureIgnoreCase) && c.FieldName.Equals(t.FieldName, StringComparison.CurrentCultureIgnoreCase) && c.IsChildTable == false).ToList();
                if (q.Count > 0)
                {
                    //修改
                    // q[0].IsAllowNull = t.IsAllowNull;
                    q[0].FieldValueType   = t.ValueType;
                    q[0].FieldValueLength = t.ValueLength;
                    edit.Add(q[0]);
                }
                else
                {
                    //添加
                    CPFormField newQ         = new CPFormField();
                    newQ.FormId              = form.Id;
                    newQ.IsChildTable        = false;
                    newQ.TableName           = t.TableName;
                    newQ.FieldName           = t.FieldName;
                    newQ.FieldTitle          = t.FieldName;
                    newQ.ControlType         = CPFormEnum.ControlTypeEnum.TextBox;
                    newQ.IsAllowNull         = t.IsAllowNull;
                    newQ.FieldValueType      = t.ValueType;
                    newQ.FieldValueLength    = t.ValueLength;
                    newQ.OrganIsCanMultiSel  = true;
                    newQ.FieldStatus         = CPFormEnum.FieldStatusEnum.Edit;
                    newQ.FieldTitleShowWidth = 20;
                    newQ.ShowWidth           = "98%";
                    newQ.MultiRows           = 5;
                    newQ.ShowHeight          = 100;

                    add.Add(newQ);
                }
            });
            #endregion

            #region 再找子表的主段
            tableCol.ForEach(childTable => {
                #region 先找出子表本身
                List <CPFormField> qT = fieldCol.Where(c => c.TableName.Equals(childTable.TableName, StringComparison.CurrentCultureIgnoreCase) && c.FieldName.Equals(childTable.TableName, StringComparison.CurrentCultureIgnoreCase) && c.IsChildTable == true).ToList();
                if (qT.Count <= 0)
                {
                    //添加
                    CPFormField newQ        = new CPFormField();
                    newQ.FormId             = form.Id;
                    newQ.IsChildTable       = true;
                    newQ.TableName          = childTable.TableName;
                    newQ.FieldName          = childTable.TableName;
                    newQ.FieldTitle         = childTable.TableName + "子表";
                    newQ.ControlType        = CPFormEnum.ControlTypeEnum.ChildTableExtend;
                    newQ.OrganIsCanMultiSel = true;
                    add.Add(newQ);
                }
                #endregion
                List <CPDbField> cTableFieldCol = CPAppContext.GetTableField(form.DbIns, childTable.TableName);
                if (cTableFieldCol.Count > 0)
                {
                    tmpAllDbField.AddRange(cTableFieldCol);
                }
                cTableFieldCol.ForEach(t => {
                    List <CPFormField> q = fieldCol.Where(c => c.TableName.Equals(t.TableName, StringComparison.CurrentCultureIgnoreCase) && c.FieldName.Equals(t.FieldName, StringComparison.CurrentCultureIgnoreCase) && c.IsChildTable == false).ToList();
                    if (q.Count > 0)
                    {
                        //修改
                        //  q[0].IsAllowNull = t.IsAllowNull;
                        q[0].FieldValueType   = t.ValueType;
                        q[0].FieldValueLength = t.ValueLength;
                        edit.Add(q[0]);
                    }
                    else
                    {
                        //添加
                        CPFormField newQ        = new CPFormField();
                        newQ.FormId             = form.Id;
                        newQ.IsChildTable       = false;
                        newQ.TableName          = t.TableName;
                        newQ.FieldName          = t.FieldName;
                        newQ.FieldTitle         = t.FieldName;
                        newQ.ControlType        = CPFormEnum.ControlTypeEnum.TextBox;
                        newQ.IsAllowNull        = t.IsAllowNull;
                        newQ.FieldValueType     = t.ValueType;
                        newQ.FieldValueLength   = t.ValueLength;
                        newQ.OrganIsCanMultiSel = true;

                        newQ.FieldStatus         = CPFormEnum.FieldStatusEnum.Edit;
                        newQ.FieldTitleShowWidth = 20;
                        newQ.ShowWidth           = "98%";
                        newQ.MultiRows           = 5;
                        newQ.ShowHeight          = 100;
                        add.Add(newQ);
                    }
                });
            });
            #endregion

            #region 再找出要删除的
            fieldCol.ForEach(t => {
                if (t.IsChildTable == false)
                {
                    List <CPDbField> qQ = tmpAllDbField.Where(c => c.TableName.Equals(t.TableName, StringComparison.CurrentCultureIgnoreCase) && c.FieldName.Equals(t.FieldName, StringComparison.CurrentCultureIgnoreCase)).ToList();
                    if (qQ.Count <= 0)
                    {
                        del.Add(t);
                    }
                }
                else
                {
                    List <CPFormChildTable> qQ = tableCol.Where(c => c.TableName.Equals(t.TableName, StringComparison.CurrentCultureIgnoreCase)).ToList();
                    if (qQ.Count <= 0)
                    {
                        del.Add(t);
                    }
                }
            });
            #endregion

            //由于ef core批量写入数据时,采用了批处理方法,但这种方式会导致写入顺序错,暂时没有找到什么方法,所以改成一条条写。
            if (add.Count > 0)
            {
                this._CPFormFieldRep.AddOneByOne(add);
            }
            if (edit.Count > 0)
            {
                this._CPFormFieldRep.Update(edit);
            }
            if (del.Count > 0)
            {
                this._CPFormFieldRep.Delete(del);
            }

            #region  时再修改视图排版里的字段信息
            List <CPFormView> viewCol = this.GetFormView(form.Id, true);
            if (add.Count > 0)
            {
                #region 增加的
                viewCol.ForEach(t => {
                    if (t.ViewType == CPFormEnum.ViewTypeEnum.OneColumn
                        ||
                        t.ViewType == CPFormEnum.ViewTypeEnum.TwoColumn)
                    {
                        int nOrder = 0;
                        if (t.ViewFieldCol.Count > 0)
                        {
                            nOrder = t.ViewFieldCol.OrderByDescending(c => c.ShowOrder).FirstOrDefault().ShowOrder.Value;
                            nOrder = nOrder + 10;
                        }
                        List <CPFormViewField> col = new List <CPFormViewField>();
                        add.ForEach(f => {
                            CPFormViewField vT = new CPFormViewField();
                            vT.FormId          = form.Id;
                            vT.ViewId          = t.Id;
                            vT.FieldId         = f.Id;
                            vT.ShowOrder       = nOrder;
                            nOrder             = nOrder + 10;
                            vT.ViewBlockIndex  = 0;
                            // vT.FieldStatus = CPFormEnum.FieldStatusEnum.Edit;
                            vT.IsSpanAll = false;
                            //vT.FieldTitleShowWidth = 20;
                            //vT.ShowWidth = "98%";
                            //vT.MultiRows = 5;
                            //vT.ShowHeight = 100;

                            col.Add(vT);
                        });
                        if (col.Count > 0)
                        {
                            this._CPFormViewFieldRep.Add(col);
                        }
                    }
                });
                #endregion
            }
            if (del.Count > 0)
            {
                #region  除的

                viewCol.ForEach(t => {
                    if (t.ViewType == CPFormEnum.ViewTypeEnum.OneColumn
                        ||
                        t.ViewType == CPFormEnum.ViewTypeEnum.TwoColumn)
                    {
                        List <CPFormViewField> col = new List <CPFormViewField>();
                        t.ViewFieldCol.ForEach(c => {
                            if (del.Where(f => f.Id.Equals(c.FieldId)).ToList().Count > 0)
                            {
                                col.Add(c);
                            }
                        });
                        if (col.Count > 0)
                        {
                            this._CPFormViewFieldRep.Delete(col);
                        }
                    }
                });
                #endregion
            }
            #endregion
            return(true);
        }