public CreateAccountForm(ParkingDatabase db, IClock clock, IMailer mailer)
 {
     Database = db;
     FormClock = clock;
     Mailer = mailer;
     InitializeComponent();
 }
 public AdminForm(IClock adminClock, IMailer mailer)
 {
     AdminClock = adminClock;
     Mailer = mailer;
     Database = new ParkingDatabase(adminClock, Mailer);
     InitializeComponent();
 }
        // fill the database with fake data for last month, using a test clock
        public static void FillLastMonthData(ParkingDatabase database, IClock testClock)
        {
            try
            {
                // fill with database with fake data
                for (int i = 0; i < 80; i++)
                {
                    CustomerAccount testAccount = new CustomerAccount(RandomString(), RandomString(), "555-555-5555",
                        RandomString() + "@tester.com", "password");
                    Billing.CreditCard.CreditCardType randomCardType = (Billing.CreditCard.CreditCardType)random.Next(3);
                    Billing.CreditCard testCard = new Billing.CreditCard(1234123412349876, Billing.CreditCard.CreditCardType.MASTERCARD);
                    Accounts.Vehicle testVehicle = new Accounts.Vehicle(RandomString() + " " + RandomString(),
                        RandomString());
                    DateTime startDate = new DateTime(2012, 11, 25, 10, 0, 0); // 11-25-12 @ 10a
                    DateTime testResDate = RandomTime(startDate);
                    database.AddAccount(testAccount);
                    database.AddCreditCard(testCard, testAccount.CustomerID);
                    database.AddVehicle(testVehicle, testAccount.CustomerID);
                    ParkingReservation testReservation = new ParkingReservation(testAccount, testVehicle,
                        testResDate, 120);

                    // generate a random transaction date in the past
                    int hours = random.Next(1, 500);
                    TimeSpan timeSpan = new TimeSpan(hours, 0, 0);
                    DateTime transactionDate = testResDate.Subtract(timeSpan);

                    // add reservation (and transaction) to database
                    database.AddReservation(testReservation, testCard.CardID, transactionDate);
                }
            }
            catch (Exception)
            { } // confict when adding reservation (ignore)
        }
        // constructor
        public ModifyReservationForm(Form prevMenu, ParkingDatabase database,
            ParkingReservation reservationToModify, IClock clock, IMailer mailer)
        {
            rand = new Random();
            Mailer = mailer;
            ModificationClock = clock;
            this.PreviousMenu = prevMenu;
            this.Database = database;
            OldReservation = reservationToModify;
            VehicleList = Database.GetVehicles(OldReservation.Customer.CustomerID);
            CardList = Database.GetCreditCards(OldReservation.Customer.CustomerID);

            InitializeComponent();

            // bind the vehicle combo box to the vehicle list
            vehicleComboBox.DataSource = VehicleList;
            vehicleComboBox.DisplayMember = "AsString";

            // set initial values based on current reservation details
            desiredMonthCalendar.MaxSelectionCount = 1;
            desiredMonthCalendar.SelectionStart = OldReservation.Date;
            desiredTimeDateTimePicker.Value = OldReservation.Date;
            durationComboBox.SelectedIndex = MinutesToDurationIndex(OldReservation.DurationMinutes);
            vehicleComboBox.SelectedItem = OldReservation.ReservationVehicle;
        }
 public CustomerForm(CustomerAccount cust, ParkingDatabase db, IClock clock, IMailer mailer)
 {
     CustomerClock = clock;
     Mailer = mailer;
     InitializeComponent();
     Customer = cust;
     Database = db;
 }
 // constructor
 public TerminalForm(IBarrier barrier, ITerminalPrinter printer, IClock termClock, IMailer mailer)
 {
     TerminalMailer = mailer;
     rand = new Random();
     Barrier = barrier;
     Printer = printer;
     TerminalClock = termClock;
     Database = new ParkingDatabase(termClock, TerminalMailer);
     InitializeComponent();
 }
        static void Main()
        {
            // define the clock, database, and mailing component to be used
            IClock clock = new SystemClock();
            IMailer mailer = new MailerStub();
            ParkingDatabase database = new ParkingDatabase(clock, mailer);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new UserForm(clock, mailer, database, false));
        }
 // Constuctor for initalizing this form
 // source: http://stackoverflow.com/questions/600869/how-to-bind-a-list-to-a-combobox-winforms
 public CreateReservationForm(ParkingDatabase db, CustomerAccount customer)
 {
     Database = db;
     Customer = customer;
     VehicleList = Database.GetVehicles(Customer.CustomerID);
     CardList = Database.GetCreditCards(Customer.CustomerID);
     InitializeComponent();
     vehicleComboBox.DataSource = VehicleList;
     vehicleComboBox.DisplayMember = "AsString";
     paymentMethodComboBox.DataSource = CardList;
     paymentMethodComboBox.DisplayMember = "AsString";
     desiredMonthCalendar.MaxSelectionCount = 1;
 }
        // constructor
        public SelectReservationToModifyForm(ParkingDatabase db, IClock custClock, IMailer mailer, CustomerAccount cust)
        {
            Mailer = mailer;
            Database = db;
            this.CustomerClock = custClock;
            Customer = cust;

            // create a binding list from the database list
            Reservations = new BindingList<ParkingReservation>(Database.GetCurrentAndFutureReservations(Customer.CustomerID));

            InitializeComponent();

            // bind the bindinglist to the combobox datasource
            reservationComboBox.DataSource = Reservations;
            reservationComboBox.DisplayMember = "ReservationID";
        }
        // constructors
        public ParkingSpotOverviewForm(ParkingDatabase db, IClock clock, IMailer mailer)
        {
            Database = db;
            this.OverviewClock = clock;
            Mailer = mailer;

            // get parking spots from the database
            ParkingSpots = Database.GetParkingSpots();

            InitializeComponent();

            // set control values
            parkingSpotComboBox.DataSource = ParkingSpots;
            parkingSpotComboBox.DisplayMember = "ParkingSpotID";
            currentTimeLabel.Text = OverviewClock.Now.ToString("g");
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // set up the print, mailer, and barrier external components to be used (stubs for now)
            ITerminalPrinter printer = new TerminalPrinterStub();
            IMailer mailer = new MailerStub();
            IBarrier barrier = new BarrierStub();

            // set up test environment
            // source: http://stackoverflow.com/questions/43711/whats-a-good-way-to-overwrite-datetime-now-during-testing
            DateTime testTime = new DateTime(2012, 12, 30, 13, 1, 0);
            IClock testClock = new TestClock(testTime); // a static clock for testing

            ParkingDatabase database = new ParkingDatabase(testClock, mailer);

            // fill with database with fake data
            for (int i = 0; i < 80; i++)
            {
                // create a random customer (including vehicle and billing info) and reservation
                CustomerAccount testAccount = new CustomerAccount(RandomString(), RandomString(), "555-555-5555",
                    RandomString() + "@tester.com", "password");
                Billing.CreditCard.CreditCardType randomCardType = (Billing.CreditCard.CreditCardType)random.Next(3);
                Billing.CreditCard testCard = new Billing.CreditCard(1234123412349876, Billing.CreditCard.CreditCardType.MASTERCARD);
                Accounts.Vehicle testVehicle = new Accounts.Vehicle(RandomString() + " " + RandomString(),
                    RandomString());
                DateTime startDate = new DateTime(2012, 12, 30, 10, 0, 0); // date to start generating from
                DateTime testResDate = RandomTime(startDate);

                // add fake customer data to database
                database.AddAccount(testAccount);
                database.AddCreditCard(testCard, testAccount.CustomerID);
                database.AddVehicle(testVehicle, testAccount.CustomerID);
                ParkingReservation testReservation = new ParkingReservation(testAccount, testVehicle,
                    testResDate, 120);

                // generate a random transaction date in the past
                int hours = random.Next(1, 500);
                TimeSpan timeSpan = new TimeSpan(hours, 0, 0);
                DateTime transactionDate = testResDate.Subtract(timeSpan);

                try
                {
                    // add fake reservation data to the database
                    database.AddReservation(testReservation, testCard.CardID, transactionDate);

                    // check in with 50% chance
                    if (random.Next(2) == 0)
                    {
                        // change status of reservation, if reservation is not in the future
                        if (testReservation.Date < testClock.Now)
                        {
                            database.ModifyReservation(testReservation, testReservation.ParkingSpotID,
                                testReservation.Date, testReservation.DurationMinutes, true,
                                testReservation.ReservationVehicle.CarID);

                            // change status of parking garage spot
                            database.SetParkingSpotStatus(testReservation.ParkingSpotID, 1);
                        }
                    }
                }
                catch (Exception)
                { } // conflict when adding reservation (ignore)
            }

            // fill database with fake data for last month
            FillLastMonthData(database, testClock);

            // reminder of admin credentials, for testing
            System.Windows.Forms.MessageBox.Show(
                string.Format("You can login as admin with\nemail: {0}\npassword: {1}",
                "*****@*****.**", "password"));
            Application.Run(new UserForm(testClock, mailer, database, true));
        }
 public GarageStatisticsForm(Form prevMenu, ParkingDatabase database)
 {
     this.PreviousMenu = prevMenu;
     this.Database = database;
     InitializeComponent();
 }