Beispiel #1
0
        //private void RelatedDataColumnValueChanged(object sender, RelatedDataColumnValueChangedArg e, FormulaDTO formula, DP_DataRepository dataItem, int columnID)
        //{

        //}


        public void CalculateProperty(EntityInstanceProperty dataProperty, ColumnCustomFormulaDTO columnCustomFormula, DP_DataRepository dataItem, bool asDefault)
        {
            var key = "formulaCalculated" + "_" + dataProperty.ColumnID;

            EditArea.RemoveDataItemMessage(dataItem, key);

            if (columnCustomFormula.OnlyOnNewData)
            {
                if (!dataItem.IsNewItem)
                {
                    AddDataMessageItem(dataItem, key, ControlItemPriority.Normal, "فرمول" + " " + columnCustomFormula.Formula.Name + " " + "بروی داده موجود اعمال نمی شود");
                    return;
                }
            }
            if (columnCustomFormula.OnlyOnEmptyValue)
            {
                if (dataProperty.Value != null && !string.IsNullOrEmpty(dataProperty.Value.ToString()))
                {
                    AddDataMessageItem(dataItem, key, ControlItemPriority.Normal, "فرمول" + " " + columnCustomFormula.Formula.Name + " " + "بروی خصوصیت دارای مقدار اعمال نمی شود");
                    return;
                }
            }


            var result = AgentUICoreMediator.GetAgentUICoreMediator.formulaManager.CalculateFormula(columnCustomFormula.Formula.ID, dataItem, AgentUICoreMediator.GetAgentUICoreMediator.GetRequester());

            dataProperty.FormulaID              = columnCustomFormula.Formula.ID;
            dataProperty.FormulaException       = null;
            dataProperty.FormulaUsageParemeters = result.FormulaUsageParemeters;


            if (result.Exception == null)
            {
                //dataProperty.Value = result.Result;

                //    AddDataMessageItem(dataItem, key, ControlItemPriority.Normal, "محاسبه شده توسط فرمول" + " " + columnCustomFormula.Formula.Title);
            }
            else
            {
                dataProperty.FormulaException = result.Exception.Message;
                //  dataProperty.Value = "";

                //اینجا خطا روی ستون یا رابطه بدهد
                AddDataMessageItem(dataItem, key, ControlItemPriority.Normal, "خطا در محاسبه فرمول" + " " + columnCustomFormula.Formula.Title + ":" + " " + dataProperty.FormulaException);
            }

            if (asDefault)
            {
                dataProperty.Value = result.Result;
            }
            else
            {
                var uiColumnValue = new UIColumnValueDTO();
                uiColumnValue.ColumnID = columnCustomFormula.ID;
                //ابجکت نشه؟ExactValue
                uiColumnValue.ExactValue   = result.Result.ToString();
                uiColumnValue.EvenHasValue = !columnCustomFormula.OnlyOnEmptyValue;
                uiColumnValue.EvenIsNotNew = !columnCustomFormula.OnlyOnNewData;
                List <UIColumnValueDTO> uIColumnValues = new List <UIColumnValueDTO>()
                {
                    uiColumnValue
                };
                EditArea.SetColumnValueFromState(dataItem, uIColumnValues, null, columnCustomFormula.Formula);
            }
        }
Beispiel #2
0
 private string FetchTypePropertyControlValue(DP_DataRepository dataRepository, SimpleViewColumnControl typePropertyControl)
 {
     return(null);
     //////return typePropertyControl.ControlPackage.BaseControlHelper.GetValue(typePropertyControl.ControlPackage);
 }
        public FunctionResult GetCodeFunctionResult(DR_Requester resuester, int codeFunctionID, DP_DataRepository dataItem)
        {
            var parameters   = new List <object>();
            var codeFunction = bizCodeFunction.GetCodeFunction(resuester, codeFunctionID);

            parameters.Add(new CodeFunctionParamOneDataItem(dataItem, resuester));
            return(GetCodeFunctionResult(codeFunction, parameters));
        }
        public object GetValueSomeHow(DR_Requester requester, DP_DataRepository sentdata, EntityRelationshipTailDTO valueRelationshipTail, int valueColumnID, bool firstIfMultiple = false)
        {
            if (valueRelationshipTail == null)
            {
                var proprty = sentdata.GetProperty(valueColumnID);
                return(proprty?.Value);
            }
            else
            {
                DP_DataRepository relatedData = null;
                if (sentdata.ParantChildRelationshipInfo != null && sentdata.ParantChildRelationshipInfo.Relationship.PairRelationshipID == valueRelationshipTail.Relationship.ID)
                {
                    if (sentdata.ParantChildRelationshipInfo.Relationship.PairRelationshipID == valueRelationshipTail.Relationship.ID)
                    {
                        relatedData = sentdata.ParantChildRelationshipInfo.SourceData;
                    }
                }
                else if (sentdata.ChildRelationshipInfos.Any(x => x.Relationship.ID == valueRelationshipTail.Relationship.ID))
                {
                    var childInfo = sentdata.ChildRelationshipInfos.First(x => x.Relationship.ID == valueRelationshipTail.Relationship.ID);
                    if (childInfo.RelatedData.Count > 1)
                    {
                        if (firstIfMultiple)
                        {
                            relatedData = childInfo.RelatedData.First();
                        }
                        else
                        {
                            throw new Exception("asav");
                        }
                    }
                    else if (childInfo.RelatedData.Count == 1)
                    {
                        relatedData = childInfo.RelatedData.First();
                    }
                    else if (childInfo.RelatedData.Count == 0)
                    {
                        //یعنی یا داده مرتبطی وجود نداشته یا حذف شده
                        return("");
                    }
                }
                if (relatedData != null)
                {
                    return(GetValueSomeHow(requester, relatedData, valueRelationshipTail.ChildTail, valueColumnID, firstIfMultiple));
                }
                else
                {
                    //var columnValues = sentdata.KeyProperties;
                    //if (columnValues == null || columnValues.Count == 0)
                    //    throw new Exception("asasd");

                    //سکوریتی داده اعمال میشود
                    //  var requester = AgentUICoreMediator.GetAgentUICoreMediator.GetRequester();

                    //این شرط منطقیه؟؟
                    if (!sentdata.IsNewItem)
                    {
                        var relationshipTailDataManager  = new RelationshipTailDataManager();
                        var searchDataTuple              = relationshipTailDataManager.GetTargetSearchItemFromRelationshipTail(sentdata, valueRelationshipTail);
                        DR_SearchFullDataRequest request = new DR_SearchFullDataRequest(requester, searchDataTuple);
                        var searchResult = new SearchRequestManager().Process(request);
                        if (searchResult.ResultDataItems.Count > 1)
                        {
                            throw new Exception("asdasd");
                        }
                        else if (searchResult.ResultDataItems.Count == 1)
                        {
                            var foundDataItem = searchResult.ResultDataItems.First();
                            var prop          = foundDataItem.GetProperty(valueColumnID);
                            if (prop != null)
                            {
                                return(prop.Value);
                            }
                            else
                            {
                                return("");
                            }
                        }
                        else
                        {
                            return("");
                        }
                    }
                    else
                    {
                        return("");
                    }
                }
            }
            //return "";
        }
Beispiel #5
0
 //FormulaDTO Formula { set; get; }
 public I_ExpressionEvaluator GetExpressionEvaluator(DP_DataRepository dataItem, DR_Requester requester, bool definition, List <int> usedFormulaIDs = null)
 {
     return(FormulaInstanceInternalHelper.GetExpressionEvaluator(dataItem, requester, definition, usedFormulaIDs));
 }
        private void ValidateISARelationships(DP_DataRepository data)
        {
            //ایزه ریلیشنهای ساب به سوپر
            foreach (var relationshipControl in EditArea.RelationshipColumnControls)
            {
                var childRel = data.ChildRelationshipInfos.First(x => x.Relationship.ID == relationshipControl.Relationship.ID);
                if (!childRel.IsHidden)
                {
                    if (relationshipControl.Relationship.TypeEnum == Enum_RelationshipType.SubToSuper)
                    {
                        var isaRelationship = (relationshipControl.Relationship as SubToSuperRelationshipDTO).ISARelationship;

                        if (isaRelationship.IsDisjoint)
                        {
                            var superDataItem = childRel.RealData.FirstOrDefault();
                            if (superDataItem != null)
                            {//اگر فول باشد در خود فرمش بررسی خواهد شد
                                if (!superDataItem.IsFullData)
                                {
                                    var superEntity = AgentUICoreMediator.GetAgentUICoreMediator.tableDrivedEntityManagerService.GetFullEntity(AgentUICoreMediator.GetAgentUICoreMediator.GetRequester(), relationshipControl.EditNdTypeArea.AreaInitializer.EntityID);
                                    var otherSuperToSubRelationships = superEntity.Relationships.Where(x => x is SuperToSubRelationshipDTO && (x as SuperToSubRelationshipDTO).ISARelationship.ID == isaRelationship.ID &&
                                                                                                       (x as SuperToSubRelationshipDTO).ID != relationshipControl.Relationship.PairRelationshipID);
                                    bool moreThanOneData = false;
                                    foreach (var otherSuperToSubRelationship in otherSuperToSubRelationships)
                                    {
                                        var requester = AgentUICoreMediator.GetAgentUICoreMediator.GetRequester();
                                        requester.SkipSecurity = true;
                                        DR_SearchViewRequest request = new DR_SearchViewRequest(requester, AgentUICoreMediator.GetAgentUICoreMediator.RelationshipDataManager.GetSecondSideSearchDataItemByRelationship(superDataItem, otherSuperToSubRelationship.ID));

                                        var otherSideData = AgentUICoreMediator.GetAgentUICoreMediator.requestRegistration.SendSearchViewRequest(request).ResultDataItems;
                                        if (otherSideData.Any())
                                        {
                                            moreThanOneData = true;
                                            break;
                                        }
                                    }
                                    if (moreThanOneData)
                                    {
                                        string relationshipNames = relationshipControl.Relationship.Entity1;
                                        foreach (var otherSuperToSubRelationship in otherSuperToSubRelationships)
                                        {
                                            relationshipNames += (relationshipNames == "" ? "" : ",") + otherSuperToSubRelationship.Entity2;
                                        }
                                        string message = "تنها یکی از";
                                        message += " " + (otherSuperToSubRelationships.Count() + 1) + " " + "رابطه" + " " + relationshipNames + " " + "با" + " " + relationshipControl.Relationship.Entity2 + " " + "ورود اطلاعات شود";

                                        AddColumnControlValidationMessage(relationshipControl, message, data);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //ایزه ریلیشنهای سوپر به ساب

            int    parentISARelationshipID        = 0;
            int    parentSubToSuperRelationshipID = 0;
            string parentSubToSuperName           = "";

            if (EditArea.AreaInitializer.SourceRelationColumnControl != null && EditArea.AreaInitializer.SourceRelationColumnControl.Relationship is SubToSuperRelationshipDTO)
            {
                parentSubToSuperRelationshipID = (EditArea.AreaInitializer.SourceRelationColumnControl.Relationship as SubToSuperRelationshipDTO).ID;
                parentSubToSuperName           = (EditArea.AreaInitializer.SourceRelationColumnControl.Relationship as SubToSuperRelationshipDTO).Entity1;
                parentISARelationshipID        = (EditArea.AreaInitializer.SourceRelationColumnControl.Relationship as SubToSuperRelationshipDTO).ISARelationship.ID;
            }
            List <Tuple <ISARelationshipDTO, List <RelationshipColumnControl> > > isaRelationships = new List <Tuple <ISARelationshipDTO, List <RelationshipColumnControl> > >();

            foreach (var relationshipControl in EditArea.RelationshipColumnControls)
            {
                var childRel = data.ChildRelationshipInfos.First(x => x.Relationship.ID == relationshipControl.Relationship.ID);
                if (!childRel.IsHidden)
                {
                    if (relationshipControl.Relationship.TypeEnum == Enum_RelationshipType.SuperToSub)
                    {
                        var isaID = (relationshipControl.Relationship as SuperToSubRelationshipDTO).ISARelationship.ID;
                        Tuple <ISARelationshipDTO, List <RelationshipColumnControl> > isaRelationship = null;
                        if (!isaRelationships.Any(x => x.Item1.ID == isaID))
                        {
                            isaRelationship = new Tuple <ISARelationshipDTO, List <RelationshipColumnControl> >((relationshipControl.Relationship as SuperToSubRelationshipDTO).ISARelationship, new List <RelationshipColumnControl>());
                            isaRelationships.Add(isaRelationship);
                        }
                        else
                        {
                            isaRelationship = isaRelationships.First(x => x.Item1.ID == isaID);
                        }
                        isaRelationship.Item2.Add(relationshipControl);
                        //}
                    }
                }
            }

            foreach (var isaRelationship in isaRelationships)
            {
                if (isaRelationship.Item1.IsTolatParticipation)
                {
                    //اگه از پرنت ساب باشه بنابراین خودش یک رابطه با داده فرض میشود
                    if (isaRelationship.Item1.ID != parentISARelationshipID)
                    {
                        bool hasData = false;
                        foreach (var relationshipControl in isaRelationship.Item2)
                        {
                            var childRelationshipInfo = data.ChildRelationshipInfos.First(x => x.Relationship.ID == relationshipControl.Relationship.ID);
                            //این بود بررسی شود  if (childRelationshipInfo.RelatedData.Any(x => x.HasDirectData))
                            if (childRelationshipInfo.RealData.Any())
                            {
                                hasData = true;
                            }
                        }
                        if (!hasData)
                        {
                            string relationshipNames = "";
                            foreach (var relationshipControl in isaRelationship.Item2)
                            {
                                relationshipNames += (relationshipNames == "" ? "" : ",") + relationshipControl.Relationship.Entity2;
                            }
                            string message = "";
                            if (isaRelationship.Item1.IsDisjoint)
                            {
                                message = "یکی از";
                            }
                            else
                            {
                                message = "حداقل یکی از";
                            }
                            message += " " + isaRelationship.Item2.Count + " " + "رابطه" + " " + relationshipNames + " " + "می بایست ورود اطلاعات شود";
                            foreach (var relationshipControl in isaRelationship.Item2)
                            {
                                AddColumnControlValidationMessage(relationshipControl, message, data);
                            }
                        }
                    }
                }

                if (isaRelationship.Item1.IsDisjoint)
                {
                    bool moreThanOneData = false;
                    bool hasData         = false;
                    if (isaRelationship.Item1.ID == parentISARelationshipID)
                    {
                        hasData = true;
                    }
                    foreach (var relationshipControl in isaRelationship.Item2)
                    {
                        var childRelationshipInfo = data.ChildRelationshipInfos.First(x => x.Relationship.ID == relationshipControl.Relationship.ID);
                        if (childRelationshipInfo.RealData.Any())
                        {
                            if (!hasData)
                            {
                                hasData = true;
                            }
                            else
                            {
                                moreThanOneData = true;
                            }
                        }
                    }
                    if (moreThanOneData)
                    {
                        string relationshipNames = "";
                        if (parentSubToSuperName != "")
                        {
                            relationshipNames = parentSubToSuperName;
                        }
                        foreach (var relationshipControl in isaRelationship.Item2)
                        {
                            relationshipNames += (relationshipNames == "" ? "" : ",") + relationshipControl.Relationship.Entity2;
                        }
                        string message = "تنها یکی از";
                        message += " " + isaRelationship.Item2.Count + " " + "رابطه" + " " + relationshipNames + " " + "با" + " " + EditArea.FullEntity.Name + " " + " " + "ورود اطلاعات شود";
                        foreach (var relationshipControl in isaRelationship.Item2)
                        {
                            AddColumnControlValidationMessage(relationshipControl, message, data);
                        }
                    }
                }
            }
        }
        private void ValidateSimpleColumn(DP_DataRepository dataItem, EntityInstanceProperty dataColumn, SimpleColumnControl simplePropertyControl)
        {
            if (simplePropertyControl.Column.IsMandatory == true)
            {
                if (dataColumn.Value == null || dataColumn.Value.ToString() == "")
                {
                    if (dataItem.IsNewItem == false || simplePropertyControl.Column.IsIdentity == false)
                    {
                        AddColumnControlValidationMessage(simplePropertyControl, "مقدار دهی این خصوصیت اجباری می باشد", dataItem);
                    }
                }
            }
            if (dataColumn.Value != null && dataColumn.Value.ToString() != "")
            {
                if (simplePropertyControl.Column.StringColumnType != null)
                {
                    if (simplePropertyControl.Column.StringColumnType.MaxLength != 0 &&
                        simplePropertyControl.Column.StringColumnType.MaxLength != -1)
                    {
                        if (dataColumn.Value.ToString().Length > simplePropertyControl.Column.StringColumnType.MaxLength)
                        {
                            string message = "حداکثر طول این خصوصیت" + " " + simplePropertyControl.Column.StringColumnType.MaxLength + " " + "کاراکتر می باشد";
                            AddColumnControlValidationMessage(simplePropertyControl, message, dataItem);
                        }
                    }
                    if (simplePropertyControl.Column.StringColumnType.MinLength != 0 &&
                        simplePropertyControl.Column.StringColumnType.MinLength != null)
                    {
                        if (dataColumn.Value.ToString().Length < simplePropertyControl.Column.StringColumnType.MinLength)
                        {
                            string message = "حداقل طول این خصوصیت" + " " + simplePropertyControl.Column.StringColumnType.MinLength + " " + "کاراکتر می باشد";
                            AddColumnControlValidationMessage(simplePropertyControl, message, dataItem);
                        }
                    }
                }

                if (simplePropertyControl.Column.NumericColumnType != null)
                {
                    if (simplePropertyControl.Column.NumericColumnType.MinValue != null)
                    {
                        var value = Convert.ToDouble(dataColumn.Value);
                        if (value < simplePropertyControl.Column.NumericColumnType.MinValue.Value)
                        {
                            string message = "حداقل مقدار این خصوصیت" + " " + simplePropertyControl.Column.NumericColumnType.MinValue.Value + " " + "می باشد";
                            AddColumnControlValidationMessage(simplePropertyControl, message, dataItem);
                        }
                    }
                    if (simplePropertyControl.Column.NumericColumnType.MaxValue != null)
                    {
                        var value = Convert.ToDouble(dataColumn.Value);
                        if (value > simplePropertyControl.Column.NumericColumnType.MaxValue.Value)
                        {
                            string message = "حداکثر مقدار این خصوصیت" + " " + simplePropertyControl.Column.NumericColumnType.MaxValue.Value + " " + "می باشد";
                            AddColumnControlValidationMessage(simplePropertyControl, message, dataItem);
                        }
                    }
                    if (simplePropertyControl.Column.NumericColumnType.Precision != 0)
                    {
                        var value = Convert.ToDouble(dataColumn.Value);
                        if (value.ToString().Replace(".", "").Length > simplePropertyControl.Column.NumericColumnType.Precision)
                        {
                            string message = "تعداد اعداد این خصوصیت از مقدار تعیین شده" + " " + simplePropertyControl.Column.NumericColumnType.Precision + " " + "بیشتر می باشد";
                            AddColumnControlValidationMessage(simplePropertyControl, message, dataItem);
                        }
                    }
                    if (simplePropertyControl.Column.NumericColumnType.Scale != 0)
                    {
                        var value = Convert.ToDouble(dataColumn.Value);
                        if (value.ToString().Contains("."))
                        {
                            var splt = value.ToString().Split('.')[1];
                            if (splt.Length > simplePropertyControl.Column.NumericColumnType.Scale)
                            {
                                string message = "تعداد اعشار این خصوصیت از مقدار تعیین شده" + " " + simplePropertyControl.Column.NumericColumnType.Scale + " " + "بیشتر می باشد";
                                AddColumnControlValidationMessage(simplePropertyControl, message, dataItem);
                            }
                        }
                    }
                }
                if (simplePropertyControl.Column.StringColumnType != null)
                {
                    if (!string.IsNullOrEmpty(simplePropertyControl.Column.StringColumnType.Format))
                    {
                        Regex regex = new Regex(simplePropertyControl.Column.StringColumnType.Format);
                        if (!regex.IsMatch(dataColumn.Value.ToString()))
                        {
                            string message = "فرمت این خصوصیت صحیح نمی باشد";
                            AddColumnControlValidationMessage(simplePropertyControl, message, dataItem);
                        }
                    }
                }



                if (simplePropertyControl.Column.ColumnValueRange != null &&
                    simplePropertyControl.Column.ColumnValueRange.Details.Any())
                {
                    List <ColumnValueRangeDetailsDTO> validValueRange = null;
                    if (dataItem.ColumnKeyValueRanges.Any(x => x.Key == simplePropertyControl.Column.ID && x.Value.Any()))
                    {
                        validValueRange = dataItem.ColumnKeyValueRanges.First(x => x.Key == simplePropertyControl.Column.ID && x.Value.Any()).Value;
                    }
                    else
                    {
                        validValueRange = simplePropertyControl.Column.ColumnValueRange.Details;
                    }
                    //if (simplePropertyControl.Column.ColumnValueRange.ValueFromTitleOrValue)
                    //{
                    //    if (!validValueRange.Any(x => x.KeyTitle == dataColumn.Value))
                    //    {
                    //        string message = "مقدار این خصوصیت در لیست مقادیر مجاز نمی باشد";
                    //        AddColumnControlValidationMessage(simplePropertyControl, message, dataItem);
                    //    }
                    //}
                    //else
                    //{
                    if (!validValueRange.Any(x => x.Value == dataColumn.Value.ToString()))
                    {
                        string message = "مقدار این خصوصیت در لیست مقادیر مجاز نمی باشد";
                        AddColumnControlValidationMessage(simplePropertyControl, message, dataItem);
                    }
                    //}
                }
            }
        }
 public EditQueryPreItem(DP_DataRepository dataItem)
 {
     DataItem = dataItem;
 }
Beispiel #9
0
        private Tuple <Enum_QueryItemType, List <EntityInstanceProperty> > GetQueryDeleteOrUpdateNull(DP_DataRepository item, ChildRelationshipInfo parentChildRelatoinshipInfo)
        {
            Enum_QueryItemType            queryItemType;
            List <EntityInstanceProperty> listEditProperties = new List <EntityInstanceProperty>();

            if (parentChildRelatoinshipInfo == null)
            {
                queryItemType = Enum_QueryItemType.Delete;
            }
            else
            {
                if (parentChildRelatoinshipInfo.RelationshipDeleteOption == RelationshipDeleteOption.DeleteCascade)
                {
                    queryItemType = Enum_QueryItemType.Delete;
                }
                else
                {
                    queryItemType = Enum_QueryItemType.Update;

                    foreach (var col in parentChildRelatoinshipInfo.Relationship.RelationshipColumns)
                    {
                        var prop = item.GetProperty(col.SecondSideColumnID);
                        if (prop == null)
                        {
                            prop = new EntityInstanceProperty(col.SecondSideColumn);
                        }
                        prop.Value = null;
                        listEditProperties.Add(prop);
                    }
                }
            }
            return(new Tuple <Enum_QueryItemType, List <EntityInstanceProperty> >(queryItemType, listEditProperties));
        }
Beispiel #10
0
 //   public event PropertyChangedEventHandler PropertyChanged;
 public FormulaDefinitionInstance(DR_Requester requester, DP_DataRepository mainObject, TableDrivedEntityDTO mainEntity)
 {
     Requester = requester;
     SetMainFormulaObject(mainObject, mainEntity);
 }
Beispiel #11
0
        public void SelectFromParent(bool isCalledFromDataView, RelationshipDTO relationship, DP_DataRepository parentDataItem, Dictionary <int, string> colAndValues)
        {
            IsCalledFromDataView = isCalledFromDataView;
            DP_SearchRepository searchItems = new DP_SearchRepository(AreaInitializer.EntityID);

            foreach (var item in relationship.RelationshipColumns)
            {
                if (colAndValues.ContainsKey(item.FirstSideColumnID))
                {
                    searchItems.Phrases.Add(new SearchProperty()
                    {
                        ColumnID = item.SecondSideColumnID, Value = colAndValues[item.FirstSideColumnID]
                    });
                }
            }
            SearchConfirmed(searchItems, true);
        }
Beispiel #12
0
        private bool GetConditionResult(EntityStateConditionDTO condition, DP_DataRepository mainDataItem, DR_Requester requester)
        {
            bool result = false;
            bool securitySubjectIsOk = false;

            if (condition.SecuritySubjects.Any())
            {
                bool hasAnyOfSubjects = false;
                foreach (var subject in condition.SecuritySubjects)
                {
                    foreach (var post in requester.Posts)
                    {
                        if (post.CurrentUserID == subject.SecuritySubjectID ||
                            post.ID == subject.SecuritySubjectID ||
                            post.OrganizationID == subject.SecuritySubjectID ||
                            post.OrganizationTypeID == subject.SecuritySubjectID ||
                            post.OrganizationTypeRoleTypeID == subject.SecuritySubjectID ||
                            post.RoleTypeID == subject.SecuritySubjectID
                            )
                        {
                            hasAnyOfSubjects = true;
                        }
                    }
                }

                if (condition.SecuritySubjectInORNotIn == InORNotIn.In)
                {
                    securitySubjectIsOk = hasAnyOfSubjects == true;
                }
                else
                {
                    securitySubjectIsOk = hasAnyOfSubjects == false;
                }
            }
            else
            {
                securitySubjectIsOk = true;
            }

            if (securitySubjectIsOk)
            {
                if (condition.ColumnID != 0)
                {
                    DataitemRelatedColumnValueHandler dataitemRelatedColumnValueHandler = new MyFormulaFunctionStateFunctionLibrary.DataitemRelatedColumnValueHandler();
                    var value = dataitemRelatedColumnValueHandler.GetValueSomeHow(requester, mainDataItem, condition.RelationshipTail, condition.ColumnID);

                    result = StateHasValue(requester, condition, value);
                }
                else if (condition.FormulaID != 0)
                {
                    FormulaFunctionHandler FormulaFunctionHandler = new FormulaFunctionHandler();
                    var value = FormulaFunctionHandler.CalculateFormula(condition.FormulaID, mainDataItem, requester);
                    result = StateHasValue(requester, condition, value.Result);
                }
                else
                {
                    result = securitySubjectIsOk;
                }
            }
            return(result);
        }
        private DP_DataRepository GetData(DP_DataRepository item)
        {
            DP_DataRepository newItem = new DP_DataRepository(item.TargetEntityID, item.TargetEntityAlias);

            foreach (var property in item.GetProperties())
            {
                if (!property.IsHidden && (property.IsKey || !property.ISFK))
                {
                    var originalProperty = item.OriginalProperties.First(x => x.ColumnID == property.ColumnID);
                    var newProperty      = newItem.AddCopyProperty(property);
                    newItem.OriginalProperties.Add(originalProperty);
                    if (property.IsReadonly)
                    {
                        newProperty.Value = originalProperty.Value;
                    }
                }
            }
            newItem.IsFullData = item.IsFullData;
            newItem.DataView   = item.DataView;
            //   newItem.HasDirectData = item.HasDirectData;
            newItem.IsDBRelationship = item.IsDBRelationship;

            //newItem.IsHiddenBecauseOfCreatorRelationshipOnShow = item.IsHiddenBecauseOfCreatorRelationshipOnShow;
            newItem.IsHiddenBecauseOfCreatorRelationshipOnState   = item.IsHiddenBecauseOfCreatorRelationshipOnState;
            newItem.IsReadonlyBecauseOfCreatorRelationshipOnShow  = item.IsReadonlyBecauseOfCreatorRelationshipOnShow;
            newItem.IsReadonlyBecauseOfCreatorRelationshipOnState = item.IsReadonlyBecauseOfCreatorRelationshipOnState;
            newItem.IsReadonlyBecauseOfState = item.IsReadonlyBecauseOfState;
            newItem.EntityListView           = item.EntityListView;
            newItem.IsNewItem = item.IsNewItem;
            // newItem.ParantChildRelationshipInfo = newParentChildRelationshipInfo;

            foreach (var childItem in item.ChildRelationshipInfos)
            {
                //مطمئنن رابطه فارن به پرایمری هست وقتی که هیدن یا ریدونلی ترو باشه
                // bool skipChildRel = false;
                //if (childItem.Relationship.MastertTypeEnum == Enum_MasterRelationshipType.FromForeignToPrimary)
                //{
                //   if (childItem.IsHidden)
                //    skipChildRel = true;
                //////else if ((childItem.Relationship.IsReadonly || childItem.IsReadonly) && childItem.CheckRelationshipIsChanged())
                //////    skipChildRel = true;
                //}
                if (!childItem.IsHidden)
                {
                    var newChildItems = new ChildRelationshipInfo();
                    newChildItems.Relationship = childItem.Relationship;

                    newChildItems.RelationshipDeleteOption = childItem.RelationshipDeleteOption;
                    foreach (var orginalData in childItem.OriginalRelatedData)
                    {
                        //if (childItem.Relationship.MastertTypeEnum == Enum_MasterRelationshipType.FromPrimartyToForeign)
                        //{
                        newChildItems.OriginalRelatedData.Add(orginalData);
                    }
                    foreach (var orginalData in childItem.RemovedOriginalDatas)
                    {
                        //bool skipOriginalData = false;

                        //برای وقتی که شرط داده اجازه حذف میداده و داده حذف شده اما قبل از آپد یت دیگه شرط اجازه حذف را به علت هیدن یا ریدونلی بودن نمیده
                        if (orginalData.IsHiddenBecauseOfCreatorRelationshipOnState || childItem.IsReadonly || orginalData.IsReadonlySomeHow

                            )
                        {
                        }
                        else
                        {
                            newChildItems.RemovedDataForUpdate.Add(orginalData);
                        }

                        //else
                        //{
                        //    var relatedDataToOriginalData = childItem.GetRelatedDataOfOriginalData(orginalData);
                        //    if (relatedDataToOriginalData.IsHiddenBecauseOfCreatorRelationshipOnState)
                        //        skipOriginalData = true;
                        //}
                        //if (!skipOriginalData)
                        //    newChildItems.RemovedDataForUpdate.Add(orginalData);
                        //}
                        //else
                        //{
                        //    newChildItems.OriginalRelatedData.Add(orginalData);
                        //}
                    }

                    var relatedData = childItem.RelatedData.ToList();
                    foreach (var ritem in relatedData)
                    {
                        if (ritem.ShoudBeCounted)
                        {
                            newChildItems.RelatedData.Add(GetData(ritem));
                        }
                    }
                    //var childDataItems = GetData(childItem, newChildItems);
                    //foreach (var cItem in childDataItems)
                    //    newChildItems.RelatedData.Add(cItem);

                    //  newChildItems.CheckAddedRemovedRelationships();
                    newItem.ChildRelationshipInfos.Add(newChildItems);
                }

                //  }
            }

            return(newItem);
        }
        public List <WorkflowRequestDTO> SearchWorkflows(DR_Requester requester, int processID, DateTime?fromData, DateTime?toDate, DP_DataRepository data, WFStateDTO currentState, WFStateDTO historyState, TransitionActionDTO selectedAction, int userID)
        {
            BizRequest bizRequest = new BizRequest();

            return(bizRequest.SearchWorkflows(requester, processID, fromData, toDate, data, currentState, historyState, selectedAction, userID));
        }
        public ChildRelationshipInfo SerachDataFromParentRelationForChildTempView(RelationshipDTO relationship, I_EditEntityArea sourceEditEntityArea, I_EditEntityArea targetEditEntityArea, DP_DataRepository parentRelationData)
        {
            //List<DP_DataRepository> re = null;
            //if (parentRelationData.ChildRelationshipInfos.Any(x => x.Relationship.ID == relationshipID))
            //{
            //    childViewData = new List<DP_DataView>();
            //    foreach (var child in parentRelationData.ChildRelationshipInfos.First(x => x.Relationship.ID == relationshipID).RelatedData)
            //        childViewData.Add(child.DataView);
            //}
            //else
            //{
            ChildRelationshipInfo childRelationshipInfo = null;

            childRelationshipInfo = parentRelationData.ChildRelationshipInfos.FirstOrDefault(x => x.Relationship.ID == relationship.ID);
            if (childRelationshipInfo == null)
            {
                childRelationshipInfo = parentRelationData.AddChildRelationshipInfo(relationship);
            }
            else
            {
                throw new Exception("Asd");
            }

            List <DP_DataRepository> result = new List <DP_DataRepository>();
            var searchDataItem = relationshipManager.GetSecondSideSearchDataItemByRelationship(parentRelationData, relationship.ID);


            if (searchDataItem != null)
            {
                var requester = AgentUICoreMediator.GetAgentUICoreMediator.GetRequester();
                DR_SearchViewRequest request = new DR_SearchViewRequest(requester, searchDataItem);
                if (targetEditEntityArea.DefaultEntityListViewDTO != null)
                {
                    request.EntityViewID = targetEditEntityArea.DefaultEntityListViewDTO.ID;
                }
                var childViewData = AgentUICoreMediator.GetAgentUICoreMediator.requestRegistration.SendSearchViewRequest(request).ResultDataItems;

                var countRequest = new DR_SearchCountRequest(requester);
                countRequest.SearchDataItems        = searchDataItem;
                countRequest.Requester.SkipSecurity = true;
                var  count            = AgentUICoreMediator.GetAgentUICoreMediator.requestRegistration.SendSearchCountRequest(countRequest);
                bool secutrityImposed = false;
                if (count.ResultCount != childViewData.Count)
                {
                    secutrityImposed = true;
                }
                if (!secutrityImposed)
                {
                    foreach (var item in childViewData)
                    {
                        var dpItem = ConvertDP_DataViewToDP_DataRepository(item, targetEditEntityArea);
                        result.Add(dpItem);
                        dpItem.IsDBRelationship = true;
                        childRelationshipInfo.AddDataToChildRelationshipInfo(dpItem, true);
                    }
                }
                else
                {
                    childRelationshipInfo.SecurityIssue = true;
                }
            }
            //}
            return(childRelationshipInfo);
        }
Beispiel #16
0
        public bool GetTreeItems(DR_Requester requester, DP_DataRepository deleteDataItem, DP_DataRepository rootDeleteItem)
        {
            List <ChildRelationshipInfo> result = new List <ChildRelationshipInfo>();
            bool loop = false;
            //   DP_DataRepository resultItem = item;
            var entity = bizTableDrivedEntity.GetTableDrivedEntity(requester, deleteDataItem.TargetEntityID, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithRelationships);

            foreach (var relationship in entity.Relationships.Where(x => x.MastertTypeEnum == Enum_MasterRelationshipType.FromPrimartyToForeign))
            {
                if (!loop)

                {
                    var searchRepository = RelationshipDataManager.GetSecondSideSearchDataItemByRelationship(deleteDataItem, relationship.ID);
                    var newrequester     = new DR_Requester();
                    newrequester.SkipSecurity = true;
                    DR_SearchViewRequest searchViewRequest = new DR_SearchViewRequest(newrequester, searchRepository);
                    var searchViewResult = SearchRequestManager.Process(searchViewRequest);
                    if (searchViewResult.ResultDataItems.Any())
                    {
                        var childRelationshipInfo = new ChildRelationshipInfo();
                        childRelationshipInfo.SourceData   = deleteDataItem;
                        childRelationshipInfo.Relationship = relationship;
                        result.Add(childRelationshipInfo);
                        childRelationshipInfo.RelationshipDeleteOption = relationship.DeleteOption;
                        deleteDataItem.ChildRelationshipInfos.Add(childRelationshipInfo);
                        if (childRelationshipInfo.RelationshipDeleteOption == RelationshipDeleteOption.SetNull)
                        {
                            foreach (var childItem in searchViewResult.ResultDataItems)
                            {
                                DP_DataRepository dataItem = new DP_DataRepository(childItem.TargetEntityID, childItem.TargetEntityAlias);
                                dataItem.DataView = childItem;
                                dataItem.ParantChildRelationshipInfo = childRelationshipInfo;
                                childRelationshipInfo.RelatedData.Add(dataItem);
                            }
                        }
                        else
                        {
                            bool repeatedInParents = false;
                            foreach (var childItem in searchViewResult.ResultDataItems)
                            {//هردفعه پرنتها برای هر ایتم گرفته نشود
                                List <DP_DataRepository> parents = GetParentDataItems(childRelationshipInfo);
                                if (parents.Any(z => z.TargetEntityID == childItem.TargetEntityID && z.KeyProperties.All(x => childItem.Properties.Any(y => y.IsKey && x.ColumnID == y.ColumnID && x.Value == y.Value))))
                                {
                                    var parentRepeted = parents.First(z => z.TargetEntityID == childItem.TargetEntityID && z.KeyProperties.All(x => childItem.Properties.Any(y => y.IsKey && x.ColumnID == y.ColumnID && x.Value == y.Value)));
                                    loop = true;
                                    repeatedInParents = true;
                                    DP_DataRepository dataItem = new DP_DataRepository(childItem.TargetEntityID, childItem.TargetEntityAlias);
                                    dataItem.DataView = childItem;
                                    dataItem.ParantChildRelationshipInfo = childRelationshipInfo;
                                    dataItem.Error = "وابستگی تکراری با " + parentRepeted.ViewInfo;
                                    childRelationshipInfo.RelatedData.Add(dataItem);
                                }
                            }
                            if (!repeatedInParents)
                            {
                                foreach (var childItem in searchViewResult.ResultDataItems)
                                {
                                    if (ChildItemExistInTree(rootDeleteItem, childItem))
                                    {
                                    }
                                    else
                                    {
                                        DP_DataRepository dataItem = new DP_DataRepository(childItem.TargetEntityID, childItem.TargetEntityAlias);
                                        dataItem.DataView = childItem;
                                        dataItem.ParantChildRelationshipInfo = childRelationshipInfo;
                                        childRelationshipInfo.RelatedData.Add(dataItem);
                                        var innerloop = GetTreeItems(requester, dataItem, rootDeleteItem);
                                        if (innerloop)
                                        {
                                            loop = true;
                                            return(loop);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(loop);
        }
        /// <summary>
        /// /////////////////////////مشترک
        /// </summary>
        /// <param name="relationshipID"></param>
        /// <param name="editEntityArea"></param>
        /// <param name="parentRelationData"></param>
        /// <returns></returns>
        public ChildRelationshipInfo SerachDataFromParentRelationForChildDataView(RelationshipDTO relationship, I_EditEntityAreaOneData sourceEditEntityArea, I_EditEntityArea targetEditEntityArea, DP_DataRepository parentRelationData)
        {
            var requester = AgentUICoreMediator.GetAgentUICoreMediator.GetRequester();

            ChildRelationshipInfo childRelationshipInfo = null;

            childRelationshipInfo = parentRelationData.ChildRelationshipInfos.FirstOrDefault(x => x.Relationship.ID == relationship.ID);
            if (childRelationshipInfo == null)
            {
                childRelationshipInfo = parentRelationData.AddChildRelationshipInfo(relationship);
            }
            else
            {
                throw new Exception("Asd");
            }

            //سکوریتی داده اعمال میشود

            var searchDataItem = relationshipManager.GetSecondSideSearchDataItemByRelationship(parentRelationData, relationship.ID);

            if (searchDataItem != null)
            {
                // DR_SearchEditRequest request = new DR_SearchEditRequest(requester, searchDataItem, targetEditEntityArea.AreaInitializer.SecurityReadOnly, true);
                DR_SearchEditRequest request = new DR_SearchEditRequest(requester, searchDataItem);
                var childFullData            = AgentUICoreMediator.GetAgentUICoreMediator.requestRegistration.SendSearchEditRequest(request).ResultDataItems;
                var countRequest             = new DR_SearchCountRequest(requester);
                countRequest.SearchDataItems        = searchDataItem;
                countRequest.Requester.SkipSecurity = true;
                var  count            = AgentUICoreMediator.GetAgentUICoreMediator.requestRegistration.SendSearchCountRequest(countRequest);
                bool secutrityImposed = false;
                if (count.ResultCount != childFullData.Count)
                {
                    secutrityImposed = true;
                }


                if (!secutrityImposed)
                {
                    foreach (var data in childFullData)
                    {
                        data.IsDBRelationship = true;
                        data.DataView         = GetDataView(data);
                        childRelationshipInfo.AddDataToChildRelationshipInfo(data, true);
                    }
                }
                else
                {
                    childRelationshipInfo.SecurityIssue = true;
                }
            }
            return(childRelationshipInfo);
            //foreach (var item in childFullData)
            //    searchedData.Add(new Tuple<DP_DataRepository, DP_DataView>(item, null));

            //return AddEditSearchData(searchedData, editEntityArea);
        }
        public override bool TryGetMember(GetMemberBinder binder,
                                          out object result)
        {
            if (m_properties.ContainsKey(binder.Name))
            {
                var property = m_properties.FirstOrDefault(x => x.Key == binder.Name).Value;
                OnProperyCalled(property);
                if (!property.ValueSearched)
                {
                    property.ValueSearched = true;
                    if (Definition)
                    {
                        if (property.PropertyType == PropertyType.Relationship)
                        {
                            var dataItem   = new DP_DataRepository(property.PropertyRelationship.EntityID2, property.PropertyRelationship.Entity2);
                            var entity     = bizTableDrivedEntity.GetPermissionedEntity(Requester, dataItem.TargetEntityID);
                            var properties = FormulaInstanceInternalHelper.GetProperties(Requester, entity, property, Definition);


                            //newObject.PropertyGetCalled += BindableTypeDescriptor_PropertyGetCalled;
                            //newObject.PropertySetChanged += FormulaObject_PropertySetChanged;
                            //newObject.PropertyChanged += FormulaObject_PropertyChanged;
                            if (property.PropertyRelationship.TypeEnum == Enum_RelationshipType.OneToMany)
                            {
                                var newObject = GetCustomSingleData(property, dataItem, Requester, Definition, properties, UsedFormulaIDs);
                                //var list = new List<MyCustomSingleData>();
                                //DataItems.Add(newObject);
                                property.Value = new MyCustomMultipleData(Requester, entity.ID, new List <MyCustomSingleData>()
                                {
                                    newObject
                                });
                            }
                            else
                            {
                                var newObject = GetCustomSingleData(property, dataItem, Requester, Definition, properties, UsedFormulaIDs);
                                property.Value = newObject;
                            }
                        }
                        else
                        {
                            property.Value = GetPropertyDefaultValue(property);
                        }
                    }
                    else
                    {
                        if (property.PropertyType == PropertyType.Relationship)
                        {
                            var entity     = bizTableDrivedEntity.GetPermissionedEntity(Requester, property.PropertyRelationship.EntityID2);
                            var properties = FormulaInstanceInternalHelper.GetProperties(Requester, entity, property, Definition);
                            if (property.PropertyRelationshipProperties == null || property.PropertyRelationshipProperties.Count == 0)
                            {
                                throw new Exception("adasdasd");
                            }
                            List <DP_DataRepository> relatedDataItems = GetRelatedDataItems(DataItem, property.PropertyRelationship, property.PropertyRelationshipProperties);

                            if (property.PropertyRelationship.TypeEnum == Enum_RelationshipType.OneToMany)
                            {
                                var list = new List <MyCustomSingleData>();

                                foreach (var relatedDataItem in relatedDataItems)
                                {
                                    list.Add(GetCustomSingleData(property, relatedDataItem, Requester, Definition, GetCloneProperties(properties), UsedFormulaIDs));
                                }
                                var newObject = new MyCustomMultipleData(Requester, entity.ID, list);
                                //    DataItems.Add(newObject);
                                //    //newObject.PropertyGetCalled += BindableTypeDescriptor_PropertyGetCalled;
                                //}
                                property.Value = newObject;
                            }
                            else if (relatedDataItems.Any())
                            {
                                var newObject = GetCustomSingleData(property, relatedDataItems.First(), Requester, Definition, properties, UsedFormulaIDs);

                                //newObject.PropertyGetCalled += BindableTypeDescriptor_PropertyGetCalled;
                                //newObject.PropertySetChanged += FormulaObject_PropertySetChanged;
                                //newObject.PropertyChanged += FormulaObject_PropertyChanged;
                                property.Value = newObject;
                            }
                        }
                        else
                        {
                            if (property.PropertyType == PropertyType.Column)
                            {
                                EntityInstanceProperty dataproperty = DataItem.GetProperty(property.ID);
                                if (dataproperty != null)
                                {
                                    property.Value = dataproperty.Value;
                                }
                                else
                                {
                                    throw new Exception("Date property" + " " + property.Name + " not found!");
                                }
                            }
                            else if (property.PropertyType == PropertyType.FormulaParameter)
                            {
                                var formula = property.Context as FormulaDTO;
                                if (UsedFormulaIDs != null && UsedFormulaIDs.Contains(formula.ID))
                                {
                                    throw new Exception("Loop");
                                }
                                if (UsedFormulaIDs == null)
                                {
                                    UsedFormulaIDs = new List <int>();
                                }
                                UsedFormulaIDs.Add(formula.ID);
                                Application.Current.Dispatcher.Invoke((Action) delegate
                                {
                                    var value = FormulaFunctionHandler.CalculateFormula(formula.ID, DataItem, Requester, UsedFormulaIDs);
                                    if (value.Exception == null)
                                    {
                                        //if ((property.Context is FormulaDTO) && (property.Context as FormulaDTO).ValueCustomType != ValueCustomType.None)
                                        //    property.Value = GetCustomTypePropertyValue(property, (property.Context as FormulaDTO).ValueCustomType, value.Result);
                                        //else
                                        property.Value = value.Result;
                                        //   e.FormulaUsageParemeters = value.FormulaUsageParemeters;
                                    }
                                    else
                                    {
                                        throw value.Exception;
                                    }
                                });
                            }
                            else if (property.PropertyType == PropertyType.State)
                            {
                                Application.Current.Dispatcher.Invoke((Action) delegate
                                {
                                    DP_DataRepository dataItem = DataItem;

                                    var stateresult = StateHandler.GetStateResult(property.ID, DataItem, Requester);
                                    if (string.IsNullOrEmpty(stateresult.Message))
                                    {
                                        property.Value = stateresult.Result;
                                    }
                                    else
                                    {
                                        throw new Exception(stateresult.Message);
                                    }
                                });
                            }
                            else if (property.PropertyType == PropertyType.Code)
                            {
                                Application.Current.Dispatcher.Invoke((Action) delegate
                                {
                                    DP_DataRepository dataItem = DataItem;

                                    var coderesult = CodeFunctionHandler.GetCodeFunctionResult(Requester, property.ID, dataItem);
                                    if (coderesult.Exception == null)
                                    {
                                        property.Value = coderesult.Result;
                                    }
                                    else
                                    {
                                        throw coderesult.Exception;
                                    }

                                    //if ((property.Context is CodeFunctionDTO) && (property.Context as CodeFunctionDTO).ValueCustomType != ValueCustomType.None)
                                    //    property.Value = GetCustomTypePropertyValue(property, (property.Context as CodeFunctionDTO).ValueCustomType, result.Result);
                                    //else
                                });
                            }
                            else if (property.PropertyType == PropertyType.DBFunction)
                            {
                                Application.Current.Dispatcher.Invoke((Action) delegate
                                {
                                    DP_DataRepository dataItem = DataItem;

                                    var coderesult = DatabaseFunctionHandler.GetDatabaseFunctionValue(Requester, property.ID, dataItem);
                                    if (coderesult.Exception == null)
                                    {
                                        property.Value = coderesult.Result;
                                    }
                                    else
                                    {
                                        throw coderesult.Exception;
                                    }

                                    //if ((property.Context is CodeFunctionDTO) && (property.Context as CodeFunctionDTO).ValueCustomType != ValueCustomType.None)
                                    //    property.Value = GetCustomTypePropertyValue(property, (property.Context as CodeFunctionDTO).ValueCustomType, result.Result);
                                    //else
                                });
                            }
                        }
                    }
                }

                result = property.Value;
                return(true);
            }
            else
            {
                throw new Exception("Property" + " " + binder.Name + " not found!");
            }
        }
        private void ValidateUnionRelationships(DP_DataRepository data)
        {
            foreach (var relationshipControl in EditArea.RelationshipColumnControls)
            {
                if (relationshipControl.Relationship.TypeEnum == Enum_RelationshipType.SubUnionToUnion)
                {
                    var childRel = data.ChildRelationshipInfos.First(x => x.Relationship.ID == relationshipControl.Relationship.ID);
                    if (!childRel.IsHidden)
                    {
                        var unionRelationship = (relationshipControl.Relationship as SubUnionToSuperUnionRelationshipDTO).UnionRelationship;
                        //چک کردن دیسجوینت بودن
                        var superDataItem = childRel.RealData.FirstOrDefault();
                        if (superDataItem != null)
                        {
                            if (!superDataItem.IsFullData)
                            {
                                var superEntity = AgentUICoreMediator.GetAgentUICoreMediator.tableDrivedEntityManagerService.GetFullEntity(AgentUICoreMediator.GetAgentUICoreMediator.GetRequester(), relationshipControl.EditNdTypeArea.AreaInitializer.EntityID);
                                var otherSuperToSubRelationships = superEntity.Relationships.Where(x => x is SuperToSubRelationshipDTO && (x as SuperToSubRelationshipDTO).ISARelationship.ID == unionRelationship.ID &&
                                                                                                   (x as SuperToSubRelationshipDTO).ID != relationshipControl.Relationship.PairRelationshipID);
                                bool moreThanOneData = false;
                                foreach (var otherSuperToSubRelationship in otherSuperToSubRelationships)
                                {
                                    var requester = AgentUICoreMediator.GetAgentUICoreMediator.GetRequester();
                                    requester.SkipSecurity = true;
                                    DR_SearchViewRequest request = new DR_SearchViewRequest(requester, AgentUICoreMediator.GetAgentUICoreMediator.RelationshipDataManager.GetSecondSideSearchDataItemByRelationship(superDataItem, otherSuperToSubRelationship.ID));

                                    var otherSideData = AgentUICoreMediator.GetAgentUICoreMediator.requestRegistration.SendSearchViewRequest(request).ResultDataItems;
                                    if (otherSideData.Any())
                                    {
                                        moreThanOneData = true;
                                        break;
                                    }
                                }

                                if (moreThanOneData)
                                {
                                    string relationshipNames = relationshipControl.Relationship.Entity1;
                                    foreach (var otherSuperToSubRelationship in otherSuperToSubRelationships)
                                    {
                                        relationshipNames += (relationshipNames == "" ? "" : ",") + otherSuperToSubRelationship.Entity2;
                                    }
                                    string message = "تنها یکی از";
                                    message += " " + (otherSuperToSubRelationships.Count() + 1) + " " + "رابطه" + " " + relationshipNames + " " + "با" + " " + relationshipControl.Relationship.Entity2 + " " + "ورود اطلاعات شود";

                                    AddColumnControlValidationMessage(relationshipControl, message, data);
                                }
                            }
                        }
                    }
                }
            }

            int    parentUnionRelationshipID      = 0;
            int    parentSubToSuperRelationshipID = 0;
            string parentSubToSuperName           = "";

            if (EditArea.AreaInitializer.SourceRelationColumnControl != null && EditArea.AreaInitializer.SourceRelationColumnControl.Relationship is SubUnionToSuperUnionRelationshipDTO)
            {
                parentSubToSuperRelationshipID = (EditArea.AreaInitializer.SourceRelationColumnControl.Relationship as SubUnionToSuperUnionRelationshipDTO).ID;
                parentSubToSuperName           = (EditArea.AreaInitializer.SourceRelationColumnControl.Relationship as SubUnionToSuperUnionRelationshipDTO).Entity1;
                parentUnionRelationshipID      = (EditArea.AreaInitializer.SourceRelationColumnControl.Relationship as SubUnionToSuperUnionRelationshipDTO).UnionRelationship.ID;
            }
            List <Tuple <UnionRelationshipDTO, List <RelationshipColumnControl> > > unionRelationships = new List <Tuple <UnionRelationshipDTO, List <RelationshipColumnControl> > >();

            foreach (var relationshipControl in EditArea.RelationshipColumnControls)
            {
                var childRel = data.ChildRelationshipInfos.First(x => x.Relationship.ID == relationshipControl.Relationship.ID);
                if (!childRel.IsHidden)
                {
                    if (relationshipControl.Relationship.TypeEnum == Enum_RelationshipType.UnionToSubUnion)
                    {
                        var unionID = (relationshipControl.Relationship as UnionToSubUnionRelationshipDTO).UnionRelationship.ID;
                        Tuple <UnionRelationshipDTO, List <RelationshipColumnControl> > unionRelationship = null;
                        if (!unionRelationships.Any(x => x.Item1.ID == unionID))
                        {
                            unionRelationship = new Tuple <UnionRelationshipDTO, List <RelationshipColumnControl> >((relationshipControl.Relationship as UnionToSubUnionRelationshipDTO).UnionRelationship, new List <RelationshipColumnControl>());
                            unionRelationships.Add(unionRelationship);
                        }
                        else
                        {
                            unionRelationship = unionRelationships.First(x => x.Item1.ID == unionID);
                        }
                        unionRelationship.Item2.Add(relationshipControl);
                        //}
                    }
                }
            }

            foreach (var unionRelationship in unionRelationships)
            {
                //توتال پارتیشپنت در یونیون برعکسه و یعنی هر ساب با یک سوپر در ارتباط باشد.این را میتوان از طریق اجباری نمودن رابطه چک کرد


                bool moreThanOneData = false;
                bool hasData         = false;
                if (unionRelationship.Item1.ID == parentUnionRelationshipID)
                {
                    hasData = true;
                }
                foreach (var relationshipControl in unionRelationship.Item2)
                {
                    var childRelationshipInfo = data.ChildRelationshipInfos.First(x => x.Relationship.ID == relationshipControl.Relationship.ID);

                    //if (childRelationshipInfo.RelatedData.Any(x => x.HasDirectData))
                    if (childRelationshipInfo.RealData.Any())
                    {
                        if (!hasData)
                        {
                            hasData = true;
                        }
                        else
                        {
                            moreThanOneData = true;
                        }
                    }
                }
                if (moreThanOneData)
                {
                    string relationshipNames = "";
                    if (parentSubToSuperName != "")
                    {
                        relationshipNames = parentSubToSuperName;
                    }
                    foreach (var relationshipControl in unionRelationship.Item2)
                    {
                        relationshipNames += (relationshipNames == "" ? "" : ",") + relationshipControl.Relationship.Entity2;
                    }
                    string message = "تنها یکی از";
                    message += " " + unionRelationship.Item2.Count + " " + "رابطه" + " " + relationshipNames + " " + "با" + " " + EditArea.FullEntity.Name + " " + " " + "ورود اطلاعات شود";
                    foreach (var relationshipControl in unionRelationship.Item2)
                    {
                        AddColumnControlValidationMessage(relationshipControl, message, data);
                    }
                }
            }
        }
Beispiel #20
0
        private void BindableTypeDescriptor_PropertyGetCalled(object sender, PropertyGetArg e)
        {
            if (e.PropertyInfo.ValueSearched == false)
            {
                if (e.PropertyInfo.PropertyType == PropertyType.Relationship)
                {
                    List <DP_DataRepository> relatedDataItems = GetRelatedDataItems((sender as FormulaObject).DataItem, e.PropertyInfo.PropertyRelationship, e.PropertyInfo.PropertyRelationshipProperties);
                    if (e.PropertyInfo.PropertyRelationship.TypeEnum == Enum_RelationshipType.OneToMany)
                    {
                        var list   = FormulaInstanceInternalHelper.GetNewFormulaObjectList(e.PropertyInfo);
                        var entity = bizTableDrivedEntity.GetPermissionedEntity(Requester, e.PropertyInfo.PropertyRelationship.EntityID2);

                        foreach (var relatedDataItem in relatedDataItems)
                        {
                            var newObject = FormulaInstanceInternalHelper.GetNewFormulaObject(e.PropertyInfo);
                            newObject.DataItem = relatedDataItem;
                            list.Add(newObject);
                            newObject.PropertyGetCalled += BindableTypeDescriptor_PropertyGetCalled;
                            //newObject.PropertySetChanged += FormulaObject_PropertySetChanged;
                            //newObject.PropertyChanged += FormulaObject_PropertyChanged;
                            //////newObject.PropertySetChanged += (sender1, e1) => NewObject_PropertySetChanged(sender1, e1, sender as FormulaObject);
                            //////newObject.PropertyGetCalled += (sender1, e1) => NewObject_PropertyGetCalled(sender1, e1, sender as FormulaObject);
                        }
                        e.PropertyInfo.Value = list;
                        var properties = FormulaInstanceInternalHelper.GetProperties(entity, e.PropertyInfo, false, false);


                        foreach (FormulaObject item in (e.PropertyInfo.Value as IList))
                        {  //بهتر نوشته شود.برای لیست لازم نیست هر دفعه خصوصیات خوانده شوند
                            if (item.PropertiesLoaded == false)
                            {
                                item.SetProperties(properties);
                            }
                        }
                    }

                    else if (relatedDataItems.Any())
                    {
                        var entity     = bizTableDrivedEntity.GetPermissionedEntity(Requester, e.PropertyInfo.PropertyRelationship.EntityID2);
                        var properties = FormulaInstanceInternalHelper.GetProperties(entity, e.PropertyInfo, false, false);
                        var newObject  = FormulaInstanceInternalHelper.GetNewFormulaObject(e.PropertyInfo);
                        newObject.DataItem = relatedDataItems.First();

                        newObject.PropertyGetCalled += BindableTypeDescriptor_PropertyGetCalled;
                        //newObject.PropertySetChanged += FormulaObject_PropertySetChanged;
                        //newObject.PropertyChanged += FormulaObject_PropertyChanged;

                        e.PropertyInfo.Value = newObject;


                        if ((e.PropertyInfo.Value as FormulaObject).PropertiesLoaded == false)
                        {
                            (e.PropertyInfo.Value as FormulaObject).SetProperties(properties);
                        }
                    }
                    e.PropertyInfo.ValueSearched = true;
                }
                else if (e.PropertyInfo.PropertyType == PropertyType.Column)
                {
                    e.PropertyInfo.ValueSearched = true;
                    EntityInstanceProperty property = (sender as FormulaObject).DataItem.GetProperty(e.PropertyInfo.ID);
                    if (property != null)
                    {
                        e.PropertyInfo.Value = property.Value;
                    }
                }
                else if (e.PropertyInfo.PropertyType == PropertyType.FormulaParameter)
                {
                    if (UsedFormulaIDs != null && UsedFormulaIDs.Contains(e.PropertyInfo.ParameterFormulaID))
                    {
                        AddException("Loop");
                    }
                    UsedFormulaIDs.Add(e.PropertyInfo.ParameterFormulaID);
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        e.PropertyInfo.ValueSearched = true;
                        var value = FormulaFunctionHandler.CalculateFormula(e.PropertyInfo.ParameterFormulaID, (sender as FormulaObject).DataItem, Requester, UsedFormulaIDs);
                        if (string.IsNullOrEmpty(value.Exception))
                        {
                            //if ((e.PropertyInfo.Context is FormulaDTO) && (e.PropertyInfo.Context as FormulaDTO).ValueCustomType != ValueCustomType.None)
                            //    e.PropertyInfo.Value = GetCustomTypePropertyValue(e.PropertyInfo, (e.PropertyInfo.Context as FormulaDTO).ValueCustomType, value.Result);
                            //else
                            e.PropertyInfo.Value     = value.Result;
                            e.FormulaUsageParemeters = value.FormulaUsageParemeters;
                        }
                        else
                        {
                            AddException(value.Exception);
                        }
                    });
                }
                else if (e.PropertyInfo.PropertyType == PropertyType.State)
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        DP_DataRepository dataItem   = (sender as FormulaObject).DataItem;
                        e.PropertyInfo.ValueSearched = true;
                        var result = StateHandler.GetStateResult(e.PropertyInfo.ID, (sender as FormulaObject).DataItem, Requester);
                        if (string.IsNullOrEmpty(result.Message))
                        {
                            e.PropertyInfo.Value = result.Result;
                        }
                        else
                        {
                            AddException(result.Message);
                        }
                    });
                }
                //else if (e.PropertyInfo.PropertyType == PropertyType.DBFormula)
                //{
                //    Application.Current.Dispatcher.Invoke((Action)delegate
                //    {
                //        DP_DataRepository dataItem = (sender as FormulaObject).DataItem;
                //        e.PropertyInfo.ValueSearched = true;
                //        var result = DatabaseFunctionHandler.GetDatabaseFunctionValue(Requester, e.PropertyInfo.ID, dataItem);

                //        //if ((e.PropertyInfo.Context is DatabaseFunctionDTO) && (e.PropertyInfo.Context as DatabaseFunctionDTO).ValueCustomType != ValueCustomType.None)
                //        //    e.PropertyInfo.Value = GetCustomTypePropertyValue(e.PropertyInfo, (e.PropertyInfo.Context as DatabaseFunctionDTO).ValueCustomType, result.Result);
                //        //else
                //        e.PropertyInfo.Value = result.Result;

                //    });
                //}
                else if (e.PropertyInfo.PropertyType == PropertyType.Code)
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        DP_DataRepository dataItem   = (sender as FormulaObject).DataItem;
                        e.PropertyInfo.ValueSearched = true;
                        var result = CodeFunctionHandler.GetCodeFunctionResult(Requester, e.PropertyInfo.ID, dataItem);
                        if (result.ExecutionException == null)
                        {
                            e.PropertyInfo.Value = result.Result;
                        }
                        else
                        {
                            AddException(result.ExecutionException.Message);
                            e.PropertyInfo.Value = "";
                        }

                        //if ((e.PropertyInfo.Context is CodeFunctionDTO) && (e.PropertyInfo.Context as CodeFunctionDTO).ValueCustomType != ValueCustomType.None)
                        //    e.PropertyInfo.Value = GetCustomTypePropertyValue(e.PropertyInfo, (e.PropertyInfo.Context as CodeFunctionDTO).ValueCustomType, result.Result);
                        //else
                    });
                }
            }
            if (PropertyGetCalled != null)
            {
                PropertyGetCalled(sender, e);
            }
        }
        //public void AddRelationshipColumnMessageItem(RelationshipColumnControl relationshipControl, string message, InfoColor infoColor, string key, DP_DataRepository causingData, bool isPermanent)
        //{
        //    BaseMessageItem baseMessageItem = new BaseMessageItem();
        //    baseMessageItem.ColumnControl = relationshipControl;
        //    baseMessageItem.Message = message;
        //    baseMessageItem.Key = key;
        //    baseMessageItem.IsPermanentMessage = isPermanent;
        //    baseMessageItem.CausingDataItem = causingData;
        //    baseMessageItem.Color = infoColor;
        //    MessageItems.Add(baseMessageItem);
        //    relationshipControl.AddControlManagerMessage(baseMessageItem);
        //}


        public void AddColumnControlValidationMessage(BaseColumnControl baseColumnControl, string message, DP_DataRepository causingData)
        {
            causingData.ISValid = false;
            ColumnControlMessageItem baseMessageItem = new ColumnControlMessageItem(baseColumnControl, ControlOrLabelAsTarget.Control);

            baseMessageItem.CausingDataItem = causingData;
            baseMessageItem.Key             = "validation";
            baseMessageItem.Message         = message;
            baseMessageItem.Priority        = ControlItemPriority.High;
            EditArea.AddColumnControlMessage(baseMessageItem);

            ColumnControlColorItem baseColorItem = new ColumnControlColorItem(baseColumnControl, ControlOrLabelAsTarget.Control);

            baseColorItem.Key             = "validation";
            baseColorItem.Color           = InfoColor.Red;
            baseColorItem.ColorTarget     = ControlColorTarget.Border;
            baseColorItem.Priority        = ControlItemPriority.High;
            baseColorItem.CausingDataItem = causingData;
            EditArea.AddColumnControlColor(baseColorItem);;
        }
Beispiel #22
0
        private List <DP_DataRepository> GetRelatedDataItems(DP_DataRepository dataItem, RelationshipDTO relationship, List <EntityInstanceProperty> relationshipProperties)
        {
            List <DP_DataRepository> result = new List <DP_DataRepository>();
            var childRelationshipInfo       = dataItem.ChildRelationshipInfos.FirstOrDefault(x => x.Relationship.ID == relationship.ID);

            if (childRelationshipInfo != null)
            {
                result = childRelationshipInfo.RelatedData.ToList();
            }
            else
            {
                bool gotFromParant = false;
                if (dataItem.ParantChildRelationshipInfo != null)
                {
                    //اگر داده پرنت بصورت بازگشتی صدا زده شده باشد از پایگاه داده نمی خواند و سعی میکند از همان داده پرنت هر چه که هست استفاده کند
                    if (dataItem.ParantChildRelationshipInfo.Relationship.TypeEnum != Enum_RelationshipType.ManyToOne)
                    {
                        if (dataItem.ParantChildRelationshipInfo.Relationship.ID == relationship.PairRelationshipID)
                        {
                            result.Add(dataItem.ParantChildRelationshipInfo.SourceData);
                            gotFromParant = true;
                        }
                    }
                }
                if (!gotFromParant)
                {
                    result = new List <DP_DataRepository>();
                    if (!relationshipProperties.Any(x => x.Value == null || string.IsNullOrEmpty(x.Value.ToString())))
                    {
                        SearchRequestManager searchProcessor = new SearchRequestManager();
                        DP_SearchRepository  searchItem      = new DP_SearchRepository(relationship.EntityID2);
                        foreach (var col in relationshipProperties)
                        {
                            searchItem.Phrases.Add(new SearchProperty()
                            {
                                ColumnID = col.ColumnID, Value = col.Value
                            });
                        }

                        //سکوریتی داده اعمال میشود
                        DR_SearchFullDataRequest request = new DR_SearchFullDataRequest(Requester, searchItem);

                        var searchResult = searchProcessor.Process(request);
                        if (searchResult.Result == Enum_DR_ResultType.SeccessfullyDone)
                        {
                            result = searchResult.ResultDataItems; // searchProcessor.GetDataItemsByListOFSearchProperties(Requester, searchDataItem).FirstOrDefault();
                        }
                        else if (searchResult.Result == Enum_DR_ResultType.ExceptionThrown)
                        {
                            throw (new Exception(searchResult.Message));
                        }

                        //result = searchProcessor.GetDataItemsByListOFSearchProperties(Requester, searchItem);

                        //nullدرست شود
                        childRelationshipInfo              = new ChildRelationshipInfo();
                        childRelationshipInfo.SourceData   = dataItem;
                        childRelationshipInfo.Relationship = relationship;
                        foreach (var item in result)
                        {
                            childRelationshipInfo.RelatedData.Add(item);
                        }
                    }
                }
            }
            return(result);
        }
Beispiel #23
0
        public FunctionResult CalculateFormulaTest(string expression, DP_DataRepository dataItem, DR_Requester requester, List <int> usedFormulaIDs = null)
        {
            var mainDataItem = GetMainDateItem(requester, dataItem);

            return(CalculateFormula(expression, mainDataItem, requester, usedFormulaIDs));
        }
        public FunctionResult GetCodeFunctionEntityResult(DR_Requester resuester, int codeFunctionEntityID, DP_DataRepository dataItem)
        {
            var codeFunctionEntity = bizCodeFunction.GetCodeFunctionEntity(resuester, codeFunctionEntityID);
            var parameters         = new List <object>();

            //var formulaUsageParemeters = new List<FormulaUsageParemetersDTO>();
            foreach (var column in codeFunctionEntity.CodeFunctionEntityColumns)
            {
                EntityInstanceProperty property = dataItem.GetProperty(column.ColumnID);
                if (property != null)
                {
                    //FormulaUsageParemetersDTO formulaUsageParemeter = new FormulaUsageParemetersDTO();
                    //formulaUsageParemeter.ParameterName = property.Name;
                    //formulaUsageParemeter.ParameterValue = (property.Value != null ? property.Value.ToString() : "<Null>");
                    //formulaUsageParemeters.Add(formulaUsageParemeter);
                    //stringParamList += (stringParamList == "" ? "" : ",") + column.FunctionColumnParamName;
                    //paramList.Add(column.FunctionColumnParamName);
                    if (property.Value != null)
                    {
                        parameters.Add(Convert.ChangeType(property.Value, column.FunctionColumnDotNetType));
                    }
                    else
                    {
                        parameters.Add(null);
                    }
                }
            }
            var result = GetCodeFunctionResult(resuester, codeFunctionEntity.CodeFunctionID, parameters);

            //   result.FormulaUsageParemeters = formulaUsageParemeters;
            return(result);
        }
Beispiel #25
0
        private List <FormulaUsageParemetersDTO> GetFormulaUsageParemeters(DR_Requester requester, FormulaDTO formula, DP_DataRepository dataItem)
        {
            List <FormulaUsageParemetersDTO> result = new List <FormulaUsageParemetersDTO>();

            foreach (var item in formula.FormulaItems)
            {
                if (item.ItemType == FormuaItemType.Column)
                {
                    FormulaUsageParemetersDTO formulaUsageParemeter = new FormulaUsageParemetersDTO();
                    formulaUsageParemeter.ParameterName = item.ItemTitle;
                    DataitemRelatedColumnValueHandler dataitemRelatedColumnValueHandler = new DataitemRelatedColumnValueHandler();
                    var value = dataitemRelatedColumnValueHandler.GetValueSomeHow(requester, dataItem, item.RelationshipTail, item.ItemID, true);
                    formulaUsageParemeter.ParameterValue = (value != null ? value.ToString() : "<Null>");
                    result.Add(formulaUsageParemeter);
                }
            }
            return(result);
        }
 //public QueryItem()
 //{
 //    ChildQueries = new List<MyConnectionManager.QueryItem>();
 //    SetIdentities = new List<MyConnectionManager.SetIdentity>();
 //    FKSources = new List<MyConnectionManager.FKToPK>();
 //    //TargetEntityID = targetEntityID;
 //    //Query = query;
 //}
 public QueryItem(TableDrivedEntityDTO targetEntity, Enum_QueryItemType queryType, List <EntityInstanceProperty> editingProperties, DP_DataRepository dataItem)
 {
     DataItem  = dataItem;
     QueryType = queryType;
     //ChildQueries = new List<MyConnectionManager.QueryItem>();
     //   SetIdentities = new List<MyConnectionManager.SetIdentity>();
     //   FKSources = new List<MyConnectionManager.FKToPK>();
     TargetEntity      = targetEntity;
     EditingProperties = editingProperties;
 }