public string GetValue(Control ctrl, XmlNode renderingDocument) { DateBoxControl dbox = (DateBoxControl)ctrl.Controls[1]; XmlDocument doc = new XmlDocument(); string root = String.IsNullOrEmpty(this.Name) ? "null" : this.Name; XmlNode nodeValue = doc.CreateElement(root); XmlElement elem = doc.CreateElement("Value"); doc.AppendChild(nodeValue); nodeValue.AppendChild(elem); nodeValue.FirstChild.InnerText = dbox.Data; if (String.IsNullOrEmpty(dbox.Data) && Common.getElementFromSchema(baseSchema).IsNillable) { elem.SetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance", "true"); } return(doc.OuterXml); }
/* For methods documentation's see the IField interface */ public Control GetWebControl(System.Web.HttpServerUtility server, XmlNode renderingDocument) { string tip = (renderingDocument.Attributes["description"] == null) ? "" : renderingDocument.Attributes["description"].Value.FromXmlValue2Render(server); 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"; lbl.ToolTip = tip; ph.Controls.Add(lbl); DateBoxControl dbox = new DateBoxControl(this); dbox.ToolTip = tip; if (renderingDocument.Attributes["class"] != null) { dbox.tbox.CssClass = renderingDocument.Attributes["class"].Value.FromXmlValue2Render(server); } if (renderingDocument.Attributes["rel"] != null) { dbox.tbox.Attributes.Add("rel", renderingDocument.Attributes["rel"].Value.FromXmlValue2Render(server)); } ph.Controls.Add(dbox); // --- ADD VALIDATORS --- RegularExpressionValidator rev = new RegularExpressionValidator(); rev.Display = ValidatorDisplay.Dynamic; rev.ControlToValidate = dbox.ID + "$" + dbox.tbox.ID; rev.ErrorMessage = "A value isn't a valid date (format: gg/mm/yyyy)"; const string REgg = "([1-9]|0[1-9]|[12][0-9]|3[01])"; const string REmm = "([1-9]|0[1-9]|1[012])"; const string REyy = "[0-9]{4}"; const string sep = "[/.-]"; rev.ValidationExpression = "^" + REgg + sep + REmm + sep + REyy + "$"; rev.ValidationGroup = "1"; ph.Controls.Add(rev); if (!Common.getElementFromSchema(baseSchema).IsNillable) { RequiredFieldValidator rqfv = new RequiredFieldValidator(); rqfv.ErrorMessage = "Required fields shouldn't be empty"; rqfv.ControlToValidate = dbox.ID + "$" + dbox.tbox.ID; rqfv.ValidationGroup = "1"; rqfv.Display = ValidatorDisplay.Dynamic; ph.Controls.Add(rqfv); } if (((XmlSchemaSimpleType)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) { RangeValidator rv = new RangeValidator(); rv.Type = ValidationDataType.Date; rv.MinimumValue = DateTime.Parse(facet.Value).ToString().Substring(0, 10); rv.ErrorMessage = "Date must be equal or later than " + DateTime.Parse(facet.Value).ToString(CultureInfo.CurrentCulture.DateTimeFormat).Substring(0, 10); rv.MaximumValue = DateTime.MaxValue.ToString().Substring(0, 10); rv.ControlToValidate = dbox.ID + "$" + dbox.tbox.ID; rv.Display = ValidatorDisplay.Dynamic; rv.ValidationGroup = "1"; ph.Controls.Add(rv); } if (facet is XmlSchemaMaxInclusiveFacet) { RangeValidator rv = new RangeValidator(); rv.Type = ValidationDataType.Date; rv.MaximumValue = DateTime.Parse(facet.Value).ToString().Substring(0, 10); rv.ErrorMessage = "Date must be equal or previous to " + DateTime.Parse(facet.Value).ToString(CultureInfo.CurrentCulture.DateTimeFormat).Substring(0, 10); rv.MinimumValue = DateTime.MinValue.ToString().Substring(0, 10); rv.ControlToValidate = dbox.ID + "$" + dbox.tbox.ID; rv.Display = ValidatorDisplay.Dynamic; rv.ValidationGroup = "1"; ph.Controls.Add(rv); } } return(ph); }