Ejemplo n.º 1
0
        private void MaskedEnable_FireAction(DynamicFormActionTrigger trigger, DynamicFormAction action, object sender, ModelPropertyChangedEventArgs e)
        {
            // find all controls and set enabled / disabled state using proper mask
            Type enumType = trigger.Param as Type;

            if (enumType == null)
            {
                // wrong settings
                _logger.Error(string.Format("MaskedEnable_FireAction: Wrong mask enum type!"));
                return;
            }

            int mask = 0;

            try
            {
                mask = ExtendedEnum.ToInt(enumType, e.Value); //e.Value != null && e.Value.ToString() != "" ? (int)System.Enum.Parse(enumType, e.Value.ToString(), true) : 0;
            }
            catch (Exception)
            {
                //_logger.Error(string.Format("MaskedEnable_FireAction: Wrong mask enum value [{0}]!", e.Value.ToString()));
            }


            // get control
            if (ReferenceEquals(null, action.Control))
            {
                action.Control = FindControlByPropertyName(action.FieldName);
            }

            if (!ReferenceEquals(null, action.Control))
            {
                // reset data using binding source of this action
                FilterObjectbase fo = action.BindingSource?.Current as FilterObjectbase;
                if (!ReferenceEquals(fo, null))
                {
                    action.Control.DataBindings[0].DataSourceUpdateMode = DataSourceUpdateMode.Never;
                    // reset field
                    fo.ResetFieldByName(action.FieldName);
                    // turn back DS update mode
                    action.Control.DataBindings[0].DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
                }
                // confront field bits with enable mask arrived from trigger
                // control remain enable only if all mask (trigger) bits are present allow bitset of field (action target)
                if ((((int)(object)action.Param & (int)(object)mask) > 0))
                {
                    action.Control.Enabled = true;
                }
                else
                {
                    action.Control.Enabled = false;
                }
                // set back default style
                if (action.Control is TextEdit)
                {
                    (action.Control as TextEdit).StyleController = DefaultStyles.ContainsKey((action.Control as TextEdit)) ? DefaultStyles[(action.Control as TextEdit)] : null;
                }
            }
        }
Ejemplo n.º 2
0
        private void repItemKeyDownHandler(object sender, KeyEventArgs ke)
        {
            if ((ke.Control && ke.KeyCode == Keys.Delete) || ((ke.KeyCode == Keys.Delete || ke.KeyCode == Keys.Back) && (sender as TextEdit)?.Text?.Length == 0))
            {
                // reset field
                FilterObjectbase fo = Current as FilterObjectbase;
                if (fo != null)
                {
                    // get field using binding
                    if ((sender as Control).DataBindings.Count > 0)
                    {
                        string FieldName = (sender as Control).DataBindings[0].BindingMemberInfo.BindingMember;

                        // avoid value kick back due to binder will react on PropertyChanged event and will pull
                        // control data back from UI to model
                        // UI is not cleared
                        (sender as Control).DataBindings[0].DataSourceUpdateMode = DataSourceUpdateMode.Never;
                        // reset field
                        fo.ResetFieldByName(FieldName);
                        // turn back DS update mode
                        (sender as Control).DataBindings[0].DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
                        // eventual null prompt
                        TextEdit te = sender as TextEdit;
                        if (te != null)
                        {
                            te.Properties.NullValuePrompt = "";

                            te.StyleController = EditorsHost.FormSupport.DefaultStyles.ContainsKey(te) ? EditorsHost.FormSupport.DefaultStyles[te] : null;
                        }
                        ke.Handled = true;
                    }
                }
            }

            /*
             * else
             * {
             *  TextEdit te = sender as TextEdit;
             *  if (te != null)
             *  {
             *      te.StyleController = _ModifiedStyle;
             *                  }
             * }
             */
        }