Exemplo n.º 1
0
        //public FluentControlLoop(Plant plant, IFluentUnit parent)
        //{

        //    _parentunit = parent;
        //    //_parent = plant;
        //    _plant = plant;
        //    _unit = parent.GetUnit();
        //    //_parent = parent;


        //}

        //public FluentControlLoop(IFluentUnit parent, string Name)
        //{


        //    _plant = parent.GetPlant();
        //    _parentunit = parent;
        //    Unit u = _parentunit.GetUnit();

        //    _loop = contx.EQControlLoops.FirstOrDefaul


        //}

        //public FluentControlLoop(IFluentUnit parent)
        //{

        //    try
        //    {

        //        Plant plant = parent.GetPlant();
        //        _plant = contx.Plants.FirstOrDefault(g => g.PlantID == plant.PlantID);
        //        Unit u = parent.GetUnit();
        //        //_parent = parent;
        //        _isnew = false;
        //        _message = "";

        //        //_loop = contx.EQControlLoops.FirstOrDefault(g => g.);
        //        _loop = contx.EQControlLoops.FirstOrDefault(g => g.Unit.UnitID == u.UnitID);



        //    }
        //    catch (Exception ex)
        //    {
        //        _message = _message + ex.ToString();

        //    }


        //}

        public IFluentControlLoop ForControlLoop(string s)
        {
            //_loop = contx.EQControlLoops.FirstOrDefault(g => g.EquipName == s);
            _loop = contx.GetEQControlLoopsByPlantByName(_plant, s);

            //_loop = contx.get
            return(this);
        }
Exemplo n.º 2
0
        public EQControlLoop GetLoopByPlantIDAndName(int PlantID, string EqName)
        {
            BrewDBContext contx = new BrewDBContext();
            var           test  = contx.EQControlLoops
                                  .Where(b => b.Plant.PlantID == PlantID)
                                  .Where(c => c.EquipName == EqName)
                                  .FirstOrDefault();

            EQControlLoop _loop = test;

            return(_loop);
        }
Exemplo n.º 3
0
        public List <EQControlLoop> AddEQControlLoopToPlant(int plantID, EQControlLoop loop)
        {
            BrewDBContext cont = new BrewDBContext();

            Plant plant = cont.Plants.FirstOrDefault(g => g.PlantID == plantID);

            plant.PlantLoops.Add(loop);

            cont.Plants.FirstOrDefault(g => g.PlantID == plantID).PlantLoops.Add(loop);
            cont.SaveChanges();

            return(cont.EQControlLoops.SelectMany(g => EQControlLoops).Where(g => g.Plant.PlantID == plantID).ToList());
        }
Exemplo n.º 4
0
        //----------------------------------------------------------------------------------------------------
        //----------------------------------------------------------------------------------------------------
        //----------------------------------------------------------------------------------------------------
        //          Plant
        //----------------------------------------------------------------------------------------------------
        //----------------------------------------------------------------------------------------------------



        public EQControlLoop CreateNewLoop(string name, string type, Plant plant, Unit unit)
        {
            BrewDBContext contx = new BrewDBContext();
            EQControlLoop _loop = new EQControlLoop();

            //Plant plant = new Plant();

            _loop.AssetTag       = "111";
            _loop.Description    = "default";
            _loop.EnableTrending = false;
            _loop.EquipName      = name;

            if (type == "")
            {
                _loop.EQType = contx.EQTypes.FirstOrDefault();
            }
            else
            {
                _loop.EQType = contx.EQTypes.FirstOrDefault(f => f.TypeDescription == type);
            }
            //_loop.Plant = _parent.GetPlant();
            _loop.Plant = contx.Plants.FirstOrDefault(e => e.PlantID == plant.PlantID);

            if (unit != null)
            {
                _loop.Unit = contx.Units.FirstOrDefault(e => e.UnitID == unit.UnitID);
            }
            else
            {
                _loop.Unit = _loop.Plant.Units.First();
            }
            //if (unit != null)
            //{
            //    _loop.Unit = contx.Units.FirstOrDefault(u => u.UnitID == unit.UnitID);

            //}
            contx.EQControlLoops.Add(_loop);
            contx.Plants.FirstOrDefault(l => l.PlantID == plant.PlantID).PlantLoops.Add(_loop);

            contx.SaveChanges();
            //contx.Plants.FirstOrDefault(g => g.PlantID == plant.PlantID).PlantLoops.Add(contx.EQControlLoops.FirstOrDefault(e => e.EquipName == _loop.BaseEquipID));
            //p.PlantLoops.Add(_loop);
            //contx.SaveChanges();

            //contx.Units.FirstOrDefault(u => u.UnitID == unit.UnitID).UnitLoops.Add(contx.EQControlLoops.FirstOrDefault(e => e.BaseEquipID == _loop.BaseEquipID));

            return(_loop);
        }
Exemplo n.º 5
0
        public EQControlLoop GetEQControlLoopsByPlantByName(Plant plant, string name)
        {
            BrewDBContext cont = new BrewDBContext();

            //List<EQControlLoop> loops = cont.EQControlLoops.SelectMany(g => EQControlLoops).Where(g => g.Plant == plant).ToList();

            var loopq = from p in cont.EQControlLoops
                        where (p.EquipName == name) && (p.Plant.PlantID == plant.PlantID)
                        select p;


            EQControlLoop loop = new EQControlLoop();

            loop = loopq.FirstOrDefault();
            return(loop);
        }
Exemplo n.º 6
0
////////        public IFluentControlLoop AddControlLoop(string LoopName, string EqDescription)
//////        public IFluentControlLoop AddControlLoop(string LoopName, string EqDescription)
//////        {
//////            //Plant p = _parent.GetPlant();
////////            Plant p = _plant;
//////            //_plant = _plant.GetPlant();
//////            _loop = _plant.PlantLoops.FirstOrDefault(g => g.EquipName == LoopName);

//////        AddControlLoop(LoopName

//////            //contx.AddEQControlLoopToPlant(

//////            if (_loop == null)
//////            {


//////                _loop = contx.CreateNewLoop(LoopName, EqDescription, _plant, _unit);


//////            }



//////            ////        _loop = new EQControlLoop();

//////            ////        _loop.AssetTag = "111";
//////            ////        _loop.Description = "default";
//////            ////        _loop.EnableTrending = false;
//////            ////        _loop.EquipName = LoopName;

//////            ////        _loop.EQType = contx.EQTypes.FirstOrDefault(f => f.TypeDescription == EqDescription);
//////            ////        //_loop.Plant = _parent.GetPlant();
//////            ////        _loop.Plant = contx.Plants.FirstOrDefault(e => e.PlantID == p.PlantID);

//////            ////        contx.EQControlLoops.Add(_loop);
//////            ////        contx.SaveChanges();
//////            ////        contx.Plants.FirstOrDefault(g => g.PlantID == p.PlantID).PlantLoops.Add(contx.EQControlLoops.FirstOrDefault(e=>e.BaseEquipID == _loop.BaseEquipID));
//////            ////        //p.PlantLoops.Add(_loop);
//////            ////        contx.SaveChanges();

//////            ////        if (_unit != null)
//////            ////        {
//////            ////            //contx.Plants.FirstOrDefault(e => e.PlantID == p.PlantID).Units.FirstOrDefault(p => p.UnitID == _unit.UnitID).UnitLoops.Add(contx.EQControlLoops.FirstOrDefault(l => l.EquipName == LoopName));

//////            ////            contx.Units.FirstOrDefault(u => u.UnitID == _unit.UnitID).UnitLoops.Add(contx.EQControlLoops.FirstOrDefault(e => e.BaseEquipID == _loop.BaseEquipID));
//////            ////            contx.SaveChanges();


//////            ////        }

//////            ////    }
//////            ////    catch (Exception ex)
//////            ////    {
//////            ////        _message = _message + ex.ToString();

//////            ////    }
//////            ////}
//////            return this;


//////        }



        /// <summary>
        /// add to unit
        /// </summary>
        /// <param name="s"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public IFluentControlLoop AddControlLoop(string name, string type = "")
        {
            if (_plant != null)
            {
                _loop = contx.Plants.FirstOrDefault(g => g.PlantID == _plant.PlantID).PlantLoops.FirstOrDefault(x => x.EquipName == name);

                if (_loop == null)
                {
                    _loop = contx.CreateNewLoop(name, type, _plant, _unit);
                }
            }

            if (_loop != null)
            {
                if (_unit != null)
                {
                    _loop = contx.AddEQControlLoopToUnit(_unit.UnitID, name);
                }
            }
            return(this);
        }
Exemplo n.º 7
0
        public EQControlLoop AddEQControlLoopToUnit(int unitID, string name)
        {
            BrewDBContext cont = new BrewDBContext();
            Unit          u    = new Unit();

            u = cont.Units.FirstOrDefault(g => g.UnitID == unitID);

            Plant plant = cont.Plants.FirstOrDefault(g => g.PlantID == u.Plant.PlantID);

            EQControlLoop loop = new EQControlLoop();

            loop = plant.PlantLoops.FirstOrDefault(g => g.EquipName == name);

            //plant.PlantLoops.Add(loop);

            cont.Units.FirstOrDefault(g => g.UnitID == unitID).UnitLoops.Add(loop);

            cont.SaveChanges();

            //return cont.EQControlLoops.SelectMany(g => EQControlLoops).Where(g => g.Plant.PlantID == plantID).ToList();
            return(loop);
        }
Exemplo n.º 8
0
        public FluentControlLoop(Plant plant, string name)
        {
            try
            {
                //Plant plant = parent;
                //_plant = parent.GetPlant();
//                _plant = contx.Plants.FirstOrDefault(g => g.PlantID == plant.PlantID);
                //_plant = contx.GetPlantByPlantID(plant.PlantID);
                _plant   = plant;
                _message = "";
                //_loop = contx.EQControlLoops.FirstOrDefault(g => g.EquipName == name);

                //var test = contx.EQControlLoops
                //    .Where(b => b.Plant.PlantID == plant.PlantID)
                //    .Where(c => c.EquipName == name)
                //    .FirstOrDefault();

                _loop = contx.GetLoopByPlantIDAndName(_plant.PlantID, name);
            }
            catch (Exception ex)
            {
                _message = _message + ex.ToString();
            }
        }