예제 #1
0
        private void GenerateElement(ElectricalGroup group, HtmlGenericControl parentElement, string treeType)
        {
            HtmlGenericControl li = new HtmlGenericControl("li");

            li.Attributes.Add("id", "eg_" + group.Id.ToString());
            li.Attributes.Add("rel", "electricalgroup");
            if (treeType == "available")
            {
                li.Attributes.Add("treetype", "available");
            }
            else
            {
                li.Attributes.Add("treetype", "added");
            }
            HtmlGenericControl a = new HtmlGenericControl("a");

            a.Attributes.Add("class", "textHolder");
            a.Attributes.Add("key", group.Id.ToString());

            a.Attributes.Add("title", group.Name);
            if (group.ParentPk.HasValue)
            {
                a.Attributes.Add("pkey", group.ParentPk.Value.ToString());
            }
            a.InnerText = string.Format("{0} - {1}", group.Abbreviation, group.Name);
            li.Controls.Add(a);
            parentElement.Controls.Add(li);
        }
 /// <summary>
 /// Deletes an existing ElectricalGroup object
 /// </summary>
 /// <param name="electricalGroup">ElectricalGroup object to delete</param>
 public void DeleteElectricalGroupPermanent(ElectricalGroup electricalGroup)
 {
     if (electricalGroup == null)
     {
         return;
     }
     Context.ElectricalGroups.Remove(electricalGroup);
     Context.SaveChanges();
 }
        public bool DeleteElectricalGroup(int key)
        {
            ElectricalGroup group = GetElectricalGroup(key);

            if (group == null)
            {
                return(true);
            }
            return(DeleteElectricalGroup(group));
        }
        /// <summary>
        /// Retrieves all mapped child Substations for a particular parentGroup.
        /// </summary>
        /// <returns>list of ElectricalGroup objects</returns>
        public void getChildSubstations(ElectricalGroup parentGroup, List <Substation> assignedSubstations)
        {
            IList <Substation> substations = GetSubstationsbyElectricalGroup(parentGroup.Id) as IList <Substation>;

            assignedSubstations.AddRange(substations);
            if (parentGroup.ChildGroups != null && parentGroup.ChildGroups.Count > 0)
            {
                foreach (ElectricalGroup cg in parentGroup.ChildGroups)
                {
                    getChildSubstations(cg, assignedSubstations);
                }
            }
        }
예제 #5
0
        //[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public XmlDocument GetAllElectricalGroupsSubstations(int poolId, int mapId)
        {
            try
            {
                if (poolId <= 0 || mapId <= 0)
                {
                    return(null);
                }
                //string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["EpicDB"].ConnectionString;
                //EpicCutPlanes epicCutPlanes = new EpicCutPlanes(ConnectionString);
                addedSubstations = new List <Substation>();
                List <Substation> sourceSubstations = new List <Substation>();
                egParents = new List <ElectricalGroup>();
                //mapEGs contain all EGs for that particular map only.
                List <ElectricalGroup> mapEGs = new List <ElectricalGroup>();
                addedSubstations = EpicCutPlanes.GetPoolSubstations(poolId);
                //for now, using Map 1 - since we are using maps now.

                // ElectricalGroup parentGroup = GetElectricalGroupChildren(
                int parentGroupId         = EpicCutPlanes.GetParentGroupId(mapId);
                HtmlGenericControl parent = new HtmlGenericControl();
                ElectricalGroup    root   = GetRootElectricalGroup(parentGroupId, true, mapEGs);

                sourceSubstations = EpicCutPlanes.GetSourceSubstations(root, addedSubstations);
                if (sourceSubstations != null)
                {
                    egParents = GetElectricalGroupParents(sourceSubstations, mapEGs); //mapId
                }
                GenerateElement(root, parent, "available");
                GenerateChildList(root, parent.Controls[parent.Controls.Count - 1] as HtmlGenericControl, "available"); //, addedSubstations, egParents);
                string contents = null;
                using (System.IO.StringWriter swriter = new System.IO.StringWriter())
                {
                    HtmlTextWriter writer = new HtmlTextWriter(swriter);
                    parent.RenderControl(writer);
                    contents = swriter.ToString();
                }

                contents = contents.Replace("<span>", "<ul>");
                contents = contents.Replace("</span>", "</ul>");
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(contents);
                //xmlDoc.LoadXml("<ul><li id='phtml_1'><a href='#'>Root node 1</a><ul><li id='phtml_2'><a href='#'>Child node 1</a><ul><li id='phtml_5'><a href='#'>Child node 5</a></li><li id='phtml_6'><a href='#'>Child node 6</a></li></ul></li><li id='phtml_3'><a href='#'>Child node 2</a></li></ul></li><li id='phtml_4'><a href='#'>Root node 2</a></li></ul>");
                return(xmlDoc);
            }
            catch (Exception ex)
            {
                //Log.Error("CutPlaneManagement::GetAllElectricalGroupsSubstations: Exception" + ex.Message + ex.StackTrace);
                throw;
            }
        }
예제 #6
0
        ///// <summary>
        ///// Gets Substation object by ID.
        ///// </summary>
        ///// <returns>Substation object.</returns>
        //public Substation GetSubstation(int substationId)
        //{
        //    try
        //    {
        //        return EpicCutPlanes.GetSubstation(substationId);
        //    }
        //    catch (Exception ex)
        //    {
        //        Log.Error("CutPlaneManagement::GetSubstation: Exception" + ex.Message + ex.StackTrace);
        //        throw;
        //    }
        //}


        bool ContainsEg(ElectricalGroup electricalGroup, List <ElectricalGroup> groupList)
        {
            //if (electricalGroup.Abbreviation=="SI")
            //{
            //    int i = 1;
            //}
            if (groupList.Contains(electricalGroup))  //Implemented Ienumerable
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void GetElectricalParentGroups(ElectricalGroup eGroup, List <ElectricalGroup> parentGroups)
        {
            var parentGroup = Context.ElectricalGroups.Where(eg => eg.Id.Equals(eGroup.ParentPk)).FirstOrDefault();

            if (parentGroup != null)
            {
                if (!parentGroups.Contains((ElectricalGroup)parentGroup))
                {
                    parentGroups.Add((ElectricalGroup)parentGroup);
                    if (parentGroup.ParentPk != null)
                    {
                        GetElectricalParentGroups((ElectricalGroup)parentGroup, parentGroups);
                    }
                }
            }
        }
예제 #8
0
 public List <ElectricalGroup> RemoveSubstations(List <string> substList, int poolId, int mapId)
 {
     try
     {
         if (poolId <= 0)
         {
             return(null);
         }
         addedSubstations = new List <Substation>();
         foreach (string substId in substList)
         {
             if (substId.Contains("subst_"))
             {
                 int substationid = substId.Replace("subst_", "").ToInt32();
                 EpicCutPlanes.DeleteSubstationPool(substationid, poolId);
                 Substation substation = EpicCutPlanes.GetSubstation(substationid);
                 addedSubstations.Add(substation);
             }
         }
         //Need to return E.G. parents hierarchy to add E.G.'s to hierarchy
         List <ElectricalGroup> mapEGs = new List <ElectricalGroup>();
         int             parentGroupId = EpicCutPlanes.GetParentGroupId(mapId);
         ElectricalGroup root          = GetRootElectricalGroup(parentGroupId, true, mapEGs);
         //addedSubstations = EpicCutPlanes.GetPoolSubstations(poolId);
         egParents = GetElectricalGroupParents(addedSubstations, mapEGs); //int mapId,
         List <ElectricalGroup> serializableEGs = new List <ElectricalGroup>();
         foreach (ElectricalGroup eg in egParents)
         {
             ElectricalGroup serializableEg = new ElectricalGroup();
             serializableEg.Abbreviation  = eg.Abbreviation;
             serializableEg.DateCreated   = eg.DateCreated;
             serializableEg.DateUpdated   = eg.DateUpdated;
             serializableEg.Id            = eg.Id;
             serializableEg.Name          = eg.Name;
             serializableEg.ParentPk      = eg.ParentPk;
             serializableEg.UserCreatedId = eg.UserCreatedId;
             serializableEg.UserUpdatedId = eg.UserUpdatedId;
             serializableEGs.Add(serializableEg);
         }
         return(serializableEGs);
     }
     catch (Exception ex)
     {
         //Log.Error("CutPlaneManagement::RemoveSubstations: Exception" + ex.Message + ex.StackTrace);
         throw;
     }
 }
예제 #9
0
        private void GenerateSubstationElement(Substation substation, ElectricalGroup group, HtmlGenericControl parentElement) //EpicDataAccess.Domain.
        {
            HtmlGenericControl li = new HtmlGenericControl("li");

            li.Attributes.Add("id", "subst_" + substation.Id.ToString());
            li.Attributes.Add("egid", group.Id.ToString());
            li.Attributes.Add("rel", "default");
            HtmlGenericControl a = new HtmlGenericControl("a");

            a.Attributes.Add("class", "textHolder");
            a.Attributes.Add("key", substation.Id.ToString());

            a.Attributes.Add("title", substation.Name);
            a.InnerText = string.Format("{0} - {1}", substation.TLA, substation.Name);
            li.Controls.Add(a);
            parentElement.Controls.Add(li);
        }
예제 #10
0
        private void GenerateDestChildList(ElectricalGroup group, HtmlGenericControl parentElement, string treeType) //, List<Substation> addedSubstations, List<ElectricalGroup> egParents)
        {
            HtmlGenericControl ul = new HtmlGenericControl("ul");

            ul.Attributes.Add("style", "display: none;");
            if (ContainsEg(group, egParents))
            {
                // EpicSubstationManager epicSubstationManager = new EpicSubstationManager();
                IList <Substation> substations = EpicCutPlanes.GetSubstationsbyElectricalGroup(group.Id) as IList <Substation>; //EpicDataAccess.Domain.
                //IList<Substation> substations = EpicMaps.GetSubstationsbyElectricalGroup(group.Id) as IList<Substation>;
                if (substations != null && substations.Count > 0 && parentElement != null)
                {
                    parentElement.Controls.Add(ul);
                    foreach (Substation s in substations) //EpicDataAccess.Domain.
                    {
                        //if (s.ElectricalGroupId != null &&
                        if (ContainsSubstation(s.Id, addedSubstations))
                        {
                            GenerateSubstationElement(s, group, ul);
                        }
                    }
                }
            }
            if (group.ChildGroups != null && group.ChildGroups.Count > 0 && parentElement != null && destinationEGCount < egParents.Count)
            {
                parentElement.Controls.Add(ul);

                foreach (ElectricalGroup cg in group.ChildGroups)
                {
                    if (ContainsEg(cg, egParents))
                    {
                        GenerateElement(cg, ul, treeType);
                        destinationEGCount++;
                        GenerateDestChildList(cg, ul.Controls[ul.Controls.Count - 1] as HtmlGenericControl, treeType); //, addedSubstations, egParents);
                    }
                    else
                    {
                        GenerateDestChildList(cg, parentElement, treeType); //, addedSubstations, egParents);
                    }
                }
            }
        }
        /// <summary>
        /// Inserts a new Map object to Db or updates any existing Map object (based on Map ID)
        /// </summary>
        /// <param name="cutplane">Map object</param>
        public int SaveElectricalGroup(ElectricalGroup electricalGroup)
        {
            ElectricalGroup currentEG = (from eg in this.Context.ElectricalGroups.Where(eg => eg.Id.Equals(electricalGroup.Id))
                                         select eg).FirstOrDefault();

            if (currentEG != null)
            {
                currentEG.DateUpdated   = electricalGroup.DateCreated;
                currentEG.UserUpdatedId = electricalGroup.UserCreatedId;
                currentEG.Abbreviation  = electricalGroup.Abbreviation;
                currentEG.Name          = electricalGroup.Name;
                currentEG.ParentPk      = electricalGroup.ParentPk;
                electricalGroup.Id      = currentEG.Id;
            }
            else
            {
                this.Context.ElectricalGroups.Add(electricalGroup);
            }
            this.Context.SaveChanges();
            return(electricalGroup.Id);
        }
예제 #12
0
        //[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public XmlDocument GetAddedGroups(int poolId, int mapId)
        {
            try
            {
                addedSubstations = new List <Substation>();
                egParents        = new List <ElectricalGroup>();
                List <ElectricalGroup> mapEGs = new List <ElectricalGroup>();

                HtmlGenericControl parent     = new HtmlGenericControl();
                int             parentGroupId = EpicCutPlanes.GetParentGroupId(mapId);
                ElectricalGroup root          = GetRootElectricalGroup(parentGroupId, true, mapEGs);

                addedSubstations = EpicCutPlanes.GetPoolSubstations(poolId);
                egParents        = GetElectricalGroupParents(addedSubstations, mapEGs); //int mapId,

                GenerateElement(root, parent, "added");
                destinationEGCount = 1;                                                                                 //Since 1 E.G. has been drawn.
                GenerateDestChildList(root, parent.Controls[parent.Controls.Count - 1] as HtmlGenericControl, "added"); //, addedSubstations, egParents);
                string contents = null;
                using (System.IO.StringWriter swriter = new System.IO.StringWriter())
                {
                    HtmlTextWriter writer = new HtmlTextWriter(swriter);
                    parent.RenderControl(writer);
                    contents = swriter.ToString();
                }
                contents = contents.Replace("<span>", "<ul>");
                contents = contents.Replace("</span>", "</ul>");
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(contents);
                //"rel", "electricalgroup")
                //xmlDoc.LoadXml("<ul><li id='dhtml_1'><a href='#'>Root node 1</a><ul><li id='dhtml_2'><a href='#'>Child node 1</a>      </li><li id='dhtml_3'><a href='#'>Child node 2</a></li></ul></li><li id='dhtml_4'><a href='#'>Root node 2</a></li></ul>");
                //<ul> <li id='eg1' rel='electricalgroup'>eg_1 <ul> <li id='sub1' rel='default'>  sub_1 </li>  <li id='sub2' rel='default'> sub2 </li></ul></li></ul>");
                return(xmlDoc);
            }
            catch (Exception ex)
            {
                //Log.Error("CutPlaneManagement::GetAddedGroups: Exception" + ex.Message + ex.StackTrace);
                throw;
            }
        }
예제 #13
0
 public ElectricalGroup GetRootElectricalGroup(int parentGroupId, bool includeChildGroups, List <ElectricalGroup> mapEGs)
 {
     try
     {
         ElectricalGroup group = EpicCutPlanes.GetElectricalGroup(parentGroupId); // GetRootElectricalGroup();
         if (group == null)
         {
             return(null);
         }
         mapEGs.Add(group);
         if (includeChildGroups)
         {
             group.ChildGroups = GetElectricalGroupChildren(group.Id, mapEGs);
         }
         return(group);
     }
     catch (Exception ex)
     {
         //Log.Error("CutPlaneManagement::GetRootElectricalGroup: Exception" + ex.Message + ex.StackTrace);
         throw;
     }
 }
        public bool DeleteElectricalGroup(ElectricalGroup group)
        {
            if (group == null)
            {
                return(true);
            }
            bool deleted = true;

            if (group.ChildGroups != null && group.ChildGroups.Count > 0)
            {
                foreach (ElectricalGroup g in group.ChildGroups)
                {
                    deleted = DeleteElectricalGroup(g);
                    if (!deleted)
                    {
                        return(deleted);
                    }
                }
            }
            DeleteElectricalGroupPermanent(group);
            return(true);
        }
        /// <summary>
        /// Retrieves all Substations not in the list of added substations
        /// </summary>
        /// <returns>list of ElectricalGroup objects</returns>
        public List <Substation> GetSourceSubstations(ElectricalGroup parentGroup, List <Substation> addedSubstations)
        {
            // int parentGroupId = GetParentGroupId(mapId);
            // ElectricalGroup parentGroup = GetElectricalParentGroups GetElectricalGroup(parentGroupId);

            if (parentGroup != null)
            {
                //First retrieve list of substations that are in this particular map.
                List <Substation> mappedSubstations = new List <Substation>();
                getChildSubstations(parentGroup, mappedSubstations);

                //Next compare mapped substations to those added into the cutplane,
                //and retrieve only those mapped substations that haven't been added to the cutplane.
                int[] addedarray  = addedSubstations.Select(ads => ads.Id).ToArray();
                var   substations = mappedSubstations.Where(ms => !addedarray.Contains(ms.Id)).Distinct(); //ms.ElectricalGroupId.HasValue &&
                return(substations != null?substations.ToList() : null);
            }
            else
            {
                return(null);
            }
        }