private void ContinueMerging(ref bool isSuccess, ref string message)
        {
            string exportedFileName = ConfigurationManager.AppSettings["ExportFileName"];

            string[] columns = new[] { "File Name", "First Name", "Last Name", "Name", "Date of Results", "Ordered By", "Job Title", "ProfCent Code", "Location", "EmployeeNo", "Last Hire Date" };
            extract  obj     = new extract();

            obj.SaveFileInSpecifiedPathXLSX(mergedResultSet, columns, Path.Combine(txtDestinationFolderPath.Text.Trim(), exportedFileName));
            isSuccess = true;
            message   = "Payroll file has been merged successfully";
        }
        private void btnUploadDocs_Click(object sender, EventArgs e)
        {
            if (!File.Exists(txtUploadDocs.Text.Trim()))
            {
                MessageBox.Show("Please select ATS results file");
                return;
            }

            FileInfo payRollfileInfo   = new FileInfo(txtUploadDocs.Text.Trim());
            var      payRollFileStatus = IsFileLocked(payRollfileInfo);

            if (!payRollFileStatus)
            {
                MessageBox.Show("Sorry, ATS Results file is already in use Please close all open instances.");
                return;
            }

            if (txtUserName.Text.Trim().Length <= 3)
            {
                MessageBox.Show("Please enter user name");
                return;
            }
            else if (txtPassword.Text.Trim().Length <= 3)
            {
                MessageBox.Show("Please enter password");
                return;
            }
            ShowProgressingDialog();
            extract programObj = new extract();

            try
            {
                var ATSResults = programObj.ReadExcelSpecificRowsFile(txtUploadDocs.Text.Trim(), Convert.ToInt32(txtRecordsFrom.Text) - 1, Convert.ToInt32(txtRecordsTo.Text) - 1);

                List <LaserFischeDto> laserFischeDtoList = new List <LaserFischeDto>();

                var filePath = Path.GetDirectoryName(txtUploadDocs.Text.Trim());

                foreach (DataRow row in ATSResults.Rows)
                {
                    LaserFischeDto laserFischeDto = new LaserFischeDto();
                    laserFischeDto.UniqueId   = row["candidateassesmentdocuploadid"].ToString();
                    laserFischeDto.UploadPath = "\\Assessments\\";
                    laserFischeDto.FileName   = row["AssesmentFileName"].ToString();

                    Byte[] bytes = File.ReadAllBytes(filePath + "\\" + laserFischeDto.FileName);
                    String file  = Convert.ToBase64String(bytes);
                    laserFischeDto.Base64Content = file;

                    laserFischeDtoList.Add(laserFischeDto);
                }

                var laserFischeList = UploadDocuments(laserFischeDtoList);

                ATSResults.Columns.Add("DocEntryId");

                int i = 0;

                foreach (var item in laserFischeList)
                {
                    ATSResults.Rows[i]["DocEntryId"] = item.DocEntryId;
                    if (item.DocEntryId > 0)
                    {
                        ATSResults.Rows[i]["UploadedToLaserFische"] = "Yes";
                    }
                    i++;
                }

                string[] columnNames = (from dc in ATSResults.Columns.Cast <DataColumn>()
                                        select dc.ColumnName).ToArray();

                programObj.SaveFileInSpecifiedPathXLSX(ATSResults, columnNames, filePath + "\\ATSResultsFile_" + txtRecordsFrom.Text + "_" + txtRecordsTo.Text + ".xlsx");

                Assessments AssessmentsObj = new Assessments(txtUserName.Text.Trim(), "Santhosh Komarraju");

                AssessmentsObj.UpdateCandidateInfo(ATSResults);

                HideProgressingDialog();

                MessageBox.Show("UploadDocuments Completed");
            }
            catch (Exception ex)
            {
                HideProgressingDialog();
                logger.Error(ex.Message);
                MessageBox.Show("UploadDocuments Faild " + ex.Message);
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (!File.Exists(txtTab3ResultFile.Text.Trim()))
            {
                MessageBox.Show("Please select result file");
                return;
            }

            FileInfo payRollfileInfo   = new FileInfo(txtTab3ResultFile.Text.Trim());
            var      payRollFileStatus = IsFileLocked(payRollfileInfo);

            if (!payRollFileStatus)
            {
                MessageBox.Show("Sorry, Results file is already in use Please close all open instances.");
                return;
            }

            try
            {
                ShowProgressingDialog();
                extract programObj = new extract();
                if (mergedResultSet == null)
                {
                    mergedResultSet = programObj.ReadExcelFile(txtTab3ResultFile.Text.Trim());
                }

                Assessments AssessmentsObj = new Assessments(txtUserName.Text.Trim(), "Santhosh Komarraju");

                mergedResultSet = mergedResultSet.AsEnumerable()
                                  .Where(r => r.Field <string>("EmployeeNo") != "")
                                  .CopyToDataTable();

                //CreatedByName can get after we loged in
                DataSet resultTables = AssessmentsObj.SaveCandidateInfo(mergedResultSet);
                if (resultTables.Tables.Count >= 1)
                {
                    if (resultTables.Tables[0].Rows.Count >= 1)
                    {
                        string[] columnNames = (from dc in resultTables.Tables[0].Columns.Cast <DataColumn>()
                                                select dc.ColumnName).ToArray();

                        var filePath = Path.GetDirectoryName(txtTab3ResultFile.Text.Trim()) + "\\ATSResultsFile.xlsx";
                        programObj.SaveFileInSpecifiedPathXLSX(resultTables.Tables[0], columnNames, filePath);
                        HideProgressingDialog();
                        MessageBox.Show("Assessment Meta Data to ATS is Completed");
                        tabControl1.SelectedIndex = 2;
                        txtUploadDocs.Text        = filePath;
                    }
                }
                else
                {
                    HideProgressingDialog();
                    MessageBox.Show("Assessment Meta Data to ATS is failed");
                }
            }
            catch (Exception ex)
            {
                HideProgressingDialog();
                logger.Error(ex.Message);
                MessageBox.Show("Assessment Meta Data to ATS is " + ex.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.";
            }
        }