Ejemplo n.º 1
0
        /// <summary>Searches the list of transactions for specified criteria.</summary>
        /// <returns>Return true if any items match</returns>
        private bool SearchTransaction()
        {
            DateTime selectedDate = TransactionDate.SelectedDate != null?DateTimeHelper.Parse(TransactionDate.SelectedDate) : DateTime.MinValue;

            string  payee         = TxtPayee.Text.ToLower();
            string  majorCategory = CmbMajorCategory.SelectedIndex != -1 ? CmbMajorCategory.SelectedValue.ToString().ToLower() : "";
            string  minorCategory = CmbMinorCategory.SelectedIndex != -1 ? CmbMinorCategory.SelectedValue.ToString().ToLower() : "";
            string  memo          = TxtMemo.Text.ToLower();
            decimal outflow       = DecimalHelper.Parse(TxtOutflow.Text.ToLower());
            decimal inflow        = DecimalHelper.Parse(TxtInflow.Text.ToLower());
            string  account       = _selectedAccount.Name?.ToLower() ?? "";

            if (selectedDate != DateTime.MinValue)
            {
                _matchingTransactions = _matchingTransactions.Where(transaction => transaction.Date == selectedDate).ToList();
            }

            if (!string.IsNullOrWhiteSpace(payee))
            {
                _matchingTransactions = _matchingTransactions.Where(transaction => transaction.Payee.ToLower().Contains(payee)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(majorCategory))
            {
                _matchingTransactions = _matchingTransactions.Where(transaction => transaction.MajorCategory.ToLower() == majorCategory).ToList();
            }

            if (!string.IsNullOrWhiteSpace(minorCategory))
            {
                _matchingTransactions = _matchingTransactions.Where(transaction => transaction.MinorCategory.ToLower() == minorCategory).ToList();
            }

            if (!string.IsNullOrWhiteSpace(memo))
            {
                _matchingTransactions = _matchingTransactions.Where(transaction => transaction.Memo.ToLower().Contains(memo)).ToList();
            }

            if (outflow != 0M)
            {
                _matchingTransactions = _matchingTransactions.Where(transaction => transaction.Outflow == outflow).ToList();
            }

            if (inflow != 0M)
            {
                _matchingTransactions = _matchingTransactions.Where(transaction => transaction.Inflow == inflow).ToList();
            }

            if (!string.IsNullOrWhiteSpace(account))
            {
                _matchingTransactions = _matchingTransactions.Where(transaction => transaction.Account.ToLower() == account).ToList();
            }

            return(_matchingTransactions.Count > 0);
        }
Ejemplo n.º 2
0
        /// <summary>Attempts to add a Transaction to the database.</summary>
        /// <returns>Returns true if successfully added</returns>
        private async Task <bool> AddTransaction()
        {
            Transaction newTransaction = new Transaction(await AppState.GetNextTransactionsIndex(), DateTimeHelper.Parse(TransactionDate.SelectedDate),
                                                         TxtPayee.Text, CmbMajorCategory.SelectedValue.ToString(), CmbMinorCategory.SelectedValue.ToString(),
                                                         TxtMemo.Text, DecimalHelper.Parse(TxtOutflow.Text), DecimalHelper.Parse(TxtInflow.Text),
                                                         _selectedAccount.Name);

            _selectedAccount.AddTransaction(newTransaction);
            AppState.AllTransactions.Add(newTransaction);

            return(await AppState.AddTransaction(newTransaction, _selectedAccount));
        }
Ejemplo n.º 3
0
        /// <summary>Attempts to add a <see cref="FuelTransaction"/> to the database.</summary>
        /// <returns>Returns true if successfully added</returns>
        private async Task <bool> ModifyTransaction()
        {
            ModifiedTransaction = new FuelTransaction(UnmodifiedTransaction.TranscationID,
                                                      UnmodifiedTransaction.VehicleID, DateTimeHelper.Parse(TransactionDate.SelectedDate), TxtStore.Text,
                                                      Int32Helper.Parse(TxtOctane.Text), DecimalHelper.Parse(TxtDistance.Text),
                                                      DecimalHelper.Parse(TxtGallons.Text), DecimalHelper.Parse(TxtPrice.Text),
                                                      DecimalHelper.Parse(TxtOdometer.Text), Int32Helper.Parse(TxtRange.Text));

            if (await AppState.DatabaseInteraction.ModifyTransaction(UnmodifiedTransaction, ModifiedTransaction))
            {
                CurrentVehicle.ModifyTransaction(UnmodifiedTransaction, ModifiedTransaction);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>Calls conversion methods based on currently selected conversion type.</summary>
        private void Convert()
        {
            switch (EnumHelper.Parse <Types>(CmbConversionType.SelectedItem.ToString()))
            {
            case Types.Mass:
                TxtConvertTo.Text = TxtConvertFrom.Text.Length > 0 ? Math.Round(decimal.Multiply(DecimalHelper.Parse(TxtConvertFrom.Text), ConvertMass(EnumHelper.Parse <Mass>(CmbConvertFrom.SelectedItem.ToString()), EnumHelper.Parse <Mass>(CmbConvertTo.SelectedItem.ToString()))), 9, MidpointRounding.AwayFromZero).ToString() : "0";
                break;

            case Types.Volume:
                TxtConvertTo.Text = TxtConvertFrom.Text.Length > 0 ? Math.Round(decimal.Multiply(DecimalHelper.Parse(TxtConvertFrom.Text), ConvertVolume(EnumHelper.Parse <Volume>(CmbConvertFrom.SelectedItem.ToString().Replace(" ", "")), EnumHelper.Parse <Volume>(CmbConvertTo.SelectedItem.ToString().Replace(" ", "")))), 9, MidpointRounding.AwayFromZero).ToString() : "0";
                break;

            case Types.Distance:
                TxtConvertTo.Text = TxtConvertFrom.Text.Length > 0 ?
                                    Math.Round(decimal.Multiply(DecimalHelper.Parse(TxtConvertFrom.Text), ConvertDistance(EnumHelper.Parse <Distance>(CmbConvertFrom.SelectedItem.ToString()), EnumHelper.Parse <Distance>(CmbConvertTo.SelectedItem.ToString()))), 9, MidpointRounding.AwayFromZero).ToString() : "0";
                break;
            }
        }
Ejemplo n.º 5
0
 /// <summary>Saves a new <see cref="Class"/>.</summary>
 private bool Save()
 {
     if (CheckValidClass())
     {
         List <DayOfWeek> days = new List <DayOfWeek>();
         if (CheckValidCheckBox(ChkSunday))
         {
             days.Add(DayOfWeek.Sunday);
         }
         if (CheckValidCheckBox(ChkMonday))
         {
             days.Add(DayOfWeek.Monday);
         }
         if (CheckValidCheckBox(ChkTuesday))
         {
             days.Add(DayOfWeek.Tuesday);
         }
         if (CheckValidCheckBox(ChkWednesday))
         {
             days.Add(DayOfWeek.Wednesday);
         }
         if (CheckValidCheckBox(ChkThursday))
         {
             days.Add(DayOfWeek.Thursday);
         }
         if (CheckValidCheckBox(ChkFriday))
         {
             days.Add(DayOfWeek.Friday);
         }
         if (CheckValidCheckBox(ChkSaturday))
         {
             days.Add(DayOfWeek.Saturday);
         }
         School.NewClass(new SchoolClass(TxtID.Text.Trim().Trim(), _selectedTeacher.Id, new List <string>(), _selectedCourse, new List <decimal> {
             DecimalHelper.Parse(TxtDaily.Text.Trim()), DecimalHelper.Parse(TxtHomework.Text.Trim()), DecimalHelper.Parse(TxtProject.Text.Trim()), DecimalHelper.Parse(TxtQuiz.Text.Trim()), DecimalHelper.Parse(TxtReport.Text.Trim()), DecimalHelper.Parse(TxtTest.Text.Trim())
         }, new List <Assignment>(), days, DateTimeHelper.Parse(TxtStartTime.Text), DateTimeHelper.Parse(TxtEndTime.Text)));
         return(true);
     }
     TxtError.Visibility = Visibility.Visible;
     return(false);
 }
        /// <summary>Attempts to add a <see cref="FuelTransaction"/> to the database.</summary>
        /// <returns>Returns true if successfully added</returns>
        private async Task <bool> AddTransaction()
        {
            FuelTransaction newTransaction = new FuelTransaction(await AppState.DatabaseInteraction.GetNextTransactionIndex(),
                                                                 CurrentVehicle.VehicleID, DateTimeHelper.Parse(TransactionDate.SelectedDate), TxtStore.Text,
                                                                 Int32Helper.Parse(TxtOctane.Text), DecimalHelper.Parse(TxtDistance.Text),
                                                                 DecimalHelper.Parse(TxtGallons.Text), DecimalHelper.Parse(TxtPrice.Text),
                                                                 DecimalHelper.Parse(TxtOdometer.Text), Int32Helper.Parse(TxtRange.Text));

            // if the odometer or distance weren't both set, determine the distance/odometer so MPG/odometer will be calculated properly
            if (newTransaction.Distance <= 0M)
            {
                if (newTransaction.Odometer > 0M && CurrentVehicle.Transactions.Count > 0)
                {
                    newTransaction.Distance = newTransaction.Odometer - CurrentVehicle.Transactions[0].Odometer;
                }
                else if (newTransaction.Odometer >= 0M && CurrentVehicle.Transactions.Count == 0)
                {
                    newTransaction.Distance = newTransaction.Odometer;
                }
            }
            else if (newTransaction.Odometer <= 0M)
            {
                if (newTransaction.Distance > 0M && CurrentVehicle.Transactions.Count > 0)
                {
                    newTransaction.Odometer = CurrentVehicle.Transactions[0].Odometer + newTransaction.Distance;
                }
                else if (newTransaction.Distance > 0M && CurrentVehicle.Transactions.Count == 0)
                {
                    newTransaction.Odometer = newTransaction.Distance;
                }
            }

            if (!await AppState.DatabaseInteraction.NewTransaction(newTransaction))
            {
                return(false);
            }
            CurrentVehicle.AddTransaction(newTransaction);
            return(true);
        }
        /// <summary>Loads all <see cref="Account"/>s.</summary>
        /// <returns>Returns all <see cref="Account"/>s</returns>
        public async Task <List <Account> > LoadAccounts()
        {
            List <Account> allAccounts = new List <Account>();
            DataSet        ds          = await SQLiteHelper.FillDataSet(_con, "SELECT * FROM Accounts");

            if (ds.Tables[0].Rows.Count > 0)
            {
                allAccounts.AddRange(from DataRow dr in ds.Tables[0].Rows select new Account(dr["Name"].ToString(), EnumHelper.Parse <AccountTypes>(dr["Type"].ToString()), new List <FinancialTransaction>()));
            }

            ds = await SQLiteHelper.FillDataSet(_con, "SELECT * FROM FinancialTransactions");

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    Account selectedAccount = allAccounts.Find(account => account.Name == dr["Account"].ToString());

                    FinancialTransaction newTransaction = new FinancialTransaction(Int32Helper.Parse(dr["ID"]),
                                                                                   DateTimeHelper.Parse(dr["Date"]), dr["Payee"].ToString(), dr["MajorCategory"].ToString(),
                                                                                   dr["MinorCategory"].ToString(), dr["Memo"].ToString(), DecimalHelper.Parse(dr["Outflow"]),
                                                                                   DecimalHelper.Parse(dr["Inflow"]), selectedAccount.Name);
                    selectedAccount.AddTransaction(newTransaction);
                }
            }

            allAccounts = allAccounts.OrderBy(account => account.Name).ToList();
            if (allAccounts.Count > 0)
            {
                foreach (Account account in allAccounts)
                {
                    account.Sort();
                }
            }

            return(allAccounts);
        }
        private async void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            FinancialTransaction newTransaction = new FinancialTransaction(_modifyTransaction.ID,
                                                                           DateTimeHelper.Parse(TransactionDate.SelectedDate), TxtPayee.Text,
                                                                           CmbMajorCategory.SelectedItem.ToString(), CmbMinorCategory.SelectedItem.ToString(), TxtMemo.Text,
                                                                           DecimalHelper.Parse(TxtOutflow.Text), DecimalHelper.Parse(TxtInflow.Text), _selectedAccount.Name);

            if (newTransaction != _modifyTransaction)
            {
                if (newTransaction.Account != _modifyTransaction.Account)
                {
                    int index = _allAccounts.FindIndex(account => account.Name == _modifyTransaction.Account);
                    _allAccounts[index].ModifyTransaction(_allAccounts[index].AllTransactions.IndexOf(_modifyTransaction),
                                                          newTransaction);
                    index = _allAccounts.FindIndex(account => account.Name == newTransaction.Account);
                    _allAccounts[index].AddTransaction(newTransaction);
                }
                else
                {
                    int index = _allAccounts.FindIndex(account => account.Name == _selectedAccount.Name);
                    _allAccounts[index].ModifyTransaction(_allAccounts[index].AllTransactions.IndexOf(_modifyTransaction), newTransaction);
                }
                if (await AppState.ModifyFinancialTransaction(newTransaction, _modifyTransaction))
                {
                    ClosePage();
                }
                else
                {
                    AppState.DisplayNotification("Unable to modify transaction.", "Personal Tracker");
                }
            }
            else
            {
                AppState.DisplayNotification("This transaction has not been modified.", "Personal Tracker");
            }
        }
        /// <summary>Loads all <see cref="FuelTransaction"/>s associated with a specific <see cref="Vehicle"/.</summary>
        /// <param name="vehicleID"><see cref="Vehicle"/> ID</param>
        /// <returns>Returns all <see cref="FuelTransaction"/>s associated with a specific <see cref="Vehicle"/.</returns>
        public async Task <List <FuelTransaction> > LoadTransactions(int vehicleID)
        {
            SQLiteCommand cmd = new SQLiteCommand {
                CommandText = "SELECT * FROM Transactions WHERE VehicleID = @id"
            };

            cmd.Parameters.AddWithValue("@id", vehicleID);

            DataSet ds = await SQLiteHelper.FillDataSet(_con, cmd);

            List <FuelTransaction> transactions = new List <FuelTransaction>();

            if (ds.Tables[0].Rows.Count > 0)
            {
                transactions.AddRange(from DataRow dr in ds.Tables[0].Rows select new FuelTransaction(Int32Helper.Parse(dr["TransactionID"]), Int32Helper.Parse(dr["VehicleID"]), DateTimeHelper.Parse(dr["Date"]), dr["Store"].ToString(), Int32Helper.Parse(dr["Octane"]), DecimalHelper.Parse(dr["Distance"]), DecimalHelper.Parse(dr["Gallons"]), DecimalHelper.Parse(dr["Price"]), DecimalHelper.Parse(dr["Odometer"]), Int32Helper.Parse(dr["Range"])));
                transactions = transactions.OrderByDescending(transaction => transaction.Date).ToList();
            }

            return(transactions);
        }
Ejemplo n.º 10
0
        /// <summary>Adds a transfer to the database.</summary>
        /// <returns>True if successful</returns>
        private async Task <bool> AddTransfer()
        {
            FinancialTransaction transferFrom = new FinancialTransaction(await AppState.GetNextFinancialTransactionIndex(), DateTimeHelper.Parse(TransferDate.SelectedDate), "Transfer", "Transfer", "Transfer", _transferToAccount.Name, DecimalHelper.Parse(TxtTransferAmount.Text), 0.00M, _transferFromAccount.Name);

            _transferFromAccount.AddTransaction(transferFrom);
            FinancialTransaction transferTo = new FinancialTransaction(await AppState.GetNextFinancialTransactionIndex() + 1, DateTimeHelper.Parse(TransferDate.SelectedDate), "Transfer", "Transfer", "Transfer", _transferFromAccount.Name, 0.00M, DecimalHelper.Parse(TxtTransferAmount.Text), _transferToAccount.Name);

            _transferToAccount.AddTransaction(transferTo);
            if (await AppState.AddFinancialTransaction(transferFrom, _transferFromAccount))
            {
                if (await AppState.AddFinancialTransaction(transferTo, _transferToAccount))
                {
                    return(true);
                }
            }
            return(false);
        }
 /// <summary>Saves the current series.</summary>
 private async Task Save()
 {
     Series newSeries = new Series(TxtName.Text.Trim(), DateTimeHelper.Parse(DatePremiere.SelectedDate), DecimalHelper.Parse(TxtRating.Text.Trim()), Int32Helper.Parse(TxtSeasons.Text.Trim()), Int32Helper.Parse(TxtEpisodes.Text.Trim()), (SeriesStatus)CmbStatus.SelectedIndex, TxtChannel.Text.Trim(), DateTimeHelper.Parse(DateFinale.SelectedDate), CmbDay.SelectedIndex >= 0 ? (DayOfWeek)CmbDay.SelectedIndex : DayOfWeek.Sunday, DateTimeHelper.Parse(TxtTime.Text.Trim()), TxtReturnDate.Text.Trim());
     await AppState.ModifySeries(SelectedSeries, newSeries);
 }
 /// <summary>Checks whether the Save buttons should be enabled.</summary>
 private void CheckButton() => BtnSave.IsEnabled = TxtName.Text.Length > 0 && DatePremiere.Text.Length > 0 && TxtRating.Text.Length > 0 && TxtSeasons.Text.Length > 0 && TxtEpisodes.Text.Length > 0 && CmbStatus.SelectedIndex >= 0 && (TxtName.Text != SelectedSeries.Name || DatePremiere.Text != SelectedSeries.PremiereDateToString || DecimalHelper.Parse(TxtRating.Text) != SelectedSeries.Rating || Int32Helper.Parse(TxtSeasons.Text) != SelectedSeries.Seasons || Int32Helper.Parse(TxtEpisodes.Text) != SelectedSeries.Episodes || (SeriesStatus)CmbStatus.SelectedIndex != SelectedSeries.Status);
Ejemplo n.º 13
0
 private async void BtnSubmit_Click(object sender, RoutedEventArgs e)
 {
     if (AppState.AllAccounts.All(account => account.Name != TxtAccountName.Text))
     {
         Enum.TryParse(CmbAccountTypes.SelectedValue.ToString().Replace(" ", ""), out AccountTypes currentType);
         Account newAccount = new Account(TxtAccountName.Text, currentType, new List <FinancialTransaction>());
         FinancialTransaction newTransaction = new FinancialTransaction(await AppState.GetNextFinancialTransactionIndex(), DateTime.Now,
                                                                        "Income", "Income", "Starting Balance", "", 0.00M, DecimalHelper.Parse(TxtBalance.Text),
                                                                        newAccount.Name);
         newAccount.AddTransaction(newTransaction);
         if (await AppState.AddAccount(newAccount))
         {
             if (await AppState.AddFinancialTransaction(newTransaction, newAccount))
             {
                 ClosePage();
             }
             else
             {
                 AppState.DisplayNotification("Unable to process new account.", "Personal Tracker");
             }
         }
     }
     else
     {
         AppState.DisplayNotification("That account name already exists.", "Personal Tracker");
     }
 }
Ejemplo n.º 14
0
 /// <summary>Saves a new <see cref="Course"/>.</summary>
 private void Save() => School.NewCourse(new Course(TxtNumber.Text.Trim(), TxtName.Text.Trim(), DecimalHelper.Parse(TxtHours.Text)));
        /// <summary>Loads all <see cref="Book"/>s from the database.</summary>
        /// <returns>All <see cref="Book"/>s</returns>
        public async Task <List <Book> > LoadBooks()
        {
            List <Book> allBooks = new List <Book>();
            DataSet     ds       = await SQLiteHelper.FillDataSet(_con, "SELECT * FROM Books");

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    allBooks.Add(new Book(dr["Name"].ToString(), dr["Author"].ToString(), dr["Series"].ToString(), DecimalHelper.Parse(dr["Number"]), DecimalHelper.Parse(dr["Rating"]), Int32Helper.Parse(dr["Year"])));
                }
            }

            return(allBooks);
        }
        /// <summary>Loads all <see cref="Television"/> from the database.</summary>
        /// <returns>All <see cref="Television"/></returns>
        public async Task <List <Series> > LoadSeries()
        {
            List <Series> allTelevision = new List <Series>();
            DataSet       ds            = await SQLiteHelper.FillDataSet(_con, "SELECT * FROM Television");

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    allTelevision.Add(new Series(dr["Name"].ToString(), DateTimeHelper.Parse(dr["PremiereDate"]), DecimalHelper.Parse(dr["Rating"]), Int32Helper.Parse(dr["Seasons"]), Int32Helper.Parse(dr["Episodes"]), (SeriesStatus)Int32Helper.Parse(dr["Status"]), dr["Channel"].ToString(), DateTimeHelper.Parse(dr["FinaleDate"]), (DayOfWeek)Int32Helper.Parse(dr["Day"]), DateTimeHelper.Parse(dr["Time"]), dr["ReturnDate"].ToString()));
                }
            }

            return(allTelevision);
        }