private void ExitButton_Click(object sender, EventArgs e)
        {
            MainScreenForm myMainScreenForm = new MainScreenForm();

            this.Hide();
            myMainScreenForm.Show();
        }
示例#2
0
        private void CustomersDeleteButton_Click(object sender, EventArgs e)
        {
            if (CustomersDataGridView.CurrentCell == null)
            {
                MessageBox.Show("Please select a customer to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string CS = ConfigurationManager.ConnectionStrings["U04i5a"].ConnectionString;
                using (MySqlConnection con = new MySqlConnection(CS))
                {
                    MySqlCommand cmd = new MySqlCommand();

                    //Set Foreign Key Checks to correct uCertify DB issues
                    cmd.CommandText = "SET FOREIGN_KEY_CHECKS = 0;DELETE FROM customer WHERE customerId = @customerId;SET FOREIGN_KEY_CHECKS = 1;";
                    cmd.Connection  = con;
                    con.Open();
                    cmd.Parameters.AddWithValue("@customerId", currentCustomerId);
                    cmd.ExecuteNonQuery();
                }
                MainScreenForm myMainScreenForm = new MainScreenForm();
                this.Hide();
                myMainScreenForm.Show();
            }
        }
        private void CancelButton_Click(object sender, EventArgs e)
        {
            MainScreenForm MyMainScreenForm = new MainScreenForm();

            this.Hide();
            MyMainScreenForm.Show();
        }
        private void SaveButton_Click(object sender, EventArgs e)
        {
            DateTime dateTimeNow  = DateTime.Now;
            string   strMaxFormat = dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss tt");//24 hours format hh gets 12 format

            try
            {
                if (NameTextBox.Text == "" || AddressTextBox.Text == "" || CityListBox.Text == "" ||
                    PostalCodeTextBox.Text == "" || PhoneNumberTextBox.Text == "")
                {
                    MessageBox.Show("Please enter values for all fields", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    string CS = ConfigurationManager.ConnectionStrings["U04i5a"].ConnectionString;
                    using (MySqlConnection con = new MySqlConnection(CS))
                    {
                        MySqlCommand cmd = new MySqlCommand();

                        cmd.CommandText = "INSERT INTO address (address, address2, cityId, postalCode, phone ) " +
                                          "VALUES (@AddressTextBox, @Address2TextBox, @CityId, @PostalCodeTextBox, @PhoneNumberTextBox);";
                        cmd.Connection = con;
                        con.Open();
                        cmd.Parameters.AddWithValue("@AddressTextBox", AddressTextBox.Text);
                        cmd.Parameters.AddWithValue("@Address2TextBox", Address2TextBox.Text);
                        cmd.Parameters.AddWithValue("@CityId", currentCityId);
                        cmd.Parameters.AddWithValue("@PostalCodeTextBox", PostalCodeTextBox.Text);
                        cmd.Parameters.AddWithValue("@PhoneNumberTextBox", PhoneNumberTextBox.Text);
                        cmd.ExecuteNonQuery();


                        cmd.CommandText = "INSERT INTO customer (customerName, addressId, active, createDate, createdBy, lastUpdateBy) " +
                                          "VALUES (@NameTextBox,@AddressId, @Active, @createDate, @createdBy, @lastUpdateBy);";
                        //gets the ID of the last inserted item.
                        long lastAddressId = cmd.LastInsertedId;

                        cmd.Connection = con;
                        cmd.Parameters.AddWithValue("@NameTextBox", NameTextBox.Text);
                        cmd.Parameters.AddWithValue("@AddressId", lastAddressId);
                        cmd.Parameters.AddWithValue("@Active", 1);
                        cmd.Parameters.AddWithValue("@CreateDate", Convert.ToDateTime(strMaxFormat).ToUniversalTime());
                        cmd.Parameters.AddWithValue("@CreatedBy", MainScreenForm.currentUser);
                        cmd.Parameters.AddWithValue("@LastUpdateBy", MainScreenForm.currentUser);
                        cmd.ExecuteNonQuery();
                    }
                    this.Close();
                    MainScreenForm myMainScreenForm = new MainScreenForm();
                    myMainScreenForm.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void SaveButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (NameTextBox.Text == "" || AddressTextBox.Text == "" || CityListBox.Text == "" ||
                    PostalCodeTextBox.Text == "" || PhoneNumberTextBox.Text == "")
                {
                    MessageBox.Show("Please enter values for all fields", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    string CS = ConfigurationManager.ConnectionStrings["U04i5a"].ConnectionString;
                    using (MySqlConnection con = new MySqlConnection(CS))
                    {
                        MySqlCommand cmd = new MySqlCommand();


                        cmd.CommandText = "UPDATE customer SET customerName = @NameTextBox, addressId = @AddressId WHERE customerId = @CustomerId;";
                        cmd.Connection  = con;
                        con.Open();
                        cmd.Parameters.AddWithValue("@CustomerId", MainScreenForm.currentCustomerId);
                        cmd.Parameters.AddWithValue("@addressId", MainScreenForm.currentAddressId);
                        cmd.Parameters.AddWithValue("@NameTextBox", NameTextBox.Text);
                        cmd.ExecuteNonQuery();


                        // SET FOREIGN_KEY_CHECKS = 0 and 1 at the end is to fix "Access denied to user" for the uCertify DB
                        cmd.CommandText = "SET FOREIGN_KEY_CHECKS = 0;UPDATE address SET address = @AddressTextBox, address2 = @Address2TextBox, cityId = @CurrentCityId, postalCode = @PostalCodeTextBox, phone = @PhoneNumberTextBox WHERE addressId = @AddressId; SET FOREIGN_KEY_CHECKS = 1;";
                        cmd.Connection  = con;
                        cmd.Parameters.AddWithValue("@AddressTextBox", AddressTextBox.Text);
                        cmd.Parameters.AddWithValue("@Address2TextBox", Address2TextBox.Text);
                        cmd.Parameters.AddWithValue("@CurrentCityId", currentCityId);
                        cmd.Parameters.AddWithValue("@PostalCodeTextBox", PostalCodeTextBox.Text);
                        cmd.Parameters.AddWithValue("@PhoneNumberTextBox", PhoneNumberTextBox.Text);
                        cmd.ExecuteNonQuery();
                        con.Close();
                    }
                    this.Close();
                    MainScreenForm myMainScreenForm = new MainScreenForm();
                    myMainScreenForm.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#6
0
 private void AppointmentsDeleteButton_Click(object sender, EventArgs e)
 {
     if (AppointmentsDataGridView.CurrentCell == null)
     {
         MessageBox.Show("Please select an appointment to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     else
     {
         string CS = ConfigurationManager.ConnectionStrings["U04i5a"].ConnectionString;
         using (MySqlConnection con = new MySqlConnection(CS))
         {
             MySqlCommand cmd = new MySqlCommand();
             cmd.CommandText = "DELETE FROM appointment WHERE appointmentId = @appointmentId";
             cmd.Connection  = con;
             con.Open();
             cmd.Parameters.AddWithValue("@appointmentId", currentAppointmentId);
             cmd.ExecuteNonQuery();
         }
         MainScreenForm myMainScreenForm = new MainScreenForm();
         this.Hide();
         myMainScreenForm.Show();
     }
 }
示例#7
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            //gives me the current time to input into the DB
            DateTime dateTimeNow  = DateTime.Now;
            string   strMaxFormat = dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss tt");//24 hours format hh gets 12 format

            try
            {
                DateTime newApptStart = Convert.ToDateTime(StartTimePicker.Text);
                DateTime xyz          = newApptStart.ToUniversalTime(); //datetime to adjust date
                var      s            = xyz.ToString("yyyy-MM-dd");


                DateTime newApptEnd       = Convert.ToDateTime(EndTimePicker.Text);
                var      newApptStartTime = newApptStart - newApptStart.Date;
                var      newApptEndTime   = newApptEnd - newApptEnd.Date;

                string query = "SELECT * from appointment where customerId = " + MainScreenForm.currentCustomerId
                               + " and start >= '" + s + " 00:00:00' and start < '" +
                               s + " 23:59:59'";

                string CS = ConfigurationManager.ConnectionStrings["U04i5a"].ConnectionString;

                DataTable dt = new DataTable();

                using (MySqlConnection con = new MySqlConnection(CS))
                {
                    con.Open();
                    MySqlCommand     cmd          = new MySqlCommand(query, con);
                    MySqlDataAdapter adaptToMySQL = new MySqlDataAdapter(selectCommand: cmd);
                    adaptToMySQL.Fill(dt);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        //changes the database time and date to local time
                        DateTime dbApptStart = (DateTime)dt.Rows[i]["start"];
                        dbApptStart = dbApptStart.ToLocalTime();
                        DateTime dbApptEnd = (DateTime)dt.Rows[i]["end"];
                        dbApptEnd = dbApptEnd.ToLocalTime();

                        var dbApptStartTime = dbApptStart - dbApptStart.Date;

                        var dbApptEndTime = dbApptEnd - dbApptEnd.Date;

                        if (Overlap(newApptStartTime, newApptEndTime, dbApptStartTime, dbApptEndTime))
                        {
                            break;
                        }
                    }
                }

                if (CustomerIdTextBox.Text == "" || DescriptionTextBox.Text == "" || TypeListBox.Text == "" || StartTimePicker.Text == "" || EndTimePicker.Text == "")
                {
                    MessageBox.Show("Please enter values for all fields", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (StartTimePicker.Value >= EndTimePicker.Value)
                {
                    MessageBox.Show("Start time must be before the end time", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (overlappingAppointment == 1)
                {
                    MessageBox.Show("The Appointment times cannot overlap", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    overlappingAppointment = 0;
                }
                else
                {
                    using (MySqlConnection con = new MySqlConnection(CS))
                    {
                        MySqlCommand cmd = new MySqlCommand();
                        cmd.CommandText = "SET FOREIGN_KEY_CHECKS = 0; UPDATE appointment SET appointmentId = @AppointmentId, customerId = @CustomerId, description = @Description, type = @TypeListBox, start = @StartTimePicker, end = @EndTimePicker WHERE appointmentId = @AppointmentId; SET FOREIGN_KEY_CHECKS = 1;";
                        cmd.Connection  = con;
                        con.Open();
                        cmd.Parameters.AddWithValue("@AppointmentId", MainScreenForm.currentAppointmentId);
                        cmd.Parameters.AddWithValue("@CustomerId", CustomerIdTextBox.Text);
                        cmd.Parameters.AddWithValue("@Description", DescriptionTextBox.Text);
                        cmd.Parameters.AddWithValue("@TypeListBox", TypeListBox.Text);
                        cmd.Parameters.AddWithValue("@StartTimePicker", Convert.ToDateTime(StartTimePicker.Value).ToUniversalTime());
                        cmd.Parameters.AddWithValue("@EndTimePicker", Convert.ToDateTime(EndTimePicker.Value).ToUniversalTime());
                        cmd.Parameters.AddWithValue("@CreateDate", MainScreenForm.today3);
                        cmd.ExecuteNonQuery();
                        con.Close();
                    }
                    this.Close();
                    MainScreenForm myMainScreenForm = new MainScreenForm();
                    myMainScreenForm.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void SignInButton_Click(object sender, EventArgs e)
        {
            DateTime dateTimeNow  = DateTime.Now;
            string   strMaxFormat = dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss tt");//24 hours format hh gets 12 format

            try
            {
                if (UsernameTextBox.Text == DbUserName && PasswordTextBox.Text == DbPassword)
                {
                    try
                    {
                        //logs the login information
                        //saves for me at: C:\Users\joshu\Google Drive\Visual Studio Projects\C969 Scheduling Software Project_05312019\C969 Scheduling Software Project\bin\Debug\C969SchedulingSoftwareProjectLogin.txt
                        FileStream outp = new FileStream(fileName, FileMode.Append, FileAccess.Write);
                        fileWriter = new StreamWriter(outp);
                        fileWriter.WriteLine("Time of login: "******".   Current Logged in user: "******".   Login was a success!");
                        fileWriter.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Cannot write to local file");
                    }



                    //checks for an appointment within 15 minutes of login
                    MySqlConnection con1 = new MySqlConnection(ConfigurationManager.ConnectionStrings["U04i5a"].ConnectionString);

                    MySqlCommand cmd1 = new MySqlCommand("SELECT * from appointment;", con1);
                    con1.Open();
                    MySqlDataAdapter adapter1 = new MySqlDataAdapter(cmd1);

                    DataTable dt = new DataTable();
                    adapter1.Fill(dt);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        //changes the database time and date to local time
                        DateTime dbApptStart = (DateTime)dt.Rows[i]["start"];
                        dbApptStart = dbApptStart.ToLocalTime();

                        TimeSpan span = dbApptStart.Subtract(dateTimeNow);
                        Console.WriteLine("Time Difference (minutes): " + span.TotalMinutes);

                        if (span.TotalMinutes < 15 && span.TotalMinutes > 0)
                        {
                            MessageBox.Show("You have an appointment within 15 minutes.");
                            break;
                        }
                    }
                    MainScreenForm MyMainScreenForm = new MainScreenForm();
                    this.Hide();
                    MyMainScreenForm.Show();
                }
                else
                {
                    try
                    {
                        //logs the login information
                        //saves for me at: C:\Users\joshu\Google Drive\Visual Studio Projects\C969 Scheduling Software Project_05312019\C969 Scheduling Software Project\bin\Debug\C969SchedulingSoftwareProjectLogin.txt
                        FileStream outp = new FileStream(fileName, FileMode.Append, FileAccess.Write);
                        fileWriter = new StreamWriter(outp);
                        fileWriter.WriteLine("Time of login: "******".   Current Logged in user: "******".   Login was not a success!");
                        fileWriter.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Cannot write to local file");
                    }


                    //login error information to the user
                    MessageBox.Show(ErrorMessage, FormType, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    UsernameTextBox.Clear();
                    PasswordTextBox.Clear();
                    return;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }