예제 #1
0
        private void SetVolumeButtonClick(object sender, EventArgs e)
        {
            errorVol          = TextBox("");
            errorVol.ID       = "errorVol" + id;
            errorVol.CssClass = "error";
            errorVol.TextMode = TextBoxMode.MultiLine;

            v = (ISetVolume)DevicesDictionary[id];
            if (Int32.TryParse(vTextBox.Text, out temp))
            {
                if (temp < 0 || temp > 100)
                {
                    errorVol.Text = "Ошибка! Недопустимое значение громкости.";
                }
                else
                {
                    v.SetVolume(temp);
                }
            }
            else
            {
                errorVol.Text = "Ошибка! Некорректный ввод громкости.";
            }
            Controls.Clear();
            Initializer();
            phErrorVol.Controls.Add(errorVol);
        }
예제 #2
0
        public ActionResult LessVolume(int id)
        {
            IDictionary <int, Device> devicesDictionary = (SortedDictionary <int, Device>)Session["Devices"];
            ISetVolume v = (ISetVolume)devicesDictionary[id];

            v.LessVolume();
            return(RedirectToAction("Index"));
        }
예제 #3
0
        public ActionResult SetVolume(int id, int vol = 0)
        {
            IDictionary <int, Device> devicesDictionary = (SortedDictionary <int, Device>)Session["Devices"];

            v = (ISetVolume)devicesDictionary[id];
            if (vol < 0 || vol > 100)
            {
                TempData["ErrorVolume"] = "Ошибка! Недопустимое значение громкости.";
            }
            else
            {
                v.SetVolume(vol);
            }

            Session["Devices"] = devicesDictionary;
            return(RedirectToAction("Index"));
        }
예제 #4
0
        public ActionResult SetVolume(int id, string volume)
        {
            IDictionary <int, Device> devicesDictionary = (SortedDictionary <int, Device>)Session["Devices"];
            ISetVolume v = (ISetVolume)devicesDictionary[id];
            int        correntVol;

            if (Int32.TryParse(volume, out correntVol))
            {
                if (correntVol >= 0 && correntVol <= 100)
                {
                    v.SetVolume(correntVol);
                }
                else
                {
                    TempData["Error"] = "Введите значение от 0 до 100!";
                }
            }
            else
            {
                TempData["Error"] = "Введите только цифры!";
            }
            Session["Devices"] = devicesDictionary;
            return(RedirectToAction("Index"));
        }
예제 #5
0
        ///////////////////////////Обработчики событий
        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();
        }
예제 #6
0
파일: Menu.cs 프로젝트: msdegt/C_Sharp.Net
        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;
                    }
                }
            }
        }
예제 #7
0
        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"));
        }