private void UpdateButton_Click_1(object sender, EventArgs e) { string timestamp = SqlUpdater.CreateTimestamp(); int userId = SqlUpdater.GetCurrentUserID(); string username = SqlUpdater.GetCurrentUserName(); int appointmentId = Convert.ToInt32(SearchBar.Text); int customerId = Convert.ToInt32(CustomerIdBox.Text); string type = TypeBox.Text; DateTime startTime = DateTime.Parse(StartTimeBox.Text).ToUniversalTime(); DateTime endTime = DateTime.Parse(EndTimeBox.Text).ToUniversalTime(); String st = DateTime.Parse(StartTimeBox.Text).ToUniversalTime().ToString("u"); String et = DateTime.Parse(EndTimeBox.Text).ToUniversalTime().ToString("u"); bool pass = Validator(); if (pass) { try { if (AppHasConflict(startTime, endTime)) { throw new AppointmentException(); } else { try { if (OutsideBusinessHours(startTime, endTime)) { throw new AppointmentException(); } else { SqlUpdater.UpdateAppt(customerId, userId, st, et, type, timestamp, username, appointmentId); mainFormObject.UpdateCalendar(); MessageBox.Show("Update Sucessfull."); Close(); } } catch (AppointmentException ex) { ex.BusinessHours(); } } } catch (AppointmentException ex) { ex.AppOverlap(); } } else { MessageBox.Show("Add Appointment Error."); } }
private void CustomerCreateButton_Click(object sender, EventArgs e) { string timestamp = SqlUpdater.CreateTimestamp(); string userName = SqlUpdater.GetCurrentUserName(); if (string.IsNullOrEmpty(CustomerNameText.Text) || string.IsNullOrEmpty(CustomerPhoneText.Text) || string.IsNullOrEmpty(CustomerCityText.Text) || string.IsNullOrEmpty(CustomerCountryText.Text) || string.IsNullOrEmpty(CustomerZipText.Text) || string.IsNullOrEmpty(CustomerAddressText.Text)) //|| //(activeYes.Checked == false && activeNo.Checked == false)) { MessageBox.Show("Please complete all fields"); } else { int countryId = SqlUpdater.CreateRecord(timestamp, userName, "country", $"'{CustomerCountryText.Text}'"); int cityId = SqlUpdater.CreateRecord(timestamp, userName, "city", $"'{CustomerCityText.Text}', '{countryId}'"); int addressId = SqlUpdater.CreateRecord(timestamp, userName, "address", $"'{CustomerAddressText.Text}', '', '{cityId}', '{CustomerZipText.Text}', '{CustomerPhoneText.Text}'"); SqlUpdater.CreateRecord(timestamp, userName, "customer", $"'{ CustomerNameText.Text}', '{addressId}', '{(ActiveYes.Checked ? 1 : 0)}'"); MessageBox.Show("Customer created."); Close(); // string timestamp = SqlUpdater.CreateTimestamp(); // string userName = SqlUpdater.GetCurrentUserName(); //if (string.IsNullOrEmpty(CustomerNameText.Text) || // string.IsNullOrEmpty(CustomerPhoneText.Text) || // string.IsNullOrEmpty(CustomerCityText.Text) || // string.IsNullOrEmpty(CustomerCountryText.Text) || // string.IsNullOrEmpty(CustomerZipText.Text) || // string.IsNullOrEmpty(CustomerAddressText.Text)) //{ // MessageBox.Show("Please complete all fields"); //} //else //{ // int countryId = SqlUpdater.CreateRecord(timestamp, userName, "country", $"'{CustomerCountryText.Text}'"); // int cityId = SqlUpdater.CreateRecord(timestamp, userName, "city", $"'{CustomerCityText.Text}', {countryId}"); // int addressId = SqlUpdater.CreateRecord(timestamp, userName, "address", $"'{CustomerAddressText.Text}', {cityId}, '{CustomerZipText.Text}', '{CustomerPhoneText.Text}'"); // SqlUpdater.CreateRecord(timestamp, userName, "customer", $"'{ CustomerNameText.Text}', {addressId}"); // MessageBox.Show("Customer created."); // Close(); } }
public bool UpdateCust(Dictionary <string, string> updatedForm) { MySqlConnection c = new MySqlConnection(SqlUpdater.conString); c.Open(); string recUpdate = $"UPDATE customer" + $" SET customerName = '{updatedForm["customerName"]}', lastUpdate = '{SqlUpdater.CreateTimestamp()}', lastUpdateBy = '{SqlUpdater.GetCurrentUserName()}'" + $" WHERE customerName = '{cForm["customerName"]}'"; MySqlCommand cmd = new MySqlCommand(recUpdate, c); int customerUpdated = cmd.ExecuteNonQuery(); recUpdate = $"UPDATE address" + $" SET address = '{updatedForm["address"]}', postalCode = '{updatedForm["zip"]}', phone = '{updatedForm["phone"]}', lastUpdate = '{SqlUpdater.CreateTimestamp()}', lastUpdateBy = '{SqlUpdater.GetCurrentUserName()}'" + $" WHERE address = '{cForm["address"]}'"; cmd = new MySqlCommand(recUpdate, c); int addressUpdated = cmd.ExecuteNonQuery(); recUpdate = $"UPDATE city" + $" SET city = '{updatedForm["city"]}', lastUpdate = '{SqlUpdater.CreateTimestamp()}', lastUpdateBy = '{SqlUpdater.GetCurrentUserName()}'" + $" WHERE city = '{cForm["city"]}'"; cmd = new MySqlCommand(recUpdate, c); int cityUpdated = cmd.ExecuteNonQuery(); recUpdate = $"UPDATE country" + $" SET country = '{updatedForm["country"]}', lastUpdate = '{SqlUpdater.CreateTimestamp()}', lastUpdateBy = '{SqlUpdater.GetCurrentUserName()}'" + $" WHERE country = '{cForm["country"]}'"; cmd = new MySqlCommand(recUpdate, c); int countryUpdated = cmd.ExecuteNonQuery(); c.Close(); if (customerUpdated != 0 && addressUpdated != 0 && cityUpdated != 0 && countryUpdated != 0) { return(true); } else { return(false); } }
private void AddButton_Click(object sender, EventArgs e) { string timestamp = SqlUpdater.CreateTimestamp(); int userId = SqlUpdater.GetCurrentUserID(); string username = SqlUpdater.GetCurrentUserName(); DateTime startTime = DateTime.Parse(StartTimeBox.Text).ToUniversalTime(); DateTime endTime = DateTime.Parse(EndTimeBox.Text).ToUniversalTime(); bool pass = Validator(); if (pass) { try { if (AppHasConflict(startTime, endTime)) { throw new AppointmentException(); } else { try { if (OutsideBusinessHours(startTime, endTime)) { throw new AppointmentException(); } else { SqlUpdater.CreateRecord(timestamp, username, "appointment", $"'{CustomerIDBox.Text}', '{DateTime.Parse(StartTimeBox.Text).ToUniversalTime():u}', '{DateTime.Parse(EndTimeBox.Text).ToUniversalTime():u}', '{TypeBox.Text}'", userId); mainFormObject.UpdateCalendar(); Close(); } } catch (AppointmentException ex) { ex.BusinessHours(); } } } catch (AppointmentException ex) { ex.AppOverlap(); } }