Exemple #1
0
        //Refreshes the entire component catalogue by removing local, and then quering the database for them all again, also rebuilds categories
        public void Refresh()
        {
            try
            {
                //Check if any reservation is older than 5 days, then deletes them
                cdbUtil_.CheckReservations();

                AllComponentList = new ObservableCollection <Component>(cdbUtil_.GetAllComponents());
                var allLoanInformationList = new ObservableCollection <LoanInformation>(ldbUtil_.GetAllLoanInformation());

                loanInformationUpdaterThread_ = new Thread(() =>
                {
                    //Set up load bar:
                    MaxLoadbar        = AllComponentList.Count;
                    StatusBarText     = "Henter låne information...";
                    LoadBarVisibility = Visibility.Visible;

                    foreach (LoanInformation li in allLoanInformationList)
                    {
                        foreach (Component c in AllComponentList)
                        {
                            if (li.Component == c.ComponentID)
                            {
                                c.ActualLoanInformation = li;
                                LoadbarProgress++;
                                break;
                            }
                        }
                    }

                    //Clean load bar:
                    StatusBarText     = "Klar";
                    LoadbarProgress   = 0;
                    LoadBarVisibility = Visibility.Hidden;
                });

                loanInformationUpdaterThread_.Start();
            }
            catch
            {
                Reconnect();
                AllComponentList = new ObservableCollection <Component>();
            }
            Categories.Clear();
            Categories.Add("Alle");
            GetUniqueCategories();
            SetComponentList(AllComponentList);
            //SendExpLoanEmail();
        }
Exemple #2
0
        //
        // GET: /Component/
        public ActionResult Index(int?componentid)
        {
            var          myComponentDataUtil = new ComponentDataUtil();
            var          myComponents        = new Components();
            var          selectedComponent   = new Component();
            var          userCommentsList    = new List <MvcHtmlString>();
            var          sortedList          = new List <Component>();
            var          emptylist           = new List <MvcHtmlString>();
            LoanDataUtil ldu = new LoanDataUtil();

            myComponents._LoanInformations = ldu.GetAllLoanInformation();

            foreach (var component in myComponentDataUtil.GetAllComponents())
            {
                myComponents._components.Add(component);
            }

            foreach (var component in myComponents._components)
            {
                if (component.ComponentID == componentid)
                {
                    selectedComponent = component;
                }
            }

            foreach (var component in myComponents._components)
            {
                if (selectedComponent.ComponentName == component.ComponentName)
                {
                    sortedList.Add(component);
                }
            }

            foreach (var component in sortedList)
            {
                if (!String.IsNullOrEmpty(component.UserComment))
                {
                    userCommentsList.Add(MvcHtmlString.Create(HttpUtility.HtmlEncode(component.UserComment + "\n\n Skrevet omkring komponent nummer: " + component.ComponentNumber).Replace("\n", "<br />")));
                }
            }
            if (userCommentsList.Count < 1)
            {
                emptylist.Add(MvcHtmlString.Create(HttpUtility.HtmlEncode("Ingen kommentarer fundet")));
                ViewData["UserComments"] = emptylist;
            }
            else
            {
                ViewData["UserComments"] = userCommentsList.Distinct().ToList();
            }

            if (sortedList.Count > 0)
            {
                ViewData["AvailableQuantity"] = myComponents.GetAvailableQuantity(sortedList[0].ComponentName);

                return(View(sortedList[0]));
            }

            ViewData["AvailableQuantity"] = 0;

            return(View());
        }
Exemple #3
0
        //
        // GET: /Home/
        public ActionResult Index(string searchString, string category, int?page)
        {
            var          componentsPerPage   = new int?();
            var          mySearcher          = new Searcher();
            var          myComponentDataUtil = new ComponentDataUtil();
            var          myComponents        = new Components();
            var          emptyComponent      = new Component();
            var          listOfQuantity      = new List <int>();
            LoanDataUtil ldu = new LoanDataUtil();

            myComponents._LoanInformations = ldu.GetAllLoanInformation();

            emptyComponent.ComponentName = "Ingen Komponenter Fundet";
            componentsPerPage            = 20;


            // Tjekker om der er indtastet en s�gning, hvis ja, hentes en komponentliste med de indtastede tags
            if (!String.IsNullOrEmpty(searchString))
            {
                var SearchTags = mySearcher.SplitString(searchString);
                myComponents._components.AddRange(myComponentDataUtil.GetComponents(SearchTags));
            }
            else
            {
                //Tjekker om man har trykket p� en kategori, hvis ja, hentes en komponentliste med den kategori
                if (!String.IsNullOrEmpty(category))
                {
                    foreach (var component in myComponentDataUtil.GetAllComponents())
                    {
                        if (component.Category == category)
                        {
                            myComponents._components.Add(component);
                        }
                    }
                }
                else
                {
                    myComponents._components.AddRange(myComponentDataUtil.GetAllComponents());
                }
            }



            //Sorterer listen med komponenter, s� den er i alfabetisk r�kkef�lge og komponenterne kun ankommer en gang.
            var sortedList = myComponents._components.DistinctBy(c => c.ComponentName).OrderBy(c => c.ComponentName).ToList();

            //Opretter liste med alle kategorier

            var listOfCategories = myComponents.GetAllCategories();

            //S�tter listen med kategorier i alfabetisk r�kkef�lge
            listOfCategories.Sort();

            //Opretter liste til hvis der ikke eksisterer nogen kategorier
            var noneFound = new List <string> {
                "Ingen kategorier fundet"
            };

            if (listOfCategories.Count != 0)
            {
                ViewData["Categories"] = listOfCategories;
            }
            else
            {
                ViewData["Categories"] = noneFound;
            }

            //Udregner hvor mange sider, der skal v�re p� hjemmesiden
            ViewData["NumberOfPages"] = (sortedList.Count + componentsPerPage - 1) / componentsPerPage;

            //Udregner hvor mange der er af hver komponent type(taget ud af Componentname), l�gger det derefter over i en ny liste

            foreach (var component in sortedList)
            {
                mySearcher = new Searcher();
                listOfQuantity.Add(myComponents.GetAvailableQuantity(component.ComponentName));
                component.ComponentInfo = mySearcher.TruncateAtWord(component.ComponentInfo, 300);
            }


            //Hvis dette tjek g�r igennem, er der ikke nok komponenter til at vise den �nskede side
            if (((componentsPerPage * page.GetValueOrDefault())) >= sortedList.Count || page < 0)
            {
                myComponents._components.Clear();
                myComponents._components.Add(emptyComponent);
                listOfQuantity.Clear();
                listOfQuantity.Add(0);
                return(View(myComponents._components));
            }

            ViewData["AvailableQuantity"] = listOfQuantity;

            //Hvis dette tjek g�r igennem har man komponenter til overs, men ikke nok til at lave en "hel" side
            if (((componentsPerPage * page.GetValueOrDefault()) + componentsPerPage) > sortedList.Count)
            {
                return(View(sortedList.GetRange((page * componentsPerPage).GetValueOrDefault(), sortedList.Count - (componentsPerPage * page).GetValueOrDefault())));
            }
            //Returnerer componentsPerPage, startende fra den side man er kommet til
            return(View(sortedList.GetRange(((page * componentsPerPage).GetValueOrDefault()), componentsPerPage.GetValueOrDefault())));
        }