Esempio n. 1
0
                public SimpleForm(T_Entity entityData, RoutedEventHandler onValidateEvent = null, Delegates.PropertyToUIElementConversion <T_Entity> PropertyToUIElementConvertor = null)
                {
                    entity     = entityData;
                    onValidate = onValidateEvent;
                    propertyToUIElementConvertor = (PropertyToUIElementConvertor == null ? propertyToUIElementConvertor : PropertyToUIElementConvertor);

                    InitializeGrid();
                    InitializeColumns();
                    FillWithDatas();

                    validButton.Click += (sender, e) =>
                    {
                        foreach (var property in entity.GetType().GetProperties())
                        {
                            if (Attribute.IsDefined(property, typeof(GCL.UIHelper.Attributes.FormMandatory)) &&
                                property.GetValue(entity) == null)
                            {
                                e.Handled = true;
                                MessageBox.Show(String.Format("{0} is mandatory", property.Name),
                                                String.Format("{0} editor error", entity.GetType()),
                                                MessageBoxButton.OK,
                                                MessageBoxImage.Error
                                                );
                                return;
                            }
                        }
                    };
                }
Esempio n. 2
0
            public static void AttachAddDeleteContextMenu <T_Item>(ref TreeView view,
                                                                   Delegates.OnUpdate <T_Item> onAdd,
                                                                   Delegates.OnUpdate <T_Item> onDelete,
                                                                   Delegates.OnUpdate <T_Item> onEdit,
                                                                   Delegates.PropertyToUIElementConversion <T_Item> PropertyToUIElementConvertor = null)
                where T_Item : class, new()
            {
                var viewCpy = view;

                var viewItemCM = new ContextMenu();
                {   // TreeViewItem context Menu
                    #region MenuItem binded to commands
                    #region Add MenuItem
                    var AddMenuItem = new MenuItem
                    {
                        Icon = new Image {
                            Source = new BitmapImage(new Uri("pack://application:,,,/VidaProteina;component/Images/Icons/add.png")), Width = 16, Height = 16
                        },
                        Header = "Add"
                    };
                    AddMenuItem.Click += (sender, e) =>
                    {
                        var item  = new T_Item();
                        var form  = new Control.SimpleForm <T_Item>(item, null, PropertyToUIElementConvertor);
                        var popup = new Control.Popup(
                            form,
                            null,
                            "Product formulary");
                        form.onValidate = (s, ev) => { onAdd(item); viewCpy.Items.Refresh(); popup.Close(); };
                        popup.Show();
                    };
                    viewItemCM.Items.Add(AddMenuItem);
                    #endregion
                    #region Delete MenuItem
                    var DeleteMenuItem = new MenuItem
                    {
                        Icon = new Image {
                            Source = new BitmapImage(new Uri("pack://application:,,,/VidaProteina;component/Images/Icons/trash.png")), Width = 16, Height = 16
                        },
                        Header = "Delete"
                    };
                    DeleteMenuItem.Click += (sender, e) =>
                    {
                        var selectedItem = (viewCpy.SelectedItem as TreeViewItem);
                        if (selectedItem == null)
                        {
                            return;
                        }

                        onDelete(selectedItem.DataContext as T_Item as T_Item);
                        viewCpy.Items.Refresh();
                    };
                    viewItemCM.Items.Add(DeleteMenuItem);
                    #endregion
                    #region Edit MenuItem
                    var EditMenuItem = new MenuItem
                    {
                        Icon = new Image {
                            Source = new BitmapImage(new Uri("pack://application:,,,/VidaProteina;component/Images/Icons/edit.png")), Width = 16, Height = 16
                        },
                        Header = "Edit"
                    };
                    EditMenuItem.Click += (sender, e) =>
                    {
                        var selectedItem = (viewCpy.SelectedItem as TreeViewItem);
                        if (selectedItem == null)
                        {
                            return;
                        }
                        // throw new InvalidOperationException("AttachAddDeleteContextMenu : Bad item type");

                        var item = selectedItem.DataContext as T_Item;

                        var form  = new Control.SimpleForm <T_Item>(item, null, PropertyToUIElementConvertor);
                        var popup = new Control.Popup(form, null, "Product modification");
                        form.onValidate = (s, ev) => { onEdit(item); popup.Close(); };
                        popup.Show();
                    };
                    viewItemCM.Items.Add(EditMenuItem);
                    #endregion
                    #endregion
                }

                view.ItemContainerStyle = new Style(typeof(TreeViewItem));
                view.ItemContainerStyle.Setters.Add(new Setter(TreeViewItem.ContextMenuProperty, viewItemCM));

                var viewCM = new ContextMenu();
                {   // TreeView context menu
                    #region Add MenuItem
                    var AddMenuItem = new MenuItem
                    {
                        Icon = new Image {
                            Source = new BitmapImage(new Uri("pack://application:,,,/VidaProteina;component/Images/Icons/add.png")), Width = 16, Height = 16
                        },
                        Header = "Add"
                    };
                    AddMenuItem.Click += (sender, e) =>
                    {
                        var item  = new T_Item();
                        var form  = new Control.SimpleForm <T_Item>(item, null, PropertyToUIElementConvertor);
                        var popup = new Control.Popup(form, null, "Product formulary");
                        form.onValidate = (s, ev) => { onAdd(item); viewCpy.Items.Refresh(); popup.Close(); };
                        popup.Show();
                    };
                    viewCM.Items.Add(AddMenuItem);
                    #endregion
                }

                view.SetValue(TreeView.ContextMenuProperty, viewCM);
            }