Пример #1
0
 public async Task <word_param[]> getPage(filter f, int start, int pageSize)
 {
     try
     {
         var q = (from c in db.words_list.AsNoTracking() select c);
         q = setWordListQueryFilter(f, q);
         if (f.isInverse)
         {
             q = q.OrderBy(c => c.reverse).ThenBy(c => c.field2).Skip(start * pageSize).Take(pageSize);
         }
         else
         {
             q = q.OrderBy(c => c.digit).ThenBy(c => c.field2).Skip(start * pageSize).Take(pageSize);
         }
         //var sql = q.ToSql();
         return(await q.ToArrayAsync());
     }
     catch (Exception ex)
     {
         if (Logger != null)
         {
             Logger.LogError(new EventId(0), ex, ex.Message);
             return(null);
         }
         else
         {
             throw ex;
         }
     }
     finally
     {
     }
 }
Пример #2
0
        public async Task <word_param_base> searchWord(filter f, string word)
        {
            //System.Runtime.CompilerServices.StrongBox <T>
            try
            {
                string w = f.isInverse == true?sharedTypes.atod(new string(word.Reverse().ToArray()), talpha) : sharedTypes.atod(word, talpha);

                int start = 0;
                var q     = (from c in db.words_list select c);

                q = setWordListQueryFilter(f, q);

                if (f.isInverse)
                {
                    q     = q.OrderBy(c => c.reverse).ThenBy(c => c.field2);
                    start = await(from c in q where w.CompareTo(c.reverse) > 0 select c).CountAsync();
                }
                else
                {
                    q     = q.OrderBy(c => c.digit).ThenBy(c => c.field2);
                    start = await(from c in q where w.CompareTo(c.digit) > 0 select c).CountAsync();
                }

                int pagenumber = start / 100;
                int count      = q.Count();

                if (count <= start)
                {
                    q = q.Skip((start - 1)).Take(1);
                }
                else
                {
                    q = q.Skip(start).Take(1);
                }
                word_param wp = await q.FirstOrDefaultAsync();

                word_param_base r = null;
                if (wp != null)
                {
                    r = (new word_param_base()
                    {
                        CountOfWords = count, wordsPageNumber = pagenumber, accent = wp.accent, digit = wp.digit, field2 = wp.field2, field5 = wp.field5, field6 = wp.field6, field7 = wp.field7, isdel = wp.isdel, isproblem = wp.isproblem, nom_old = wp.nom_old, own = wp.own, part = wp.part, reestr = wp.reestr, reverse = wp.reverse, suppl_accent = wp.suppl_accent, type = wp.type
                    });
                }
                return(r);
            }
            catch (Exception ex)
            {
                if (Logger != null)
                {
                    Logger.LogError(new EventId(0), ex, ex.Message);
                    return(null);
                }
                else
                {
                    throw ex;
                }
            }
        }
Пример #3
0
 public async Task <int> CountWords(filter f)
 {
     try
     {
         var q = (from c in db.words_list select c);
         q = setWordListQueryFilter(f, q);
         return(await q.CountAsync());
     }
     catch (Exception ex)
     {
         if (Logger != null)
         {
             Logger.LogError(new EventId(0), ex, ex.Message);
             return(-1);
         }
         else
         {
             throw ex;
         }
     }
 }
Пример #4
0
 // перетворення рядка в код (якщо не потрібно враховувати \', то askip=true)
 private IQueryable <word_param> setWordListQueryFilter(filter f, IQueryable <word_param> q)
 {
     if ((f.isStrFiltering) && (!string.IsNullOrEmpty(f.str)))
     {
         string s = sharedTypes.atod(f.str, talpha);
         //switch (f.fetchType)
         //{
         //    case FetchType.StartsWith:
         //        q = q.Where(c => c.digit.StartsWith(s));
         //        //q = q.Where(c => c.reestr.Replace("\"","").StartsWith(f.str));
         //        break;
         //    case FetchType.EndsWith:
         //        q = q.Where(c => c.digit.EndsWith(s));
         //        //q = q.Where(c => c.reestr.Replace("\"", "").EndsWith(f.str));
         //        break;
         //    case FetchType.Contains:
         //        q = q.Where(c => c.digit.Contains(s));
         //        //q = q.Where(c => c.reestr.Replace("\"", "").Contains(f.str));
         //        break;
         //}
         q = q.Where(c => EF.Functions.Like(c.digit, s));
     }
     if (f.ispclass)
     {
         q = q.Where(c => c.type == f.pclass);
     }
     if (f.ispofs)
     {
         if (f.pofs > 70)
         {
             q = q.Where(c => c.part == f.pofs);
         }
         else
         {
             q = q.Where(c => ((c.parts.gr_id == f.pofs) && (c.part < 70)));
         }
     }
     return(q);
 }