private void Btn_ImportXML_Click(object sender, EventArgs e) { try { ControllerFurniture.GetterSetterPathXML = TxtBox_PathXML.Text; if (string.IsNullOrWhiteSpace(ControllerFurniture.GetterSetterPathXML)) { MessageBox.Show("Empty path XML", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (RadioButton_New.Checked) { ControllerFurniture.NewXMLImport(); } else if (RadioButton_Update.Checked) { ControllerFurniture.UpdateXMLImport(); } else { MessageBox.Show("Please select \"New\" or \"Update\" checkbox !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } BackgroundWorkerData = new BackgroundWorker(); BackgroundWorkerData.WorkerReportsProgress = true; // This event will be raised on the worker thread when the worker starts BackgroundWorkerData.DoWork += BackgroundWorkerData_DoWork; // This event will be raised when we call ReportProgress BackgroundWorkerData.ProgressChanged += BackgroundWorkerData_ProgressChanged; BackgroundWorkerData.RunWorkerCompleted += BackgroundWorkerData_RunWorkerCompleted; BackgroundWorkerData.RunWorkerAsync(); } } catch (Exception Exception) { TextBoxStatusImport.AppendText("[!] Error ! " + Exception.Message + "\n"); } }
private void BackgroundWorkerData_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show("Errors in importation XML !"); } else if (e.Cancelled) { MessageBox.Show("Importation XML canceled !"); } else { // Reset the progress bar ProgressBar_ImportXML.Value = 100; if (MessageBox.Show("Importation XML completed !") == DialogResult.OK) { ProgressBar_ImportXML.Value = 0; } ControllerFurniture.RefreshListView(-1); Mercure.MainWindow.StatusSQL_Label.Text = "You have imported XML File."; } TextBoxStatusImport.AppendText("\nList of errors :\n"); if (ListException.Count == 0) { TextBoxStatusImport.AppendText("Empty error list\n"); } else { foreach (Exception Exception in ListException) { TextBoxStatusImport.AppendText("[!] Error ! " + Exception.Message + "\n"); } ListException.Clear(); } }