Пример #1
0
        // navigates user back to the participants view window
        private void BtnBack_Click(object sender, RoutedEventArgs e)
        {
            ParticipantsView back = new ParticipantsView();

            back.Show();
            this.Close();
        }
Пример #2
0
        //users adds a new participant to the database
        private void BtnAddParticipant_Click(object sender, RoutedEventArgs e)
        {
            // A try catch statement that asks the user to input data first
            try
            {
                //temporary storage location for database columns
                int    id        = Convert.ToInt32(txtParticipantID.Text);
                string FirstName = txtFirstName.Text;
                string Surname   = txtSurname.Text;
                string Address1  = txtAddress1.Text;
                string Address2  = txtAddress2.Text;
                string Town      = txtTown.Text;
                string County    = txtCounty.Text;
                string Postcode  = txtPostcode.Text;
                string ContactNo = txtContactNo.Text;
                string DOB       = txtDOB.Text;
                //query that then inserts user inputs from the textboxes to the database
                string query = "Insert into Participants(ParticipantID, FirstName, Surname, Address1, Address2, Town, County, Postcode, ContactNo,DOB) Values " +
                               "(" + id + ", '" + FirstName + "', '" + Surname + "', '" + Address1 + "', '" + Address2 + "', '" + Town + "', '" + County + "', '" + Postcode + "', '" + ContactNo + "', '" + DOB + "')";

                //opens the connection to the datbase
                SQLiteConnection conn = new SQLiteConnection("Data Source = C:\\SQLite\\CAWT.db; Version = 3;");
                conn.Open();
                //runs the query and the closes the connection to the database
                SQLiteCommand cmd = new SQLiteCommand(query, conn);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Client Successfully added");
                conn.Close();
                //navigates the user back to the participants view window after user has been added
                ParticipantsView participant = new ParticipantsView();
                participant.Show();
                this.Close();
            }

            catch (Exception)
            {
                MessageBox.Show("Please enter some details");
            }
        }
Пример #3
0
        //creates an appointment and loads data into the appointments table on the database
        private void BtnMakeAppointment_Click(object sender, RoutedEventArgs e)
        {
            // A try catch statement that asks the user to input data first
            try
            {
                //creates a temporary storage location the users inputs
                int    id       = Convert.ToInt32(txtAppointmentID.Text);
                string Time     = txtTime.Text;
                string Date     = txtDate.Text;
                string Location = txtLocation.Text;
                int    Sid      = Convert.ToInt32(txtStaffID.Text);
                int    Pid      = Convert.ToInt32(txtParticipantID.Text);

                //inserts query that inserts the data into the appointments table on the database
                string query = "Insert into Appointments(AppointmentID, Time, Date, Location, StaffID, ParticipantID) Values " +
                               "(" + id + ", '" + Time + "', '" + Date + "', '" + Location + "', " + Sid + ", " + Pid + ")";

                //opens the database connection
                SQLiteConnection conn = new SQLiteConnection("Data Source = C:\\SQLite\\CAWT.db; Version = 3;");
                conn.Open();
                SQLiteCommand cmd = new SQLiteCommand(query, conn);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Appointment Successfully added");
                conn.Close();

                //navigates the user back to the participants view window after the insert is complete
                ParticipantsView back = new ParticipantsView();
                back.Show();
                this.Close();
            }

            catch (Exception)
            {
                MessageBox.Show("Please enter valid appointment details");
            }
        }
Пример #4
0
        //Login Button
        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            //Path for the database
            SQLiteConnection conn = new SQLiteConnection("Data Source = C:\\SQLite\\CAWT.db; Version = 3; ");

            // A try catch statement that asks the user to input data first
            try
            {
                //Opening the database connection
                conn.Open();
                //Query for the database that selects all users from the login table
                string        query = "Select * from Login where Username='******' and Password='******'";
                SQLiteCommand cmd   = new SQLiteCommand(query, conn);

                SQLiteDataReader reader = cmd.ExecuteReader();

                //creating the admin page requirements
                string password = "******";
                string userName, enterPassword;
                userName      = txtUsername.Text;
                enterPassword = txtPassword.Password;

                //setting the counter to 0 an incrementing it to check for different users
                int count = 0;
                while (reader.Read())
                {
                    count++;
                }

                //log in successfully
                if (count == 1)
                {
                    MessageBox.Show("Username and Password was correct");
                    conn.Close();

                    //directs user with the password "password" to the admin page
                    if (password.Equals(enterPassword))
                    {
                        MessageBox.Show("Welcome admin user");
                        MainWindow main = new MainWindow();
                        main.Show();
                        this.Close();
                    }
                    //directs all other users to the user page
                    else
                    {
                        ParticipantsView user = new ParticipantsView();
                        user.Show();
                        this.Close();
                    }
                }

                //tells the user at login that the username is a duplicate
                else if (count > 1)
                {
                    MessageBox.Show("Duplicate Username and Password, Try Again");
                }

                //tells the user that there login credientals are wrong and try again
                else if (count < 1)
                {
                    MessageBox.Show("Invalid, please try again");
                }
            }
            // error checker to check and display exceptions
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }