static void Main(string[] args) { Console.WriteLine("Would you like to process images? Enter Y or N. "); string x = Console.ReadLine(); //Console.WriteLine("Would you like to process nutrition labels? Enter Y or N. "); //string y = Console.ReadLine(); //test WebClientUtility WCU = new WebClientUtility(); CsvLibrary cl = new CsvLibrary(); XmlUtil xu = new XmlUtil(); NutritionLabel nl = new NutritionLabel(); try { #region CSV Parse if(x.Equals("Y")|| x.Equals("y")) { XDocument testx = XDocument.Load(@"D:\TestData\samplexml.xml"); NutritionInfo ni = new NutritionInfo(); Console.WriteLine("Target CSV File: " + FullFilePath); Console.WriteLine("Target Image Directory: " + NewFilePath); WCU.GenerateImageFiles(FullFilePath, NewFilePath); WCU.SaveURLImages(); // Console.WriteLine("Product Count: " + WCU.productimages.Count()); CsvLibrary.WriteCsv(WCU.productimages, ProductImagePath); Console.WriteLine("Images Processed, press Enter to continue."); } #endregion //if(y.Equals("Y")|| (y.Equals("y"))) //{ //XmlDocument test = new XmlDocument(); //Console.WriteLine("This is Nut Path: " + NutrientPath); //cl.ReadCsv(NutrientPath); //cl.WriteNutritionCsv(NutrientPath, NewNutPath); //test.Load(@"D:\TestData\samplexml.xml"); //Console.WriteLine(xu.GetNodeCount(test, "//product")); // XmlNodeList products = XmlUtil.GetNodeList(test, "//product"); //@"D:\TestData\uploads.csv" // List<NutrientUpload> uber = nl.GenerateNutrientList(products); //foreach (XmlNode x in products) //{ // Console.WriteLine(x.ChildNodes.Count); // foreach(XmlNode y in x.ChildNodes) // { // Console.Write(y.Name); // if (y.Name.Equals("STOCK_CODE")) // { // Console.WriteLine(y.InnerText); // } // } // // Console.WriteLine(x.SelectSingleNode("//STOCK_CODE").InnerText); // // Console.WriteLine(x.FirstChild.InnerText); //} //List<NutrientUpload> uber = new List<NutrientUpload>(); //uber.Add(new NutrientUpload { StockCode = "Sylvester", HTML = "Test" }); //uber.Add(new NutrientUpload { StockCode = "Jack", HTML = "Test" }); //foreach (NutrientUpload x in uber) //{ // Console.WriteLine(x.StockCode + " " + x.HTML); //} //nl.GenerateNutritionCsv(nl.GenerateNutrientList(products), @"D:\TestData\nutrientupload.csv"); //Console.Read(); //} } catch(Exception ex) { Console.WriteLine("An error has occurred. Contact developer with the exception: " + ex.Message); Console.WriteLine(ex.StackTrace); Console.Read(); } finally { CsvLibrary.WriteCsv(WCU.skippedrecords, SkippedRecPath); } }
public override void Execute() { Console.Clear(); string message = "Dania w karcie:\n"; int i = 1; foreach (Potrawa p in repository.GetPotrawy()) { message += string.Format("{0}. {1} {2} zł\n", i++, p.Nazwa, p.Cena); } Console.WriteLine(message + "Wybierz operację: [A]-Dodaj/[D]-Usuń/[I]-Importuj/[E]-Eksportuj,[X]-Wyjdź"); var operation = Pick.ForceProperKey(new List <ConsoleKey> { ConsoleKey.D, ConsoleKey.A, ConsoleKey.I, ConsoleKey.E, ConsoleKey.X }); //---------------------------Export------------------------ if (operation == ConsoleKey.E) { var potrawy = repository.GetPotrawy(); var export = new List <List <string> >(); foreach (var p in potrawy) { export.Add(new List <string> { p.Nazwa, string.Format("{0}", p.Cena) }); } CsvLibrary.Export(export, "..\\..\\Restauracja_Dania.csv"); } //---------------------------Import------------------------ else if (operation == ConsoleKey.I) { string path = Pick.SelectFile("CSV Files (*.csv)|*.csv"); try { var importResult = CsvLibrary.Import(path); foreach (List <string> l in importResult) { var cena = double.Parse(l[1]); repository.AddPotrawa(l[0], cena); } Console.WriteLine("Pomyślnie zaimportowano dane!"); } catch (Exception) { Console.Error.WriteLine("Błąd importu!!!"); } Thread.Sleep(2000); } //---------------------------Dodawanie------------------------ else if (operation == ConsoleKey.A) { Console.Clear(); Console.WriteLine("Podaj nazwę dania: "); var nazwa = Console.ReadLine(); Console.WriteLine("Podaj cenę: "); try { var cena = double.Parse(Console.ReadLine()); repository.AddPotrawa(nazwa, cena); } catch (Exception) { Console.WriteLine("Zły format ceny!"); Thread.Sleep(1000); } } //---------------------------Usuwanie------------------------ else if (operation == ConsoleKey.D) { message += "Wybierz numer z listy: "; var pick = Pick.SelectFromList(message, i - 1); var potrawy = repository.GetPotrawy(); repository.DelPotrawa(potrawy[pick - 1].Id_potrawy); } }