/// <summary> /// delete group and all child nodes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ToolStripMenuItem3_Click(object sender, EventArgs e) { try { using (var objProvider = new MailProvider()) { //get parent group node Group objParentGroup = objProvider.GetGroup((int)treeView1.SelectedNode.Tag, treeView1.SelectedNode.Name); //get receiver node Receiver objReceiver = objProvider.GetReceiver((int)treeView1.SelectedNode.Tag, treeView1.SelectedNode.Name); //if selected is receiver node if (objReceiver != null) { objProvider.RemoveReceiver(objReceiver); } //if selected is group parent node if (objParentGroup != null) { //get all childs Recievers List <Group> objChildsToDeleteList = objProvider.Base.Groups. Where(gr => gr.LeftKey >= objParentGroup.LeftKey && gr.RightKey <= objParentGroup.RightKey).ToList(); //delete all childs foreach (var node in objChildsToDeleteList) { List <Receiver> objReceiversList = objProvider.Base.Receivers.Where(r => r.Group.Id == node.Id).ToList(); for (int iJ = 0; iJ < objReceiversList.Count; ++iJ) { objProvider.RemoveReceiver(objReceiversList[iJ]); } objProvider.RemoveGroup(node); } //update parent branch List <Group> objParentsList = objProvider.Base.Groups.Where(gr => gr.RightKey > objParentGroup.RightKey && gr.LeftKey < objParentGroup.LeftKey).ToList(); foreach (var node in objParentsList) { node.RightKey = node.RightKey - (objParentGroup.RightKey - objParentGroup.LeftKey + 1); } //update other childs List <Group> objChildList = objProvider.Base.Groups.Where(gr => gr.LeftKey > objParentGroup.RightKey).ToList(); foreach (var node in objChildList) { node.LeftKey = node.LeftKey - (objParentGroup.RightKey - objParentGroup.LeftKey + 1); node.RightKey = node.RightKey - (objParentGroup.RightKey - objParentGroup.LeftKey + 1); } } } UpdateTree(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// send Email method /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { try { using (var objProvider = new MailProvider()) { //create Email if (textBox8.Text == String.Empty || richTextBox2.Text == String.Empty) { throw new ArgumentNullException("Fill all fields!"); } //if selected node is Group Group objGroup = objProvider.GetGroup((int)treeView1.SelectedNode.Tag, treeView1.SelectedNode.Name); Receiver objReceiver = objProvider.GetReceiver((int)treeView1.SelectedNode.Tag, treeView1.SelectedNode.Name); if (objGroup != null) { foreach (var receiver in objGroup.Receivers) { var objEmail = new Email() { Receiver = receiver, Text = richTextBox2.Text, Header = textBox8.Text, SendingTime = DateTime.Now }; objProvider.AddEmail(objEmail); SendEmail(objEmail); } } //if receiver if (objReceiver != null) { var objEmail = new Email() { Receiver = objReceiver, Text = richTextBox2.Text, Header = textBox8.Text, SendingTime = DateTime.Now }; objProvider.AddEmail(objEmail); SendEmail(objEmail); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <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); } }