private bool GetParentSearchRepository(AdvanceSearchNode newnode)
        {
            if (newnode.Phrase is DP_SearchRepository)
            {
                if ((newnode.Phrase as DP_SearchRepository) == firstRepository)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (newnode.ParentNode == null)
            {
                return(false);
            }
            else if (newnode.ParentNode.Phrase is DP_SearchRepository)
            {
                if ((newnode.ParentNode.Phrase as DP_SearchRepository) == firstRepository)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(GetParentSearchRepository(newnode.ParentNode));
            }
        }
        private void RootAndMenu_Clicked(object sender, EventArgs e, AdvanceSearchNode node, AndOREqualType andOrType)
        {
            var logicPhrase = new LogicPhraseDTO();

            logicPhrase.AndOrType = andOrType;
            AddLogicNode(node, logicPhrase);
        }
 public bool ShowSearchRepository(DP_SearchRepository item)
 {
     if (RootNode != null)
     {
         RootNode = null;
         AdvancedSearchView.ClearTreeItems();
     }
     AddLogicNode(null, item);
     return(true);
 }
 private void RemoveMenu_Clicked(object sender, EventArgs e, AdvanceSearchNode parentNode, AdvanceSearchNode node)
 {
     if (parentNode != null)
     {
         parentNode.NodeManager.RemoveItem(node.NodeManager);
         parentNode.ChildItems.Remove(node);
         if (parentNode.Phrase is LogicPhraseDTO)
         {
             (parentNode.Phrase as LogicPhraseDTO).Phrases.Remove(node.Phrase);
         }
     }
 }
        private void Relationship_ClickedNew(object sender1, EventArgs e1, AdvanceSearchNode node, RelationshipDTO relationship)
        {
            SearchEntityArea advancedAndRaw = new EntityArea.SearchEntityArea();
            var searchViewInitializer       = new SearchEntityAreaInitializer();

            searchViewInitializer.EntityID           = relationship.EntityID2;
            searchViewInitializer.Title              = relationship.Alias;
            searchViewInitializer.SourceRelationship = relationship;
            advancedAndRaw.SearchDataDefined        += (sender, e) => AdvancedAndRaw_SearchDataDefinedNew(sender, e, relationship, node, advancedAndRaw.SearchView);
            advancedAndRaw.SetAreaInitializer(searchViewInitializer);
            AgentUICoreMediator.GetAgentUICoreMediator.UIManager.GetDialogWindow().ShowDialog(advancedAndRaw.SearchView, searchViewInitializer.Title, Enum_WindowSize.Big);
        }
        //Tuple<int,>
        //  object lastSearchView;
        private void RootAndMenu_Clicked1(object sender1, EventArgs e1, AdvanceSearchNode andOrNode)
        {
            I_RawSearchEntityArea rawSearchEntityArea = new RawSearchEntityArea();
            var searchViewInitializer = new SearchEntityAreaInitializer();

            searchViewInitializer.EntityID = SearchInitializer.EntityID;
            //if (SearchInitializer.TempEntity != null && SearchInitializer.TempEntity.ID == SearchInitializer.EntityID)
            //    searchViewInitializer.TempEntity = SearchInitializer.TempEntity;
            rawSearchEntityArea.SetAreaInitializer(searchViewInitializer);
            rawSearchEntityArea.SearchDataDefined += (sender, e) => RawSearchEntityArea_SearchDataDefined(sender, e, andOrNode, rawSearchEntityArea.RawSearchView);
            //lastSearchView = rawSearchEntityArea.RawSearchView;
            AgentUICoreMediator.GetAgentUICoreMediator.UIManager.GetDialogWindow().ShowDialog(rawSearchEntityArea.RawSearchView, "خصوصیات", Enum_WindowSize.Big);
        }
        private void Relationship_ClickedEdit(object sender1, EventArgs e1, AdvanceSearchNode node, DP_SearchRepository dP_SearchRepository)
        {
            SearchEntityArea advancedAndRaw = new EntityArea.SearchEntityArea();
            var searchViewInitializer       = new SearchEntityAreaInitializer();

            searchViewInitializer.PreDefinedSearch   = dP_SearchRepository;
            searchViewInitializer.EntityID           = dP_SearchRepository.TargetEntityID;
            searchViewInitializer.Title              = dP_SearchRepository.Title;
            searchViewInitializer.SourceRelationship = dP_SearchRepository.SourceRelationship;
            advancedAndRaw.SearchDataDefined        += (sender, e) => AdvancedAndRaw_SearchDataDefinedEdit(sender, e, node, advancedAndRaw.SearchView);
            advancedAndRaw.SetAreaInitializer(searchViewInitializer);
            AgentUICoreMediator.GetAgentUICoreMediator.UIManager.GetDialogWindow().ShowDialog(advancedAndRaw.SearchView, searchViewInitializer.Title, Enum_WindowSize.Big);
        }
        private void AddSearchPropertyNode(SearchProperty phrase, AdvanceSearchNode andOrNode)
        {
            var newnode = new AdvanceSearchNode();

            newnode.ParentNode = andOrNode;
            newnode.Title      = phrase.ColumnID.ToString();
            andOrNode.ChildItems.Add(newnode);
            newnode.NodeManager = andOrNode.NodeManager.AddChildItem();
            newnode.NodeManager.SetHeader(newnode.Title);
            newnode.Phrase = phrase;

            I_AdvanceSearchMenu removeMenu = newnode.NodeManager.AddMenu("حذف");

            removeMenu.Clicked += (sender1, e1) => RemoveMenu_Clicked(sender1, e1, andOrNode, newnode);
        }
 private void RawSearchEntityArea_SearchDataDefined(object sender, SearchPropertyArg e, AdvanceSearchNode andOrNode, object view)
 {
     AgentUICoreMediator.GetAgentUICoreMediator.UIManager.CloseDialog(view);
     foreach (var phrase in e.SearchItems)
     {
         AddSearchPropertyNode(phrase, andOrNode);
         if (andOrNode.Phrase is LogicPhraseDTO)
         {
             (andOrNode.Phrase as LogicPhraseDTO).Phrases.Add(phrase);
         }
     }
 }
        private void AdvancedAndRaw_SearchDataDefinedEdit(object sender, SearchDataArg e, AdvanceSearchNode node, object view)
        {
            AgentUICoreMediator.GetAgentUICoreMediator.UIManager.CloseDialog(view);

            if (e.SearchItems != null)
            {
                node.ParentNode.NodeManager.RemoveItem(node.NodeManager);
                node.ParentNode.ChildItems.Remove(node);
                (node.ParentNode.Phrase as LogicPhraseDTO).Phrases.Remove(node.Phrase);
                (node.ParentNode.Phrase as LogicPhraseDTO).Phrases.Add(e.SearchItems);
                AddLogicNode(node.ParentNode, e.SearchItems);
            }
        }
        private void AdvancedAndRaw_SearchDataDefinedNew(object sender, SearchDataArg e, RelationshipDTO relationship, AdvanceSearchNode node, object view)
        {
            AgentUICoreMediator.GetAgentUICoreMediator.UIManager.CloseDialog(view);

            if (node.Phrase is LogicPhraseDTO)
            {
                (node.Phrase as LogicPhraseDTO).Phrases.Add(e.SearchItems);
            }

            AddLogicNode(node, e.SearchItems);
        }
        //private AdvanceSearchNode AddSearchRepository(AdvanceSearchNode parentNode, DP_SearchRepository searchRepository)
        //{
        //    if (searchRepository == null)
        //        return null;
        //    var newnode = new AdvanceSearchNode();
        //    newnode.ParentNode = parentNode;
        //    newnode.Title = searchRepository.Name;
        //    newnode.NodeManager.SetHeader(newnode.Title);
        //    newnode.Phrase = searchRepository;
        //    if (parentNode != null)
        //    {
        //        parentNode.ChildItems.Clear();
        //        parentNode.NodeManager.ClearItems();
        //        newnode.EntityID = searchRepository.TargetEntityID;
        //        newnode.NodeManager = parentNode.NodeManager.AddChildItem();

        //    }
        //    else
        //    {
        //        newnode.EntityID = SearchInitializer.EntityID;
        //        RootNode = newnode;
        //        newnode.NodeManager = AdvancedSearchView.AddTreeItem();
        //    }
        //    foreach (var item in searchRepository.Phrases)
        //    {
        //        if (item is DP_SearchRepository)
        //        {
        //            AddSearchRepository(newnode, (item as DP_SearchRepository));
        //        }
        //        else if (item is LogicPhrase)
        //        {
        //            AddLogicPhrase(newnode, (item as LogicPhrase));
        //        }
        //        else if (item is SearchProperty)
        //        {
        //            AddChildNode((item as SearchProperty), newnode);
        //        }
        //    }
        //    return newnode;
        //}
        private AdvanceSearchNode AddLogicNode(AdvanceSearchNode parentNode, LogicPhraseDTO logicPhrase)
        {
            if (RootNode == null && logicPhrase is DP_SearchRepository)
            {
                firstRepository = logicPhrase as DP_SearchRepository;
            }

            var newnode = new AdvanceSearchNode();

            newnode.ParentNode = parentNode;
            if (logicPhrase is DP_SearchRepository)
            {
                newnode.Title = (logicPhrase as DP_SearchRepository).Title;
            }
            else
            {
                if (logicPhrase.AndOrType == AndOREqualType.And)
                {
                    newnode.Title = "And";
                }
                else if (logicPhrase.AndOrType == AndOREqualType.Or)
                {
                    newnode.Title = "Or";
                }
                else if (logicPhrase.AndOrType == AndOREqualType.NotAnd)
                {
                    newnode.Title = "Not And";
                }
                else if (logicPhrase.AndOrType == AndOREqualType.NotOr)
                {
                    newnode.Title = "Not Or";
                }
            }
            if (parentNode != null)
            {
                if (logicPhrase is DP_SearchRepository)
                {
                    newnode.EntityID = (logicPhrase as DP_SearchRepository).TargetEntityID;
                }
                else
                {
                    newnode.EntityID = parentNode.EntityID;
                }
            }
            else
            {
                newnode.EntityID = SearchInitializer.EntityID;
            }
            if (parentNode != null)
            {
                parentNode.ChildItems.Add(newnode);
            }
            else
            {
                RootNode = newnode;
            }
            if (parentNode != null)
            {
                newnode.NodeManager = parentNode.NodeManager.AddChildItem();
            }
            else
            {
                newnode.NodeManager = AdvancedSearchView.AddTreeItem();
            }
            newnode.NodeManager.SetHeader(newnode.Title);
            newnode.Phrase = logicPhrase;
            //(newnode.Phrase as LogicPhrase).AndOrType = logicPhrase.AndOrType;
            foreach (var item in logicPhrase.Phrases)
            {
                if (item is DP_SearchRepository)
                {
                    AddLogicNode(newnode, (item as LogicPhraseDTO));
                }
                else if (item is LogicPhraseDTO)
                {
                    AddLogicNode(newnode, (item as LogicPhraseDTO));
                }
                else if (item is SearchProperty)
                {
                    AddSearchPropertyNode((item as SearchProperty), newnode);
                }
            }
            if (GetParentSearchRepository(newnode))
            {
                I_AdvanceSearchMenu rootAndMenu = newnode.NodeManager.AddMenu("And");
                rootAndMenu.Clicked += (sender, e) => RootAndMenu_Clicked(sender, e, newnode, AndOREqualType.And);
                I_AdvanceSearchMenu rootNotAndMenu = newnode.NodeManager.AddMenu("Not And");
                rootAndMenu.Clicked += (sender, e) => RootAndMenu_Clicked(sender, e, newnode, AndOREqualType.NotAnd);
                I_AdvanceSearchMenu rootOrMenu = newnode.NodeManager.AddMenu("Or");
                rootOrMenu.Clicked += (sender, e) => RootAndMenu_Clicked(sender, e, newnode, AndOREqualType.Or);
                I_AdvanceSearchMenu rootNotOrMenu = newnode.NodeManager.AddMenu("Or");
                rootOrMenu.Clicked += (sender, e) => RootAndMenu_Clicked(sender, e, newnode, AndOREqualType.NotOr);

                I_AdvanceSearchMenu simpleSearchMenu = newnode.NodeManager.AddMenu("خصوصیات");
                simpleSearchMenu.Clicked += (sender1, e1) => RootAndMenu_Clicked1(sender1, e1, newnode);

                foreach (var relationship in FullEntity.Relationships) //.Where(x => x.SearchEnabled == true))
                {
                    I_AdvanceSearchMenu relationshipSearchMenu = newnode.NodeManager.AddMenu(relationship.Alias);
                    relationshipSearchMenu.Clicked += (sender1, e1) => Relationship_ClickedNew(sender1, e1, newnode, relationship);
                }
            }
            else
            {
                if (logicPhrase is DP_SearchRepository)
                {
                    I_AdvanceSearchMenu editRelationshipSearchMenu = newnode.NodeManager.AddMenu("اصلاح");
                    editRelationshipSearchMenu.Clicked += (sender1, e1) => Relationship_ClickedEdit(sender1, e1, newnode, (logicPhrase as DP_SearchRepository));
                }
            }
            if (parentNode != null)
            {
                I_AdvanceSearchMenu removeMenu = newnode.NodeManager.AddMenu("حذف");
                removeMenu.Clicked += (sender1, e1) => RemoveMenu_Clicked(sender1, e1, parentNode, newnode);
            }
            return(newnode);
        }