Пример #1
0
        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);
        }
Пример #2
0
        private void SetHTMLObjects(Form newForm)
        {
            //Controls to be built out..
            List<TextBox> TextBoxes             = new List<TextBox>();
            List<DropDownList> DropDownLists    = new List<DropDownList>();
            List<Button> Buttons                = new List<Button>();

            /*Main layout for divs and spans per object, including the child divs within the element object type*/
            HtmlGenericControl dynamicDemandDiv  = new HtmlGenericControl("div");
            HtmlGenericControl dynamicActionsDiv = new HtmlGenericControl("div");
            HtmlGenericControl dynamicChildDiv   = new HtmlGenericControl("div");

            dynamicActionsDiv.ID = "actions";
            dynamicDemandDiv.ID = "db-form-hidden";
            dynamicChildDiv.Attributes.Add("class", "group");

            dynamicActionsDiv.ClientIDMode  = ClientIDMode.Static;
            dynamicDemandDiv.ClientIDMode   = ClientIDMode.Static;
            dynamicChildDiv.ClientIDMode    = ClientIDMode.Static;

            //Set Header..
            litHeader.Text = newForm.Header;

            ///TODO:
            ///Create a new approach for element actions, but for the moment this is work when needing the correct action per element type.
            List<ElementAction> lElementActions = new List<ElementAction>();
            foreach (Element e in newForm.Elements){
                if (e.Actions.Count > 0){
                    lElementActions = e.Actions;
                    break;
                }
            }

            //Iteration of the actions within the element action list..
            foreach (ElementAction item in lElementActions){
                HtmlGenericControl actionDiv = new HtmlGenericControl("input");
                //validation against single action type
                if (!String.IsNullOrEmpty(item.Action)){
                    actionDiv.Attributes.Add("type", "hidden");
                    actionDiv.Attributes.Add("value", item.Action);
                    dynamicActionsDiv.Controls.Add(actionDiv);
                }
                //Validation against multi action type
                if (!String.IsNullOrEmpty(item.ActionParameters.Value)){
                    actionDiv.ID = "ecasRedirect";
                    actionDiv.Attributes.Add("type", "hidden");
                    actionDiv.Attributes.Add("value", item.ActionParameters.Key);
                    actionDiv.Attributes.Add("redirect", item.ActionParameters.Value);
                    actionDiv.ClientIDMode = ClientIDMode.Static;
                    dynamicActionsDiv.Controls.Add(actionDiv);
                }
            }

            //Creating dynamic holders
            foreach (string container in newForm.ContainerNames){
                Panel newPanel = new Panel();
                newPanel.ID = "pnl" + container.ToLower();
                newPanel.ClientIDMode = ClientIDMode.Static;
                pnlContainer.Controls.Add(newPanel);
            }

            //Creating dynamic objects
            foreach (Element element in newForm.Elements){
                //Create a new span each iteration through the elements..
                HtmlGenericControl dynamicDiv = new HtmlGenericControl("div");
                dynamicDiv.Attributes.Add("class", "set");
                dynamicDiv.Attributes.Add("fcid", element.FormControlID.ToString());
                dynamicDiv.ClientIDMode = ClientIDMode.Static;

                HtmlGenericControl dynamicSpan = new HtmlGenericControl("span");
                dynamicSpan.ClientIDMode = ClientIDMode.Static;

                //Set's each objects property set here..
                SetHtmlObjectsProperties(element, ref dynamicDiv, ref dynamicSpan, ref dynamicChildDiv);
            }

            //Build Dynamic Demand Base...
            pnlContainer.Controls.Add(dynamicDemandDiv);
            pnlContainer.Controls.Add(dynamicActionsDiv);
        }