public bool InsertDataIntoExternalReportTable(DR_Requester requester, int reportID, int entityID, int id, string fromquery) { var entity = new BizTableDrivedEntity().GetSimpleEntityWithColumns(requester, entityID); var tmpTableName = "xr_" + entity.TableName; var columns = GetExternalReportTableColumns(entity); var selectColumns = ""; foreach (var item in columns) { if (item.Name != "ReportKey") { selectColumns += (selectColumns == "" ? "" : ",") + entity.TableName + "." + item.Name; } else { selectColumns += (selectColumns == "" ? "" : ",") + id + " as ReportKey"; } } var query = "select " + selectColumns + " " + fromquery; var dbHelper = ConnectionManager.GetDBHelper(entity.DatabaseID); string result = ""; result = "Insert into " + tmpTableName + " " + query; dbHelper.ExecuteNonQuery(result); return(true); }
public EntityListViewDTO GetEntityKeysListView(DR_Requester requester, int entityID) { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); var entityDTO = bizTableDrivedEntity.GetTableDrivedEntity(requester, entityID, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithoutRelationships); return(ToEntityKeysListView(entityDTO)); }
private void SetColumns() { BizColumn bizColumn = new BizColumn(); BizTableDrivedEntity biz = new BizTableDrivedEntity(); var entityID = 0; if (lokRelationshipTail.SelectedItem == null) { entityID = EntityID; } else { EntityRelationshipTailDTO item = lokRelationshipTail.SelectedItem as EntityRelationshipTailDTO; entityID = item.TargetEntityID; } var entity = biz.GetTableDrivedEntity(MyProjectManager.GetMyProjectManager.GetRequester(), entityID, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithoutRelationships); var columns = entity.Columns; // .Where(x => x.ForeignKey == false).ToList(); // برای وضعیتهایی که به دسترسی داده وصل میشن همه ستونها لازمند چون مثلا برای درخواست سرویس شناسه دفتر با شناسه خاری سازمان کاربر چک میشود. اما برای وضعیتهای فرم کلید خارجی ها کنترل نمی شوند که باعث فعال شدن اقدامات بشوند. چون داینامیک تغییر نمی کنند. البته بعهتر است برنامه تغییر کند که کلید خارجی ها با تغییر رابطه تغییر کنند. cmbColumns.DisplayMemberPath = "Alias"; cmbColumns.SelectedValuePath = "ID"; cmbColumns.ItemsSource = columns; if (Message != null && Message.ID != 0) { if (Message.ColumnID != 0) { cmbColumns.SelectedValue = Message.ColumnID; } } }
public void UpdateEntityExternalReports(DR_Requester requester, EntityExternalReportDTO message) { using (var projectContext = new DataAccess.MyProjectEntities()) { BizEntityReport bizEntityReport = new MyModelManager.BizEntityReport(); var dbEntitySpecifiedReport = projectContext.EntityExternalReport.FirstOrDefault(x => x.ID == message.ID); if (dbEntitySpecifiedReport == null) { message.ReportType = ReportType.SearchableReport; message.SearchableReportType = SearchableReportType.ExternalReport; dbEntitySpecifiedReport = new EntityExternalReport(); dbEntitySpecifiedReport.EntitySearchableReport = bizEntitySearchableReport.ToNewEntitySearchableReport(message); } else { bizEntitySearchableReport.ToUpdateEntitySearchableReport(dbEntitySpecifiedReport.EntitySearchableReport, message); } dbEntitySpecifiedReport.URL = message.URL; if (dbEntitySpecifiedReport.ID == 0) { projectContext.EntityExternalReport.Add(dbEntitySpecifiedReport); } var entity = new BizTableDrivedEntity().GetSimpleEntityWithColumns(requester, message.TableDrivedEntityID); CreateReportTable(entity); //ساختن جدول معادل projectContext.SaveChanges(); } }
public frmEntitySearch(int entityID, int entitySearchID) { InitializeComponent(); EntityID = entityID; BizTableDrivedEntity biz = new BizTableDrivedEntity(); var entity = biz.GetTableDrivedEntity(MyProjectManager.GetMyProjectManager.GetRequester(), EntityID, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithoutRelationships); if (entity.IsView) { colRelationshipTail.IsVisible = false; } EntitySearchID = entitySearchID; SetRelationshipTails(); if (EntitySearchID == 0) { Message = new EntitySearchDTO(); ShowMessage(); } else { GetEntityEntitySearch(EntitySearchID); } dtgColumns.CellEditEnded += DtgConditions_CellEditEnded; dtgColumns.RowLoaded += DtgColumns_RowLoaded; colRelationshipTail.EditItemClicked += ColRelationshipTail_EditItemClicked; ControlHelper.GenerateContextMenu(dtgColumns); }
public DP_EntityResult GetEntity(DP_EntityRequest request, EntityColumnInfoType entityColumnInfoType, EntityRelationshipInfoType entityRelationshipInfoType) { DP_EntityResult result = new DP_EntityResult(); BizTableDrivedEntity biz = new BizTableDrivedEntity(); result.Entity = biz.GetTableDrivedEntity(request.Requester, request.EntityID, entityColumnInfoType, entityRelationshipInfoType); return(result); }
//private void TreeItems_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) //{ // e.Handled = true; // if (treeItems.SelectedItem != null) // { // CheckSelectedItem(treeItems.SelectedItem as RadTreeViewItem); // } //} //private void CheckSelectedItem(RadTreeViewItem treeViewItem) //{ // if (ItemSelected != null) // { // TreeFormulaParameterSelectedArg arg = new TreeFormulaParameterSelectedArg(); ; // var selectedItem = treeViewItem.DataContext; // if (selectedItem is ColumnDTO) // { // var column = (selectedItem as ColumnDTO); // var columnFormulaParameter = new ColumnFormulaParameter(); // columnFormulaParameter.ColumnID = column.ID; // columnFormulaParameter.FormulaParameterFullPath = GetColumnParameterName(treeViewItem, column, ""); // columnFormulaParameter.ParameterTitle = column.Alias; // columnFormulaParameter.ParameterType = bizColumn.GetColumnDotNetType(column); // arg.Parameter = columnFormulaParameter; // } // else if (selectedItem is FormulaParameterDTO) // { // var paremeter = (selectedItem as FormulaParameterDTO); // var existingFormulaParameter = new ExistingFormulaParameter(); // existingFormulaParameter.FormulaParameterID = paremeter.ID; // existingFormulaParameter.FormulaParameterFullPath = GetParameterName(treeViewItem, paremeter, ""); // existingFormulaParameter.ParameterTitle = paremeter.Title; // existingFormulaParameter.ParameterType = bizFormula.GetFormulaDotNetType(paremeter.FormulaID); // arg.Parameter = existingFormulaParameter; // } // else if (selectedItem is RelationshipDTO) // { // var relationship = (selectedItem as RelationshipDTO); // var relationshipFormulaParameter = new RelationshipFormulaParameter(); // relationshipFormulaParameter.FormulaParameterFullPath = GetRelaionshipName(treeViewItem, relationship, ""); // relationshipFormulaParameter.ParameterTitle = relationship.Entity2; // relationshipFormulaParameter.ParameterType = null; // arg.Parameter = relationshipFormulaParameter; // } // //if (arg.Parameter.ParameterName.EndsWith("." + singleName)) // // arg.Parameter.FormulaParameterPath = arg.Parameter.ParameterName.Replace("." + singleName, ""); // //else // // arg.Parameter.FormulaParameterPath = ""; // ItemSelected(this, arg); // } //} //private string GetColumnParameterName(RadTreeViewItem treeViewItem, ColumnDTO column, string result = "") //{ // if (treeViewItem.Parent is RadTreeViewItem) // { // if ((treeViewItem.Parent as RadTreeViewItem).Parent == treeItems.Items[0]) // return result + (result == "" ? "" : ".") + column.Name; // else if ((treeViewItem.Parent as RadTreeViewItem).DataContext is RelationshipDTO) // { // var relationship = (treeViewItem.Parent as RadTreeViewItem).DataContext as RelationshipDTO; // result = formulaHelper.GetRelationshipIdentifier(relationship) + (result == "" ? "" : ".") + result; // return GetColumnParameterName(treeViewItem.Parent as RadTreeViewItem, column, result); // } // else // return GetColumnParameterName(treeViewItem.Parent as RadTreeViewItem, column, result); // } // return ""; //} //private string GetParameterName(RadTreeViewItem treeViewItem, FormulaParameterDTO parameter, string result = "") //{ // if (treeViewItem.Parent is RadTreeViewItem) // { // if ((treeViewItem.Parent as RadTreeViewItem).Parent == treeItems.Items[0]) // return result + (result == "" ? "" : ".") + parameter.Name; // else if ((treeViewItem.Parent as RadTreeViewItem).DataContext is RelationshipDTO) // { // var relationship = (treeViewItem.Parent as RadTreeViewItem).DataContext as RelationshipDTO; // result = formulaHelper.GetRelationshipIdentifier(relationship) + (result == "" ? "" : ".") + result; // return GetParameterName(treeViewItem.Parent as RadTreeViewItem, parameter, result); // } // else // return GetParameterName(treeViewItem.Parent as RadTreeViewItem, parameter, result); // } // return ""; //} //private string GetRelaionshipName(RadTreeViewItem treeViewItem,RelationshipDTO relationship, string result = "") //{ // if (treeViewItem.Parent is RadTreeViewItem) // { // if ((treeViewItem.Parent as RadTreeViewItem).Parent == null) // return result; // else if ((treeViewItem as RadTreeViewItem).DataContext is RelationshipDTO) // { // var currentRelationship = (treeViewItem as RadTreeViewItem).DataContext as RelationshipDTO; // result = formulaHelper.GetRelationshipIdentifier(currentRelationship) + (result == "" ? "" : ".") + result; // return GetRelaionshipName(treeViewItem.Parent as RadTreeViewItem, relationship, result); // } // else // return GetRelaionshipName(treeViewItem.Parent as RadTreeViewItem, relationship, result); // } // return result; //} private void PopulateTree() { if (EntityID != 0) { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); var entity = bizTableDrivedEntity.GetTableDrivedEntity(MyProjectManager.GetMyProjectManager.GetRequester(), EntityID, EntityColumnInfoType.WithoutColumn, EntityRelationshipInfoType.WithoutRelationships); var rootNode = AddFormulaObjectNode(treeItems.Items, DatabaseObjectCategory.Entity, 0, (string.IsNullOrEmpty(entity.Alias) ? entity.Name : entity.Alias)); PopulateTreeItems(rootNode.Items, EntityID); rootNode.IsExpanded = true; } }
private void SetSubReportRelationshipTails() { BizEntityRelationshipTail bizEntityRelationshipTail = new BizEntityRelationshipTail(); BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); //var entity = bizTableDrivedEntity.GetTableDrivedEntity(EntityID, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithRelationships); var relatinships = bizEntityRelationshipTail.GetEntityRelationshipTails(MyProjectManager.GetMyProjectManager.GetRequester(), EntityID); colRelationshipTail.ItemsSource = relatinships; colRelationshipTail.DisplayMemberPath = "EntityPath"; colRelationshipTail.SelectedValueMemberPath = "ID"; }
public frmTestLookup() { InitializeComponent(); BizTableDrivedEntity biz = new BizTableDrivedEntity(); //lookup.AddColumn("ID"); //lookup.AddColumn("Name"); //lookup.SelectedValueMember = "ID"; //lookup.DisplayMember = "Name"; //lookup.ItemsSource = biz.GetAllEntities(); }
private void btnSave_Click(object sender, RoutedEventArgs e) { if (txtViewName.Text == "") { MessageBox.Show("عنوان مناسب تعریف نشده است"); return; } foreach (var item in Message.EntitySearchAllColumns) { if (item.RelationshipTailID != 0) { var relationshipTail = bizEntityRelationshipTail.GetEntityRelationshipTail(MyProjectManager.GetMyProjectManager.GetRequester(), item.RelationshipTailID); BizTableDrivedEntity bizTableDrivedEntity = new MyModelManager.BizTableDrivedEntity(); var entity = bizTableDrivedEntity.GetSimpleEntity(MyProjectManager.GetMyProjectManager.GetRequester(), EntityID);; var linkedServerMessage = bizEntityRelationshipTail.CheckLinkedServers(entity, relationshipTail); if (linkedServerMessage != "") { var message = "اشکال در تعریف لینک سرور برای ستون" + " " + (string.IsNullOrEmpty(item.Alias) ? item.ColumnID.ToString() : item.Alias); message += Environment.NewLine + linkedServerMessage; MessageBox.Show(message); return; } } } foreach (var item in Message.EntitySearchAllColumns) { if (item.RelationshipTailID != 0) { if (item.ColumnID == 0) { BizTableDrivedEntity biz = new BizTableDrivedEntity(); var relationshipTail = bizEntityRelationshipTail.GetEntityRelationshipTail(MyProjectManager.GetMyProjectManager.GetRequester(), item.RelationshipTailID); var entity = biz.GetTableDrivedEntity(MyProjectManager.GetMyProjectManager.GetRequester(), relationshipTail.TargetEntityID, EntityColumnInfoType.WithoutColumn, EntityRelationshipInfoType.WithoutRelationships); if (entity.IsView) { MessageBox.Show("به منظور استفاده از رشته رابطه" + " " + relationshipTail.EntityPath + " " + "، به علت منتهی شدن با نما، انتخاب ستون هدف اجباری می باشد"); return; } } } } Message.TableDrivedEntityID = EntityID; Message.Title = txtViewName.Text; Message.ID = bizEntitySearch.UpdateEntitySearchs(Message); if (EntitySearchUpdated != null) { EntitySearchUpdated(this, new MyProject_WPF.EntitySearchUpdatedArg() { ID = Message.ID }); } MessageBox.Show("اطلاعات ثبت شد"); }
private void CheckPermissoinToEdit(DR_Requester requester, BaseResult result, List <QueryItem> allQueryItems) { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); bool permission = true; foreach (var entityGroup in allQueryItems.GroupBy(x => x.TargetEntity.ID)) { if (!bizTableDrivedEntity.DataIsAccessable(requester, entityGroup.Key, new List <SecurityAction>() { SecurityAction.EditAndDelete })) { permission = false; var entity = allQueryItems.First(x => x.TargetEntity.ID == entityGroup.Key).TargetEntity; result.Details.Add(ToResultDetail("عدم دسترسی", "عدم دسترسی ثبت به موجودیت" + " " + entity.Alias, "")); } else if (bizTableDrivedEntity.DataIsReadonly(requester, entityGroup.Key)) { permission = false; var entity = allQueryItems.First(x => x.TargetEntity.ID == entityGroup.Key).TargetEntity; result.Details.Add(ToResultDetail("عدم دسترسی", "عدم دسترسی ثبت به موجودیت" + " " + entity.Alias, "")); } } if (permission) { BizColumn bizColumn = new BizColumn(); foreach (var query in allQueryItems) { foreach (var column in query.EditingProperties) { if (!bizColumn.DataIsAccessable(requester, column.ColumnID) || column.IsHidden) { permission = false; result.Details.Add(ToResultDetail("عدم دسترسی", "عدم دسترسی به ستون" + " " + column.Column.Alias, "")); } else if (column.ValueIsChanged && (bizColumn.DataIsReadonly(requester, column.ColumnID) || column.IsReadonly)) { permission = false; result.Details.Add(ToResultDetail("عدم دسترسی", "عدم دسترسی ثبت به ستون" + " " + column.Column.Alias, "")); } } } } if (permission == false) { result.Result = Enum_DR_ResultType.ExceptionThrown; result.Message = "خطا در ثبت"; } }
public void UpdateUIComposition(DR_Requester requester, int entityID) { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); var entity = bizTableDrivedEntity.GetTableDrivedEntity(requester, entityID, EntityColumnInfoType.WithFullColumns, EntityRelationshipInfoType.WithRelationships); //اینجا کش شدن روابط توجه شود List <EntityUICompositionDTO> generetedUIComposition = null; if (!EntityHasUIComposition(entity)) { generetedUIComposition = GenerateUIComposition(entity); Save(entityID, generetedUIComposition); } else { var entityUICompositions = GetEntityUICompositionTree(entityID); generetedUIComposition = new List <EntityUICompositionDTO>(); //var rootItem = new List<EntityUICompositionDTO>(); //List<EntityUICompositionDTO> result = new List<EntityUICompositionDTO>(); List <RelationshipDTO> candidateRelationships = GetCandidUpdateRelationships(entityUICompositions, entity); if (candidateRelationships.Any()) { var tabControl = GetOrCreateRelationshipTabControl(entityUICompositions.RootItem); if (tabControl.ID == 0) { generetedUIComposition.Add(tabControl); } foreach (var relationship in candidateRelationships) { AddTabPageRelationship(tabControl, relationship, generetedUIComposition); } } if (generetedUIComposition.Any()) { using (var projectContext = new DataAccess.MyProjectEntities()) { foreach (var parentGroup in generetedUIComposition.Where(x => x.ParentItem.ID != 0).GroupBy(x => x.ParentItem)) { var parentDBItem = projectContext.EntityUIComposition.First(x => x.ID == parentGroup.Key.ID); CheckAddItems(entityID, generetedUIComposition, parentGroup.Key, parentDBItem, projectContext); } projectContext.SaveChanges(); } } //AddPrimaryToForeignRelationshipUICompositionItem(result[0], result, entity.Relationships.Where(x => x.DataEntryEnabled == true && x.MastertTypeEnum == Enum_MasterRelationshipType.FromPrimartyToForeign).ToList(), index); } }
private void SetColumns(EntitySearchColumnsDTO condition) { colColumns.DisplayMemberPath = "Name"; colColumns.SelectedValueMemberPath = "ID"; BizTableDrivedEntity biz = new BizTableDrivedEntity(); if (condition.RelationshipTailID == 0) { var entity = biz.GetTableDrivedEntity(MyProjectManager.GetMyProjectManager.GetRequester(), EntityID, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithoutRelationships); condition.vwValueColumns = entity.Columns;; } else { var relationshipTail = bizEntityRelationshipTail.GetEntityRelationshipTail(MyProjectManager.GetMyProjectManager.GetRequester(), condition.RelationshipTailID); var entity = biz.GetTableDrivedEntity(MyProjectManager.GetMyProjectManager.GetRequester(), relationshipTail.TargetEntityID, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithoutRelationships); condition.vwValueColumns = entity.Columns; } }
private void SetArcGroupGrid() { BizArcRelationship biz = new BizArcRelationship(); dtgArcGroup.ItemsSource = biz.GetArcRelationshipGroups(TableDrivedEntityID); //روابط هر دو طرف تکرار میشوند BizRelationship bizRelationship = new BizRelationship(); BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); var entity = bizTableDrivedEntity.GetTableDrivedEntity(TableDrivedEntityID, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithRelationships); var listRelationships = entity.Relationships; var rel = dtgArcRelationships.Columns[0] as GridViewComboBoxColumn; rel.ItemsSource = listRelationships; rel.DisplayMemberPath = "Name"; rel.SelectedValueMemberPath = "ID"; }
//public bool UpdateArhiveItemTags(int iD, List<int> selectedTags) //{ // using (var context = new MyIdeaDataDBEntities()) // { // var item = context.ArchiveItem.First(x => x.ID == iD); // while (item.ArchiveItem_Tag.Any()) // context.ArchiveItem_Tag.Remove(item.ArchiveItem_Tag.First()); // foreach (var tagid in selectedTags) // { // item.ArchiveItem_Tag.Add(new ArchiveItem_Tag() { TagID = tagid }); // } // context.SaveChanges(); // return true; // } //} public bool UpdateArchiveItemFileBinary(DR_Requester requester, int iD, byte[] file) { using (var context = new MyIdeaDataDBEntities()) { //سکوریتی ثبت میتونه اینجا هم چک بشه var item = context.ArchiveItem.First(x => x.ID == iD); BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, item.MyDataItem.TableDrivedEntityID, new List <SecurityAction>() { SecurityAction.ArchiveEdit })) { throw new Exception("عدم دسترسی ثبت آرشیو"); } item.FileRepository1.Content = file; SetPossibleThumbnail(context, item, (Enum_ArchiveItemMainType)item.MainType, (Enum_ArchiveItemFileType)item.FileType, item.FileRepository1.Content, item.FileRepository1.FileName); context.SaveChanges(); return(true); } }
public EntitySearchDTO GetDefaultEntitySearch(DR_Requester requester, int entityID) { EntitySearchDTO result = null; using (var projectContext = new DataAccess.MyProjectEntities()) { var entity = projectContext.TableDrivedEntity.First(x => x.ID == entityID); if (entity.EntitySearch != null) { if (DataIsAccessable(requester, entity.EntitySearch)) { result = ToEntitySearchDTO(requester, entity.EntitySearch, true); } else { return(null); } } else { var defaultListView = entity.EntitySearch1.FirstOrDefault(); if (defaultListView != null) { if (DataIsAccessable(requester, defaultListView)) { result = ToEntitySearchDTO(requester, defaultListView, true); } else { return(null); } } else { //باید یک دیفالت ساخته و فرستاده شه BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); var entityDTO = bizTableDrivedEntity.GetPermissionedEntity(requester, entityID); result = ToEntitySimpleSearch(entityDTO); } } } return(result); }
//private void SetCommands() //{ // if (cmbEntities.SelectedItem != null) // { // var entity = cmbEntities.SelectedItem as TableDrivedEntityDTO; // BizEntityCommand bizEntityCommand = new BizEntityCommand(); // var commands = bizEntityCommand.GetEntityCommands(entity.ID, false); // cmbCommands.ItemsSource = commands; // cmbCommands.DisplayMemberPath = "Title"; // cmbCommands.SelectedValuePath = "ID"; // } //} private void SetColumns(int entityID) { //if (lokEntities.SelectedItem != null) //{ // var entity = lokEntities.SelectedItem as TableDrivedEntityDTO; //var columns = bizColumn.GetColumns(entity.ID, true); //columns.Add(null); //cmbColumns.ItemsSource = columns; //cmbColumns.DisplayMemberPath = "Name"; //cmbColumns.SelectedValuePath = "ID"; BizTableDrivedEntity biz = new BizTableDrivedEntity(); var entity = biz.GetTableDrivedEntity(entityID, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithoutRelationships); cmbConditionalColumns.ItemsSource = entity.Columns; cmbConditionalColumns.DisplayMemberPath = "Name"; cmbConditionalColumns.SelectedValuePath = "ID"; //} }
public bool UpdateMultipleArchiveItemInfo(DR_Requester requester, List <int> IDs, bool changeFolder, int?folderID, bool changeTagIDs, List <int> selectedTagIds) { using (var context = new MyIdeaDataDBEntities()) { //سکوریتی ثبت میتونه اینجا هم چک بشه //BizArchive bizArchive = new BizArchive(); foreach (var iD in IDs) { var item = context.ArchiveItem.First(x => x.ID == iD); BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, item.MyDataItem.TableDrivedEntityID, new List <SecurityAction>() { SecurityAction.ArchiveEdit })) { throw new Exception("عدم دسترسی ثبت آرشیو"); } if (changeFolder) { item.FolderID = folderID; } if (changeTagIDs) { //var entityArchiveTags = bizArchive.GetArchiveTags(item.MyDataItem.TableDrivedEntityID, true); //var entityTagIds = entityArchiveTags.Select(x => x.ID).ToList(); while (item.ArchiveItem_Tag.Any()) { context.ArchiveItem_Tag.Remove(item.ArchiveItem_Tag.First()); } foreach (var tagid in selectedTagIds) { item.ArchiveItem_Tag.Add(new ArchiveItem_Tag() { TagID = tagid }); } } } context.SaveChanges(); return(true); } }
public long GetExternalReportKey(DR_Requester requester, int reportID, int entityID, DP_SearchRepository searchItem) { BizEntityExternalReport bizEntityExternalReport = new BizEntityExternalReport(); BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); SearchRequestManager searchRequestManager = new SearchRequestManager(); var query = searchRequestManager.GetSelectFromExternal(requester, entityID, searchItem, true); var entity = bizTableDrivedEntity.GetSimpleEntity(requester, entityID); if (query != null) { // var transactionresult = ConnectionManager.ExecuteTransactionalQueryItems(allQueryItems.Where(x => !string.IsNullOrEmpty(x.Query)).ToList()); //var guid = Guid.NewGuid().ToString(); var id = 0; using (var model = new MyIdeaDataDBEntities()) { var newItem = new ExternalReportKeys(); newItem.DateTime = DateTime.Now; newItem.RequesterID = requester.Identity; newItem.ReportID = reportID; model.ExternalReportKeys.Add(newItem); model.SaveChanges(); id = newItem.ID; } if (id != 0) { var inserted = bizEntityExternalReport.InsertDataIntoExternalReportTable(requester, reportID, entityID, id, query.Item2); if (inserted) { return(id); } } } return(0); }
public LetterResult UpdateLetter(LetterDTO message, DR_Requester requester) { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, message.DataItem.TargetEntityID, new List <SecurityAction>() { SecurityAction.LetterEdit })) { throw new Exception("عدم دسترسی ثبت نامه"); } LetterResult result = new LetterResult(); bool isNew = message.ID == 0; var letterSetting = GetLetterSetting(); if (letterSetting != null) { if (letterSetting.BeforeLetterSaveCodeID != 0) { var resultFunction = codeFunctionHandler.GetCodeFunctionResult(requester, letterSetting.BeforeLetterSaveCodeID, message); if (resultFunction.Exception != null) { var logResult = bizLogManager.AddLog(GetBeforeUpdateExceptionLog(message, resultFunction.Exception, isNew ? DataLogType.LetterInsert : DataLogType.LetterUpdate), requester); if (!string.IsNullOrEmpty(logResult)) { ResultDetail logException = new ResultDetail(); logException.Title = "خطای ثبت لاگ"; logException.Description = "خطای لاگ برای اقدام قبل از ثبت نامه"; logException.TechnicalDescription = logResult; result.Details.Add(logException); } result.Message = "اقدامات مرتبط قبل از ثبت نامه با خطا همراه بود"; return(result); } } } using (var letterModel = new MyIdeaDataDBEntities()) { try { var dbLetter = letterModel.Letter.FirstOrDefault(x => x.ID == message.ID); if (dbLetter == null) { dbLetter = new Letter(); dbLetter.CreationDate = DateTime.Now; dbLetter.UserID = requester.Identity; //var dataItemID = bizDataItem.GetOrCreateDataItem(message.DataItem); if (message.DataItem.DataItemID == 0) { dbLetter.MyDataItemID = bizDataItem.GetOrCreateDataItem(message.DataItem); message.DataItem.DataItemID = dbLetter.MyDataItemID; } else { dbLetter.MyDataItemID = message.DataItem.DataItemID; } } dbLetter.ID = message.ID; dbLetter.Desc = message.Desc; dbLetter.LetterNumber = message.LetterNumber; dbLetter.IsGeneratedOrSelected = message.IsGeneratedOrSelected; dbLetter.FromExternalSource = message.IsExternalOrInternal; dbLetter.ExternalSourceKey = message.ExternalCode; dbLetter.LetterNumber = message.LetterNumber; dbLetter.LetterDate = message.LetterDate; dbLetter.LetterTemplateID = message.LetterTemplateID == 0 ? (int?)null : message.LetterTemplateID; dbLetter.LetterTypeID = message.LetterTypeID; dbLetter.RelatedLetterID = message.RelatedLetterID == 0 ? (int?)null : message.RelatedLetterID; dbLetter.Title = message.Title; if (dbLetter.FileRepository == null) { if (message.AttechedFile != null && message.AttechedFile.Content != null) { dbLetter.FileRepository = bizFileRepository.ToFileRepository(letterModel, message.AttechedFile); } } if (dbLetter.ID == 0) { letterModel.Letter.Add(dbLetter); } letterModel.SaveChanges(); message.ID = dbLetter.ID; result.SavedID = dbLetter.ID; result.Result = true; } catch (Exception ex) { result.Result = false; result.Message = ex.Message; } finally { var logResult = bizLogManager.AddLog(GetUpdateLetterDataLog(message, result.Message, isNew ? DataLogType.LetterInsert : DataLogType.LetterUpdate), requester); if (!string.IsNullOrEmpty(logResult)) { ResultDetail logException = new ResultDetail(); logException.Title = "خطای ثبت لاگ"; logException.Description = "خطای لاگ برای ثبت نامه"; logException.TechnicalDescription = logResult; result.Details.Add(logException); } } } if (result.Result == false) { result.Message = "عملیات ثبت با خطا همراه بود"; return(result); } else { bool afterSaveException = false; if (letterSetting != null) { if (letterSetting.AfterLetterSaveCodeID != 0) { var resultFunction = codeFunctionHandler.GetCodeFunctionResult(requester, letterSetting.AfterLetterSaveCodeID, message); if (resultFunction.Exception != null) { afterSaveException = true; var logResult = bizLogManager.AddLog(GetAfterUpdateExceptionLog(message, resultFunction.Exception, isNew ? DataLogType.LetterInsert : DataLogType.LetterUpdate), requester); if (!string.IsNullOrEmpty(logResult)) { ResultDetail logException = new ResultDetail(); logException.Title = "خطای ثبت لاگ"; logException.Description = "خطای لاگ برای اقدام بعد از ثبت نامه"; logException.TechnicalDescription = logResult; result.Details.Add(logException); } return(result); } } } if (afterSaveException) { result.Message = "عملیات ثبت با موفقیت انجام شد اما اقدامات بعد از ثبت با خطا همراه بود"; } else { result.Message = "عملیات ثبت با موفقیت انجام شد"; } return(result); } }
//public DP_EntitySearchResult GetEntitySearch(DP_EntitySearchRequest request) //{ // return bizPackageManager.GetEntitySearch(request); //} //public RR_ReportResult GetReport(RR_ReportRequest request, bool withDetails) //{ // return bizPackageManager.GetReport(request, withDetails); //} //public List<RelationshipFilterDTO> GetRelationshipFilters(int relationshipID) //{ // return bizPackageManager.GetRelationshipFilters(relationshipID); //} //public DP_NavigatoinTreeResult GetNavigationTree(DP_NavigationTreeRequest request) //{ // return bizPackageManager.GetNavigationTree(request); //} public bool IndependentDataEntry(int entityID) { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); return(bizTableDrivedEntity.IndependentDataEntry(entityID)); }
public ArchiveDeleteResult DeleteArchiveItemDataItems(List <int> items, DR_Requester requester) { ArchiveDeleteResult result = new ArchiveDeleteResult(); using (var context = new MyIdeaDataDBEntities()) { bool saved = false; bool exceptioned = false; foreach (var item in items) { string exception = ""; //itemResult.ID = item.ID; var dbItem = context.ArchiveItem.First(x => x.ID == item); try { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, dbItem.MyDataItem.TableDrivedEntityID, new List <SecurityAction>() { SecurityAction.ArchiveEdit })) { throw new Exception("عدم دسترسی ثبت نامه"); } while (dbItem.ArchiveItem_Tag.Any()) { context.ArchiveItem_Tag.Remove(dbItem.ArchiveItem_Tag.First()); } context.ArchiveItem.Remove(dbItem); //سکوریتی حذف میتونه اینجا هم چک بشه context.SaveChanges(); saved = true; //itemResult.Result = true; } catch (Exception ex) { exception = ex.Message; ResultDetail itemResult = new ResultDetail(); exceptioned = true; itemResult.Title = "خطا"; itemResult.Description = "حذف فایل با شناسه" + " " + dbItem.ID + " " + "با خطا همراه بود"; itemResult.TechnicalDescription = ex.Message; result.Details.Add(itemResult); } finally { var logResult = bizLogManager.AddLog(GetDeleteItemDataLog(dbItem, exception), requester); if (!string.IsNullOrEmpty(logResult)) { ResultDetail logException = new ResultDetail(); logException.Title = "خطای ثبت لاگ"; logException.Description = "ثبت لاگ برای حذف فایل با شناسه" + " " + dbItem.ID + " " + "با خطا همراه بود"; logException.TechnicalDescription = logResult; result.Details.Add(logException); } } } if (saved && exceptioned) { result.Message = "حذف برخی از فایلها با خطا همراه بود"; } else if (saved) { result.Message = "عملیات حذف با موفقیت انجام شد"; } else if (exceptioned) { result.Message = "عملیات حذف با خطا همراه بود"; } else { result.Message = "عملیات حذف انجام نشد"; } } return(result); }
public ArchiveResult CreateArchiveItems(ArchiveItemDTO message, DR_Requester requester) { ArchiveResult result = new ArchiveResult(); try { // افزوده شدن نامه ها به آرشیو بعدا بررسی شود if (message.ID != 0) { throw new Exception(); } BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, message.DatItem.TargetEntityID, new List <SecurityAction>() { SecurityAction.ArchiveEdit })) { throw new Exception("عدم دسترسی ثبت آرشیو"); } using (var context = new MyIdeaDataDBEntities()) { var dbArchiveItem = new ArchiveItem(); if (message.DatItem.DataItemID == 0) { dbArchiveItem.MyDataItemID = bizDataItem.GetOrCreateDataItem(message.DatItem); message.DatItem.DataItemID = dbArchiveItem.MyDataItemID; } else { dbArchiveItem.MyDataItemID = message.DatItem.DataItemID; } //var dataItem = bizDataItem.GetOrCreateDataItem(message.DatItem); //var archiveItemDataItem = new MyDataItem_ArchiveItem(); dbArchiveItem.FolderID = message.FolderID; dbArchiveItem.CreationDate = DateTime.Now; dbArchiveItem.UserID = requester.Identity; dbArchiveItem.Name = message.Name; var type = GetArchiveItemType(message); message.FileType = type.Item2; message.MainType = type.Item1; dbArchiveItem.FileType = (short)message.FileType; dbArchiveItem.MainType = (short)message.MainType; if (message.AttechedFile != null && message.AttechedFile.Content != null) { dbArchiveItem.FileSize = message.AttechedFile.Content.Count(); dbArchiveItem.FileRepository1 = bizFileRepository.ToFileRepository(context, message.AttechedFile); } SetPossibleThumbnail(context, dbArchiveItem, message.MainType, message.FileType, message.AttechedFile.Content, message.AttechedFile.FileName); //if (!hasThumbnail) //{ // dbArchiveItem.ThumbnailFileRepositoryID = null; // // dbArchiveItem.FileRepository1 = null; //} foreach (var tagid in message.TagIDs) { dbArchiveItem.ArchiveItem_Tag.Add(new ArchiveItem_Tag() { TagID = tagid }); } context.ArchiveItem.Add(dbArchiveItem); context.SaveChanges(); message.ID = dbArchiveItem.ID; result.Result = true; //انتیتی فرمورک قاطی داره رابطه فایل را برای تامبنیل هم میزاره //context.SaveChanges(); } } catch (Exception ex) { result.Result = false; result.Message = ex.Message; } finally { var logResult = bizLogManager.AddLog(GetCreateItemDataLog(message, result.Message), requester); if (!string.IsNullOrEmpty(logResult)) { result.Message += (!string.IsNullOrEmpty(result.Message) ? Environment.NewLine : "") + "خطا در ثبت لاگ" + " , " + logResult; } } return(result); }
public bool CreateReportTable(DR_Requester requester, int entityID) { var entity = new BizTableDrivedEntity().GetSimpleEntityWithColumns(requester, entityID); return(CreateReportTable(entity)); }
public bool IsEntityEnabled(int entityID) { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); return(bizTableDrivedEntity.IsEntityEnabled(entityID)); }
private void SetRelatoinshipTree(LetterTemplateRelationshipFieldDTO parent, List <LetterTemplatePlainFieldDTO> plaintFields, List <LetterTemplateRelationshipFieldDTO> relationshipFields, List <Tuple <string, Field> > allFormFileds, string parentTail = "") { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); int start; int end; if (parent == null) { start = 0; end = 1000000; } else { start = parent.tmpConsumedRange.Item1; end = parent.tmpConsumedRange.Item2; } //TableDrivedEntityDTO entity = null; //if (parent == null) // entity = defaultEntity; //else if (parent.InternalLetterTemplate.TableDrivedEntityID != 0) // entity = bizTableDrivedEntity.GetTableDrivedEntity(parent.InternalLetterTemplate.TableDrivedEntityID, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithoutRelationships); foreach (var field in allFormFileds.Where(x => x.Item1.StartsWith("rel_") && x.Item1.EndsWith("_start") && x.Item2.Result.Start > start)) { var splt = field.Item1.Split('_'); var fieldName = ""; if (splt.Count() > 2) { fieldName = splt[0] + "_" + splt[1] + "_" + splt[2]; } else { fieldName = splt[0] + "_" + splt[1]; } var endField = GetRelationshipFieldEnd(field.Item1, allFormFileds); if (endField != null) { if (ItemIsInRangeOf(endField, start, end)) { if (!ItemIsInRangeOfChilds(field.Item2, relationshipFields)) { var newField = new LetterTemplateRelationshipFieldDTO(); newField.FieldName = fieldName; newField.tmpConsumedRange = new Tuple <int, int>(field.Item2.Result.End, endField.Result.Start); newField.StartLetterField = field.Item2; newField.EndLetterField = endField; //////var relName = field.Name.Split('_')[1]; //////var relationship = entity.Relationships.FirstOrDefault(x => x.Entity2 == relName); //////if (relationship != null) //////{ ////// newField.RelationshipID = relationship.ID; ////// newField.InternalLetterTemplate.TableDrivedEntityID = relationship.EntityID2; ////// //SetLetterRelationshipTemplates(newField); ////// //SetRelationshipFiltered(newField); ////// var firstTemplate = newField.tmpInternalLetterTemplates.FirstOrDefault(); ////// if (firstTemplate != null) ////// newField.InternalLetterTemplate.ID = firstTemplate.ID; //////} var tail = (parentTail == "" ? "" : parentTail + ",") + fieldName; SetRelatoinshipTree(newField, newField.PartialLetterTemplate.PlainFields, newField.PartialLetterTemplate.RelationshipFields, allFormFileds, tail); relationshipFields.Add(newField); } } } } foreach (var field in allFormFileds.Where(x => !x.Item1.StartsWith("rel_")))// (x.Item1.StartsWith("col_") || x.Item1.StartsWith("prm_")) && x.Item2.Result.Start > start)) { var splt = field.Item1.Split('_'); var fieldName = field.Item1;// splt[0] + "_" + splt[1]; if (ItemIsInRangeOf(field.Item2, start, end)) { if (!ItemIsInRangeOfChilds(field.Item2, relationshipFields)) { var newField = new LetterTemplatePlainFieldDTO(); newField.FieldName = fieldName; newField.LetterField = field.Item2; newField.tmpParentTail = parentTail; //if (fieldName.ToLower().StartsWith("col_")) //{ // //اینجا جای ست گردن مقادیر پیش فرض نیست.باید در همان فرم انجام شود // //////if (entity != null) // //////{ // ////// var columnName = field.Name.Split('_')[1]; // ////// var column = entity.Columns.FirstOrDefault(x => x.Name == columnName); // ////// if (column != null) // ////// newField.ColumnID = column.ID; // //////} //} //else if (fieldName.ToLower().StartsWith("prm_")) //{ // //اینجا جای ست گردن مقادیر پیش فرض نیست.باید در همان فرم انجام شود // //////int entityID = 0; // //////if (parent == null) // ////// entityID = EntityID; // //////else // ////// entityID = parent.InternalLetterTemplate.TableDrivedEntityID; // //////if (entityID != 0) // //////{ // ////// var paramters = bizFormula.GetFormulaParameters(entityID); // ////// var parameterName = field.Name.Split('_')[1]; // ////// var parameter = paramters.FirstOrDefault(x => x.Name == parameterName); // ////// if (parameter != null) // ////// newField.ParameterID = parameter.ID; // //////} //} plaintFields.Add(newField); } } } }
private void btnSave_Click(object sender, RoutedEventArgs e) { //ستونهای رابطه برای مشتقها از موجودیت پایه حذف شوند //کد نوشته شود //if (txtName.Text == "") //{ // MessageBox.Show("نام موجودیت مشخص نشده است", "نام موجودیت"); // return; //} //if ((cmbDrivedEntities.SelectedValue == null ? 0 : (int)cmbDrivedEntities.SelectedValue) == BaseEntity.ID) //{ // if (txtCriteria.Text != "") // { // MessageBox.Show("برای موجودیت پایه شرط نمیتوان تعریف نمود", "شرط موجودیت"); // return; // } //} //else //{ // if (txtCriteria.Text == "") // { // MessageBox.Show("شرط موجودیت مشخص نشده است", "شرط موجودیت"); // return; // } //} //if (Inheritance) //{ //if (!Message.DeterminerValues.Any()) //{ // MessageBox.Show("مقادیر تعیین کننده نوع موجودیت مشخص نشده است"); // return; //} if (optIsDisjoint.IsChecked == false && optIsOverlap.IsChecked == false) { MessageBox.Show("نوع رابطه ارث بری مشخص نشده است", "Disjoint or Overlap"); return; } if (optIsTolatParticipation.IsChecked == false && optIsPartialParticipation.IsChecked == false) { MessageBox.Show("نوع رابطه ارث بری مشخص نشده است", "TolatParticipation or PartialParticipatio"); return; } foreach (var entity in Message.DrivedEntities) { foreach (var column in entity.Item3.Columns) { if (!column.PrimaryKey) { if (Message.BaseEntity.Columns.Any(x => x.ID == column.ID)) { MessageBox.Show("ستون" + " " + column.Name + " " + "همزمان در موجودیت پایه و همچنین زیر موجودیت" + " " + entity.Item3.Name + " " + "تعریف شده است"); return; } } } foreach (var rel in entity.Item3.Relationships) { if (Message.BaseEntity.Relationships.Any(x => x.ID == rel.ID)) { MessageBox.Show("رابطه" + " " + rel.Name + " " + "همزمان در موجودیت پایه و همچنین زیر موجودیت" + " " + entity.Item3.Name + " " + "تعریف شده است"); return; } } } if (optIsOverlap.IsChecked == true) { foreach (var entity in Message.DrivedEntities) { foreach (var column in entity.Item3.Columns) { if (Message.DrivedEntities.Any(x => x != entity && x.Item3.Columns.Any(y => !y.PrimaryKey && y.ID == column.ID))) { MessageBox.Show("ستون" + " " + column.Name + " " + "در بیش از یک زیر موجودیت تعریف شده و این برای روابط ارث بری" + " " + "Overlap" + " " + "امکان پذیر نمی باشد"); return; } } } foreach (var entity in Message.DrivedEntities) { foreach (var relationship in entity.Item3.Relationships) { if (Message.DrivedEntities.Any(x => x != entity && x.Item3.Relationships.Any(y => y.ID == relationship.ID))) { MessageBox.Show("رابطه" + " " + relationship.Name + " " + "در بیش از یک زیر موجودیت تعریف شده و این برای روابط ارث بری" + " " + "Overlap" + " " + "امکان پذیر نمی باشد"); return; } } } } foreach (var entity in Message.DrivedEntities) { if (!entity.Item1.DeterminerColumnValues.Any()) { var message = "برای یک یا چند موجودیت مشتق ستون و یا مقدار تعیین کننده مشخص نشده است"; MessageBox.Show(message); return; } if (optIsDisjoint.IsChecked == true) { foreach (var values in entity.Item1.DeterminerColumnValues) { if (Message.DrivedEntities.Any(x => x != entity && x.Item1.DeterminerColumnValues.Any(y => y.Value == values.Value))) { var message = "مقدار تعیین کننده" + " '" + values + "' " + "برای بیش از یک زیر موجودیت تعریف شده است"; MessageBox.Show(message); return; } } } } UpdateSubEntities(); foreach (var DrivedEntity in Message.DrivedEntities) { if (DrivedEntity.Item1.SuperEntityDeterminerColumnID == 0) { MessageBox.Show("برای زیر موجودیت" + " " + DrivedEntity.Item3.Name + " " + "ستون تعیین موجودیت مشخص نشده است"); return; } if (!DrivedEntity.Item1.DeterminerColumnValues.Any()) { MessageBox.Show("برای زیر موجودیت" + " " + DrivedEntity.Item3.Name + " " + "مقادیر تعیین موجودیت مشخص نشده است"); return; } if (!Message.BaseEntity.Columns.Any(x => x.ID == DrivedEntity.Item1.SuperEntityDeterminerColumnID)) { MessageBox.Show("ستون تعیین کننده برای زیر موجودیت" + " " + DrivedEntity.Item3.Name + " " + "در موجودیت پایه موجود نمی باشد"); return; } } foreach (var DrivedEntity in Message.DrivedEntities) { if (DrivedEntity.Item3.Name == "") { var message = "برای یک یا چند موجودیت مشتق نام موجودیت تعریف نشده است"; MessageBox.Show(message); return; } } Message.ISARelationship.IsDisjoint = optIsDisjoint.IsChecked == true; Message.ISARelationship.IsTolatParticipation = optIsTolatParticipation.IsChecked == true; BizTableDrivedEntity biz = new BizTableDrivedEntity(); var id = biz.Save(MyProjectManager.GetMyProjectManager.GetRequester(), Message); MessageBox.Show("اطلاعات ثبت شد"); }
private Task DetermineRelationshipType(List <RelationshipImportItem> listNew, List <TableDrivedEntityDTO> entities) { return(Task.Run(() => { BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); ModelDataHelper dataHelper = new ModelDataHelper(); Dictionary <string, string> isaKeys = new Dictionary <string, string>(); foreach (var item in listNew) { var pkEntity = entities.First(x => x.Name == item.Relationship.Entity1); var fkEntity = entities.First(x => x.Name == item.Relationship.Entity2); item.Relationship.EntityID1 = pkEntity.ID; item.Relationship.EntityID2 = fkEntity.ID; item.Relationship.Entity1 = pkEntity.Name; item.Relationship.Entity2 = fkEntity.Name; item.Relationship.DatabaseID1 = pkEntity.DatabaseID; item.Relationship.DatabaseID2 = fkEntity.DatabaseID; foreach (var relcol in item.Relationship.RelationshipColumns) { var col1 = pkEntity.Columns.First(x => x.Name == relcol.FirstSideColumn.Name); relcol.FirstSideColumnID = col1.ID; relcol.FirstSideColumn = col1; var col2 = fkEntity.Columns.First(x => x.Name == relcol.SecondSideColumn.Name); relcol.SecondSideColumnID = col2.ID; relcol.SecondSideColumn = col2; } //item.Relationship.RelatesOnPrimaryKeys = bizRelationship.RelatesOnPrimaryKeys(item.Relationship, new List<TableDrivedEntityDTO>() { pkEntity, fkEntity }); //item.Relationship.FKCoumnIsNullable = item.Relationship.RelationshipColumns.Any(x => x.SecondSideColumn.IsNull); InfoUpdated(this, new ItemImportingStartedArg() { CurrentProgress = listNew.IndexOf(item) + 1, TotalProgressCount = listNew.Count, ItemName = "Determinig Relationship Type" + " " + item.Relationship.Name }); item.Relationship.RelationInfo = dataHelper.GetRelationshipsInfo(item.Relationship, pkEntity, fkEntity); //if (relationInfo.FKRelatesOnPrimaryKey) //{ // //var subEntity = bizTableDrivedEntity.GetTableDrivedEntity(relationship.EntityID2, EntityColumnInfoType.WithSimpleColumns, EntityRelationshipInfoType.WithoutRelationships); // //if (isaRelationship == null) // //{ // // isaRelationship = new Tuple<TableDrivedEntityDTO, List<Tuple<RelationshipDTO, TableDrivedEntityDTO>>>(entity, new List<Tuple<RelationshipDTO, TableDrivedEntityDTO>>() { new Tuple<RelationshipDTO, TableDrivedEntityDTO>(relationship, subEntity) }); // //} // //else // // isaRelationship.Item2.Add(new Tuple<RelationshipDTO, TableDrivedEntityDTO>(relationship, subEntity)); // item.Relationship.TypeEnum = Enum_RelationshipType.SuperToSub; //} //else //{ Enum_OrginalRelationshipType originalType = Enum_OrginalRelationshipType.None; if (item.Relationship.FKSidePKColumnsAreFkColumns) { originalType = Enum_OrginalRelationshipType.SuperToSub; } else { if (Database.DBHasData) { if (item.Relationship.RelationInfo.MoreThanOneFkForEachPK == false) { originalType = Enum_OrginalRelationshipType.OneToOne; } else { originalType = Enum_OrginalRelationshipType.OneToMany; } } else { originalType = Enum_OrginalRelationshipType.OneToMany; } } if (originalType == Enum_OrginalRelationshipType.SuperToSub) { item.Relationship.OrginalTypeEnum = Enum_OrginalRelationshipType.SuperToSub; if (isaKeys.ContainsKey(item.Relationship.Entity1)) { item.Relationship.OrginalRelationshipGroup = isaKeys[item.Relationship.Entity1]; } else { var key = "ISA_OnPK_" + item.Relationship.Entity1; isaKeys.Add(item.Relationship.Entity1, key); item.Relationship.OrginalRelationshipGroup = key; } } else if (originalType == Enum_OrginalRelationshipType.OneToOne) { bool otoCondition = false; if (item.Relationship.RelationInfo.FKHasData == true) { //این شرط جدید اضافه شد. برای اینکه اگر کلید خارجی جزو پرایمری ها باشد معلوم است که ارتباط چند به چند یا مالکیت منظور بوده است if (!item.Relationship.RelationshipColumns.Any(x => x.SecondSideColumn.PrimaryKey)) { long relcount = dataHelper.GetRelationDataCount(fkEntity, item.Relationship); if (relcount > 10) { long fkcount = dataHelper.GetDataCount(fkEntity); long pkcount = dataHelper.GetDataCount(pkEntity); long biggerCount = 0; long smallerCount = 0; if (fkcount >= pkcount) { biggerCount = fkcount; smallerCount = pkcount; } else { biggerCount = pkcount; smallerCount = fkcount; } //if (pkcount > relcount) //{ if (biggerCount > 50000) { if (relcount >= biggerCount / 10) { otoCondition = true; } } else if (pkcount > 10000) { if (relcount >= biggerCount / 5) { otoCondition = true; } } else if (pkcount > 2000) { if (relcount >= biggerCount / 2.5) { otoCondition = true; } } else { if (relcount >= biggerCount / 1.5) { otoCondition = true; } } } //} //else //{ // if(relcount>10) // otoCondition = true; //} } } if (otoCondition) { item.Relationship.OrginalTypeEnum = Enum_OrginalRelationshipType.OneToOne; } else { item.Relationship.OrginalTypeEnum = Enum_OrginalRelationshipType.OneToMany; } } else { item.Relationship.OrginalTypeEnum = Enum_OrginalRelationshipType.OneToMany; } //} } })); }
public LetterDeleteResult DeleteLetter(DR_Requester requester, int letterID) { LetterDeleteResult result = new LetterDeleteResult(); string exception = ""; using (var context = new MyIdeaDataDBEntities()) { //سکوریتی ثبت میتونه اینجا هم چک بشه //itemResult.ID = item.ID; var dbItem = context.Letter.First(x => x.ID == letterID); BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); if (!bizTableDrivedEntity.DataIsAccessable(requester, dbItem.MyDataItem.TableDrivedEntityID, new List <SecurityAction>() { SecurityAction.LetterEdit })) { throw new Exception("عدم دسترسی ثبت نامه"); } try { if (dbItem.Letter1.Any()) { foreach (var item in dbItem.Letter1) { ResultDetail relatedItemException = new ResultDetail(); relatedItemException.Title = "دارای نامه مرتبط"; relatedItemException.Description = "نامه به شماره" + " " + item.LetterNumber + " " + "به تاریخ" + " " + item.LetterDate; result.Details.Add(relatedItemException); } result.Message = "به علت وجود نامه های مرتبط عملیات حذف امکان پذیر نمی باشد"; return(result); } context.Letter.Remove(dbItem); context.SaveChanges(); result.Result = true; result.Message = "عملیات حذف با موفقیت انجام شد"; } catch (Exception ex) { exception = ex.Message; ResultDetail itemResult = new ResultDetail(); itemResult.Title = "خطا"; itemResult.Description = "حذف نامه با شناسه" + " " + letterID + " " + "با خطا همراه بود"; itemResult.TechnicalDescription = ex.Message; result.Details.Add(itemResult); result.Message = "عملیات حذف با خطا همراه بود"; } finally { var logResult = bizLogManager.AddLog(GetDeleteItemDataLog(dbItem, exception), requester); if (!string.IsNullOrEmpty(logResult)) { ResultDetail logException = new ResultDetail(); logException.Title = "خطای ثبت لاگ"; logException.Description = "ثبت لاگ برای حذف فایل با شناسه" + " " + dbItem.ID + " " + "با خطا همراه بود"; logException.TechnicalDescription = logResult; result.Details.Add(logException); } } } return(result); }