Ejemplo n.º 1
0
        public int BindFrom_ComboBox_Int(ComboBox cb, ErrorControl errctrl, IRule rule)
        {
            cb.BackColor = Color.Empty;
            errctrl.clearError();

            int result = 0;
            object selected = cb.SelectedItem;

            if (selected != null)
            {
                if (selected is Kunde)
                {
                    result = ((Kunde)selected).Kundenid;
                }
                else if (selected is Projekt)
                {
                    result = ((Projekt)selected).Projektid;
                }
                else if (selected is Kontakt)
                {
                    result = ((Kontakt)selected).Kontaktid;
                }
                else if (selected is Rechnung)
                {
                    result = ((Rechnung)selected).Rechnungid;
                }
                else if (selected is Buchungskategorie)
                {
                    result = ((Buchungskategorie)selected).Bkatid;
                }
            }

            if (rule != null)
            {
                if (!rule.Eval(selected, errctrl))
                {
                    haserrors = true;
                    cb.BackColor = Color.Red;
                }
            }

            return result;
        }
Ejemplo n.º 2
0
        public bool Eval(object value, ErrorControl ctrl)
        {
            if (value is string)
            {
                if (string.IsNullOrWhiteSpace((string)value))
                {
                    ctrl.setError("Das Feld darf nicht leer sein!");
                    return false;
                }
            }
            else
            {
                if (value == null)
                {
                    ctrl.setError("Bitte wählen Sie ein Objekt aus!");
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 3
0
        public DateTime BindFrom_DateTime(Control ctrl, ErrorControl errctrl, IRule rule)
        {
            ctrl.BackColor = Color.Empty;
            errctrl.clearError();

            DateTime result = DateTime.Today;

            if (ctrl is DateTimePicker)
            {
                result = ((DateTimePicker)ctrl).Value;
            }

            if (rule != null)
            {
                if (!rule.Eval(result, errctrl))
                {
                    haserrors = true;
                    ctrl.BackColor = Color.Red;
                }
            }

            return result;
        }
Ejemplo n.º 4
0
        public double BindFrom_Double(Control ctrl, ErrorControl errctrl, IRule rule)
        {
            ctrl.BackColor = Color.Empty;
            errctrl.clearError();

            double result = 0;
            if (!double.TryParse(ctrl.Text, out result))
            {
                haserrors = true;
                ctrl.BackColor = Color.Red;
                errctrl.setError("Der Wert muss eine Zahl sein!");
            }

            if (rule != null)
            {
                if (!rule.Eval(result, errctrl))
                {
                    haserrors = true;
                    ctrl.BackColor = Color.Red;
                }
            }

            return result;
        }
Ejemplo n.º 5
0
        public string BindFrom_String(Control ctrl, ErrorControl errctrl, IRule rule)
        {
            ctrl.BackColor = Color.Empty;
            errctrl.clearError();

            string result = ctrl.Text;

            if (rule != null)
            {
                if (!rule.Eval(result, errctrl))
                {
                    haserrors = true;
                    ctrl.BackColor = Color.Red;
                }
            }

            return result;
        }