示例#1
0
 public void AddCall(FullCall call)
 {
     phones.AddCall(call);
 }
示例#2
0
        public void ParserCheckLists(IEnumerable <IFormFile> files)
        {
            using (var stream = files.First().OpenReadStream())
            {
                XLWorkbook wb = new XLWorkbook(stream);
                FillStageDictionary(wb);
            }


            foreach (var file in files)
            {
                string Manager = Regex.Match(file.FileName, @"(\w+)").Groups[1].Value;
                using (var stream = file.OpenReadStream())
                {
                    XLWorkbook   wb   = new XLWorkbook(stream);
                    IXLWorksheet page = wb.Worksheets.First();

                    IXLCell  cell = page.Cell(1, 5);
                    DateTime curDate;
                    if (cell.DataType == XLDataType.DateTime)
                    {
                        curDate = cell.GetDateTime();
                    }
                    else
                    {
                        if (!DateTime.TryParse(cell.GetString(), new CultureInfo("ru-RU"), DateTimeStyles.None, out curDate))
                        {
                            DateTime.TryParse(cell.GetString(), new CultureInfo("en-US"), DateTimeStyles.None, out curDate);
                        }
                    }
                    string  phoneNumber;
                    IXLCell phoneCell;
                    while (!(cell.IsEmpty() && cell.CellRight().IsEmpty() && !cell.IsMerged()))
                    {
                        if (cell.GetString() != "")
                        {
                            if (cell.DataType == XLDataType.DateTime)
                            {
                                curDate = cell.GetDateTime();
                            }
                            else
                            {
                                if (!DateTime.TryParse(cell.GetString(), new CultureInfo("ru-RU"), DateTimeStyles.None, out curDate))
                                {
                                    DateTime.TryParse(cell.GetString(), new CultureInfo("en-US"), DateTimeStyles.None, out curDate);
                                }
                            }
                        }

                        phoneCell = cell.CellBelow();
                        if (phoneCell.GetString() == "")
                        {
                            phoneCell = phoneCell.CellBelow();
                        }
                        if (phoneCell.GetString() != "")
                        {
                            string link;
                            if (phoneCell.HasHyperlink)
                            {
                                link = phoneCell.GetHyperlink().ExternalAddress.AbsoluteUri;
                            }
                            else
                            {
                                link = "";
                            }
                            Match outgoing = Regex.Match(phoneCell.GetString().ToUpper(), @"ИСХОДЯЩИЙ");
                            phoneNumber = Regex.Replace(phoneCell.GetString().ToUpper(), @"[^\d]", String.Empty);
                            string oldphonenum = phoneNumber;
                            oldphonenum = "8 (" + oldphonenum.Substring(1, 3) + ") " + oldphonenum.Substring(4, 3) + "-" + oldphonenum.Substring(7, 2) + "-" + oldphonenum.Substring(9);
                            while (phoneNumber[0] == '0')
                            {
                                phoneNumber = phoneNumber.Substring(1);
                            }
                            if (phoneNumber[0] == '9')
                            {
                                phoneNumber = '8' + phoneNumber;
                            }
                            if (phoneNumber[0] == '7' || phoneNumber[0] == '8')
                            {
                                phoneNumber = "8 (" + phoneNumber.Substring(1, 3) + ") " + phoneNumber.Substring(4, 3) + "-" + phoneNumber.Substring(7, 2) + "-" + phoneNumber.Substring(9);
                            }

                            if (processedCalls.Exists(c => c.Client == oldphonenum) && oldphonenum != phoneNumber)
                            {
                                var testCall = processedCalls.Where(c => c.Client == oldphonenum).First();
                                processedCalls.Remove(testCall);
                                testCall.Client = phoneNumber;
                                processedCalls.Add(testCall);
                            }
                            if (processedCalls.Exists(c => c.Client == phoneNumber && c.Link == ""))
                            {
                                var testCall = processedCalls.Where(c => c.Client == phoneNumber).First();
                                testCall.Link = link;
                            }

                            var   CellStage = page.Cell("A5");
                            Regex rx        = new Regex("ИТОГ");
                            int   corrRow   = 5;
                            Match Mcomment  = Regex.Match(page.Cell(corrRow, 1).GetString().ToUpper(), @"КОРРЕКЦИИ");
                            while (!Mcomment.Success)
                            {
                                corrRow++;
                                Mcomment = Regex.Match(page.Cell(corrRow, 1).GetString().ToUpper(), @"КОРРЕКЦИИ");
                            }
                            while (!rx.Match(CellStage.GetString().ToUpper()).Success&& !rx.Match(CellStage.CellRight().CellRight().CellRight().GetString().ToUpper()).Success)
                            {
                                if (CellStage.GetString() != "" && page.Cell(CellStage.Address.RowNumber, cell.Address.ColumnNumber).GetString() != "")
                                {
                                    var exCallSeq = processedCalls.Where(c => (c.Client == phoneNumber));
                                    var exCall    = new ProcessedCall();
                                    if (exCallSeq.Count() > 0)
                                    {
                                        exCall = exCallSeq.First();
                                        //exCall.StartDateAnalyze = curDate.AddDays(-1);
                                    }
                                    else
                                    {
                                        exCall.ClientState      = "";
                                        exCall.StartDateAnalyze = DateTime.MinValue;
                                    }
                                    if (curDate >= exCall.StartDateAnalyze ||
                                        (
                                            exCall.ClientState.ToUpper() == "В РАБОТЕ") &&
                                        exCall.StartDateAnalyze < DateTime.Today.AddDays(1)
                                        )
                                    {
                                        DateTime DateNext        = new DateTime();
                                        var      NextContactCell = page.Cell(corrRow + 6, cell.Address.ColumnNumber);
                                        if (NextContactCell.GetString() != "")
                                        {
                                            if (NextContactCell.DataType == XLDataType.DateTime)
                                            {
                                                DateNext = NextContactCell.GetDateTime();
                                            }
                                            else
                                            {
                                                if (!DateTime.TryParse(NextContactCell.GetString(), new CultureInfo("ru-RU"), DateTimeStyles.None, out DateNext))
                                                {
                                                    DateTime.TryParse(NextContactCell.GetString(), new CultureInfo("en-US"), DateTimeStyles.None, out DateNext);
                                                }
                                            }
                                        }
                                        if (curDate > DateTime.Now.AddMonths(-1) && Regex.Match(file.Name, "Гакова|Малькова|Лукина|Кожевникова|Рыбачук", RegexOptions.IgnoreCase).Success)
                                        {
                                            phones.AddCall(new FullCall(phoneNumber, link, Regex.Replace(CellStage.GetString(), @"[\d()]", String.Empty).Trim(), curDate, outgoing.Success, page.Cell(corrRow, cell.Address.ColumnNumber).GetString(), Manager, page.Cell(corrRow + 5, cell.Address.ColumnNumber).GetString(), DateNext));
                                        }
                                        phonesForFirst.AddCall(new FullCall(phoneNumber, link, Regex.Replace(CellStage.GetString(), @"[\d()]", String.Empty).Trim(), curDate, outgoing.Success, page.Cell(corrRow, cell.Address.ColumnNumber).GetString(), Manager, page.Cell(corrRow + 5, cell.Address.ColumnNumber).GetString(), DateNext));
                                    }
                                }
                                CellStage = CellStage.CellBelow();
                            }
                        }

                        cell = cell.CellRight();
                    }
                    phones.CleanSuccess(ref processedCalls);
                }
            }
        }