Exemplo n.º 1
0
        /// <summary>
        /// this method create TreeView from NestedSetsTree
        /// </summary>
        /// <param name="objLogicNode">node of NestedSetsTree</param>
        /// <param name="objVisualNode">node of TreeView</param>
        private void CreateTreeView(Group objLogicNode, TreeNode objVisualNode)
        {
            using (var objProvider = new MailProvider()) {
                //выборка всех recievers котоыре принадлежат к текущей группе
                List <Receiver> objReceivers = objProvider.GetReceiversByGroupId(objLogicNode.Id);

                foreach (var reciever in objReceivers)
                {
                    var objNewTreeNode = new TreeNode()
                    {
                        Tag  = reciever.Id,
                        Name = reciever.Name,
                        Text = reciever.Name
                    };
                    objVisualNode.Nodes.Add(objNewTreeNode);
                }
                //выбор подчиненных узлов на первом уровне, т.е на всех непосредсвенных детей родительского узла
                //SELECT id, name, level FROM my_tree WHERE left_key >= $left_key AND right_key <= $right_key ORDER BY left_key

                var objChildNodes = objProvider.Base.Groups.
                                    Where(gr => gr.LeftKey > objLogicNode.LeftKey && gr.RightKey < objLogicNode.RightKey && gr.Level == objLogicNode.Level + 1).
                                    OrderBy(b => b.LeftKey).
                                    ToList();

                //add all childs on one level
                foreach (var node in objChildNodes)
                {
                    var objNewTreeNode = new TreeNode()
                    {
                        Tag  = node.Id,
                        Name = node.Name,
                        Text = node.Name,
                    };
                    objVisualNode.Nodes.Add(objNewTreeNode);
                    CreateTreeView(node, objNewTreeNode);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// get info about node
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            try {
                treeView1.SelectedNode = e.Node;

                if (e.Button == MouseButtons.Right)
                {
                    contextMenuStrip1.Show();
                }
                using (var objProvider = new MailProvider()) {
                    Receiver objReceiver = objProvider.GetReceiver((int)treeView1.SelectedNode.Tag, treeView1.SelectedNode.Name);
                    Group    objGroup    = objProvider.GetGroup((int)treeView1.SelectedNode.Tag, treeView1.SelectedNode.Name);

                    comboBox2.Items.Clear();
                    comboBox2.Items.AddRange(objProvider.GetAllGroups().ToArray());
                    listBox1.Items.Clear();
                    richTextBox1.Clear();

                    //clear MailList fields
                    textBox10.Clear();
                    textBox9.Clear();
                    richTextBox3.Clear();
                    label18.Text = String.Empty;

                    //if node is receiver
                    if (objReceiver != null)
                    {
                        comboBox2.SelectedItem = objReceiver.Group;

                        textBox1.Text     = objReceiver.Name;
                        textBox2.Text     = objReceiver.Email;
                        richTextBox1.Text = String.Format("{0}: {1}\n", objReceiver.Name, objReceiver.Email);

                        UpdateListBox1();

                        textBox1.Enabled = true;
                        textBox2.Enabled = true;
                        textBox3.Enabled = false;
                        textBox3.Clear();
                        button4.Enabled = false;
                    }
                    //if group
                    if (objGroup != null)
                    {
                        comboBox2.SelectedItem = objGroup;
                        textBox3.Text          = objGroup.Name;
                        List <Receiver> objrReceivers = objProvider.GetReceiversByGroupId(objGroup.Id);
                        foreach (var receiver in objrReceivers)
                        {
                            richTextBox1.Text += String.Format("{0}: {1}\n", receiver.Name, receiver.Email);
                        }

                        textBox3.Enabled = true;
                        textBox1.Clear();
                        textBox1.Enabled = false;
                        textBox2.Clear();
                        textBox2.Enabled = false;
                        button4.Enabled  = true;
                    }
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }