Exemple #1
0
        // Get all recorded sorting operations if any exists in format
        // Id: 1; Sorted Date: yyyy/MM/dd HH:mm:ss;
        public string GetAllRecordsList()
        {
            if (!Directory.Exists(ResultDirectory))
            {
                throw new FileNotFoundException("There are no sorting results present.");
            }

            FileInfo[] vFiles = GetFiles();

            if (vFiles.Length == 0)
            {
                throw new FileNotFoundException("There are no sorting results present.");
            }

            List <SortedData> vRecords = new List <SortedData>();

            foreach (FileInfo vFile in vFiles)
            {
                bool vSuccess = int.TryParse(vFile.Name.Replace(vFile.Extension, ""), out int vFileID);
                if (vSuccess)
                {
                    SortedData vDataEntry = new SortedData
                    {
                        ID       = vFileID,
                        SortDate = vFile.LastWriteTime
                    };
                    vRecords.Add(vDataEntry);
                }
            }

            return("Available results lists IDs:" +
                   Environment.NewLine + string.Join(", " + Environment.NewLine, vRecords.OrderBy(r => r.ID)));
        }
Exemple #2
0
        // Return single record if passed ID exits
        public string GetRecord(int pID)
        {
            if (!Directory.Exists(ResultDirectory))
            {
                throw new FileNotFoundException("There are no sorting results present.");
            }

            FileInfo[] vFiles = GetFiles(pID);

            if (vFiles.Length == 0)
            {
                throw new IndexOutOfRangeException("There is no records with pesented ID.");
            }

            _ = int.TryParse(vFiles[0].Name.Replace(vFiles[0].Extension, ""), out int vFileID);
            SortedData vDataEntry = new SortedData
            {
                ID       = vFileID,
                SortDate = vFiles[0].LastWriteTime
            };

            return(vDataEntry.ToString() +
                   Environment.NewLine + "Result" +
                   Environment.NewLine + File.ReadAllText(vFiles[0].FullName));
        }
Exemple #3
0
        public void SortDistances()
        {
            CreateDepths(Camera);

            SortedData.Clear();
            foreach (InstanceData t in Data.Where(t => t.Depth < CullDistance))
            {
                SortedData.Add(t, t.Depth);
            }
        }
Exemple #4
0
 public void Clear()
 {
     Data.Clear();
     SortedData.Clear();
 }
        public ActionResult AjaxLoading()
        {
            var draw          = Request.Form.GetValues("draw").FirstOrDefault();
            var start         = Request.Form.GetValues("start").FirstOrDefault();
            var length        = Request.Form.GetValues("length").FirstOrDefault();
            var sortColumn    = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
            var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
            var searchValue   = Request.Form.GetValues("search[value]").FirstOrDefault();

            int skip             = (start != null) ? Convert.ToInt32(start) : 0;
            int take             = (length != null) ? Convert.ToInt32(length) : 1;
            int totalRecordCount = 0;

            using (Context ctx = new Context())
            {
                totalRecordCount = ctx.BookObtainCount();
                var Data = ctx.BookGetAll();
                IOrderedEnumerable <Book> SortedData;
                if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
                {
                    if (sortColumnDir == "asc")
                    {
                        switch (sortColumn.ToLower())
                        {
                        case ("isbn"):
                            SortedData = Data.OrderBy(x => x.ISBN);
                            break;

                        case ("bookname"):
                            SortedData = Data.OrderBy(x => x.BookName);
                            break;

                        case ("pages"):
                            SortedData = Data.OrderBy(x => x.Pages);
                            break;

                        case ("daysoverdue"):
                            SortedData = Data.OrderBy(x => x.DaysOverdue);
                            break;

                        case ("genrename"):
                            SortedData = Data.OrderBy(x => x.GenreName);
                            break;

                        default:
                            SortedData = Data.OrderBy(x => x.BookName);
                            break;
                        }
                    }
                    else
                    {
                        switch (sortColumn.ToLower())
                        {
                        case ("isbn"):
                            SortedData = Data.OrderByDescending(x => x.ISBN);
                            break;

                        case ("bookname"):
                            SortedData = Data.OrderByDescending(x => x.BookName);
                            break;

                        case ("pages"):
                            SortedData = Data.OrderByDescending(x => x.Pages);
                            break;

                        case ("daysoverdue"):
                            SortedData = Data.OrderByDescending(x => x.DaysOverdue);
                            break;

                        case ("genrename"):
                            SortedData = Data.OrderByDescending(x => x.GenreName);
                            break;

                        default:
                            SortedData = Data.OrderByDescending(x => x.BookName);
                            break;
                        }
                    }
                }
                else
                {
                    SortedData = (IOrderedEnumerable <Book>)Data;
                }
                //Search
                IEnumerable <Book> FilteredAndSortedData;
                if (!string.IsNullOrEmpty(searchValue))
                {
                    FilteredAndSortedData = SortedData.Where
                                            (
                        x => ((x.ISBN != null && x.ISBN.Contains(searchValue)) |
                              ((x.BookName != null) && x.BookName.Contains(searchValue)) |
                              ((x.GenreName != null) && x.GenreName.Contains(searchValue))

                              )
                                            );
                }
                else
                {
                    FilteredAndSortedData = SortedData;
                }
                List <Book> FinalData     = FilteredAndSortedData.ToList();
                int         FilteredCount = FinalData.Count;
                return(Json(new { draw = draw, recordsTotal = totalRecordCount,
                                  recordsFiltered = FilteredCount,
                                  data = FinalData.Skip(skip).Take(take), }));
            }
        }