Example #1
0
        // Return to the Edit Database form
        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.Visible = false;

            EditDatabase form = new EditDatabase();

            form.Show();

            this.Dispose();
        }
Example #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            // Prompt for changes
            if (MessageBox.Show("Are you sure you want to change this student's information?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                SQLiteConnection connect = new SQLiteConnection(Login.connection);

                // Update the database
                try
                {
                    String[] queries = new String[3];

                    queries[0] = "UPDATE Students SET FirstName = @FirstName, LastName = @LastName, PID = @PID WHERE PID = '" + textBoxPID.Text + "';";
                    queries[1] = "UPDATE HISTORY SET PID = @PID WHERE PID = '" + textBoxPID.Text + "';";
                    queries[2] = "UPDATE CheckOut SET PID = @PID WHERE PID = '" + textBoxPID.Text + "';";

                    foreach (String query in queries)
                    {
                        SQLiteCommand cmd = new SQLiteCommand(query, connect);
                        connect.Open();
                        cmd.Parameters.AddWithValue("@FirstName", textBoxNewFirstName.Text);
                        cmd.Parameters.AddWithValue("@LastName", textBoxNewLastName.Text);
                        cmd.Parameters.AddWithValue("@PID", textBoxNewPID.Text);
                        cmd.ExecuteNonQuery();
                        connect.Close();
                    }
                }
                catch (SQLiteException exp)
                {
                    MessageBox.Show(exp.Message.ToString());
                }
                finally
                {
                    if (connect.State == ConnectionState.Open)
                    {
                        connect.Close();
                    }
                }

                // Refresh back to Edit Database once record is updated
                this.Visible = false;

                EditDatabase form = new EditDatabase();
                form.Show();

                this.Dispose();
            }
            else
            {
                // Do Nothing and discard changes
            }
        }
Example #3
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            // Necessary code for PID error checking
            int PIDparse;
            int pid = Int32.Parse(textBoxPID.Text);

            // Check for any blank fields
            if (string.IsNullOrWhiteSpace(textBoxNewDevice.Text))
            {
                MessageBox.Show("Please type in the device name.");
            }

            if (string.IsNullOrWhiteSpace(textBoxNewSerial.Text))
            {
                MessageBox.Show("Please use the scanner or manually input the device serial number.");
            }

            if (string.IsNullOrWhiteSpace(textBoxNewCheckOut.Text))
            {
                MessageBox.Show("Please indicate the correct check out date.");
            }

            if (string.IsNullOrWhiteSpace(textBoxNewDueDate.Text))
            {
                MessageBox.Show("Please indicate the correct due date.");
            }

            if (string.IsNullOrWhiteSpace(textBoxNewCheckIn.Text))
            {
                MessageBox.Show("Please indicate the correct check in date.");
            }

            if (string.IsNullOrWhiteSpace(textBoxNewDueDate.Text))
            {
                MessageBox.Show("Please indicate the correct due date.");
            }


            // Verify that the PID is approprite in length and type (6 numbers)
            else if (string.IsNullOrWhiteSpace(textBoxNewPID.Text))
            {
                MessageBox.Show("Please enter the student's PID.");
            }
            else if (textBoxNewPID.Text.Length != 6 || !int.TryParse(textBoxNewPID.Text, out PIDparse))
            {
                MessageBox.Show("The PID entered was not valid. Please enter a valid PID (6 numbers long)");
            }

            else
            {
                // Prompt for changes
                if (MessageBox.Show("Are you sure you want to change the information in the database?", "Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    SQLiteConnection connect = new SQLiteConnection(Login.connection);

                    // Make changes according to the info in the New Information text boxes
                    try
                    {
                        String[] queries = new String[2];
                        queries[0] = "UPDATE History SET CheckOutDate = @CheckOutDate, DueDate = @DueDate, Assets = @Assets, Comments = @Comments, CheckInDate = @CheckInDate, ReturnComments = @ReturnComments " +
                                     "WHERE PID = '" + textBoxPID.Text + "' AND CheckOutDate = '" + textBoxCheckOut.Text + "';";
                        queries[1] = "UPDATE CheckOut SET CheckOutDate = @CheckOutDate, DueDate = @DueDate, Assets = @Assets, Comments = @Comments " +
                                     "WHERE CheckOutDate = '" + textBoxCheckOut.Text + "';";

                        foreach (String query in queries)
                        {
                            SQLiteCommand cmd = new SQLiteCommand(query, connect);
                            connect.Open();

                            cmd.Parameters.AddWithValue("@CheckOutDate", textBoxNewCheckOut.Text);
                            cmd.Parameters.AddWithValue("@DueDate", textBoxNewDueDate.Text);
                            cmd.Parameters.AddWithValue("@CheckInDate", textBoxNewCheckIn.Text);
                            cmd.Parameters.AddWithValue("@Comments", textBoxNewComments.Text);
                            cmd.Parameters.AddWithValue("@Assets", textBoxNewAsset.Text);
                            cmd.Parameters.AddWithValue("@ReturnComments", textBoxNewReturnComments.Text);
                            cmd.ExecuteNonQuery();
                            connect.Close();
                        }
                    }
                    catch (SQLiteException exp)
                    {
                        MessageBox.Show(exp.Message.ToString());
                    }
                    finally
                    {
                        if (connect.State == ConnectionState.Open)
                        {
                            connect.Close();
                        }
                    }

                    // Refresh back to Home after New Check Out is completed
                    this.Visible = false;

                    EditDatabase form = new EditDatabase();
                    form.Show();

                    this.Dispose();
                }
                else
                {
                    // Discard changes
                }
            }
        }