public String SerializeObject(DynamicFieldsAggregator _Object)
        {
            try
            {
                String XmlizedString = null;

                MemoryStream memoryStream = new MemoryStream();

                XmlSerializer xs = new XmlSerializer(typeof(DynamicFieldsAggregator));

                XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);

                xs.Serialize(xmlTextWriter, _Object);

                memoryStream = (MemoryStream)xmlTextWriter.BaseStream;

                XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());

                return XmlizedString;
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// Method that will create the ASP.net Controls based on the DynamicFieldsAggregator Class
        /// </summary>
        private static List<Control> CreateDynamicsFields(DynamicFieldsAggregator aggregator, Dictionary<string, object> parameters)
        {
            List<Control> controlList = new List<Control>();

            foreach (DynamicControls control in aggregator.Controls)
            {
                string controlValue = string.Empty;

                if (parameters.ContainsKey("DateTime"))
                {
                    if (control.Name.Equals(Globals.CallEntry.ActionDateFieldName))
                        controlValue = ((DateTime)parameters["DateTime"]).ToString("MM/dd/yyyy");
                    else if (control.Name.Equals(Globals.CallEntry.ActionTimeFieldName))
                        controlValue = ((DateTime)parameters["DateTime"]).ToString("HH:mm");
                }

                if (control is DynamicTextBoxXml)
                {
                    DynamicTextBox customControl = new DynamicTextBox(control as DynamicTextBoxXml);
                    controlList.Add(customControl);
                    if (customControl.Text.Equals(string.Empty) && !controlValue.Equals(string.Empty))
                        customControl.Text = controlValue;
                }
                else if (control is DynamicDropDownListXml)
                {
                    DynamicDropDownList customControl = new DynamicDropDownList(control as DynamicDropDownListXml);
                    controlList.Add(customControl);
                }
                else if (control is DynamicGridViewXml)
                {
                    DynamicGridView customControl = new DynamicGridView(control as DynamicGridViewXml);
                    controlList.Add(customControl);
                }
                else if (control is DynamicCountableTextBoxXml)
                {
                    DynamicCountableTextBox customControl = new DynamicCountableTextBox(control as DynamicCountableTextBoxXml);
                    controlList.Add(customControl);
                    if (customControl.Text.Equals(string.Empty) && !controlValue.Equals(string.Empty))
                        customControl.Text = controlValue;
                }
                else if (control is DynamicDatePickerXml)
                {
                    DynamicDatePicker customControl = new DynamicDatePicker(control as DynamicDatePickerXml);
                    controlList.Add(customControl);
                    if (!customControl.Value.HasValue && !controlValue.Equals(string.Empty))
                        customControl.Value = Convert.ToDateTime(controlValue, new System.Globalization.CultureInfo("en-US"));
                }
                else if (control is DynamicTimeXml)
                {
                    DynamicTime customControl = new DynamicTime(control as DynamicTimeXml);
                    controlList.Add(customControl);
                    if (customControl.Text.Equals(string.Empty) && !controlValue.Equals(string.Empty))
                        customControl.Text = controlValue;
                }
                else if (control is DynamicFilteredTextBoxXml)
                {
                    DynamicFilteredTextBox customControl = new DynamicFilteredTextBox(control as DynamicFilteredTextBoxXml);
                    controlList.Add(customControl);
                    if (customControl.Text.Equals(string.Empty) && !controlValue.Equals(string.Empty))
                        customControl.Text = controlValue;
                }
                else if (control is DynamicCheckBoxXml)
                {
                    DynamicCheckBox customControl = new DynamicCheckBox(control as DynamicCheckBoxXml);
                    controlList.Add(customControl);
                }
                else if (control is DynamicRadioButtonListXml)
                {
                    DynamicRadioButtonList customControl = new DynamicRadioButtonList(control as DynamicRadioButtonListXml);
                    controlList.Add(customControl);
                }
            }

            foreach (Extenders extender in aggregator.Extenders)
            {
                if (extender is VisibleExtenderXml)
                {
                    VisibleExtenderXml extenderXml = extender as VisibleExtenderXml;

                    WebControl caller = FindControlByName(controlList, extenderXml.CallerControlName) as WebControl;
                    WebControl target = FindControlByName(controlList, extenderXml.TargetControlName) as WebControl;

                    if (caller != null && target != null)
                    {
                        VisibleExtender vExtender = new VisibleExtender(extenderXml, caller, target);

                        if (caller is DynamicTextBox)
                        {
                            ((DynamicTextBox)caller).addExtender(vExtender);
                        }
                        else if (caller is DynamicCountableTextBox)
                        {
                            ((DynamicCountableTextBox)caller).addExtender(vExtender);
                        }
                        else if (caller is DynamicDropDownList)
                        {
                            ((DynamicDropDownList)caller).addExtender(vExtender);
                        }
                        else if (caller is DynamicRadioButtonList)
                        {
                            ((DynamicRadioButtonList)caller).addExtender(vExtender);
                        }
                        else if (caller is DynamicCheckBox)
                        {
                            ((DynamicCheckBox)caller).addExtender(vExtender);
                        }
                    }
                }
                else if (extender is AutoFillExtenderXml)
                {
                    AutoFillExtenderXml extenderXml = extender as AutoFillExtenderXml;

                    WebControl target = FindControlByName(controlList, extenderXml.TargetControlName) as WebControl;

                    if (target != null)
                    {
                        AutoFillExtender aExtender = new AutoFillExtender(extenderXml, target);
                        switch (extenderXml.Type)
                        {
                            case Hulcher.OneSource.CustomerService.Core.Globals.CallEntry.AutoFillType.JobCity:
                            case Hulcher.OneSource.CustomerService.Core.Globals.CallEntry.AutoFillType.JobState:
                            case Hulcher.OneSource.CustomerService.Core.Globals.CallEntry.AutoFillType.JobCountry:
                                if (parameters.ContainsKey("JobID"))
                                    aExtender._filterId = parameters["JobID"].ToString();
                                break;
                            case Hulcher.OneSource.CustomerService.Core.Globals.CallEntry.AutoFillType.PreviousCallType:
                                if (parameters.ContainsKey("JobID"))
                                    aExtender._filterId = parameters["JobID"].ToString();
                                break;
                            default:
                                break;
                        }

                        if (!string.IsNullOrEmpty(extenderXml.ConditionalControlName))
                            aExtender._conditionalControlName = extenderXml.ConditionalControlName;

                        if (target is DynamicTextBox)
                        {
                            ((DynamicTextBox)target).addExtender(aExtender);
                        }
                        else if (target is DynamicCountableTextBox)
                        {
                            ((DynamicCountableTextBox)target).addExtender(aExtender);
                        }
                        else if (target is DynamicDropDownList)
                        {
                            ((DynamicDropDownList)target).addExtender(aExtender);
                        }
                    }
                }
                else if (extender is ValidationExtenderXml)
                {
                    ValidationExtenderXml extenderXml = extender as ValidationExtenderXml;

                    WebControl caller = FindControlByName(controlList, extenderXml.CallerControlName) as WebControl;
                    WebControl target = FindControlByName(controlList, extenderXml.TargetControlName) as WebControl;

                    if (caller != null && target != null)
                    {
                        ValidationExtender vExtender = new ValidationExtender(extenderXml, target, caller);

                        if (caller is DynamicTextBox)
                        {
                            ((DynamicTextBox)caller).addExtender(vExtender);
                        }
                        else if (caller is DynamicCountableTextBox)
                        {
                            ((DynamicCountableTextBox)caller).addExtender(vExtender);
                        }
                    }
                }
                else if (extender is ListExtenderXml)
                {
                    ListExtenderXml extenderXml = extender as ListExtenderXml;

                    WebControl target = FindControlByName(controlList, extenderXml.TargetControlName) as WebControl;

                    if (target != null)
                    {
                        ListExtender lExtender = new ListExtender(extenderXml, target);

                        if (target is DynamicDropDownList)
                        {
                            ((DynamicDropDownList)target).addExtender(lExtender);
                        }
                        else if (target is DynamicRadioButtonList)
                        {
                            ((DynamicRadioButtonList)target).addExtender(lExtender);
                        }
                    }
                }
                else if (extender is CascadeListExtenderXml)
                {
                    CascadeListExtenderXml extenderXml = extender as CascadeListExtenderXml;

                    WebControl caller = FindControlByName(controlList, extenderXml.SourceControlName) as WebControl;
                    WebControl target = FindControlByName(controlList, extenderXml.TargetControlName) as WebControl;

                    if (caller != null && target != null)
                    {
                        CascadeListExtender cExtender = new CascadeListExtender(extenderXml, target, caller);

                        if (caller is DynamicDropDownList)
                        {
                            ((DynamicDropDownList)caller).addExtender(cExtender);
                        }
                    }
                }
                else if (extender is GridViewExtenderXml)
                {
                    GridViewExtenderXml extenderXml = extender as GridViewExtenderXml;

                    WebControl source = FindControlByName(controlList, extenderXml.SourceControlName) as WebControl;
                    WebControl target = FindControlByName(controlList, extenderXml.TargetControlName) as WebControl;

                    if (source != null && target != null)
                    {
                        GridViewExtender cExtender = new GridViewExtender(source, target, extenderXml.Label);

                        if (source is DynamicGridView)
                        {
                            ((DynamicGridView)source).AddExtender(cExtender);
                        }
                    }
                }
            }

            return controlList;
        }
        /// <summary>
        /// Receives an DynamicFieldsAggregator and serialize it creating a Xml String
        /// </summary>
        public static string CreateXmlFromField(DynamicFieldsAggregator aggregator)
        {
            DynamicFieldsSerialize serializer = new DynamicFieldsSerialize();

            return serializer.SerializeObject(aggregator);
        }
Exemplo n.º 4
0
 private string GetXmlFromAggregator(DynamicFieldsAggregator aggregator)
 {
     DynamicFieldsSerialize serializer = new DynamicFieldsSerialize();
     return serializer.SerializeObject(aggregator);
 }
Exemplo n.º 5
0
        private DynamicFieldsAggregator CreateAggregatorForSpecificCustomerInfo(IList<int> selectedCustomerInfoType)
        {
            List<CS_CustomerSpecificInfoType> customerSpecificType = _customerSpecificInfoTypeRepository.ListAll(e => e.Active && selectedCustomerInfoType.Contains(e.ID)).ToList();

            DynamicFieldsAggregator aggregator = new DynamicFieldsAggregator();

            for (int i = 0; i < customerSpecificType.Count; i++)
            {
                DynamicLabel label = new DynamicLabel();
                label.Text = customerSpecificType[i].Description + ":";
                label.Css = "dynamicLabel";

                string controlName = StringManipulation.RemoveSpecialCharactersForControlName("txt" + customerSpecificType[i].Description.Replace(" ", ""));

                DynamicTextBoxXml textbox = new DynamicTextBoxXml("", controlName, false, "", "", 255, label, "input", "", true);
                textbox.CustomerSpecificInfoTypeID = customerSpecificType[i].ID;
                aggregator.Controls.Add(textbox);
            }

            return aggregator;
        }