Beispiel #1
0
        private void Save_test(object sender, RoutedEventArgs e)
        {
            try
            {
                pb_save.Visibility = Visibility.Visible;
                pi_save.Visibility = Visibility.Collapsed;

                // Make sure all fields that must contain numbers contain numbers and not letters
                int b_numer;
                try
                {
                    b_numer = Int32.Parse(building_number.Text);
                }
                catch
                {
                    throw new Exception("אנא וודא שלא הכנסת אותיות או תווים בשדות בהם עליך להכניס מספר");
                }

                // Builds a new address according to the data
                BE.Address address = new BE.Address(street.Text, b_numer, city.Text);

                int      hour  = Int32.Parse(((ListViewItem)test_hour.SelectedItem).Content.ToString().Replace(":00", ""));
                DateTime _date = (DateTime)test_date.SelectedDate;
                DateTime date  = new DateTime(_date.Year, _date.Month, _date.Day, hour, 0, 0);

                BE.Test test = new BE.Test(Trainee.ID, date, address, Trainee.Learned);

                if (txt_credit_card_number.Text.Length < 18 || txt_credit_card_date.Text.Length != 5 || txt_credit_card_CVV.Text.Length != 3)
                {
                    throw new Exception("שגיאה בפרטי האשראי: פרטי כרטיס האשראי שהכנסת לא נכונים, או שלא מילאת את כל השדות הדרושים");
                }

                BackgroundWorker worker = new BackgroundWorker()
                {
                    WorkerSupportsCancellation = true
                };
                worker.DoWork += (object sender1, DoWorkEventArgs args) =>
                {
                    try
                    {
                        iBL_Imp.Add_test(test);
                        //iBL_Imp.Send_Email(test);
                        new Thread(() => { iBL_Imp.Send_Email(test); }).Start();
                        args.Cancel = false;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        args.Cancel = true;
                    }
                };
                worker.RunWorkerCompleted += (object sender1, RunWorkerCompletedEventArgs args) =>
                {
                    if (!args.Cancelled)
                    {
                        home_address.IsChecked = false;
                        Home_Address(home_address, null);
                        test_date.SelectedDate      = null;
                        test_hour.SelectedItem      = null;
                        txt_credit_card_date.Text   = "";
                        txt_credit_card_CVV.Text    = "";
                        txt_credit_card_number.Text = "";

                        string           test_data = "נרשמת בהצלחה לטסט ב" + test.Test_time.ToLongDateString() + " בשעה " + test.Test_time.ToShortTimeString() + "\nהטסט מתחיל ב" + test.Address.ToString() + "\nהאם ברצונך להוסיף את הטסט ללוח השנה שלך?";
                        MessageBoxResult result    = MessageBox.Show(test_data, "הטסט נשמר בהצלחה", MessageBoxButton.YesNo);
                        switch (result)
                        {
                        case MessageBoxResult.Yes:
                            iBL_Imp.Add_To_Calender(test);
                            break;

                        default:
                            break;
                        }
                    }

                    pb_save.Visibility = Visibility.Collapsed;
                    pi_save.Visibility = Visibility.Visible;
                };

                worker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

                pb_save.Visibility = Visibility.Collapsed;
                pi_save.Visibility = Visibility.Visible;
            }
        }