Esempio n. 1
0
 private void dataForm1_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "IDProdotto")
     {
         e.Cancel = true;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Wire up the Password and PasswordConfirmation Accessors as the fields get generated.
        /// </summary>
        private void RegisterForm_AutoGeneratingField(object dataForm, DataFormAutoGeneratingFieldEventArgs e)
        {
            // Put all the fields in adding mode
            e.Field.Mode = DataFieldMode.AddNew;

            //if (e.PropertyName == "Password")
            //{
            //    PasswordBox passwordBox = (PasswordBox)e.Field.Content;
            //    this.registrationData.PasswordAccessor = () => passwordBox.Password;
            //}
            //else if (e.PropertyName == "PasswordConfirmation")
            //{
            //    PasswordBox passwordConfirmationBox = (PasswordBox)e.Field.Content;
            //    this.registrationData.PasswordConfirmationAccessor = () => passwordConfirmationBox.Password;
            //}
            //else if (e.PropertyName == "UserName")
            //{
            //    TextBox textBox = (TextBox)e.Field.Content;
            //    textBox.LostFocus += this.UserNameLostFocus;
            //}
            //else if (e.PropertyName == "Question")
            //{
            //    // Create a ComboBox populated with security questions
            //    ComboBox comboBoxWithSecurityQuestions = RegistrationForm.CreateComboBoxWithSecurityQuestions();

            //    // Replace the control
            //    // Note: Since TextBox.Text treats empty text as string.Empty and ComboBox.SelectedItem
            //    // treats an empty selection as null, we need to use a converter on the binding
            //    //e.Field.ReplaceTextBox(comboBoxWithSecurityQuestions, ComboBox.SelectedItemProperty, binding => binding.Converter = new TargetNullValueConverter());
            //}
        }
        /// <summary>
        /// Wire up the Password and PasswordConfirmation accessors as the fields get generated.
        /// Also bind the Question field to a ComboBox full of security questions, and handle the LostFocus event for the UserName TextBox.
        /// </summary>
        private void RegisterForm_AutoGeneratingField(object dataForm, DataFormAutoGeneratingFieldEventArgs e)
        {
            // Put all the fields in adding mode
            e.Field.Mode = DataFieldMode.AddNew;

            if (e.PropertyName == "UserName")
            {
                this.userNameTextBox = (TextBox)e.Field.Content;
                this.userNameTextBox.LostFocus += this.UserNameLostFocus;
            }
            else if (e.PropertyName == "Password")
            {
                PasswordBox passwordBox = new PasswordBox();
                e.Field.ReplaceTextBox(passwordBox, PasswordBox.PasswordProperty);
                this.registrationData.PasswordAccessor = () => passwordBox.Password;
            }
            else if (e.PropertyName == "PasswordConfirmation")
            {
                PasswordBox passwordConfirmationBox = new PasswordBox();
                e.Field.ReplaceTextBox(passwordConfirmationBox, PasswordBox.PasswordProperty);
                this.registrationData.PasswordConfirmationAccessor = () => passwordConfirmationBox.Password;
            }
            else if (e.PropertyName == "Question")
            {
                ComboBox questionComboBox = new ComboBox();
                questionComboBox.ItemsSource = RegistrationForm.GetSecurityQuestions();
                e.Field.ReplaceTextBox(questionComboBox, ComboBox.SelectedItemProperty, binding => binding.Converter = new TargetNullValueConverter());
            }
        }
 /// <summary>
 /// Handles <see cref="DataForm.AutoGeneratingField"/> to provide the PasswordAccessor.
 /// </summary>
 private void LoginForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "Password")
     {
         PasswordBox passwordBox = (PasswordBox)e.Field.Content;
         this.loginInfo.PasswordAccessor = () => passwordBox.Password;
     }
 }
 private void editForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "MemberID" || e.PropertyName == "BookID" || e.PropertyName == "Category" || e.PropertyName == "CategoryID" || e.PropertyName == "BookOfDays")
     {
         e.Cancel = true ;
     }
     if (e.PropertyName == "Description")
     {
         TextBox textDesc = (TextBox)e.Field.Content;
         textDesc.AcceptsReturn = true;
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Handles <see cref="DataForm.AutoGeneratingField"/> to provide the PasswordAccessor.
 /// </summary>
 private void LoginForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "UserName")
     {
         this.userNameTextBox = (TextBox)e.Field.Content;
     }
     else if (e.PropertyName == "Password")
     {
         PasswordBox passwordBox = new PasswordBox();
         e.Field.ReplaceTextBox(passwordBox, PasswordBox.PasswordProperty);
         this.loginInfo.PasswordAccessor = () => passwordBox.Password;
     }
 }
Esempio n. 7
0
        /// <summary>
        ///     Extends <see cref="DataForm.OnAutoGeneratingField" /> by replacing <see cref="TextBox"/>es with <see cref="PasswordBox"/>es
        ///     whenever applicable
        /// </summary>
        protected override void OnAutoGeneratingField(DataFormAutoGeneratingFieldEventArgs e)
        {
            // Get metadata about the property being defined
            PropertyInfo propertyInfo = this.CurrentItem.GetType().GetProperty(e.PropertyName);

            // Do the password field replacement if that is the case
            if (e.Field.Content is TextBox && this.IsPasswordProperty(propertyInfo))
            {
                //e.Field.ReplaceTextBox(new PasswordBox(), PasswordBox.PasswordProperty);
            }

            // Keep this newly generated field accessible through the Fields property
            this.fields[e.PropertyName] = e.Field;

            // Call base implementation (which will call other event listeners)
            base.OnAutoGeneratingField(e);
        }
Esempio n. 8
0
        /// <summary>
        /// Handles <see cref="DataForm.AutoGeneratingField"/> to provide the PasswordAccessor.
        /// </summary>
        private void ChangePasswordForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
        {
            PasswordBox passwordBox = new PasswordBox();
            e.Field.ReplaceTextBox(passwordBox, PasswordBox.PasswordProperty);
            if (e.PropertyName == "Password")
            {
                this.changePasswordInfo.PasswordAccessor = () => passwordBox.Password;
            }
            else if (e.PropertyName == "OldPassword")
            {
                this.oldPasswordTextBox = (PasswordBox)e.Field.Content;
                this.changePasswordInfo.OldPasswordAccessor = () => passwordBox.Password;
            }
            else if (e.PropertyName == "PasswordConfirmation")
            {
                this.changePasswordInfo.PasswordConfirmationAccessor = () => passwordBox.Password;
            }

            //both password boxes need to be replaced
        }
Esempio n. 9
0
        private void RegisterForm_AutoGeneratingField(object dataForm, DataFormAutoGeneratingFieldEventArgs e)
        {
            // Put all the fields in adding mode
            e.Field.Mode = DataFieldMode.AddNew;

            if (e.PropertyName == "Password")
            {
                PasswordBox passwordBox = new PasswordBox();
                if (EditMode)
                {
                    //passwordBox.IsEnabled = false;
                    //passwordBox.Visibility = System.Windows.Visibility.Collapsed;
                    passwordBox.Password = "******";
                }
                e.Field.ReplaceTextBox(passwordBox, PasswordBox.PasswordProperty);
                this.registrationData.PasswordAccessor = () => passwordBox.Password;
            }
            else if (e.PropertyName == "PasswordConfirmation")
            {
                PasswordBox passwordConfirmationBox = new PasswordBox();
                if (EditMode)
                {
                    //passwordConfirmationBox.IsEnabled = false;
                    passwordConfirmationBox.Password = "******";
                    //passwordConfirmationBox.Visibility = System.Windows.Visibility.Collapsed;
                }
                e.Field.ReplaceTextBox(passwordConfirmationBox, PasswordBox.PasswordProperty);

                this.registrationData.PasswordConfirmationAccessor = () => passwordConfirmationBox.Password;
            }
            else if (e.PropertyName == "UserName" && !string.IsNullOrEmpty(registrationData.UserName))
            {
                TextBox textBox = (TextBox)e.Field.Content;
                if (EditMode)
                {
                    textBox.Text = registrationData.UserName;
                    textBox.IsEnabled = false;
                }
                textBox.LostFocus += this.UserNameLostFocus;
            }
            else if (e.PropertyName == "Question")
            {
                // Create a ComboBox populated with security questions
                ComboBox comboBoxWithSecurityQuestions = new ComboBox(); //DataFrom.CreateComboBoxWithSecurityQuestions();

                // Replace the control
                // Note: Since TextBox.Text treats empty text as string.Empty and ComboBox.SelectedItem
                // treats an empty selection as null, we need to use a converter on the binding
                e.Field.ReplaceTextBox(comboBoxWithSecurityQuestions, ComboBox.SelectedItemProperty, binding => binding.Converter = new TargetNullValueConverter());
            }
            else if (e.PropertyName == "GroupName")
            {
                comboBoxGroups = new ComboBox();
                comboBoxGroups.ItemsSource = GroupService.Groups;
                var groupLoadResult = GroupService.Load(GroupService.GetGroupsQuery());
                comboBoxGroups.DisplayMemberPath = "GroupName";
                Binding b = new Binding();
                b.Path = new PropertyPath("IsStudent");
                b.Mode = BindingMode.OneWay;
                b.Source = this;
                comboBoxGroups.SetBinding(ComboBox.IsEnabledProperty, b);
                if (EditMode)
                {
                    groupLoadResult.Completed += new EventHandler(groupLoadResult_Completed);
                }

                e.Field.ReplaceTextBox(comboBoxGroups, ComboBox.SelectedItemProperty);
            }

            else if (e.PropertyName == "UserRole")
            {
                comboBoxRoles = new ComboBox();
                comboBoxRoles.ItemsSource = RoleService.aspnet_Roles;
                var roleLoadResult = RoleService.Load(RoleService.GetAspnet_RolesQuery());
                comboBoxRoles.DisplayMemberPath = "RoleName";
                comboBoxRoles.SelectionChanged += new SelectionChangedEventHandler(comboBoxWithSecurityQuestions_SelectionChanged);
                if (EditMode)
                {
                    roleLoadResult.Completed += new EventHandler(roleLoadResult_Completed);
                }
                e.Field.ReplaceTextBox(comboBoxRoles, ComboBox.SelectedItemProperty, binding => binding.Converter = new TargetNullValueConverter());
            }
            else if (e.PropertyName == "FirstName" && EditMode && !string.IsNullOrEmpty(registrationData.FirstName))
            {
                var firstNameTextBox = (TextBox)e.Field.Content;
                firstNameTextBox.Text = registrationData.FirstName;
            }
            else if (e.PropertyName == "LastName" && EditMode && !string.IsNullOrEmpty(registrationData.LastName))
            {
                var lastNameTextBox = (TextBox)e.Field.Content;
                lastNameTextBox.Text = registrationData.LastName;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Generates a field based on a property type and a property name.
        /// </summary>
        /// <param name="propertyType">The type of the property.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="bindingMode">The binding mode.</param>
        /// <param name="panel">The panel to insert the field into.</param>
        /// <returns>A value indicating whether or not the field was generated.</returns>
        private bool GenerateField(Type propertyType, string propertyName, BindingMode bindingMode, Panel panel)
        {
            // Create a new DataField for the property.
            DataField newField = new DataField();
            Control control = GetControlFromType(propertyType);
            DependencyProperty dependencyProperty = GetBindingPropertyFromType(propertyType);

            control.TabIndex = this.GetNextTabIndex();
            newField.Content = control;

            if (bindingMode == BindingMode.TwoWay && !string.IsNullOrEmpty(propertyName))
            {
                control.SetBinding(
                    dependencyProperty,
                    new Binding(propertyName)
                    {
                        Mode = BindingMode.TwoWay,
                        ValidatesOnExceptions = true,
                        NotifyOnValidationError = true,
                        Converter = propertyType.IsEnum ? new DataFormToStringConverter() : null
                    });
            }
            else
            {
                control.SetBinding(
                    dependencyProperty,
                    new Binding(propertyName)
                    {
                        Mode = BindingMode.OneWay,
                        Converter = propertyType.IsEnum ? new DataFormToStringConverter() : null
                    });

                newField.IsReadOnly = true;
            }

            // If there's no path, coerce the field to read-only mode and give it
            // a label of "value" (since otherwise it would be blank).
            if (string.IsNullOrEmpty(propertyName))
            {
                newField.IsReadOnly = true;
                newField.Label = propertyType.Name;
            }

            // Raise the AutoGeneratingField event in case the user wants to cancel or replace the
            // field being generated.
            DataFormAutoGeneratingFieldEventArgs e = new DataFormAutoGeneratingFieldEventArgs(propertyName, propertyType, newField);
            this.OnAutoGeneratingField(e);

            if (e.Cancel)
            {
                return false;
            }
            else
            {
                panel.Children.Add(e.Field);
                return true;
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Raises the AutoGeneratingField event.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnAutoGeneratingField(DataFormAutoGeneratingFieldEventArgs e)
 {
     EventHandler<DataFormAutoGeneratingFieldEventArgs> handler = this.AutoGeneratingField;
     if (handler != null)
     {
         handler(this, e);
     }
 }
        public void InvalidateForm()
        {
            if (partGrid != null)
            {
                partGrid.Children.Clear();
                this.DiscoverObject();

                Grid grid1 = new Grid();
                grid1.Margin = new Thickness(5);
                grid1.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(1, GridUnitType.Auto)
                });
                grid1.ColumnDefinitions.Add(new ColumnDefinition());// {Width = new GridLength(1, GridUnitType.Auto)});
                //grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });

                int row = 0;

                var listProperties = from p in this.displays
                                     orderby(p.Value.GetOrder() ?? 0)
                                     select this.properties[p.Key];

                foreach (PropertyInfo property in listProperties)
                {
                    var nm = displays[property.Name].GetName();
                    if (string.IsNullOrEmpty(nm))
                    {
                        nm = property.Name;
                    }
                    var tooltip = displays[property.Name].GetDescription();

                    var lbl = GetLabelTextBlock(nm, tooltip);

                    // Binding Creation
                    Binding binding = new Binding(property.Name);
                    binding.Source           = this.CurrentItem;
                    binding.ConverterCulture = CultureInfo.CurrentCulture;
                    binding.Mode             = (bindables[property.Name].Direction == BindingDirection.TwoWay
                        ? BindingMode.TwoWay
                        : BindingMode.OneWay);
                    binding.ValidatesOnDataErrors   = true;
                    binding.ValidatesOnExceptions   = true;
                    binding.NotifyOnValidationError = true;
                    binding.UpdateSourceTrigger     = UpdateSourceTrigger.PropertyChanged;

#if !SILVERLIGHT
                    //binding.NotifyOnTargetUpdated = true;
                    //binding.NotifyOnSourceUpdated = true;
                    //binding.IsAsync = true;
#endif

#if !SILVERLIGHT
                    foreach (ValidationAttribute attribs in this.validations[property.Name])
                    {
                        ValidationRule rule = new AttributeValidationRule(attribs, property.Name);
                        binding.ValidationRules.Add(rule);
                        if (!this.rules.ContainsKey(property.Name))
                        {
                            this.rules.Add(property.Name, new List <ValidationRule>());
                        }
                        this.rules[property.Name].Add(rule);
                    }
#endif

                    // Control creation
                    FrameworkElement editorControl = this.GetControlFromProperty(property, binding);

                    if (editorControl == null)
                    {
                        continue;
                    }

                    var df = new DataField()
                    {
                        Content = editorControl, Label = lbl
                    };

                    DataFormAutoGeneratingFieldEventArgs e = new DataFormAutoGeneratingFieldEventArgs(property.Name,
                                                                                                      property.PropertyType, df);
                    EventHandler <DataFormAutoGeneratingFieldEventArgs> eventHandler = this.AutoGeneratingField;
                    if (eventHandler != null)
                    {
                        eventHandler(this, e);
                    }

                    if (e.Cancel)
                    {
                        continue;
                    }

                    ToolTipService.SetToolTip(df.Content, displays[property.Name].GetDescription());
#if !SILVERLIGHT
                    Validation.SetErrorTemplate(df.Content, ErrorTemplate);
#endif
                    //df.Content.HorizontalAlignment = Windows.HorizontalAlignment.Stretch;

                    // Add to view
                    RowDefinition newRow = new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    };
                    grid1.RowDefinitions.Add(newRow);
                    if (df.Content.Height.CompareTo(Double.NaN) != 0)
                    {
                        newRow.Height = new GridLength(df.Content.Height);
                    }
                    Grid.SetColumn(df.Label, 0);
                    Grid.SetRow(df.Label, row);
                    Grid.SetColumn(df.Content, 1);
                    Grid.SetRow(df.Content, row);

                    grid1.Children.Add(df.Label);
                    grid1.Children.Add(df.Content);
                    this.controls.Add(property.Name, df.Content);

                    row++;
                }

                partGrid.Children.Add(grid1);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Wire up the Password and PasswordConfirmation accessors as the fields get generated.
        /// Also bind the Question field to a ComboBox full of security questions, and handle the LostFocus event for the UserName TextBox.
        /// </summary>
        private void RegisterForm_AutoGeneratingField(object dataForm, DataFormAutoGeneratingFieldEventArgs e)
        {
            // Put all the fields in adding mode
            e.Field.Mode = DataFieldMode.AddNew;

            var registrationData = DataContext as RegistrationData;

            if (e.PropertyName == "UserName")
            {
                this.userNameTextBox = (TextBox)e.Field.Content;
                this.userNameTextBox.LostFocus += this.UserNameLostFocus;
            }
            else if (e.PropertyName == "Password")
            {
                PasswordBox passwordBox = new PasswordBox();
                e.Field.ReplaceTextBox(passwordBox, PasswordBox.PasswordProperty);
                registrationData.PasswordAccessor = () => passwordBox.Password;
            }
            else if (e.PropertyName == "PasswordConfirmation")
            {
                PasswordBox passwordConfirmationBox = new PasswordBox();
                e.Field.ReplaceTextBox(passwordConfirmationBox, PasswordBox.PasswordProperty);
                registrationData.PasswordConfirmationAccessor = () => passwordConfirmationBox.Password;
            }
            else if (e.PropertyName == "Foundry")
            {
                this.foundryCombobox = new ComboBox();
                foundryCombobox.ItemsSource = Foundries;
                e.Field.ReplaceTextBox(foundryCombobox, ComboBox.SelectedItemProperty);
                foundryCombobox.SelectionChanged += this.foundryComboboxSelectionChanged;
            }
            else if (e.PropertyName == "Role")
            {
                roleCombobox = new ComboBox();
                roleCombobox.ItemsSource = Roles;
                e.Field.ReplaceTextBox(roleCombobox, ComboBox.SelectedItemProperty);
                roleCombobox.SelectionChanged += this.roleComboboxSelectionChanged;
            }

            else if (e.PropertyName == "CustomerCompany")
            {
                this.customerCombobox = new ComboBox();
                e.Field.ReplaceTextBox(customerCombobox, ComboBox.SelectedItemProperty);
            }
        }
Esempio n. 14
0
 private void EditFormAutoGeneratingField(object dataForm, DataFormAutoGeneratingFieldEventArgs e)
 {
 }
        /// <summary>
        /// Wire up the Password and PasswordConfirmation accessors as the fields get generated.
        /// Also bind the Question field to a ComboBox full of security questions, and handle the LostFocus event for the UserName TextBox.
        /// </summary>
        private void RegisterForm_AutoGeneratingField(object dataForm, DataFormAutoGeneratingFieldEventArgs e)
        {
            // Put all the fields in adding mode
            e.Field.Mode = DataFieldMode.AddNew;

            if (e.PropertyName == "UserName")
            {
                this.userNameTextBox = (TextBox)e.Field.Content;
             }
            else if (e.PropertyName == "Password")
            {
                PasswordBox passwordBox = new PasswordBox();
                e.Field.ReplaceTextBox(passwordBox, PasswordBox.PasswordProperty);
                this.registrationData.PasswordAccessor = () => passwordBox.Password;
            }
            else if (e.PropertyName == "PasswordConfirmation")
            {
                PasswordBox passwordConfirmationBox = new PasswordBox();
                e.Field.ReplaceTextBox(passwordConfirmationBox, PasswordBox.PasswordProperty);
                this.registrationData.PasswordConfirmationAccessor = () => passwordConfirmationBox.Password;
            }
        }
        private void RecordDataFormAutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
        {
            e.Field.Mode = DataFieldMode.Edit;

            if (e.PropertyName == "Type")
            {
                var accountTypeList = _category == AccountCategory.Expense ? AccountBookContext.Instance.ExpenseTypeList : AccountBookContext.Instance.IncomeTypeList;
                var cmbAccountType = new ComboBox();
                cmbAccountType.DisplayMemberPath = "TypeName";
                cmbAccountType.Name = "CmbAccountType";
                cmbAccountType.ItemsSource = accountTypeList;
                cmbAccountType.SelectedItem = accountTypeList[1];
                cmbAccountType.ItemContainerStyle = Application.Current.Resources["ExAccountTypeItemPanelStyle"] as Style;
                e.Field.ReplaceTextBox(cmbAccountType, Selector.SelectedIndexProperty, binding =>
                {
                    binding.Mode = BindingMode.TwoWay;
                    binding.Converter = new AccountTypeConverter(_category == AccountCategory.Expense ? AccountBookContext.Instance.ExpenseTypeList : AccountBookContext.Instance.IncomeTypeList);
                });
            }
            else if (e.PropertyName == "Consumer")
            {
                var cmbConsumer = new ComboBox();
                cmbConsumer.Name = "CmbConsumer";
                cmbConsumer.DisplayMemberPath = "FriendlyName";
                cmbConsumer.ItemsSource = AccountBookContext.Instance.ConsumerList;
                e.Field.ReplaceTextBox(cmbConsumer, Selector.SelectedIndexProperty, binding =>
                {
                    binding.Mode = BindingMode.TwoWay;
                    binding.Converter = new ConsumeUserConverter();
                });
            }
            else if (e.PropertyName == "Memo")
            {
                var memoTextBox = e.Field.Content as TextBox;
                if (memoTextBox != null)
                {
                    memoTextBox.Height = 120;
                    memoTextBox.Width = 180;
                    memoTextBox.TextWrapping = TextWrapping.Wrap;
                }
            }
        }
Esempio n. 17
0
 private void companyForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     if (e.PropertyName == "Logo")
     {
         FileUpload fileUploader = new FileUpload();
         e.Field.ReplaceTextBox(fileUploader, FileUpload.UploadedFileProperty);
     }
 }
Esempio n. 18
0
 /// <summary>
 /// 自动生成登录框DataForm
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void LoginForm_AutoGeneratingField(object sender, DataFormAutoGeneratingFieldEventArgs e)
 {
     switch (e.PropertyName)
     {
         case "UserName":
             this._userNameTextBox = (TextBox)e.Field.Content;
             break;
         case "Password":
             {
                 var passwordBox = new PasswordBox();
                 e.Field.ReplaceTextBox(passwordBox, PasswordBox.PasswordProperty);
                 this.LogInfo.PasswordAccessor = () => passwordBox.Password;
             }
             break;
     }
 }