Пример #1
0
        private void butStart_Click(object Sender, EventArgs e)
        {
            butStop.IsEnabled = true;
            nameOfFile        = new DataClassString2();

            worker1 = new Worker();
            worker1.ProcessChanged          += worker_ProcessChanged;
            worker1.WorkCompleted           += worker_WorkCompleted;
            worker1.ListBoxNotUniqEvent     += worker_ListBoxNotUniqEvent;
            worker1.ListBoxNotValidEvent    += worker_ListBoxNotValidEvent;
            worker1.ListBoxInBlackListEvent += worker_ListBoxInBlackListEvent;
            worker1.StageChanged            += worker_StageChanged;

            if (choosedFileName == null || choosedBlackListName == null)
            {
                MessageBox.Show("Select the input file and the blacklist");
            }
            else
            {
                butStart.IsEnabled = false;

                ParameterizedThreadStart forSecondThread2 = worker1.ReadTheFile;
                forSecondThread2 += worker1.ReadTheBlackList;
                forSecondThread2 += worker1.ValidationTaxId;
                forSecondThread2 += worker1.SearchNotUniqTaxId;
                forSecondThread2 += worker1.SearchTaxIdInBlackList;
                forSecondThread2 += worker1.WriteResultsIntoFile;

                nameOfFile.N1 = choosedFileName;
                nameOfFile.N2 = choosedBlackListName;

                Thread thread1 = new Thread(forSecondThread2);
                thread1.Start(nameOfFile);
            }
        }
Пример #2
0
        /// <summary>
        /// Reads data from a file with a black-list
        /// </summary>
        /// <param name="fileName">Contains paths and names of incoming files (a list of customers and a black-list)  </param>
        public void ReadTheBlackList(object fileName)
        {
            StageChanged("Loading information from the blacklist");

            string blistNameString;

            blistNameString = ((DataClassString2)fileName).N2;
            Excel.Application ObjWorkExcel = new Excel.Application();
            Excel.Workbook    ObjWorkBook  = ObjWorkExcel.Workbooks.Open(blistNameString);
            Excel.Worksheet   ObjWorkSheet = (Excel.Worksheet)ObjWorkBook.Sheets[1];

            var lastCell     = ObjWorkSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell);
            int lastColumnBL = (int)lastCell.Column;
            int lastRowBL    = (int)lastCell.Row;

            for (int i = 1; i <= lastColumnBL; i++)
            {
                ObjWorkSheet.Columns[i].AutoFit();
            }

            blackList = new DataClassString2[lastRowBL - 1];
            for (int i = 0; i < lastRowBL - 1; i++)
            {
                blackList[i]    = new DataClassString2();
                blackList[i].N1 = ObjWorkSheet.Cells[i + 2, 1].Text.ToString();
                blackList[i].N1 = blackList[i].N1.Trim();
                blackList[i].N2 = ObjWorkSheet.Cells[i + 2, 2].Text.ToString();
                blackList[i].N2 = blackList[i].N2.Trim();
            }

            ObjWorkBook.Close(false, Type.Missing, Type.Missing);
            ObjWorkExcel.Quit();
            GC.Collect();

            ProcessChanged(20);
        }