Esempio n. 1
0
        private void buttonBuyItems_Click(object sender, EventArgs e)
        {
            // Get the customer id
            int customerID = DBWIDGET.RetrieveSingleID("SELECT c.customer_id FROM customer c, person p WHERE p.person_id = c.customer_id AND p.fname = '" + username + "'");

            foreach (IcecreamItem i in items)
            {
                // Get the icecream id
                int iceCreamID = DBWIDGET.RetrieveSingleID("SELECT i.ice_cream_id FROM ice_cream i WHERE i.flavour = '" + i.flavour + "'");

                //Set the date
                DateTime dateTime      = new DateTime(2018, 6, 11, 8, 27, 0);
                string   formattedDate = dateTime.ToString("d"); //?
                string   formattedTime = dateTime.ToString("T");

                int amountToMake = i.amount;

                for (int j = 0; j < amountToMake; j++)
                {
                    //Do an SQL query to add the items to be delivered, etc (requires a lot of linking with drivers and factories, etc)
                    // 1- Customer to Icecream via orders
                    DBWIDGET.Insert("INSERT into orders(date_ordered, time_ordered, ice_cream_id, customer_id) VALUES(to_date('" + formattedDate + "', 'MM/DD/YYYY'), '" + formattedTime + "', " + iceCreamID + ", " + customerID + ")");
                }
                // 2- Create a delivery truck?
                // 3- connect delivery truck to this icecream order?
            }

            //Tell the user the items will be delivered ... etc
            MessageBox.Show("Items have been brought. Will be delivered in ** days");

            //Close this window
            this.Close();
        }
Esempio n. 2
0
        private void buttonAddProduct_Click(object sender, EventArgs e)
        {
            // Add a new product from the DB
            string flavour     = textBoxFlavour.Text;
            string amountMade  = textBoxIcecreamMade.Text;
            string factoryname = comboBoxSelectFactory.Text;

            //get the last index value
            int nextIndex = DBWIDGET.getDBSize("SELECT count(*) FROM ice_cream");

            //get the id of the factory
            int factoryID = DBWIDGET.RetrieveSingleID("SELECT f.factory_id FROM factory f WHERE f.flocation = '" + factoryname + "'");

            //Do an SQL insert to add a new icecream to the DB
            DBWIDGET.Insert("INSERT into ice_cream (ice_cream_id, flavour, amount_made) VALUES(" + nextIndex + ", '" + flavour + "', " + amountMade + ")");
            DBWIDGET.Insert("INSERT into makes (factory_id, ice_cream_id) VALUES(" + factoryID + ", " + nextIndex + ")");

            this.Close();
        }
        private void buttonAddUser_Click(object sender, EventArgs e)
        {
            string firstname = textBoxFirstname.Text;
            string lastname = textBoxLastname.Text;
            string phoneNumber = textBoxPhone.Text;
            string streetAddress = textBoxStreet.Text;
            string city = textBoxCity.Text;
            string postcode = textBoxPostcode.Text;
            string factoryName = comboBoxFactoryNames.Text;

            bool isFilledIn = false;
            bool isUsernameFree = false;
            bool isSuccessfulAdd = false;

            //Check all textbox's - only continue if they are filled - otherwise tell the user
            if (string.IsNullOrWhiteSpace(firstname))
                isFilledIn = false;
            else if (string.IsNullOrWhiteSpace(lastname))
                isFilledIn = false; 
            else if (string.IsNullOrWhiteSpace(phoneNumber))
                isFilledIn = false;
            else if (string.IsNullOrWhiteSpace(streetAddress))
                isFilledIn = false;
            else if (string.IsNullOrWhiteSpace(city))
                isFilledIn = false;
            else if (string.IsNullOrWhiteSpace(postcode))
                isFilledIn = false;
            else if (string.IsNullOrWhiteSpace(factoryName))
                isFilledIn = false;
            else
                isFilledIn = true;

            if (isFilledIn)
            {
                //Do an SQL check to see if username is free to use - edit "isUsernameFree"
                isUsernameFree = !DBWIDGET.itemExists("SELECT * FROM Person WHERE fname='" + firstname + "'");

                if (isUsernameFree)
                {
                    //Do an SQL statement to get the last Person ID, then + 1 to it
                    int nextID = DBWIDGET.getDBSize("SELECT count(*) FROM Person") + 1;

                    //get the manager ID for the selected factory
                    int managerID = DBWIDGET.RetrieveSingleID("SELECT m.management_id FROM managementi m, owns o, factory f WHERE o.factory_id = f.factory_id AND o.manager_id = m.management_id AND f.flocation = '" + factoryName + "'");

                    //Do an SQL insert to add a new user - if successful then edit "isSuccessfulAdd"
                    isSuccessfulAdd = DBWIDGET.Insert("INSERT INTO Person (person_ID, fname, lname, Phone_number, Street_Address, City, Postcode) VALUES (" + nextID + ", '" + firstname + "', '" + lastname + "', '" + phoneNumber + "', '" + streetAddress + "', '" + city + "', '" + postcode + "')");

                    //then add them as a driver
                    DBWIDGET.Insert("INSERT INTO driver (driver_id) VALUES (" + nextID + ")");

                    //as employed by management who owns factory selected
                    DBWIDGET.Insert("INSERT into employs (manager_id, driver_id) VALUES (" + managerID + ", " + nextID + ")");

                    if (isSuccessfulAdd)
                    {
                        //close form
                        this.Close();
                    }
                    else
                    {
                        //Tell the user there has been an error
                        MessageBox.Show("Error on user profile addition. Contact System Admin");
                    }
                }
                else
                {
                    //Username is taken
                    MessageBox.Show("Username is taken. Please enter a new first/user name");
                    textBoxFirstname.Clear();
                    textBoxFirstname.Focus();
                }
            }
            else
            {
                //Need to fill in all boxes
                MessageBox.Show("Please fill in all areas.");
            }
        }