Exemplo n.º 1
0
        /// <summary>
        /// runs the procedure for saving a cash flow
        /// returns a boolean to indicate if the flow was saved successfully or not.
        /// </summary>
        /// <returns></returns>
        private bool saveCashFlow()
        {
            if (isFormCashFlowValid())
            {
                cashFlow flowToSave = getCashFlowFromForm();

                if (loadedFlow == null)
                {
                    common.addCashFlowToProfile(loadedProfile, flowToSave);
                    loadCashFlowIntoForm(flowToSave);
                }
                else
                {
                    common.updateCashFlowOnAccount(loadedProfile, loadedFlow, flowToSave);
                    loadCashFlowIntoForm(flowToSave);
                }
                tsslFlowStatus.Text = "Flow Saved: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();
                return(true);
            }
            else
            {
                using (frmMessageBox messageBox = new frmMessageBox())
                {
                    common.setFormFontSize(messageBox, common.getMainForm().loadedFontSize);
                    common.getMainForm().loadedTheme.themeForm(messageBox);
                    messageBox.show("Unable to save current flow!\r\n" +
                                    "Please make sure all fields are properly filled out.",
                                    "Error Saving Cash Flow", MessageBoxButtons.OK);
                }
                return(false);
            }
        }
Exemplo n.º 2
0
    /// <summary>
    /// Replaces an item in a list with a new item
    /// </summary>
    /// <param name="parentList"></param>
    /// <param name="itemToReplace"></param>
    /// <param name="newItem"></param>
    public static void replaceItemInList(List <cashFlow> parentList, cashFlow itemToReplace, cashFlow newItem)
    {
        int index = parentList.IndexOf(itemToReplace);

        if (index != -1)
        {
            parentList[index] = newItem;
        }
    }
Exemplo n.º 3
0
    public static void deleteCashFlowFromProfile(fundingProfile owningProfile, cashFlow flowToDelete)
    {
        owningProfile.cashFlows.Remove(flowToDelete);
        //Database stuff
        database.sqlStatement deleteSql = new database.sqlStatement();
        deleteSql.connectionString = database.getConnectString();

        deleteSql.query = "DELETE FROM bmw_cash_flow " +
                          "WHERE id = @id ";

        deleteSql.queryParameters.Add("@id", flowToDelete.id);

        database.executeNonQueryOnDatabase(deleteSql);
    }
Exemplo n.º 4
0
        public void testOverdueCashflows()
        {
            cashFlow testFlow = new cashFlow();

            testFlow.dueDate = DateTime.Now.AddDays(-1);
            Assert.IsTrue(testFlow.isOverDue());

            testFlow.dueDate = DateTime.Now.AddSeconds(-1);
            Assert.IsTrue(testFlow.isOverDue());

            testFlow.dueDate = DateTime.Now.AddDays(+1);
            Assert.IsFalse(testFlow.isOverDue());

            testFlow.dueDate = DateTime.Now.AddSeconds(+1);
            Assert.IsFalse(testFlow.isOverDue());
        }
Exemplo n.º 5
0
        public void loadCashFlowIntoForm(cashFlow flowToLoad)
        {
            this.loadedFlow = flowToLoad;

            this.txtCashFlowName.Text   = flowToLoad.name;
            this.txtCashFlowAmount.Text = flowToLoad.amount.ToString();
            this.txtCashFlowDate.Text   = flowToLoad.flowDate.ToShortDateString();
            if (flowToLoad.dueDate != null)
            {
                this.txtCashFlowDueDate.Text = ((DateTime)flowToLoad.dueDate).ToShortDateString();
            }
            else
            {
                this.txtCashFlowDueDate.Text = "";
            }
            this.cbCashFlowType.Text = flowToLoad.flowType.ToString();
        }
Exemplo n.º 6
0
        public void testGetAccountCashFlows()
        {
            userAccount    testAccount = new userAccount();
            fundingProfile testProfile = new fundingProfile();
            cashFlow       testFlow    = new cashFlow();

            fundingProfile testProfile2 = new fundingProfile();
            cashFlow       testFlow2    = new cashFlow();

            testFlow.name  = "Test Flow 1";
            testFlow2.name = "Test Flow 2";

            testProfile.cashFlows.Add(testFlow);
            testProfile2.cashFlows.Add(testFlow2);

            testAccount.profiles.Add(testProfile);
            testAccount.profiles.Add(testProfile2);

            Assert.IsTrue(testAccount.getAccountCashFlows().Contains(testFlow));
            Assert.IsTrue(testAccount.getAccountCashFlows().Contains(testFlow2));
        }
Exemplo n.º 7
0
        public void testDataWithinRange()
        {
            List <cashFlow> testFlows        = new List <cashFlow>();
            DateTime        targetLowerBound = new DateTime(2018, 2, 1);
            DateTime        targetUpperBound = new DateTime(2018, 2, 28);

            /* create the IN RANGE flows */
            cashFlow inRangeFlow1 = new cashFlow();
            cashFlow inRangeFlow2 = new cashFlow();
            cashFlow inRangeFlow3 = new cashFlow();

            inRangeFlow1.flowDate = new DateTime(2018, 2, 1);
            inRangeFlow2.flowDate = new DateTime(2018, 2, 22);
            inRangeFlow3.flowDate = new DateTime(2018, 2, 28);

            testFlows.Add(inRangeFlow1);
            testFlows.Add(inRangeFlow2);
            testFlows.Add(inRangeFlow3);

            /* create the OUT OF RANGE flows */
            cashFlow outOfRangeFlow1 = new cashFlow();
            cashFlow outOfRangeFlow2 = new cashFlow();

            outOfRangeFlow1.flowDate = new DateTime(2018, 1, 7);
            outOfRangeFlow1.flowDate = new DateTime(2018, 3, 22);

            testFlows.Add(outOfRangeFlow1);
            testFlows.Add(outOfRangeFlow2);

            /* run Tests against the flows */
            List <cashFlow> filteredSet = common.getCashFlowsWithinRange(testFlows, targetLowerBound, targetUpperBound);

            Assert.IsTrue(filteredSet.Contains(inRangeFlow1));
            Assert.IsTrue(filteredSet.Contains(inRangeFlow2));
            Assert.IsTrue(filteredSet.Contains(inRangeFlow3));

            Assert.IsFalse(filteredSet.Contains(outOfRangeFlow1));
            Assert.IsFalse(filteredSet.Contains(outOfRangeFlow2));
        }
Exemplo n.º 8
0
    public static void addCashFlowToProfile(fundingProfile profileToRecieveFlow, cashFlow flowToAdd)
    {
        profileToRecieveFlow.cashFlows.Add(flowToAdd);
        //Database stuff
        database.sqlStatement insertSql = new database.sqlStatement();
        insertSql.connectionString = database.getConnectString();

        insertSql.query = "INSERT INTO bmw_cash_flow " +
                          "(id,profile_id,flow_name,flow_type,amount,transaction_date,due_date) " +
                          "VALUES " +
                          "(@id,@profile_id,@flow_name,@flow_type,@amount,@transaction_date,@due_date) ";

        insertSql.queryParameters.Add("@id", flowToAdd.id);
        insertSql.queryParameters.Add("@profile_id", profileToRecieveFlow.id);
        insertSql.queryParameters.Add("@flow_name", flowToAdd.name);
        insertSql.queryParameters.Add("@flow_type", flowToAdd.flowType);
        insertSql.queryParameters.Add("@amount", flowToAdd.amount);
        insertSql.queryParameters.Add("@transaction_date", flowToAdd.flowDate);
        insertSql.queryParameters.Add("@due_date", flowToAdd.dueDate);

        database.executeNonQueryOnDatabase(insertSql);
    }
Exemplo n.º 9
0
    public static void updateCashFlowOnAccount(fundingProfile owningProfile, cashFlow oldFlow, cashFlow updatedFlow)
    {
        replaceItemInList(owningProfile.cashFlows, oldFlow, updatedFlow);
        //Database stuff
        database.sqlStatement updateSql = new database.sqlStatement();
        updateSql.connectionString = database.getConnectString();

        updateSql.query = "UPDATE bmw_cash_flow " +
                          "SET flow_name = @flow_name, " +
                          "flow_type = @flow_type, " +
                          "amount = @amount, " +
                          "transaction_date = @transaction_date, " +
                          "due_date = @due_date " +
                          "WHERE id = @id ";

        updateSql.queryParameters.Add("@id", oldFlow.id);
        updateSql.queryParameters.Add("@flow_name", updatedFlow.name);
        updateSql.queryParameters.Add("@flow_type", updatedFlow.flowType);
        updateSql.queryParameters.Add("@amount", updatedFlow.amount);
        updateSql.queryParameters.Add("@transaction_date", updatedFlow.flowDate);
        updateSql.queryParameters.Add("@due_date", updatedFlow.dueDate);

        database.executeNonQueryOnDatabase(updateSql);
    }