Beispiel #1
0
        private void GenerateFieleds(Document doc, DP_DataView dataItem, LetterTemplateDTO letterTemplete, DR_Requester requester)
        {
            var fileds = GetFields(doc);

            //ParagraphFormat paragraphFormat = null;
            GenerateValues(doc, dataItem, letterTemplete, fileds.Item1, fileds.Item2, requester, "main", null);
            //PrepareDocForGenerate(null, fileds.Item1, fileds.Item2);
            //GenerateValues(null, fileds.Item1, fileds.Item2, dataItem, requester);

            //foreach (var relationshipField in fileds.Item2)
            //{
            //    var bizField = letterTemplete.RelationshipFields.FirstOrDefault(x => x.FieldName == relationshipField.FieldName);
            //    if (bizField != null)
            //    {
            //        if (bizField.RelationshipID != 0)
            //        {
            //            var searchRepository = relationshipDataManager.GetSearchDataItemByRelationship(dataItem, bizField.RelationshipID, requester);
            //            var relatedDataItems = searchProcessor.GetDataItemsByListOFSearchProperties(requester, searchRepository);
            //            if (relatedDataItems.Any())
            //            {
            //                foreach (var item in relatedDataItems)
            //                {
            //                    CopyRange(relationshipField, item);
            //                }
            //            }
            //            RemoveRange(relationshipField);
            //        }
            //    }
            //}
        }
        private LetterTemplateDTO ToLetterTemplateDTO(LetterTemplate item)
        {
            LetterTemplateDTO result = new LetterTemplateDTO();

            result.Name = item.Name;
            result.TableDrivedEntityID = item.TableDrivedEntityID;
            result.ID = item.ID;
            return(result);
        }
        private void SetOwnerPart(DR_Requester requester, LetterTemplateDTO result, LetterTemplate ownerDbItem, bool withDetails)
        {
            result.TableDrivedEntityID = ownerDbItem.TableDrivedEntityID;
            result.Name             = ownerDbItem.Name;
            result.EntityListViewID = ownerDbItem.EntityListViewID;
            if (withDetails)
            {
                BizEntityListView bizEntityListView = new BizEntityListView();

                result.EntityListView = bizEntityListView.GetEntityListView(requester, ownerDbItem.EntityListViewID);
                if (result.EntityListView == null)
                {
                    throw new Exception("عدم دسترسی به لیست نمایش به شناسه" + " " + ownerDbItem.EntityListViewID);
                }

                BizFormula bizFormula = new BizFormula();
                foreach (var item in ownerDbItem.LetterTemplatePlainField)
                {
                    LetterTemplatePlainFieldDTO field = new LetterTemplatePlainFieldDTO();
                    field.FieldName = item.FieldName;
                    field.EntityListViewColumnsID = (item.EntityListViewColumnsID == null) ? 0 : item.EntityListViewColumnsID.Value;
                    if (field.EntityListViewColumnsID != 0)
                    {
                        field.EntityListViewColumns = result.EntityListView.EntityListViewAllColumns.First(x => x.ID == item.EntityListViewColumnsID);
                    }
                    field.FormulaID = (item.FormulaID == null) ? 0 : item.FormulaID.Value;
                    field.ID        = item.ID;
                    //if (item.ColumnID != null)
                    //    field.Type = LetterTemplateFieldType.Column;
                    //else if (item.ParameterID != null)
                    //    field.Type = LetterTemplateFieldType.Parameter;
                    //if (item.RelationshipID != null)
                    //    field.Type = LetterTemplateFieldType.RangeRelationship;

                    result.PlainFields.Add(field);
                }
                BizEntityRelationshipTail bizEntityRelationshipTail = new MyModelManager.BizEntityRelationshipTail();
                foreach (var item in ownerDbItem.LetterTemplateRelationshipField)
                {
                    LetterTemplateRelationshipFieldDTO field = new LetterTemplateRelationshipFieldDTO();
                    field.RelationshipTailID = item.EntityRelationshipTailID;
                    //field.EntityPreDefinedSearchID = (item.EntityPreDefinedSearchID == null) ? 0 : item.EntityPreDefinedSearchID.Value;
                    field.ID = item.ID;
                    field.RelationshipTail = bizEntityRelationshipTail.ToEntityRelationshipTailDTO(item.EntityRelationshipTail);
                    //field.NextLine = item.NextLine==true;
                    field.IsRow     = item.IsRow == true;
                    field.FieldName = item.FieldName;
                    field.PartialLetterTemplateID = item.PartialLetterTemplateID;
                    field.PartialLetterTemplate   = ToPartialLetterTemplateDTO(requester, item.PartialLetterTemplate, true);
                    //field.PartialLetterTemplate = ToPartialLetterTemplate(item.PartialLetterTemplate, true);
                    result.RelationshipFields.Add(field);
                }
            }
        }
Beispiel #4
0
        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);
                }
            }
        }
        private void SetOwnerDBPart(MyProjectEntities projectContext, LetterTemplate owner, LetterTemplateDTO message)
        {
            owner.TableDrivedEntityID = message.TableDrivedEntityID;
            owner.Name             = message.Name;
            owner.EntityListViewID = message.EntityListViewID;
            while (owner.LetterTemplatePlainField.Any())
            {
                projectContext.LetterTemplatePlainField.Remove(owner.LetterTemplatePlainField.First());
            }
            foreach (var item in message.PlainFields)
            {
                LetterTemplatePlainField dbField = new DataAccess.LetterTemplatePlainField();
                dbField.FieldName = item.FieldName;
                dbField.EntityListViewColumnsID = (item.EntityListViewColumnsID == 0) ? (int?)null : item.EntityListViewColumnsID;
                dbField.FormulaID = (item.FormulaID == 0) ? (int?)null : item.FormulaID;
                owner.LetterTemplatePlainField.Add(dbField);
            }

            while (owner.LetterTemplateRelationshipField.Any())
            {
                projectContext.LetterTemplateRelationshipField.Remove(owner.LetterTemplateRelationshipField.First());
            }
            foreach (var item in message.RelationshipFields)
            {
                LetterTemplateRelationshipField dbField = new DataAccess.LetterTemplateRelationshipField();
                dbField.FieldName = item.FieldName;
                dbField.EntityRelationshipTailID = item.RelationshipTailID;
                //dbField.NextLine = item.NextLine;
                dbField.IsRow = item.IsRow;
                //dbField.EntityPreDefinedSearchID = (item.EntityPreDefinedSearchID == 0) ? (int?)null : item.EntityPreDefinedSearchID;
                dbField.PartialLetterTemplateID = item.PartialLetterTemplateID;
                owner.LetterTemplateRelationshipField.Add(dbField);
            }
        }