public ActionResult PreviousChannel(int id) { IDictionary <int, Device> devicesDictionary = (SortedDictionary <int, Device>)Session["Devices"]; ISetChannel c = (ISetChannel)devicesDictionary[id]; c.PreviousChannel(); return(RedirectToAction("Index")); }
///////////////////////////Обработчики событий private void ButtonClick(object sender, EventArgs e) { Button button = (Button)sender; string[] mass = button.ID.Split(new char[] { ' ' }); if (DevicesDictionary[id] is ISetChannel) { ch = (ISetChannel)DevicesDictionary[id]; } if (DevicesDictionary[id] is ISetVolume) { v = (ISetVolume)DevicesDictionary[id]; } if (DevicesDictionary[id] is IRateOfOpening) { r = (IRateOfOpening)DevicesDictionary[id]; } switch (mass[0]) { case "on": DevicesDictionary[id].On(); break; case "off": DevicesDictionary[id].Off(); break; case "nCh": ch.NextChannel(); break; case "eCh": ch.EarlyChannel(); break; case "prevCh": ch.PreviousChannel(); break; case "maxV": v.MaxVolume(); break; case "minV": v.MinVolume(); break; case "mute": v.SetMute(); break; case "open": r.Open(); break; case "close": r.Close(); break; case "scan": chSetup = (IChannelSetup)DevicesDictionary[id]; chSetup.ChannelScan(); break; } Controls.Clear(); Initializer(); }
public void Show() { CO = new CreateObject(); DevicesDictionary.Add("TV1", CO.CreateTv()); DevicesDictionary.Add("Ref1", CO.CreateRef()); DevicesDictionary.Add("Shut1", CO.CreateShut()); DevicesDictionary.Add("Boiler1", CO.CreateBoiler()); DevicesDictionary.Add("WS1", CO.CreateWs()); while (true) { Console.Clear(); foreach (var dev in DevicesDictionary) { Console.WriteLine("Название: " + dev.Key + ", " + dev.Value.ToString()); } Console.WriteLine(); Console.Write("Введите команду: "); string[] commands = Console.ReadLine().Split(' '); if (commands[0].ToLower() == "exit" & commands.Length == 3) { return; } if (commands.Length != 3) { Help(); continue; } if (commands[0].ToLower() == "add" && !DevicesDictionary.ContainsKey(commands[2])) { if (commands[1] == "TV") { DevicesDictionary.Add(commands[2], CO.CreateTv()); continue; } if (commands[1] == "ref") { DevicesDictionary.Add(commands[2], CO.CreateRef()); continue; } if (commands[1] == "shut") { DevicesDictionary.Add(commands[2], CO.CreateShut()); continue; } if (commands[1] == "boiler") { DevicesDictionary.Add(commands[2], CO.CreateBoiler()); continue; } if (commands[1] == "WS") { DevicesDictionary.Add(commands[2], CO.CreateWs()); continue; } } if (commands[0].ToLower() == "add" && DevicesDictionary.ContainsKey(commands[2])) { Console.WriteLine("Устройство с таким именем уже существует"); Console.WriteLine("Нажмите любую клавишу для продолжения"); Console.ReadLine(); continue; } if (commands[0].ToLower() == "del" && !DevicesDictionary.ContainsKey(commands[2])) { Console.WriteLine("Выполнение команды невозможно, т.к. устройство с таким именем не существует"); Console.WriteLine("Нажмите любую клавишу для продолжения"); Console.ReadLine(); continue; } if (!DevicesDictionary.ContainsKey(commands[2])) { Help(); continue; } if (commands[0].ToLower() == "del" && DevicesDictionary.ContainsKey(commands[2])) { DevicesDictionary.Remove(commands[2]); continue; } switch (commands[0].ToLower()) { case "on": DevicesDictionary[commands[2]].On(); break; case "off": DevicesDictionary[commands[2]].Off(); break; } if (DevicesDictionary[commands[2]] is IChannelSetup) { IChannelSetup t = (IChannelSetup)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "scan": Console.Clear(); Console.WriteLine(t.ChannelScan()); Console.ReadKey(); break; case "list_chan": Console.WriteLine(t.ListChannel()); Console.ReadKey(); break; } } if (DevicesDictionary[commands[2]] is ISetChannel) { ISetChannel ch = (ISetChannel)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "next": ch.NextChannel(); break; case "early": ch.EarlyChannel(); break; case "go_to": Console.WriteLine("Введите номер канала: "); Input = Console.ReadLine(); if (Int32.TryParse(Input, out temp)) { if (temp < 0 || temp > ch.MAXchannel) { Console.WriteLine("Ошибка. Такого канала не существует!"); Console.ReadKey(); } else { ch.GoToChannel(temp); } } else { Console.WriteLine("Ошибка! Некорректный ввод номера канала."); Console.ReadKey(); } break; case "prev_chan": ch.PreviousChannel(); break; } } if (DevicesDictionary[commands[2]] is ISetVolume) { ISetVolume v = (ISetVolume)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "mute": v.SetMute(); break; case "max_vol": v.MaxVolume(); break; case "min_vol": v.MinVolume(); break; case "set_vol": Console.WriteLine("Введите уровень громкости в пределах 0...100: "); Input = Console.ReadLine(); if (Int32.TryParse(Input, out temp)) { if (temp < 0 || temp > 100) { Console.WriteLine("Ошибка! Недопустимое значение громкости."); Console.ReadKey(); } else { v.SetVolume(temp); } } else { Console.WriteLine("Ошибка! Некорректный ввод громкости."); Console.ReadKey(); } break; } } if (DevicesDictionary[commands[2]] is IRateOfOpening) { IRateOfOpening r = (IRateOfOpening)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "open": r.Open(); break; case "close": r.Close(); break; } } if (DevicesDictionary[commands[2]] is ISetFreezeMode) { ISetFreezeMode r = (ISetFreezeMode)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "low": r.SetLowFreeze(); break; case "colder": r.SetColderFreezing(); break; case "deep": r.SetDeepFreeze(); break; case "defrost": r.SetDefrost(); break; } } if (DevicesDictionary[commands[2]] is ISetTemperature) { ISetTemperature r = (ISetTemperature)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "level_t": Console.WriteLine("Введите желаемую температуру в диапазоне 2...15: "); Input = Console.ReadLine(); if (Double.TryParse(Input, out t)) { if (t < 2 || t > 15) { Console.WriteLine("Ошибка! Недопустимое значение температуры."); Console.ReadKey(); } else { r.SetLevelTemperature(t); } } else { Console.WriteLine("Ошибка! Некорректный ввод температуры."); Console.ReadKey(); } break; } } if (DevicesDictionary[commands[2]] is ICustomMode) { ICustomMode w = (ICustomMode)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "custom": Console.WriteLine("Введите желаемый уровень температуры в диапазоне 30...90: "); Input = Console.ReadLine(); if (Double.TryParse(Input, out t)) { if (t < 30 || t > 90) { Console.WriteLine("Ошибка! Недопустимое значение температуры."); Console.ReadKey(); } else { w.SetCustomMode(t); } } else { Console.WriteLine("Ошибка! Некорректный ввод температуры."); Console.ReadKey(); } break; } } if (DevicesDictionary[commands[2]] is ITimeOfDayMode) { ITimeOfDayMode w = (ITimeOfDayMode)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "morning": w.SetMorningMode(); break; case "evening": w.SetEveningMode(); break; } } if (DevicesDictionary[commands[2]] is IModeHeating) { IModeHeating b = (IModeHeating)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "min_mode": b.SetMinMode(); break; case "max_mode": b.SetMaxMode(); break; } } if (DevicesDictionary[commands[2]] is IEnterLevel) { IEnterLevel e = (IEnterLevel)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "ent_l": Console.WriteLine("Введите уровень влажности почвы: "); Input = Console.ReadLine(); if (Int32.TryParse(Input, out temp)) { if (temp < 0 || temp > 100) { Console.WriteLine("Ошибка! Недопустимое значение уровня влажности почвы."); Console.ReadKey(); } else { e.EnterLevel(temp); } } else { Console.WriteLine("Ошибка! Некорректный ввод уровня влажности почвы."); Console.ReadKey(); } break; } } } }
public void Show() { ADD = new CreateDevices(); DevicesDictionary.Add("TV1", ADD.AddTV()); DevicesDictionary.Add("Refr1", ADD.AddFridge()); DevicesDictionary.Add("Lamp1", ADD.AddLamp()); DevicesDictionary.Add("Kettle1", ADD.AddKettle()); DevicesDictionary.Add("Condit1", ADD.AddConditioner()); while (true) { Console.Clear(); foreach (var dev in DevicesDictionary) { Console.WriteLine("Device: " + dev.Key + ", " + dev.Value.ToString()); } Console.WriteLine(); Console.Write("Введите команду: "); string[] commands = Console.ReadLine().Split(' '); if (commands[0].ToLower() == "exit" & commands.Length == 3) { return; } if (commands.Length != 3) { Help(); continue; } if (commands[0].ToLower() == "add" && !DevicesDictionary.ContainsKey(commands[2])) { if (commands[1] == "TV") { DevicesDictionary.Add(commands[2], ADD.AddTV()); continue; } if (commands[1] == "ref") { DevicesDictionary.Add(commands[2], ADD.AddFridge()); continue; } if (commands[1] == "ket") { DevicesDictionary.Add(commands[2], ADD.AddKettle()); continue; } if (commands[1] == "lamp") { DevicesDictionary.Add(commands[2], ADD.AddLamp()); continue; } if (commands[1] == "cond") { DevicesDictionary.Add(commands[2], ADD.AddConditioner()); continue; } } if (commands[0].ToLower() == "add" && DevicesDictionary.ContainsKey(commands[2])) { Console.WriteLine("Device with such name already exists"); Console.WriteLine("Press any key to continue"); Console.ReadLine(); continue; } if (commands[0].ToLower() == "del" && !DevicesDictionary.ContainsKey(commands[2])) { Console.WriteLine("Device with such name doesn`t exist"); Console.WriteLine("Press any key to continue"); Console.ReadLine(); continue; } if (!DevicesDictionary.ContainsKey(commands[2])) { Help(); continue; } if (commands[0].ToLower() == "del" && DevicesDictionary.ContainsKey(commands[2])) { DevicesDictionary.Remove(commands[2]); continue; } switch (commands[0].ToLower()) { case "on": case "ON": case "On": DevicesDictionary[commands[2]].On(); break; case "off": case "Off": case "OFF": DevicesDictionary[commands[2]].Off(); break; } if (DevicesDictionary[commands[2]] is IChannelsList) { IChannelsList t = (IChannelsList)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "show": Console.Clear(); Console.WriteLine(t.ShowChannelList()); Console.ReadKey(); break; case "list_chan": Console.WriteLine(t.ListChannel()); Console.ReadKey(); break; } } if (DevicesDictionary[commands[2]] is ISetChannel) { ISetChannel ch = (ISetChannel)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "next": case "Next": case "NEXT": ch.NextChannel(); break; case "previous": case "Previous": case "PREVIOUS": ch.PreviousChannel(); break; case "choose": case "CHOOSE": case "Choose": Console.WriteLine("Enter the channel number: "); variable = Console.ReadLine(); if (Int32.TryParse(variable, out buffer)) { if (buffer < 0 || buffer > ch.MAXchannel) { Console.WriteLine("Error. U can`t set such channel."); Console.ReadKey(); } else { ch.ChooseChannel(buffer); } } else { Console.WriteLine("Error! U failed to set number of channel"); Console.ReadKey(); } break; } } if (DevicesDictionary[commands[2]] is ISound) { ISound sound = (ISound)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "mute": sound.VolumeMute(); break; case "vol_up": sound.VolumeUp(); break; case "vol_down": sound.VolumeDown(); break; case "set_vol": Console.WriteLine("Enter the volume [1-100] : "); variable = Console.ReadLine(); if (Int32.TryParse(variable, out buffer)) { if (buffer < 0 || buffer > 100) { Console.WriteLine("Error! Wrong volume."); Console.ReadKey(); } else { sound.SetVolume(buffer); } } else { Console.WriteLine("Error! Can`t set the volume!"); Console.ReadKey(); } break; } } if (DevicesDictionary[commands[2]] is IBrightness) { IBrightness sound = (IBrightness)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "set_bright": Console.WriteLine("Enter the volume [1-100] : "); variable = Console.ReadLine(); if (Int32.TryParse(variable, out buffer)) { if (buffer < 0 || buffer > 100) { Console.WriteLine("Error! Wrong brightness."); Console.ReadKey(); } else { sound.SetBrightness(buffer); } } else { Console.WriteLine("Error! Can`t set the volume!"); Console.ReadKey(); } break; } } if (DevicesDictionary[commands[2]] is IFreezModes) { IFreezModes type = (IFreezModes)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "NoFrost": case "nofrost": case "Nofrost": type.NoFrostMode(); break; case "normal": case "Normal": type.NormalMode(); break; case "ventilation": case "Ventilation": type.VentilationMode(); break; case "SuperFrost": case "superfrost": case "Superfrost": type.SuperFrostMode(); break; } } if (DevicesDictionary[commands[2]] is ISetTemperature) { ISetTemperature t = (ISetTemperature)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "set_temp": Console.WriteLine("Set temperature [-4...10] "); variable = Console.ReadLine(); if (Int32.TryParse(variable, out buffer)) { if (buffer < -4 || buffer > 10) { Console.WriteLine("Error! Failed to set temperature."); Console.ReadKey(); } else { t.SetTemperature(buffer); } } else { Console.WriteLine("Error! Try to set temperature once more!"); Console.ReadKey(); } break; } } if (DevicesDictionary[commands[2]] is IConditionerModes) { IConditionerModes mode = (IConditionerModes)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "heat_mode": case "Heat_mode": mode.HeatingMode(); break; case "Aero_mode": case "aero_mode": mode.AerationMode(); break; case "cool_mode": case "Cool_mode": mode.CoolingMode(); break; } } if (DevicesDictionary[commands[2]] is ILightColors) { Console.ResetColor(); ILightColors color = (ILightColors)DevicesDictionary[commands[2]]; switch (commands[0].ToLower()) { case "white_light": case "White_light": color.WhiteLight(); break; case "Red_light": case "red_light": color.RedLight(); break; case "pink_light": case "Pink_light": color.PinkLight(); break; case "Yellow_light": case "yellow_light": color.YellowLight(); break; case "Blue_light": case "blue_light": color.BlueLight(); break; } } } }
public ActionResult Operation(int id, string command) { IDictionary <int, Device> devicesDictionary = (SortedDictionary <int, Device>)Session["Devices"]; if (devicesDictionary[id] is ISetChannel) { ch = (ISetChannel)devicesDictionary[id]; } if (devicesDictionary[id] is ISetVolume) { v = (ISetVolume)devicesDictionary[id]; } if (devicesDictionary[id] is IRateOfOpening) { r = (IRateOfOpening)devicesDictionary[id]; } if (devicesDictionary[id] is IChannelSetup) { s = (IChannelSetup)devicesDictionary[id]; } switch (command) { case "on": devicesDictionary[id].On(); break; case "off": devicesDictionary[id].Off(); break; case "nCh": ch.NextChannel(); break; case "eCh": ch.EarlyChannel(); break; case "prevCh": ch.PreviousChannel(); break; case "maxV": v.MaxVolume(); break; case "minV": v.MinVolume(); break; case "mute": v.SetMute(); break; case "open": r.Open(); break; case "close": r.Close(); break; case "scan": s.ChannelScan(); break; case "listChan": string str = s.ListChannel().Replace("Список каналов:", " "); string[] mass = str.Split('№'); TempData["Mass"] = mass; return(RedirectToAction("List", "ListTV")); } Session["Devices"] = devicesDictionary; return(RedirectToAction("Index")); }