Beispiel #1
0
        // this is to support some nesting work that Jay wanted to do
        private void TraverseEformControls(ControlCollection controls, XmlDocument xmlDoc)
        {
            List <IEformInputField> invalidFields = new List <IEformInputField>();

            foreach (Control con in controls)
            {
                if (con is IEformInputField)
                {
                    IEformInputField iEformField = con as IEformInputField;
                    // get raw node value
                    string nodeVal = GetNodeValue(iEformField, xmlDoc);
                    // no value found, node not found
                    if (nodeVal == null)
                    {
                        invalidFields.Add(iEformField);
                    }
                    else
                    {
                        // otherwise set control value
                        this.SetControlValue(iEformField, xmlDoc, nodeVal);
                    }
                }
                else if (con is HtmlContainerControl)
                {
                    TraverseEformControls(con.Controls, xmlDoc);
                }
            }

            // Publish Error if any invalid fields found
            if (invalidFields.Count > 0)
            {
                string newLine     = System.Environment.NewLine;
                string controlName = this.GetType().BaseType.Name;
                string controlPath = this.AppRelativeVirtualPath;
                // display that there was an xml mismatch
                System.Text.StringBuilder errorMessage = new System.Text.StringBuilder(string.Format("There was an error finding control values in component '{0}' in the XML Document.{1}", this.GetType().BaseType.Name, newLine));
                // display contorl and path to control
                errorMessage.AppendLine(string.Format("Control: {0}{2}Path: {1}{2}", controlName, controlPath, newLine));
                foreach (IEformInputField iEformField in invalidFields)
                {
                    // disable control
                    iEformField.Enabled  = false;
                    iEformField.CssClass = "DisabledEformInputField";
                    // set tooltip
                    if (iEformField is WebControl)
                    {
                        (iEformField as WebControl).ToolTip = disabledHelpText;
                    }

                    string tableName      = iEformField.Table;
                    string fieldName      = iEformField.Field;
                    string recordId       = iEformField.RecordId;
                    string parentRecordId = iEformField.ParentRecordId;
                    string controlType    = iEformField.GetType().Name;
                    errorMessage.AppendLine(string.Format("{5}Table: {0}{5} Field: {1}{5} RecordId: {2}{5} ParentRecordId: {3}{5}Control Type: {4}{5}{5}", tableName, fieldName, recordId, parentRecordId, controlType, newLine));
                }
                Exception ex = new Exception(errorMessage.ToString());
                ExceptionHandler.Publish(ex, XML_MISSMATCH_ERROR);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Writes the value from the eform input field to the associated Xml Node. Handles record Id's for one to many relations
        /// </summary>
        /// <param name="con"></param>
        /// <param name="xmlDoc"></param>
        protected void SetXmlNodeValue(IEformInputField con, XmlDocument xmlDoc)
        {
            if (con.Table != null)
            {
                XmlNode node = GetXmlNode(con.Table, con.Field, con.RecordId, con.ParentRecordId, xmlDoc);

                if (node != null)
                {
                    node.InnerText = PageUtil.GetInputControlValue(con);
                }
            }
        }
Beispiel #3
0
        private void WriteField(string table, string[] fields)
        {
            // preserve sanity
            if (table == null || table == "" || fields.Length == 0)
            {
                return;
            }

            Hashtable stringMap = new Hashtable();

            foreach (string s in fields)
            {
                stringMap[s] = "";
            }

            string      modFolder     = Caisis.UI.Core.Classes.XmlUtil.GetParentModuleDirectory(_eformFileName + ".xml", "EForms");
            XmlDocument eformsXml     = XmlUtil.GetXmlDoc("~\\Modules\\" + modFolder + "\\EForms\\" + _eformFileName + ".xml");
            XmlNodeList eformSections = eformsXml.SelectNodes("eform[@name='" + _eformName + "']/eformSection");

            holder.Controls.Clear();

            // need to record all the controls you have loaded so you don't load twice - jf
            List <string> loadedControlNames = new List <string>();


            foreach (XmlNode sectionNode in eformSections)
            {
                foreach (XmlNode controlNode in sectionNode)
                {
                    System.Web.UI.UserControl eFormControl = base.GetEFormControl(controlNode.Attributes["controlName"].Value + ".ascx");

                    foreach (Control con in eFormControl.Controls)
                    {
                        if (con is IEformInputField)
                        {
                            // we need to add (to our holder) the control containing table/fields and highlight the appropriate fields
                            IEformInputField inputField = (IEformInputField)con;
                            if (table == inputField.Table && stringMap.ContainsKey(inputField.Field))
                            {
                                if (!holder.Controls.Contains(eFormControl) && (!loadedControlNames.Contains(controlNode.Attributes["controlName"].Value)))
                                {
                                    holder.Controls.Add(eFormControl);
                                    loadedControlNames.Add(controlNode.Attributes["controlName"].Value);
                                }
                                base.SetInvalidStyle(con, "e7d1c8");
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// For the given eform docuemnt, build client scripts for handling client sider EFromDefaultValue logic.
        /// </summary>
        /// <param name="eformsXml">The Eform document containing EFromDefaultValue mappings</param>
        protected void BuildDefaultValuesScript(XmlDocument eformsXml)
        {
            var eFields = EFormController.GetEformDefaultValues(eformsXml);

            if (eFields.Count() > 0)
            {
                // list of all eform inputs
                IEnumerable <IEformInputField> inputs = PageUtil.GetControls <IEformInputField>(Page);
                // list of eform labels
                IEnumerable <EformDefaultLabel> labels = PageUtil.GetControls <EformDefaultLabel>(Page);
                // create JSON Serialier and list of output objects
                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                // list of client JSON objects
                List <string> _clientConfigs = new List <string>();
                // temp: fix to empty RecordId's
                Func <string, string, bool> matchRecordIds = (r1, r2) =>
                {
                    return((!string.IsNullOrEmpty(r1) ? r1 : "1") == (!string.IsNullOrEmpty(r2) ? r2 : "1"));
                };
                foreach (var eField in eFields)
                {
                    // FIND INPUTS
                    // i.e., Table=Encounters, RecordId=1
                    var inputsByTableRecordId = inputs.Where(input => input.Table == eField.TargetTable && matchRecordIds(input.RecordId, eField.TargetRecordId));
                    // i.e., Table=Encounters, Field=EncDate, RecordId=1
                    var targetInput = inputsByTableRecordId.Where(input => input.Field == eField.TargetField);
                    // i.e., Table=Encounters, Field!=EncDate, RecordId=1
                    var targetInputSiblings = inputsByTableRecordId.Except(targetInput);
                    // get type of default
                    EFormController.EformDefaultType type = eField.GetDefaultType();
                    if (targetInput.Count() > 0)
                    {
                        // get eform input field
                        IEformInputField targetInputField = targetInput.First();
                        // i.e., find sources by table and record (will be reduced by field, if needed)
                        var sourceInputs = from input in inputs
                                           // validate table
                                           where !string.IsNullOrEmpty(eField.TargetTable)
                                           where input.Table == eField.SourceTable && matchRecordIds(input.RecordId, eField.SourceRecordId)
                                           select input;

                        // get child input fields of target
                        if (eField.TriggeredByChildren)
                        {
                            // i.e. target=Survey.SurveyType,1, children=SurveyItems where ParentRecordId = 1
                            var targetChildInputs = from childTable in BOL.BusinessObject.GetChildTableNames(eField.TargetTable)
                                                    from input in inputs
                                                    where input.Table == childTable && matchRecordIds(input.ParentRecordId, targetInputField.RecordId)
                                                    select input;
                            if (targetChildInputs.Count() > 0)
                            {
                                // TODO: do we just combine sibling and children and rely on side effect ???
                                targetInputSiblings = targetInputSiblings.Concat(targetChildInputs).Distinct();
                            }
                        }

                        // FILTER and VALIDATE
                        bool hasClientFields = true;
                        switch (type)
                        {
                        case EFormController.EformDefaultType.Default:
                            // no source
                            sourceInputs = sourceInputs.Take(0);
                            break;

                        case EFormController.EformDefaultType.SourceDefaultValue:
                            // validate: 1+ source
                            if (sourceInputs.Count() == 0)
                            {
                                hasClientFields = false;
                            }
                            break;

                        case EFormController.EformDefaultType.SourceValue:
                            // validate: only 1 source (match exact Field)
                            sourceInputs = sourceInputs.Where(i => i.Field == eField.SourceField).Take(1);
                            if (sourceInputs.Count() == 0)
                            {
                                hasClientFields = false;
                            }
                            break;

                        // never gets called
                        default:
                            hasClientFields = false;
                            break;
                        }

                        // BUILD: client scripts

                        if (hasClientFields)
                        {
                            // get fields as Control to get client id
                            Control targetInputControl = targetInputField as Control;
                            IEnumerable <Control> targetInputSiblingControls = targetInputSiblings.OfType <Control>();
                            IEnumerable <Control> sourceInputControls        = sourceInputs.OfType <Control>();

                            // BUILD: client JSON
                            var JSONConfig = new
                            {
                                DefaultType     = type.ToString(),
                                DefaultValue    = eField.DefaultValue,
                                Target          = new { Type = targetInputControl.GetType().Name, Id = targetInputControl.ClientID },
                                TargetSiblings  = targetInputSiblingControls.Select(s => new { Type = s.GetType().Name, Id = s.ClientID }),
                                Sources         = sourceInputControls.Select(t => new { Type = t.GetType().Name, Id = t.ClientID }),
                                RequireSiblings = eField.RequireSiblings,
                                TriggerSiblings = eField.TriggeredBySiblings
                            };
                            // serialize object
                            string JSONConfigString = serializer.Serialize(JSONConfig);
                            _clientConfigs.Add(JSONConfigString);
                        }
                    }

                    // BUILD: default labels
                    if (type == EFormController.EformDefaultType.Default)
                    {
                        foreach (var label in labels)
                        {
                            // parse via id
                            if (!string.IsNullOrEmpty(label.DefaultField))
                            {
                                string labelTable    = "";
                                string labelField    = "";
                                string labelRecordId = "";
                                EFormController.EformDefaultValueField.ParseDefaultField(label.DefaultField, ref labelTable, ref labelField, ref labelRecordId);
                                if (eField.TargetTable == labelTable && eField.TargetField == labelField && eField.TargetRecordId == labelRecordId)
                                {
                                    label.Text = eField.DefaultValue;
                                }
                            }
                        }
                    }
                }
                // CLIENT SCRIPT: build and register client script
                if (_clientConfigs.Count() > 0)
                {
                    // serialize list of objects into JSON array for client scripts
                    string configJSONArray = "[" + string.Join(",", _clientConfigs.ToArray()) + "]";

                    // register start up script: validate functions exists
                    string _script = "if(window.initEformDefaultValues) { window.initEformDefaultValues(" + configJSONArray + "); }";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "initEformDefaultValues_" + this.ClientID, _script, true);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Writes value from control to matching Xml node.
        /// </summary>
        /// <param name="con"></param>
        /// <param name="xDoc"></param>
        protected void WriteControlValueToXmlNode(Control con, XmlDocument xDoc)
        {
            // TODO: give this method the parent id treatment
            if (con is EformHidden)
            {
                IEformInputField tb = (IEformInputField)con;
                this.SetXmlNodeValue(tb, xDoc);
            }
            else if (con is EformTextBox)
            {
                EformTextBox tb = (EformTextBox)con;
                this.SetXmlNodeValue(tb, xDoc);
            }

            else if (con is EformComboBox)
            {
                IEformInputField tb = (IEformInputField)con;
                this.SetXmlNodeValue(tb, xDoc);
            }

            else if (con is EformTextArea)
            {
                IEformInputField tb = (IEformInputField)con;
                this.SetXmlNodeValue(tb, xDoc);
            }

            else if (con is EformDropDownList)
            {
                IEformInputField tb = (IEformInputField)con;
                this.SetXmlNodeValue(tb, xDoc);
            }
            else if (con is EformSelect)
            {
                EformSelect es = (EformSelect)con;
                this.SetXmlNodeValue(es, xDoc);
            }
            else if (con is EformCheckBox)
            {
                EformCheckBox cb = (EformCheckBox)con;

                string recordId = cb.RecordId;
                // XmlNode node = null;

                /*
                 #region get node
                 * // use recordId to locate the node if it is set
                 * if (recordId != null && !recordId.Equals(""))
                 * {
                 *      string xPath = "//"+cb.Table+"[attribute::RecordId='"+recordId+"']";
                 *      XmlNode parentNode = xDoc.SelectSingleNode(xPath);
                 *      if (parentNode != null)
                 *      {
                 *              node = parentNode.SelectSingleNode("child::"+cb.Field);
                 *      }
                 * }
                 * else // in all other cases, find the first node that matches the table and field name.
                 * {
                 *      string xpath = "//" + cb.Table + "/" + cb.Field;
                 *
                 *      node = xDoc.SelectSingleNode(xpath);
                 * }
                 #endregion
                 */

                XmlNode node = GetXmlNode(cb.Table, cb.Field, cb.RecordId, cb.ParentRecordId, xDoc);

                if (node != null)
                {
                    string val = Request.Form[con.UniqueID];

                    if (val != null && val.Equals("on"))
                    {
                        // brandon: cb.Text is the text label (sigh. ask Microsoft)
                        // node.InnerText = cb.Text;
                        node.InnerText = cb.Value;
                    }
                    else
                    {
                        node.InnerText = "";
                    }
                }
            }
            else if (con is EformRadioButton)
            {
                EformRadioButton rb = (EformRadioButton)con;

                string recordId = rb.RecordId;

                /*
                 * XmlNode node = null;
                 *
                 #region get node
                 * // use recordId to locate the node if it is set
                 * if (recordId != null && !recordId.Equals(""))
                 * {
                 *      string xPath = "//"+rb.Table+"[attribute::RecordId='"+recordId+"']";
                 *      XmlNode parentNode = xDoc.SelectSingleNode(xPath);
                 *      if (parentNode != null)
                 *      {
                 *              node = parentNode.SelectSingleNode("child::"+rb.Field);
                 *      }
                 * }
                 * else // in all other cases, find the first node that matches the table and field name.
                 * {
                 *      string xpath = "//" + rb.Table + "/" + rb.Field;
                 *
                 *      node = xDoc.SelectSingleNode(xpath);
                 * }
                 #endregion
                 *
                 */

                XmlNode node = GetXmlNode(rb.Table, rb.Field, rb.RecordId, rb.ParentRecordId, xDoc);

                if (node != null)
                {
                    string val = Request.Form[con.UniqueID];

                    if (val != null && val.Equals("on"))
                    {
                        // brandon: cb.Text is the text label (sigh. ask Microsoft)
                        // node.InnerText = cb.Text;
                        node.InnerText = rb.Value;
                    }
                    else
                    {
                        node.InnerText = "";
                    }
                }
            }
            else if (con is EformRadioButtonList)
            {
                // EformRadioButtonList rb = (EformRadioButtonList) con;
                EformRadioButtonList rb = (EformRadioButtonList)con;

                XmlNode node = FetchNode(xDoc, rb.Table, rb.Field, rb.RecordId, rb.ParentRecordId);

                if (node != null)
                {
                    node.InnerText = rb.Value;// Request.Form[con.UniqueID];

                    if (node.InnerText != null && !"".Equals(node.InnerText))
                    {
                        // handle additional fields
                        if (rb.Field1 != null && !"".Equals(rb.Field1))
                        {
                            XmlNode node1 = FetchNode(xDoc, rb.Table, rb.Field1, rb.RecordId, rb.ParentRecordId);
                            node1.InnerText = rb.Value1;
                        }

                        if (rb.Field2 != null && !"".Equals(rb.Field2))
                        {
                            XmlNode node2 = FetchNode(xDoc, rb.Table, rb.Field2, rb.RecordId, rb.ParentRecordId);
                            node2.InnerText = rb.Value2;
                        }

                        if (rb.Field3 != null && !"".Equals(rb.Field3))
                        {
                            XmlNode node3 = FetchNode(xDoc, rb.Table, rb.Field3, rb.RecordId, rb.ParentRecordId);
                            node3.InnerText = rb.Value3;
                        }
                    }
                }
            }
            else if (con is EformRadioButtonGroup)
            {
                // save each additional field
                // may also need to deal w/ xml for child controls
                EformRadioButtonGroup rg = (EformRadioButtonGroup)con;
                string val = rg.GetSelectedValue(this.Request);
                if (val != null && !"".Equals(val))
                {
                    // DO WE NEED TO WORRY ABOUT PARENT ID HERE?
                    if (rg.Field1 != null && !"".Equals(rg.Field1))
                    {
                        XmlNode node = FetchNode(xDoc, rg.Table, rg.Field1, rg.RecordId, rg.ParentRecordId);
                        node.InnerText = rg.Value1;
                    }

                    if (rg.Field2 != null && !"".Equals(rg.Field2))
                    {
                        XmlNode node = FetchNode(xDoc, rg.Table, rg.Field2, rg.RecordId, rg.ParentRecordId);
                        node.InnerText = rg.Value2;
                    }

                    if (rg.Field3 != null && !"".Equals(rg.Field3))
                    {
                        XmlNode node = FetchNode(xDoc, rg.Table, rg.Field3, rg.RecordId, rg.ParentRecordId);
                        node.InnerText = rg.Value3;
                    }

                    // we already know our value
                    EformRadioButton rb = rg.GetCheckedButton(this.Request);
                    if (rb != null)
                    {
                        XmlNode node = GetXmlNode(rg.Table, rg.Field, rg.RecordId, rg.ParentRecordId, xDoc);

                        if (node != null)
                        {
                            node.InnerText = rb.Value;
                        }
                    }
                }
                else                 // we will have to unset values if the user "cleared" the group of radio buttons
                {
                    if (rg.Field1 != null && !"".Equals(rg.Field1))
                    {
                        XmlNode node1 = FetchNode(xDoc, rg.Table, rg.Field1, rg.RecordId, rg.ParentRecordId);
                        node1.InnerText = null;
                    }

                    if (rg.Field2 != null && !"".Equals(rg.Field2))
                    {
                        XmlNode node2 = FetchNode(xDoc, rg.Table, rg.Field2, rg.RecordId, rg.ParentRecordId);
                        node2.InnerText = null;
                    }

                    if (rg.Field3 != null && !"".Equals(rg.Field3))
                    {
                        XmlNode node3 = FetchNode(xDoc, rg.Table, rg.Field3, rg.RecordId, rg.ParentRecordId);
                        node3.InnerText = null;
                    }

                    XmlNode node = GetXmlNode(rg.Table, rg.Field, rg.RecordId, rg.ParentRecordId, xDoc);

                    if (node != null)
                    {
                        node.InnerText = null;
                    }
                }
            }
            else if (con is EformCheckBoxList || con is EformRadioButtonList)
            {
                IEformInputField eFormControl = con as IEformInputField;
                this.SetXmlNodeValue(eFormControl, xDoc);
            }
        }
Beispiel #6
0
 /// <summary>
 /// Gets the value of the node.
 /// </summary>
 /// <param name="con"></param>
 /// <param name="xmlDoc"></param>
 /// <returns></returns>
 private string GetNodeValue(IEformInputField con, XmlDocument xmlDocument)
 {
     return(GetNodeValue(con.Table, con.Field, con.RecordId, con.ParentRecordId, xmlDocument));
 }
Beispiel #7
0
        /// <summary>
        /// Populate eform input field with value from Xml Document node
        /// </summary>
        /// <param name="con"></param>
        /// <param name="xmlDoc"></param>
        protected void SetControlValue(IEformInputField con, XmlDocument xmlDoc)
        {
            string conValue = GetNodeValue(con, xmlDoc);

            SetControlValue(con, xmlDoc, conValue);
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="con"></param>
        /// <param name="xmlDoc"></param>
        /// <param name="inputFieldValue"></param>
        protected void SetControlValue(IEformInputField con, XmlDocument xmlDoc, string inputFieldValue)
        {
            if (inputFieldValue != null)
            {
                // TODO: collapse this into a call on the IEformInputField interface
                if (con is EformTextBox)
                {
                    EformTextBox temp = (EformTextBox)con;
                    //temp.Value = inputFieldValue;
                    temp.Text = inputFieldValue;
                }

                else if (con is EformHidden)
                {
                    EformHidden temp = (EformHidden)con;
                    // let's experiment
                    string val = inputFieldValue;
                    if (temp.Field.EndsWith("Date")) // we want Dates enabled to pick up the DateText conversion
                    {
                        temp.Disabled = false;
                        // we need to propagate the value here, b/c it would be empty on the page
                        temp.Value = val;
                    }
                    else if (val == null || "".Equals(val))
                    {
                        temp.Disabled = true;
                    }
                    else
                    {
                        temp.Disabled = false;
                        // persist the value in this case
                        temp.Value = val;
                    }

                    // leave the value alone, keeping what was on the page;
                    // temp.Value = inputFieldValue;
                }

                else if (con is EformTextArea)
                {
                    EformTextArea temp = (EformTextArea)con;
                    //temp.Value = inputFieldValue;
                    temp.Text = inputFieldValue;
                }

                else if (con is EformDropDownList)
                {
                    EformDropDownList temp = (EformDropDownList)con;
                    //temp.Value = inputFieldValue;
                    temp.SelectedValue = inputFieldValue;
                }

                else if (con is EformComboBox)
                {
                    EformComboBox temp = (EformComboBox)con;
                    temp.Value = inputFieldValue;
                }

                //else if (con is EformRadioButtonList)
                //{
                //    EformRadioButtonList temp = (EformRadioButtonList)con;
                //    string val = inputFieldValue;

                //    if (val != null && !val.Equals(""))
                //        temp.SelectedValue = val;
                //}
                else if (con is EformRadioButtonGroup)
                {
                    EformRadioButtonGroup rg = (EformRadioButtonGroup)con;

                    // tell it to the child controls
                    foreach (Control c in rg.Controls)
                    {
                        if (c is EformRadioButton)
                        {
                            EformRadioButton rb = (EformRadioButton)c;

                            string nodeInnerText = GetNodeValue(rg, xmlDoc);

                            if (nodeInnerText != null && !"".Equals(nodeInnerText))
                            {
                                if (rb.Value.Equals(nodeInnerText))
                                {
                                    rb.Checked = true;
                                }
                            }
                        }
                    }
                }
                else if (con is EformRadioButton)
                {
                    EformRadioButton rb = (EformRadioButton)con;

                    string nodeInnerText = inputFieldValue;

                    if (nodeInnerText != null && nodeInnerText != "")
                    {
                        rb.Checked = true;
                    }
                }
                else if (con is EformCheckBox)
                {
                    EformCheckBox cb = (EformCheckBox)con;

                    string nodeInnerText = inputFieldValue;

                    if (nodeInnerText != null && nodeInnerText != "")
                    {
                        cb.Checked = true;
                    }
                }
                else if (con is EformSelect)
                {
                    EformSelect temp = (EformSelect)con;
                    temp.Text = inputFieldValue;
                }
                else if (con is EformCheckBoxList || con is EformRadioButtonList)
                {
                    IEformInputField eFormControl = con as IEformInputField;
                    eFormControl.Value = inputFieldValue;
                }
            }
        }