private void btnSave_Click(object sender, EventArgs e) { if (_drink == null) { var cognac = new Cognac { Bottle = new Bottle() }; if (!SetCognacProperties(cognac)) { return; } _modelService.AddDrink(cognac); } else { var cognac = (Cognac)_drink; if (!SetCognacProperties(cognac)) { return; } } DialogResult = DialogResult.OK; }
static void Main(string[] args) { Cognac CamusCuvee = new Cognac(2500, 128, "Germany", "alcohol blend 41, 43, 44 years"); Cognac DelamainLeVoyage = new Cognac(6500, 200, "Georgia", "infused alcohols for 150 years"); Cognac HardyPerfectionFire = new Cognac(6700, 160, "France", "rare French Colombard grapes"); Cognac LArtdeMartell = new Cognac(3630, 140, "Germany", "hints of currant and hazelnut flavor"); Cognac HenriIVDudognon = new Cognac(2000000, 300, "Mexico", "The best 100 year old spirits"); Cognac.AddCognac(CamusCuvee); Cognac.AddCognac(DelamainLeVoyage); Cognac.AddCognac(HardyPerfectionFire); Cognac.AddCognac(LArtdeMartell); Cognac.AddCognac(HenriIVDudognon); Console.WriteLine(); Console.WriteLine("Выберете фильтр поиска: 1 - цена, 2 - выдержка, 3 - страна производитель, 4 - основной компонент"); int choise = Convert.ToInt32(Console.ReadLine()); switch (choise) { case 1: Console.WriteLine("Введите цену для поиска: "); double priceSearch = Convert.ToDouble(Console.ReadLine()); Cognac.SearchPrice(priceSearch); break; case 2: Console.WriteLine("Введите выдержку для поиска: "); int agedSearch = Convert.ToInt32(Console.ReadLine()); Cognac.SearchAged(agedSearch); break; case 3: Console.WriteLine("Введите страну для поиска: "); string countrySearch = Console.ReadLine(); Cognac.SearchCountry(countrySearch); break; case 4: Console.WriteLine("Введите основной компонент для поиска: "); string componentSearch = Console.ReadLine(); Cognac.SearchComponent(componentSearch); break; default: Console.WriteLine("Такого параметра не найдено! Нажмите ENTER чтобы завершить работу!"); break; } }
private bool SetCognacProperties(Cognac cognac) { cognac.Name = tbName.Text; try { cognac.Cost = decimal.Parse(tbCost.Text); } catch (FormatException) { MessageBox.Show("Enter the correct price!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } try { cognac.AlcoholContent = float.Parse(tbAlcoholContent.Text); } catch (FormatException) { MessageBox.Show("Enter the correct alcohol content!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } cognac.DateOfBottling = dtpDageOfBottling.Value; cognac.Class = tbClass.Text; cognac.BarrelMaterial = tbBarrelMaterial.Text; try { cognac.Bottle.Volume = int.Parse(tbVolume.Text); } catch (FormatException) { MessageBox.Show("Enter the correct bottle volume!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } cognac.Bottle.Color = tbColor.Text; return(true); }
static public void AddCognac(Cognac Obj) { cognacList.Add(Obj); }
public static void Main(string[] args) { // setting up localization, just in case var appLocale = ConfigurationManager.AppSettings.Get("appLocale"); System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(appLocale); // declaring variables bool isProgramStarted = true; bool isCartEmpty = true; int userCommandInput; int userQtyInput; // creating null objects for further work Beer beer = null; Wine wine = null; Vodka vodka = null; Gin gin = null; Cognac cognac = null; Whisky whisky = null; // saying hello to user Console.Clear(); MessageLib.SayHello(); Console.ReadKey(); do { // showing menu to user Console.Clear(); MessageLib.Menu(); // accepting and validating input from user ParseUserInputToInt(true, out userCommandInput); switch (userCommandInput) { // adding beer to cart case (int)MenuActions.AddBeer: MessageLib.AskHowMuchBottles(); ParseUserInputToInt(false, out userQtyInput); beer = new Beer(userQtyInput); isCartEmpty = false; break; // adding wine to cart case (int)MenuActions.AddWine: MessageLib.AskHowMuchBottles(); ParseUserInputToInt(false, out userQtyInput); wine = new Wine(userQtyInput); isCartEmpty = false; break; // adding vodka to cart case (int)MenuActions.AddVodka: MessageLib.AskHowMuchBottles(); ParseUserInputToInt(false, out userQtyInput); vodka = new Vodka(userQtyInput); isCartEmpty = false; break; // adding gin to cart case (int)MenuActions.AddGin: MessageLib.AskHowMuchBottles(); ParseUserInputToInt(false, out userQtyInput); gin = new Gin(userQtyInput); isCartEmpty = false; break; // adding cognac to cart case (int)MenuActions.AddCognac: MessageLib.AskHowMuchBottles(); ParseUserInputToInt(false, out userQtyInput); cognac = new Cognac(userQtyInput); isCartEmpty = false; break; // adding whisky to cart case (int)MenuActions.AddWhisky: MessageLib.AskHowMuchBottles(); ParseUserInputToInt(false, out userQtyInput); whisky = new Whisky(userQtyInput); isCartEmpty = false; break; // showing user his cart case (int)MenuActions.ShowCart: // if cart is empty show user appropriate message if (isCartEmpty) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\nYour cart is empty!"); Console.ResetColor(); Console.WriteLine("\nPress any key to return to menu..."); Console.ReadKey(); break; } // otherwise user's cart will be processed and shown Inventory.ShowInventory(beer, wine, vodka, gin, cognac, whisky); Console.WriteLine("\nPress any key to return to menu..."); Console.ReadKey(); break; // exiting the program case (int)MenuActions.Exit: MessageLib.SayGoodbye(); isProgramStarted = false; break; // otherwise throw an error default: Console.ForegroundColor = ConsoleColor.Red; Console.Write("\nInvalid input! Please try again: "); Console.ResetColor(); break; } }while (isProgramStarted); }