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."); } }
static public int FindUser(string userName, string password) { MySqlConnection C = new MySqlConnection(SqlUpdater.conString); C.Open(); MySqlCommand cmd = new MySqlCommand($"SELECT userId FROM user WHERE userName = '******' AND password = '******'", C); MySqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { rdr.Read(); SqlUpdater.SetCurrentUserID(Convert.ToInt32(rdr[0])); SqlUpdater.SetCurrentUserName(userName); rdr.Close(); return(SqlUpdater.GetCurrentUserID()); } return(0); }
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(); } }