Пример #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);
        }
Пример #2
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");
            }
        }
Пример #3
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.";
            }
        }
Пример #4
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);
        }