예제 #1
0
 private bool UpdateDBConnectionBox()
 {
     if (MDB_Board.DB_Connection != null && MDB_Board.DB_Connection.State == ConnectionState.Closed)
     {
         MDB_Board.ConnectToMysql(server, database, uid, password);
     }
     if (MDB_Board.DB_Connection != null && MDB_Board.DB_Connection.State == ConnectionState.Open)
     {
         Dispatcher.Invoke(new Action(() =>
         {
             db_status_txtbox.Background = new SolidColorBrush(Color.FromArgb(0xCC, 0x11, 0x9E, 0xDA)); //#CC119EDA
             db_status_txtbox.Foreground = Brushes.White;
         }), DispatcherPriority.Background);
         return(true);
     }
     else
     {
         Dispatcher.Invoke(new Action(() =>
         {
             db_status_txtbox.Background = Brushes.Red;
         }), DispatcherPriority.Background);
         return(false);
     }
 }
예제 #2
0
        private void Start_test_button_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckIfFormComplete())
            {
                MessageBox.Show("Please select all itens correctly", "Wrong Fields", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);
                SetStartButtonState(true);
                return;
            }
            MDB_Board = new MDB_BOARD(new Init_State())
            {
                BoardOperator         = operator_txtbox.Text,
                BoardWorkstation      = combo_workStation.Text,
                SerialNumber          = GetSerialNumber(),
                BoardErrorDescription = "No Errors"
            };
            MDB_Board.ConnectToMysql(server, database, uid, password);

            //Check for a Valid DB Connection - Error Exit Program
            if (!UpdateDBConnectionBox())
            {
                MessageBox.Show("Error Connecting to Database", "Check Database configuration", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);
                SetStartButtonState(true);
                return;
            }
            //Check for a valid Serial Number or a Repeated One - Error Exit Program
            if (String.IsNullOrEmpty(MDB_Board.SerialNumber) || MDB_Board.CheckRepeatedTest())
            {
                MessageBox.Show("Error In Serial Number", "Repeated Serial Number", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);
                SetStartButtonState(true);
                return;
            }
            //So far so good...
            ResetProgressBar();
            //Assign Serial Communication Ports
            MDB_Board.RS232Port = SerialCom.SelectedItem.ToString();
            MDB_Board.NucleoSerialCommunication(CurrentPort.SelectedItem.ToString());
            //Validate Serial Ports - Error Exit Program
            if (!MDB_Board.CorrectPortConfig())
            {
                MDB_Board.CloseSerialPort();
                MessageBox.Show("Wrong Port Selection", "Wrong Fields", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);
                SetStartButtonState(true);
                return;
            }
            //Set Correct Power Supply
            MDB_Board.SetMDBSupply();
            //Everything is Ok
            //Start Testing with scripts in a Thread
            try
            {
                MDB_Board.InitializeList();
                test_list.ItemsSource = MDB_Board.list_itens;
                UpdateTextEvolution(Environment.NewLine + "---------------------------");
                StartTimer();
                Thread Test_Thread = new Thread(() => MDB_Board.StartTesting());
                Test_Thread.Start();
            }
            catch
            {
                SetStartButtonState(true);
                MessageBox.Show("Can't communicate with board" + Environment.NewLine + "Please check cable connection", "No communication with board", MessageBoxButton.OK, MessageBoxImage.Error);
                timer.Stop();
            }
        }