Exemplo n.º 1
0
        static public void notifyOne(int userID)
        {
            Boolean notifyGoals;
            Boolean notifyBudgets;

            DataAbstract DA = new DataAbstract();

            notifyBudgets = Convert.ToBoolean(DA.returnUser(userID).Tables[0].Rows[0].Field <object>("GoalsNotifications"));
            notifyGoals   = Convert.ToBoolean(DA.returnUser(userID).Tables[0].Rows[0].Field <object>("BudgetsNotifications"));
            DataTable accounts = DA.returnAccounts(userID).Tables[0];
            string    emailMsg = "Report on your financial status \n";

            for (int i = 0; i < accounts.Rows.Count; ++i) //iterate through all accounts of the user
            {
                long accountNum = Convert.ToInt64(accounts.Rows[i].Field <object>("AcctNumber"));


                //Section for proceessing Goal portion of email
                if (notifyGoals)
                {
                    //emailMsg += getGoalText(accountNum);
                }//end of goals section
                //Section for processing Budget section of email
                if (notifyBudgets)
                {
                    DataTable budgets = DA.returnBudgets(accountNum).Tables[0];
                    emailMsg += "\n\nYour current Budget Updates \n";
                    for (int j = 0; j < budgets.Rows.Count; ++j)
                    {
                        DataRow b = budgets.Rows[j];
                        int     notificationCount = Convert.ToInt32(b.Field <object>("NotificationCount"));
                        int     budgetID          = Convert.ToInt32(b.Field <object>("BudgetID"));

                        string categoryName = DA.returnCategoryName(Convert.ToInt32(b.Field <object>("CategoryID")));
                        double currentAmt   = Convert.ToDouble(b.Field <object>("CurrentAmt"));
                        double maxAmt       = Convert.ToDouble(b.Field <object>("MaxAmt"));
                        double percent      = currentAmt / maxAmt;

                        Notifications N = new Notifications();
                        int           notificationCountUpdate = N.Check("budget", percent * 100);

                        if (notificationCountUpdate > notificationCount)
                        {
                            DA.updateNotificationBudgets(budgetID, notificationCountUpdate);
                            string budgetString = categoryName + " has reached " + (percent * 100).ToString("N0") + "%\n";
                            emailMsg += budgetString;
                        }
                    }//end of budgets
                }
                string[]      m    = emailMsg.Trim().Split();
                Notifications Note = new Notifications();
                Note.sendEmail(emailMsg, accountNum.ToString());
            }//end of specific account
        }