void processor_Complete(int New_Progress) { // Check to see if Processor thread should be stopped if ((this.processor != null) && (this.processor.StopThread)) { try { // terminate the Processor thread processThread.Abort(); processThread.Join(); processor = null; } catch (System.Threading.ThreadAbortException) { // A ThreadAbortException has been invoked on the // Processor thread. Write the import data to an // Excel worksheet and update the form controls only // if the MainForm is not being disposed. // update the status controls on this form if (!this.Disposing) { labelStatus.Text = "Processing stopped at record " + (progressBar1.Value + 1).ToString("#,##0;") + " of " + progressBar1.Maximum.ToString("#,##0;") + " records"; progressBar1.Value = progressBar1.Minimum; this.Cursor = Cursors.Default; } try { // Create an Excel Worksheet named 'Output' on the input data file, // and write the importer results to the spreadsheet. Export_as_Excel(); } catch { } finally { // create a table to display the results DataTable displayTbl = this.processor.Report_Data.Copy(); // create the Results form Results_Form showResults = new Results_Form(displayTbl, processor.Importer_Type, previewCheckBox.Checked); // hide the Importer form this.Hide(); // show the Results form showResults.ShowDialog(); // enable form controls on the Importer form this.Enable_FormControls(); // show the Importer form this.ShowDialog(); } } catch { } } else { // The complete flag is true, set the Cursor and ProgressBar back to default values. this.Cursor = Cursors.Default; progressBar1.Value = progressBar1.Minimum; // disable the Stop button this.executeButton.Button_Enabled = false; try { // Create an Excel Worksheet named 'Output' on the input data file, // and write the importer results to the spreadsheet. Export_as_Excel(); } catch { } finally { // create a table to display the results DataTable displayTbl = this.processor.Report_Data.Copy(); // create the Results form Results_Form showResults = new Results_Form(displayTbl, processor.Importer_Type, previewCheckBox.Checked); // hide the Importer form this.Hide(); // show the Results form showResults.ShowDialog(); // enable form controls on the Importer form this.Enable_FormControls(); // show the Importer form this.ShowDialog(); } } }
/// <summary> Imports the records from the indicated source file </summary> protected void Import_Records(System.Data.DataTable inputFile) { // update class variable this.excelDataTbl = inputFile; // Display an hourglass cursor and set max value on the ProgressBar this.Cursor = Cursors.WaitCursor; progressBar1.Maximum = this.Total_Records; // Step through each column map control List <SobekCM.Resource_Object.Mapped_Fields> mapping = new List <SobekCM.Resource_Object.Mapped_Fields>(); foreach (Column_Assignment_Control thisColumn in column_map_inputs) { mapping.Add(thisColumn.Mapped_Field); } // Step through each constant map control Constant_Fields constantCollection = new Constant_Fields(); foreach (Constant_Assignment_Control thisConstant in constant_map_inputs) { constantCollection.Add(thisConstant.Mapped_Field, thisConstant.Mapped_Constant); } //add columns to the input data table if (!excelDataTbl.Columns.Contains("New BIB ID")) { excelDataTbl.Columns.Add("New BIB ID"); } else { excelDataTbl.Columns.Remove("New BIB ID"); excelDataTbl.Columns.Add("New BIB ID"); } if (!excelDataTbl.Columns.Contains("New VID ID")) { excelDataTbl.Columns.Add("New VID ID"); } else { excelDataTbl.Columns.Remove("New VID ID"); excelDataTbl.Columns.Add("New VID ID"); } if (!excelDataTbl.Columns.Contains("Messages")) { excelDataTbl.Columns.Add("Messages"); } else { excelDataTbl.Columns.Remove("Messages"); excelDataTbl.Columns.Add("Messages"); } // disable some of the form controls this.Disable_FormControls(); // enable the Stop button this.executeButton.Button_Enabled = true; // Show the progress bar this.progressBar1.Visible = true; progressBar1.Value = progressBar1.Minimum; // reset the status label labelStatus.Text = ""; this.previewCheckBox.Enabled = false; // Write the current mappings, etc.. write_mappings_and_constants(inputFile, mapping, constantCollection); try { // Create the Processor and assign the Delegate method for event processing. processor = new SpreadSheet_Importer_Processor(inputFile, mapping, constantCollection, previewCheckBox.Checked); processor.New_Progress += new New_Importer_Progress_Delegate(processor_New_Progress); processor.Complete += new New_Importer_Progress_Delegate(processor_Complete); // Create the thread to do the processing work, and start it. processThread = new Thread(new ThreadStart(processor.Do_Work)); processThread.SetApartmentState(ApartmentState.STA); processThread.Start(); } catch (Exception e) { // display the error message DLC.Tools.Forms.ErrorMessageBox.Show("Error encountered while processing!\n\n" + e.Message, "DLC Importer Error", e); // enable form controls on the Importer form this.Enable_FormControls(); this.Cursor = Cursors.Default; progressBar1.Value = progressBar1.Minimum; } }
/// <summary> Imports the records from the indicated source file </summary> protected void Import_Records(System.Data.DataTable inputFile) { // update class variable this.excelDataTbl = inputFile; // Display an hourglass cursor and set max value on the ProgressBar this.Cursor = Cursors.WaitCursor; progressBar1.Maximum = this.Total_Records; // Step through each column map control List<SobekCM.Resource_Object.Mapped_Fields> mapping = new List<SobekCM.Resource_Object.Mapped_Fields>(); foreach (Column_Assignment_Control thisColumn in column_map_inputs) { mapping.Add(thisColumn.Mapped_Field); } // Step through each constant map control Constant_Fields constantCollection = new Constant_Fields(); foreach (Constant_Assignment_Control thisConstant in constant_map_inputs) { constantCollection.Add(thisConstant.Mapped_Field, thisConstant.Mapped_Constant); } //add columns to the input data table if (!excelDataTbl.Columns.Contains("New BIB ID")) excelDataTbl.Columns.Add("New BIB ID"); else { excelDataTbl.Columns.Remove("New BIB ID"); excelDataTbl.Columns.Add("New BIB ID"); } if (!excelDataTbl.Columns.Contains("New VID ID")) excelDataTbl.Columns.Add("New VID ID"); else { excelDataTbl.Columns.Remove("New VID ID"); excelDataTbl.Columns.Add("New VID ID"); } if (!excelDataTbl.Columns.Contains("Messages")) excelDataTbl.Columns.Add("Messages"); else { excelDataTbl.Columns.Remove("Messages"); excelDataTbl.Columns.Add("Messages"); } // disable some of the form controls this.Disable_FormControls(); // enable the Stop button this.executeButton.Button_Enabled = true; // Show the progress bar this.progressBar1.Visible = true; progressBar1.Value = progressBar1.Minimum; // reset the status label labelStatus.Text = ""; this.previewCheckBox.Enabled = false; // Write the current mappings, etc.. write_mappings_and_constants( inputFile, mapping, constantCollection); try { // Create the Processor and assign the Delegate method for event processing. processor = new SpreadSheet_Importer_Processor(inputFile, mapping, constantCollection, previewCheckBox.Checked ); processor.New_Progress += new New_Importer_Progress_Delegate(processor_New_Progress); processor.Complete += new New_Importer_Progress_Delegate(processor_Complete); // Create the thread to do the processing work, and start it. processThread = new Thread(new ThreadStart(processor.Do_Work)); processThread.SetApartmentState(ApartmentState.STA); processThread.Start(); } catch (Exception e) { // display the error message DLC.Tools.Forms.ErrorMessageBox.Show("Error encountered while processing!\n\n" + e.Message, "DLC Importer Error", e); // enable form controls on the Importer form this.Enable_FormControls(); this.Cursor = Cursors.Default; progressBar1.Value = progressBar1.Minimum; } }