async private void btnExportToExcel_Click(object sender, EventArgs e)
        {
            bool   isSuccess = false;
            string message   = string.Empty;

            try
            {
                ShowProgressingDialog();
                string exportedFileName             = ConfigurationManager.AppSettings["ExportFileName"];
                string splittedPrefixFileName       = ConfigurationManager.AppSettings["SplittedPrefixFileName"];
                string PasswordProtectedFilesFolder = ConfigurationManager.AppSettings["PasswordProtectedFiles"];
                string WrongFormatFilesFolder       = ConfigurationManager.AppSettings["WrongFormatFiles"];
                string WrongFormatSplittedFiles     = ConfigurationManager.AppSettings["WrongFormatSplittedFiles"];
                string ProcessedFilesFolder         = ConfigurationManager.AppSettings["ProcessedFiles"];
                string NoMatchingHireFolder         = ConfigurationManager.AppSettings["NoMatchingHire"];

                if (!Directory.Exists(txtDestinationFolderPath.Text.Trim()))
                {
                    Directory.CreateDirectory(txtDestinationFolderPath.Text.Trim());
                }
                if (File.Exists(txtPayRollFilePath.Text.Trim()))
                {
                    FileInfo resultsfileInfo   = new FileInfo(txtPayRollFilePath.Text.Trim());
                    var      resultsFileStatus = IsFileLocked(resultsfileInfo);
                    if (resultsFileStatus)
                    {
                        List <string> PasswordProtectedFiles = new List <string>();
                        List <string> WrongFormatFiles       = new List <string>();
                        List <string> ProcessedFiles         = new List <string>();
                        List <string> NoMatchingHireFiles    = new List <string>();
                        if (ExportDataIntoExcel.StartExport(WrongFormatFilesFolder, WrongFormatSplittedFiles, txtSourceFilePath.Text.Trim().Split(';'), txtDestinationFolderPath.Text.Trim(),
                                                            exportedFileName, splittedPrefixFileName, txtFilePrefix.Text, txtPassword1.Text, txtPassword2.Text, txtPassword3.Text,
                                                            txtPassword4.Text, txtPassword5.Text,
                                                            txtPassword6.Text, ref PasswordProtectedFiles,
                                                            ref WrongFormatFiles))
                        {
                            //HideProgressingDialog();
                            //MessageBox.Show("Data has been successfully exported into Excel.");
                            txtResultsFile.Text = txtDestinationFolderPath.Text.Trim() + "//" + exportedFileName;
                            MergeWithpayRollFile(ref isSuccess, ref message, ref ProcessedFiles,
                                                 ref NoMatchingHireFiles);
                        }
                        else
                        {
                            isSuccess = false;
                            message   = "Data has been unsuccessfully exported into Excel.";
                        }

                        if (isSuccess)
                        {
                            //Thread.Sleep(5000);
                            //copy protected files into OpenFailed folder
                            if (!Directory.Exists(System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(), PasswordProtectedFilesFolder)))
                            {
                                Directory.CreateDirectory(System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(), PasswordProtectedFilesFolder));
                            }
                            foreach (string lstItem in PasswordProtectedFiles)
                            {
                                await AssementsUpload.MoveFileAsync(
                                    lstItem, System.IO.Path.Combine(
                                        System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(),
                                                               PasswordProtectedFilesFolder), new FileInfo(lstItem).Name)
                                    );
                            }
                            //move incorrect format files to FormatNotFound folder start
                            #region move incorrect format files to FormatNotFound folder start
                            if (!Directory.Exists(System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(), WrongFormatFilesFolder)))
                            {
                                Directory.CreateDirectory(System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(), WrongFormatFilesFolder));
                            }
                            foreach (string lstItem in WrongFormatFiles)
                            {
                                await AssementsUpload.MoveFileAsync(
                                    lstItem, System.IO.Path.Combine(
                                        System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(),
                                                               WrongFormatFilesFolder), new FileInfo(lstItem).Name)
                                    );
                            }
                            #endregion move incorrect format files to FormatNotFound folder end
                            //move incorrect format files to FormatNotFound folder end

                            //move processed files to processed files folder start
                            #region move processed files to processed files folder start
                            if (!Directory.Exists(System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(), ProcessedFilesFolder)))
                            {
                                Directory.CreateDirectory(System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(), ProcessedFilesFolder));
                            }
                            foreach (string lstItem in ProcessedFiles)
                            {
                                await AssementsUpload.MoveFileAsync(
                                    System.IO.Path.Combine(txtSourceFilePath.Text.Trim(), lstItem),
                                    System.IO.Path.Combine(
                                        System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(),
                                                               ProcessedFilesFolder), lstItem)
                                    );
                            }
                            #endregion move processed files to processed files folder end
                            //move processed files to processed files folder end

                            //move unprocessed files to processed files folder start
                            #region move unprocessed files to processed files folder start
                            if (!Directory.Exists(System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(), NoMatchingHireFolder)))
                            {
                                Directory.CreateDirectory(System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(), NoMatchingHireFolder));
                            }
                            foreach (string lstItem in NoMatchingHireFiles)
                            {
                                await AssementsUpload.MoveFileAsync(
                                    System.IO.Path.Combine(txtSourceFilePath.Text.Trim(), lstItem),
                                    System.IO.Path.Combine(
                                        System.IO.Path.Combine(txtDestinationFolderPath.Text.Trim(),
                                                               NoMatchingHireFolder), lstItem)
                                    );
                            }
                            #endregion move unprocessed files to processed files folder end
                            //move unprocessed files to processed files folder end
                        }
                    }
                    else
                    {
                        message = "Sorry, PayRoll file is already in use Please close all open instances.";
                    }
                }
                else
                {
                    message = "Sorry, PayRoll file is doesn't exist.";
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                message = "Please check source and destination paths " + ex.Message;
            }
            finally
            {
                tabControl1.SelectedIndex = 1;
                HideProgressingDialog();
                MessageBox.Show(message);
            }
        }
        public void MergeWithpayRollFile
            (ref bool isSuccess, ref string message, ref List <string> ProcessedFiles, ref List <string> NoMatchingHireFiles)
        {
            if (File.Exists(txtResultsFile.Text.Trim()))
            {
                FileInfo resultsfileInfo   = new FileInfo(txtResultsFile.Text.Trim());
                var      resultsFileStatus = IsFileLocked(resultsfileInfo);
                if (resultsFileStatus)
                {
                    if (File.Exists(txtPayRollFilePath.Text.Trim()))
                    {
                        FileInfo payRollfileInfo   = new FileInfo(txtPayRollFilePath.Text.Trim());
                        var      payRollFileStatus = IsFileLocked(payRollfileInfo);
                        if (payRollFileStatus)
                        {
                            // ShowProgressingDialog();

                            string exportedFileName         = ConfigurationManager.AppSettings["ExportFileName"];
                            string duplicateRecordsFileName = ConfigurationManager.AppSettings["DuplicateRecordsFileName"];
                            string splittedPrefixFileName   = ConfigurationManager.AppSettings["SplittedPrefixFileName"];
                            string payrollColumnName        = ConfigurationManager.AppSettings["PayrollNumberColumnName"];
                            string resultsFile = txtResultsFile.Text.Trim();

                            DataTable duplicateResults   = null;
                            DataTable mergedResulteTable = null;

                            int dateTolarence = Convert.ToInt32(txtDateTolarence.Text);

                            bool result = ExportDataIntoExcel.ReadPayrollUpdateResultFile(payrollColumnName, txtPayRollFilePath.Text.Trim(),
                                                                                          txtDestinationFolderPath.Text.Trim(), exportedFileName,
                                                                                          resultsFile, dateTolarence, out duplicateResults,
                                                                                          out mergedResulteTable, out ProcessedFiles, out NoMatchingHireFiles);

                            if (!result)
                            {
                                mergedResultSet = mergedResulteTable;
                                string[] columns = new[] { "Last Name", "First Name", "Last Hire", "EmployeeNo", "ProfCent Code", "Location Code", "Job Title" };
                                extract  obj     = new extract();
                                obj.SaveFileInSpecifiedPathXLSX(duplicateResults, columns, Path.Combine(txtDestinationFolderPath.Text.Trim(), duplicateRecordsFileName));

                                HideProgressingDialog();

                                if ((MessageBox.Show("Duplicate records were found and concern file has been saved into destination folder", "Do you want to continue merging anyway?", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == DialogResult.Yes))
                                {
                                    ShowProgressingDialog();
                                    ContinueMerging(ref isSuccess, ref message);
                                }
                            }
                            else
                            {
                                mergedResultSet = mergedResulteTable;
                                string[] columns = new[] { "File Name", "First Name", "Last Name", "Name", "Date of Results", "Ordered By", "Job Title", "ProfCent Code", "Location", "EmployeeNo", "Last Hire Date", "Payroll Job Title", "Candidate ID", "School", "Major" };
                                extract  obj     = new extract();
                                obj.SaveFileInSpecifiedPathXLSX(mergedResulteTable, columns,
                                                                Path.Combine(txtDestinationFolderPath.Text.Trim(), exportedFileName));
                                txtTab3ResultFile.Text = txtDestinationFolderPath.Text.Trim() + "//" + exportedFileName;
                                isSuccess = true;
                                message   = "Payroll file has been merged successfully";
                            }
                        }
                        else
                        {
                            isSuccess = false;
                            message   = "Sorry, PayRoll file is already in use Please close all open instances.";
                        }
                    }
                    else
                    {
                        isSuccess = false;
                        message   = "Please select Payroll file";
                    }
                }
                else
                {
                    isSuccess = false;
                    message   = "Sorry, Results file is already in use Please close all open instances.";
                }
            }
            else
            {
                isSuccess = false;
                message   = "Please select results file.";
            }
        }