private void TestData(DP_DataRepository data) { try { FormulaFunctionHandler handler = new MyFormulaFunctionStateFunctionLibrary.FormulaFunctionHandler(); ////var child = new ChildRelationshipInfo(); ////child.Relationship = new BizRelationship().GetRelationship(33); ////SearchRequestManager searchProcessor = new SearchRequestManager(); ////DP_SearchRepository searchItem = new DP_SearchRepository(75); ////searchItem.Phrases.Add(new SearchProperty() { ColumnID = 68, Value = "بانک تجارت" }); ////DP_DataRepository childdata = null; ////var requester = GetRequester(); //////سکوریتی داده اعمال میشود ////DR_SearchFullDataRequest request = new DR_SearchFullDataRequest(requester, searchItem); ////var searchResult = searchProcessor.Process(request); ////if (searchResult.Result == Enum_DR_ResultType.SeccessfullyDone) //// childdata = searchResult.ResultDataItems.First(); ////else if (searchResult.Result == Enum_DR_ResultType.ExceptionThrown) //// throw (new Exception(searchResult.Message)); //////var childdata = searchProcessor.GetDataItemsByListOFSearchProperties(GetRequester(), searchItem).First(); ////child.ParentData = data; //childdata.ParantChildRelationshipInfo = child; ////childdata.SetProperties(newProp); //child.RelatedData.Add(childdata); //data.ChildRelationshipInfos.Add(child); var result = handler.CalculateFormula(ExpressionEditor.ExpressionText, data, MyProjectManager.GetMyProjectManager.GetRequester()); if (string.IsNullOrEmpty(result.Exception)) { MessageBox.Show(result.Result == null ? "null" : result.Result.ToString()); } else { MessageBox.Show(result.Exception); } } catch (Exception ex) { MessageBox.Show(ex.Message); } //برنگشتن آبجکت // آیتمهای فرمول }
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 CustomObject).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); foreach (CustomObject 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); 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 CustomObject).PropertiesLoaded == false) { (e.PropertyInfo.Value as CustomObject).SetProperties(properties); } } e.PropertyInfo.ValueSearched = true; } else if (e.PropertyInfo.PropertyType == PropertyType.Column) { e.PropertyInfo.ValueSearched = true; EntityInstanceProperty property = (sender as CustomObject).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 CustomObject).DataItem, Requester, false, 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 CustomObject).DataItem; e.PropertyInfo.ValueSearched = true; var result = StateHandler.GetStateResult(e.PropertyInfo.ID, (sender as CustomObject).DataItem, Requester); if (string.IsNullOrEmpty(result.Message)) { e.PropertyInfo.Value = result.Result; } else { AddException(result.Message); } }); } else if (e.PropertyInfo.PropertyType == PropertyType.Code) { Application.Current.Dispatcher.Invoke((Action) delegate { DP_DataRepository dataItem = (sender as CustomObject).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 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 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); }