예제 #1
0
        //====================================================================================================================
        // ADD COMPONENT
        public ActionResult AddComponent()
        {
            var userName = User.Identity.GetUserName();
            var xmlDB    = new XMLDatabase(userName, _context.Users.First(c => c.Name == userName).ActProject);

            //Load pagename
            String pageName;

            if (String.IsNullOrEmpty(userName))
            {
                pageName = "";
            }
            else
            {
                pageName = _context.Users.First(c => c.Name == userName).ActProject;
            }

            var addComponentFactoryViewModel = new AddComponentFactoryViewModel()
            {
                ComponentLocations = xmlDB.Locations.ToList(),
                Standards          = xmlDB.Standards.ToList(),
                PageName           = pageName
            };

            return(View("ComponentForm", addComponentFactoryViewModel));
        }
예제 #2
0
        //====================================================================================================================
        // EDIT COMPONENT
        public ActionResult Edit(int id)
        {
            var userName = User.Identity.GetUserName();
            var xmlDB    = new XMLDatabase(userName, _context.Users.First(c => c.Name == userName).ActProject);

            //Load pagename
            String pageName;

            if (String.IsNullOrEmpty(userName))
            {
                pageName = "";
            }
            else
            {
                pageName = _context.Users.First(c => c.Name == userName).ActProject;
            }

            var component = xmlDB.Components.SingleOrDefault(c => c.Id == id);

            if (component == null)
            {
                return(HttpNotFound());
            }

            //Two cases - setup component with and without standard
            if (component.StandardId != null && component.StandardId != 0)
            {
                //Convert String Value to AuxValueX
                foreach (var parameter in component.Setup.Parameters.ToList())
                {
                    //Do that only for IO and Parameter Types
                    if (parameter.Type != ParType.IO && parameter.Type != ParType.Parameter)
                    {
                        continue;
                    }

                    if (parameter.Type == ParType.Parameter)
                    {//Case Parameter
                        if (parameter.DataType == DataType.BOOL)
                        {
                            parameter.AuxValueBOOL = Convert.ToBoolean(Convert.ToInt32(parameter.Value));
                        }
                        else
                        {
                            if (parameter.Value == "TODO")
                            {
                                parameter.AuxValueFLOAT = null;
                            }
                            else
                            {
                                parameter.AuxValueFLOAT = (float)Convert.ToDouble(parameter.Value);
                            }
                        }
                    }
                    else
                    {//case IO
                        if (parameter.Value == "TODO" || parameter.Value == "AlwaysOFF" || parameter.Value == "AlwaysON")
                        {
                            parameter.AuxValueINT = null;
                        }
                        else
                        {
                            parameter.AuxValueINT = Convert.ToInt32(parameter.Value);
                        }
                    }
                }
            }

            var viewModel = new AddComponentFactoryViewModel
            {
                Component          = component,
                ComponentLocations = xmlDB.Locations.ToList(),
                Standards          = xmlDB.Standards,
                DIChilds           = xmlDB.IOs.Where(c => (c.ConnectionType == Enums.ConnectionType.DI && c.ComponentId == component.Id)).ToList(),
                DOChilds           = xmlDB.IOs.Where(c => (c.ConnectionType == Enums.ConnectionType.DO && c.ComponentId == component.Id)).ToList(),
                AIChilds           = xmlDB.IOs.Where(c => (c.ConnectionType == Enums.ConnectionType.AI && c.ComponentId == component.Id)).ToList(),
                AOChilds           = xmlDB.IOs.Where(c => (c.ConnectionType == Enums.ConnectionType.AO && c.ComponentId == component.Id)).ToList(),
                PageName           = pageName
            };

            return(View("ComponentForm", viewModel));
        }