示例#1
0
 //---------------------------------------------------------------------
 // Loads the transactions into transaction history
 //---------------------------------------------------------------------
 public void loadTransactions()
 {
     lbTransactionHistory.Items.Clear();
     dt = database.getTransactionHistory(currentUser.getPrimaryKey());
     foreach (DataRow dataRow in dt.Rows)
     {
         transaction = new Transaction(dataRow["Description"].ToString(),
                                       Int32.Parse(dataRow["Amount"].ToString()),
                                       null,
                                       dataRow["Date"].ToString(),
                                       dataRow["Time"].ToString(),
                                       Int32.Parse(dataRow["TransactionNumber"].ToString()),
                                       false,
                                       0);
         if (dataRow["Category"].ToString() != "null")
         {
             Category temp = categories.getCategory(categories.getIndex(dataRow["Category"].ToString()));
             transaction.setCategory(temp);
         }
         if (dataRow["Auto"].ToString() == "True")
         {
             transaction.setAuto(true);
             transaction.setFreq(Int32.Parse(dataRow["Frequency"].ToString()));
             autoList.add(transaction);
         }
         recentHistory.AddTransaction(transaction);
         InsertTransaction(NULLCATEGORY);
     }
 }
示例#2
0
        //---------------------------------------------------------------------
        // Checks if there was an error with the information entered in
        // if not Creates the new Transaction
        // if so displays a relevent error message
        // params: (in object, in EventArgs)
        //---------------------------------------------------------------------
        private void CreateButt_Click_1(object sender, EventArgs e)
        {
            Category    category    = null;
            Transaction trans       = transHistory.getLastTransaction();
            int         transnumber = 0;    // set for the frist transaction

            //setting the transaction number for the transaction if there was a previous transaction
            if (trans != null)
            {
                transnumber = transHistory.getTransactionCount();
            }
            Date d = new Date();

            //if expense and addition or checked. ERROR.
            if (cbExpense.Checked && cbRevenue.Checked)
            {
                lblError.Show();
            }
            else if (AutoCheck.Checked == true && FreqCB.Text == " ")
            {
                AutomaticError.Visible = true;
            }
            else if (d.toDate(DateTimePicker.Value.ToShortDateString()).isBefore(currentDate))
            {
                DateErr.Visible = true;
            }

            //if revenue is checked or expense is checked and category is not selected. NOTE: can not have a revenue in a category
            else if (cbRevenue.Checked || (cbExpense.Checked && CatePicker.Text == ""))
            {
                int auto;
                if (AutoCheck.Checked == false)
                {
                    auto = 0;
                }
                else
                {
                    string tbString  = FreqCB.Text;
                    string frequency = tbString.Substring(0, 1);
                    auto = Int32.Parse(frequency);
                    if (auto == YEARLYINDEX)
                    {
                        auto = YEAR;
                    }
                    else if (auto == SIXMONTHSINDEX)
                    {
                        auto = SIXMONTHS;
                    }
                    else if (auto == MONTHLYINDEX)
                    {
                        auto = MONTH;
                    }
                    else if (auto == BIWEEKLYINDEX)
                    {
                        auto = BIWEEKLY;
                    }
                    else if (auto == WEEKLYINDEX)
                    {
                        auto = WEEKLY;
                    }
                }

                if (cbRevenue.Checked)
                {
                    newTransaction = new Transaction(DescTB.Text,
                                                     ADDITION * Double.Parse(PriceTB.Text),
                                                     null,
                                                     DateTimePicker.Value.ToShortDateString(), DateTimePicker.Value.ToShortTimeString(), transnumber, AutoCheck.Checked, auto);
                }
                else
                {
                    newTransaction = new Transaction(DescTB.Text,
                                                     Double.Parse(PriceTB.Text),
                                                     null,
                                                     DateTimePicker.Value.ToShortDateString(), DateTimePicker.Value.ToShortTimeString(), transnumber, AutoCheck.Checked, auto);
                }

                if (AutoCheck.Checked == true)
                {
                    AutoList.add(newTransaction);
                    currentUser.changeBalance();
                }

                commandHandler.addTransaction(newTransaction, primaryKey);
                this.ReturnData = newTransaction;
                this.Visible    = false;
            }

            //if expense is checked
            else if (cbExpense.Checked)
            {
                int auto;
                if (AutoCheck.Checked == false)
                {
                    auto = 0;
                }
                else
                {
                    string tbString  = FreqCB.Text;
                    string frequency = tbString.Substring(0, 1);
                    auto = Int32.Parse(frequency);
                }

                category = Cate.getCategory(Cate.getIndex(CatePicker.Text));

                newTransaction = new Transaction(DescTB.Text,
                                                 Double.Parse(PriceTB.Text),
                                                 category, DateTimePicker.Value.ToShortDateString(),
                                                 DateTimePicker.Value.ToShortTimeString(), transnumber, AutoCheck.Checked, auto);

                if (AutoCheck.Checked == true)
                {
                    AutoList.add(newTransaction);

                    currentUser.changeBalance();
                }

                AutoList.add(newTransaction);

                updateCategoryOnNewTransaction(newTransaction, category, primaryKey);

                this.ReturnData = newTransaction;
                this.Visible    = false;
            }
        }