Пример #1
0
        ///////////////////////////////////////////////
        ///Background worker functions.
        ///////////////////////////////////////////////

        /// <summary>
        /// Background worker 1 work method.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if (state == State.LoadingFile)
            {
                input = new ExcelData(fileName);
            }
        }
Пример #2
0
        /// <summary>
        /// Starts filtering of the input Excel file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FilterStartButton_Click(object sender, EventArgs e)
        {
            //If rows have been confirmed.
            if (input.dataColumnsReady &&
                input.typeColumnsReady)
            {
                //Workbook
                output = new ExcelData(null);

                try
                {
                    //Read file from dialog.
                    NamesList      = new HashSet <string>();
                    FormulaStrings = new Dictionary <string, string>();
                    OpenFileDialog namesDialog   = new OpenFileDialog();
                    OpenFileDialog formulaDialog = new OpenFileDialog();
                    if (namesDialog.ShowDialog() == DialogResult.OK)
                    {
                        if (formulaDialog.ShowDialog() == DialogResult.OK)
                        {
                            StreamReader sr1 = new StreamReader(namesDialog.FileName);

                            StreamReader sr2 = new StreamReader(formulaDialog.FileName);
                            string       lineA;
                            string       lineB;
                            int          count = 1;
                            while ((lineA = sr1.ReadLine()) != null)
                            {
                                lineA = lineA.ToUpper();
                                lineB = sr2.ReadLine();
                                if (NamesList.Contains(lineA))
                                {
                                    //do nothing
                                    inputDuplicates++;
                                }
                                else
                                {
                                    NamesList.Add(lineA);
                                    FormulaStrings.Add(lineA, lineB);
                                }
                                count++;
                            }
                            sr1.Close();
                            sr2.Close();

                            //Launch worker threads.
                            state = State.FilterProcessing;
                            LoadingImage.Visible = true;
                            activeThreads        = 1;
                            WorkerThreadEnabled  = true;
                            backgroundWorker2.RunWorkerAsync();
                        }
                        else
                        {
                            throw new Exception("Error loading file.");
                        }
                    }
                    else
                    {
                        throw new Exception("Error loading file.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error cargando el archivo, verifique el formato.");
                }
            }
            else
            {
                MessageBox.Show("Por favor confimar fila y filtro");
            }
        }