Ejemplo n.º 1
0
        protected void txtTm_TextChanged(object sender, EventArgs e)
        {
            PropertyInfo property = dataSource.GetType().GetProperty(column.Text);
            TextBox      txt      = (TextBox)sender;

            try
            {
                object oValue;
                if (txt.Text.Trim() == string.Empty)
                {
                    oValue = NullFinder.GetNullValue(column.DataType);
                }
                else
                {
                    DateTime oldValue = (DateTime)property.GetValue(dataSource, null);
                    string   newValue = string.Format("{0} {1}", oldValue.ToShortDateString(), txt.Text);
                    oValue = DateTime.Parse(newValue);
                }
                property.SetValue(dataSource, oValue, null);
            }
            catch (Exception)
            {
                txtTm_DataBinding(txt, null);
            }
        }
Ejemplo n.º 2
0
        //when the value of the field is changed (by the user), and is valid
        //the handler updates the associated property of the datasource.
        protected void txt_TextChanged(object sender, EventArgs e)
        {
            PropertyInfo property = dataSource.GetType().GetProperty(column.Text);
            TextBox      txt      = (TextBox)sender;

            try
            {
                object oValue;
                if (txt.Text.Trim() == string.Empty)
                {
                    oValue = NullFinder.GetNullValue(column.DataType);
                }
                else
                {
                    oValue = NullFinder.Parse(txt.Text, property.PropertyType);
                }
                property.SetValue(dataSource, oValue, null);
            }
            catch (Exception)
            {
                txt_DataBinding(txt, null);
            }
        }
Ejemplo n.º 3
0
        public virtual WebControl RenderInEditor()
        {
            if (column.IsCDDExtender || column.IsTextChangeExtender)
            {
                return(null);
            }
            if (!column.IsEditable || column.IsStatic)
            {
                Label lbl = new Label();
                lbl.Width = new Unit(100, UnitType.Percentage);
                if (column.IsStatic)
                {
                    lbl.Text = column.Text;
                }
                else
                {
                    lbl.DataBinding += new EventHandler(lbl_DataBinding);
                }
                return(lbl);
            }
            if (column.IsLookup)
            {
                DropDownList ddl = new DropDownList();
                ddl.Width                 = new Unit(100, UnitType.Percentage);
                ddl.DataBinding          += new EventHandler(ddl_DataBinding);
                ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
                IDictionary <object, string> dictionary = lookup.GetLookup(column.Lookup);
                foreach (object key in dictionary.Keys)
                {
                    ListItem item = new ListItem(dictionary[key], key.ToString());
                    ddl.Items.Add(item);
                }
                var validationRule = from rule in column.Rules
                                     where (rule.ValidationType == "Required") && ((RequiredValidationRule)rule).IsRequired
                                     select rule;
                if (validationRule.Count() == 0)
                {
                    ddl.Items.Add(new ListItem(string.Empty, NullFinder.GetNullValue(column.DataType).ToString()));
                }
                ddl.ID = string.Format("ddl{0}", column.Name);
                return(ddl);
            }
            if (column.IsCascadedLookup)// || column.IsCDDExtended)
            {
                DropDownList ddl = new DropDownList();
                ddl.ID    = string.Format("ddl{0}", column.Name);
                ddl.Width = new Unit(100, UnitType.Percentage);
                ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
                return(ddl);
            }
            else
            {
                Panel   ph  = new Panel();
                TextBox txt = new TextBox();
                txt.Width        = new Unit(100, UnitType.Percentage);
                txt.DataBinding += new EventHandler(txt_DataBinding);
                txt.TextChanged += new EventHandler(txt_TextChanged);
                txt.ID           = string.Format("txt{0}", column.Name);
                if (column.IsLongText)
                {
                    txt.TextMode = TextBoxMode.MultiLine;
                }

                ph.Controls.Add(txt);
                //for each rule specified in the column descriptor
                //the renderer attaches the appropriate validator control
                foreach (ValidationRule rule in column.Rules)
                {
                    BaseValidator validationControl = null;
                    switch (rule.ValidationType)
                    {
                    case "Required":
                        if (((RequiredValidationRule)rule).IsRequired)
                        {
                            validationControl = new RequiredFieldValidator();
                        }
                        break;

                    case "Pattern":
                        RegularExpressionValidator validator = new RegularExpressionValidator();
                        validator.ValidationExpression = ((PatternValidationRule)rule).Pattern;
                        validationControl = validator;
                        break;

                    case "Range":
                        RangeValidator      rangeValidator = new RangeValidator();
                        RangeValidationRule rangeRule      = (RangeValidationRule)rule;
                        rangeValidator.MinimumValue = rangeRule.LeftBoundary;
                        rangeValidator.MaximumValue = rangeRule.RightBoundary;
                        validationControl           = rangeValidator;
                        break;

                    case "Compare":
                        CompareValidator      compareValidator = new CompareValidator();
                        CompareValidationRule compareRule      = (CompareValidationRule)rule;
                        compareValidator.Operator       = compareRule.CompareOperator;
                        compareValidator.Type           = compareRule.RuleDataType;
                        compareValidator.ValueToCompare = compareRule.ValueToCompare;
                        validationControl = compareValidator;
                        break;
                    }
                    if (validationControl != null)
                    {
                        validationControl.ValidationGroup   = "GINDataEditor";
                        validationControl.ControlToValidate = txt.ID;
                        validationControl.ErrorMessage      = rule.ErrorMessage;
                        validationControl.Text = "*";
                        ph.Controls.Add(validationControl);
                    }
                }
                return(ph);
            }
        }