Ejemplo n.º 1
0
        protected bool CategoryMe(TranSaction s)
        {
            bool bReturn = false;

            if (s != null)
            {
                foreach (var element in MyFilterXML)
                {
                    if ((s.Description.ToLower().IndexOf(element.Value.ToLower()) != -1) && s.Description.Length > 0)
                    {
                        s.myFilter   = element.Value;
                        s.myCategory = element.Key;
                        if (modifiedTransactions != null)
                        {
                            modifiedTransactions.Add(s);
                            myTransactions.Remove(s);
                        }
                        else
                        {
                            modifiedTransactions = new TranSactionS();
                            modifiedTransactions.Add(s);
                            myTransactions.Remove(s);
                        }
                        bReturn = true;
                    }
                }
            }
            else
            {
                myLogging.LogError("Transaction is NULL.", "Error");
                bReturn = false;
            }

            return(bReturn);
        }
Ejemplo n.º 2
0
        protected void bttnSubmitFilter_Click(object sender, EventArgs e)
        {
            if (Session["currentTransaction"] != null)
            {
                currentTransaction = (TranSaction)Session["currentTransaction"];

                if (lblTransactionDescription.Text.IndexOf(txtFilter.Text) != -1)
                {
                    //look at our updated MyFilterXML to see if there an existing filter
                    if (!CategoryMe(currentTransaction))
                    {
                        MyFilterXML.Add(new KeyValuePair <string, string>(RadioButtonList1.SelectedItem.Text, txtFilter.Text.Trim()));
                        Session["XMLFilter"] = MyFilterXML;

                        currentTransaction.myCategory = RadioButtonList1.SelectedValue.ToString();
                        currentTransaction.myFilter   = txtFilter.Text.Trim();

                        if (modifiedTransactions != null)
                        {
                            modifiedTransactions.Add(currentTransaction);
                        }
                        else
                        {
                            modifiedTransactions = new TranSactionS();
                            modifiedTransactions.Add(currentTransaction);
                        }

                        myTransactions.Remove(currentTransaction);

                        if (myTransactions.Count > 0)
                        {
                            Session["modifiedTransactions"] = modifiedTransactions;
                            Server.Transfer("CategorizeMe.aspx");
                        }
                    }
                }
                else
                {
                    lblFilterError.Text = "Please choose your filter words part of the description.";
                }
            }
            else
            {
                lblFilterError.Text = "Something has horrible gone wrong.";
            }
        }
Ejemplo n.º 3
0
        private void ShowMyTransactions(TranSactionS transactionS, string desiredCategory)
        {
            TranSactionS DesiredCategoryTranSactionS = new TranSactionS();

            foreach (TranSaction s in transactionS)
            {
                if (s.myCategory == desiredCategory.ToString())
                {
                    DesiredCategoryTranSactionS.Add(s);
                }
            }

            ListView1.DataSource = DesiredCategoryTranSactionS;
            ListView1.DataBind();

            DrawMyPieChart(DesiredCategoryTranSactionS, desiredCategory);
        }
Ejemplo n.º 4
0
        private void FilterTransactionsWithThisCategory(string category, TranSactionS selectTranSactionS)
        {
            TranSactionS subTransactionS = new TranSactionS();
            Dictionary <string, decimal> displayTransactions = new Dictionary <string, decimal>();
            bool bExist = false;

            //find all our category
            foreach (TranSaction s in selectTranSactionS)
            {
                if (category.ToLower().IndexOf(s.myCategory.ToString().ToLower()) != -1)
                {
                    subTransactionS.Add(s);
                }
            }

            //group all the same filter into one
            foreach (TranSaction s in subTransactionS)
            {
                bExist = false;

                foreach (KeyValuePair <string, decimal> p in displayTransactions)
                {
                    //filter already exist, update the amount
                    if (s.myFilter.ToLower().IndexOf(p.Key.ToLower()) != -1)
                    {
                        bExist = true;
                        string  mFilter = p.Key;
                        decimal mAmount = p.Value + Math.Abs(s.Amt);

                        displayTransactions.Remove(p.Key);
                        displayTransactions.Add(mFilter, mAmount);

                        break;
                    }
                }

                if (!bExist)
                {
                    displayTransactions.Add(s.myFilter, Math.Abs(s.Amt));
                }
            }

            if (displayTransactions != null)
            {
                ListView1.DataSource = subTransactionS;
                ListView1.DataBind();

                //MyGraph graph1 = new MyGraph(subTransactionS, p);
                Legend leg = new Legend();
                Chart2.Legends.Add(leg);

                //Chart1.Series["Series1"]["Exploded"] = "true";
                // Set series and legend tooltips
                Chart2.Series["Series2"].ToolTip       = "#VALX: #VAL{C}";
                Chart2.Series["Series2"].LegendToolTip = "#PERCENT";
                //Chart2.Series["Series2"].PostBackValue = "#INDEX";
                //Chart2.Series["Series2"].LegendPostBackValue = "#INDEX";

                Chart2.Series["Series2"].Points.DataBindXY(displayTransactions.Keys, "Filter", displayTransactions.Values, "Amount");

                // Set series visual attributes
                Chart2.Series["Series2"].ChartType    = SeriesChartType.Pie;
                Chart2.Series["Series2"].ShadowOffset = 2;
                Chart2.Series["Series2"].BorderColor  = Color.DarkGray;
                //Chart2.Series["Series2"]["PieLabelStyle"] = "outside";
            }
        }
Ejemplo n.º 5
0
        //no date params, assume to draw pie chart from only the latest last month.
        private void DrawMyPieChart(TranSactionS myDrawTransactions, DateTime startDate, DateTime endDate)
        {
            DateTime monthYearOnly         = DateTime.MinValue;
            DateTime latestTransactionDate = GetLatestTransactionDate(myDrawTransactions);

            if (selectTranSactionS == null)
            {
                selectTranSactionS = new TranSactionS();
            }
            else
            {
                selectTranSactionS.Clear();
            }

            if (myDrawTransactions != null)
            {
                //show last latest month transactions
                if (startDate.Equals(DateTime.MinValue) && endDate.Equals(DateTime.MinValue))
                {
                    foreach (TranSaction s in myDrawTransactions)
                    {
                        //since our list is sorted, from highest
                        if ((s.myDate.Year.Equals(latestTransactionDate.Year) && s.myDate.Month.Equals(latestTransactionDate.Month)))
                        {
                            selectTranSactionS.Add(s);
                        }
                        else
                        {
                            //we only interested in the last latest month transactions
                            break;
                        }
                    }
                }
                else if (endDate > startDate)
                {
                    foreach (TranSaction s in myDrawTransactions)
                    {
                        if ((s.myDate >= startDate) && (s.myDate <= endDate))
                        {
                            selectTranSactionS.Add(s);
                        }
                    }
                }
                else if (endDate.Equals(startDate))
                {
                    foreach (TranSaction s in myDrawTransactions)
                    {
                        if ((s.myDate.Equals(endDate)))
                        {
                            selectTranSactionS.Add(s);
                        }
                    }
                }

                if (selectTranSactionS != null)
                {
                    MyGraph graph1 = new MyGraph(selectTranSactionS);
                    Legend  leg    = new Legend();
                    Chart1.Legends.Add(leg);

                    // Set series and legend tooltips
                    Chart1.Series["Series1"].ToolTip             = "#VALX: #VAL{C}";
                    Chart1.Series["Series1"].LegendToolTip       = "#PERCENT";
                    Chart1.Series["Series1"].PostBackValue       = "#INDEX";
                    Chart1.Series["Series1"].LegendPostBackValue = "#INDEX";

                    Chart1.Series["Series1"].Points.DataBindXY(graph1.GraphDatas, "Category", graph1.GraphDatas, "Amount");

                    // Set series visual attributes
                    Chart1.Series["Series1"].ChartType        = SeriesChartType.Pie;
                    Chart1.Series["Series1"].ShadowOffset     = 2;
                    Chart1.Series["Series1"].BorderColor      = Color.DarkGray;
                    Chart1.Series["Series1"]["PieLabelStyle"] = "inside";

                    ListView1.DataSource = selectTranSactionS;
                    ListView1.DataBind();
                }


                Session["endDate"]   = endDate;
                Session["startDate"] = startDate;
            }
            else
            {
                //Error, Null datas
            }
        }
Ejemplo n.º 6
0
        private bool DrawMyBarChart(TranSactionS TransactionS)
        {
            bool bReturn = false;

            if (TransactionS != null)
            {
                TranSactionS deposit = new TranSactionS();
                TranSactionS withraw = new TranSactionS();

                Legend leg = new Legend();
                Chart3.Legends.Add(leg);

                Chart3.Series.Add("Spending");
                Chart3.Series.Add("Deposit");

                //Chart3.Series["Spending"].PostBackValue = "#INDEX";
                //Chart3.Series["Spending"].LegendPostBackValue = "#INDEX";

                //Chart3.Series["Deposit"].PostBackValue = "#INDEX";
                //Chart3.Series["Deposit"].LegendPostBackValue = "#INDEX";

                withraw.AddRange(TransactionS);

                foreach (TranSaction s in withraw.ToList())
                {
                    if (s.myCategory == "Bank")
                    {
                        deposit.Add(s);
                        withraw.Remove(s);
                    }
                }

                barGraphLookUp = (Lookup <string, decimal>)withraw.ToLookup(p => p.myDate.ToString("y"), p => p.Amt);

                foreach (IGrouping <string, decimal> TransactionsGroup in barGraphLookUp)
                {
                    decimal amount = 0.00m;

                    foreach (decimal s in TransactionsGroup)
                    {
                        amount += Math.Abs(s);
                    }

                    Chart3.Series["Spending"].Points.AddXY(TransactionsGroup.Key, amount);
                }

                barGraphLookUp = (Lookup <string, decimal>)deposit.ToLookup(p => p.myDate.ToString("y"), p => p.Amt);

                foreach (IGrouping <string, decimal> TransactionsGroup in barGraphLookUp)
                {
                    decimal amount = 0.00m;

                    foreach (decimal s in TransactionsGroup)
                    {
                        amount += Math.Abs(s);
                    }

                    Chart3.Series["Deposit"].Points.AddXY(TransactionsGroup.Key, amount);
                }

                // Set series visual attributes
                Chart3.Series["Spending"].ChartType    = SeriesChartType.Column;
                Chart3.Series["Spending"].ShadowOffset = 2;
                Chart3.Series["Spending"].Color        = Color.Red;


                Chart3.Series["Deposit"].ChartType    = SeriesChartType.Column;
                Chart3.Series["Deposit"].ShadowOffset = 2;
                Chart3.Series["Deposit"].Color        = Color.Green;

                Chart3.ChartAreas[0].AxisY.Title = "Value in $$";
                Chart3.Titles[0].Text            = "Overall Spendings";


                bReturn = true;
            }

            return(bReturn);
        }
Ejemplo n.º 7
0
        public TranSactionS ReadMyCSV()
        {
            TranSactionS myTransactions = new TranSactionS();

            //file exist?
            FileStream   aFile   = null;
            StreamReader sreader = null;

            try
            {
                aFile   = new FileStream(fileName, FileMode.Open);
                sreader = new StreamReader(aFile);

                string line;
                line = sreader.ReadLine();
                //read each line
                //Date,Description,"Check Number",Amount format
                //Note in Description, there might be multiple commas
                //So we parse for Date, Amount, Check #, and assume the rest is Description

                DateTime tranDate;
                decimal  tranAmnt;
                string   tranCategory;
                string   tranType;
                string   tranCheck;
                string   tranFilter = "Empty";
                string   tmp;
                int      pos = 0;

                while (line != null)
                {
                    //get the string to the first position of ,
                    pos = line.IndexOf(',');

                    tmp = line.Remove(pos);

                    // try to put it in DateTime, else it not a transaction line
                    if (DateTime.TryParse(tmp, out tranDate))
                    {
                        //remove the previous DateTime
                        line = line.Substring(pos + 2);

                        //get the string last position of ,
                        pos = line.LastIndexOf(',');
                        tmp = line.Substring(pos++);
                        tmp = tmp.Replace(",", "");

                        if (decimal.TryParse(tmp, out tranAmnt))
                        {
                            if (tranAmnt < 0)
                            {
                                tranType = "Withraw";
                            }
                            else
                            {
                                tranType = "Deposit";
                            }

                            //remove the last string and to try find the check description if there any
                            line      = line.Substring(0, pos - 1);
                            pos       = line.LastIndexOf(',');
                            tmp       = line.Substring(pos);
                            tmp       = tmp.Replace(",", "");
                            tranCheck = tmp;

                            //whatever left in string should be category because of the way data are
                            //filter it as HouseBill,Restaurant,Grocery,CarMaintenance????
                            line         = line.Substring(0, pos - 1);
                            tranCategory = line;

                            //put it in our transaction
                            TranSaction transaction;

                            transaction = new TranSaction(tranDate, tranCategory, tranCheck, tranAmnt, tranType, tranCategory, tranFilter);

                            //put it in our transactionS
                            myTransactions.Add(transaction);
                        }
                        else
                        {
                            //Unable to parse for line amount.
                            myLogging.LogError("Unable to parse for amount." + line, "Error");
                        }
                    }
                    else
                    {
                        //Not a transaction line or invalid format. Unable to parse for date.
                        myLogging.LogError("Not a transaction line or invalid format. Unable to parse for date." + line, "Warning");
                    }


                    line = sreader.ReadLine();
                }
            }
            catch (IOException e)
            {
                myLogging.LogError(e.ToString(), "Error");
            }
            finally
            {
                //destroy file thingy?
                if (sreader != null)
                {
                    sreader.Dispose();
                }

                if (aFile != null)
                {
                    aFile.Dispose();
                }
            }
            return(myTransactions);
        }