private void createButton_Click(object sender, EventArgs e) { string timestamp = SqlUpdater.CreateTimestamp(); string userName = SqlUpdater.GetCurrentUserName(); if (string.IsNullOrEmpty(nameTextBox.Text) || string.IsNullOrEmpty(phoneNumberTextBox.Text) || string.IsNullOrEmpty(cityTextBox.Text) || string.IsNullOrEmpty(countryTextBox.Text) || string.IsNullOrEmpty(zipCodeTextBox.Text) || string.IsNullOrEmpty(addressTextBox.Text)) { MessageBox.Show("Please complete all fields"); } else { int countryId = SqlUpdater.CreateRecord(timestamp, userName, "country", $"'{countryTextBox.Text}'"); int cityId = SqlUpdater.CreateRecord(timestamp, userName, "city", $"'{cityTextBox.Text}', '{countryId}'"); int addressId = SqlUpdater.CreateRecord(timestamp, userName, "address", $"'{addressTextBox.Text}', '', '{cityId}', '{zipCodeTextBox.Text}', '{phoneNumberTextBox.Text}'"); SqlUpdater.CreateRecord(timestamp, userName, "customer", $"'{ nameTextBox.Text}', '{addressId}', '{(activeRadio.Checked ? 1 : 0)}'"); MessageBox.Show("Customer created."); Close(); } }
public void MainForm_Load(bool week) { DateTime filter = week ? CalcDateFilter("week") : CalcDateFilter("month"); DataTable dtRecord = SqlUpdater.FirstCal(SqlUpdater.DateSQLFormat(filter), week); dataGridView1.DataSource = dtRecord; }
private void reportButton_Click(object sender, EventArgs e) { DataRowView drv = typeComboBox.SelectedItem as DataRowView; try { string item = typeComboBox.SelectedItem.ToString(); IDictionary <string, object> dictionary = SqlUpdater.ReportAppoint(item); janResult.Text = dictionary["Jan"].ToString(); febResult.Text = dictionary["Feb"].ToString(); marResult.Text = dictionary["Mar"].ToString(); aprResult.Text = dictionary["Apr"].ToString(); mayResult.Text = dictionary["May"].ToString(); junResult.Text = dictionary["Jun"].ToString(); julResult.Text = dictionary["Jul"].ToString(); augResult.Text = dictionary["Aug"].ToString(); sepResult.Text = dictionary["Sep"].ToString(); octResult.Text = dictionary["Oct"].ToString(); novResult.Text = dictionary["Nov"].ToString(); decResult.Text = dictionary["Dec"].ToString(); } catch (Exception ex) { Console.WriteLine(ex); } }
private void reportButton_Click(object sender, EventArgs e) { DataRowView drv = consultantComboBox.SelectedItem as DataRowView; int id = Convert.ToInt32(consultantComboBox.SelectedValue); DataTable dtRecord = SqlUpdater.Schedule(id.ToString()); dataGridView1.DataSource = dtRecord; }
private void searchButton_Click(object sender, EventArgs e) { string appointmentId = appointmentIDTextBox.Text; appointmentDetails = SqlUpdater.GetAppointmentDetails(appointmentId); pullCustomerID.Text = appointmentDetails["customerId"]; pullTypeLabel.Text = appointmentDetails["type"]; pullStartLabel.Text = appointmentDetails["start"]; pullEndLabel.Text = appointmentDetails["end"]; }
private void searchButton_Click(object sender, EventArgs e) { string appointmentId = searchTextBox.Text; form = SqlUpdater.GetAppointmentDetails(appointmentId); customerIDTextBox.Text = form["customerId"]; typeTextBox.Text = form["type"]; startTextBox.Text = SqlUpdater.ConvertToTimezone(form["start"]); endTextBox.Text = (SqlUpdater.ConvertToTimezone(form["end"])); }
public static bool AppHasConflict(DateTime startTime, DateTime endTime) { foreach (var app in SqlUpdater.GetAppointments().Values) { if (startTime < DateTime.Parse(app["end"].ToString()) && DateTime.Parse(app["start"].ToString()) < endTime) { return(true); } } return(false); }
private void updateButton_Click(object sender, EventArgs e) { string timestamp = SqlUpdater.CreateTimestamp(); int userId = SqlUpdater.GetCurrentUserID(); string username = SqlUpdater.GetCurrentUserName(); int appointmentId = Convert.ToInt32(searchTextBox.Text); int customerId = Convert.ToInt32(customerIDTextBox.Text); string type = typeTextBox.Text; DateTime startTime = DateTime.Parse(startTextBox.Text).ToUniversalTime(); DateTime endTime = DateTime.Parse(endTextBox.Text).ToUniversalTime(); string st = DateTime.Parse(startTextBox.Text).ToUniversalTime().ToString("u"); string et = DateTime.Parse(endTextBox.Text).ToUniversalTime().ToString("u"); bool pass = Validator(); if (pass) { try { if (AppHasConflict(startTime, endTime)) { throw new AppointmentExceptions(); } else { try { if (OutsideBusinessHours(startTime, endTime)) { throw new AppointmentExceptions(); } else { SqlUpdater.UpdateAppt(customerId, userId, st, et, type, timestamp, username, appointmentId); mainFormObject.UpdateCalendar(); MessageBox.Show("Update Successful!"); Close(); } } catch (AppointmentExceptions ex) { ex.BusinessHours(); } } } catch (AppointmentExceptions ex) { ex.ApptOverlap(); } } 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 loginButton_Click(object sender, EventArgs e) { if (FindUser(userTextBox.Text, passwordTextBox.Text) != 0) { this.Hide(); MainForm MainForm = new MainForm { loginForm = this }; Logger.WriteUserLoginLog(SqlUpdater.GetCurrentUserName()); MainForm.Show(); } else { MessageBox.Show(errorMessage); passwordTextBox.Text = ""; } }
private void searchButton_Click(object sender, EventArgs e) { int customerId = SqlUpdater.FindCustomer(custSearchBox.Text); if (customerId != 0) { customerDetails = SqlUpdater.GetCustomerDetails(customerId); pullNameLabel.Text = customerDetails["customerName"]; pullPhoneLabel.Text = customerDetails["phone"]; pullAddressLabel.Text = customerDetails["address"]; pullCityLabel.Text = customerDetails["city"]; pullZipCodeLabel.Text = customerDetails["zip"]; pullCountryLabel.Text = customerDetails["country"]; } else { MessageBox.Show("Unable to find customer."); } }
private void searchButton_Click(object sender, EventArgs e) { { int customerId = SqlUpdater.FindCustomer(custSearchBox.Text); if (customerId != 0) { cForm = SqlUpdater.GetCustomerDetails(customerId); nameTextBox.Text = cForm["customerName"]; phoneTextBox.Text = cForm["phone"]; cityTextBox.Text = cForm["city"]; addressTextBox.Text = cForm["address"]; zipCodeTextBox.Text = cForm["zip"]; countryTextBox.Text = cForm["country"]; } else { MessageBox.Show("Unable to find this customer."); } } }
private void addButton_Click(object sender, EventArgs e) { string timestamp = SqlUpdater.CreateTimestamp(); int userId = SqlUpdater.GetCurrentUserID(); string username = SqlUpdater.GetCurrentUserName(); DateTime startTime = DateTime.Parse(startTextBox.Text).ToUniversalTime(); DateTime endTime = DateTime.Parse(endTextBox.Text).ToUniversalTime(); bool pass = Validator(); if (pass) { try { if (AppHasConflict(startTime, endTime)) { throw new AppointmentExceptions(); } else { try { if (OutsideBusinessHours(startTime, endTime)) { throw new AppointmentExceptions(); } else { SqlUpdater.CreateRecord(timestamp, username, "appointment", $"'{custIDTextBox.Text}', '{DateTime.Parse(startTextBox.Text).ToUniversalTime():u}', '{DateTime.Parse(endTextBox.Text).ToUniversalTime():u}', '{typeTextBox.Text}'", userId); mainFormObject.UpdateCalendar(); Close(); } } catch (AppointmentExceptions ex) { ex.BusinessHours(); } } } catch (AppointmentExceptions ex) { ex.ApptOverlap(); } }
private void allReportsButton_Click(object sender, EventArgs e) { try { IDictionary <string, object> dictionary = SqlUpdater.ReportAll(); janResult.Text = dictionary["Jan"].ToString(); febResult.Text = dictionary["Feb"].ToString(); marResult.Text = dictionary["Mar"].ToString(); aprResult.Text = dictionary["Apr"].ToString(); mayResult.Text = dictionary["May"].ToString(); junResult.Text = dictionary["Jun"].ToString(); julResult.Text = dictionary["Jul"].ToString(); augResult.Text = dictionary["Aug"].ToString(); sepResult.Text = dictionary["Sep"].ToString(); octResult.Text = dictionary["Oct"].ToString(); novResult.Text = dictionary["Nov"].ToString(); decResult.Text = dictionary["Dec"].ToString(); } catch (Exception ex) { Console.WriteLine(ex); } }
public bool UpdateCust(Dictionary <string, string> updatedForm) { MySqlConnection conn = new MySqlConnection(SqlUpdater.conString); conn.Open(); /*string recUpdate = $"UPDATE customer" + $" SET customerName = '{updatedForm["customerName"]}', lastUpdate = '{SqlUpdater.CreateTimestamp()}', lastUpdateBy = '{SqlUpdater.GetCurrentUserName()}'" + * $" WHERE customerName = '{cForm["customerName"]}'"; * MySqlCommand cmd = new MySqlCommand(recUpdate, conn); * int customerUpdated = cmd.ExecuteNonQuery();*/ string recUpdate = $"UPDATE customer" + $" SET customerName = '{updatedForm["customerName"]}', lastUpdate = '{SqlUpdater.CreateTimestamp()}', lastUpdateBy = '{SqlUpdater.GetCurrentUserName()}'" + $" WHERE customerName = '{cForm["customerName"]}'"; MySqlCommand cmd = new MySqlCommand(recUpdate, conn); 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, conn); 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, conn); 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, conn); int countryUpdated = cmd.ExecuteNonQuery(); conn.Close(); if (customerUpdated != 0 && addressUpdated != 0 && cityUpdated != 0 && countryUpdated != 0) { return(true); } else { return(false); } }