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;
            }
        }
        public async Task <SqlQueryRunner.RunQueryResults> RunQuery([FromBody] RunQueryParams param)
        {
            var cs    = ConnectionStringsProvider.GetById(param.conn_string_id);
            var query = await SqlQueryRunner.RunQuery(cs, param.query_text, param.slow);

            return(query);
        }
        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;
            }
        }
Exemple #4
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;
            }
        }
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            Configuration             = builder.Build();
            ConnectionStringsProvider = new ConnectionStringsProvider(Configuration, env.ContentRootPath);
        }
        public async Task <Table[]> GetConnectionStrings([FromUri] string conn_string_id)
        {
            var query = @"
					SELECT '['  +TABLE_CATALOG + '].['  + TABLE_SCHEMA + '].[' + TABLE_NAME + ']' as table_name, '[' + COLUMN_NAME + ']' as name, DATA_TYPE as type
					FROM INFORMATION_SCHEMA.COLUMNS
					ORDER BY table_name
			"            ;
            var cs    = ConnectionStringsProvider.GetById(conn_string_id).value;

            return((await Utils.GetDictsFromQuery(query, cs))
                   .GroupBy(x => x["table_name"] as string)
                   .Select(x => new Table
            {
                name = x.Key,
                fields = x.Select(f => f.ToObject <Table.Field>()).ToArray()
            })
                   .ToArray());
        }
Exemple #8
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;
            }
        }
Exemple #9
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;
            }
        }
        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;
            }
        }
Exemple #11
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;
            }
        }
 public AppConfigProvider()
 {
     ConnectionStrings = new ConnectionStringsProvider();
     AppSettings       = new AppSettingsProvider();
 }