public PaymentCard(int pin, string cardNumber, Customer holder, Account account)
 {
     CardNumber = cardNumber;
     Pin = pin;
     Holder = holder;
     ConnectedAccount = account;
     active = true;
 }
Example #2
0
 public Account(string number, Customer holder)
 {
     transactions = new List<Transaction>();
     holders = new List<Customer>();
     Number = number;
     holders.Add(holder);
     SetName();
 }
Example #3
0
        public bool IsHolder(Customer c)
        {
            foreach (Customer cust in holders)
            {
                if (cust.Ssn == c.Ssn)
                {
                    return true;
                }
            }

            return false;
        }
Example #4
0
        public List<List<object>> CustomerData()
        {
            List<List<object>> results = new List<List<object>>();


            // Customers
            List<object> customers = new List<object>();

            SqlConnection myConnection = new SqlConnection();
            myConnection.ConnectionString = connectionString;
            myConnection.Open();
            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;
            myCommand.CommandText = $"SELECT Ssn, FirstName, LastName FROM Customer";

            var result = myCommand.ExecuteReader();

            using (result)
            {
                while (result.Read())
                {
                    string ssn = (string)result["Ssn"];
                    string fname = (string)result["FirstName"];
                    string lname = (string)result["LastName"];

                    Customer c = new Customer(ssn, fname, lname);
                    customers.Add(c);
                }
            }

            myConnection.Close();

            // Accounts
            List<object> accounts = new List<object>();

            SqlConnection conn2 = new SqlConnection();
            conn2.ConnectionString = connectionString;
            conn2.Open();
            SqlCommand cmd2 = new SqlCommand();
            cmd2.Connection = conn2;
            cmd2.CommandText = $"SELECT AccountNumber, Holder FROM Account";

            var result2 = cmd2.ExecuteReader();

            using (result2)
            {
                while (result2.Read())
                {
                    string number = result2["AccountNumber"].ToString();
                    string holderSsn = (string)result2["Holder"];
                    Customer c = null;

                    foreach (Customer customer in customers)
                    {
                        if (customer.Ssn == holderSsn)
                        {
                            c = customer;
                        }
                    }

                    Account a = new Account(number, c);
                    accounts.Add(a);
                }
            }

            conn2.Close();


            // PaymentCards
            List<object> paymentCards = new List<object>();

            SqlConnection conn3 = new SqlConnection();
            conn3.ConnectionString = connectionString;
            conn3.Open();
            SqlCommand cmd3 = new SqlCommand();
            cmd3.Connection = conn3;
            cmd3.CommandText = $"SELECT Pin, CardNumber, Holder, PrimaryAccount FROM PaymentCard";

            var result3 = cmd3.ExecuteReader();

            using (result3)
            {
                while (result3.Read())
                {
                    string cardNumber = (string)result3["CardNumber"];
                    int pin = (int)result3["Pin"];
                    string holderSsn = (string)result3["Holder"];
                    string account = result3["PrimaryAccount"].ToString();
                    Customer c = null;
                    Account a = null;

                    foreach (Customer customer in customers)
                    {
                        if (customer.Ssn == holderSsn)
                        {
                            c = customer;
                        }
                    }

                    foreach (Account acc in accounts)
                    {
                        if (acc.Number == cardNumber)
                        {
                            a = acc;
                        }
                    }

                    PaymentCard pc = new PaymentCard(pin, cardNumber, c, a);
                    paymentCards.Add(pc);
                }
            }

            conn3.Close();

            // Adds the dictionarys to the list
            results.Add(customers);
            results.Add(accounts);
            results.Add(paymentCards);

            return results;
        }