Ejemplo n.º 1
0
        public void AddRepeatTransaction(Transaction trans, int frequency = 1, bool monthly = true)
        {
            int index = repeatedTrans.IndexOf(repeatedTrans.Where(x => (string.Compare(x.Bin, trans.Bin) == 0) &&
                                                                  (string.Compare(x.Description, trans.Description) == 0) &&
                                                                  (x.Value == trans.Value)).FirstOrDefault());

            RepeatTransaction[] rTransArr = repeatedTrans.OrderBy(x => x.TransactionID).ToArray();
            int[] sortedIDArr             = new int[rTransArr.Length];

            for (int i = 0; i < rTransArr.Length; ++i)
            {
                sortedIDArr[i] = rTransArr[i].TransactionID;
            }

            if (index == -1)
            {
                RepeatTransaction repeat = new RepeatTransaction(trans, frequency, monthly)
                {
                    TransactionID = IDGenerator.RandIDGen(10000, sortedIDArr)
                };
                repeatedTrans.Add(repeat);
                Account.InsertRepeatTransaction(repeat);
                repeat.Setup = false;
            }
        }
Ejemplo n.º 2
0
        static public void DeleteRepeatedTransaction(RepeatTransaction trans)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(ConnectionStr))
                {
                    conn.Open();
                    if (conn.State == System.Data.ConnectionState.Open)
                    {
                        using (SqlCommand command = conn.CreateCommand())
                        {
                            command.CommandType = System.Data.CommandType.StoredProcedure;
                            command.CommandText = "stpDeleteRepeatedTransaction";

                            //add parameters
                            command.Parameters.Add(new SqlParameter("@User", Username));
                            command.Parameters.Add(new SqlParameter("@TransactionID", trans.TransactionID));

                            command.ExecuteNonQuery();
                        }
                    }
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 3
0
 public Transaction(RepeatTransaction transaction)
 {
     Value        = transaction.Value;
     Description  = transaction.Description;
     Bin          = transaction.Bin;
     BinID        = transaction.BinID;
     Date         = transaction.Date;
     DrawerGoal   = transaction.DrawerGoal;
     DrawerExp    = transaction.DrawerExp;
     IncomeSplit  = transaction.IncomeSplit;
     DrawerGoalID = transaction.DrawerGoalID;
 }
Ejemplo n.º 4
0
        static public ObservableCollection <RepeatTransaction> SelectRepeatTransactions()
        {
            var    repeatTransList = new ObservableCollection <RepeatTransaction>();
            string commandStr      = "SELECT * FROM [RepeatedTransactions] WHERE [User] = '" + Username + "'";

            try
            {
                using (SqlConnection conn = new SqlConnection(ConnectionStr))
                {
                    conn.Open();
                    if (conn.State == System.Data.ConnectionState.Open)
                    {
                        using (SqlCommand command = conn.CreateCommand())
                        {
                            command.CommandText = commandStr;

                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    RepeatTransaction temp = new RepeatTransaction()
                                    {
                                        Value         = reader.GetDecimal(0),
                                        Description   = reader.GetString(1),
                                        Date          = reader.GetDateTime(2),
                                        IncomeString  = (reader.IsDBNull(3)) ? string.Empty : reader.GetString(3),
                                        DrawerGoal    = (reader.IsDBNull(4)) ? string.Empty : reader.GetString(4),
                                        DrawerGoalID  = reader.GetInt32(5),
                                        IncomeSplit   = reader.GetBoolean(6),
                                        DrawerExp     = reader.GetBoolean(7),
                                        Bin           = reader.GetString(8),
                                        Frequency     = reader.GetInt32(10),
                                        Monthly       = reader.GetBoolean(11),
                                        BinID         = reader.GetInt32(12),
                                        TransactionID = reader.GetInt32(13)
                                    };
                                    temp.Setup = false;
                                    repeatTransList.Add(temp);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            return(repeatTransList);
        }
Ejemplo n.º 5
0
        public void RemoveRepeatTransaction(RepeatTransaction repeatTrans)
        {
            int index = repeatedTrans.IndexOf(repeatedTrans.Where(x => x.TransactionID == repeatTrans.TransactionID).FirstOrDefault());

            //string.Compare(x.Bin, repeatTrans.Bin) == 0 &&
            //string.Compare(x.Description, repeatTrans.Description) == 0 &&
            //x.Frequency == repeatTrans.Frequency &&
            //x.Monthly == repeatTrans.Monthly &&
            //x.Value == repeatTrans.Value
            if (index != -1)
            {
                Account.DeleteRepeatedTransaction(repeatedTrans[index]);
                repeatedTrans.RemoveAt(index);
            }
        }
Ejemplo n.º 6
0
        //need to test this
        public void CheckRepeatTransac(RepeatTransaction trans, int index)
        {
            DateTime transactionDate = new DateTime(trans.Date.Year, trans.Date.Month, trans.Date.Day);

            if (trans.Monthly)
            {
                transactionDate = transactionDate.AddMonths(trans.Frequency);
            }
            else
            {
                transactionDate = transactionDate.AddDays(trans.Frequency);
            }



            if (DateTime.Compare(DateTime.Today, transactionDate) > -1)
            {
                if (repeatedTrans[index].Value > 0m)
                {
                    AddIncome(trans.Value, trans.Description, transactionDate, trans.Bin, trans.IncomeSplit);
                    repeatedTrans[index].Date = transactionDate;
                    // = new Income(trans.Transaction.Value, trans.Transaction.Description, trans.Transaction.Bin, transactionDate);
                }
                else
                {
                    AddExpense(trans.Value, trans.Description, transactionDate, trans.Bin, trans.DrawerExp, trans.DrawerGoal);
                    repeatedTrans[index].Date = transactionDate; //new Expense
                    //{
                    //    Value = exp.Value,
                    //    Description = exp.Description,
                    //    Date = transactionDate,//new myDateTime(transactionDate),
                    //    Bin = exp.Bin,
                    //    DrawerExp = exp.GetDrawerExp(),
                    //    Drawer = exp.GetDrawer(),
                    //};
                }

                //repeatedTrans[index].Transaction.Date = new myDateTime(transactionDate);
                CheckRepeatTransac(trans, index);
            }
        }
Ejemplo n.º 7
0
        static public void UpdateRepeatTransaction(RepeatTransaction trans)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(ConnectionStr))
                {
                    conn.Open();
                    if (conn.State == System.Data.ConnectionState.Open)
                    {
                        using (SqlCommand command = conn.CreateCommand())
                        {
                            command.CommandType = System.Data.CommandType.StoredProcedure;
                            command.CommandText = "stpUpdateRepeatedTransaction";

                            //add parameters
                            command.Parameters.Add(new SqlParameter("@Value", trans.Value));
                            command.Parameters.Add(new SqlParameter("@Description", trans.Description));
                            command.Parameters.Add(new SqlParameter("@Date", trans.Date));
                            command.Parameters.Add(new SqlParameter("@BinSplitString", trans.IncomeString));
                            command.Parameters.Add(new SqlParameter("@DrawerGoal", trans.DrawerGoal));
                            command.Parameters.Add(new SqlParameter("@DrawerGoalID", trans.DrawerGoalID));
                            command.Parameters.Add(new SqlParameter("@IncomeSplit", trans.IncomeSplit));
                            command.Parameters.Add(new SqlParameter("@DrawerExpense", trans.DrawerExp));
                            command.Parameters.Add(new SqlParameter("@Bin", trans.Bin));
                            command.Parameters.Add(new SqlParameter("@User", Username));
                            command.Parameters.Add(new SqlParameter("@Frequency", trans.Frequency));
                            command.Parameters.Add(new SqlParameter("@Monthly", trans.Monthly));
                            command.Parameters.Add(new SqlParameter("@BinID", trans.BinID));
                            command.Parameters.Add(new SqlParameter("@TransactionID", trans.TransactionID));

                            command.ExecuteNonQuery();
                        }
                    }
                }
            }
            catch
            {
            }
        }