示例#1
0
 private void ReloadEditor()
 {
     if (Transaction == null)
     {
         Name            = "New transaction";
         Description     = string.Empty;
         TransactionType = TransactionTypeOptions.FirstOrDefault();
         Customer        = CustomerOptions.FirstOrDefault();
         Date            = DateTime.Now;
         Value           = 0M;
     }
     else
     {
         Name            = Transaction.Name;
         Description     = Transaction.Description;
         TransactionType = TransactionTypeOptions.Where(tt => tt != null && tt.Id == Transaction.TransactionTypeId).FirstOrDefault();
         if (TransactionType == null)
         {
             TransactionType = TransactionTypeOptions.FirstOrDefault();
         }
         Customer = CustomerOptions.Where(c => c != null && c.Id == Transaction.CustomerId).FirstOrDefault();
         if (Customer == null)
         {
             Customer = CustomerOptions.FirstOrDefault();
         }
         Date  = Transaction.Date;
         Value = Transaction.Value;
     }
     isTransactionTypeBoxDirty = false;
 }
示例#2
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;
            }
        }