Exemplo n.º 1
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));
        }
Exemplo n.º 2
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());
        }