protected baseImporter_Processor(Constant_Fields constantCollection)
        {
            // Create the objects to keep track of errors and items processed
            report   = new Importer_Report();
            errors   = new List <string>();
            warnings = new List <string>();

            // Save the parameters
            this.constantCollection = constantCollection;

            // Set some constants;
            recordsSavedToDB = 0;
            recordsProcessed = 0;
            recordsSkipped   = 0;
            errorCnt         = 0;
            preview_counter  = 1;
            allow_overlay    = false;

            // Load the data tables needed
            //     TrackingDB.CS_TrackingDatabase.Refresh_Bib_Table();
            //  allInstitutions = SobekCM.Library.Database.SobekCM_Database.Get_Codes_Item_Aggregations(true, null);

            // Declare the lists which will hold the new bib id and receiving id information
            Provided_Bib_To_New_Bib       = new Dictionary <string, string>();
            Provided_Bib_To_New_Receiving = new Dictionary <string, int>();
            BibID_To_Last_VID             = new Dictionary <string, int>();
            New_Bib_IDs = new List <string>();

            // Set some defaults
            default_projects      = new List <string>();
            default_material_type = String.Empty;
        }
        /// <summary> Constructor for a new instance of this class </summary>
        /// <param name="fields"> Fields which will be added to each record created </param>
        /// <param name="inputFile"> Text of the input file </param>
        /// <param name="outputFile"> Text for the output file as well </param>
        public MARC_Importer_Processor(string inputFile, Constant_Fields constantCollection, string Destination_Folder, string BibID_Start, int First_BibID)
            : base(constantCollection)
        {
            // Save the parameters
            this.inputFile     = inputFile;
            destination_folder = Destination_Folder;
            bibid_start        = BibID_Start;
            next_bibid_counter = First_BibID;

            // Allow overlay from MARC records
            base.allow_overlay = true;

            // Create the parser
            parser = new MARC21_Exchange_Format_Parser();

            // Set the error and marc subfolders
            marc_folder  = destination_folder + "\\MARC";
            error_folder = destination_folder + "\\Error";
        }
        /// <summary> Constructor for a new instance of this class </summary>
        /// <param name="InputDataTable">Table from the Excel spreadsheet being processed</param>
        /// <param name="Mapping">Arraylist of 'enum Mapped_Fields' members.</param>
        public SpreadSheet_Importer_Processor(DataTable InputDataTable, List <Mapped_Fields> Mapping, Constant_Fields constantCollection, string Destination_Folder, string BibID_Start, int First_BibID)
            : base(constantCollection)
        {
            // Save the parameters
            inputDataTbl       = InputDataTable;
            mapping            = Mapping;
            destination_folder = Destination_Folder;
            bibid_start        = BibID_Start;
            next_bibid_counter = First_BibID;

            // Set the error and marc subfolders
            marc_folder  = destination_folder + "\\MARC";
            error_folder = destination_folder + "\\Error";
        }
Пример #4
0
        private void write_mappings_and_constants(DataTable inputFile, List <Mapped_Fields> mapping, Constant_Fields constantCollection)
        {
            try
            {
                string       mapping_name  = filename + ".importdata";
                StreamWriter mappingWriter = new StreamWriter(mapping_name, false);
                mappingWriter.WriteLine("MAPPING:");
                int column = 0;
                foreach (Mapped_Fields mappedField in mapping)
                {
                    mappingWriter.WriteLine("\t\"" + inputFile.Columns[column].ColumnName.Replace("\"", "&quot;") + "\" --> " + Bibliographic_Mapping.Mapped_Field_To_String(mappedField));
                    column++;
                }
                mappingWriter.WriteLine();
                mappingWriter.WriteLine("CONSTANTS:");
                foreach (Constant_Field_Data constantData in constantCollection.constantCollection)
                {
                    if ((constantData.Data.Length > 0) && (constantData.Field != Mapped_Fields.None))
                    {
                        mappingWriter.WriteLine("\t" + Bibliographic_Mapping.Mapped_Field_To_String(constantData.Field) + " <-- \"" + constantData.Data.Replace("\"", "&quot;"));
                    }
                }

                mappingWriter.Flush();
                mappingWriter.Close();
            }
            catch (Exception ee)
            {
                MessageBox.Show("Unable to save the import data for this job.    \n\n" + ee, "Error saving mapping", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #5
0
        /// <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;
            }
        }
Пример #6
0
        private void sheetComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ExcelBibliographicReader read = new ExcelBibliographicReader();

            try
            {
                // Make sure there is a filename and a sheet name
                if ((fileTextBox.Text.Length > 0) && (sheetComboBox.SelectedIndex >= 0))
                {
                    // reset the status label
                    labelStatus.Text = "";

                    read.Sheet    = sheetComboBox.Text;
                    read.Filename = fileTextBox.Text;

                    // Declare constant fields
                    Constant_Fields constants = new Constant_Fields();

                    columnNamePanel.Controls.Clear();
                    column_map_inputs.Clear();

                    columnNamePanel.Enabled = true;
                    pnlConstants.Enabled    = true;

                    // Display an hourglass cursor:
                    Cursor = Cursors.WaitCursor;


                    // Try reading data from the selected Excel Worksheet
                    bool readFlag = true;

                    while (readFlag)
                    {
                        try
                        {
                            if (!read.Check_Source())
                            {
                                ResetFormControls();
                                return;
                            }
                            else
                            {
                                readFlag = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            ErrorMessageBox.Show(ex.Message, "Unexpected Error", ex);
                        }
                    }


                    // change cursor back to default
                    Cursor = Cursors.Default;

                    excelDataTbl = read.excelData;

                    if (read.excelData.Rows.Count > 0 || read.excelData.Columns.Count > 0)
                    {
                        int column_counter = 1;
                        foreach (DataColumn thisColumn in excelDataTbl.Columns)
                        {
                            // Create the column mapping custom control
                            Column_Assignment_Control thisColControl = new Column_Assignment_Control();

                            // Get the column name
                            string thisColumnName = thisColumn.ColumnName;
                            thisColControl.Column_Name = thisColumnName;
                            if (thisColumnName == "F" + column_counter)
                            {
                                thisColControl.Empty = true;
                            }

                            thisColControl.Location = new Point(10, 10 + ((column_counter - 1) * 30));
                            columnNamePanel.Controls.Add(thisColControl);
                            column_map_inputs.Add(thisColControl);

                            // Select value in list control that matches to a Column Name
                            thisColControl.Select_List_Item(thisColumnName);

                            // Increment for the next column
                            column_counter++;
                        }

                        // Move to STEP 3
                        show_step_3();

                        if (column_map_inputs.Count > 0)
                        {
                            // Move to STEP 4
                            show_step_4();
                        }
                    }


                    // Close the reader
                    read.Close();
                }
            }
            catch (Exception ex)
            {
                ErrorMessageBox.Show(ex.Message, "Unexpected Error", ex);
            }
            finally
            {
                // change cursor back to default
                Cursor = Cursors.Default;

                // Close the reader
                read.Close();
            }
        }
Пример #7
0
        /// <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;
            }
        }