Example #1
0
        public void DoRevise()
        {
            UpdateProgress(currentProgress, "---Чтение содержимого выбранных файлов");

            double progressPerFile = 50.0d / (terminalFiles.Count + 1);

            UpdateProgress(currentProgress, "Чтениые файла: " + halvaCardInfo.FileName);
            CsvFileContentReader.ReadCsvFileContent(halvaCardInfo);
            if (halvaCardInfo.FileContents.Count == 0)
            {
                UpdateProgress(currentProgress, "!!!Файл с отчетом по картам 'Халва' не содержит данных");
                return;
            }

            currentProgress += progressPerFile;
            UpdateProgress(currentProgress, "Считано строк: " + halvaCardInfo.FileContents.Count);

            long totalLinesReaded = 0;

            foreach (ItemFileInfo fileInfo in terminalFiles)
            {
                UpdateProgress(currentProgress, "Чтение файла: " + fileInfo.FileName);
                UpdateProgress(currentProgress, "Тип файла: " + ExcelFileContentReader.ReadExcelFileContent(fileInfo));

                currentProgress += progressPerFile;
                UpdateProgress(currentProgress, "Считано строк: " + fileInfo.FileContents.Count);
                totalLinesReaded += fileInfo.FileContents.Count;
            }

            if (totalLinesReaded == 0)
            {
                UpdateProgress(currentProgress, "!!!В выбранных файлах с отчетами по терминалам " +
                               "не удалось считать ни одной строки");
                return;
            }

            UpdateProgress(currentProgress, "---Сверка считанных данных");
            int    fullCoincidence    = 6;
            double progressPerContent = 40.0d / halvaCardInfo.FileContents.Count;

            foreach (FileContent halvaContent in halvaCardInfo.FileContents)
            {
                currentProgress += progressPerContent;
                UpdateProgress(currentProgress);

                int coincidence = 0;
                foreach (ItemFileInfo terminalFile in terminalFiles)
                {
                    if (!string.IsNullOrEmpty(halvaContent.UniqueOperationNumberRNN))
                    {
                        FileContent terminalContent = terminalFile.FileContents.Where(
                            x => x.UniqueOperationNumberRNN.Equals(halvaContent.UniqueOperationNumberRNN)).FirstOrDefault();

                        if (terminalContent != null)
                        {
                            halvaContent.CoincidenceRowNumber = terminalContent.CoincidenceRowNumber;

                            if (halvaContent.AuthorizationCode.Equals(terminalContent.AuthorizationCode))
                            {
                                coincidence++;
                            }
                            else
                            {
                                halvaContent.Comment += "Код авторизации; ";
                            }

                            CheckCoincidence(halvaContent, terminalContent, out int coin, out string comm);
                            coincidence          += coin;
                            halvaContent.Comment += comm;
                        }
                    }

                    if (coincidence == 0)
                    {
                        List <FileContent> searchResults = terminalFile.FileContents.Where(
                            x => x.AuthorizationCode.Equals(halvaContent.AuthorizationCode)).ToList();

                        if (searchResults.Count == 0)
                        {
                            continue;
                        }

                        foreach (FileContent terminalContent in searchResults)
                        {
                            if (!CheckCoincidence(halvaContent, terminalContent, out int coin, out string comm))
                            {
                                continue;
                            }

                            halvaContent.Comment += "Уникальный номер операции (RNN); ";
                            halvaContent.CoincidenceRowNumber = terminalContent.CoincidenceRowNumber;

                            coincidence          += coin;
                            halvaContent.Comment += comm;
                        }
                    }

                    if (coincidence == 0)
                    {
                        continue;
                    }

                    coincidence++;
                    halvaContent.CoincidenceSource = terminalFile.FullPath;
                    break;
                }

                halvaContent.CoincidencePercent = (double)coincidence / (double)fullCoincidence;
                if (coincidence == fullCoincidence)
                {
                    halvaContent.CoincidenceType = "Полное";
                }
                else if (coincidence == 0)
                {
                    halvaContent.CoincidenceType = "Не найдено";
                }
                else
                {
                    halvaContent.CoincidenceType = "Частичное";
                }
            }

            UpdateProgress(currentProgress, "---Выгрузка данных в Excel");
            string resultFile = ExcelFileContentWriter.WriteFileInfoToExcel(halvaCardInfo, UpdateProgress, currentProgress);

            if (!string.IsNullOrEmpty(resultFile))
            {
                UpdateProgress(currentProgress, "Данные сохранены в файл: " + resultFile);
                Process.Start(resultFile);
            }

            UpdateProgress(100, "===Завершено");
        }
Example #2
0
        private bool CheckCoincidence(FileContent halvaContent, FileContent terminalContent, out int coincidence, out string comment)
        {
            coincidence = 0;
            comment     = string.Empty;
            bool errorDate = false;
            bool errorTime = false;

            if (halvaContent.TransactionCommittingDate.Equals(terminalContent.TransactionCommittingDate))
            {
                coincidence++;
            }
            else
            {
                bool isDtHalvaParsed    = DateTime.TryParse(halvaContent.TransactionCommittingDate, out DateTime dtHalva);
                bool isDtTerminalParsed = DateTime.TryParse(terminalContent.TransactionCommittingDate, out DateTime dtTerminal);

                if (isDtHalvaParsed && isDtTerminalParsed)
                {
                    if (dtHalva.Date == dtTerminal.Date)
                    {
                        coincidence++;
                    }
                    else
                    {
                        errorDate = true;
                        comment  += "Дата совершения транзакции; ";
                    }
                }
                else
                {
                    errorDate = true;
                    comment  += "Дата совершения транзакции; ";
                }
            }

            int halvaTimeLength  = halvaContent.TransactionCommitingTime.Length;
            int resultTimeLength = terminalContent.TransactionCommitingTime.Length;

            if (halvaTimeLength >= 5 && resultTimeLength >= 5)
            {
                string halvaTime  = halvaContent.TransactionCommitingTime.Substring(0, 5);
                string resultTime = terminalContent.TransactionCommitingTime.Substring(0, 5);
                resultTime = resultTime.Replace('.', ':');                 //For Sberbank time format

                if (TimeSpan.TryParse(halvaTime, out TimeSpan halvaTimeSpan) &&
                    TimeSpan.TryParse(resultTime, out TimeSpan resultTimeSpan))
                {
                    if (halvaContent.City.ToLower().EndsWith("уфа"))
                    {
                        resultTimeSpan -= TimeSpan.FromHours(2);
                    }

                    if (Math.Abs((resultTimeSpan - halvaTimeSpan).TotalMinutes) <= 2)
                    {
                        coincidence++;
                    }
                    else
                    {
                        errorTime = true;
                        comment  += "Время совершения транзакции; ";
                    }
                }
                else
                {
                    if (halvaTime.Equals(resultTime))
                    {
                        coincidence++;
                    }
                    else
                    {
                        errorTime = true;
                        comment  += "Время совершения транзакции; ";
                    }
                }
            }
            else
            {
                if (halvaContent.TransactionCommitingTime.Equals(terminalContent.TransactionCommitingTime))
                {
                    coincidence++;
                }
                else
                {
                    errorTime = true;
                    comment  += "Время совершения транзакции; ";
                }
            }

            if (errorDate && errorTime)
            {
                return(false);
            }

            if (double.TryParse(halvaContent.OperationAmount, out double halvaOperationAmountParsed) &&
                double.TryParse(terminalContent.OperationAmount, out double resultOperationAmountParsed))
            {
                if (halvaOperationAmountParsed == resultOperationAmountParsed)
                {
                    coincidence++;
                }
                else
                {
                    comment += "Сумма операции; ";
                }
            }
            else
            {
                if (halvaContent.OperationAmount.Equals(terminalContent.OperationAmount))
                {
                    coincidence++;
                }
                else
                {
                    comment += "Сумма операции; ";
                }
            }

            int halvaCardLength  = halvaContent.CardNumber.Length;
            int resultCardLength = terminalContent.CardNumber.Length;

            if (halvaCardLength >= 4 && resultCardLength >= 4)
            {
                string halvaCardLast4  = halvaContent.CardNumber.Substring(halvaCardLength - 4, 4);
                string resultCardLast4 = terminalContent.CardNumber.Substring(halvaCardLength - 4, 4);

                if (halvaCardLast4.Equals(resultCardLast4))
                {
                    coincidence++;
                }
                else
                {
                    comment += "Номер карты; ";
                }
            }
            else
            {
                if (halvaContent.CardNumber.Equals(terminalContent.CardNumber))
                {
                    coincidence++;
                }
                else
                {
                    comment += "Номер карты; ";
                }
            }

            return(true);
        }