// Close Button click private void reportCloseButton_Click(object sender, EventArgs e) { // Show main form and close this form DataInterface.DBClose(); mainForm.Show(); MainForm.customerReport.Close(); }
// Save Button Click private void customerSaveButton_Click(object sender, EventArgs e) { // Check if inputs are valid if (validateInputs()) { // attempt to save update customer entry try { // Pass data from form to update customer query DataInterface.updateCustomer( Convert.ToInt32(customerIDTextBox.Text), customerNameTextBox.Text, customerAddressTextBox.Text, customerCityTextBox.Text, customerCountryTextBox.Text, customerZipCodeTextBox.Text, customerPhoneTextBox.Text, customerActiveCheckBox.Checked, customerAddress2TextBox.Text); DataInterface.DBClose(); CustomerMainForm.editCustomer = this; customerForm.Show(); CustomerMainForm.editCustomer.Close(); } // Display message and cancel save if an exception rises catch (Exception ex) { MessageBox.Show(ex.Message); return; } } }
// Cancel Button - Return to MainForm private void appointmentCancelButton_Click(object sender, EventArgs e) { // Close database, set MainForms form to this form, show MainForm again, close this form DataInterface.DBClose(); MainForm.addAppointmentForm = this; mainForm.Show(); MainForm.addAppointmentForm.Close(); }
// Consultant Report Button Click private void consultantReportButton_Click(object sender, EventArgs e) { // Open new Consultant Report Form DataInterface.DBClose(); consultantReport = new ConsultantReportForm(); ConsultantReportForm.mainForm = this; consultantReport.Show(); }
// Cancel Button click private void customerCancelButton_Click(object sender, EventArgs e) { // Show CustomerMainForm, close this form DataInterface.DBClose(); CustomerMainForm.editCustomer = this; customerForm.Show(); CustomerMainForm.editCustomer.Close(); }
// Cancel Button Click private void appointmentCancelButton_Click(object sender, EventArgs e) { // Show MainForm again, close this form DataInterface.DBClose(); MainForm.updateAppointmentForm = this; mainForm.Show(); MainForm.updateAppointmentForm.Close(); }
// Customer Report Button Click private void customerReportButton_Click(object sender, EventArgs e) { // Open new Customer Report DataInterface.DBClose(); customerReport = new CustomerReportForm(); CustomerReportForm.mainForm = this; customerReport.Show(); }
// Add Button Click private void mainAddButton_Click(object sender, EventArgs e) { DataInterface.DBClose(); AddAppointmentForm appointmentForm = new AddAppointmentForm(); AddAppointmentForm.mainForm = this; appointmentForm.Show(); }
// Month Report Button Click private void button1_Click(object sender, EventArgs e) { // Open new MonthReportForm DataInterface.DBClose(); monthReport = new MonthReportForm(); MonthReportForm.mainForm = this; monthReport.Show(); }
// Edit Button Click private void customerEditButton_Click(object sender, EventArgs e) { // Open new edit customer form and set reference DataInterface.DBClose(); editCustomer = new EditCustomerForm(); EditCustomerForm.customerForm = this; editCustomer.Show(); }
// Add Button Click private void customerAddButton_Click(object sender, EventArgs e) { // open add customer form DataInterface.DBClose(); addCustomer = new AddCustomerForm(); AddCustomerForm.customerForm = this; addCustomer.Show(); }
// Back Button Click private void customerBackButton_Click(object sender, EventArgs e) { // Return to main form, close this form DataInterface.DBClose(); MainForm.customerForm = this; mainForm.Show(); MainForm.customerForm.Close(); }
// Edit Button Click private void mainEditButton_Click(object sender, EventArgs e) { // Attempt to selected row try { DataInterface.DBClose(); updateAppointmentForm = new EditAppointmentForm(); EditAppointmentForm.mainForm = this; updateAppointmentForm.Show(); } // If unable to locate Appointment Data, display Exception message catch (DataNotFoundException ex) { MessageBox.Show(ex.Message); } }
// Populate DataGridView with appointment data public void displayAppointments() { // Clear DataTable of any prior information appointmentsDT.Clear(); String query = ""; // Obtain selected date from MonthCalendar DateTime selectedDate = appointmentCalendar.SelectionRange.Start.ToUniversalTime(); // Determine sunday and saturday for week view, convert to universal time for accurate comparison to DB values DateTime sunday = selectedDate.AddDays(-(int)selectedDate.DayOfWeek).ToUniversalTime(); DateTime saturday = selectedDate.AddDays(-(int)selectedDate.DayOfWeek + (int)DayOfWeek.Saturday).ToUniversalTime(); // Check which view is selected and query data accordingly if (dgvViewMonthRadioButton.Checked) { query = $"SELECT a.appointmentId AS ID, c.customerName AS 'Customer Name', a.title AS Title, a.start AS Start, a.end AS End FROM appointment AS a, customer AS c WHERE c.customerId = a.customerId AND MONTH(a.start) = '{appointmentCalendar.SelectionStart.Month}' AND YEAR(a.start) = '{appointmentCalendar.SelectionStart.Year}' AND a.createdBy = '{DataInterface.getCurrentUserName()}' ORDER BY a.start"; } else if (dgvViewWeekRadioButton.Checked) { query = $"SELECT a.appointmentId AS ID, c.customerName AS 'Customer Name', a.title AS Title, a.start AS Start, a.end AS End FROM appointment AS a, customer AS c WHERE c.customerId = a.customerId AND a.start >= '{sunday.ToString("yyyy-MM-dd hh:MM:ss")}' - INTERVAL 3 MINUTE AND a.start < '{saturday.AddHours(24).ToString("yyyy-MM-dd hh:MM:ss")}' - INTERVAL 3 MINUTE AND a.createdBy = '{DataInterface.getCurrentUserName()}' ORDER BY a.start"; } else if (dgvViewDayRadioButton.Checked) { query = $"SELECT a.appointmentId AS ID, c.customerName AS 'Customer Name', a.title AS Title, a.start AS Start, a.end AS End FROM appointment AS a, customer AS c WHERE c.customerId = a.customerId AND a.start >= '{selectedDate.ToString("yyyy-MM-dd hh:MM:ss")}' - INTERVAL 3 MINUTE AND a.start < '{selectedDate.AddHours(24).ToString("yyyy-MM-dd hh:MM:ss")}' - INTERVAL 3 MINUTE AND a.createdBy = '{DataInterface.getCurrentUserName()}' ORDER BY a.start"; } // Execute query and fill DataTable DataInterface.DBOpen(); MySqlDataAdapter adp = new MySqlDataAdapter(query, DataInterface.conn); MySqlCommandBuilder cmd = new MySqlCommandBuilder(adp); adp.Fill(appointmentsDT); // Convert start and end times to local time DataInterface.convertToLocal(appointmentsDT, "Start"); DataInterface.convertToLocal(appointmentsDT, "End"); // Set DataSource for DataGridView to display data within DataTable appointmentsDGV.DataSource = appointmentsDT; appointmentsDGV.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; DataInterface.DBClose(); }
// Login Button CLick private void loginLoginButton_Click(object sender, EventArgs e) { // Obtain login information string userName = loginUsernameTextBox.Text; string password = loginPasswordTextBox.Text; int userID; // Check if username or password are empty if (String.IsNullOrWhiteSpace(loginUsernameTextBox.Text) || String.IsNullOrWhiteSpace(loginPasswordTextBox.Text)) { // Display appropriate message based on language if (currentCulture == "fr-FR") { MessageBox.Show("Le nom d'utilisateur et le mot de passe ne peuvent pas être vides"); } else { MessageBox.Show("Username and password cannot be empty"); } return; } // Open database connection DataInterface.DBOpen(); // Build Query MySqlCommand cmd = new MySqlCommand($"SELECT userId FROM user WHERE userName = '******' AND password = '******'", DataInterface.conn); MySqlDataReader reader = cmd.ExecuteReader(); // If matching data is present, set current user information and open MainForm if (reader.HasRows) { // Read rows returned reader.Read(); // Set userID based on row returned userID = Convert.ToInt32(reader[0]); // set current user information DataInterface.setCurrentUserID(userID); DataInterface.setCurrentUserName(userName); // close database connection reader.Close(); DataInterface.DBClose(); // Hide Login form and open MainForm MainForm mainForm = new MainForm(); MainForm.loginForm = this; this.Hide(); mainForm.Show(); loginUsernameTextBox.Text = ""; loginPasswordTextBox.Text = ""; recordLogin(DataInterface.getCurrentUserName()); } // Username/Password do not match information in database else { // Dipslay language appropriate error message MessageBox.Show(errorMessage); loginPasswordTextBox.Text = ""; } }
// Close Button Click private void reportCloseButton_Click(object sender, EventArgs e) { DataInterface.DBClose(); mainForm.Show(); MainForm.consultantReport.Close(); }