/// <summary> Imports the records from the indicated source file </summary> protected void Import_Records(DataTable inputFile) { // update class variable excelDataTbl = inputFile; // Display an hourglass cursor and set max value on the ProgressBar progressBar1.Maximum = Total_Records; // Step through each column map control List <Mapped_Fields> mapping = new List <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(); string first_bibid = String.Empty; foreach (Constant_Assignment_Control thisConstant in constant_map_inputs) { if (thisConstant.Mapped_Name == "First BibID") { first_bibid = thisConstant.Mapped_Constant; } else { constantCollection.Add(thisConstant.Mapped_Field, thisConstant.Mapped_Constant); } } // validate the form if ((folderTextBox.Text.Trim().Length == 0) || (!Directory.Exists(folderTextBox.Text.Trim()))) { MessageBox.Show("Enter a valid destination folder. ", "Invalid Destination Folder", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // If a column was mapped to BibID, skip this string bibid_start = "nobib"; int first_bibid_int = 0; if (!has_bibid_mapping) { if (first_bibid.Length < 3) { MessageBox.Show("You must enter a constant for the 'First BibID' value and it must begin with two letters. \n\nThis is the first ObjectID that will be used for the resulting METS files. ", "Choose First BibID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (first_bibid.Length > 10) { MessageBox.Show("The complete BibID/ObjectID cannot be longer than 10 digits. ", "Invalid First BibID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Pad the bibid to 10 digits, in case it is not 10 first_bibid = first_bibid.PadRight(10, '0'); // First two must be characters if ((!Char.IsLetter(first_bibid[0])) || (!Char.IsLetter(first_bibid[1]))) { MessageBox.Show("You must enter a constant for the 'First BibID' value and it must begin with two letters. \n\nThis is the first ObjectID that will be used for the resulting METS files. ", "Choose First BibID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check that it ends in numbers if ((!Char.IsNumber(first_bibid[9])) || (!Char.IsNumber(first_bibid[8])) || (!Char.IsNumber(first_bibid[7])) || (!Char.IsNumber(first_bibid[6]))) { MessageBox.Show("The last four digits of the BibID must be numeric. \n\nTry shortening the length or changing trailing characters to numers. ", "Invalid First BibID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Try to break the first_bibid up into character portion and number portion int numbers_start = 9; for (int i = 9; i >= 0; i--) { if (!Char.IsNumber(first_bibid[i])) { numbers_start = i + 1; break; } } bibid_start = first_bibid.Substring(0, numbers_start); first_bibid_int = Convert.ToInt32(first_bibid.Substring(numbers_start)); } //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")) { excelDataTbl.Columns.Add("New VID"); } else { excelDataTbl.Columns.Remove("New VID"); excelDataTbl.Columns.Add("New VID"); } //if (!excelDataTbl.Columns.Contains("Messages")) // excelDataTbl.Columns.Add("Messages"); //else //{ // excelDataTbl.Columns.Remove("Messages"); // excelDataTbl.Columns.Add("Messages"); //} // disable some of the form controls Disable_FormControls(); // Change color on both the 'step3' and 'step 4 labels step3Label.ForeColor = ControlPaint.LightLight(SystemColors.ActiveCaption); step4Label.ForeColor = ControlPaint.LightLight(SystemColors.ActiveCaption); step5Label.ForeColor = ControlPaint.LightLight(SystemColors.ActiveCaption); // Toggle the button text executeButton.Button_Text = "STOP"; cancelButton.Button_Text = "CLEAR"; // enable the Stop button executeButton.Button_Enabled = true; // Show the progress bar progressBar1.Visible = true; progressBar1.Value = progressBar1.Minimum; Cursor = Cursors.WaitCursor; // reset the status label labelStatus.Text = ""; // 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, folderTextBox.Text.Trim(), bibid_start, first_bibid_int); processor.New_Progress += processor_New_Progress; processor.Complete += processor_Complete; // Create the thread to do the processing work, and start it. processThread = new Thread(processor.Do_Work); processThread.SetApartmentState(ApartmentState.STA); processThread.Start(); } catch (Exception e) { // display the error message ErrorMessageBox.Show("Error encountered while processing!\n\n" + e.Message, "DLC Importer Error", e); // enable form controls on the Importer form Enable_FormControls(); Cursor = Cursors.Default; progressBar1.Value = progressBar1.Minimum; } }
/// <summary> Imports the records from the indicated source file </summary> protected void Import_Records() { // Step through each constant map control Constant_Fields constantCollection = new Constant_Fields(); string first_bibid = String.Empty; foreach (Constant_Assignment_Control thisConstant in constant_map_inputs) { if (thisConstant.Mapped_Name == "First BibID") { first_bibid = thisConstant.Mapped_Constant; } else { constantCollection.Add(thisConstant.Mapped_Field, thisConstant.Mapped_Constant); } } // validate the form if ((folderTextBox.Text.Trim().Length == 0) || (!Directory.Exists(folderTextBox.Text.Trim()))) { MessageBox.Show("Enter a valid destination folder. ", "Invalid Destination Folder", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (first_bibid.Length < 3) { MessageBox.Show("You must enter a constant for the 'First BibID' value and it must begin with two letters. \n\nThis is the first ObjectID that will be used for the resulting METS files. ", "Choose First BibID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (first_bibid.Length > 10) { MessageBox.Show("The complete BibID/ObjectID cannot be longer than 10 digits. ", "Invalid First BibID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Pad the bibid to 10 digits, in case it is not 10 first_bibid = first_bibid.PadRight(10, '0'); // First two must be characters if ((!Char.IsLetter(first_bibid[0])) || (!Char.IsLetter(first_bibid[1]))) { MessageBox.Show("You must enter a constant for the 'First BibID' value and it must begin with two letters. \n\nThis is the first ObjectID that will be used for the resulting METS files. ", "Choose First BibID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check that it ends in numbers if ((!Char.IsNumber(first_bibid[9])) || (!Char.IsNumber(first_bibid[8])) || (!Char.IsNumber(first_bibid[7])) || (!Char.IsNumber(first_bibid[6]))) { MessageBox.Show("The last four digits of the BibID must be numeric. \n\nTry shortening the length or changing trailing characters to numers. ", "Invalid First BibID", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Try to break the first_bibid up into character portion and number portion int numbers_start = 9; for (int i = 9; i >= 0; i--) { if (!Char.IsNumber(first_bibid[i])) { numbers_start = i + 1; break; } } string bibid_start = first_bibid.Substring(0, numbers_start); int first_bibid_int = Convert.ToInt32(first_bibid.Substring(numbers_start)); // disable some of the form controls Disable_FormControls(); // Show the progress bar progressBar1.Visible = true; progressBar1.Maximum = 10; progressBar1.Value = 0; // reset the status label labelStatus.Text = ""; try { // Create the Processor and assign the Delegate method for event processing. processor = new MARC_Importer_Processor(sourceTextBox.Text, constantCollection, folderTextBox.Text, bibid_start, first_bibid_int); processor.New_Progress += processor_New_Progress; processor.Complete += processor_Complete; // Create the thread to do the processing work, and start it. processThread = new Thread(processor.Do_Work); processThread.SetApartmentState(ApartmentState.STA); processThread.Start(); } catch (Exception e) { // display the error message ErrorMessageBox.Show("Error encountered while processing!\n\n" + e.Message, "DLC Importer Error", e); // enable form controls on the Importer form Enable_FormControls(); Cursor = Cursors.Default; progressBar1.Value = progressBar1.Minimum; } }