CreateReportTableDlg.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. using System;
  9. using System.Drawing;
  10. using System.Collections;
  11. using System.ComponentModel;
  12. using System.Windows.Forms;
  13. using System.Xml;
  14. using SamplesCommon;
  15. namespace CreateReport
  16. {
  17. /// <summary>
  18. /// Summary description for CreateReportTableDlg.
  19. /// </summary>
  20. public class CreateReportTableDlg : System.Windows.Forms.Form
  21. {
  22. private System.Windows.Forms.Label label2;
  23. private System.Windows.Forms.Label label3;
  24. private System.Windows.Forms.Button buttonOK;
  25. private System.Windows.Forms.Button buttonCancel;
  26. private System.Windows.Forms.Label tablesLBL;
  27. private System.Windows.Forms.ComboBox tablesCB;
  28. /// <summary>
  29. /// Required designer variable.
  30. /// </summary>
  31. private System.ComponentModel.Container components = null;
  32. public bool isOKed = false;
  33. private System.Windows.Forms.ListBox availableColumnsLB;
  34. private System.Windows.Forms.ListBox selectedColumnsLB;
  35. private System.Windows.Forms.Button buttonAddItem;
  36. private System.Windows.Forms.Button buttonRemoveItem;
  37. public static TableData[] m_tableNameColumnMap = null;
  38. public string m_packageName = "";
  39. public string m_reportName = "";
  40. public string m_tableName = "";
  41. public string[] m_columnList = null;
  42. public CreateReportTableDlg()
  43. {
  44. //
  45. // Required for Windows Form Designer support
  46. //
  47. InitializeComponent();
  48. //
  49. // TODO: Add any constructor code after InitializeComponent call
  50. //
  51. }
  52. public CreateReportTableDlg(TableData[] tableNameColumnMap, string packageName, string reportName)
  53. {
  54. //
  55. // Required for Windows Form Designer support
  56. //
  57. InitializeComponent();
  58. //
  59. // TODO: Add any constructor code after InitializeComponent call
  60. //
  61. m_tableNameColumnMap = tableNameColumnMap;
  62. m_packageName = packageName;
  63. m_reportName = reportName;
  64. m_tableName = "";
  65. }
  66. /// <summary>
  67. /// Clean up any resources being used.
  68. /// </summary>
  69. protected override void Dispose( bool disposing )
  70. {
  71. if( disposing )
  72. {
  73. if(components != null)
  74. {
  75. components.Dispose();
  76. }
  77. }
  78. base.Dispose( disposing );
  79. }
  80. #region Windows Form Designer generated code
  81. /// <summary>
  82. /// Required method for Designer support - do not modify
  83. /// the contents of this method with the code editor.
  84. /// </summary>
  85. private void InitializeComponent()
  86. {
  87. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CreateReportTableDlg));
  88. this.tablesLBL = new System.Windows.Forms.Label();
  89. this.tablesCB = new System.Windows.Forms.ComboBox();
  90. this.label2 = new System.Windows.Forms.Label();
  91. this.availableColumnsLB = new System.Windows.Forms.ListBox();
  92. this.buttonAddItem = new System.Windows.Forms.Button();
  93. this.buttonRemoveItem = new System.Windows.Forms.Button();
  94. this.selectedColumnsLB = new System.Windows.Forms.ListBox();
  95. this.label3 = new System.Windows.Forms.Label();
  96. this.buttonOK = new System.Windows.Forms.Button();
  97. this.buttonCancel = new System.Windows.Forms.Button();
  98. this.SuspendLayout();
  99. //
  100. // tablesLBL
  101. //
  102. this.tablesLBL.Location = new System.Drawing.Point(16, 8);
  103. this.tablesLBL.Name = "tablesLBL";
  104. this.tablesLBL.Size = new System.Drawing.Size(48, 16);
  105. this.tablesLBL.TabIndex = 0;
  106. this.tablesLBL.Text = "Tables:";
  107. //
  108. // tablesCB
  109. //
  110. this.tablesCB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  111. | System.Windows.Forms.AnchorStyles.Right)));
  112. this.tablesCB.Location = new System.Drawing.Point(16, 24);
  113. this.tablesCB.Name = "tablesCB";
  114. this.tablesCB.Size = new System.Drawing.Size(184, 21);
  115. this.tablesCB.TabIndex = 1;
  116. this.tablesCB.SelectedIndexChanged += new System.EventHandler(this.tablesCB_SelectedIndexChanged);
  117. //
  118. // label2
  119. //
  120. this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  121. | System.Windows.Forms.AnchorStyles.Left)));
  122. this.label2.Location = new System.Drawing.Point(16, 64);
  123. this.label2.Name = "label2";
  124. this.label2.Size = new System.Drawing.Size(104, 16);
  125. this.label2.TabIndex = 2;
  126. this.label2.Text = "Available Columns:";
  127. //
  128. // availableColumnsLB
  129. //
  130. this.availableColumnsLB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  131. | System.Windows.Forms.AnchorStyles.Left)));
  132. this.availableColumnsLB.HorizontalScrollbar = true;
  133. this.availableColumnsLB.Location = new System.Drawing.Point(16, 80);
  134. this.availableColumnsLB.Name = "availableColumnsLB";
  135. this.availableColumnsLB.Size = new System.Drawing.Size(184, 225);
  136. this.availableColumnsLB.TabIndex = 3;
  137. //
  138. // buttonAddItem
  139. //
  140. this.buttonAddItem.Anchor = System.Windows.Forms.AnchorStyles.Top;
  141. this.buttonAddItem.Location = new System.Drawing.Point(216, 152);
  142. this.buttonAddItem.Name = "buttonAddItem";
  143. this.buttonAddItem.Size = new System.Drawing.Size(72, 24);
  144. this.buttonAddItem.TabIndex = 4;
  145. this.buttonAddItem.Text = "> > >";
  146. this.buttonAddItem.Click += new System.EventHandler(this.buttonAddItem_Click);
  147. //
  148. // buttonRemoveItem
  149. //
  150. this.buttonRemoveItem.Anchor = System.Windows.Forms.AnchorStyles.Top;
  151. this.buttonRemoveItem.Location = new System.Drawing.Point(216, 208);
  152. this.buttonRemoveItem.Name = "buttonRemoveItem";
  153. this.buttonRemoveItem.Size = new System.Drawing.Size(75, 23);
  154. this.buttonRemoveItem.TabIndex = 5;
  155. this.buttonRemoveItem.Text = "< < <";
  156. this.buttonRemoveItem.Click += new System.EventHandler(this.buttonRemoveItem_Click);
  157. //
  158. // selectedColumnsLB
  159. //
  160. this.selectedColumnsLB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  161. | System.Windows.Forms.AnchorStyles.Right)));
  162. this.selectedColumnsLB.HorizontalScrollbar = true;
  163. this.selectedColumnsLB.Location = new System.Drawing.Point(304, 80);
  164. this.selectedColumnsLB.Name = "selectedColumnsLB";
  165. this.selectedColumnsLB.SelectionMode = System.Windows.Forms.SelectionMode.None;
  166. this.selectedColumnsLB.Size = new System.Drawing.Size(184, 225);
  167. this.selectedColumnsLB.TabIndex = 6;
  168. //
  169. // label3
  170. //
  171. this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  172. this.label3.Location = new System.Drawing.Point(304, 64);
  173. this.label3.Name = "label3";
  174. this.label3.Size = new System.Drawing.Size(100, 16);
  175. this.label3.TabIndex = 7;
  176. this.label3.Text = "Selected Columns";
  177. //
  178. // buttonOK
  179. //
  180. this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  181. this.buttonOK.Location = new System.Drawing.Point(304, 320);
  182. this.buttonOK.Name = "buttonOK";
  183. this.buttonOK.Size = new System.Drawing.Size(75, 23);
  184. this.buttonOK.TabIndex = 8;
  185. this.buttonOK.Text = "OK";
  186. this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
  187. //
  188. // buttonCancel
  189. //
  190. this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  191. this.buttonCancel.Location = new System.Drawing.Point(408, 320);
  192. this.buttonCancel.Name = "buttonCancel";
  193. this.buttonCancel.Size = new System.Drawing.Size(75, 23);
  194. this.buttonCancel.TabIndex = 9;
  195. this.buttonCancel.Text = "Cancel";
  196. this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
  197. //
  198. // CreateReportTableDlg
  199. //
  200. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  201. this.AutoScroll = true;
  202. this.ClientSize = new System.Drawing.Size(512, 358);
  203. this.Controls.Add(this.buttonCancel);
  204. this.Controls.Add(this.buttonOK);
  205. this.Controls.Add(this.label3);
  206. this.Controls.Add(this.selectedColumnsLB);
  207. this.Controls.Add(this.buttonRemoveItem);
  208. this.Controls.Add(this.buttonAddItem);
  209. this.Controls.Add(this.availableColumnsLB);
  210. this.Controls.Add(this.label2);
  211. this.Controls.Add(this.tablesCB);
  212. this.Controls.Add(this.tablesLBL);
  213. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  214. this.Name = "CreateReportTableDlg";
  215. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  216. this.Text = "CreateReportTableDlg";
  217. this.Load += new System.EventHandler(this.CreateReportTableDlg_Load);
  218. this.ResumeLayout(false);
  219. }
  220. #endregion
  221. private void buttonCancel_Click(object sender, System.EventArgs e)
  222. {
  223. isOKed = false;
  224. this.Close();
  225. }
  226. private void buttonOK_Click(object sender, System.EventArgs e)
  227. {
  228. isOKed = true;
  229. this.Close();
  230. }
  231. private void CreateReportTableDlg_Load(object sender, System.EventArgs e)
  232. {
  233. }
  234. private void tablesCB_SelectedIndexChanged(object sender, System.EventArgs e)
  235. {
  236. availableColumnsLB.Items.Clear();
  237. string selectedTableName = (string)tablesCB.SelectedItem;
  238. if (selectedTableName == null)
  239. {
  240. return;
  241. }
  242. for (int i=0; i<m_tableNameColumnMap.GetLength(0); i++)
  243. {
  244. string currentTableName = m_tableNameColumnMap[i].getTableName();
  245. if (0 == selectedTableName.CompareTo(currentTableName))
  246. {
  247. // found the selected table name in the Table/Column map
  248. // now retrieve the associated columns for display
  249. int nbColumns = m_tableNameColumnMap[i].getColumns().GetLength(0);
  250. XmlNodeWrapper[] columns = new XmlNodeWrapper[nbColumns];
  251. columns = m_tableNameColumnMap[i].getColumns();
  252. for (int j=0; j<nbColumns; j++)
  253. {
  254. availableColumnsLB.Items.Add(columns[j]);
  255. }
  256. break;
  257. }
  258. }
  259. }
  260. private void buttonAddItem_Click(object sender, System.EventArgs e)
  261. {
  262. string selectedText = availableColumnsLB.SelectedItem.ToString();
  263. if ( (selectedText != null) && (0 !=selectedText.CompareTo("")) &&
  264. !selectedColumnsLB.Items.Contains(availableColumnsLB.SelectedItem) )
  265. {
  266. selectedColumnsLB.Items.Add(availableColumnsLB.SelectedItem);
  267. }
  268. }
  269. private void buttonRemoveItem_Click(object sender, System.EventArgs e)
  270. {
  271. int selectedIndex = selectedColumnsLB.SelectedIndex;
  272. if (selectedIndex >= 0)
  273. {
  274. selectedColumnsLB.Items.RemoveAt(selectedIndex);
  275. }
  276. }
  277. public XmlNodeWrapper[] getSelectedColumnList()
  278. {
  279. int nbSelectedColumns = selectedColumnsLB.Items.Count;
  280. XmlNodeWrapper[] selectedColumns = new XmlNodeWrapper[nbSelectedColumns];
  281. for (int i=0; i<nbSelectedColumns; i++)
  282. {
  283. selectedColumns[i] = (XmlNodeWrapper)selectedColumnsLB.Items[i];
  284. }
  285. return selectedColumns;
  286. }
  287. public string getSelectedTableName()
  288. {
  289. string selectedTableName = (string)tablesCB.SelectedItem;
  290. if ( (selectedTableName == null) || (0 == selectedTableName.CompareTo("")) )
  291. {
  292. MessageBox.Show("Please select a table name.");
  293. }
  294. return selectedTableName;
  295. }
  296. public void populateTableNameList()
  297. {
  298. tablesCB.Items.Clear();
  299. if (m_tableNameColumnMap.GetLength(0) <= 0)
  300. {
  301. return;
  302. }
  303. int nbTables = m_tableNameColumnMap.GetLength(0);
  304. for (int i=0; i<nbTables; i++)
  305. {
  306. tablesCB.Items.Add(m_tableNameColumnMap[i].getTableName());
  307. }
  308. }
  309. public void selectTableIndex(int index)
  310. {
  311. tablesCB.SelectedIndex = index;
  312. }
  313. }
  314. }