/// <summary> /// Creates and adds the required GUI elements /// </summary> private void CreateGUI() { // Create the add button AddButton = ControlsFactory.CreateStandardAddCircularButton(); AddButton.Command = new RelayCommand(async() => { // Create the form var form = CeidDiplomatikiDataModelHelpers.CreatePageMapDataForm(); // Set the model form.Model = new PageMap(); // Show the dialog var dialogResult = await DialogHelpers.ShowConventionalAddDialogAsync(this, "Page creation", null, form); // If we didn't get positive feedback... if (!dialogResult.Feedback) { // Return return; } // Update the values of the model form.UpdateModelValues(); // Get the manager var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager; // Register it manager.Register(form.Model); // Save the changes var result = await manager.SaveChangesAsync(); // If there was an error... if (!result.Successful) { // Show the error await result.ShowDialogAsync(this); // Return return; } // Add it to the presenter DataPresenter.Add(form.Model); }); // Add it to the content grid ContentGrid.Children.Add(AddButton); }
/// <summary> /// Creates and returns the <see cref="BaseItemsControlPage{TClass}.DataPresenter"/> /// </summary> /// <returns></returns> protected override IDataPresenter <PageMap> CreateDataPresenter() { return(new CollapsibleDataGrid <PageMap>() { Mapper = CeidDiplomatikiDataModelHelpers.PageMapMapper.Value } .ShowData(x => x.Name) .ShowData(x => x.Color) .ShowData(x => x.Category) .ShowData(x => x.Order) .ShowData(x => x.Presenter) .ShowData(x => x.Pages) .SetColorUIElement(x => x.Color) .SetDataPresenterSubElement(x => x.Pages, model => model.Pages.Count.ToString("page", "pages", "No pages"), model => CreateDataPresenter(), (presenter, model, button) => { button.VectorSource = IconPaths.PlusPath; button.Command = new RelayCommand(async() => { // Create the form var form = CeidDiplomatikiDataModelHelpers.CreatePageMapDataForm(); // Set the model form.Model = new PageMap() { Parent = model }; // Show the dialog var dialogResult = await DialogHelpers.ShowConventionalAddDialogAsync(this, "Page creation", null, form); // If we didn't get positive feedback... if (!dialogResult.Feedback) { // Return return; } // Update the values of the model form.UpdateModelValues(); // Add the model to the parent model model.Pages.Add(form.Model); // Get the manager var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager; // Save the changes var result = await manager.SaveChangesAsync(); // If there was an error... if (!result.Successful) { // Show the error await result.ShowDialogAsync(this); // Return return; } // Add it to the presenter presenter.Add(form.Model); }); }) .ConfigureOptions((container, grid, row, model) => { container.AddEditOption("Page modification", null, () => CeidDiplomatikiDataModelHelpers.CreatePageMapDataForm(), async(model) => await CeidDiplomatikiDI.GetCeidDiplomatikiManager.SaveChangesAsync()); container.AddDeleteOption("Page deletion", null, async(model) => { // Get the manger var manager = CeidDiplomatikiDI.GetCeidDiplomatikiManager; // If there is a parent... if (model.Parent != null) { // Remove the model form the parent model.Parent.Pages.Remove(model); } // Else... else { // This is a root page so remove it from the manager manager.Unregister(model); } // Save the changes return await manager.SaveChangesAsync(); }); })); }
/// <summary> /// Creates and returns the GUI in a form of a <see cref="FrameworkElement"/> /// </summary> /// <returns></returns> protected override FrameworkElement CreateBaseGUIElement() { // Create the content stack panel ContentStackPanel = new StackPanel() { Orientation = Orientation.Vertical }; #region SQLite // Create the SQLite stack panel collapsible vertical menu SQLiteStackPanelCollapsibleVerticalMenu = new StackPanelCollapsibleVerticalMenu <UIElement>() { IsOpen = true, Text = "SQLite" }; // Create the SQLite options data grid SQLiteOptionsDataGrid = CeidDiplomatikiDataModelHelpers.CreateDefaultSQLiteOptionsDataModelDataGrid(); SQLiteOptionsDataGrid.ConfigureOptions((container, grid, row, model) => { container.AddDeleteOption(async(button) => await RemoveOptionAsync(model)); }); SQLiteOptionsDataGrid.Margin = new Thickness(NormalUniformMargin); // Add it to the collapsible menu SQLiteStackPanelCollapsibleVerticalMenu.Add(SQLiteOptionsDataGrid); // Add the collapsible menu to the stack panel ContentStackPanel.Children.Add(SQLiteStackPanelCollapsibleVerticalMenu); #endregion #region MySQL // Create the MySQL stack panel collapsible vertical menu MySQLStackPanelCollapsibleVerticalMenu = new StackPanelCollapsibleVerticalMenu <UIElement>() { IsOpen = true, Text = "MySQL" }; // Create the MySQL options data grid MySQLOptionsDataGrid = CeidDiplomatikiDataModelHelpers.CreateDefaultMySQLOptionsDataModelDataGrid(); MySQLOptionsDataGrid.ConfigureOptions((container, grid, row, model) => { container.AddOpenOption(async(button) => { var provider = SQLDatabaseProvider.MySQL; // Get the analyzer var analyzer = CeidDiplomatikiDI.GetDatabaseAnalyzer(provider); // Get the connection string model.TryGetConnectionString(out var connectionString); // Get the database var database = analyzer.GetDatabases().First(x => x.DatabaseName == model.DatabaseName); // Show the page await WindowsControlsDI.GetWindowsDialogManager.OpenAsync(model.DatabaseName, IconPaths.DatabasePath, () => { return(new QueryMapsPage(database, model)); }, connectionString); }); container.AddDeleteOption(async(button) => await RemoveOptionAsync(model)); }); MySQLOptionsDataGrid.Margin = new Thickness(NormalUniformMargin); // Add it to the collapsible menu MySQLStackPanelCollapsibleVerticalMenu.Add(MySQLOptionsDataGrid); // Add the collapsible menu to the stack panel ContentStackPanel.Children.Add(MySQLStackPanelCollapsibleVerticalMenu); #endregion #region SQLServer // Create the SQLServer stack panel collapsible vertical menu SQLServerStackPanelCollapsibleVerticalMenu = new StackPanelCollapsibleVerticalMenu <UIElement>() { IsOpen = true, Text = "SQLServer" }; // Create the SQLServer options data grid SQLServerOptionsDataGrid = CeidDiplomatikiDataModelHelpers.CreateDefaultSQLServerOptionsDataModelDataGrid(); SQLServerOptionsDataGrid.ConfigureOptions((container, grid, row, model) => { container.AddDeleteOption(async(button) => await RemoveOptionAsync(model)); }); SQLServerOptionsDataGrid.Margin = new Thickness(NormalUniformMargin); // Add it to the collapsible menu SQLServerStackPanelCollapsibleVerticalMenu.Add(SQLServerOptionsDataGrid); // Add the collapsible menu to the stack panel ContentStackPanel.Children.Add(SQLServerStackPanelCollapsibleVerticalMenu); #endregion #region PostgreSQL // Create the PostgreSQL stack panel collapsible vertical menu PostgreSQLStackPanelCollapsibleVerticalMenu = new StackPanelCollapsibleVerticalMenu <UIElement>() { IsOpen = true, Text = "PostgreSQL" }; // Create the PostgreSQL options data grid PostgreSQLOptionsDataGrid = CeidDiplomatikiDataModelHelpers.CreateDefaultPostgreSQLOptionsDataModelDataGrid(); PostgreSQLOptionsDataGrid.ConfigureOptions((container, grid, row, model) => { container.AddDeleteOption(async(button) => await RemoveOptionAsync(model)); }); PostgreSQLOptionsDataGrid.Margin = new Thickness(NormalUniformMargin); // Add it to the collapsible menu PostgreSQLStackPanelCollapsibleVerticalMenu.Add(PostgreSQLOptionsDataGrid); // Add the collapsible menu to the stack panel ContentStackPanel.Children.Add(PostgreSQLStackPanelCollapsibleVerticalMenu); #endregion // Return the content stack panel return(ContentStackPanel); }