private void RootAndMenu_Clicked(object sender, EventArgs e, AdvanceSearchNode node, AndOREqualType andOrType)
        {
            var logicPhrase = new LogicPhraseDTO();

            logicPhrase.AndOrType = andOrType;
            AddLogicNode(node, logicPhrase);
        }
        public LogicPhraseDTO GetQuickSearchLogicPhrase(string text, EntitySearchDTO entitySearch)
        {
            LogicPhraseDTO quickSearchLogic = new LogicPhraseDTO();

            quickSearchLogic.AndOrType = AndOREqualType.Or;
            foreach (var item in entitySearch.EntitySearchAllColumns)
            {
                if (item.ColumnID != 0)
                {
                    SearchProperty searchProperty = new SearchProperty();
                    searchProperty.SearchColumnID = item.ID;
                    searchProperty.ColumnID       = item.ColumnID;
                    searchProperty.IsKey          = item.Column.PrimaryKey;
                    searchProperty.Value          = text;
                    LogicPhraseDTO logic = null;
                    if (item.RelationshipTail == null)
                    {
                        logic = quickSearchLogic;
                    }
                    else
                    {
                        logic           = AgentHelper.GetOrCreateSearchRepositoryFromRelationshipTail(quickSearchLogic, item.RelationshipTail, null);
                        logic.AndOrType = AndOREqualType.Or;
                    }

                    int      n;
                    var      isNumeric = int.TryParse(text, out n);
                    DateTime a;
                    var      isDateTime = DateTime.TryParse(text, out a);

                    if (item.Column.ColumnType == Enum_ColumnType.Numeric)
                    {
                        if (!isNumeric)
                        {
                            continue;
                        }
                        searchProperty.Operator = CommonOperator.Equals;
                    }
                    else if (item.Column.ColumnType == Enum_ColumnType.Date)
                    {
                        continue;
                    }
                    else if (item.Column.ColumnType == Enum_ColumnType.Boolean)
                    {
                        continue;
                    }
                    else if (item.Column.ColumnType == Enum_ColumnType.String)
                    {
                        searchProperty.Operator = CommonOperator.Contains;
                    }
                    else
                    {
                        continue;
                    }
                    logic.Phrases.Add(searchProperty);
                }
            }
            return(quickSearchLogic);
        }
        //public List<PreDefinedSearchColumns> GetSearchColumns()
        //{
        //    List<PreDefinedSearchColumns> result = new List<PreDefinedSearchColumns>();
        //    foreach (var property in SimpleColumnControls)
        //    {
        //        var value = property.ControlManager.GetValue();
        //        if (PropertyHasValue(property, value))
        //        {
        //            PreDefinedSearchColumns item = new PreDefinedSearchColumns();
        //            if (property.EntitySearchColumn != null)
        //                item.EntitySearchColumnsID = property.EntitySearchColumn.ID;
        //            else
        //                item.ColumnID = property.Column.ID;
        //            item.Value = value;
        //            item.Operator = property.ControlManager.GetOperator();
        //            result.Add(item);
        //        }
        //    }
        //    return result;
        //}
        public DP_SearchRepository GetSearchRepository()
        {
            if (firstRepository == null)
            {
                firstRepository = new DP_SearchRepository(SearchInitializer.EntityID);
            }
            else
            {
                firstRepository.Phrases.Clear();
            }
            firstRepository.Title          = SearchInitializer.Title;
            firstRepository.IsSimpleSearch = true;
            firstRepository.EntitySearchID = EntitySearch == null ? 0 : EntitySearch.ID;
            foreach (var property in SimpleColumnControls)
            {
                var value = property.ControlManager.GetValue(null);
                if (PropertyHasValue(property, value))
                {
                    LogicPhraseDTO logic = null;
                    if (property.EntitySearchColumn.RelationshipTail == null)
                    {
                        logic = firstRepository;
                    }
                    else
                    {
                        logic = AgentHelper.GetOrCreateSearchRepositoryFromRelationshipTail(firstRepository, property.EntitySearchColumn.RelationshipTail, null);
                    }

                    SearchProperty searchProperty = new SearchProperty();
                    searchProperty.SearchColumnID = property.EntitySearchColumn != null ? property.EntitySearchColumn.ID : 0;
                    searchProperty.ColumnID       = property.Column.ID;
                    searchProperty.IsKey          = property.Column.PrimaryKey;
                    searchProperty.Value          = value;
                    searchProperty.Operator       = property.ControlManager.GetOperator();
                    logic.Phrases.Add(searchProperty);
                }
            }

            foreach (var relControl in RelationshipColumnControls)
            {
                if (relControl.EditNdTypeArea.GetDataList().Any())
                {
                    var            data  = relControl.EditNdTypeArea.GetDataList().First();
                    LogicPhraseDTO logic = AgentHelper.GetOrCreateSearchRepositoryFromRelationshipTail(firstRepository, relControl.EntitySearchColumn.RelationshipTail, data);

                    //foreach (var property in data.KeyProperties)
                    //{
                    //    SearchProperty searchProperty = new SearchProperty();
                    //    searchProperty.SearchColumnID = relControl.EntitySearchColumn != null ? relControl.EntitySearchColumn.ID : 0;
                    //    searchProperty.ColumnID = property.Column.ID;
                    //    searchProperty.IsKey = property.Column.PrimaryKey;
                    //    searchProperty.Value = property.Value;
                    //    searchProperty.Operator = CommonOperator.Equals;
                    //    logic.Phrases.Add(searchProperty);
                    //}
                }
                else
                {
                    var text = relControl.EditNdTypeArea.TemporaryDisplayView.GetSearchText();
                    if (!string.IsNullOrEmpty(text))
                    {
                        var entitySearch     = relControl.EditNdTypeArea.SearchViewEntityArea.SearchEntityArea.SimpleSearchEntityArea.EntitySearch;
                        var quickSearchLogic = GetQuickSearchLogicPhrase(text, entitySearch);

                        firstRepository.Phrases.Add(quickSearchLogic);
                    }
                }
            }


            //foreach (var relControl in RelationshipColumnControls)
            //{

            //    else
            //    {
            //        var value = relControl.EditNdTypeArea.TemporaryDisplayView.GetSearchText();
            //        if (!string.IsNullOrEmpty(value))
            //        {
            //            SearchProperty searchProperty = new SearchProperty();
            //            searchProperty.SearchColumnID = relControl.EntitySearchColumn != null ? relControl.EntitySearchColumn.ID : 0;
            //            searchProperty.Value = value;
            //            searchProperty.Operator = CommonOperator.Contains;
            //            logic.Phrases.Add(searchProperty);
            //        }
            //    }

            //}
            return(firstRepository);
        }
        //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);
        }
        private void ConfirmUpdateForm_Decided(object sender, ConfirmUpdateDecision e)
        {
            if (e.Confirm)
            {
                var            requester = AgentUICoreMediator.GetAgentUICoreMediator.GetRequester();
                DR_EditRequest request   = new DR_EditRequest(requester);
                request.EditPackages = Datas;

                var reuslt = AgentUICoreMediator.GetAgentUICoreMediator.requestRegistration.SendEditRequest(request);
                if (reuslt.Result == Enum_DR_ResultType.SeccessfullyDone)
                {
                    AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo(EditArea.SimpleEntity.Alias + " : " + "عملیات ثبت با موفقیت انجام شد", reuslt.Details, MyUILibrary.Temp.InfoColor.Green);
                }
                else if (reuslt.Result == Enum_DR_ResultType.JustMajorFunctionDone)
                {
                    AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo(EditArea.SimpleEntity.Alias + " : " + "عملیات ثبت با موفقیت انجام شد اما برخی عملیات جانبی کامل انجام نشد", reuslt.Details, MyUILibrary.Temp.InfoColor.Blue);
                }
                else if (reuslt.Result == Enum_DR_ResultType.ExceptionThrown)
                {
                    AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo(EditArea.SimpleEntity.Alias + " : " + "عملیات ثبت با خطا همراه بود", reuslt.Details, MyUILibrary.Temp.InfoColor.Red);
                }

                if (reuslt.Result == Enum_DR_ResultType.SeccessfullyDone ||
                    reuslt.Result == Enum_DR_ResultType.JustMajorFunctionDone)
                {
                    DP_SearchRepository searchDataItem = new DP_SearchRepository(EditArea.AreaInitializer.EntityID);
                    foreach (var item in reuslt.UpdatedItems)
                    {
                        var            listProperties = new List <EntityInstanceProperty>();
                        LogicPhraseDTO logicPhrase    = new LogicPhraseDTO();
                        foreach (var keyProperty in item.KeyProperties)
                        {
                            logicPhrase.Phrases.Add(new SearchProperty()
                            {
                                ColumnID = keyProperty.ColumnID, Value = keyProperty.Value
                            });
                        }
                        searchDataItem.AndOrType = AndOREqualType.Or;
                        searchDataItem.Phrases.Add(logicPhrase);
                    }
                    ///   var requestSearchEdit = new DR_SearchEditRequest(requester, searchDataItem, EditArea.AreaInitializer.SecurityReadOnly, true);
                    var requestSearchEdit = new DR_SearchEditRequest(requester, searchDataItem);
                    var results           = AgentUICoreMediator.GetAgentUICoreMediator.requestRegistration.SendSearchEditRequest(requestSearchEdit);
                    if (results.ResultDataItems.Count > 0)
                    {
                        if (EditArea is I_EditEntityAreaOneData)
                        {
                            (EditArea as I_EditEntityAreaOneData).ClearData(false);

                            var data = results.ResultDataItems[0];
                            data.DataView = EditArea.AreaInitializer.EditAreaDataManager.GetDataView(data);
                            var addResult = (EditArea as I_EditEntityAreaOneData).AddData(data, true);
                            if (!addResult)
                            {
                                AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo("عدم دسترسی به داده و یا داده های وابسته", results.ResultDataItems[0].ViewInfo, Temp.InfoColor.Red);
                            }
                        }
                        else if (EditArea is I_EditEntityAreaMultipleData)
                        {
                            (EditArea as I_EditEntityAreaMultipleData).ClearData(false);
                            foreach (var data in results.ResultDataItems)
                            {
                                data.DataView = EditArea.AreaInitializer.EditAreaDataManager.GetDataView(data);
                                var addResult = (EditArea as I_EditEntityAreaMultipleData).AddData(data, true);
                                if (!addResult)
                                {
                                    AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo("عدم دسترسی به داده و یا داده های وابسته", results.ResultDataItems[0].ViewInfo, Temp.InfoColor.Red);
                                }
                            }
                        }
                    }
                    else
                    {
                        AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo("عدم دسترسی به داده", "", Temp.InfoColor.Red);
                        (EditArea as BaseEditEntityArea).ClearData(true);
                    }
                }
            }
            AgentUICoreMediator.GetAgentUICoreMediator.UIManager.CloseDialog(sender);
        }