public MainWindow() { try { db = new ProjectDatabase(); InitializeComponent(); ReloadEmployeeList(); } catch (SqlException ex) { MessageBox.Show("Database error: " + ex.Message); } }
private void btnSavePayment_Click(object sender, RoutedEventArgs e) { //collect info from the text boxes: int id = Convert.ToInt32(tbEmployeeID.Text); double hourlyRate; if (!double.TryParse(tbHourlyRatePay.Text, out hourlyRate)) { MessageBox.Show("Please, enter the hourly rate"); return; } double hours; if (!double.TryParse(tbNoOfHoursPay.Text, out hours)) { MessageBox.Show("Please, enter the amount of hours worked"); return; } hourlyRate = Convert.ToDouble(tbHourlyRatePay.Text); hours = Convert.ToDouble(tbNoOfHoursPay.Text); double net = Convert.ToDouble(tbTotalNetPay.Text); Payment payment = new Payment(); payment.Id = id; payment.HourlyRate = hourlyRate; payment.NetPay = net; payment.Hours = hours; try { db = new ProjectDatabase(); db.AddPayment(payment); MessageBox.Show("The Payment record was successfully saved."); this.Close(); } catch (SqlException ex) { //MessageBox.Show("Check the Database Connection Please."); MessageBox.Show(ex.ToString()); } }