Ejemplo n.º 1
0
        public void TestFindTextInBrackets()
        {
            string          ToTest = @"abc123(hello), asdlf;kj(world)";
            MatchCollection Col    = RegexExpressions.GetTextFromBracketToBracket(ToTest);

            Assert.AreEqual(2, Col.Count);
            Assert.AreEqual("(hello)", Col[0].Value);
            Assert.AreEqual("(world)", Col[1].Value);
        }
Ejemplo n.º 2
0
        public void TestPhoneNumberRegex()
        {
            string          ToTest = @"+250 486-7712
+250-486-7712
250-486-7712, 250 486 7712, +250-486-7712
250-48507712"; // this line isn't a phone number due to the 7 characters instead of 3 then 4
            MatchCollection Col    = RegexExpressions.GetPhoneNumbers(ToTest);

            Assert.AreEqual(5, Col.Count);
            Assert.AreEqual("+250 486-7712", Col[0].Value);
            Assert.AreEqual("+250-486-7712", Col[1].Value);
            Assert.AreEqual("250-486-7712", Col[2].Value);
            Assert.AreEqual("250 486 7712", Col[3].Value);
            Assert.AreEqual("+250-486-7712", Col[4].Value);
        }
Ejemplo n.º 3
0
        public IList <TSHoursRecord> FindHoursRecords(string searchString)
        {
            var searchTokensList = SplittingSearchQueryToQueryList(searchString);

            IList <TSHoursRecord> hoursRecords = new List <TSHoursRecord>();

            //если введено две записи(например фамилия и отчетная дата)
            if (searchTokensList.Count != 0 && (searchTokensList.Count > 1 && searchTokensList.Count <= 3))
            {
                var    findRecordDate   = new DateTime(); //дата на начало времен по тому, что null не сделать
                var    listTexts        = new List <string>();
                var    projectShortName = string.Empty;
                double hours            = 0;
                if (searchTokensList.Count == 2)
                {
                    //пройти все значения и назначить дату если она есть иначе new DateTime()
                    foreach (var token in searchTokensList)
                    {
                        var tmpData   = CheckData(token);
                        var isProject = RegexExpressions.IsMatch(token.ToUpper());

                        if (tmpData != null)
                        {
                            findRecordDate = (DateTime)tmpData;
                        }
                        else if (isProject)
                        {
                            projectShortName = token;
                        }
                        else if (double.TryParse(token.Replace(".", ","), out var newhours))
                        {
                            hours = newhours;
                        }
                        else
                        {
                            listTexts.Add(token);
                        }
                    }
                    //Если текстовых полей не вводилось
                    if (listTexts.Count == 0)
                    {
                        hoursRecords = Get(records => records.Where(x =>
                                                                    //Код проекта и отчетная дата
                                                                    (x.Project.ShortName != null && x.Project.ShortName.ToLower() == projectShortName) &&
                                                                    (x.RecordDate != null && x.RecordDate == findRecordDate)
                                                                    ||
                                                                    //Код проекта и часы
                                                                    (x.Project.ShortName != null && x.Project.ShortName.ToLower() == projectShortName) &&
                                                                    (x.Hours != null && x.Hours == hours)
                                                                    )
                                           .OrderBy(x => x.Employee.LastName)
                                           //.ThenBy(x => x.Employee.FirstName)
                                           //.ThenBy(x => x.Employee.MidName)
                                           .ThenBy(x => x.RecordDate).ToList());
                    }

                    if (listTexts.Count == 1)
                    {
                        hoursRecords = Get(records => records.Where(x =>
                                                                    //Фамилия и отчетная дата
                                                                    ((x.Employee.LastName != null && x.Employee.LastName.ToLower().Contains(listTexts.FirstOrDefault())) &&
                                                                     (x.RecordDate != null && x.RecordDate == (DateTime)findRecordDate))
                                                                    ||
                                                                    //Имя и отчетная дата
                                                                    ((x.Employee.FirstName != null && x.Employee.FirstName.ToLower().Contains(listTexts.FirstOrDefault())) &&
                                                                     (x.RecordDate != null && x.RecordDate == findRecordDate))
                                                                    ||
                                                                    //Фамилия и код проекта
                                                                    (x.Employee.LastName != null && x.Employee.LastName.ToLower().Contains(listTexts.FirstOrDefault())) &&
                                                                    (x.Project.ShortName != null && x.Project.ShortName.ToLower() == projectShortName)
                                                                    ||
                                                                    //Фамилия и часы
                                                                    (x.Employee.LastName != null && x.Employee.LastName.ToLower().Contains(listTexts.FirstOrDefault())) &&
                                                                    (x.Hours != null && x.Hours == hours)

                                                                    )
                                           .OrderBy(x => x.Employee.LastName)
                                           //.ThenBy(x => x.Employee.FirstName)
                                           //.ThenBy(x => x.Employee.MidName)
                                           .ThenBy(x => x.RecordDate).ToList());
                    }
                    //Если задано два текстовых поля(например фамилия и состав работ)
                    else if (listTexts.Count == 2)
                    {
                        //пришлось создавать новые переменные, т.к Linq почему-то не понимает если напрямую указывать listTexts[0]
                        var firstText  = listTexts[0];
                        var secondText = listTexts[1];
                        hoursRecords = Get(records => records.Where(x =>
                                                                    //Фамилия и состав работ
                                                                    (x.Employee.LastName != null && x.Employee.LastName.ToLower().Contains(firstText) ||
                                                                     x.Employee.LastName.ToLower().Contains(secondText)) &&
                                                                    (x.Description != null && x.Description.ToLower().Contains(firstText)) ||
                                                                    (x.Description != null && x.Description.ToLower().Contains(secondText)))
                                           .Where(x => x.Employee.LastName.ToLower().Contains(firstText) || x.Employee.LastName.ToLower().Contains(secondText))
                                           .OrderBy(x => x.Employee.LastName)
                                           //.ThenBy(x => x.Employee.FirstName)
                                           //.ThenBy(x => x.Employee.MidName)
                                           .ThenBy(x => x.RecordDate).ToList());
                    }
                }
            }
            else if (searchTokensList.Count == 1)
            {
                var findDate = CheckData(searchString) ?? new DateTime();

                hoursRecords = Get(records => records.Where(x =>
                                                            (x.Employee.FirstName != null && x.Employee.FirstName.ToLower().Contains(searchTokensList.FirstOrDefault())) ||
                                                            (x.Employee.LastName != null && x.Employee.LastName.ToLower().Contains(searchTokensList.FirstOrDefault())) ||
                                                            (x.Employee.MidName != null && x.Employee.MidName.ToLower().Contains(searchTokensList.FirstOrDefault())) ||
                                                            (x.Project.ShortName != null && x.Project.ShortName.ToLower().Contains(searchTokensList.FirstOrDefault())) ||
                                                            (x.RecordDate != null && x.RecordDate == (DateTime)findDate)
                                                            //|| (hoursRecord.Hours != null && hoursRecord.Hours.Equals(Convert.ToDouble(searchTokensList.FirstOrDefault())))
                                                            || (x.Description != null && x.Description.Contains(searchTokensList.FirstOrDefault()))
                                                            /*|| (x.Created != null && x.Created.ToString().Contains(searchTokensList.FirstOrDefault()))*/)
                                   .OrderBy(x => x.Employee.LastName)
                                   //.ThenBy(x => x.Employee.FirstName)
                                   //.ThenBy(x => x.Employee.MidName)
                                   .ThenBy(x => x.RecordDate).ToList());
            }


            return(hoursRecords);
        }