Ejemplo n.º 1
0
        /// <summary>
        /// Inserts the EForm object into DB
        /// </summary>
        /// <param name="eform"></param>
        private void SaveEForm(Eform eform)
        {
            // default version number
            string versionNumber = "0";

            // ??? version number used for active bit, on insert, turn on, on exisitng, use prvious value
            if (!string.IsNullOrEmpty(POSTEFormId))
            {
                MetadataEForm prevEform = new MetadataEForm();
                prevEform.Get(int.Parse(POSTEFormId));
                versionNumber = prevEform[MetadataEForm.EFormVersionNum].ToString();
            }
            EformMetadataBuilder builder = new EformMetadataBuilder(eform.Name, eform.Disease, versionNumber);

            foreach (EformPage page in eform.Pages)
            {
                builder.NewPage(page.Title, "1");
                for (int i = 0; i < page.Sections.Length; i++)
                {
                    EformSection section = page.Sections[i];
                    ProcessSection(builder, section, i);
                }
            }

            // after traversing, save
            builder.Save();

            // update eform id hidden

            // locate inserted record


            MetadataEForm biz = new MetadataEForm();

            // after save, if existing eform exists, remove duplicate
            if (!string.IsNullOrEmpty(POSTEFormId))// && POSTEFormId != EFormId.Value)
            {
                int eformId = int.Parse(POSTEFormId);
                biz.Delete(eformId);

                biz           = GetEFormbyName(eform.Name);
                EFormId.Value = biz[MetadataEForm.MetadataEFormId].ToString();
                // set client message
                OperationMessage.Value = string.Empty;
            }
            else
            {
                biz           = GetEFormbyName(eform.Name);
                EFormId.Value = biz[MetadataEForm.MetadataEFormId].ToString();
                // set client message
                OperationMessage.Value = string.Empty;
            }
        }
Ejemplo n.º 2
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);
                    }
                }
            }
        }