Example #1
0
        public bool SaveViewHTML(int viewId, string viewHTML)
        {
            CPFormView view = this.GetFormViewByViewId(viewId, false);

            view.FormViewHTML = viewHTML;
            this._CPFormViewRep.Update(view);
            return(true);
        }
Example #2
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 #3
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 #4
0
        public List <CPFormField> GetFormFieldByViewId(int viewId)
        {
            CPFormView view = this.GetFormViewByViewId(viewId, false);

            return(this.GetFormFieldCol(view.FormId));
        }
Example #5
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));
        }