public void AddDevice(string device = "", string name = "", string fabricator = "")
 {
     DatabaseMapping databaseMapping = null;
     switch (device)
     {
         case "clock":
             Clock clock = new Clock(name);
             _deviceContext.Clocks.Add(clock);
             databaseMapping = new DatabaseMapping { DeviceTypeId = 1, Clock = clock };
             break;
         case "microwave":
             MicrowaveFabricatorInfo mi = microwaveFabricatorInfo[fabricator];
             Microwave microwave = new Microwave(name, mi.Volume, mi.Lamp);
             _deviceContext.Microwaves.Add(microwave);
             databaseMapping = new DatabaseMapping { DeviceTypeId = 2, Microwave = microwave };
             break;
         case "oven":
             OvenFabricatorInfo oi = ovenFabricatorInfo[fabricator];
             Oven oven = new Oven(name, oi.Volume, oi.Lamp);
             _deviceContext.Ovens.Add(oven);
             databaseMapping = new DatabaseMapping { DeviceTypeId = 3, Oven = oven };
             break;
         case "fridge":
             FridgeFabricatorInfo fi = fridgeFabricatorInfo[fabricator];
             Fridge fridge = new Fridge(name, fi.Coldstore, fi.Freezer);
             _deviceContext.Fridges.Add(fridge);
             databaseMapping = new DatabaseMapping { DeviceTypeId = 4, Fridge = fridge };
             break;
         default: return;
     }
     _deviceContext.DatabaseMappings.Add(databaseMapping);
     _deviceContext.SaveChanges();
 }
Beispiel #2
0
        // Create
        public void Create(string device)
        {
            switch (device)
            {
            case "Tv":
                Tv tv = new Tv();
                db.Tvs.Add(tv);
                db.SaveChanges();
                Session["SelectedDevice"] = tv;
                Session["DeviceConsole"]  = new DeviceConsole(tv);
                break;

            case "Fridge":
                Fridge fridge = new Fridge();
                db.Fridges.Add(fridge);
                db.SaveChanges();
                Session["SelectedDevice"] = fridge;
                Session["DeviceConsole"]  = new DeviceConsole(fridge);
                break;

            case "Lamp":
                Lamp lamp = new Lamp();
                db.Lamps.Add(lamp);
                db.SaveChanges();
                Session["SelectedDevice"] = lamp;
                Session["DeviceConsole"]  = new DeviceConsole(lamp);
                break;

            case "Cooker":
                Cooker cooker = new Cooker();
                db.Cookers.Add(cooker);
                db.SaveChanges();
                Session["SelectedDevice"] = cooker;
                Session["DeviceConsole"]  = new DeviceConsole(cooker);
                break;

            case "Microwave":
                Microwave microwave = new Microwave();
                db.Microwaves.Add(microwave);
                db.SaveChanges();
                Session["SelectedDevice"] = microwave;
                Session["DeviceConsole"]  = new DeviceConsole(microwave);
                break;

            default:
                break;
            }
            selectedDevice = (Session["SelectedDevice"] as Device);
            deviceConsole  = (Session["DeviceConsole"] as DeviceConsole);
            RefreshPage();
        }
 public void AddMicrowave(string name, string fabricator)
 {
     if (!microwaveInfo.ContainsKey(fabricator))
     {
         return;
     }
     MicrowaveInfo mi = microwaveInfo[fabricator];
     Microwave microwave = new Microwave(name, mi.Volume, mi.Lamp);
     microwave.OperationDone += (sender) =>
     {
         //throw new ApplicationException("Микроволновка отработала!!!");
     };
     AddDevice(microwave);
 }
Beispiel #4
0
        // Delete
        protected void LinkButtonDelete_Click(object sender, EventArgs e)
        {
            if (selectedDevice != null)
            {
                string device = (selectedDevice as Device).TypeDevice();
                int    id     = (selectedDevice as Device).Id;

                switch (device)
                {
                case "Tv":
                    Tv tv = db.Tvs.Find(id);
                    if (tv != null)
                    {
                        db.Tvs.Remove(tv);
                        db.SaveChanges();
                        PanelDevicesDeleteControl(tv.Id, tv.TypeDevice());
                    }
                    break;

                case "Fridge":
                    Fridge fridge = db.Fridges.Find(id);
                    if (fridge != null)
                    {
                        db.Fridges.Remove(fridge);
                        db.SaveChanges();
                        PanelDevicesDeleteControl(fridge.Id, fridge.TypeDevice());
                    }
                    break;

                case "Lamp":
                    Lamp lamp = db.Lamps.Find(id);
                    if (lamp != null)
                    {
                        db.Lamps.Remove(lamp);
                        db.SaveChanges();
                        PanelDevicesDeleteControl(lamp.Id, lamp.TypeDevice());
                    }
                    break;

                case "Cooker":
                    Cooker cooker = db.Cookers.Find(id);
                    if (cooker != null)
                    {
                        db.Cookers.Remove(cooker);
                        db.SaveChanges();
                        PanelDevicesDeleteControl(cooker.Id, cooker.TypeDevice());
                    }
                    break;

                case "Microwave":
                    Microwave microwave = db.Microwaves.Find(id);
                    if (microwave != null)
                    {
                        db.Microwaves.Remove(microwave);
                        db.SaveChanges();
                        PanelDevicesDeleteControl(microwave.Id, microwave.TypeDevice());
                    }
                    break;

                default:
                    break;
                }
                Session["SelectedDevice"] = null;
                Session["DeviceConsole"]  = null;
                selectedDevice            = null;
                deviceConsole             = null;
                RefreshPage();
            }
        }