Esempio n. 1
0
        // GET: DrugOrder/NewStock/5
        public ActionResult NewStock()
        {
            var currentList = Storage.Instance.drugList.Where(x => x.Stock == 0).ToList();


            Random random = new Random();

            for (int i = 0; i < currentList.Count(); i++)
            {
                int number = random.Next(1, 15);
                currentList.ElementAt(i).Stock = number;

                var drugPreviouslyDeleted = new DrugModel
                {
                    Id   = currentList.ElementAt(i).Id,
                    Name = currentList.ElementAt(i).DrugName,
                };
                DrugModel.Add(drugPreviouslyDeleted);
            }

            return(RedirectToAction("SupplyStock"));
        }
Esempio n. 2
0
        public ActionResult CSV(HttpPostedFileBase postedfile)
        {
            string FilePath;

            if (postedfile != null)
            {
                string Path = Server.MapPath("~/Data/");
                if (!Directory.Exists(Path))
                {
                    Directory.CreateDirectory(Path);
                }
                FilePath = Path + System.IO.Path.GetFileName(postedfile.FileName);
                postedfile.SaveAs(FilePath);

                string csvData = System.IO.File.ReadAllText(FilePath);
                csvData.Split();
                foreach (string row in csvData.Split('\n'))
                {
                    if (!string.IsNullOrEmpty(row))
                    {
                        try
                        {
                            Regex    regx = new Regex("," + "(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");
                            string[] line = regx.Split(row);

                            string price = Convert.ToString(regx.Split(row)[4]);
                            price = price.Substring(1, price.Length - 1);

                            var drug = new DrugOrderModel
                            {
                                Id          = Convert.ToInt32(regx.Split(row)[0]),
                                DrugName    = line[1],
                                Description = line[2],
                                Producer    = line[3],
                                Price       = Convert.ToDouble(price),
                                Stock       = Convert.ToInt32(regx.Split(row)[5]),
                            };
                            //SAVE MEDICINE ON THE LIST
                            Storage.Instance.drugList.Add(drug);
                        }
                        catch
                        {
                        }
                    }
                }

                using (var fileStream = new FileStream(FilePath, FileMode.Open))
                {
                    using (var streamReader = new StreamReader(fileStream))
                    {
                        streamReader.ReadLine();
                        while (!streamReader.EndOfStream)
                        {
                            var row = streamReader.ReadLine();

                            Regex    regx = new Regex("," + "(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");
                            string[] line = regx.Split(row);

                            var drug = new DrugModel
                            {
                                Id   = Convert.ToInt32(line[0]),
                                Name = line[1],
                            };
                            //SAVE MEDICINE ON THE TREE
                            DrugModel.Add(drug);
                        }
                    }
                }
            }
            return(View());
        }