private void btnEdit_Click(object sender, EventArgs e) { // Получим id выбранного теста int selectedrowindex = dataGridTests.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dataGridTests.Rows[selectedrowindex]; int selected_id = Convert.ToInt32(selectedRow.Cells["id_test"].Value); EditTest ete = new EditTest(selected_id); ete.Show(); }
/// <summary> /// Add new test /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SetTest_Button_Click(object sender, RoutedEventArgs e) { SetTest.IsEnabled = false; SetTest.ToolTip = "Checking Internet Connection"; LabelConnecting.Visibility = Visibility.Visible; new Thread(() => { try { //Check internet connectivity try { var wc = new WebClient(); wc.DownloadData("https://www.google.com/"); } catch { throw new Exception("There is No Internet Connection.Please Try Again Later."); } //open window void Act1() { LabelConnecting.Visibility = Visibility.Hidden; SetTest.IsEnabled = true; SetTest.ToolTip = ""; var win = new EditTest(_trainee); win.ShowDialog(); Refresh(); } Dispatcher.BeginInvoke((Action)Act1); } catch (Exception ex) { void Act2() { LabelConnecting.Visibility = Visibility.Hidden; SetTest.IsEnabled = true; SetTest.ToolTip = ""; ExceptionMessage.Show(ex.Message, ex.ToString()); } Dispatcher.BeginInvoke((Action)Act2); } }).Start(); }
/// <summary> /// Add new trainee /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddTestClick(object sender, RoutedEventArgs e) { ProgressLabel.Content = "Connecting to Internet..."; ProgressLabel.Visibility = Visibility.Visible; new Thread(() => { try { //Check internet connectivity try { var wc = new WebClient(); wc.DownloadData("https://www.google.com/"); } catch { throw new Exception("There is No Internet Connection.Please Try Again Later."); } //open window void Act1() { ProgressLabel.Visibility = Visibility.Collapsed; var win = new EditTest(); win.ShowDialog(); RefreshData(); } Dispatcher.BeginInvoke((Action)Act1); } catch (Exception ex) { void Act2() { ProgressLabel.Visibility = Visibility.Collapsed; ExceptionMessage.Show(ex.Message, ex.ToString()); } Dispatcher.BeginInvoke((Action)Act2); } }).Start(); }
/// <summary> /// Update selected Trainee in a new window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdateTestClick(object sender, EventArgs e) { try { //save test details var test = TestGrid.SelectedItem as Test; if (test == null) { return; } var win = new EditTest(test?.Id); var passed = test?.Passed; //open window win.ShowDialog(); RefreshData(); //get trainee and updated test var trainee = _bL.AllTrainees.First(x => x.Id == test?.TraineeId); test = _bL.AllTests.First(x => x.Id == test?.Id); //if the passed state didn't change if (test.Passed == passed) { return; } //Set Label ProgressLabel.Content = "Sending Email to " + trainee.FirstName + " " + trainee.LastName + "..."; ProgressLabel.Visibility = Visibility.Visible; //Send Email to trainee var thread = new Thread(() => { try { Pdf.CreateLicensePdf(test, trainee); Email.SentEmailToTraineeAfterTest(test, trainee); void Act() { ExceptionMessage.Show("Successfully Send Email to " + trainee.FirstName + " " + trainee.LastName); } Dispatcher.BeginInvoke((Action)Act); } catch (Exception ex) { void Act() { ExceptionMessage.Show(ex.Message, ex.ToString()); } Dispatcher.BeginInvoke((Action)Act); } void Action() { ProgressLabel.Visibility = Visibility.Hidden; } Dispatcher.BeginInvoke((Action)Action); }); thread.Start(); } catch (Exception ex) { if (ex.Message != "Object reference not set to an instance of an object.") { ExceptionMessage.Show(ex.Message, ex.ToString()); } } }
private void editTest_Click(object sender, EventArgs e) { EditTest edittest = new EditTest(); edittest.ShowDialog(); }