Beispiel #1
0
        private void btnSaveChanges_Click(object sender, EventArgs e) //when the 'Save Changes' button is clicked, it updates the database for any information that's been changed
        {
            clsDBConnector  dbConnector = new clsDBConnector();       //defines any variables needed
            OleDbDataReader dr;
            string          sqlStr;
            string          newCompanyName, newPostcode, newDefaultPassword, newCompanyEmail, newPassword;

            newCompanyName     = txtCompanyName.Text; //sets the variables as required
            newPostcode        = txtPostcode.Text;
            newDefaultPassword = txtDefaultPassword.Text;
            newCompanyEmail    = txtCompanyEmail.Text;
            newPassword        = txtPassword.Text;

            dbConnector.Connect();

            sqlStr = "UPDATE tblCompany " +
                     "SET companyName = '" + newCompanyName + "', hqPostcode = '" + newPostcode + "', defaultPassword = '******', companyEmail = '" + newCompanyEmail + "', companyPassword = '******'" +
                     " WHERE (tblCompany.CompanyID = " + companyID + ")"; //writes the SQL string

            dr = dbConnector.DoSQL(sqlStr);                               //executes the SQL string

            dr.Close();
            dbConnector.close();

            MessageBox.Show("Changes made."); //alerts the user of any changes made
            this.Close();                     //closes the form so no accidental changes can be made
        }
Beispiel #2
0
        private int getLowestAngle(DateTime dateTime) //finds the lowest angle
        {
            int lowestAngle = 0;

            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT MIN(tblGarmentStatus.angle) AS Expr1 " +
                     "FROM (((tblCompany INNER JOIN " +
                     "tblUser ON tblCompany.companyID = tblUser.companyID) INNER JOIN " +
                     "tblGarmentBirthCertificate ON tblUser.email = tblGarmentBirthCertificate.userEmail) INNER JOIN " +
                     "tblGarmentStatus ON tblGarmentBirthCertificate.masterMACAddress = tblGarmentStatus.masterMACAddress) " +
                     "HAVING (tblCompany.companyID = " + companyID + ") AND (tblGarmentStatus.[dateTime] >= #" + dateTime.ToString("MM/dd/yyyy 00:00:00") + "#) AND (tblGarmentStatus.[dateTime] < #" + (dateTime.AddDays(1).ToString("MM/dd/yyyy 00:00:00")) + "#)";

            dr = dbConnector.DoSQL(sqlStr);

            while (dr.Read())
            {
                lowestAngle = Convert.ToInt32(dr[0]);
            }

            dr.Close();
            dbConnector.close();

            return(lowestAngle);
        }
Beispiel #3
0
        private void setUpPage()
        {
            clsDBConnector  dbConnector = new clsDBConnector(); //sets the text boxes to what the company's current details are
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT companyName, hqPostcode, defaultPassword, companyEmail, companyPassword " +
                     "FROM tblCompany " +
                     "WHERE (companyID = " + companyID + ")"; //writes the SQL string

            dr = dbConnector.DoSQL(sqlStr);                   //executes the SQL string

            while (dr.Read())
            {
                txtCompanyName.Text     = dr[0].ToString(); //sets the variables to what they need to be
                txtPostcode.Text        = dr[1].ToString();
                txtDefaultPassword.Text = dr[2].ToString();
                txtCompanyEmail.Text    = dr[3].ToString();
                txtPassword.Text        = dr[4].ToString();
            }

            dr.Close();
            dbConnector.close();
        }
Beispiel #4
0
        private void setUpPage()
        {
            clsDBConnector  dbConnector = new clsDBConnector(); //finds all they relevant information needed about the company
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT companyID, companyName, defaultPassword " +
                     "FROM tblCompany " +
                     "WHERE (companyEmail = '" + company_email + "')"; //writes the SQL string

            dr = dbConnector.DoSQL(sqlStr);                            //executes the SQL string

            while (dr.Read())
            {
                company_ID       = Convert.ToInt32(dr[0]); //sets the required variables
                company_name     = dr[1].ToString();
                default_password = dr[2].ToString();
            }

            dr.Close();
            dbConnector.close();

            lblCompanyName.Text  = company_name; //sets the page up
            lblLoggedInTime.Text = "Logged in at " + Convert.ToString(DateTime.Now);
            lblOnlineTime.Text   = "0";
        }
Beispiel #5
0
        private void setUpGraph(DateTime chosenDate)
        {
            chart1.Series.Clear(); //draws a graph corresponding to the date and garment
            chart1.Series.Add("Angles");
            chart1.Series["Angles"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT tblGarmentStatus.angle, tblGarmentStatus.[dateTime] " +
                     "FROM (tblGarmentStatus INNER JOIN " +
                     "tblGarmentBirthCertificate ON tblGarmentStatus.masterMACAddress = tblGarmentBirthCertificate.masterMACAddress) " +
                     "WHERE (tblGarmentBirthCertificate.userEmail = '" + email + "') AND (tblGarmentStatus.masterMACAddress = '" + MACAddress + "')";

            dr = dbConnector.DoSQL(sqlStr);

            while (dr.Read())
            {
                DateTime theTime = Convert.ToDateTime(dr[1]);
                if (theTime.Date == chosenDate)
                {
                    chart1.Series["Angles"].Points.AddXY(theTime.ToString("HH:mm:ss"), dr[0]);
                }
            }

            dr.Close();
            dbConnector.close();
        }
Beispiel #6
0
        private void setUpPage()
        {
            int             i           = 0; //sets all the required variables
            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT email, firstName, surname " +
                     "FROM tblUser " +
                     "WHERE  (userTypeID = 1)"; //writes out the SQL string

            dr = dbConnector.DoSQL(sqlStr);     //executes the SQL string

            while (dr.Read())
            {
                Button btn = new Button();     //creates buttons for each superuser
                btn.BackColor = Color.DarkOrange;
                btn.ForeColor = Color.White;
                btn.Size      = new Size(100, 90);
                btn.Visible   = true;
                btn.Tag       = dr[0].ToString();
                btn.Text      = dr[1].ToString() + " " + dr[2].ToString();
                btn.Name      = "btn_ " + i;
                i++;
                btn.Click += btn_Click;
                flpEmployees.Controls.Add(btn);
            }

            dr.Close();
            dbConnector.close();
        }
Beispiel #7
0
        private int getEvents(DateTime dateTime, string eventType) //finds the number of critical events
        {
            int noOfEvents = 0;

            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT COUNT(tblTypeOfEvent.eventName) AS Expr1 " +
                     "FROM (((tblGarmentStatus INNER JOIN " +
                     "tblGarmentBirthCertificate ON tblGarmentStatus.masterMACAddress = tblGarmentBirthCertificate.masterMACAddress) INNER JOIN " +
                     "tblEvents ON tblGarmentStatus.garmentStatusID = tblEvents.garmentStatusID) INNER JOIN " +
                     "tblTypeOfEvent ON tblEvents.typeOfEventID = tblTypeOfEvent.typeOfEventID) " +
                     "HAVING (tblGarmentBirthCertificate.masterMACAddress = '" + MACAddress + "') AND (tblTypeOfEvent.eventName = '" + eventType + "') AND (tblGarmentBirthCertificate.userEmail = '" + email + "') AND (tblGarmentStatus.[dateTime] >= #" + dateTime.ToString("MM/dd/yyyy 00:00:00") + "#) AND (tblGarmentStatus.[dateTime] < #" + (dateTime.AddDays(1).ToString("MM/dd/yyyy 00:00:00")) + "#)";

            dr = dbConnector.DoSQL(sqlStr);

            while (dr.Read())
            {
                noOfEvents = Convert.ToInt32(dr[0]);
            }

            dr.Close();
            dbConnector.close();

            return(noOfEvents);
        }
Beispiel #8
0
        private void setUpPage() //sets up the combo box for a list of dates
        {
            List <garmentStatus> garmentList = new List <garmentStatus>();
            clsDBConnector       dbConnector = new clsDBConnector();
            OleDbDataReader      dr;
            string sqlStr;

            dbConnector.Connect();
            sqlStr = "SELECT Format(tblGarmentStatus.[dateTime], 'Short Date') AS Expr1 " +
                     "FROM ((tblGarmentStatus INNER JOIN " +
                     "tblGarmentBirthCertificate ON tblGarmentStatus.masterMACAddress = tblGarmentBirthCertificate.masterMACAddress) INNER JOIN " +
                     "tblUser ON tblGarmentBirthCertificate.userEmail = tblUser.email) " +
                     "WHERE ((tblGarmentBirthCertificate.MasterMACAddress = '" + MACAddress + "') AND (tblUser.email = '" + email + "')) " +
                     "GROUP BY Format(tblGarmentStatus.[dateTime], 'Short Date')";
            dr = dbConnector.DoSQL(sqlStr);
            while (dr.Read())
            {
                garmentList.Add(new garmentStatus {
                    dateAndTime = Convert.ToDateTime(dr[0])
                });
            }
            dr.Close();
            dbConnector.close();

            cmbGarmentStatuses.DisplayMember = "dateAndTime";
            cmbGarmentStatuses.ValueMember   = "dateAndTime";
            cmbGarmentStatuses.DataSource    = garmentList;
        }
Beispiel #9
0
        private void btnSaveChanges_Click(object sender, EventArgs e)
        {
            clsDBConnector  dbConnector = new clsDBConnector(); //defines any variables that are needed
            OleDbDataReader dr;
            string          sqlStr;
            string          newEmail, newFirstName, newSurname, newHouseNameNo, newPostcode, newPassword;
            int             newNestNo;
            DateTime        newDOB;

            newEmail       = txtEmail.Text; //sets the varibales to the required values
            newFirstName   = txtFirstName.Text;
            newSurname     = txtSurname.Text;
            newHouseNameNo = txtHouseNo.Text;
            newPostcode    = txtPostcode.Text;
            newPassword    = txtPassword.Text;
            newNestNo      = Convert.ToInt32(nudNestID.Value);
            newDOB         = dtpDOB.Value;

            dbConnector.Connect();

            sqlStr = "UPDATE tblUser " +
                     "SET email = '" + newEmail + "', [password] = '" + newPassword + "', firstName = '" + newFirstName + "', surname = '" + newSurname + "', dateOfBirth = '" + newDOB + "', nestID = " + newNestNo + ", postcode = '" + newPostcode + "', houseName = '" + newHouseNameNo + "'" +
                     " WHERE (tblUser.email = '" + email + "')"; //writes the SQL string

            dr = dbConnector.DoSQL(sqlStr);                      //executes the SQL string

            dr.Close();
            dbConnector.close();

            MessageBox.Show("Changes made."); //alerts the user that the changes have been made
            this.Close();                     //closes the form once changes are made
        }
Beispiel #10
0
        private int getHighestAngle(DateTime dateTime) //finds the highest angle
        {
            int highestAngle = 0;

            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT MAX(tblGarmentStatus.angle) AS Expr1 " +
                     "FROM (tblGarmentStatus INNER JOIN " +
                     "tblGarmentBirthCertificate ON tblGarmentStatus.masterMACAddress = tblGarmentBirthCertificate.masterMACAddress) " +
                     "HAVING (tblGarmentBirthCertificate.masterMACAddress = '" + MACAddress + "') AND (tblGarmentBirthCertificate.userEmail = '" + email + "') AND (tblGarmentStatus.[dateTime] >= #" + dateTime.ToString("MM/dd/yyyy 00:00:00") + "#) AND (tblGarmentStatus.[dateTime] < #" + (dateTime.AddDays(1).ToString("MM/dd/yyyy 00:00:00")) + "#)";


            dr = dbConnector.DoSQL(sqlStr);

            while (dr.Read())
            {
                highestAngle = Convert.ToInt32(dr[0]);
            }

            dr.Close();
            dbConnector.close();

            return(highestAngle);
        }
Beispiel #11
0
        private void setUpPage()
        {
            int             i           = 0; //defines all required variables
            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT masterMACAddress " +
                     "FROM tblGarmentBirthCertificate " +
                     "WHERE userEmail = '" + email + "'"; //writes the SQL string

            dr = dbConnector.DoSQL(sqlStr);

            while (dr.Read())
            {
                Button btn = new Button(); //creates a button for each company
                btn.BackColor = Color.DarkOrange;
                btn.ForeColor = Color.White;
                btn.Size      = new Size(100, 90);
                btn.Visible   = true;
                btn.Text      = dr[0].ToString();;
                btn.Name      = "btn_ " + i;
                i++;
                btn.Click += btn_Click;
                flpExistingGarments.Controls.Add(btn);
            }

            dr.Close();
            dbConnector.close();
        }
Beispiel #12
0
        private void setUpPage()
        {
            clsDBConnector  dbConnector = new clsDBConnector(); //sets any variables needed
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT [password], firstName, surname, dateOfBirth, nestID, postcode, houseName " +
                     "FROM tblUser " +
                     "WHERE (email = '" + email + "')"; //writes the SQL string

            dr = dbConnector.DoSQL(sqlStr);             //executes the SQL

            while (dr.Read())
            {
                txtEmail.Text     = email; //sets the text box values as required
                txtPassword.Text  = dr[0].ToString();
                txtFirstName.Text = dr[1].ToString();
                txtSurname.Text   = dr[2].ToString();
                dtpDOB.Value      = Convert.ToDateTime(dr[3]);
                nudNestID.Value   = Convert.ToInt32(dr[4]);
                txtPostcode.Text  = dr[5].ToString();
                txtHouseNo.Text   = dr[6].ToString();
            }

            dr.Close();
            dbConnector.close();
        }
        private void btnSaveChanges_Click(object sender, EventArgs e) //when the 'Save Changes' button is clicked, this updates the database for any information that's been changed
        {
            clsDBConnector  dbConnector = new clsDBConnector();       //defines required variables
            OleDbDataReader dr;
            string          sqlStr;
            string          newFirstName, newSurname, newHouseNameNo, newPostcode, newPassword;
            int             newNestNo;
            DateTime        newDOB;

            newFirstName   = txtFirstName.Text; //sets required variables
            newSurname     = txtSurname.Text;
            newHouseNameNo = txtHouseNo.Text;
            newPostcode    = txtPostcode.Text;
            newPassword    = txtPassword.Text;
            newNestNo      = Convert.ToInt32(nudNestID.Value);
            newDOB         = dtpDOB.Value;

            dbConnector.Connect();
            sqlStr = "UPDATE tblUser " +
                     "SET [password] = '" + newPassword + "', firstName = '" + newFirstName + "', surname = '" + newSurname + "', dateOfBirth = '" + newDOB +
                     "', nestID = " + newNestNo + ", postcode = '" + newPostcode + "', houseName = '" + newHouseNameNo + "'" +
                     " WHERE (tblUser.email = '" + email + "')"; //writes the SQL string
            dr = dbConnector.DoSQL(sqlStr);                      //executes the SQL
            dr.Close();
            dbConnector.close();

            MessageBox.Show("Changes made."); //alerts the user that the changes have been made
            this.Close();                     //closes the form to avoid trying to make the same changes twice
        }
Beispiel #14
0
        private void setUpPage()
        {
            int             i           = 0; //defines all required variables
            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT companyID, companyName " +
                     "FROM tblCompany "; //writes the SQL string

            dr = dbConnector.DoSQL(sqlStr);

            while (dr.Read())
            {
                Button btn = new Button(); //creates a button for each company
                btn.BackColor = Color.DarkOrange;
                btn.ForeColor = Color.White;
                btn.Size      = new Size(100, 90);
                btn.Visible   = true;
                btn.Tag       = dr[0].ToString();
                btn.Text      = dr[1].ToString();;
                btn.Name      = "btn_ " + i;
                i++;
                btn.Click += btn_Click;
                flpCompanies.Controls.Add(btn);
            }

            dr.Close();
            dbConnector.close();
        }
Beispiel #15
0
        private void setUpListBox(DateTime selectedDate)
        {
            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();
            sqlStr = "SELECT tblUser.email, tblUser.firstName, tblUser.surname, tblGarmentStatus.angle, tblEvents.eventID, tblTypeOfEvent.eventName " +
                     "FROM (((tblGarmentBirthCertificate INNER JOIN " +
                     "tblUser ON tblGarmentBirthCertificate.userEmail = tblUser.email) INNER JOIN " +
                     "tblGarmentStatus ON tblGarmentBirthCertificate.masterMACAddress = tblGarmentStatus.masterMACAddress) INNER JOIN " +
                     "(tblEvents INNER JOIN " +
                     "tblTypeOfEvent ON tblEvents.typeOfEventID = tblTypeOfEvent.typeOfEventID) ON tblGarmentStatus.garmentStatusID = tblEvents.garmentStatusID) " +
                     "WHERE (tblUser.companyID = " + companyID + ") AND (tblGarmentStatus.[dateTime] >= #" + selectedDate.ToString("MM/dd/yyyy 00:00:00") + "#) AND (tblGarmentStatus.[dateTime] < #" + (selectedDate.AddDays(1).ToString("MM/dd/yyyy 00:00:00")) + "#)";
            dr = dbConnector.DoSQL(sqlStr);
            lstEvents.Items.Clear();
            while (dr.Read())
            {
                lstEvents.Items.Add(dr[0].ToString());
                lstEvents.Items[lstEvents.Items.Count - 1].SubItems.Add(dr[1].ToString());
                lstEvents.Items[lstEvents.Items.Count - 1].SubItems.Add(dr[2].ToString());
                lstEvents.Items[lstEvents.Items.Count - 1].SubItems.Add(dr[3].ToString());
                lstEvents.Items[lstEvents.Items.Count - 1].SubItems.Add(dr[4].ToString());
                lstEvents.Items[lstEvents.Items.Count - 1].SubItems.Add(dr[5].ToString());
            }
            dr.Close();
            dbConnector.close();
        }
Beispiel #16
0
        private void getName()
        {
            clsDBConnector  dbConnector = new clsDBConnector(); //finds all they relevant information needed about the company
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT firstName, surname " +
                     "FROM tblUser " +
                     "WHERE (email = '" + email + "')"; //writes SQL code

            dr = dbConnector.DoSQL(sqlStr);             //executes the SQL string

            while (dr.Read())
            {
                name = dr[0].ToString() + " " + dr[1].ToString(); //sets the name
            }

            dr.Close();
            dbConnector.close();
        }
        private void setUpPage()
        {
            lblCompanyName.Text = company_name + " Employees"; //sets the title
            int i = 0;

            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;

            string sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT tblUser.email, tblUser.firstName, tblUser.surname " +
                     "FROM (tblCompany INNER JOIN " +
                     "tblUser ON tblCompany.companyID = tblUser.companyID) " +
                     "WHERE (tblCompany.companyID = " + company_ID + ")"; //writes the SQL string

            dr = dbConnector.DoSQL(sqlStr);                               //executes the SQL string

            while (dr.Read())
            {
                Button btn = new Button(); //creates a Flow Layout Pannel with a button for each employee
                btn.BackColor = Color.DarkOrange;
                btn.ForeColor = Color.White;
                btn.Size      = new Size(100, 90);
                btn.Visible   = true;
                btn.Tag       = dr[0].ToString();
                btn.Text      = dr[1].ToString() + " " + dr[2].ToString();
                btn.Name      = "btn_ " + i;
                i++;
                btn.Click += btn_Click;
                flpEmployees.Controls.Add(btn);
            }

            dr.Close();
            dbConnector.close();
        }
Beispiel #18
0
        private void setUpPage()                               //uses dynamic controls to view the names and ID's of all employees
        {
            lblCompanyName.Text = company_name + " Employees"; //sets the title of the page

            int             i           = 0;                   //defines all the required variables
            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT tblUser.email, tblUser.firstName, tblUser.surname " +
                     "FROM (tblCompany INNER JOIN " +
                     "tblUser ON tblCompany.companyID = tblUser.companyID) " +
                     "WHERE (tblCompany.companyID = " + company_ID + ")"; //writes the SQL string

            dr = dbConnector.DoSQL(sqlStr);                               //executes the SQL string

            while (dr.Read())
            {
                Button btn = new Button(); //sets up a button for each user
                btn.BackColor = Color.DarkOrange;
                btn.ForeColor = Color.White;
                btn.Size      = new Size(100, 90);
                btn.Visible   = true;
                btn.Tag       = dr[0].ToString();
                btn.Text      = dr[1].ToString() + " " + dr[2].ToString();
                btn.Name      = "btn_ " + i;
                i++;
                btn.Click += btn_Click;
                flpEmployees.Controls.Add(btn);
            }

            dr.Close();
            dbConnector.close();
        }
Beispiel #19
0
        private void setUpPage()                          //click on a nest ID to see its details & most recent status
        {
            lblCompanyName.Text = companyName + " Nests"; //sets the page title

            int             i           = 0;              //defines all required variables
            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();

            sqlStr = "SELECT tblNestBirthCertificate.NestID " +
                     "FROM (tblCompany INNER JOIN " +
                     "tblNestBirthCertificate ON tblCompany.companyID = tblNestBirthCertificate.companyID) " +
                     "WHERE (tblCompany.companyID = " + companyID + ")"; //writes the SQL string

            dr = dbConnector.DoSQL(sqlStr);                              //executes the sql string

            while (dr.Read())
            {
                Button btn = new Button(); //sets up buttons to show each nest
                btn.BackColor = Color.DarkOrange;
                btn.ForeColor = Color.White;
                btn.Size      = new Size(100, 90);
                btn.Visible   = true;
                btn.Tag       = dr[0].ToString();
                btn.Text      = dr[0].ToString();
                btn.Name      = "btn_ " + i;
                i++;
                btn.Click += btn_Click;
                flpEmployees.Controls.Add(btn);
            }

            dr.Close();
            dbConnector.close();
        }
Beispiel #20
0
        private string GetData(DateTime selectedDate)
        {
            string          dataToPrint = "";
            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string          sqlStr;

            dbConnector.Connect();
            sqlStr = "SELECT tblUser.email, tblGarmentStatus.angle, tblEvents.eventID, tblTypeOfEvent.eventName " +
                     "FROM (((tblGarmentBirthCertificate INNER JOIN " +
                     "tblUser ON tblGarmentBirthCertificate.userEmail = tblUser.email) INNER JOIN " +
                     "tblGarmentStatus ON tblGarmentBirthCertificate.masterMACAddress = tblGarmentStatus.masterMACAddress) INNER JOIN " +
                     "(tblEvents INNER JOIN " +
                     "tblTypeOfEvent ON tblEvents.typeOfEventID = tblTypeOfEvent.typeOfEventID) ON tblGarmentStatus.garmentStatusID = tblEvents.garmentStatusID) " +
                     "WHERE (tblUser.companyID = " + companyID + ") AND (tblGarmentStatus.[dateTime] >= #" + selectedDate.ToString("MM/dd/yyyy 00:00:00") + "#) AND (tblGarmentStatus.[dateTime] < #" + (selectedDate.AddDays(1).ToString("MM/dd/yyyy 00:00:00")) + "#)";
            dr = dbConnector.DoSQL(sqlStr);
            lstEvents.Items.Clear();
            dataToPrint = header;
            while (dr.Read())
            {
                dataToPrint = dataToPrint + string.Format("{0,-50}{1,-10}{2,-25}{3,-25}", dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString()) + "\n";
            }
            return(dataToPrint);
        }
Beispiel #21
0
        private void btnLogin_Click(object sender, EventArgs e) //when the 'Login' button is clicked
        {
            string          input_email, input_password;        //declares all variables needed
            clsDBConnector  dbConnector = new clsDBConnector();
            OleDbDataReader dr, drCompany;
            string          sqlStr;

            bool loggedin = false;          //this is to decide whether the user has or hasn't logged in so it knows whether to display an error message or not

            input_email    = txtEmail.Text; //takes the user inputs
            input_password = txtPassword.Text;

            dbConnector.Connect();

            if (rbSuperuser.Checked == true || rbUser.Checked == true)        //works out the type of user logging in
            {
                sqlStr = "SELECT email, [password], userTypeID FROM tblUser"; //states the sql statement

                dr = dbConnector.DoSQL(sqlStr);                               //executes the SQL statement

                while (dr.Read())
                {
                    if (input_email == dr[0].ToString() && input_password == dr[1].ToString()) //checks to see if the login credentials are correct
                    {
                        loggedin = true;
                        int userType = Convert.ToInt32(dr[2].ToString());

                        if (userType == 1) //opens the superuser homepage
                        {
                            frmSuperuserHomepage superuserHomepageForm = new frmSuperuserHomepage(input_email);
                            superuserHomepageForm.Show();
                        }

                        else if (userType == 2) //opens the ordinary user homepage
                        {
                            frmUserHomepage userHomepageForm = new frmUserHomepage(input_email);
                            userHomepageForm.Show();
                        }

                        this.Close();
                    }
                }

                dr.Close();
                dbConnector.close();
            }

            else if (rbCompany.Checked == true)
            {
                sqlStr = "SELECT companyEmail, companyPassword FROM tblCompany"; //states the sql statement

                drCompany = dbConnector.DoSQL(sqlStr);                           //executes the SQL statement

                while (drCompany.Read())
                {
                    if (input_email == drCompany[0].ToString() && input_password == drCompany[1].ToString()) //checks to see if the login credentials are correct
                    {
                        loggedin = true;

                        frmCompaniesHomepage companyHomepageForm = new frmCompaniesHomepage(input_email); //opens the companies homepage
                        companyHomepageForm.Show();

                        this.Close();
                    }
                }
            }

            if (!loggedin) //if they have not been logged in, an error message will show in the form of a message box
            {
                MessageBox.Show("Email, password or user type is incorrect. Please try again.");
                txtEmail.Clear();
                txtPassword.Clear();
            }

            dbConnector.close();
        }