public DP_DataRepository SearchDataForEditFromExternalSource(int entityID, DP_BaseData searchViewData, I_EditEntityArea editEntityArea)
        {
            DP_SearchRepository searchDataItem = new DP_SearchRepository(entityID);

            foreach (var col in searchViewData.KeyProperties)
            {
                searchDataItem.Phrases.Add(new SearchProperty()
                {
                    ColumnID = col.ColumnID, Value = col.Value
                });
            }
            var requester = AgentUICoreMediator.GetAgentUICoreMediator.GetRequester();

            //   var requestSearchEdit = new DR_SearchEditRequest(requester, searchDataItem, editEntityArea.AreaInitializer.SecurityReadOnly, true);
            var requestSearchEdit = new DR_SearchEditRequest(requester, searchDataItem);
            var foundItem         = AgentUICoreMediator.GetAgentUICoreMediator.requestRegistration.SendSearchEditRequest(requestSearchEdit).ResultDataItems;

            if (foundItem.Any())
            {
                foundItem[0].DataView = GetDataView(foundItem[0]);
                return(foundItem[0]);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        //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 List<DP_DataRepository> SearchDataForEditFromExternalSource(int entityID, List<DP_DataRepository> searchViewData, I_EditEntityArea editEntityArea)
        //{

        //    DP_SearchRepository SearchDataItem = new DP_SearchRepository(entityID);
        //    List<DP_DataRepository> result = new List<DP_DataRepository>();
        //    foreach (var item in searchViewData)
        //    {
        //        foreach (var col in item.KeyProperties)
        //        {
        //            SearchDataItem.Phrases.Add(new SearchProperty() { ColumnID = col.ColumnID, Value = col.Value });
        //        }

        //        var requester = AgentUICoreMediator.GetAgentUICoreMediator.GetRequester();
        //        var requestSearchEdit = new DR_SearchEditRequest(requester, SearchDataItem);
        //        var froundItem = AgentUICoreMediator.GetAgentUICoreMediator.SendSearchEditRequest(requestSearchEdit).ResultDataItems;
        //        if (froundItem.Any())
        //            result.Add(froundItem[0]);
        //        else
        //        {
        //            AgentUICoreMediator.GetAgentUICoreMediator.UIManager.ShowInfo("عدم دسترسی به داده", item.ProperyValues, Temp.InfoColor.Red);
        //        }
        //    }
        //    return result;
        //}
        public DP_DataView SearchDataForViewFromExternalSource(int entityID, DP_BaseData searchViewData, I_EditEntityArea editEntityArea)
        {
            DP_SearchRepository SearchDataItem = new DP_SearchRepository(entityID);

            foreach (var col in searchViewData.KeyProperties)
            {
                SearchDataItem.Phrases.Add(new SearchProperty()
                {
                    ColumnID = col.ColumnID, Value = col.Value
                });
            }
            var requester = AgentUICoreMediator.GetAgentUICoreMediator.GetRequester();

            var requestSearchView = new DR_SearchViewRequest(requester, SearchDataItem);
            var foundItem         = AgentUICoreMediator.GetAgentUICoreMediator.requestRegistration.SendSearchViewRequest(requestSearchView).ResultDataItems;

            if (foundItem.Any())
            {
                return(foundItem[0]);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public DP_DataView GetDataView(DP_BaseData data)
        {
            var newrequester = new DR_Requester();

            newrequester.SkipSecurity = true;
            DP_SearchRepository searchDataViewItem = new DP_SearchRepository(data.TargetEntityID);

            foreach (var col in data.KeyProperties)
            {
                searchDataViewItem.Phrases.Add(new SearchProperty()
                {
                    ColumnID = col.ColumnID, Value = col.Value
                });
            }
            DR_SearchViewRequest searchViewRequest = new DR_SearchViewRequest(newrequester, searchDataViewItem);
            var searchViewResult = SearchRequestManager.Process(searchViewRequest);

            if (searchViewResult.ResultDataItems.Any())
            {
                return(searchViewResult.ResultDataItems[0]);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        // SecurityHelper securityHelper = new SecurityHelper();
        //public EntityRelationshipTailDTO GetRelationshipTail(int id)
        //{
        //    return bizRelationshipTail.GetEntityRelationshipTail(id);
        //}
        //مهم اینه که داده مبدا از ویو نباشد
        public DP_SearchRepository GetTargetSearchItemFromRelationshipTail(DP_BaseData firstDataItem, EntityRelationshipTailDTO relationshipTail)
        {
            DP_SearchRepository searchItem = null;
            var linkedRelationshipTails    = GetLinkedRelationshipTails(relationshipTail.ReverseRelationshipTail);

            searchItem = GetSourceSideSearchItemFromRelationshipTail(linkedRelationshipTails.First, true, firstDataItem);
            return(searchItem);
        }
Exemplo n.º 6
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 DataItemDTO GetDataItem(int tableDrivedEntityID, List<EntityInstanceProperty> keyProperties)
        //{
        //    using (var model = new MyIdeaDataDBEntities())
        //    {
        //        var dbDataItem = GetDBDataItem(model, tableDrivedEntityID, keyProperties);
        //        if (dbDataItem != null)
        //            return ToDataItemDTO(dbDataItem);
        //        else return null;
        //    }

        //}

        public int GetOrCreateDataItem(DP_BaseData dataItem)
        {
            using (var model = new MyIdeaDataDBEntities())
            {
                var MyDataItem = GetDBDataItem(model, dataItem.TargetEntityID, dataItem.KeyProperties);
                if (MyDataItem == null)
                {
                    //if(dataItem.DataView!=null)
                    //{
                    //    foreach(var item in dataItem.DataView.Properties)
                    //    {
                    //        info += (info == "" ? "" : ",") + item.Value;
                    //    }
                    //}
                    //else
                    //{
                    //    foreach (var item in dataItem.KeyProperties)
                    //    {
                    //        info += (info == "" ? "" : ",") + item.Value;
                    //    }
                    //}
                    MyDataItem = new MyDataItem();
                    MyDataItem.TableDrivedEntityID = dataItem.TargetEntityID;
                    if (dataItem is DP_DataView)
                    {
                        MyDataItem.Info = (dataItem as DP_DataView).ViewInfo;
                    }
                    else if (dataItem is DP_DataRepository)
                    {
                        MyDataItem.Info = (dataItem as DP_DataRepository).ViewInfo;
                    }

                    foreach (var keyColumn in dataItem.KeyProperties)
                    {
                        MyDataItem.MyDataItemKeyColumns.Add(new MyDataItemKeyColumns()
                        {
                            ColumnID = keyColumn.ColumnID, Value = keyColumn.Value == null ? null : keyColumn.Value.ToString()
                        });
                    }
                    model.MyDataItem.Add(MyDataItem);
                    model.SaveChanges();
                }
                return(MyDataItem.ID);
            }
        }
 public bool SetDataItemDTO(DP_BaseData dataItem)
 {
     if (dataItem.DataItemID != 0)
     {
         return(true);
     }
     else
     {
         using (var model = new MyIdeaDataDBEntities())
         {
             var dbDataItem = GetDBDataItem(model, dataItem.TargetEntityID, dataItem.KeyProperties);
             if (dbDataItem != null)
             {
                 dataItem.DataItemID = dbDataItem.ID;
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
 }
Exemplo n.º 9
0
 private DP_SearchRepository GetSourceSideSearchItemFromRelationshipTail(LinkedListNode <EntityRelationshipTailDTO> linkedListNode, bool addPreDefinedSearch, DP_BaseData lastDataItem)
 {
     if (linkedListNode != null)
     {
         DP_SearchRepository result = new DP_SearchRepository(linkedListNode.Value.Relationship.EntityID1);
         var childPhrase            = GetSourceSideSearchItemFromRelationshipTail(linkedListNode.Next, addPreDefinedSearch, lastDataItem);
         childPhrase.SourceRelationship = linkedListNode.Value.Relationship;
         result.Phrases.Add(childPhrase);
         return(result);
     }
     else
     {
         DP_SearchRepository result = new DP_SearchRepository(lastDataItem.TargetEntityID);
         foreach (var column in lastDataItem.KeyProperties)
         {
             result.Phrases.Add(new SearchProperty()
             {
                 ColumnID = column.ColumnID, Value = column.Value
             });
         }
         return(result);
     }
 }
Exemplo n.º 10
0
        public List <DataLogDTO> SearchDataLogs(DR_Requester requester, int entityID, DateTime?fromDate, DateTime?toDate, DP_BaseData dataItem, DataLogType?logType, int columnID, int userID, bool?withMajorException, bool?withMinorException)
        {
            List <DataLogDTO> result = new List <DataLogDTO>();

            using (var context = new MyIdeaDataDBEntities())
            {
                var dataLogs = context.DataLog as IQueryable <DataLog>;
                if (entityID != 0)
                {
                    dataLogs = dataLogs.Where(x => x.MyDataItem.TableDrivedEntityID == entityID);
                }
                if (fromDate != null)
                {
                    dataLogs = dataLogs.Where(x => x.Date >= fromDate);
                }
                if (toDate != null)
                {
                    dataLogs = dataLogs.Where(x => x.Date <= toDate);
                }
                if (logType != null)
                {
                    dataLogs = dataLogs.Where(x => x.MainType == (short)logType);
                }
                if (dataItem != null)
                {
                    int dataItemID = bizDataItem.GetDataItemID(dataItem.TargetEntityID, dataItem.KeyProperties);
                    if (dataItemID == 0)
                    {
                        dataItemID = -1;
                    }
                    dataLogs = dataLogs.Where(x => x.MyDataItemID == dataItemID);
                }
                if (columnID != 0)
                {
                    dataLogs = dataLogs.Where(x => x.EditDataItemColumnDetails.Any(y => y.ColumnID == columnID));
                }
                if (userID != 0)
                {
                    dataLogs = dataLogs.Where(x => x.UserID == userID);
                }
                if (withMajorException != null)
                {
                    dataLogs = dataLogs.Where(x => x.MajorFunctionException == withMajorException);
                }
                if (withMinorException != null)
                {
                    dataLogs = dataLogs.Where(x => x.MinorFunctionException == withMinorException);
                }
                foreach (var item in dataLogs.OrderBy(x => x.ID))
                {
                    result.Add(ToDataLogDTO(requester, item, false));
                }
            }
            return(result);
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
0
        public DP_SearchRepository GetSecondSideSearchDataItemByRelationship(DP_BaseData firstSideDataItem, int relationshipID)
        {
            var relationship = bizRelationship.GetRelationship(relationshipID);

            return(GetSecondSideSearchItemByRelationship(firstSideDataItem, relationship));
        }
Exemplo n.º 13
0
 public List <DataLogDTO> SearchDataLogs(DR_Requester requester, int entityID, DateTime?fromDate, DateTime?toDate, DP_BaseData dataItem, DataLogType?logType,
                                         int columnID, int userID, bool?withMajorException, bool?withMinorException)
 {
     return(bizLogManager.SearchDataLogs(requester, entityID, fromDate, toDate, dataItem, logType, columnID, userID, withMajorException, withMinorException));
 }
        public DR_ResultEdit Process(DR_EditRequest request)
        {
            DR_ResultEdit result = new DR_ResultEdit();
            var           preEditQueryResults = new List <EditQueryPreItem>();

            foreach (var item in request.EditPackages)
            {
                preEditQueryResults.Add(new EditQueryPreItem(item));
            }

            actionActivityManager.DoBeforeEditActionActivities(request.Requester, preEditQueryResults);
            if (preEditQueryResults.Any(x => x.BeforeSaveActionActivitiesResult == Enum_DR_SimpleResultType.ExceptionThrown))
            {
                var exceptionItem = preEditQueryResults.First(x => x.BeforeSaveActionActivitiesResult == Enum_DR_SimpleResultType.ExceptionThrown);
                result.Result = Enum_DR_ResultType.ExceptionThrown;
                var logResult = bizLogManager.AddLog(GetBeforeSaveExceptionLog(exceptionItem), request.Requester);
                if (!string.IsNullOrEmpty(logResult))
                {
                    result.Details.Add(ToResultDetail("خطا در ثبت لاگ", "", logResult));
                }
                result.Details.Add(ToResultDetail(exceptionItem.DataItem.ViewInfo, "فعالیتهای قبل از ذخیره شدن داده با خطا همراه بود", exceptionItem.BeforeSaveActionActivitiesMessage));
            }
            else
            {
                //var internalResult = GetInternalResult(request as DR_EditRequest);
                var allQueryItems = editQueryItemManager.GetQueryItems(request.Requester, request.EditPackages);
                if (allQueryItems.Any(x => string.IsNullOrEmpty(x.Query)))
                {
                    throw new Exception("sdfsdf");
                }

                CheckPermissoinToEdit(request.Requester, result, allQueryItems);
                if (result.Result == Enum_DR_ResultType.ExceptionThrown)
                {
                    return(result);
                }

                var editQueryResults = new List <EditQueryResultItem>();
                foreach (var item in allQueryItems)
                {
                    editQueryResults.Add(new EditQueryResultItem(item));
                }

                actionActivityManager.DoBeforeDeleteActionActivities(request.Requester, editQueryResults);
                if (editQueryResults.Any(x => x.BeforeSaveActionActivitiesResult == Enum_DR_SimpleResultType.ExceptionThrown))
                {
                    var exceptionItem = editQueryResults.First(x => x.BeforeSaveActionActivitiesResult == Enum_DR_SimpleResultType.ExceptionThrown);
                    result.Result = Enum_DR_ResultType.ExceptionThrown;
                    var logResult = bizLogManager.AddLog(GetBeforeDeleteExceptionLog(exceptionItem), request.Requester);
                    if (!string.IsNullOrEmpty(logResult))
                    {
                        result.Details.Add(ToResultDetail("خطا در ثبت لاگ", "", logResult));
                    }
                    result.Details.Add(ToResultDetail(exceptionItem.QueryItem.DataItem.ViewInfo, "فعالیتهای قبل از ذخیره شدن داده با خطا همراه بود", exceptionItem.BeforeSaveActionActivitiesMessage));
                }
                else
                {
                    var transactionresult = ConnectionManager.ExecuteTransactionalQueryItems(allQueryItems);
                    if (transactionresult.Successful)
                    {
                        actionActivityManager.DoAfterEditActionActivities(request.Requester, editQueryResults);
                        var logResult = bizLogManager.AddLogs(GetUpdateDataSuccessfulLogs(editQueryResults), request.Requester);
                        if (!string.IsNullOrEmpty(logResult))
                        {
                            result.Details.Add(ToResultDetail("خطا در ثبت لاگ", "", logResult));
                        }

                        foreach (var item in request.EditPackages)
                        {
                            var baseData          = new DP_BaseData(item.TargetEntityID, item.TargetEntityAlias);
                            var listKeyProperties = new List <EntityInstanceProperty>();
                            if (item.IsNewItem && item.KeyProperties.Any(x => x.IsIdentity))
                            {
                                var dataItem = editQueryResults.First(x => x.QueryItem.DataItem == item).QueryItem.DataItem;
                                foreach (var key in dataItem.KeyProperties)
                                {
                                    baseData.Properties.Add(key);
                                }
                            }
                            else
                            {
                                foreach (var key in item.KeyProperties)
                                {
                                    baseData.Properties.Add(key);
                                }
                            }
                            result.UpdatedItems.Add(baseData);
                        }

                        if (editQueryResults.Any(x => x.AfterSaveActionActivitiesResult == Enum_DR_SimpleResultType.ExceptionThrown))
                        {
                            result.Result = Enum_DR_ResultType.JustMajorFunctionDone;
                            foreach (var item in editQueryResults.Where(x => x.AfterSaveActionActivitiesResult == Enum_DR_SimpleResultType.ExceptionThrown))
                            {
                                result.Details.Add(ToResultDetail(item.QueryItem.DataItem.ViewInfo, "فعالیتهای بعد از ذخیره شدن داده با خطا همراه بود", item.AfterSaveActionActivitiesMessage));
                            }
                        }
                        else
                        {
                            result.Result = Enum_DR_ResultType.SeccessfullyDone;
                        }
                    }
                    else
                    {
                        result.Result = Enum_DR_ResultType.ExceptionThrown;
                        if (editQueryResults.Any(x => x.DataUpdateResult == Enum_DR_SimpleResultType.ExceptionThrown))
                        {
                            foreach (var item in transactionresult.QueryItems.Where(x => x.Exception != null))
                            {
                                editQueryResults.First(x => x.QueryItem == item.QueryItem).DataUpdateMessage = item.Exception.Message;
                                editQueryResults.First(x => x.QueryItem == item.QueryItem).DataUpdateResult  = Enum_DR_SimpleResultType.ExceptionThrown;
                            }
                            var exceptionItem = editQueryResults.First(x => x.DataUpdateResult == Enum_DR_SimpleResultType.ExceptionThrown);
                            var logResult     = bizLogManager.AddLog(GetUpdateDataExceptionLog(exceptionItem), request.Requester);
                            if (!string.IsNullOrEmpty(logResult))
                            {
                                result.Details.Add(ToResultDetail("خطا در ثبت لاگ", "", logResult));
                            }
                            result.Details.Add(ToResultDetail(exceptionItem.QueryItem.DataItem.ViewInfo, "ذخیره شدن داده با خطا همراه بود", exceptionItem.DataUpdateMessage));
                        }
                        else
                        {
                            result.Details.Add(ToResultDetail("خطای عمومی ثبت", "ذخیره شدن داده با خطا همراه بود", transactionresult.Message));
                        }
                    }
                }
            }
            return(result);
        }
 public bool SetDataItemDTO(DP_BaseData dataItem)
 {
     return(bizDataItem.SetDataItemDTO(dataItem));
 }