PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/WordTemplate1/WordTemplate1/Formulaire/AreaPathIterationForm.cs

#
C# | 288 lines | 238 code | 44 blank | 6 comment | 110 complexity | e72498f0cf93a0effe389e4fe2e3c9fc MD5 | raw file
  1. /****
  2. *
  3. * Code provenant de l'outils Bowis de codeplex
  4. * Merci !!!
  5. *
  6. * *******/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Windows.Forms;
  15. using Microsoft.TeamFoundation.Server;
  16. using Microsoft.TeamFoundation.Client;
  17. using System.Xml;
  18. namespace WordTemplate1.Formulaire
  19. {
  20. public partial class AreaPathIterationForm : Form
  21. {
  22. TfsTeamProjectCollection server;
  23. ICommonStructureService css;
  24. string projectName;
  25. public AreaPathIterationForm()
  26. {
  27. InitializeComponent();
  28. this.projectName = TFS.project.Name;
  29. this.server = TFS.tfsTP;
  30. this.lblTeamProjectCollection.Text = server.Name;
  31. this.lblTeamProjectName.Text = this.projectName;
  32. }
  33. private void AreaPathIterationForm_Load(object sender, EventArgs e)
  34. {
  35. css = (ICommonStructureService)server.GetService(typeof(ICommonStructureService));
  36. ProjectInfo projectInfo = css.GetProjectFromName(projectName);
  37. NodeInfo[] nodes = css.ListStructures(projectInfo.Uri);
  38. XmlElement AreaTree = css.GetNodesXml(new string[] { nodes[1].Uri }, true);
  39. XmlElement IterationsTree = css.GetNodesXml(new string[] { nodes[0].Uri }, true);
  40. tvArea.Nodes.Clear();
  41. tvIteration.Nodes.Clear();
  42. var areaNode = tvArea.Nodes.Add("Area");
  43. var iterationNode = tvIteration.Nodes.Add("Iteration");
  44. areaNode.Tag = nodes[1].Uri;
  45. iterationNode.Tag = nodes[0].Uri;
  46. XmlNode AreaNodes = AreaTree.ChildNodes[0];
  47. XmlNode IterationsNodes = IterationsTree.ChildNodes[0];
  48. MakeList(areaNode, AreaNodes, StructureType.Area);
  49. MakeList(iterationNode, IterationsNodes, StructureType.Iteration);
  50. tvArea.ExpandAll();
  51. tvIteration.ExpandAll();
  52. }
  53. enum StructureType
  54. {
  55. Iteration = 0,
  56. Area = 1
  57. }
  58. private void MakeList(TreeNode parentNode, XmlNode tree, StructureType type)
  59. {
  60. if (tree.FirstChild != null)
  61. {
  62. int myNodeCount = tree.FirstChild.ChildNodes.Count;
  63. for (int i = 0; i < myNodeCount; i++)
  64. {
  65. XmlNode Node = tree.ChildNodes[0].ChildNodes[i];
  66. TreeNode newNode = null;
  67. if (type == StructureType.Area)
  68. newNode = parentNode.Nodes.Add(Node.Attributes["Name"].Value);
  69. else
  70. newNode = parentNode.Nodes.Add(Node.Attributes["Name"].Value);
  71. newNode.Tag = Node.Attributes["NodeID"].Value;
  72. if (Node.ChildNodes != null && Node.ChildNodes.Count > 0)
  73. MakeList(newNode, Node, type);
  74. }
  75. }
  76. }
  77. TreeNode editingNode;
  78. private void btnAddIteration_Click(object sender, EventArgs e)
  79. {
  80. editingNode = tvIteration.SelectedNode.Nodes.Add("Iteration N");
  81. tvIteration.SelectedNode = editingNode;
  82. editingNode.BeginEdit();
  83. }
  84. private void TreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
  85. {
  86. e.Node.EndEdit(false);
  87. e.Node.Text = e.Label;
  88. if (e.Node.Tag != null)
  89. css.RenameNode(e.Node.Tag.ToString(), e.Label);
  90. else
  91. {
  92. string uri = css.CreateNode(e.Node.Text, e.Node.Parent.Tag.ToString());
  93. e.Node.Tag = uri;
  94. }
  95. }
  96. private void btnDeleteIteration_Click(object sender, EventArgs e)
  97. {
  98. DeleteSelectedNode(tvIteration);
  99. }
  100. private void btnUpIteration_Click(object sender, EventArgs e)
  101. {
  102. UpSelectedNode(tvIteration);
  103. }
  104. private void btnDownIteration_Click(object sender, EventArgs e)
  105. {
  106. DownSelectedNode(tvIteration);
  107. }
  108. private void tvIteration_AfterSelect(object sender, TreeViewEventArgs e)
  109. {
  110. if (e.Action == TreeViewAction.ByKeyboard || e.Action == TreeViewAction.ByMouse || e.Action == TreeViewAction.Unknown)
  111. {
  112. btnDownIteration.Enabled = e.Node != null && e.Node.Parent != null && e.Node.NextNode != null;
  113. btnUpIteration.Enabled = e.Node != null && e.Node.Parent != null && e.Node.PrevNode != null;
  114. btnDeleteIteration.Enabled = e.Node != null && e.Node.Parent != null;
  115. btnLeftIteration.Enabled = e.Node != null && e.Node.Parent != null && e.Node.Parent.Parent != null;
  116. btnRightIteration.Enabled = e.Node != null && e.Node.Parent != null && e.Node.PrevNode != null;
  117. }
  118. }
  119. private void tvArea_AfterSelect(object sender, TreeViewEventArgs e)
  120. {
  121. if (e.Action == TreeViewAction.ByKeyboard || e.Action == TreeViewAction.ByMouse || e.Action == TreeViewAction.Unknown)
  122. {
  123. btnDownArea.Enabled = e.Node != null && e.Node.Parent != null && e.Node.NextNode != null;
  124. btnUpArea.Enabled = e.Node != null && e.Node.Parent != null && e.Node.PrevNode != null;
  125. btnDeleteArea.Enabled = e.Node != null && e.Node.Parent != null;
  126. btnLeftArea.Enabled = e.Node != null && e.Node.Parent != null && e.Node.Parent.Parent != null;
  127. btnRightArea.Enabled = e.Node != null && e.Node.Parent != null && e.Node.PrevNode != null;
  128. }
  129. }
  130. private void btnAddArea_Click(object sender, EventArgs e)
  131. {
  132. editingNode = tvArea.SelectedNode.Nodes.Add("Area N");
  133. tvArea.SelectedNode = editingNode;
  134. editingNode.BeginEdit();
  135. }
  136. private void btnDeleteArea_Click(object sender, EventArgs e)
  137. {
  138. DeleteSelectedNode(tvArea);
  139. }
  140. private void btnUpArea_Click(object sender, EventArgs e)
  141. {
  142. UpSelectedNode(tvArea);
  143. }
  144. private void btnDownArea_Click(object sender, EventArgs e)
  145. {
  146. DownSelectedNode(tvArea);
  147. }
  148. private void btnLeftArea_Click(object sender, EventArgs e)
  149. {
  150. MoveLeftSelectedNode(tvArea);
  151. }
  152. private void btnRightArea_Click(object sender, EventArgs e)
  153. {
  154. MoveRightSelectedNode(tvArea);
  155. }
  156. private void btnLeftIteration_Click(object sender, EventArgs e)
  157. {
  158. MoveLeftSelectedNode(tvIteration);
  159. }
  160. private void btnRightIteration_Click(object sender, EventArgs e)
  161. {
  162. MoveRightSelectedNode(tvIteration);
  163. }
  164. private void tvIteration_KeyUp(object sender, KeyEventArgs e)
  165. {
  166. TreeView treeview = tvIteration;
  167. if (e.KeyCode == Keys.F2 && treeview.SelectedNode != null && treeview.SelectedNode.Parent != null)
  168. {
  169. treeview.SelectedNode.BeginEdit();
  170. }
  171. }
  172. private void tvArea_KeyUp(object sender, KeyEventArgs e)
  173. {
  174. TreeView treeview = tvArea;
  175. if (e.KeyCode == Keys.F2 && treeview.SelectedNode != null && treeview.SelectedNode.Parent != null)
  176. {
  177. treeview.SelectedNode.BeginEdit();
  178. }
  179. }
  180. private void MoveLeftSelectedNode(TreeView treeview)
  181. {
  182. TreeNode currentNode = treeview.SelectedNode;
  183. if (currentNode != null && currentNode.Parent != null && currentNode.Parent.Parent != null)
  184. {
  185. css.MoveBranch(currentNode.Tag.ToString(), currentNode.Parent.Parent.Tag.ToString());
  186. TreeNode newParent = currentNode.Parent.Parent;
  187. int newIndex = currentNode.Parent.Index + 1;
  188. currentNode.Remove();
  189. newParent.Nodes.Add(currentNode);
  190. treeview.SelectedNode = currentNode;
  191. }
  192. }
  193. private void MoveRightSelectedNode(TreeView treeview)
  194. {
  195. TreeNode currentNode = treeview.SelectedNode;
  196. if (currentNode != null && currentNode.Parent != null && currentNode.PrevNode != null)
  197. {
  198. css.MoveBranch(currentNode.Tag.ToString(), currentNode.PrevNode.Tag.ToString());
  199. TreeNode newParent = currentNode.PrevNode;
  200. currentNode.Remove();
  201. newParent.Nodes.Add(currentNode);
  202. treeview.SelectedNode = currentNode;
  203. }
  204. }
  205. private void UpSelectedNode(TreeView treeview)
  206. {
  207. TreeNode currentNode = treeview.SelectedNode;
  208. if (currentNode != null && currentNode.Parent != null && currentNode.PrevNode != null)
  209. {
  210. css.ReorderNode(currentNode.Tag.ToString(), -1);
  211. TreeNode parent = currentNode.Parent;
  212. int newIndex = currentNode.Index - 1;
  213. parent.Nodes.Remove(currentNode);
  214. parent.Nodes.Insert(newIndex, currentNode);
  215. treeview.SelectedNode = currentNode;
  216. }
  217. }
  218. private void DownSelectedNode(TreeView treeview)
  219. {
  220. TreeNode currentNode = treeview.SelectedNode;
  221. if (currentNode != null && currentNode.Parent != null && currentNode.NextNode != null)
  222. {
  223. css.ReorderNode(currentNode.Tag.ToString(), +1);
  224. TreeNode parent = currentNode.Parent;
  225. int newIndex = currentNode.Index + 1;
  226. parent.Nodes.Remove(currentNode);
  227. parent.Nodes.Insert(newIndex, currentNode);
  228. treeview.SelectedNode = currentNode;
  229. }
  230. }
  231. private void DeleteSelectedNode(TreeView treeview)
  232. {
  233. TreeNode node = treeview.SelectedNode;
  234. if (node != null && node.Parent != null)
  235. {
  236. string reclassifyUri = "";
  237. if (node.Parent.Tag != null)
  238. reclassifyUri = node.Parent.Tag.ToString();
  239. css.DeleteBranches(new string[] { node.Tag.ToString() }, reclassifyUri);
  240. treeview.Nodes.Remove(node);
  241. }
  242. }
  243. }
  244. }