public FunctionResult CalculateFormula(int formulaID, DP_DataRepository mainDataItem, DR_Requester requester) { FormulaFunctionHandler FormulaFunctionHandler = new FormulaFunctionHandler(); return(FormulaFunctionHandler.CalculateFormula(formulaID, mainDataItem, requester)); }
private void GenerateValues(Document doc, DP_DataView dataviewItem, LetterTemplateDTO letterTemplete, List <LetterTemplatePlainFieldDTO> plainFields, List <LetterTemplateRelationshipFieldDTO> relationshipFields, DR_Requester requester, string parentTail, ParagraphFormat paragraphFormat) { //int start; //int end; //if (parentTail == "") //{ // start = 0; // end = 1000000; //} //else //{ // start = parentRange.Item1; // end = parentRange.Item2; //} foreach (var plainField in plainFields) { if (plainField.tmpParentTail == parentTail) { var bizField = letterTemplete.PlainFields.FirstOrDefault(x => x.FieldName.ToLower() == plainField.FieldName.ToLower()); if (bizField != null) { if (bizField.EntityListViewColumnsID != 0) { //درست شود var property = dataviewItem.Properties.FirstOrDefault(x => x.RelativeName == bizField.EntityListViewColumns.RelativeColumnName); if (property != null) { (plainField.LetterField as Field).Result.Text = property.Value == null ? "" : property.Value.ToString(); } } else if (bizField.FormulaID != 0) { DP_DataRepository dataRepository = new DP_DataRepository(dataviewItem.TargetEntityID, dataviewItem.TargetEntityAlias); dataRepository.DataView = dataviewItem; foreach (var key in dataviewItem.Properties.Where(x => x.IsKey)) { dataRepository.AddProperty(new ColumnDTO() { ID = key.ColumnID }, key.Value); } var parameterValue = formulaHandler.CalculateFormula(bizField.FormulaID, dataRepository, requester); if (parameterValue.Result != null) { (plainField.LetterField as Field).Result.Text = parameterValue.Result.ToString(); } } } } } foreach (var relationshipField in relationshipFields) { var bizField = letterTemplete.RelationshipFields.FirstOrDefault(x => x.FieldName.ToLower() == relationshipField.FieldName.ToLower()); if (bizField != null) { //List<EntityInstanceProperty> columnValues = new List<EntityInstanceProperty>(); //foreach (var property in dataviewItem.KeyProperties) // columnValues.Add(property); //var searchRepository = relationshipDataManager.GetSearchDataItemByRelationship(dataItem, bizField.RelationshipID, requester); //var relatedDataItems = searchProcessor.GetDataItemsByListOFSearchProperties(requester, searchRepository); List <DP_DataView> relatedDataItems = null; //سکوریتی داده اعمال میشود RelationshipTailDataManager relationshipTailDataManager = new RelationshipTailDataManager(); var searchDataItem = relationshipTailDataManager.GetTargetSearchItemFromRelationshipTail(dataviewItem, bizField.RelationshipTail); DR_SearchViewRequest request = new DR_SearchViewRequest(requester, searchDataItem); request.EntityViewID = bizField.PartialLetterTemplate.EntityListViewID; var searchResult = searchProcessor.Process(request); if (searchResult.Result == Enum_DR_ResultType.SeccessfullyDone) { relatedDataItems = searchResult.ResultDataItems; } else if (searchResult.Result == Enum_DR_ResultType.ExceptionThrown) { throw (new Exception(searchResult.Message)); } //DR_SearchByRelationshipTailRequest request = new DR_SearchByRelationshipTailRequest(requester); //request.FirstRelationshipFirstSideKeyColumns = columnValues; //request.RelationshipTail = bizField.RelationshipTail; //var process = searchProcessor.Process(request); //if (process.Result == Enum_DR_ResultType.SeccessfullyDone) // relatedDataItems = process.ResultDataItems; //else if (process.Result == Enum_DR_ResultType.ExceptionThrown) // throw (new Exception(process.Message)); if (relatedDataItems.Any()) { int itemIndex = 0; foreach (var item in relatedDataItems) { itemIndex++; var copyItem = Copy(doc, relationshipField.StartLetterField as Field, relationshipField.EndLetterField as Field, bizField.IsRow, ref paragraphFormat);; if (copyItem != null) { var tail = (parentTail == "" ? "" : parentTail + ",") + relationshipField.FieldName; var fields = GetFields(doc, copyItem, tail); GenerateValues(doc, item, bizField.PartialLetterTemplate, fields.Item1, fields.Item2, requester, tail, paragraphFormat); } } } ClearItem(doc, relationshipField.StartLetterField as Field, relationshipField.EndLetterField as Field, bizField.IsRow); } } }