private async void Delete()
        {
            AllowInput = false;

            try
            {
                IDatabaseService dbconn = new DatabaseService();
                dbconn.ConnectionString = ConnectionStringsProvider.Get();
                await dbconn.TransactionTypeService.DeleteAsync(TransactionType.Id);

                var transactionTypesRaw = await dbconn.TransactionTypeService.GetTransactionTypesAsync();

                TransactionTypes = new ObservableCollection <ITransactionType>(transactionTypesRaw);
                TransactionType  = null;
                ReloadEditor();
            }
            catch (SqlException e) when(e.ToString().Contains("REFERENCE") && e.ToString().Contains("FK_"))
            {
                MessageBox.Show("Selected Transaction Type cannot be deleted.\n\nThere are either Transactions or Customers that refer to it.", "Database constraint notice", MessageBoxButton.OK, MessageBoxImage.Hand);
            }
            catch (SqlException e)
            {
                MessageBox.Show("Unexpected SQL error occurred while deleting entry in database. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception)
            {
                MessageBox.Show("Unexpected error occurred while deleting entry in database", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                AllowInput = true;
            }
        }
        protected async override void OnLoad(object param)
        {
            try
            {
                IDatabaseService dbconn = new DatabaseService();
                dbconn.ConnectionString = ConnectionStringsProvider.Get();

                var transactionTypesRaw = await dbconn.TransactionTypeService.GetTransactionTypesAsync();

                TransactionTypes = new ObservableCollection <ITransactionType>(transactionTypesRaw);

                ReloadEditor();
                base.OnLoad(param);
            }
            catch (SqlException e)
            {
                MessageBox.Show("Unexpected SQL error occurred while accessing database. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception)
            {
                MessageBox.Show("Unexpected error occurred while accessing database", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                AllowInput = true;
            }
        }
Example #3
0
        private async void Delete()
        {
            AllowInput = false;

            try
            {
                IDatabaseService dbconn = new DatabaseService();
                dbconn.ConnectionString = ConnectionStringsProvider.Get();

                await dbconn.TransactionService.DeleteAsync(Transaction.Id);

                var transactionsRaw = await dbconn.TransactionService.GetTransactionsAsync();

                Transactions = new ObservableCollection <ITransaction>(transactionsRaw);

                Transaction = null;

                ReloadEditor();
            }
            catch (SqlException e)
            {
                MessageBox.Show("Unexpected SQL error occurred while deleting entry in database. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception)
            {
                MessageBox.Show("Unexpected error occurred while deleting entry in database", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                AllowInput = true;
            }
        }
        private async void Import()
        {
            AllowInput = false;

            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter     = "JSON|*.json";
                ofd.DefaultExt = "json";

                if (ofd.ShowDialog() == true && ofd.CheckFileExists && ofd.CheckPathExists)
                {
                    var imported = FileExporter.FileExporter.ImportTransactionType(ofd.FileName);

                    IDatabaseService dbconn = new DatabaseService();
                    dbconn.ConnectionString = ConnectionStringsProvider.Get();

                    foreach (var entry in imported)
                    {
                        if (!TransactionTypes.Any(c => c.Name == entry.Name))
                        {
                            entry.Id = 0;
                            await dbconn.TransactionTypeService.SaveAsync(entry);
                        }
                    }

                    var transactionTypesRaw = await dbconn.TransactionTypeService.GetTransactionTypesAsync();

                    TransactionTypes = new ObservableCollection <ITransactionType>(transactionTypesRaw);

                    TransactionType = null;

                    ReloadEditor();
                }
            }
            catch (FileFormatException e)
            {
                MessageBox.Show("Invalid file format loaded. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (IOException e)
            {
                MessageBox.Show("Unexpected error occurred while loading JSON file. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (SqlException e)
            {
                MessageBox.Show("Unexpected SQL error occurred while saving imported entry in database. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception)
            {
                MessageBox.Show("Unexpected error occurred while importing", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                AllowInput = true;
            }
        }
Example #5
0
        protected async override void OnLoad(object param)
        {
            AllowInput = false;

            try
            {
                IDatabaseService dbconn = new DatabaseService();
                dbconn.ConnectionString = ConnectionStringsProvider.Get();

                TransactionTypeOptions = await dbconn.TransactionTypeService.GetTransactionTypesAsync();

                CustomerOptions = await dbconn.CustomerService.GetCustomersAsync();

                var transactionsRaw = await dbconn.TransactionService.GetTransactionsAsync();

                Transactions = new ObservableCollection <ITransaction>(transactionsRaw);

                ReloadEditor();

                RaisePropertyChanged("TransactionTypeOptions");
                RaisePropertyChanged("CustomerOptions");

                TransactionType       = TransactionTypeOptions.FirstOrDefault();
                FilterTransactionType = TransactionTypeOptions.FirstOrDefault();
                Customer       = CustomerOptions.FirstOrDefault();
                FilterCustomer = CustomerOptions.FirstOrDefault();

                base.OnLoad(param);
            }
            catch (SqlException e)
            {
                MessageBox.Show("Unexpected SQL error occurred while accessing database. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception)
            {
                MessageBox.Show("Unexpected error occurred while accessing database", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                AllowInput = true;
            }
        }
Example #6
0
        private async void Save()
        {
            AllowInput = false;

            try
            {
                IDatabaseService dbconn = new DatabaseService();
                dbconn.ConnectionString = ConnectionStringsProvider.Get();

                int newId = await dbconn.TransactionService.SaveAsync(new Transaction()
                {
                    Id                = Transaction == null ? 0 : Transaction.Id,
                    Name              = this.Name,
                    Description       = this.Description,
                    TransactionTypeId = TransactionType.Id,
                    CustomerId        = Customer.Id == 0 ? null : (int?)Customer.Id,
                    Date              = this.Date,
                    Value             = this.Value
                });

                var transactionsRaw = await dbconn.TransactionService.GetTransactionsAsync();

                Transactions = new ObservableCollection <ITransaction>(transactionsRaw);

                Transaction = null;

                ReloadEditor();
            }
            catch (SqlException e)
            {
                MessageBox.Show("Unexpected SQL error occurred while saving entry in database. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception)
            {
                MessageBox.Show("Unexpected error occurred while saving entry in database", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                AllowInput = true;
            }
        }
Example #7
0
        protected async override void OnLoad(object param)
        {
            AllowInput = false;

            try
            {
                //BcDrawer = bcdFactory.CreateForTransactions(param as Grid);
                ReloadTimeStepOptions();
                TimeStep = CurrentTimeStepOptions.FirstOrDefault();

                IDatabaseService dbconn = new DatabaseService();
                dbconn.ConnectionString = ConnectionStringsProvider.Get();

                CustomerOptions = await dbconn.CustomerService.GetCustomersAsync();

                data = await dbconn.TransactionService.GetTransactionsAsync();

                RaisePropertyChanged("CustomerOptions");

                FilterCustomer = CustomerOptions.FirstOrDefault();
                IsIncome       = false;

                ReloadBarChart();
                ReloadPieChart();

                base.OnLoad(param);
            }
            catch (SqlException e)
            {
                MessageBox.Show("Unexpected SQL error occurred while accessing database. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception)
            {
                MessageBox.Show("Unexpected error occurred while accessing database", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                AllowInput = true;
            }
        }
Example #8
0
        private async void Save()
        {
            AllowInput = false;

            try
            {
                IDatabaseService dbconn = new DatabaseService();
                dbconn.ConnectionString = ConnectionStringsProvider.Get();

                int newId = await dbconn.CustomerService.SaveAsync(new Customer()
                {
                    Id          = Customer == null ? 0 : Customer.Id,
                    Name        = this.Name,
                    Description = this.Description,
                    DefaultTransactionTypeId = Dtt.Id == 0 ? null : (int?)Dtt.Id,
                    Active = this.Active
                });

                var customersRaw = await dbconn.CustomerService.GetCustomersAsync();

                Customers = new ObservableCollection <ICustomer>(customersRaw);

                Customer = null;

                ReloadEditor();
            }
            catch (SqlException e)
            {
                MessageBox.Show("Unexpected SQL error occurred while saving entry in database. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception)
            {
                MessageBox.Show("Unexpected error occurred while saving entry in database", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                AllowInput = true;
            }
        }