Пример #1
0
        /// <summary>
        /// Создание новой папки в работе
        /// </summary>
        /// <param name="parentNode">Родитель</param>
        /// <param name="newFolderName">Имя новой папки</param>
        /// <returns>Новая папка</returns>
        public static WorkFolderNode CreateNewFolder(WorkFolderNode parentNode, string newFolderName)
        {
            if (parentNode != null)
            {
                try
                {
                    int result = Environment.FolderData.New(parentNode.ID, newFolderName);
                    if (result != 0)
                    {
                        var newNode = new WorkFolderNode(result, newFolderName, parentNode.Emp);

                        parentNode.Nodes.Add(newNode);
                        newNode.RemoveBold();
                        newNode.EnsureVisible();
                        return(newNode);
                    }
                }
                catch (Exception ex)
                {
                    Lib.Win.Data.Env.WriteToLog(ex);
                }
            }

            return(parentNode);
        }
Пример #2
0
        public WorkFolderNode AddExistingFolder(int nodeID, int empID)
        {
            if (nodeID <= 0)
            {
                return(null);
            }
            try
            {
                DataRow dr = Environment.WorkFolderData(nodeID, empID);
                if (dr == null)
                {
                    Environment.ReloadReadData();
                    dr = Environment.WorkFolderData(nodeID, empID);
                }

                WorkFolderNode newNode = null;

                if (dr != null)
                {
                    int parentID = (int)dr[Environment.FolderData.ParentField];

                    WorkFolderNode parentNode = ContainsByID(parentID, empID)
                                                    ? GetByID(parentID, empID)
                                                    : AddExistingFolder(parentID, empID);

                    if (parentNode != null)
                    {
                        newNode = new WorkFolderNode(nodeID, (string)dr[Environment.FolderData.NameField], parentNode.Emp);

                        parentNode.Nodes.Add(newNode);
                        newNode.RemoveBold();
                    }
                    else
                    {
                        Lib.Win.Data.Env.WriteToLog("parentNode == null");
                    }
                }
                else
                {
                    Lib.Win.Data.Env.WriteToLog("dr == null");
                }

                return(newNode);
            }
            catch (Exception ex)
            {
                Lib.Win.Data.Env.WriteToLog(ex);
            }

            return(null);
        }
Пример #3
0
        private WorkFolderNode Populate(DataRow dr, DataRelation rel)
        {
            WorkFolderNode node = new WorkFolderNode(
                (int)dr[Environment.FolderData.IDField],                 // id
                (string)dr[Environment.FolderData.NameField],            // text
                Emp);

            foreach (DataRow row in dr.GetChildRows(rel))
            {
                WorkFolderNode newNode = Populate(row, rel);
                node.Nodes.Add(newNode);
            }

            return(node);
        }
Пример #4
0
        private void NewItemDialog_DialogEvent(object source, Kesco.Lib.Win.DialogEventArgs e)
        {
            Kesco.Lib.Win.Document.EnterStringDialog dialog = e.Dialog as Kesco.Lib.Win.Document.EnterStringDialog;
            if (dialog == null || dialog.DialogResult != DialogResult.OK)
            {
                return;
            }

            string folderName = dialog.Input;
            int    result     = Environment.FolderData.New(ID, folderName);

            if (result != 0)
            {
                var newNode = new WorkFolderNode(result, folderName, Emp);

                Nodes.Add(newNode);
                newNode.RemoveBold();
                newNode.EnsureVisible();
                TreeView.SelectedNode = newNode;
            }
        }
Пример #5
0
        /// <summary>
        ///   Получает папку ВРаботе укзанным id
        /// </summary>
        /// <param name="id"> Код папки </param>
        /// <param name="empID"> Код сотрудника </param>
        public WorkFolderNode GetByID(int id, int empID)
        {
            WorkFolderNode result = null;

            for (int i = 0; i < Nodes.Count && result == null; i++)
            {
                WorkFolderNode wfnode = Nodes[i] as WorkFolderNode;
                if (wfnode != null)
                {
                    if (wfnode.ID == id && wfnode.Emp.ID == empID)
                    {
                        result = wfnode;
                    }
                    else
                    {
                        result = wfnode.GetByID(id, empID);
                    }
                }
            }
            return(result);
        }
Пример #6
0
        public override void LoadSubNodes()
        {
            Nodes.Clear();
            if (TreeView != null)
            {
                TreeView.Cursor = Cursors.WaitCursor;
            }
            CancellationToken ct   = source.Token;
            Task <DataSet>    task = System.Threading.Tasks.Task <DataSet> .Factory.StartNew(() => { return(Environment.FolderData.GetFolders(Emp.ID, ct)); }, ct);

            Task taskc = System.Threading.Tasks.Task.Factory.ContinueWhenAny <DataSet>(new Task <DataSet>[] { task }, (taskC) =>
            {
                if (taskC.Status != TaskStatus.RanToCompletion)
                {
                    return;
                }
                if (ct.IsCancellationRequested)
                {
                    ct.ThrowIfCancellationRequested();
                }
                DataSet ds;
                lock (this)
                {
                    ds = taskC.Result;
                }
                if (ds != null && ds.Tables.Contains(Environment.FolderData.TableName) && ds.Relations.Contains(Environment.FolderData.ParentRelation))
                {
                    using (DataTable dt = ds.Tables[Environment.FolderData.TableName])
                    {
                        lock (this)
                        {
                            var rel = ds.Relations[Environment.FolderData.ParentRelation];
                            foreach (DataRow dr in dt.Rows)
                            {
                                DataRow[] drs = dr.GetParentRows(rel);

                                if (drs != null && drs.Length == 0)
                                {
                                    if (this.TreeView.InvokeRequired)
                                    {
                                        this.TreeView.BeginInvoke(new Action <DataRow>((DataRow dR) =>
                                        {
                                            var node = Populate(dR, rel);
                                            Nodes.Add(node);
                                            if (ct.IsCancellationRequested)
                                            {
                                                ct.ThrowIfCancellationRequested();
                                            }
                                            if (dr == dt.Rows[dt.Rows.Count - 1])
                                            {
                                                node.UpdateStatusBegin(false, UpdateNode);
                                            }
                                            else
                                            {
                                                node.UpdateStatusBegin(false);
                                            }
                                        }), dr);
                                    }
                                    else
                                    {
                                        WorkFolderNode node = Populate(dr, rel);
                                        Nodes.Add(node);
                                    }
                                }
                            }
                        }
                        ds.Dispose();
                    }
                }
                else
                {
                    OnUpdateNode();
                }
            }, ct);

            if (TreeView != null)
            {
                TreeView.Cursor = Cursors.Default;
            }

            base.LoadSubNodes();
        }