internal static IEnumerable <Model.Common.ArchiveGroup> GetChildArchiveGroups(int archiveGroupID) { List <Model.Common.ArchiveGroup> list = new List <Model.Common.ArchiveGroup>(); Model.Common.ArchiveCommonDataClassesDataContext dc = new Model.Common.ArchiveCommonDataClassesDataContext(Setting.Sql.ThisProgram.DatabaseConnection.ConnectionString); Model.Common.ArchiveGroup archiveGroup = dc.ArchiveGroups.Where(t => t.ID == archiveGroupID).Single(); AddChildArchiveGroupsToList(dc, list, archiveGroup); return(list); }
private static void AddChildArchiveGroupsToList(Model.Common.ArchiveCommonDataClassesDataContext dc, List <Model.Common.ArchiveGroup> list, Model.Common.ArchiveGroup archiveGroup) { foreach (var item in dc.ArchiveGroups.Where(t => t.ParentID == archiveGroup.ID)) { list.Add(item); AddChildArchiveGroupsToList(dc, list, item); } }
private static void AddBaseArchiveGroupTabsToList(List <Model.Common.ArchiveGroup> list, Model.Common.ArchiveGroup archiveGroup) { if (archiveGroup.ParentID.HasValue) { list.Add(archiveGroup.ArchiveGroup1); AddBaseArchiveGroupTabsToList(list, archiveGroup.ArchiveGroup1); } }
private void toolStripItemClick(object sender, EventArgs e) { #region AddArchiveGroup if (sender == toolStripMenuItemAddArchiveGroup) { Model.Common.ArchiveCommonDataClassesDataContext dc = new Model.Common.ArchiveCommonDataClassesDataContext(Setting.Sql.ThisProgram.DatabaseConnection.ConnectionString); dc.Connection.Open(); dc.Transaction = dc.Connection.BeginTransaction(); try { Model.Common.ArchiveGroup archiveGroup = Model.Common.ArchiveGroup.GetNewInstance("گروه بایگانی جدید", this.SelectedNode == null ? null : (this.SelectedNode.Tag as Model.Common.ArchiveTree).ArchiveGroupID); dc.ArchiveGroups.InsertOnSubmit(archiveGroup); dc.SubmitChanges(); Model.Common.ArchiveTree groupTree = Model.Common.ArchiveTree.GetNewInstance(null, archiveGroup.ID, null, null, null, this.SelectedNode == null ? null : (int?)(this.SelectedNode.Tag as Model.Common.ArchiveTree).ID, this.SelectedNode == null ? GetMaxIndex(this.Nodes) + 1 : GetMaxIndex(this.SelectedNode.Nodes) + 1); dc.ArchiveTrees.InsertOnSubmit(groupTree); dc.SubmitChanges(); TreeNode node = AddNode(this.SelectedNode == null ? null : this.SelectedNode, groupTree); this.SelectedNode = node; node.EnsureVisible(); node.BeginEdit(); } catch (Exception ex) { dc.Transaction.Rollback(); dc.Connection.Close(); PersianMessageBox.Show(this, "خطا در ثبت اطلاعات" + "\r\n\r\n" + ex.Message); return; } dc.Transaction.Commit(); dc.Connection.Close(); } #endregion #region AddArchive else if (sender == toolStripMenuItemAddArchive) { try { int maxArchiveCount = Setting.Program.MaxArchiveCount(); if (Controller.Common.ArchiveController.GetActiveArchivesCount() >= maxArchiveCount) { PersianMessageBox.Show(this, "امکان تعریف بیش از " + maxArchiveCount.ToString() + " بایگانی وجود ندارد"); return; } View.ArchiveManageForms.ArchiveAdd _ArchiveAddForm = new View.ArchiveManageForms.ArchiveAdd(); if (_ArchiveAddForm.ShowDialog() != DialogResult.OK) { return; } Model.Common.ArchiveTree groupTree = Controller.Common.ArchiveController.AddArchive(this.SelectedNode == null ? null : (this.SelectedNode.Tag as Model.Common.ArchiveTree).ArchiveGroupID, _ArchiveAddForm.SelectedDatabasePath, _ArchiveAddForm.UseDatabase, _ArchiveAddForm.SelectedDocumentsPathOrDatabasePath, this.SelectedNode == null ? GetMaxIndex(this.Nodes) + 1 : GetMaxIndex(this.SelectedNode.Nodes) + 1, this.SelectedNode == null ? null : (int?)(this.SelectedNode.Tag as Model.Common.ArchiveTree).ID); TreeNode node = AddNode(this.SelectedNode == null ? null : this.SelectedNode, groupTree); this.SelectedNode = node; node.EnsureVisible(); node.BeginEdit(); } catch (Exception ex) { PersianMessageBox.Show(this, "خطا" + "\r\n" + ex.Message); } } #endregion #region AddFilter else if (sender == toolStripMenuItemAddFilter) { Model.Common.ArchiveCommonDataClassesDataContext dc = new Model.Common.ArchiveCommonDataClassesDataContext(Setting.Sql.ThisProgram.DatabaseConnection.ConnectionString); dc.Connection.Open(); dc.Transaction = dc.Connection.BeginTransaction(); try { } catch (Exception ex) { dc.Transaction.Rollback(); dc.Connection.Close(); PersianMessageBox.Show(this, "خطا در ثبت اطلاعات" + "\r\n\r\n" + ex.Message); return; } dc.Transaction.Commit(); dc.Connection.Close(); } #endregion #region AddGroupBy else if (sender == toolStripMenuItemAddGroupBy) { Model.Common.ArchiveCommonDataClassesDataContext dc = new Model.Common.ArchiveCommonDataClassesDataContext(Setting.Sql.ThisProgram.DatabaseConnection.ConnectionString); dc.Connection.Open(); dc.Transaction = dc.Connection.BeginTransaction(); try { } catch (Exception ex) { dc.Transaction.Rollback(); dc.Connection.Close(); PersianMessageBox.Show(this, "خطا در ثبت اطلاعات" + "\r\n\r\n" + ex.Message); return; } dc.Transaction.Commit(); dc.Connection.Close(); } #endregion #region AddNode else if (sender == toolStripMenuItemAddNode) { Model.Common.ArchiveCommonDataClassesDataContext dc = new Model.Common.ArchiveCommonDataClassesDataContext(Setting.Sql.ThisProgram.DatabaseConnection.ConnectionString); dc.Connection.Open(); dc.Transaction = dc.Connection.BeginTransaction(); try { Model.Common.ArchiveTree groupTree = Model.Common.ArchiveTree.GetNewInstance("گروه جدید", null, null, null, null, this.SelectedNode == null ? null : (int?)(this.SelectedNode.Tag as Model.Common.ArchiveTree).ID, this.SelectedNode == null ? GetMaxIndex(this.Nodes) + 1 : GetMaxIndex(this.SelectedNode.Nodes) + 1); dc.ArchiveTrees.InsertOnSubmit(groupTree); dc.SubmitChanges(); TreeNode node = AddNode(this.SelectedNode == null ? null : this.SelectedNode, groupTree); this.SelectedNode = node; node.EnsureVisible(); node.BeginEdit(); } catch (Exception ex) { dc.Transaction.Rollback(); dc.Connection.Close(); PersianMessageBox.Show(this, "خطا در ثبت اطلاعات" + "\r\n\r\n" + ex.Message); return; } dc.Transaction.Commit(); dc.Connection.Close(); } #endregion #region Rename else if (sender == toolStripMenuItemRename) { this.SelectedNode.BeginEdit(); } #endregion #region Delete else if (sender == toolStripMenuItemDelete) { if (this.SelectedNode.Nodes.Count > 0) { PersianMessageBox.Show(this, "فقط گره های خالی را می توانید حذف کنید"); return; } Model.Common.ArchiveTree groupTree = this.SelectedNode.Tag as Model.Common.ArchiveTree; string title = null; string groupTreeType = null; switch (groupTree.GetNodeType()) { case NjitSoftware.Model.Common.ArchiveTree.NodeTypes.Node: title = groupTree.Title; groupTreeType = null; break; case NjitSoftware.Model.Common.ArchiveTree.NodeTypes.ArchiveGroup: title = groupTree.ArchiveGroup.Title; groupTreeType = "گروه بایگانی"; break; case NjitSoftware.Model.Common.ArchiveTree.NodeTypes.Archive: title = groupTree.Archive.Title; groupTreeType = "بایگانی"; break; case NjitSoftware.Model.Common.ArchiveTree.NodeTypes.Filter: title = groupTree.Title; groupTreeType = "فیلتر"; break; case NjitSoftware.Model.Common.ArchiveTree.NodeTypes.GroupBy: title = groupTree.Title; groupTreeType = "گروه بندی"; break; } if (groupTreeType != null) { var result = PersianMessageBox.Show(this, string.Format("{0} '{1}' حذف شود؟", groupTreeType, title), "تایید حذف", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result != DialogResult.Yes) { return; } } Model.Common.ArchiveCommonDataClassesDataContext dc = new Model.Common.ArchiveCommonDataClassesDataContext(Setting.Sql.ThisProgram.DatabaseConnection.ConnectionString); dc.Connection.Open(); dc.Transaction = dc.Connection.BeginTransaction(); try { switch (groupTree.GetNodeType()) { case Model.Common.ArchiveTree.NodeTypes.Node: dc.ArchiveTrees.DeleteAllOnSubmit(dc.ArchiveTrees.Where(t => t.ID == groupTree.ID)); dc.SubmitChanges(); break; case Model.Common.ArchiveTree.NodeTypes.ArchiveGroup: dc.ArchiveTrees.DeleteAllOnSubmit(dc.ArchiveTrees.Where(t => t.ID == groupTree.ID)); dc.SubmitChanges(); var fields = dc.ArchiveGroupFields.Where(t => t.ArchiveGroupID == groupTree.ArchiveGroupID); var tabs = dc.ArchiveGroupTabs.Where(t => t.ArchiveGroupID == groupTree.ArchiveGroupID); dc.ArchiveGroupFields.DeleteAllOnSubmit(fields); dc.SubmitChanges(); dc.ArchiveGroupTabs.DeleteAllOnSubmit(tabs); dc.SubmitChanges(); dc.ArchiveGroups.DeleteAllOnSubmit(dc.ArchiveGroups.Where(t => t.ID == groupTree.ArchiveGroupID)); dc.SubmitChanges(); break; case Model.Common.ArchiveTree.NodeTypes.Archive: dc.ArchiveTrees.DeleteAllOnSubmit(dc.ArchiveTrees.Where(t => t.ID == groupTree.ID)); dc.SubmitChanges(); var archive = dc.Archives.Where(t => t.ID == groupTree.ArchiveID); foreach (var item in archive) { item.Active = false; } dc.SubmitChanges(); break; case Model.Common.ArchiveTree.NodeTypes.Filter: dc.ArchiveTrees.DeleteAllOnSubmit(dc.ArchiveTrees.Where(t => t.ID == groupTree.ID)); dc.SubmitChanges(); break; case Model.Common.ArchiveTree.NodeTypes.GroupBy: dc.ArchiveTrees.DeleteAllOnSubmit(dc.ArchiveTrees.Where(t => t.ID == groupTree.ID)); dc.SubmitChanges(); break; default: throw new Exception(); } Controller.Common.AccessPermissionTree.SaveArchivesTrees(dc); } catch (Exception ex) { dc.Transaction.Rollback(); dc.Connection.Close(); PersianMessageBox.Show(this, "خطا در حذف" + "\r\n\r\n" + ex.Message); return; } dc.Transaction.Commit(); dc.Connection.Close(); TreeNode node = this.SelectedNode; this.SelectedNode = (node.PrevNode ?? node.NextNode) ?? node.Parent; node.Remove(); } #endregion #region AddToNewGroup else if (sender == toolStripMenuItemAddToNewGroup) { Model.Common.ArchiveCommonDataClassesDataContext dc = new Model.Common.ArchiveCommonDataClassesDataContext(Setting.Sql.ThisProgram.DatabaseConnection.ConnectionString); dc.Connection.Open(); dc.Transaction = dc.Connection.BeginTransaction(); try { Model.Common.ArchiveTree groupTree = Model.Common.ArchiveTree.GetNewInstance("گروه جدید", null, null, null, null, this.SelectedNode.Parent == null ? null : (int?)(this.SelectedNode.Parent.Tag as Model.Common.ArchiveTree).ID, this.SelectedNode.Parent == null ? GetMaxIndex(this.Nodes) + 1 : GetMaxIndex(this.SelectedNode.Parent.Nodes) + 1); dc.ArchiveTrees.InsertOnSubmit(groupTree); dc.SubmitChanges(); foreach (var item in dc.ArchiveTrees.Where(t => t.ID == (this.SelectedNode.Tag as Model.Common.ArchiveTree).ID)) { item.ParentID = groupTree.ID; } dc.SubmitChanges(); TreeNode node = AddNode(this.SelectedNode.Parent == null ? null : this.SelectedNode.Parent, groupTree); TreeNode currentNode = this.SelectedNode; currentNode.Remove(); node.Nodes.Add(currentNode); this.SelectedNode = node; node.Expand(); node.EnsureVisible(); node.BeginEdit(); } catch (Exception ex) { dc.Transaction.Rollback(); dc.Connection.Close(); PersianMessageBox.Show(this, "خطا در ثبت اطلاعات" + "\r\n\r\n" + ex.Message); return; } dc.Transaction.Commit(); dc.Connection.Close(); } else if (sender == toolStripMenuItemAddArchiveGroupTab) { try { NjitSoftware.Model.Common.ArchiveTree T = (NjitSoftware.Model.Common.ArchiveTree) this.SelectedNode.Tag; new View.ArchiveManageForms.ArchiveGroupTab(T.ArchiveGroupID.Value, 1).ShowDialog(); } catch (Exception ex) { PersianMessageBox.Show(this, "خطا در نمایش فرم مدیریت گروه های اطلاعاتی" + "\r\n\r\n" + ex.Message); return; } } #endregion }