protected override void CommitEdit()
        {
            var completeDatabaseModelCurrentItem = (CompleteDatabaseModel)DataForm.CurrentItem;

            if (null != completeDatabaseModelCurrentItem && completeDatabaseModelCurrentItem.ConfirmTheOperation)
            {
                MessageBoxResult result = MessageBox.Show($"Dodać {completeDatabaseModelCurrentItem?.NumberOfRecords} rekordów do bazy danych? Uwaga istniejące dane zostaną usunięte z bazy danych!", "Potwierdź operację!", MessageBoxButton.OKCancel);
                if (result == MessageBoxResult.OK)
                {
                    if (DataForm != null && DataForm.ValidateItem())
                    {
                        _mainWindow.Opacity   = 50;
                        _mainWindow.IsEnabled = false;
                        Task task = Task.Run(() =>
                        {
                            return(StudentsRepository.GetInstance().CreateExampleStudents((int)completeDatabaseModelCurrentItem?.NumberOfRecords));
                        });
                        task.GetAwaiter().OnCompleted(() =>
                        {
                            MessageBox.Show($"Dodałem {completeDatabaseModelCurrentItem?.NumberOfRecords} rekordów do bazy danych.", "Operacja zakończona");
                            _mainWindow.Opacity   = 100;
                            _mainWindow.IsEnabled = true;
                        });
                    }
                }
            }
            else
            {
                MessageBox.Show($"Proszę zaznaczyć potwierdź operację!", "Potwierdź operację!", MessageBoxButton.OK);
            }
        }
        protected override void Delete()
        {
            var completeDatabaseModelCurrentItem = (Students)DataForm.CurrentItem;

            if (null != completeDatabaseModelCurrentItem)
            {
                if (DataForm != null && DataForm.ValidateItem())
                {
                    MessageBoxResult result = MessageBox.Show($"Usunąć rekord Id: {completeDatabaseModelCurrentItem?.Id} z bazy danych?", "Potwierdź operację!", MessageBoxButton.OKCancel);
                    if (result == MessageBoxResult.OK)
                    {
                        _mainWindow.Opacity   = 50;
                        _mainWindow.IsEnabled = false;
                        Task task = Task.Run(async() =>
                        {
                            return(await StudentsRepository.GetInstance().DeleteAsync(completeDatabaseModelCurrentItem));
                        });
                        task.GetAwaiter().OnCompleted(() =>
                        {
                            base.Delete();
                            MessageBox.Show($"Usunięto rekord Id: {completeDatabaseModelCurrentItem?.Id} z bazy danych.", "Operacja zakończona");
                            _mainWindow.Opacity   = 100;
                            _mainWindow.IsEnabled = true;
                        });
                    }
                }
            }
        }
        protected override void CommitEdit()
        {
            var completeDatabaseModelCurrentItem = (Students)DataForm.CurrentItem;

            if (null != completeDatabaseModelCurrentItem)
            {
                if (DataForm != null && DataForm.ValidateItem())
                {
                    MessageBoxResult result = MessageBox.Show($"Zapisać dane rekordu Id: {completeDatabaseModelCurrentItem?.Id} do bazy danych?", "Potwierdź operację!", MessageBoxButton.OKCancel);
                    if (result == MessageBoxResult.OK)
                    {
                        _mainWindow.Opacity   = 50;
                        _mainWindow.IsEnabled = false;
                        var task = Task.Run(async() =>
                        {
                            completeDatabaseModelCurrentItem = completeDatabaseModelCurrentItem.Id.ToString() == "00000000-0000-0000-0000-000000000000"
                                ? await StudentsRepository.GetInstance().AddAsync(completeDatabaseModelCurrentItem)
                                : await StudentsRepository.GetInstance().SaveAsync(completeDatabaseModelCurrentItem);
                        });
                        task.GetAwaiter().OnCompleted(() =>
                        {
                            base.CommitEdit();
                            MessageBox.Show($"Zapisano dane rekordu Id: {completeDatabaseModelCurrentItem?.Id} do bazy danych.", "Operacja zakończona");
                            _mainWindow.Opacity   = 100;
                            _mainWindow.IsEnabled = true;
                        });
                    }
                }
            }
        }
Example #4
0
 protected override void CommitEdit()
 {
     if (DataForm != null && DataForm.ValidateItem())
     {
         if (commitEditOp(DataForm.CurrentItem))
         {
             DataForm.CommitEdit();
             (DataForm.ParentOfType <RadWindow>()).DialogResult = true;
             (DataForm.ParentOfType <RadWindow>()).Close();
         }
     }
 }
Example #5
0
        /// <summary>
        /// Returns whether or not a DependencyObject has errors.
        /// </summary>
        /// <param name="element">The element to test.</param>
        /// <returns>Whether or not it has errors.</returns>
        public static bool ElementHasErrors(DependencyObject element)
        {
            if (element == null)
            {
                return(false);
            }

            if (Validation.GetHasError(element))
            {
                return(true);
            }
            else
            {
                int childrenCount = VisualTreeHelper.GetChildrenCount(element);

                for (int i = 0; i < childrenCount; i++)
                {
                    DependencyObject childElement = VisualTreeHelper.GetChild(element, i);

                    DataForm childDataForm = childElement as DataForm;

                    // If we've found a child DataForm, validate it instead of continuing.
                    if (childDataForm != null)
                    {
                        childDataForm.ValidateItem();

                        if (!childDataForm.IsItemValid)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (ElementHasErrors(childElement))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
        }
Example #6
0
        protected override void CommitEdit()
        {
            var appSettingsCurrentItem = (AppSettings)DataForm.CurrentItem;

            if (null != appSettingsCurrentItem)
            {
                if (appSettingsCurrentItem.CheckForUpdateAndMigrate)
                {
                    _mainWindow.Opacity   = 50;
                    _mainWindow.IsEnabled = false;
                    var message = new StringBuilder();
                    var task    = Task.Run(() =>
                    {
                        var erpSerwisDbContext = new Core.Data.ErpSerwisDbContext();
                        var isCheckForUpdateAndCreateMssqlMdf = erpSerwisDbContext.CheckForUpdateAndCreateMssqlMdf(appSettingsCurrentItem);
                        var isCheckForUpdateAndMigrate        = erpSerwisDbContext.CheckForUpdateAndMigrate(appSettingsCurrentItem);
                        if (isCheckForUpdateAndCreateMssqlMdf)
                        {
                            message.Append($"Sprawdziłem i utworzyłem bazę danych w formacie Ms SQL MDF w dniu: { appSettingsCurrentItem.LastMigrateDateTime }").Append(Environment.NewLine);
                        }
                        else
                        {
                            message.Append($"Błąd tworzenia bazy danych w formacie Ms SQL MDF!").Append(Environment.NewLine);
                        }
                        if (isCheckForUpdateAndMigrate)
                        {
                            message.Append($"Sprawdziłem i przeprowadziłem migrację w dniu: { appSettingsCurrentItem.LastMigrateDateTime }").Append(Environment.NewLine);
                        }
                        else
                        {
                            message.Append($"Błąd migracji bazy danych!").Append(Environment.NewLine);
                        }
                    });
                    task.GetAwaiter().OnCompleted(() =>
                    {
                        MessageBox.Show(message.ToString(), "Status operacji");
                        _mainWindow.Opacity   = 100;
                        _mainWindow.IsEnabled = true;
                    });
                }
                if (DataForm != null && DataForm.ValidateItem())
                {
                    var saveResult = false;
                    _mainWindow.Opacity   = 50;
                    _mainWindow.IsEnabled = false;
                    Task task = Task.Run(async() =>
                    {
                        saveResult = await AppSettingsRepository.GetInstance().SaveAsync(appSettingsCurrentItem);
                        return(saveResult);
                    });
                    task.GetAwaiter().OnCompleted(() =>
                    {
                        if (saveResult)
                        {
                            MessageBox.Show($"Zapisano ustawienia w lokalizacji { appSettingsCurrentItem.GetFilePath() }", "Operacja zakończona.");
                        }
                        else
                        {
                            MessageBox.Show($"Nie można zapisać ustawień w lokalizacji { appSettingsCurrentItem.GetFilePath() }!", "Błąd!");
                        }
                        _mainWindow.Opacity   = 100;
                        _mainWindow.IsEnabled = true;
                    });
                }
            }
        }