private void BuildFormObjects(Form newForm, DataTable formData, DataTable formContainers, DataTable formElements, DataTable formChildElements, DataTable elementActions, DataTable formActions, DataTable elementBehaviors)
        {
            //Instantiate new lists
            newForm.ContainerNames = new List<string>();
            newForm.Elements = new List<Element>();

            #region Validation

            #region FormData

            //Validation
            if (!formData.Rows[0]["Name"].Equals(null))
                newForm.Name = formData.Rows[0]["Name"].ToString();

            if (!formData.Rows[0]["ItemID"].Equals(null))
                newForm.SitecoreID = formData.Rows[0]["ItemID"].ToString();

            if (!formData.Rows[0]["CSSClass"].Equals(null))
                newForm.CssClass = formData.Rows[0]["CSSClass"].ToString();

            if (!formData.Rows[0]["Header"].Equals(null))
                newForm.Header = formData.Rows[0]["Header"].ToString();

            #endregion

            #region FormContainer

            newForm.ContainerNames = new List<string>();
            foreach (DataRow row in formContainers.Rows)
            {
                //Validation
                if (!row["ContainerID"].Equals(null))
                    newForm.ContainerNames.Add(row["ContainerID"].ToString());
            }

            #endregion

            #region FormElement

            foreach (DataRow row in formElements.Rows)
            {
                Element element = new Element();

                //Validation
                if (!row["FormControl_ID"].Equals(null))
                    element.FormControlID = Convert.ToInt32(row["FormControl_ID"]);
                if (!row["LabelName"].Equals(null))
                    element.LabelName = row["LabelName"].ToString();
                if (!row["OrderNumber"].Equals(null))
                    element.OrderNumber = Convert.ToInt32(row["OrderNumber"].ToString());
                if (!row["ContainerName"].Equals(null))
                    element.ControllerName = row["ContainerName"].ToString();
                if (!row["ElementType"].Equals(null))
                    element.Type = row["ElementType"].ToString();
                if (!row["Validate"].Equals(null))
                    element.Validate = Convert.ToBoolean(row["Validate"].ToString());
                if (!row["ControlName"].Equals(null))
                    element.ControlName = row["ControlName"].ToString();
                if (!row["AprimoFieldName"].Equals(null))
                    element.AprimoName = row["AprimoFieldName"].ToString();
                if (!row["ControlList_ID"].Equals(null))
                    element.ControlID = (int)row["ControlList_ID"];

                #region ChildElements

                if (element.Type.ToLower().Equals("group"))
                {
                    //validation for element type group name
                    if (!row["GroupName"].Equals(null))
                        element.GroupName = row["GroupName"].ToString();

                    //iteration step for child element within the group element type
                    element.ChildElements = formChildElements.AsEnumerable().Select(child => new Element
                    {
                        FormControlID   = child.Field<int>("FormControl_ID"),
                        ControlID       = child.Field<int>("ControlList_ID"),
                        LabelName       = child.Field<string>("Text"),
                        ControlValue    = child.Field<string>("Value"),
                    }).ToList();
                }

                #endregion

                #region Action

                ElementAction action = new ElementAction();
                element.Actions = new List<ElementAction>();

                for (int i = 0; i < elementActions.Rows.Count; i++)
                {
                    //Validation
                    if (!elementActions.Rows[i]["ActionName"].Equals(null))
                    {
                        element.Actions.Add(new ElementAction { Action = elementActions.Rows[i]["ActionName"].ToString()});
                        element.Actions.Add(action);
                    }
                }

                #region FormActions
                for (int i = 0; i < formActions.Rows.Count; i++)
                {
                    //Validation
                    if (!formActions.Rows[i]["ECASReturnURL"].Equals(null))
                    {
                        element.Actions.Add(new ElementAction { ActionParameters =new KeyValuePair<string,string>("ECAS Login Required", formActions.Rows[i]["ECASReturnURL"].ToString())});
                        element.Actions.Add(action);
                    }
                }

                #endregion

                #endregion

                #region Behaviors

                foreach (DataRow behaviorRow in elementBehaviors.Rows)
                {
                    ElementBehavior elementBehavior = new ElementBehavior();

                    //Validation
                    if (behaviorRow["BehaviorName"].Equals(null))
                    {
                        elementBehavior.Behavior = behaviorRow["BehaviorName"].ToString();
                        element.Behaviors.Add(elementBehavior);
                    }
                }

                #endregion

                //add element to list of elements..
                newForm.Elements.Add(element);
            }

            #endregion

            #endregion

            //Build out HTML Objects...
            SetHTMLObjects(newForm);
        }
        private Form LoadForm(Esri.FormGenerator.Form newForm, DataTable formData, DataTable formContainers, DataTable formElements, DataTable elementActions, DataTable elementBehaviors)
        {
            //Instantiate new lists
            newForm.ContainerNames = new List<string>();
            newForm.Elements = new List<Element>();

            #region Validation

                #region FormData

                //Validation
                if (!formData.Rows[0]["Name"].Equals(null))
                    newForm.Name = formData.Rows[0]["Name"].ToString();

                if (!formData.Rows[0]["ItemID"].Equals(null))
                    newForm.SitecoreID = formData.Rows[0]["ItemID"].ToString();

                if (!formData.Rows[0]["CSSClass"].Equals(null))
                    newForm.CssClass = formData.Rows[0]["CSSClass"].ToString();

                #endregion

                #region FormContainer

                foreach (DataRow row in formContainers.Rows)
                {
                    //Validation
                    if (!row["ContainerID"].Equals(null))
                        newForm.ContainerNames = new List<string>();
                        newForm.ContainerNames.Add(row["ContainerID"].ToString());
                }

                #endregion

                #region FormElement

                foreach (DataRow row in formElements.Rows)
                {
                    Element element = new Element();

                    //Validation
                    if (!row["LabelName"].Equals(null))
                        element.LabelName = row["LabelName"].ToString();
                    if (!row["OrderNumber"].Equals(null))
                        element.OrderName = Convert.ToInt32(row["OrderNumber"].ToString());
                    if (!row["ContainerName"].Equals(null))
                        element.ControllerName = row["ContainerName"].ToString();
                    if (!row["ElementType"].Equals(null))
                        element.Type = row["ElementType"].ToString();
                    if (!row["Validate"].Equals(null))
                        element.Validate = Convert.ToBoolean(row["Validate"].ToString());
                    if (!row["ControlName"].Equals(null))
                        element.ControlName = row["ControlName"].ToString();

                    #region Action

                    foreach (DataRow elementRow in elementActions.Rows)
                    {
                        ElementAction action = new ElementAction();

                        //Validation
                        if (!elementActions.Rows[0]["ActionName"].Equals(null))
                        {
                            element.Actions = new List<ElementAction>();
                            element.Actions.Add(new ElementAction { Action = elementActions.Rows[0]["ActionName"].ToString() });
                            element.Actions.Add(action);
                        }
                    }

                    #endregion

                    #region Behaviors

                    foreach (DataRow behaviorRow in elementBehaviors.Rows)
                    {
                        ElementBehavior behavior = new ElementBehavior();

                        //Validation
                        if (behaviorRow["BehaviorName"].Equals(null))
                        {
                            behavior.Behavior = behaviorRow["BehaviorName"].ToString();
                            element.Behaviors.Add(behavior);
                        }
                    }

                    #endregion

                    //add element to list of elements..
                    newForm.Elements.Add(element);
                }

                #endregion

            #endregion

            return newForm;
        }