Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }