// Class Methods /// <summary> /// Gets a list of Addresses, and updates the list with Database info /// </summary> /// <param name="addresses"></param> public void fillAddressDropdown(List <Address> addresses) { using (var conn = new MySqlConnection(connecterString)) { MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM address"; MySqlDataReader reader1 = DataChanges.GetMySqlReader(conn, cmd.CommandText); //Use this to see if the country exists, and to count the number of countries while (reader1.Read()) { var AddressId = (int)reader1["addressId"]; var Address1 = reader1["address"].ToString(); var Address2 = reader1["address2"].ToString(); var CityId = (int)reader1["cityId"]; var PostalCode = reader1["postalCode"].ToString(); var Phone = reader1["phone"].ToString(); var CreatedBy = reader1["createdBy"].ToString(); var LastUpdateBy = reader1["lastUpdateBy"].ToString(); Address myAddress = new Address(AddressId, Address1, Address2, CityId, PostalCode, Phone, CreatedBy, LastUpdateBy); addresses.Add(myAddress); } conn.Close(); cmd.Connection.Close(); foreach (var addr in addresses) { // Populate a new row on the combobox comboBox_AddressPopulate.Items.Add(addr.address.ToString() + ", " + addr.address2.ToString()); // fill the city object for the address object addr.cityObject = new City(addr.cityId, loggedInUser, conn); } //Set the list equal to the class list Addresses = addresses; } }
/// <summary> /// Loads all the lists and variables needed to create reports /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Frm_Reports_Load(object sender, EventArgs e) { comboBox_SelectReport.Items.Add(reportAppointmentMonthOption); comboBox_SelectReport.Items.Add(reportConsultantScheduleOption); comboBox_SelectReport.Items.Add(reportCustomerAppointmentsOption); //Load all appointments into Lists to be able to search them quickly once this loads using (var conn = new MySqlConnection(connecterString)) { string getAppointments = "SELECT * FROM appointment"; var reader = DataChanges.GetMySqlReader(conn, getAppointments); while (reader.Read()) { //Fill Appointment Object Minus the Customer object Appointment appointment = new Appointment(); appointment.appointmentId = (int)reader["appointmentId"]; appointment.customerId = (int)reader["customerId"]; appointment.title = reader["title"].ToString(); appointment.description = reader["description"].ToString(); appointment.location = reader["location"].ToString(); appointment.contact = reader["contact"].ToString(); appointment.start = Convert.ToDateTime(reader["start"]); appointment.end = Convert.ToDateTime(reader["end"]); appointment.createDate = Convert.ToDateTime(reader["createDate"]); appointment.createdBy = reader["createdBy"].ToString(); appointment.lastUpdate = Convert.ToDateTime(reader["lastUpdate"]); appointment.lastUpdateBy = reader["lastUpdateBy"].ToString(); appointment.type = reader["appointmentType"].ToString(); appointment.userId = (int)reader["userId"]; //Add Appointment to list of Appointments one by one appointments.Add(appointment); } reader.Close(); foreach (var appointment in appointments) { appointment.customerObject = customers.Where(i => i.customerID == appointment.customerId).First(); } //Load all Users into a list to be able to search those quickly string getUsersQuery = "SELECT * FROM user"; var usersReader = DataChanges.GetMySqlReader(conn, getUsersQuery); while (usersReader.Read()) { User readUser = new User(); readUser.userId = (int)usersReader["userId"]; readUser.userName = usersReader["userName"].ToString(); users.Add(readUser); } usersReader.Close(); } //Load all Customer Names and ID's (This is being done in Main Form when this form is created) }
/// <summary> /// Loads Needed information when form is loading /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddAppointment_Load(object sender, EventArgs e) { timeZoneName = selectedTimeZone; using (var conn = new MySqlConnection(connecterString)) { //Load list of customers customers = new List <Customer>(); string getCustomersQuery = "SELECT * FROM customer WHERE active = 1"; var reader = DataChanges.GetMySqlReader(conn, getCustomersQuery); while (reader.Read()) { int customerId = (int)reader["customerId"]; string customerName = reader["customerName"].ToString(); int addressId = (int)reader["addressId"]; bool active = (bool)reader["active"]; string createdBy = reader["createdBy"].ToString(); string lastUpdateBy = reader["lastUpdateBy"].ToString(); Customer customer = new Customer(customerId, customerName, addressId, active, createdBy, lastUpdateBy); customers.Add(customer); } conn.Close(); foreach (var customer in customers) { comboBox_CustomerSelect.Items.Add(customer.customerID.ToString() + " - " + customer.customerName); } //Fill in Locations Dropdown with a few Appointment Types for the consulting company. Sales Call, comboBox_SelectLocation.Items.Add(phoenixLocation); comboBox_SelectLocation.Items.Add(newYorkLocation); comboBox_SelectLocation.Items.Add(londonLocation); /*Fill in Appointment Types Dropdown * - Introduction call(from referral/ Sign Up from sales department/ website) * - Regular Consulting Meeting * - Evaluation Meeting * - Discharge Meeting */ comboBox_AppointmentType.Items.Add("Introduction Call"); comboBox_AppointmentType.Items.Add("Regular Consulting Meeting"); comboBox_AppointmentType.Items.Add("Evaluation Meeting"); comboBox_AppointmentType.Items.Add("Discharge Meeting"); if (selectedAppointmentId != 0) { //set to update if appointment was selected to edit Text = "Update Appointment"; Btn_Add.Text = "Update"; //Fill in form Txt_AppointmentId.Text = selectedAppointment.appointmentId.ToString(); Txt_Title.Text = selectedAppointment.title; Txt_Description.Text = selectedAppointment.description; var location = selectedAppointment.location; TimeZoneInfo selectedTimeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName); dateTimePicker_AppointmentDateStartTime.Text = (TimeZoneInfo.ConvertTimeFromUtc(selectedAppointment.start, selectedTimeZone)).ToString(); dateTimePicker_AppointmentDateEndTime.Text = (TimeZoneInfo.ConvertTimeFromUtc(selectedAppointment.end, selectedTimeZone)).ToString(); comboBox_AppointmentType.Text = selectedAppointment.type.ToString(); comboBox_CustomerSelect.Text = selectedAppointment.customerObject.customerName; comboBox_SelectLocation.Text = selectedAppointment.location; } } }