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(); } }
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(); } }