Exemplo n.º 1
0
        public static List <Payment> GetPayments(Int32 transactionID)
        {
            List <Payment> payments = new List <Payment>();
            Transaction    t        = TransactionSQLAccess.GetTransaction(transactionID);

            using (MySqlConnection conn = new MySqlConnection(SQLConstants.CONNECTION_STRING))
            {
                conn.Open();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "select userid, amount from payment where tid=?tid";
                    cmd.Parameters.Add("?tid", MySqlDbType.Int32).Value = transactionID;

                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int     userId = reader.GetInt32(0);
                            Decimal amount = reader.GetDecimal(1);
                            bool    isDebt = (amount < 0);

                            User    user    = UserSQLAccess.GetUser(userId);
                            Payment payment = new Payment(user, amount, t, isDebt);

                            payments.Add(payment);
                        }
                    }
                }
            }

            return(payments);
        }
Exemplo n.º 2
0
        public static List <Payment> GetAllPayments()
        {
            List <Payment> payments = new List <Payment>();

            using (MySqlConnection conn = new MySqlConnection(SQLConstants.CONNECTION_STRING))
            {
                conn.Open();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "select userid, tid, amount from payment";
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int     userId        = reader.GetInt32(0);
                            int     transactionId = reader.GetInt32(1);
                            Decimal amount        = reader.GetDecimal(2);
                            bool    isDebt        = (amount < 0);

                            User        user        = UserSQLAccess.GetUser(userId);
                            Transaction transaction = TransactionSQLAccess.GetTransaction(transactionId);
                            Payment     payment     = new Payment(user, amount, transaction, isDebt);

                            payments.Add(payment);
                        }
                    }
                }
            }

            return(payments);
        }
Exemplo n.º 3
0
        public static List <Payment> GetPayments(IList <User> users)
        {
            List <Payment> payments = new List <Payment>();

            using (MySqlConnection conn = new MySqlConnection(SQLConstants.CONNECTION_STRING))
            {
                conn.Open();
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    StringBuilder cmdText = new StringBuilder();
                    foreach (User currentUser in users)
                    {
                        if (cmdText.Length > 0)
                        {
                            cmdText.Append(" or ");
                        }
                        cmdText.Append(String.Format(" userid = {0}", currentUser.ID));
                    }
                    cmdText.Insert(0, "select userid, tid, amount from payment where");

                    cmd.CommandText = cmdText.ToString();

                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int     userId = reader.GetInt32(0);
                            int     tid    = reader.GetInt32(1);
                            Decimal amount = reader.GetDecimal(2);
                            bool    isDebt = (amount < 0);

                            User        user        = UserSQLAccess.GetUser(userId);
                            Transaction transaction = TransactionSQLAccess.GetTransaction(tid);
                            Payment     payment     = new Payment(user, amount, transaction, isDebt);

                            payments.Add(payment);
                        }
                    }
                }
            }

            return(payments);
        }