public LetterDTO GetLetter(DR_Requester requester, int letterID, bool withDetails) { using (var letterModel = new MyIdeaDataDBEntities()) { using (var projectContext = new MyProjectEntities()) { var dbitem = letterModel.Letter.First(x => x.ID == letterID); var letetr = ToLetterDTO(requester, dbitem, withDetails, projectContext); //BizLetterTemplate bizLetterTemplate = new BizLetterTemplate(); if (withDetails) { var letterSetting = GetLetterSetting(); if (letterSetting != null) { if (letterSetting.BeforeLetterLoadCodeID != 0) { var result = codeFunctionHandler.GetCodeFunctionResult(requester, letterSetting.BeforeLetterLoadCodeID, letetr); if (result.Exception == null) { //if (!string.IsNullOrEmpty(result.Message)) //{ //} } else { } } } } return(letetr); } } }
private void CommandManager_Clicked(object sender, EventArgs e) { CodeFunctionHandler codeFunctionHandler = new CodeFunctionHandler(); //var parameters = new List<object>(); //parameters.Add(new CommandFunctionParam(editArea, AgentUICoreMediator.GetAgentUICoreMediator.GetRequester())); DP_DataRepository data = null; if (EditArea is I_EditEntityAreaOneData) { data = (EditArea as I_EditEntityAreaOneData).GetDataList().FirstOrDefault(); } else if (EditArea is I_EditEntityAreaMultipleData) { data = (EditArea as I_EditEntityAreaMultipleData).GetSelectedData().FirstOrDefault(); } if (data != null) { var result = codeFunctionHandler.GetCodeFunctionResult(AgentUICoreMediator.GetAgentUICoreMediator.GetRequester(), EntityCommandDTO.CodeFunctionID, data); if (result.Exception != null) { AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo("خطا", result.Exception.Message, Temp.InfoColor.Red); } } else { AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo("داده ای انتخاب نشده است"); } }
//public FunctionResult CalculateFormula(int formulaID, DP_DataView dataItem, DR_Requester requester, List<int> usedFormulaIDs = null) //{ // //DP_DataRepository data = new DP_DataRepository(mainDataItem.TargetEntityID, mainDataItem.TargetEntityAlias); // //data.Properties = mainDataItem.Properties; // return CalculateFormula(formulaID,dataItem, requester, usedFormulaIDs); //} public FunctionResult CalculateFormula(int formulaID, DP_BaseData dataItem, DR_Requester requester, List <int> usedFormulaIDs = null) { FunctionResult result = null; var formula = bizFormula.GetFormula(requester, formulaID, true); var mainDataItem = GetMainDateItem(requester, dataItem); if (formula.FormulaType == FormulaType.Linear) { var linearFormula = bizFormula.GetLinearFormula(requester, formulaID, false); result = CalculateFormula(linearFormula.FormulaText, mainDataItem, requester, usedFormulaIDs); } else { if (formula.FormulaType == FormulaType.CodeFunctionEntity) { CodeFunctionHandler codeFunctionHandler = new CodeFunctionHandler(); result = codeFunctionHandler.GetCodeFunctionEntityResult(requester, formula.CodeFunctionEntityID, mainDataItem); } else if (formula.FormulaType == FormulaType.CodeFunction) { CodeFunctionHandler codeFunctionHandler = new CodeFunctionHandler(); result = codeFunctionHandler.GetCodeFunctionResult(requester, formula.CodeFunctionID, mainDataItem); } else if (formula.FormulaType == FormulaType.DatabaseFunctionEntity) { DatabaseFunctionHandler databaseFunctionHandler = new DatabaseFunctionHandler(); result = databaseFunctionHandler.GetDatabaseFunctionValue(requester, formula.DatabaseFunctionEntityID, mainDataItem); } } result.FormulaUsageParemeters = GetFormulaUsageParemeters(requester, formula, mainDataItem); return(result); }
public void DoBeforeDeleteActionActivities(DR_Requester requester, List <EditQueryResultItem> items) { BizBackendActionActivity bizActionActivity = new BizBackendActionActivity(); foreach (var editQuertyResult in items.Where(x => x.QueryItem.QueryType == Enum_QueryItemType.Delete)) { var queryItem = editQuertyResult.QueryItem; var actionActivities = bizActionActivity.GetActionActivities(queryItem.TargetEntity.ID, new List <Enum_EntityActionActivityStep>() { Enum_EntityActionActivityStep.BeforeDelete }, true, true); CodeFunctionHandler codeFunctionHelper = new CodeFunctionHandler(); foreach (var entityActionActivity in actionActivities) { if (entityActionActivity.CodeFunctionID != 0) { var resultFunction = codeFunctionHelper.GetCodeFunctionResult(requester, entityActionActivity.CodeFunctionID, queryItem.DataItem); if (resultFunction.Exception != null) { editQuertyResult.BeforeSaveActionActivitiesResult = Enum_DR_SimpleResultType.ExceptionThrown; editQuertyResult.BeforeSaveActionActivitiesMessage += resultFunction.Exception.Message; return; } } } } }
private void View_ExternalInfoRequested(object sender, LetterExternalInfoRequestedArg e) { if (LetterSetting != null && LetterSetting.LetterExternalInfoCodeID != 0) { View.UpdateMessage(); LetterDTO sendingLetter = new LetterDTO(); sendingLetter.ExternalCode = e.ExternalCode; var result = codeFunctionHandler.GetCodeFunctionResult(AgentUICoreMediator.GetAgentUICoreMediator.GetRequester(), LetterSetting.LetterExternalInfoCodeID, sendingLetter); if (result.Exception == null) { if (!string.IsNullOrEmpty(sendingLetter.Title)) { LetterMessage.Title = sendingLetter.Title; } LetterMessage.LetterDate = sendingLetter.LetterDate; if (string.IsNullOrEmpty(LetterMessage.Desc) && !string.IsNullOrEmpty(sendingLetter.Desc)) { LetterMessage.Desc = sendingLetter.Desc; } LetterMessage.AttechedFile = sendingLetter.AttechedFile; if (LetterMessage.AttechedFile != null && LetterMessage.AttechedFile.Content != null) { if (LetterMessage.AttechedFile.FileName == null) { LetterMessage.AttechedFile.FileName = "فایل ضمیمه دارد"; } if (LetterMessage.AttechedFile.FileExtension == null) { LetterMessage.AttechedFile.FileExtension = "???"; } View.ViewExternalFileInfo(LetterMessage.AttechedFile.FileName + "." + LetterMessage.AttechedFile.FileExtension); View.ViewExternalFilePanelVisibility = true; } else { View.ViewExternalFilePanelVisibility = false; LetterMessage.AttechedFile = null; } //اگر فایل از منبع خارجی کلا حذف شده بود چی؟ //LetterMessage.IsExternalOrInternal = true; View.ShowMessage(LetterMessage); } else { } } else { AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowMessage("رویه ای به منظور دربافت اطلاعات نامه خارجی موجود نمی باشد"); return; } }
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!"); } }
public void DoAfterEditActionActivities(DR_Requester requester, List <EditQueryResultItem> items) { BizBackendActionActivity bizActionActivity = new BizBackendActionActivity(); foreach (var editQuertyResult in items.Where(x => x.QueryItem.QueryType == Enum_QueryItemType.Insert || x.QueryItem.QueryType == Enum_QueryItemType.Update)) { var queryItem = editQuertyResult.QueryItem; if (queryItem.QueryType == Enum_QueryItemType.Insert || queryItem.QueryType == Enum_QueryItemType.Update) { var actionActivities = bizActionActivity.GetActionActivities(queryItem.DataItem.TargetEntityID, new List <Enum_EntityActionActivityStep>() { Enum_EntityActionActivityStep.AfterSave }, false, true); CodeFunctionHandler codeFunctionHelper = new CodeFunctionHandler(); DatabaseFunctionHandler databaseFunctionHandler = new DatabaseFunctionHandler(); foreach (var entityActionActivity in actionActivities) { if (entityActionActivity.CodeFunctionID != 0) { var resultFunction = codeFunctionHelper.GetCodeFunctionResult(requester, entityActionActivity.CodeFunctionID, queryItem.DataItem); if (resultFunction.Exception != null) { editQuertyResult.AfterSaveActionActivitiesResult = Enum_DR_SimpleResultType.ExceptionThrown; editQuertyResult.AfterSaveActionActivitiesMessage += resultFunction.Exception.Message; } } else if (entityActionActivity.DatabaseFunctionEntityID != 0) { ////اصلاح شود و با خصوصیات صدا زده شود یا حداقل لیست خصوصیات ارسال شود چون بهتره ارتباط var resultFunction = databaseFunctionHandler.GetDatabaseFunctionValue(requester, entityActionActivity.DatabaseFunctionEntityID, queryItem.DataItem); if (resultFunction.Exception != null) { editQuertyResult.AfterSaveActionActivitiesResult = Enum_DR_SimpleResultType.ExceptionThrown; editQuertyResult.AfterSaveActionActivitiesMessage += resultFunction.Exception.Message; } } } } } foreach (var editQuertyResult in items.Where(x => x.QueryItem.QueryType == Enum_QueryItemType.Delete)) { var queryItem = editQuertyResult.QueryItem; var actionActivities = bizActionActivity.GetActionActivities(queryItem.TargetEntity.ID, new List <Enum_EntityActionActivityStep>() { Enum_EntityActionActivityStep.AfterDelete }, false, true); CodeFunctionHandler codeFunctionHelper = new CodeFunctionHandler(); DatabaseFunctionHandler databaseFunctionHandler = new DatabaseFunctionHandler(); foreach (var entityActionActivity in actionActivities) { if (entityActionActivity.CodeFunctionID != 0) { var resultFunction = codeFunctionHelper.GetCodeFunctionResult(requester, entityActionActivity.CodeFunctionID, queryItem.DataItem); if (resultFunction.Exception != null) { editQuertyResult.AfterSaveActionActivitiesResult = Enum_DR_SimpleResultType.ExceptionThrown; editQuertyResult.AfterSaveActionActivitiesMessage += resultFunction.Exception.Message; } } else if (entityActionActivity.DatabaseFunctionEntityID != 0) { var resultFunction = databaseFunctionHandler.GetDatabaseFunctionValue(requester, entityActionActivity.DatabaseFunctionEntityID, queryItem.DataItem); if (resultFunction.Exception != null) { editQuertyResult.AfterSaveActionActivitiesResult = Enum_DR_SimpleResultType.ExceptionThrown; editQuertyResult.AfterSaveActionActivitiesMessage += resultFunction.Exception.Message; } } } } // var deleteResult = new DR_ResultDelete(); //new DeleteRequestManager().DoAfterDeleteActionActivities(requester, queryItems.Where(x => x.QueryType == Enum_QueryItemType.Delete), deleteResult); //result.Message += deleteResult.Message; }