static void Main(string[] args) { var shop = new Shop(); var fridge = new Fridge("KoelerMan", "X850", 180, "White"); var microWave = new MicroWave("Philips", "Z50", 100, 950); var gsm = new Gsm("Nokia", "Stone of death", 350, true); shop.AddProduct(fridge); shop.AddProduct(microWave); shop.AddProduct(gsm); shop.AddProducts(fridge, microWave); shop.ShowAllProductDetails(); Console.ReadLine(); }
public ActionResult Create(string deviceType, string deviceName) { var res = from t in deviceList where t.Value.name == deviceName select t.Value; int count = 0; foreach (var source in res) { count++; } if (deviceName == "") { ViewBag.ErrorNoname = "Имя устройства необходимо заполнить"; ViewBag.dropDownDeviceList = CreateDevList(); return(View()); } else if (count > 0) { ViewBag.ErrorContains = "Устройство с таким именем уже существует!"; ViewBag.dropDownDeviceList = CreateDevList(); return(View()); } else { Device newDevice; switch (deviceType) { default: newDevice = new Fringe(deviceName, -20, 7); Device lamp = new Device("FringeLamp"); ((Fringe)newDevice).Lamp = lamp; break; case "tv": newDevice = new TVSet(deviceName, 1, 100); break; case "mw": newDevice = new MicroWave(deviceName, 50, 200); break; case "oven": newDevice = new Oven(deviceName, 50, 300); break; case "satellite": newDevice = new Satellite(deviceName); break; case "gamebox": newDevice = new GameBox(deviceName); break; } int devCount = (int)System.Web.HttpContext.Current.Session["NextId"]; string key = "dev" + devCount.ToString(); deviceList.Add(key, newDevice); devCount++; System.Web.HttpContext.Current.Session["NextId"] = devCount; return(RedirectToAction("Index")); } }
// Обработчик нажатия кнопки добавления Устройств protected void AddDeviceButtonClick(object sender, EventArgs e) { int count = 0; var res = from t in devicesDictionary where t.Value.name == DeviceName.Text select t.Value; foreach (var source in res) { count++; } if (count == 0) { Device newDevice; switch (dropDownDevicesList.SelectedIndex) { default: newDevice = new Fringe(DeviceName.Text, -20, 5); Device lamp = new Device("FringeLamp"); ((Fringe)newDevice).Lamp = lamp; break; case 1: newDevice = new TVSet(DeviceName.Text, 0, 100); break; case 2: newDevice = new MicroWave(DeviceName.Text, 50, 250); ((MicroWave)newDevice).highTemperature(100); break; case 3: newDevice = new Oven(DeviceName.Text, 50, 300); ((Oven)newDevice).highTemperature(100); break; case 4: newDevice = new Satellite(DeviceName.Text); foreach (Control parent in DevicePanel.Controls) { foreach (Control chield in parent.Controls) { if (chield is DropDownList && chield.ID == "source") { ((DropDownList)chield).Items.Add(DeviceName.Text); } } } break; case 5: newDevice = new GameBox(DeviceName.Text); foreach (Control parent in DevicePanel.Controls) { foreach (Control chield in parent.Controls) { if (chield is DropDownList && chield.ID == "source") { ((DropDownList)chield).Items.Add(DeviceName.Text); } } } break; } int id = (int)Session["NextId"]; devicesDictionary.Add(id, newDevice); ErrText.Text = ""; DevicePanel.Controls.Add(new DeviceControl(id, devicesDictionary)); id++; Session["NextId"] = id; } else { ErrText.Text = "Устройство с такими именем уже сущесвует"; } }