Beispiel #1
0
        private TreeNode AddNode(TreeNode node, Model.Common.ArchiveTree item)
        {
            TreeNode newNode = new TreeNode();
            string   title;

            if (item.GroupBy != null)
            {
                title = item.GroupBy;
            }
            else if (item.Filter != null)
            {
                title = item.Filter;
            }
            else if (item.Archive != null)
            {
                title = item.Archive.Title;
            }
            else if (item.ArchiveGroup != null)
            {
                title = item.ArchiveGroup.Title;
            }
            else if (item.Title != null)
            {
                title = item.Title;
            }
            else
            {
                title = "";
            }
            newNode.Text             = title;
            newNode.Tag              = item;
            newNode.Name             = item.ID.ToString();
            newNode.SelectedImageKey = newNode.ImageKey = Enum.GetName(typeof(Model.Common.ArchiveTree.NodeTypes), item.GetNodeType());
            if (node == null)
            {
                this.Nodes.Add(newNode);
            }
            else
            {
                node.Nodes.Add(newNode);
            }
            if (item.GetNodeType() == Model.Common.ArchiveTree.NodeTypes.GroupBy)
            {
                IEnumerable <string> groupItems = GetGroupItems(item.ArchiveID.Value, item.GroupBy);
                if (groupItems != null)
                {
                    foreach (string groupItem in groupItems)
                    {
                        Model.Common.ArchiveTree newArchiveTree = Model.Common.ArchiveTree.GetNewInstance(groupItem, item.ArchiveGroupID, item.ArchiveID, item.GroupBy + "=" + groupItem, null, item.ID, 0);
                        AddNode(node, newArchiveTree);
                    }
                }
            }
            return(newNode);
        }
Beispiel #2
0
        private void LoadArchive()
        {
            Model.Common.ArchiveTree           groupTree = archiveTreeView.SelectedNode.Tag as Model.Common.ArchiveTree;
            Model.Common.ArchiveTree.NodeTypes nodeType  = groupTree.GetNodeType();
            switch (nodeType)
            {
            case Model.Common.ArchiveTree.NodeTypes.Node:
            case Model.Common.ArchiveTree.NodeTypes.ArchiveGroup:
                return;

            case Model.Common.ArchiveTree.NodeTypes.Archive:
            case Model.Common.ArchiveTree.NodeTypes.Filter:
            case Model.Common.ArchiveTree.NodeTypes.GroupBy:
                break;

            default:
                throw new Exception();
            }
            if (!Setting.User.ThisProgram.CheckUserAccessPermission(Setting.User.AccessPermissionUnits.Archive, groupTree.Archive.ID.ToString()))
            {
                PersianMessageBox.Show(this, string.Format("مجوز دسترسی به بایگانی '{0}' برای شما صادر نشده است", groupTree.Archive.Title));
                return;
            }
            this.State = FormWindowState.Minimized;
            Setting.Archive.ThisProgram.SelectedArchiveTree = groupTree;

            //نمایش اینکه سندی دارد که بهش اعلام خرابی کرده باشند در این بایگانی
            int Count = checkDocumentFailure(groupTree.ArchiveID);

            if (Count != 0)
            {
                var dialogResult = PersianMessageBox.Show(this, "تعداد اسناد خراب گزارش شده برابر است با: " + Count + "مایل به مشاهده گزارش لیست اسناد خراب هستید؟", "تایید ", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                {
                    View.DocumentFailure df = new DocumentFailure();
                    df.Show(this);
                }
            }
            //نمایش پروندهایی که به امانت رفته اما پس داده نشده است
            string _DossiersNumber = CheckLending();

            if (_DossiersNumber != "")
            {
                var dialogResult = PersianMessageBox.Show(this, "پرونده های شماره: " + _DossiersNumber + "زمان اتمام امانتشان به اتمام رسیده است  مایل به مشاهده لیست پرونده های امانت گرفته شده هستید؟", "تایید ", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                {
                    View.LendingManageForms.LendingList df = new LendingManageForms.LendingList();
                    df.Show(this);
                }
            }
            //آیا اضافه کردن اطلاعات دانشجو را داشته باشد یا خیر ؟
        }
Beispiel #3
0
        private int GetMaxIndex(TreeNodeCollection treeNodeCollection)
        {
            int max = 0;

            foreach (TreeNode item in treeNodeCollection)
            {
                Model.Common.ArchiveTree gt = item.Tag as Model.Common.ArchiveTree;
                if (gt.Index > max)
                {
                    max = gt.Index;
                }
            }
            return(max);
        }
Beispiel #4
0
        protected override void OnItemDrag(ItemDragEventArgs e)
        {
            base.OnItemDrag(e);
            TreeNode treeNode = e.Item as TreeNode;

            if (treeNode != null)
            {
                Model.Common.ArchiveTree groupTree = treeNode.Tag as Model.Common.ArchiveTree;
                if (groupTree != null)
                {
                    if (groupTree.GetNodeType() == Model.Common.ArchiveTree.NodeTypes.Node || groupTree.GetNodeType() == Model.Common.ArchiveTree.NodeTypes.ArchiveGroup)
                    {
                        this.DoDragDrop(e.Item, DragDropEffects.All);
                    }
                }
            }
        }
Beispiel #5
0
        private void archiveTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (archiveTreeView.SelectedNode == null)
            {
                return;
            }
            Model.Common.ArchiveTree           groupTree = archiveTreeView.SelectedNode.Tag as Model.Common.ArchiveTree;
            Model.Common.ArchiveTree.NodeTypes nodeType  = groupTree.GetNodeType();
            switch (nodeType)
            {
            case Model.Common.ArchiveTree.NodeTypes.Node:
            case Model.Common.ArchiveTree.NodeTypes.ArchiveGroup:
                return;

            case Model.Common.ArchiveTree.NodeTypes.Archive:
            case Model.Common.ArchiveTree.NodeTypes.Filter:
            case Model.Common.ArchiveTree.NodeTypes.GroupBy:
                break;

            default:
                throw new Exception();
            }
            Setting.Archive.ThisProgram.SelectedArchiveTree = groupTree;
        }
Beispiel #6
0
        protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e)
        {
            base.OnAfterLabelEdit(e);
            if (e.Label != null)
            {
                Model.Common.ArchiveTree groupTree = e.Node.Tag as Model.Common.ArchiveTree;
                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.Filter:
                    case Model.Common.ArchiveTree.NodeTypes.GroupBy:
                    case Model.Common.ArchiveTree.NodeTypes.Node:
                        groupTree.Title = e.Label;
                        var data1 = dc.ArchiveTrees.Where(t => t.ID == groupTree.ID);
                        foreach (var item in data1)
                        {
                            item.Title = e.Label;
                        }
                        dc.SubmitChanges();
                        break;

                    case Model.Common.ArchiveTree.NodeTypes.ArchiveGroup:
                        groupTree.ArchiveGroup.Title = e.Label;
                        var data2 = dc.ArchiveGroups.Where(t => t.ID == groupTree.ArchiveGroupID);
                        foreach (var item in data2)
                        {
                            item.Title = e.Label;
                        }
                        dc.SubmitChanges();
                        break;

                    case Model.Common.ArchiveTree.NodeTypes.Archive:
                        string originalArchiveTitle = groupTree.Archive.Title;
                        groupTree.Archive.Title = e.Label;
                        var data3 = dc.Archives.Where(t => t.ID == groupTree.ArchiveID);
                        foreach (var item in data3)
                        {
                            item.Title = e.Label;
                        }
                        dc.SubmitChanges();
                        try
                        {
                            Setting.User.ThisProgram.AddLog(dc, Setting.User.UserOparatesPlaceNames.بایگانی, Setting.User.UserOparatesNames.ویرایش, "", "تغییر نام بایگانی '" + originalArchiveTitle + "' به '" + e.Label + "'");
                        }
                        catch
                        {
                            throw new Exception("خطا در ذخیره عملکرد کاربر جاری");
                        }
                        Controller.Common.AccessPermissionTree.SaveArchivesTrees(dc);
                        break;

                    default:
                        throw new Exception();
                    }
                }
                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();
            }
        }
Beispiel #7
0
        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            base.OnDragDrop(drgevent);
            if (drgevent.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                TreeNode destinationNode = this.GetNodeAt(this.PointToClient(new Point(drgevent.X, drgevent.Y)));
                TreeNode dragedNode      = (TreeNode)drgevent.Data.GetData("System.Windows.Forms.TreeNode");
                if (drgevent.Effect == DragDropEffects.Move)
                {
                    Model.Common.ArchiveCommonDataClassesDataContext dc = new Model.Common.ArchiveCommonDataClassesDataContext(Setting.Sql.ThisProgram.DatabaseConnection.ConnectionString);
                    dc.Connection.Open();
                    dc.Transaction = dc.Connection.BeginTransaction();
                    try
                    {
                        if (destinationNode != null)
                        {
                            Model.Common.ArchiveTree destinationNodeTree = destinationNode.Tag as Model.Common.ArchiveTree;
                            Model.Common.ArchiveTree dragedNodeTree      = dragedNode.Tag as Model.Common.ArchiveTree;
                            foreach (var item in dc.ArchiveTrees.Where(t => t.ID == dragedNodeTree.ID))
                            {
                                item.ParentID = destinationNodeTree.ID;
                                item.Index    = GetMaxIndex(destinationNode.Nodes) + 1;
                            }
                        }
                        else
                        {
                            Model.Common.ArchiveTree dragedNodeTree = dragedNode.Tag as Model.Common.ArchiveTree;
                            foreach (var item in dc.ArchiveTrees.Where(t => t.ID == dragedNodeTree.ID))
                            {
                                item.ParentID = null;
                                item.Index    = GetMaxIndex(this.Nodes) + 1;
                            }
                        }
                        dc.SubmitChanges();
                    }
                    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();

                    dragedNode.Remove();
                    if (destinationNode != null)
                    {
                        destinationNode.Nodes.Add(dragedNode);
                    }
                    else
                    {
                        this.Nodes.Add(dragedNode);
                    }

                    this.SelectedNode = dragedNode;

                    dragedNode.EnsureVisible();
                }
                else if (drgevent.Effect == DragDropEffects.Copy)
                {
                    Model.Common.ArchiveTree destinationNodeTree = (destinationNode.Tag as Model.Common.ArchiveTree);
                    Model.Common.ArchiveTree dragedNodeTree      = (dragedNode.Tag as Model.Common.ArchiveTree);

                    int temp = dragedNodeTree.Index;
                    dragedNodeTree.Index      = destinationNodeTree.Index;
                    destinationNodeTree.Index = temp;

                    Model.Common.ArchiveCommonDataClassesDataContext dc = new Model.Common.ArchiveCommonDataClassesDataContext(Setting.Sql.ThisProgram.DatabaseConnection.ConnectionString);
                    dc.Connection.Open();
                    dc.Transaction = dc.Connection.BeginTransaction();
                    try
                    {
                        foreach (var item in dc.ArchiveTrees.Where(t => t.ID == dragedNodeTree.ID))
                        {
                            item.Index = dragedNodeTree.Index;
                        }
                        foreach (var item in dc.ArchiveTrees.Where(t => t.ID == destinationNodeTree.ID))
                        {
                            item.Index = destinationNodeTree.Index;
                        }
                        dc.SubmitChanges();
                    }
                    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();

                    this.SelectedNode = dragedNode;
                    dragedNode.EnsureVisible();
                    LoadData();
                }
            }
        }
Beispiel #8
0
 private void AddNodes(TreeNode node, IEnumerable <Model.Common.ArchiveTree> groupTrees, Model.Common.ArchiveTree groupTree)
 {
     foreach (var i in groupTrees.Where(t => t.ParentID == groupTree.ID).OrderBy(t => t.Index))
     {
         TreeNode newnode = AddNode(node, i);
         AddNodes(newnode, groupTrees, i);
     }
 }
Beispiel #9
0
        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
        }
Beispiel #10
0
        internal static Model.Common.ArchiveTree AddArchive(int?archiveGroupID, string databasePath, bool useDatabaseForSaveDocuments, string dcumentsPathOrDatabasePath, int index, int?parentID)
        {
            Model.Common.ArchiveCommonDataClassesDataContext dc        = new Model.Common.ArchiveCommonDataClassesDataContext(Setting.Sql.ThisProgram.DatabaseConnection.ConnectionString);
            Model.Archive.ArchiveDataClassesDataContext      archiveDc = null;

            dc.Connection.Open();
            dc.Transaction = dc.Connection.BeginTransaction();
            try
            {
                Model.Common.Archive archive = Model.Common.Archive.GetNewInstance("", "بایگانی جدید", databasePath, true, false, archiveGroupID);
                dc.Archives.InsertOnSubmit(archive);
                dc.SubmitChanges();

                Model.Common.Archive originalArchive = dc.Archives.Where(t => t.ID == archive.ID).Single();

                SqlHelper.CreateArchive(dc, originalArchive, databasePath);

                Model.Common.ArchiveTree groupTree = Model.Common.ArchiveTree.GetNewInstance(null, null, archive.ID, null, null, parentID, index);
                dc.ArchiveTrees.InsertOnSubmit(groupTree);
                dc.SubmitChanges();

                string archiveDocumentDatabaseOrFilesPath;
                if (useDatabaseForSaveDocuments)
                {
                    archiveDocumentDatabaseOrFilesPath = SqlHelper.CreateArchiveDocumnetDatabase(dc, dcumentsPathOrDatabasePath);
                }
                else
                {
                    archiveDocumentDatabaseOrFilesPath = dcumentsPathOrDatabasePath;
                }

                archiveDc = new Model.Archive.ArchiveDataClassesDataContext(Setting.Sql.ThisProgram.GetDatabaseConnection(originalArchive.Name).ConnectionString);
                archiveDc.Connection.Open();
                archiveDc.Transaction = archiveDc.Connection.BeginTransaction();

                NjitSoftware.Model.Archive.ArchiveSetting archiveSettingInstance = NjitSoftware.Model.Archive.ArchiveSetting.GetNewInstance(null, null, false, "نام سازمان", null, archiveDocumentDatabaseOrFilesPath, "شماره پرسنلی", 0, 1000, true, useDatabaseForSaveDocuments, useDatabaseForSaveDocuments ? dcumentsPathOrDatabasePath : null, "", null, null, 0);
                var archiveSettingsQuery = archiveDc.ArchiveSettings.Select(t => t);
                if (archiveSettingsQuery.Count() > 0)
                {
                    NjitSoftware.Model.Archive.ArchiveSetting original = archiveSettingsQuery.First();
                    NjitSoftware.Model.Archive.ArchiveSetting.Copy(original, archiveSettingInstance);
                }
                else
                {
                    NjitSoftware.Model.Archive.ArchiveSetting.Insert(archiveDc, archiveSettingInstance);
                }
                archiveDc.SubmitChanges();
                if (useDatabaseForSaveDocuments)
                {
                    Model.Archive.DocumentSaveLocation _DocumentSaveLocation = Model.Archive.DocumentSaveLocation.GetNewInstance("پایگاه داده شماره یک", archiveDocumentDatabaseOrFilesPath, true);
                    archiveDc.DocumentSaveLocations.InsertOnSubmit(_DocumentSaveLocation);
                    archiveDc.SubmitChanges();
                }
                if (archiveGroupID.HasValue)
                {
                    List <Model.Common.ArchiveGroupTab> archiveGroupTabs = Controller.Common.ArchiveGroupTabController.GetAllSelfAndBaseArchiveGroupTabs(archiveGroupID.Value);
                    foreach (var tab in archiveGroupTabs)
                    {
                        Controller.Common.ArchiveGroupTabController.AddArchiveTabToArchive(tab, dc, archiveDc);
                    }
                }
                Controller.Common.AccessPermissionTree.SaveArchivesTrees(dc);

                try
                {
                    Setting.User.ThisProgram.AddLog(Setting.User.UserOparatesPlaceNames.بایگانی, Setting.User.UserOparatesNames.افزودن, null, "افزودن بایگانی '" + archive.Title + "'");
                }
                catch
                {
                    throw new Exception("خطا در ذخیره عملکرد کاربر جاری");
                }

                if (archiveDc != null)
                {
                    archiveDc.Transaction.Commit();
                }
                dc.Transaction.Commit();
                return(groupTree);
            }
            catch (Exception ex)
            {
                if (archiveDc != null)
                {
                    archiveDc.Transaction.Rollback();
                }
                dc.Transaction.Rollback();
                throw new Exception("خطا در ثبت اطلاعات" + "\r\n\r\n" + ex.Message);
            }
            finally
            {
                if (archiveDc != null)
                {
                    archiveDc.Connection.Close();
                }
                dc.Connection.Close();
            }
        }