static void Add(DrugStoreNetwork network) { var added = false; var drugStoreName = GetNonNumberValue("Drugstore Name "); // checking for (int i = 0; i < network.NumberOfStores; i++) { var store = network[i]; if (store.Name == drugStoreName) { added = true; } } if (!added) { var numberOfPills = GetNumberValue("How many pills"); var locationDrugStore = GetNonNumberValue("Where Drug store locate "); var drugStore = new DrugStore { Name = drugStoreName, Location = locationDrugStore }; // insert pill according to user give Console.WriteLine("Insert {0} Pills ", numberOfPills); for (int i = 0; i < numberOfPills; i++) { // using indexer to access private arrays drugStore[i] = new Pill { PillName = GetNonNumberValue("Name"), Manufacture = GetNonNumberValue("Manufacture"), Price = GetNumberValue("Price"), DrugStoreName = drugStore.Name }; } network[network.NumberOfStores] = drugStore; Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Added successfully"); Console.ResetColor(); } else { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(drugStoreName + " is already added!!!"); Console.ResetColor(); } }
static void OpenDrugStore(DrugStoreNetwork network) { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(); Console.WriteLine("Insert path to file"); Console.ResetColor(); var _path = Console.ReadLine(); using (StreamReader sr = File.OpenText(_path)) { string s = ""; while ((s = sr.ReadLine()) != null) { string[] temp = s.Split(','); DrugStore store = new DrugStore() { Name = temp[0], Location = temp[1] }; Pill pill = new Pill() { PillName = temp[2], Manufacture = temp[3], Price = Convert.ToInt16(temp[4]) }; store[store.NumberOfPills] = pill; network[network.NumberOfStores] = store; } } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Added Drugstore from " + _path + " Successfully!"); Console.ResetColor(); }