Пример #1
0
 private DateTime GetOldestTransactionDate(TranSactionS Transactions)
 {
     Transactions.Sort();
     //our sort should sort highest to lowest
     //so we can pull the first transaction out and it should have the last latest month
     return(Transactions.Last().myDate);
 }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            GetXMLFileLoc();

            if (Session["myTranSactions"] != null)
            {
                myTransactions = (TranSactionS)Session["myTranSactions"];

                if (Session["modifiedTransactions"] != null)
                {
                    modifiedTransactions = (TranSactionS)Session["modifiedTransactions"];
                }

                GetXMLFilter();


                FilterPanel.Visible = true;
                PopulateCategories(myTransactions);
            }
            else
            {
                FilterPanel.Visible = false;
                lblMessage.Text     = "Error:  No data found.";
            }
        }
Пример #3
0
        private void PopulateCategories(TranSactionS mTranSactionS)
        {
            foreach (TranSaction s in mTranSactionS.ToList())
            {
                currentTransaction = s;

                if (!CategoryMe(currentTransaction))
                {
                    //can't get the category by comparing what the filter xml have
                    //have to ask for user to figure out what it is

                    lblTransactionDescription.Text = s.Description.ToString();
                    Session["currentTransaction"]  = currentTransaction;

                    break;
                }
            }

            if (myTransactions.Count < 1)
            {
                //if our filter is complete display our result in new page
                SaveFilter();
                Session.Remove("myTranSactions");
                //Session.Remove("XMLFilter");
                //Session.Remove("XMLFileLoc");
                Session["modifiedTransactions"] = modifiedTransactions;
                Server.Transfer("MyFinan53.aspx");
            }
        }
Пример #4
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);
        }
Пример #5
0
        private bool buildMyGraphDatas(TranSactionS myDrawTransactions, string desiredCategory)
        {
            bool bReturn = false;

            if (myDrawTransactions != null)
            {
                if (GraphDatas != null)
                {
                    GraphDatas.Clear();
                }
                else
                {
                    GraphDatas = new List <MyGraphData>();
                    foreach (TranSaction s in myDrawTransactions)
                    {
                        GraphDatas.Add(new MyGraphData {
                            Category = s.myFilter, Amount = Math.Abs(s.Amt)
                        });
                    }
                }

                bReturn = true;
            }

            return(bReturn);
        }
Пример #6
0
 private void BindSubCategory(string category, TranSactionS selectTranSactionS)
 {
     if (category.Length > 0)
     {
         category = category.Replace("Total", "");
         FilterTransactionsWithThisCategory(category, selectTranSactionS);
     }
 }
Пример #7
0
        protected void bttnUpload_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                try
                {
                    //to set max upload size: web.config.comments file, find a node called <httpRuntime> ->set the maxRequestLength
                    //http://msdn.microsoft.com/en-us/library/aa479405.aspx


                    FileUpload1.SaveAs(UploadDir + FileUpload1.FileName);
                    lblError.Text = "File name: " + FileUpload1.PostedFile.FileName + "<br>" + FileUpload1.PostedFile.ContentLength + " kb<br>" +
                                    "Content type: " + FileUpload1.PostedFile.ContentType;

                    //Our category transactions are first loaded with description
                    //Build of filter to figure out what category each transaction

                    //Read the csv file
                    String FileName = UploadDir + FileUpload1.FileName;


                    ReadCSV myCSV = new ReadCSV(FileName);
                    myMainTranSactionS = myCSV.ReadMyCSV();

                    if (myMainTranSactionS.Count < 1)
                    {
                        errLog.LogError("No transaction found.", "Error");
                    }
                    else
                    {
                        //We need to put modified the category depend on each transaction

                        Session["myTranSactions"] = myMainTranSactionS;
                        Server.Transfer("CategorizeMe.aspx");
                    }

                    if (Session["myTranSactions"] == null)
                    {
                        Session["myTranSactions"] = myMainTranSactionS;
                    }

                    Server.Transfer("ShowData.aspx");
                }
                catch (Exception ex)
                {
                    errLog.LogError(ex.Message.ToString(), "Error");
                }
            }
            else
            {
                lblError.Text += "You have not specified a file.";
            }
        }
Пример #8
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.";
            }
        }
Пример #9
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);
        }
Пример #10
0
        private void DrawMyPieChart(TranSactionS selectTranSactionS, string desiredCategory)
        {
            if (selectTranSactionS != null)
            {
                MyGraph graph1 = new MyGraph(selectTranSactionS, desiredCategory);
                foreach (TranSaction s in selectTranSactionS)
                {
                    if (s.myCategory == desiredCategory)
                    {
                    }
                }

                Legend leg = new Legend();

                Chart1.Legends.Add(leg);
                Chart1.Series["Series1"].Points.DataBindXY(graph1.GraphDatas, "Category", graph1.GraphDatas, "Amount");
            }
            else
            {
                //no data selected
            }
        }
Пример #11
0
        //DateTime latestTransactionDate = DateTime.MinValue;


        protected void Page_Load(object sender, EventArgs e)
        {
            IntialValue();

            if (Session["modifiedTransactions"] != null)
            {
                IntroductionPanel.Visible = false;
                ViewPanel.Visible         = true;

                myMainTranSactionS = (TranSactionS)Session["modifiedTransactions"];

                if (Session["endDate"] != null)
                {
                    endDate = (DateTime)Session["endDate"];
                }

                if (Session["startDate"] != null)
                {
                    startDate = (DateTime)Session["startDate"];
                }

                DrawMyBarChart(myMainTranSactionS);
                DrawMyPieChart(myMainTranSactionS, startDate, endDate);
            }
            else
            {
                IntroductionPanel.Visible = true;
                ViewPanel.Visible         = false;
            }


            if (IsPostBack)
            {
            }
            else if (!IsPostBack)
            {
            }
        }
Пример #12
0
 public MyGraph(TranSactionS myDrawTransactions)
 {
     buildMyGraphDatas(myDrawTransactions);
 }
Пример #13
0
        public bool buildMyGraphDatas(TranSactionS myDrawTransactions)
        {
            bool bReturn = false;

            if (myDrawTransactions != null)
            {
                if (GraphDatas != null)
                {
                    GraphDatas.Clear();
                }
                else
                {
                    GraphDatas = new List <MyGraphData>();
                }

                myDrawTransactions.doStatistic();

                if (Math.Abs(myDrawTransactions.mytranTotalBank) > 0)
                {
                    GraphDatas.Add(new MyGraphData {
                        Category = "TotalBank", Amount = Math.Abs(myDrawTransactions.mytranTotalBank)
                    });
                }

                if (Math.Abs(myDrawTransactions.mytranTotalInsurance) > 0)
                {
                    GraphDatas.Add(new MyGraphData {
                        Category = "TotalInsurance", Amount = Math.Abs(myDrawTransactions.mytranTotalInsurance)
                    });
                }

                if (Math.Abs(myDrawTransactions.mytranTotalCommunicationBill) > 0)
                {
                    GraphDatas.Add(new MyGraphData {
                        Category = "TotalCommunicationBill", Amount = Math.Abs(myDrawTransactions.mytranTotalCommunicationBill)
                    });
                }

                if (Math.Abs(myDrawTransactions.mytranTotalPetBill) > 0)
                {
                    GraphDatas.Add(new MyGraphData {
                        Category = "TotalPetBill", Amount = Math.Abs(myDrawTransactions.mytranTotalPetBill)
                    });
                }

                if (Math.Abs(myDrawTransactions.mytranTotalCable) > 0)
                {
                    GraphDatas.Add(new MyGraphData {
                        Category = "TotalCable", Amount = Math.Abs(myDrawTransactions.mytranTotalCable)
                    });
                }

                if (Math.Abs(myDrawTransactions.mytranTotalOther) > 0)
                {
                    GraphDatas.Add(new MyGraphData {
                        Category = "TotalOther", Amount = Math.Abs(myDrawTransactions.mytranTotalOther)
                    });
                }

                if (Math.Abs(myDrawTransactions.mytranTotalGrocery) > 0)
                {
                    GraphDatas.Add(new MyGraphData {
                        Category = "TotalGrocery", Amount = Math.Abs(myDrawTransactions.mytranTotalGrocery)
                    });
                }

                if (Math.Abs(myDrawTransactions.mytranTotalRestaurant) > 0)
                {
                    GraphDatas.Add(new MyGraphData {
                        Category = "TotalRestaurant", Amount = Math.Abs(myDrawTransactions.mytranTotalRestaurant)
                    });
                }

                if (Math.Abs(myDrawTransactions.mytranTotalCarBill) > 0)
                {
                    GraphDatas.Add(new MyGraphData {
                        Category = "TotalCarBill", Amount = Math.Abs(myDrawTransactions.mytranTotalCarBill)
                    });
                }

                if (Math.Abs(myDrawTransactions.mytranTotalHomeBill) > 0)
                {
                    GraphDatas.Add(new MyGraphData {
                        Category = "TotalHomeBill", Amount = Math.Abs(myDrawTransactions.mytranTotalHomeBill)
                    });
                }

                bReturn = true;
            }

            return(bReturn);
        }
Пример #14
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);
        }
Пример #15
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);
        }
Пример #16
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
            }
        }
Пример #17
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";
            }
        }
Пример #18
0
 public MyGraph(TranSactionS myDrawTransactions, string desiredCategory)
 {
     buildMyGraphDatas(myDrawTransactions, desiredCategory);
 }