Beispiel #1
0
        public ActionResult AddToOrder()
        {
            try
            {
                Drug selected;


                var newDrug3 = new Models.Drug();
                var newDrug4 = new Models.Drug();
                var newDrug5 = new Models.Drug();
                newDrug3.Name = search;
                newDrug5.ID   = -1;
                newDrug4.ID   = Singleton.Instance.Drugindex.find(newDrug3, newDrug5, Singleton.Instance.Drugindex.Root).Data.ID;

                if (newDrug4.ID != -1)
                {
                    selected = Singleton.Instance.DrugsList.ElementAt(newDrug4.ID);
                    return(View(selected));
                }
                else
                {
                    DrugNotFound();
                }
            }


            catch
            {
            }
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #2
0
        public IActionResult ReadFile(FileClass model)
        {
            if (ModelState.IsValid)
            {
                string uFileName = null;
                if (model.csv != null)
                {
                    string uploadFolder = Path.Combine(this.hostingEnvironment.WebRootPath, "csv");
                    uFileName = Guid.NewGuid().ToString() + model.csv.FileName;
                    string filePath = Path.Combine(uploadFolder, uFileName);

                    using (FileStream fileStream = System.IO.File.Create(filePath))
                    {
                        model.csv.CopyTo(fileStream);
                        fileStream.Flush();
                    }
                    string[] lines = System.IO.File.ReadAllLines(filePath);

                    TextReader      reader    = new StreamReader(filePath);
                    TextFieldParser csvReader = new TextFieldParser(reader);
                    csvReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
                    csvReader.SetDelimiters(",");
                    csvReader.HasFieldsEnclosedInQuotes = true;
                    string[] fields;

                    while (!csvReader.EndOfData)
                    {
                        try
                        {
                            fields = csvReader.ReadFields();
                            var newDrug  = new Models.Drug();
                            var newDrug2 = new Models.Drug();
                            newDrug.ID          = Convert.ToInt32(fields[0]);
                            newDrug.Name        = fields[1];
                            newDrug.Description = fields[2];
                            newDrug.Factory     = fields[3];
                            newDrug.Price       = fields[4];
                            newDrug.Stock       = Convert.ToInt32(fields[5]);

                            newDrug2.ID   = Convert.ToInt32(fields[0]) - 1;
                            newDrug2.Name = fields[1];
                            object obj = newDrug2;

                            Singleton.Instance.DrugsList.AddLast(newDrug);
                            Singleton.Instance.Drugindex.AddTo(newDrug2, Singleton.Instance.Drugindex.Root);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            csvok();
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public ActionResult AddToOrder(IFormCollection collection)
        {
            var newDrug3 = new Models.Drug();
            var newDrug5 = new Models.Drug();

            newDrug5.ID   = -1;
            newDrug3.Name = search;


            try
            {
                Drug selected;



                int quantity = Convert.ToInt32(collection["OrderedQuantity"]);
                selected = Singleton.Instance.DrugsList.ElementAt(Singleton.Instance.Drugindex.find(newDrug3, newDrug5, Singleton.Instance.Drugindex.Root).Data.ID);
                selected.OrderedQuantity = quantity;

                if ((selected.OrderedQuantity <= selected.Stock) && quantity != 0)
                {
                    selected.Stock = selected.Stock - quantity;
                    Singleton.Instance.OrderedDrugs.AddLast(selected);
                    Drugadded();
                    if (selected.Stock == 0)
                    {
                        Singleton.Instance.Drugindex.Remove(newDrug3);
                        remove();
                    }
                }
                else
                {
                    OutOfStockMessage();
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult AddToOrder()
        {
            try
            {
                Drug selected;


                var newDrug3 = new Models.Drug();

                newDrug3.Name = search;

                selected = Singleton.Instance.DrugsList.ElementAt(Singleton.Instance.Drugindex.find(newDrug3, Singleton.Instance.Drugindex.root).Data.ID);


                return(View(selected));
            }


            catch
            {
            }
            return(null);
        }
Beispiel #5
0
        public ActionResult ReStock()
        {
            Random random = new Random();
            Drug   drug;
            var    newDrug = new Models.Drug();
            int    i;

            for (i = 0; Singleton.Instance.DrugsList.Length > i; i++)
            {
                drug = Singleton.Instance.DrugsList.ElementAt(i);


                if (drug.Stock == 0)
                {
                    newDrug.ID   = Singleton.Instance.DrugsList.ElementAt(i).ID - 1;
                    newDrug.Name = Singleton.Instance.DrugsList.ElementAt(i).Name;
                    drug.Stock   = random.Next(1, 15);
                    Singleton.Instance.Drugindex.AddTo(newDrug, Singleton.Instance.Drugindex.Root);
                    Restocked();
                }
            }

            return(RedirectToAction("Index"));
        }