Esempio n. 1
0
        private void newCustomer1Btn_Click(object sender, EventArgs e)
        {
            string firstName = newCustomer1Txt.Text.Trim(' ');
            string lastName  = newCustomer2Txt.Text.Trim(' ');
            string phone     = newCustomer3Txt.Text.Trim(' ');
            string email     = newCustomer4Txt.Text.Trim(' ');
            string address   = newCustomer5Txt.Text.Trim(' ');

            if (!Check.areValidInputs(firstName, lastName, phone, email, address))
            {
                Prompt.enterValidInput();
                return;
            }
            if (!Check.isPhone(phone))
            {
                Prompt.enterPhone();
                return;
            }

            if (!Check.isEmail(email))
            {
                Prompt.enterEmail();
                return;
            }

            try
            {
                if (CustomersTable.hasCustomer(firstName, lastName, phone))
                {
                    Prompt.alreadyInDB("customer");
                    return;
                }


                CustomersTable.add(lastName, firstName, email, address, phone);

                clearRadioButtons(newCustomerPnl);
                clearTextBoxes(newCustomerPnl);

                if (currentUser.isAdmin())
                {
                    setCurrentMainPanel(adminPnl);
                }
            }catch
            {
                CustomersTable.adapter.Dispose();
                Prompt.dbError();
            }
        }
Esempio n. 2
0
        private void rent2Btn_Click(object sender, EventArgs e)
        {
            string firstName = rent2Txt.Text.Trim(' ');
            string lastName  = rent3Txt.Text.Trim(' ');
            string phone     = rent4Txt.Text.Trim(' ');
            int    customerId;

            if (!Check.areValidInputs(firstName, lastName, phone))
            {
                Prompt.enterValidInput();
                return;
            }

            if (!Check.isPhone(phone))
            {
                Prompt.enterPhone();
                return;
            }
            try
            {
                if (!CustomersTable.hasCustomer(firstName, lastName, phone))
                {
                    Prompt.notACustomer();
                    return;
                }

                customerId = CustomersTable.getCustomerId(firstName, lastName, phone);

                currentCustomer = new Customer(customerId, firstName, lastName);

                CopiesTable.makeUnavailable(currentDVD.getUpc());

                RentalsTable.add(currentDVD.getUpc(), currentCustomer.getCustomerId(), currentUser.getUserName(), Date.dateAfter(7));
                CustomersTable.incrementTimesRented(currentCustomer.getCustomerId());
                MoviesTable.incrementTimesRented(currentDVD.getUpc());
                clearTextBoxes(rent2Pnl);
                setCurrentMainPanel(rentPnl);
            }catch
            {
                CustomersTable.adapter.Dispose();
                RentalsTable.adapter.Dispose();
                MoviesTable.adapter.Dispose();
                CopiesTable.adapter.Dispose();
                Prompt.dbError();
            }
        }
Esempio n. 3
0
        private void removeCustomer1Btn_Click(object sender, EventArgs e)
        {
            string customerId = removeCustomer1Txt.Text.Trim(' ');

            if (!Check.areValidInputs(customerId))
            {
                Prompt.enterValidInput();
                return;
            }
            if (!Check.isNumeric(customerId))
            {
                Prompt.enterNumeric("Customer Id");
                return;
            }

            try
            {
                if (!CustomersTable.hasCustomer(Int32.Parse(customerId)))
                {
                    Prompt.notInDB("customer", customerId);
                    return;
                }
                if (RentalsTable.customerIsRenting(Int32.Parse(customerId)))
                {
                    Prompt.removalDependency("customer", "rental");
                    return;
                }

                CustomersTable.setDeleted(true, Int32.Parse(customerId));

                clearTextBoxes(removeCustomerPnl);
                //exit to admin panel
                setCurrentMainPanel(adminPnl);
            }catch
            {
                CustomersTable.adapter.Dispose();
                RentalsTable.adapter.Dispose();
                Prompt.dbError();
            }
        }