private DataLinkDTO ToDataLinkDTO(DataLinkDefinition item, bool withDetails)
        {
            DataLinkDTO result = new DataLinkDTO();

            bizEntityReport.ToEntityReportDTO(item.EntityDataItemReport.EntityReport, result, withDetails);
            result.SecondSideEntityID   = item.SecondSideEntityID;
            result.NotJointEntities     = item.NotJointEntities == true;
            result.FirstSideDataMenuID  = item.FirstSideDataMenuID ?? 0;
            result.SecondSideDataMenuID = item.SecondSideDataMenuID ?? 0;
            if (withDetails)
            {
                BizEntityRelationshipTail         bizEntityRelationshipTail         = new MyModelManager.BizEntityRelationshipTail();
                BizEntityRelationshipTailDataMenu bizEntityRelationshipTailListView = new MyModelManager.BizEntityRelationshipTailDataMenu();

                foreach (var dbRel in item.DataLinkDefinition_EntityRelationshipTail)
                {
                    var rel = new DataLinkRelationshipTailDTO();
                    rel.RelationshipTailID = dbRel.EntityRelationshipTailID;
                    rel.EntityRelationshipTailDataMenuID = dbRel.EntityRelationshipTailDataMenuID ?? 0;
                    if (rel.EntityRelationshipTailDataMenuID != 0)
                    {
                        rel.EntityRelationshipTailDataMenu = bizEntityRelationshipTailListView.ToEntityRelationshipTailDataMenuDTO(dbRel.EntityRelationshipTailDataMenu, true);
                    }
                    //   rel.FromFirstSideToSecondSide = dbRel.FromFirstSideToSecondSide;
                    rel.ID = dbRel.ID;
                    rel.RelationshipTail = bizEntityRelationshipTail.ToEntityRelationshipTailDTO(dbRel.EntityRelationshipTail);
                    result.RelationshipsTails.Add(rel);
                }
            }



            return(result);
        }
Beispiel #2
0
 private void NewItem()
 {
     Message = new DataLinkDTO();
     Message.TableDrivedEntityID = FirstEntityID;
     ShowMessage();
 }
        private DataLinkItemGroup GetIncludedDataLinkItems(EntityRelationshipTailDTO relationshipTail, DataLinkDTO selectedDataLink, DP_DataView relationshipFirstData, DP_DataView targetData, int level
                                                           , EntityRelationshipTailDataMenuDTO relationshipTailDataMenuDTO, DataLinkItem parentDataLinkItem = null, DataLinkItemGroup result = null, List <DataLinkItem> allItems = null)
        {
            if (result == null)
            {
                result = new DataLinkItemGroup();
            }
            if (relationshipTail != null && relationshipTail.ChildTail != null)
            {
                RelationshipTailDataManager relationshipTailDataManager = new RelationshipTailDataManager();

                //var firstData = new DP_DataRepository();
                //firstData.TargetEntityID = FirstData.TargetEntityID;
                //firstData.DataView = FirstData;
                //foreach (var key in FirstData.KeyProperties)
                //{
                //    firstData.AddProperty(new ColumnDTO() { ID = key.ColumnID }, key.Value);
                //}
                var searchDataTuple         = AgentUICoreMediator.GetAgentUICoreMediator.RelationshipDataManager.GetSecondSideSearchDataItemByRelationship(relationshipFirstData, relationshipTail.Relationship.ID);
                var searchPhraseToOtherData = relationshipTailDataManager.GetTargetSearchItemFromRelationshipTail(targetData, relationshipTail.ChildTail.ReverseRelationshipTail);
                searchDataTuple.Phrases.AddRange(searchPhraseToOtherData.Phrases);
                var requester = AgentUICoreMediator.GetAgentUICoreMediator.GetRequester();
                //سکوریتی داده اعمال میشود
                var searchRequest = new DR_SearchViewRequest(requester, searchDataTuple);
                //searchRequest.EntityID = parentTail.RelationshipTargetEntityID;
                var searchResult = AgentUICoreMediator.GetAgentUICoreMediator.requestRegistration.SendSearchViewRequest(searchRequest);

                if (parentDataLinkItem != null)
                {
                    parentDataLinkItem.TailPath = relationshipTail.RelationshipIDPath;
                    if (relationshipTailDataMenuDTO != null)
                    {
                        if (relationshipTailDataMenuDTO.Items.Any(x => x.Path == parentDataLinkItem.TailPath))
                        {
                            parentDataLinkItem.DataMenuID = relationshipTailDataMenuDTO.Items.First(x => x.Path == parentDataLinkItem.TailPath).DataMenuSettingID;
                        }
                    }
                }
                if (searchResult.Result == Enum_DR_ResultType.SeccessfullyDone)
                {
                    foreach (var item in searchResult.ResultDataItems)
                    {
                        DataLinkItem found = null;
                        if (allItems == null)
                        {
                            allItems = new List <DataLinkItem>();
                        }
                        else
                        {
                            if (selectedDataLink.NotJointEntities == true)
                            {
                                if (allItems.Any(x => AgentHelper.DataItemsAreEqual(item, x.DataItem)))
                                {
                                    var fItem = allItems.First(x => AgentHelper.DataItemsAreEqual(item, x.DataItem));
                                    found = fItem;
                                }
                            }
                        }
                        if (found == null)
                        {
                            found          = new DataLinkItem();
                            found.DataItem = item;
                            found.Level    = level;

                            result.Items.Add(found);
                            allItems.Add(found);
                        }
                        if (parentDataLinkItem != null)
                        {
                            result.Relations.Add(new DataLinkRelation(parentDataLinkItem, found));
                        }

                        GetIncludedDataLinkItems(relationshipTail.ChildTail, selectedDataLink, item, targetData, level + 1, relationshipTailDataMenuDTO, found, result);
                    }
                }
                else
                {
                    AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo(searchResult.Message, searchResult.Details, MyUILibrary.Temp.InfoColor.Red);
                }
            }
            return(result);
        }
        //AssignedPermissionDTO _Permission;
        //public AssignedPermissionDTO Permission
        //{
        //    get
        //    {
        //        if (_Permission == null)
        //            _Permission = AgentUICoreMediator.GetAgentUICoreMediator.SecurityHelper.GetAssignedPermissions(AgentUICoreMediator.GetAgentUICoreMediator.GetRequester(), AreaInitializer.EntityID, false);
        //        return _Permission;
        //    }
        //}
        //private void ManageSecurity()
        //{
        //    if (Permission.GrantedActions.Any(x => x == SecurityAction.NoAccess))
        //    {
        //        SecurityNoAccess = true;
        //    }
        //    else
        //    {
        //        if (Permission.GrantedActions.Any(x => x == SecurityAction.EditAndDelete || x == SecurityAction.Edit))
        //        {
        //            SecurityEdit = true;
        //        }
        //        else if (Permission.GrantedActions.Any(x => x == SecurityAction.ReadOnly))
        //        {
        //            SecurityReadonly = true;
        //        }
        //        else
        //            SecurityNoAccess = true;
        //    }
        //    ImposeSecurity();
        //}

        //private void ImposeSecurity()
        //{
        //    if (SecurityNoAccess)
        //    {
        //        View = null;
        //        AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo("عدم دسترسی به آرشیو");
        //    }
        //    else
        //    {
        //        if (!SecurityReadonly && !SecurityEdit)
        //        {
        //            View = null;
        //            AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo("عدم دسترسی به آرشیو");

        //        }
        //    }
        //}
        //private void View_DataLinkChanged(object sender, EventArgs e)
        //{

        //}

        private void SetDataLink(int dataLinkID)
        {
            SelectedDataLink = AgentUICoreMediator.GetAgentUICoreMediator.DataLinkManager.GetDataLink(AgentUICoreMediator.GetAgentUICoreMediator.GetRequester(), dataLinkID);
            View.ClearEntityViews();
            if (SelectedDataLink != null)
            {
                EditEntityAreaInitializer editEntityAreaInitializer1 = new EditEntityAreaInitializer();
                editEntityAreaInitializer1.EntityID      = SelectedDataLink.TableDrivedEntityID;
                editEntityAreaInitializer1.IntracionMode = CommonDefinitions.UISettings.IntracionMode.Select;
                editEntityAreaInitializer1.DataMode      = CommonDefinitions.UISettings.DataMode.One;
                var FirstSideEditEntityAreaResult = EditEntityAreaConstructor.GetEditEntityArea(editEntityAreaInitializer1);
                if (FirstSideEditEntityAreaResult.Item1 != null)
                {
                    FirstSideEditEntityArea = FirstSideEditEntityAreaResult.Item1 as I_EditEntityAreaOneData;
                    FirstSideEditEntityArea.SetAreaInitializer(editEntityAreaInitializer1);
                    View.SetFirstSideEntityView(FirstSideEditEntityArea.TemporaryDisplayView, FirstSideEditEntityArea.SimpleEntity.Alias);
                }
                else
                {
                    if (!string.IsNullOrEmpty(FirstSideEditEntityAreaResult.Item2))
                    {
                        AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowMessage(FirstSideEditEntityAreaResult.Item2);
                    }
                    return;
                }
                EditEntityAreaInitializer editEntityAreaInitializer2 = new EditEntityAreaInitializer();
                editEntityAreaInitializer2.EntityID      = SelectedDataLink.SecondSideEntityID;
                editEntityAreaInitializer2.IntracionMode = CommonDefinitions.UISettings.IntracionMode.Select;
                editEntityAreaInitializer2.DataMode      = CommonDefinitions.UISettings.DataMode.One;
                var SecondSideEditEntityAreaResult = EditEntityAreaConstructor.GetEditEntityArea(editEntityAreaInitializer2);
                if (SecondSideEditEntityAreaResult.Item1 != null)
                {
                    SecondSideEditEntityArea = SecondSideEditEntityAreaResult.Item1 as I_EditEntityAreaOneData;
                    SecondSideEditEntityArea.SetAreaInitializer(editEntityAreaInitializer2);
                    View.SetSecondSideEntityView(SecondSideEditEntityArea.TemporaryDisplayView, SecondSideEditEntityArea.SimpleEntity.Alias);
                }
                else
                {
                    return;
                }
                bool firstDataSetToFirst  = false;
                bool firstDataSetToSecond = false;
                if (FirstData != null)
                {
                    if (SelectedDataLink.TableDrivedEntityID == FirstData.TargetEntityID)
                    {
                        FirstSideEditEntityArea.ClearData(false);
                        FirstSideEditEntityArea.ShowDataFromExternalSource(FirstData);
                        firstDataSetToFirst = true;
                    }
                    else if (SelectedDataLink.SecondSideEntityID == FirstData.TargetEntityID)
                    {
                        SecondSideEditEntityArea.ClearData(false);
                        SecondSideEditEntityArea.ShowDataFromExternalSource(FirstData);
                        firstDataSetToSecond = true;
                    }
                }
                if (OtherData != null)
                {
                    if (!firstDataSetToFirst && SelectedDataLink.TableDrivedEntityID == OtherData.TargetEntityID)
                    {
                        FirstSideEditEntityArea.ClearData(false);
                        FirstSideEditEntityArea.ShowDataFromExternalSource(OtherData);
                    }
                    else if (!firstDataSetToSecond && SelectedDataLink.SecondSideEntityID == OtherData.TargetEntityID)
                    {
                        SecondSideEditEntityArea.ClearData(false);
                        SecondSideEditEntityArea.ShowDataFromExternalSource(OtherData);
                    }
                }
            }
        }
        public int UpdateDataLink(DataLinkDTO message)
        {
            using (var projectContext = new DataAccess.MyProjectEntities())
            {
                BizEntityDataItemReport bizEntityDataItemReport = new BizEntityDataItemReport();

                var dbEntity = projectContext.DataLinkDefinition.FirstOrDefault(x => x.ID == message.ID);
                if (dbEntity == null)
                {
                    message.ReportType            = ReportType.DataItemReport;
                    dbEntity                      = new DataLinkDefinition();
                    dbEntity.EntityDataItemReport = bizEntityDataItemReport.ToNewEntityDataItemReport(message);
                    dbEntity.EntityDataItemReport.DataItemReportType = (short)DataItemReportType.DataLinkReport;
                }
                else
                {
                    bizEntityDataItemReport.ToUpdateEntityDataItemReport(dbEntity.EntityDataItemReport, message);
                }

                dbEntity.SecondSideEntityID = message.SecondSideEntityID;
                dbEntity.NotJointEntities   = message.NotJointEntities;

                if (message.FirstSideDataMenuID != 0)
                {
                    dbEntity.FirstSideDataMenuID = message.FirstSideDataMenuID;
                }
                else
                {
                    dbEntity.FirstSideDataMenuID = null;
                }
                if (message.SecondSideDataMenuID != 0)
                {
                    dbEntity.SecondSideDataMenuID = message.SecondSideDataMenuID;
                }
                else
                {
                    dbEntity.SecondSideDataMenuID = null;
                }

                while (dbEntity.DataLinkDefinition_EntityRelationshipTail.Any())
                {
                    projectContext.DataLinkDefinition_EntityRelationshipTail.Remove(dbEntity.DataLinkDefinition_EntityRelationshipTail.First());
                }
                foreach (var item in message.RelationshipsTails)
                {
                    var dbRel = new DataLinkDefinition_EntityRelationshipTail();
                    dbRel.EntityRelationshipTailID = item.RelationshipTailID;
                    if (item.EntityRelationshipTailDataMenuID != 0)
                    {
                        dbRel.EntityRelationshipTailDataMenuID = item.EntityRelationshipTailDataMenuID;
                    }
                    //   dbRel.FromFirstSideToSecondSide = item.FromFirstSideToSecondSide;
                    dbEntity.DataLinkDefinition_EntityRelationshipTail.Add(dbRel);
                }

                if (dbEntity.ID == 0)
                {
                    projectContext.DataLinkDefinition.Add(dbEntity);
                }

                try
                {
                    projectContext.SaveChanges();
                }
                catch (DbUpdateException e)
                {
                    throw e;
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
                catch (Exception ex)
                {
                    //result.Result = Enum_DR_ResultType.ExceptionThrown;
                    //result.Message = "خطا در ثبت" + Environment.NewLine + ex.Message;
                }
                return(dbEntity.ID);
            }
        }