Ejemplo n.º 1
0
        public string GetValue(Control ctrl1, XmlNode renderingDocument)
        {
            IntBoxControl ibox = (IntBoxControl)ctrl1.Controls[1];
            string        root = String.IsNullOrEmpty(this.Name) ? "null" : this.Name;

            XmlDocument doc       = new XmlDocument();
            XmlNode     nodeValue = doc.CreateElement(root);

            doc.AppendChild(nodeValue);
            XmlElement elem = doc.CreateElement("Value");

            nodeValue.AppendChild(elem);

            try
            {
                nodeValue.FirstChild.InnerText = double.IsNaN(Double.Parse(ibox.Text)) ? "" : ibox.Text.FromNotEncodedRender2XmlValue();
            }
            catch (Exception) { nodeValue.FirstChild.InnerText = ""; }
            if (nodeValue.FirstChild.InnerText == "" && Common.getElementFromSchema(baseSchema).IsNillable)
            {
                elem.SetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
            }
            return(doc.OuterXml);
        }
Ejemplo n.º 2
0
        public System.Web.UI.Control GetWebControl(System.Web.HttpServerUtility server, System.Xml.XmlNode renderingDocument)
        {
            PlaceHolder ph = new PlaceHolder();

            Label lbl = new Label();

            if (renderingDocument.Attributes["renderedLabel"] != null)
            {
                lbl.Text = renderingDocument.Attributes["renderedLabel"].Value.FromXmlValue2Render(server);
            }
            else
            {
                lbl.Text = this.Name.FromXmlName2Render(server);
            }
            lbl.CssClass = "label";
            ph.Controls.Add(lbl);

            IntBoxControl ibox = new IntBoxControl(this);

            //ibox.CausesValidation = false;

            if (renderingDocument.Attributes["class"] != null)
            {
                ibox.CssClass = renderingDocument.Attributes["class"].Value.FromXmlValue2Render(server);
            }
            if (renderingDocument.Attributes["rel"] != null)
            {
                ibox.Attributes.Add("rel", renderingDocument.Attributes["rel"].Value.FromXmlValue2Render(server));
            }
            if (renderingDocument.Attributes["description"] != null)
            {
                ibox.ToolTip = renderingDocument.Attributes["description"].Value.FromXmlValue2Render(server);
            }

            ph.Controls.Add(ibox);


            if (!Common.getElementFromSchema(baseSchema).IsNillable)
            {
                RequiredFieldValidator rqfv = new RequiredFieldValidator();
                rqfv.ErrorMessage      = "Required fields shouldn't be empty";
                rqfv.ControlToValidate = ibox.ID;
                rqfv.ValidationGroup   = "1";
                rqfv.Display           = ValidatorDisplay.Dynamic;
                ph.Controls.Add(rqfv);
            }

            // Adding the regular expression validator to ensure the content to be an integer
            RegularExpressionValidator intValidator = new RegularExpressionValidator();

            intValidator.ValidationExpression = @"-?[0-9]+";
            intValidator.ControlToValidate    = ibox.ID;
            intValidator.ErrorMessage         = "Integer required!";
            intValidator.ValidationGroup      = "1";
            intValidator.Display = ValidatorDisplay.Dynamic;
            ph.Controls.Add(intValidator);

            if (Common.getElementFromSchema(baseSchema).SchemaType == null)
            {
                return(ph);
            }
            XmlSchemaObjectCollection constrColl =
                ((XmlSchemaSimpleTypeRestriction)((XmlSchemaSimpleType)Common.getElementFromSchema(baseSchema).SchemaType).Content).Facets;

            foreach (XmlSchemaFacet facet in constrColl)
            {
                if (facet is XmlSchemaMinInclusiveFacet)
                {
                    ph.Controls.Add(getGreaterThanValidator(Int32.Parse(facet.Value), ibox.ID));
                }
                else if (facet is XmlSchemaMaxInclusiveFacet)
                {
                    ph.Controls.Add(getLowerThanValidator(Int32.Parse(facet.Value), ibox.ID));
                }
            }

            return(ph);
        }