/// <summary> /// Set section title and build field list columns /// </summary> /// <param name="section"></param> public void BuildSection(EformSection section) { SectionTitle.Text = section.Title; ShowTitle.Checked = section.ShowTitle; // if section is grid, all fields in col 1 if (section.IsGrid) { Col1.BuildSectionFields(section.Fields.AsEnumerable(), false, true); } // otherwise fill fields in columns else { // get a list of fields for columns IEnumerable <EformField> col1 = GetFields(section, 0); IEnumerable <EformField> col2 = GetFields(section, 1); // bind field lists Col1.BuildSectionFields(col1, false, section.IsGrid); Col2.BuildSectionFields(col2, false, section.IsGrid); } }
/// <summary> /// For the given seciton, insert Date fields to match DateTextFields /// </summary> /// <param name="section">An Eform Section</param> private void NormalizeDateFields(EformSection section) { var dateFields = from field in section.Fields where field.Field.EndsWith("DateText") let dateValueField = field.Field.Replace("DateText", "Date") // only add date fields where exits where BOL.BusinessObject.HasField(field.Table, dateValueField) // create new eform field let dateEformField = new EformField(field.Table, dateValueField, typeof(CaisisHidden).Name) select dateEformField; // get a count of exisint columns int colCount = (from field in section.Fields select field.ColIndex).Distinct().Count(); // get count of existing rows int rowCount = (from field in section.Fields select field.RowIndex).Distinct().Count(); // add date fields to section for (int i = 0; i < dateFields.Count(); i++) { EformField dateField = dateFields.ElementAt(i); section.AddField(dateField); // grid date fields will be inserted at the end of last row if (section.IsGrid) { dateField.RowIndex = rowCount - 1; dateField.ColIndex = colCount + i; } // normal section fields will be inserted in a new row in first column else { dateField.RowIndex = rowCount + i; dateField.ColIndex = 0; } } }
/// <summary> /// Traverses a Section on nested child section, building INSERT /// </summary> /// <param name="builder"></param> /// <param name="section"></param> /// <param name="sectionIndex"></param> private void ProcessSection(EformMetadataBuilder builder, EformSection section, int sectionIndex) { // run date normalization NormalizeDateFields(section); // validate section bool isValid = AuditSectionFields(section); // continuing processing section and sub sections if (isValid) { if (section.IsGrid) { if (section.Fields.Count() > 0) { string tableName = section.Fields[0].Table; IEnumerable <string> gridFields = from f in section.Fields where f.Table == tableName select f.Field; // all fields in section should have the same name if (gridFields.Count() == section.Fields.Count()) { // use first field in grid as base for generating ids EformField baseField = section.Fields.First(); int recordId = GetRecordId(baseField.Table, baseField.Field, sectionIndex); int parentRecordId = GetParentRecordId(baseField.Table, baseField.Field); builder.NewGridSection(section.Title, section.ShowTitle, "1", tableName, gridFields, recordId, parentRecordId); } } } else { int colCount = (from field in section.Fields select field.ColIndex).Distinct().Count(); int rowCount = (from field in section.Fields select field.RowIndex).Distinct().Count(); builder.NewSection(section.Title, section.ShowTitle, "1", rowCount, colCount); // insert fields by col index, using colIndex + secitonIndex // to generate unique seed for each column in each section for (int colIndex = 0, seed = sectionIndex; colIndex < colCount; colIndex++, seed++) { // get list of fields in column var colFields = from field in section.Fields where field.ColIndex == colIndex select field; // insert fields foreach (EformField field in colFields) { int recordId = GetRecordId(field.Table, field.Field, seed); int parentRecordId = GetParentRecordId(field.Table, field.Field); builder.AddFieldToSection(field.Table, field.Field, field.RowIndex, colIndex, recordId, parentRecordId); } } } // recursively process child sections if (section.ChildSections.Count() > 0) { foreach (EformSection childSection in section.ChildSections) { ProcessSection(builder, childSection, sectionIndex); } } } }