Ejemplo n.º 1
0
        private CustomObject GetMainFormulaObject(DP_DataRepository mainDataItem)
        {
            CustomObject formulaObject = new CustomObject();

            if (!mainDataItem.IsNewItem && MyDataHelper.DataItemPrimaryKeysHaveValue(mainDataItem) && !MyDataHelper.DataItemNonPrimaryKeysHaveValues(mainDataItem))
            {
                SearchRequestManager searchProcessor = new SearchRequestManager();
                DP_SearchRepository  searchDataItem  = new DP_SearchRepository(mainDataItem.TargetEntityID);
                foreach (var property in mainDataItem.GetProperties())
                {
                    searchDataItem.Phrases.Add(new SearchProperty()
                    {
                        ColumnID = property.ColumnID, Value = property.Value
                    });
                }

                //سکوریتی داده اعمال میشود
                //یعنی ممکن است به خود داده دسترسی نداشته باشد و یا حتی به بعضی از فیلدها و روابط
                DR_SearchFullDataRequest request = new DR_SearchFullDataRequest(Requester, searchDataItem);
                var result = searchProcessor.Process(request);
                if (result.Result == Enum_DR_ResultType.SeccessfullyDone)
                {
                    formulaObject.DataItem = result.ResultDataItems.FirstOrDefault(); // searchProcessor.GetDataItemsByListOFSearchProperties(Requester, searchDataItem).FirstOrDefault();
                }
                else if (result.Result == Enum_DR_ResultType.ExceptionThrown)
                {
                    throw (new Exception(result.Message));
                }
            }
            else
            {
                formulaObject.DataItem = mainDataItem;
            }
            return(formulaObject);
        }
Ejemplo n.º 2
0
        private static DP_DataRepository GetMainDateItem(DR_Requester requester, DP_BaseData dataItem)
        {
            bool getDataItem = false;

            if (dataItem is DP_DataView)
            {
                getDataItem = true;
            }
            else
            {
                if (!(dataItem as DP_DataRepository).IsNewItem && MyDataHelper.DataItemPrimaryKeysHaveValue((dataItem as DP_DataRepository)) && !MyDataHelper.DataItemNonPrimaryKeysHaveValues((dataItem as DP_DataRepository)))
                {
                    getDataItem = true;
                }
            }

            if (getDataItem)
            {
                SearchRequestManager searchProcessor = new SearchRequestManager();
                DP_SearchRepository  searchDataItem  = new DP_SearchRepository(dataItem.TargetEntityID);
                foreach (var property in dataItem.KeyProperties)
                {
                    searchDataItem.Phrases.Add(new SearchProperty()
                    {
                        ColumnID = property.ColumnID, Value = property.Value
                    });
                }

                //سکوریتی داده اعمال میشود
                //یعنی ممکن است به خود داده دسترسی نداشته باشد و یا حتی به بعضی از فیلدها و روابط
                DR_SearchFullDataRequest request = new DR_SearchFullDataRequest(requester, searchDataItem);
                var result = searchProcessor.Process(request);
                if (result.Result != Enum_DR_ResultType.ExceptionThrown)
                {
                    return(result.ResultDataItems.FirstOrDefault()); // searchProcessor.GetDataItemsByListOFSearchProperties(Requester, searchDataItem).FirstOrDefault();
                }
                else
                {
                    throw (new Exception(result.Message));
                }
            }
            else
            {
                return(dataItem as DP_DataRepository);
            }
        }
        public DP_DataView ToDataViewDTO(DR_Requester requester, MyDataItem dbDataItem, bool lastInfo)
        {
            DP_DataView result = null;
            bool        error  = false;

            if (lastInfo)
            {
                DP_SearchRepository searchDataItem = new DP_SearchRepository(dbDataItem.TableDrivedEntityID);
                foreach (var property in dbDataItem.MyDataItemKeyColumns)
                {
                    searchDataItem.Phrases.Add(new SearchProperty()
                    {
                        ColumnID = property.ColumnID, Value = property.Value
                    });
                }
                DR_SearchViewRequest request = new DR_SearchViewRequest(requester, searchDataItem);
                var searchResult             = searchRequestManager.Process(request);
                if (searchResult.Result == Enum_DR_ResultType.SeccessfullyDone)
                {
                    result = searchResult.ResultDataItems.FirstOrDefault();
                }
                else if (searchResult.Result == Enum_DR_ResultType.ExceptionThrown)
                {
                    error = true;
                }
            }

            if (!lastInfo || error)
            {
                result            = new DP_DataView(dbDataItem.TableDrivedEntityID, "");
                result.DataItemID = dbDataItem.ID;
                //result.TargetEntityID = dbDataItem.TableDrivedEntityID;
                //   List<EntityInstanceProperty> listProperties = new List<EntityInstanceProperty>();
                BizColumn bizColumn = new BizColumn();

                foreach (var property in dbDataItem.MyDataItemKeyColumns)
                {
                    result.Properties.Add(new EntityInstanceProperty(bizColumn.GetColumn(property.ColumnID, true))
                    {
                        Value = property.Value
                    });
                }
            }
            return(result);
            //result.SetProperties(listProperties);
        }
        public FormulaObject(DP_DataRepository dataItem, DR_Requester requester, bool isDefinitionFormulaObject = false)
        {
            Requester = requester;
            bool getFromDB = false;

            if (isDefinitionFormulaObject == false)
            {
                if (!dataItem.IsNewItem && MyDataHelper.DataItemPrimaryKeysHaveValue(dataItem) && !MyDataHelper.DataItemNonPrimaryKeysHaveValues(dataItem))
                {
                    getFromDB = true;
                }
            }
            if (getFromDB)
            {
                SearchRequestManager searchProcessor = new SearchRequestManager();
                DP_SearchRepository  searchDataItem  = new DP_SearchRepository(dataItem.TargetEntityID);
                foreach (var property in dataItem.GetProperties())
                {
                    searchDataItem.Phrases.Add(new SearchProperty()
                    {
                        ColumnID = property.ColumnID, Value = property.Value
                    });
                }

                //سکوریتی داده اعمال میشود
                //یعنی ممکن است به خود داده دسترسی نداشته باشد و یا حتی به بعضی از فیلدها و روابط
                DR_SearchFullDataRequest request = new DR_SearchFullDataRequest(Requester, searchDataItem);
                var result = searchProcessor.Process(request);
                if (result.Result == Enum_DR_ResultType.SeccessfullyDone)
                {
                    dataItem = result.ResultDataItems.FirstOrDefault(); // searchProcessor.GetDataItemsByListOFSearchProperties(Requester, searchDataItem).FirstOrDefault();
                }
                else if (result.Result == Enum_DR_ResultType.ExceptionThrown)
                {
                    throw (new Exception(result.Message));
                }
            }
            DataItem = dataItem;
            this.PropertyGetCalled   += FormulaObject_PropertyGetCalled;
            IsDefinitionFormulaObject = isDefinitionFormulaObject;

            var entity     = bizTableDrivedEntity.GetPermissionedEntity(Requester, DataItem.TargetEntityID);
            var properties = FormulaInstanceInternalHelper.GetProperties(entity, null, false, true);

            SetProperties(properties);
        }
        public FunctionResult ValidateServiceRequest(CodeFunctionParamOneDataItem data)
        {
            FunctionResult result         = new FunctionResult();
            var            productItemRel = data.DataItem.ChildRelationshipInfos.FirstOrDefault(x => x.Relationship.Entity2Alias.Contains("کالا"));

            if (productItemRel != null)
            {
                if (productItemRel.RelatedData.Any())
                {
                    var dataItem = productItemRel.RelatedData.First();
                    if (!dataItem.IsFullData)
                    {
                        SearchRequestManager requestManager = new SearchRequestManager();

                        DP_SearchRepository SearchDataItem = new DP_SearchRepository(dataItem.TargetEntityID);
                        foreach (var col in dataItem.KeyProperties)
                        {
                            SearchDataItem.Phrases.Add(new SearchProperty()
                            {
                                ColumnID = col.ColumnID, Value = col.Value
                            });
                        }
                        var requester = new DR_Requester()
                        {
                            SkipSecurity = true
                        };
                        var request      = new DR_SearchFullDataRequest(requester, SearchDataItem);
                        var resultSearch = requestManager.Process(request);
                        dataItem = resultSearch.ResultDataItems[0];
                    }
                    var property = dataItem.Properties.FirstOrDefault(x => x.Column.Name.ToLower().Contains("brand"));
                    if (property != null)
                    {
                        if (property.Value != null && property.Value.ToString().ToLower() == "Hisense".ToLower())
                        {
                            result.Result    = false;
                            result.Exception = new Exception("امکان استفاده از برند انتخاب شده وجود ندارد");
                        }
                    }
                }
            }
            result.Result = true;
            return(result);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public byte[] GenerateLetter(int letterTemplateID, List <EntityInstanceProperty> keyProperties, DR_Requester requester)
        {
            var letterTemplete = bizLetterTemplate.GetMainLetterTepmplate(requester, letterTemplateID);
            DP_SearchRepository searchDataItem = new DP_SearchRepository(letterTemplete.TableDrivedEntityID);

            foreach (var property in keyProperties)
            {
                searchDataItem.Phrases.Add(new SearchProperty()
                {
                    ColumnID = property.ColumnID, Value = property.Value
                });
            }

            DP_DataView dataviewItem = null;
            //سکوریتی داده اعمال میشود
            //////DR_SearchFullDataRequest request = new DR_SearchFullDataRequest(requester,searchDataItem);
            //////var searchResult = searchProcessor.Process(request);
            //////if (searchResult.Result == Enum_DR_ResultType.SeccessfullyDone)
            //////    dataItem = searchResult.ResultDataItems.FirstOrDefault();
            //////else if (searchResult.Result == Enum_DR_ResultType.ExceptionThrown)
            //////    throw (new Exception(searchResult.Message));

            DR_SearchViewRequest request = new DR_SearchViewRequest(requester, searchDataItem);

            request.EntityViewID = letterTemplete.EntityListViewID;
            var searchResult = searchProcessor.Process(request);

            if (searchResult.Result == Enum_DR_ResultType.SeccessfullyDone)
            {
                dataviewItem = searchResult.ResultDataItems.FirstOrDefault();
            }
            else if (searchResult.Result == Enum_DR_ResultType.ExceptionThrown)
            {
                throw (new Exception(searchResult.Message));
            }


            //var dataItem = searchProcessor.GetDataItemsByListOFSearchProperties(requester, searchDataItem).FirstOrDefault();


            string path     = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var    fileName = Guid.NewGuid() + "." + letterTemplete.FileExtension;
            string filePath = path + @"\\" + fileName;

            System.IO.File.WriteAllBytes(filePath, letterTemplete.Content);

            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document    doc  = new Microsoft.Office.Interop.Word.Document();

            doc = word.Documents.Open(filePath);
            doc.Activate();
            word.Visible = true;
            //foreach (Microsoft.Office.Interop.Word.ContentControl cc in doc.ContentControls)
            //{
            //    //cc.
            //    //MessageBox.Show(cc.Tag);
            //    //MessageBox.Show(cc.Title);
            //}
            //List<Microsoft.Office.Interop.Word.Field> letterFields = new List<Microsoft.Office.Interop.Word.Field>();
            //foreach (Microsoft.Office.Interop.Word.Field field in doc.Fields)
            //    letterFields.Add(field);

            GenerateFieleds(doc, dataviewItem, letterTemplete, requester);


            //   doc.SaveAs2(@"N:\mehler\Ausgefuellt.docx");
            doc.Save();
            doc.Close();
            word.Quit();

            return(System.IO.File.ReadAllBytes(filePath));
        }
Ejemplo n.º 8
0
        private DP_SearchRepository GetSecondSideSearchItemByRelationship(DP_BaseData firstSideDataItem, RelationshipDTO relationship)
        {
            var relationshipFirstSideColumnExist = true;

            foreach (var col in relationship.RelationshipColumns)
            {
                if (!firstSideDataItem.Properties.Any(x => x.Value != null && !string.IsNullOrEmpty(x.Value.ToString()) && x.ColumnID == col.FirstSideColumnID))
                {
                    relationshipFirstSideColumnExist = false;
                }
            }
            if (relationshipFirstSideColumnExist)
            {
                List <EntityInstanceProperty> properties     = new List <EntityInstanceProperty>();
                DP_SearchRepository           resultDataItem = new DP_SearchRepository(relationship.EntityID2);
                foreach (var col in relationship.RelationshipColumns)
                {
                    var value = firstSideDataItem.GetProperty(col.FirstSideColumnID).Value;
                    if (value == null)
                    {
                        return(null);
                    }
                    resultDataItem.Phrases.Add(new SearchProperty()
                    {
                        ColumnID = col.SecondSideColumnID, Value = value
                    });
                }
                return(resultDataItem);
            }
            else if (relationship.MastertTypeEnum == Enum_MasterRelationshipType.FromPrimartyToForeign ||
                     relationship.MastertTypeEnum == Enum_MasterRelationshipType.FromForeignToPrimary)
            {
                DP_SearchRepository resultDataItem = new DP_SearchRepository(relationship.EntityID2);
                if (firstSideDataItem.KeyProperties.Any() && firstSideDataItem.KeyProperties.All(x => x.Value != null && !string.IsNullOrEmpty(x.Value.ToString())))
                {
                    DP_SearchRepository searchItem = new DP_SearchRepository(relationship.EntityID1);
                    foreach (var col in firstSideDataItem.KeyProperties)
                    {
                        searchItem.Phrases.Add(new SearchProperty()
                        {
                            ColumnID = col.ColumnID, Value = col.Value
                        });
                    }
                    var requester = new DR_Requester();
                    requester.SkipSecurity = true;
                    DR_SearchFullDataRequest request         = new DR_SearchFullDataRequest(requester, searchItem);
                    SearchRequestManager     searchProcessor = new SearchRequestManager();
                    var searchResult = searchProcessor.Process(request);
                    if (searchResult.Result == Enum_DR_ResultType.SeccessfullyDone)
                    {
                        firstSideDataItem = searchResult.ResultDataItems.First();
                    }
                    else if (searchResult.Result == Enum_DR_ResultType.ExceptionThrown)
                    {
                        throw (new Exception(searchResult.Message));
                    }

                    List <EntityInstanceProperty> properties = new List <EntityInstanceProperty>();

                    foreach (var col in relationship.RelationshipColumns)
                    {
                        var value = firstSideDataItem.GetProperty(col.FirstSideColumnID).Value;
                        if (value == null)
                        {
                            return(null);
                        }
                        resultDataItem.Phrases.Add(new SearchProperty()
                        {
                            ColumnID = col.SecondSideColumnID, Value = value
                        });
                    }
                    return(resultDataItem);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public DR_ResultSearchKeysOnly SendSearchKeysOnlyRequest(DR_SearchKeysOnlyRequest request)
        {
            SearchRequestManager editProcessor = new SearchRequestManager();

            return(editProcessor.Process(request as DR_SearchKeysOnlyRequest));
        }
Ejemplo n.º 11
0
        public DR_ResultSearchFullData SendSearchFullDataRequest(DR_SearchFullDataRequest request)
        {
            SearchRequestManager editProcessor = new SearchRequestManager();

            return(editProcessor.Process(request as DR_SearchFullDataRequest));
        }