SamplesWindow.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2008
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  9. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  10. using System;
  11. using System.Drawing;
  12. using System.Collections;
  13. using System.ComponentModel;
  14. using System.Windows.Forms;
  15. using System.Reflection;
  16. using cognosdotnet_10_2;
  17. namespace SamplesCommon
  18. {
  19. /// <summary>
  20. /// The main window for sample programs.
  21. ///
  22. /// Add an event handler to Actions.Click to perform the action
  23. /// demonstrated by this sample.
  24. ///
  25. /// Add an Activated event handler to this window to set the
  26. /// applicationName, applicationVersion, applicationAction, and
  27. /// applicationTitle properties.
  28. /// </summary>
  29. public class SamplesWindow : System.Windows.Forms.Form
  30. {
  31. private System.Windows.Forms.MainMenu mainMenu;
  32. private System.Windows.Forms.MenuItem menuItem1;
  33. private System.Windows.Forms.MenuItem menuItem3;
  34. private System.Windows.Forms.TextBox urlText;
  35. private System.Windows.Forms.Label label1;
  36. private System.Windows.Forms.ListBox resultsBox;
  37. private System.Windows.Forms.Button actionButton;
  38. private System.Windows.Forms.MenuItem menuExit;
  39. private System.Windows.Forms.MenuItem menuAbout;
  40. private IContainer components;
  41. public SamplesWindow()
  42. {
  43. //
  44. // Required for Windows Form Designer support
  45. //
  46. InitializeComponent();
  47. this.Activated += new EventHandler( SamplesWindow_Activated );
  48. System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = false;
  49. }
  50. /// <summary>
  51. /// Clean up any resources being used.
  52. /// </summary>
  53. protected override void Dispose( bool disposing )
  54. {
  55. if( disposing )
  56. {
  57. if(components != null)
  58. {
  59. components.Dispose();
  60. }
  61. }
  62. base.Dispose( disposing );
  63. }
  64. #region Windows Form Designer generated code
  65. /// <summary>
  66. /// Required method for Designer support - do not modify
  67. /// the contents of this method with the code editor.
  68. /// </summary>
  69. private void InitializeComponent()
  70. {
  71. this.components = new System.ComponentModel.Container();
  72. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SamplesWindow));
  73. this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
  74. this.menuItem1 = new System.Windows.Forms.MenuItem();
  75. this.menuExit = new System.Windows.Forms.MenuItem();
  76. this.menuItem3 = new System.Windows.Forms.MenuItem();
  77. this.menuAbout = new System.Windows.Forms.MenuItem();
  78. this.urlText = new System.Windows.Forms.TextBox();
  79. this.actionButton = new System.Windows.Forms.Button();
  80. this.label1 = new System.Windows.Forms.Label();
  81. this.resultsBox = new System.Windows.Forms.ListBox();
  82. this.SuspendLayout();
  83. //
  84. // mainMenu
  85. //
  86. this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  87. this.menuItem1,
  88. this.menuItem3});
  89. //
  90. // menuItem1
  91. //
  92. this.menuItem1.Index = 0;
  93. this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  94. this.menuExit});
  95. this.menuItem1.Text = "File";
  96. //
  97. // menuExit
  98. //
  99. this.menuExit.Index = 0;
  100. this.menuExit.Text = "Exit";
  101. this.menuExit.Click += new System.EventHandler(this.menuExit_Click);
  102. //
  103. // menuItem3
  104. //
  105. this.menuItem3.Index = 1;
  106. this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  107. this.menuAbout});
  108. this.menuItem3.Text = "Help";
  109. //
  110. // menuAbout
  111. //
  112. this.menuAbout.Index = 0;
  113. this.menuAbout.Text = "About...";
  114. this.menuAbout.Click += new System.EventHandler(this.menuAbout_Click);
  115. //
  116. // urlText
  117. //
  118. this.urlText.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  119. | System.Windows.Forms.AnchorStyles.Right)));
  120. this.urlText.Location = new System.Drawing.Point(240, 24);
  121. this.urlText.Name = "urlText";
  122. this.urlText.Size = new System.Drawing.Size(319, 20);
  123. this.urlText.TabIndex = 0;
  124. this.urlText.Text = "http://localhost:9300/p2pd/servlet/dispatch";
  125. //
  126. // actionButton
  127. //
  128. this.actionButton.Location = new System.Drawing.Point(16, 16);
  129. this.actionButton.Name = "actionButton";
  130. this.actionButton.Size = new System.Drawing.Size(96, 32);
  131. this.actionButton.TabIndex = 2;
  132. this.actionButton.Text = "(Action)";
  133. //
  134. // label1
  135. //
  136. this.label1.Location = new System.Drawing.Point(118, 24);
  137. this.label1.Name = "label1";
  138. this.label1.Size = new System.Drawing.Size(116, 16);
  139. this.label1.TabIndex = 3;
  140. this.label1.Text = "Server URL:";
  141. this.label1.TextAlign = System.Drawing.ContentAlignment.BottomRight;
  142. //
  143. // resultsBox
  144. //
  145. this.resultsBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  146. | System.Windows.Forms.AnchorStyles.Left)
  147. | System.Windows.Forms.AnchorStyles.Right)));
  148. this.resultsBox.HorizontalScrollbar = true;
  149. this.resultsBox.Location = new System.Drawing.Point(16, 64);
  150. this.resultsBox.Name = "resultsBox";
  151. this.resultsBox.Size = new System.Drawing.Size(543, 160);
  152. this.resultsBox.TabIndex = 4;
  153. //
  154. // SamplesWindow
  155. //
  156. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  157. this.ClientSize = new System.Drawing.Size(575, 241);
  158. this.Controls.Add(this.resultsBox);
  159. this.Controls.Add(this.label1);
  160. this.Controls.Add(this.actionButton);
  161. this.Controls.Add(this.urlText);
  162. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  163. this.Menu = this.mainMenu;
  164. this.Name = "SamplesWindow";
  165. this.Text = "IBM Cognos Samples";
  166. this.ResumeLayout(false);
  167. this.PerformLayout();
  168. }
  169. #endregion
  170. private string app_name = null;
  171. private string app_version = null;
  172. /// <summary>
  173. /// The application's name, as shown in the About dialog box.
  174. /// </summary>
  175. public string applicationName {
  176. set {
  177. app_name = value;
  178. }
  179. get {
  180. return app_name;
  181. }
  182. }
  183. /// <summary>
  184. /// The application's version string, as shown in the About dialog box.
  185. /// </summary>
  186. public string applicationVersion {
  187. set {
  188. app_version = value;
  189. }
  190. get {
  191. return app_version;
  192. }
  193. }
  194. /// <summary>
  195. /// The application's action string, as shown on the button in the main window.
  196. /// </summary>
  197. public string applicationAction {
  198. set {
  199. actionButton.Text = value;
  200. }
  201. get {
  202. return actionButton.Text;
  203. }
  204. }
  205. /// <summary>
  206. /// The application's main window title bar string.
  207. /// </summary>
  208. public string applicationTitle {
  209. set {
  210. this.Text = value;
  211. }
  212. get {
  213. return this.Text;
  214. }
  215. }
  216. /// <summary>
  217. /// Actions launched by the Action button.
  218. ///
  219. /// Add event handlers to the Click event of this object.
  220. /// </summary>
  221. public System.Windows.Forms.Button Actions {
  222. get {
  223. return actionButton;
  224. }
  225. }
  226. /// <summary>
  227. /// Return the Server URL.
  228. /// </summary>
  229. public string serverUrl {
  230. get {
  231. return urlText.Text;
  232. }
  233. }
  234. /// <summary>
  235. /// Add a single line of text to the output window.
  236. /// </summary>
  237. /// <param name="text">A line of text.</param>
  238. public void AddText( string text ) {
  239. resultsBox.Items.Add( text );
  240. }
  241. /// <summary>
  242. /// Add several lines of text to the output window.
  243. /// </summary>
  244. /// <param name="text">An array of text.</param>
  245. public void AddText( string[] text ) {
  246. foreach( string s in text ) {
  247. AddText( s );
  248. }
  249. }
  250. /// <summary>
  251. /// Add several lines of text (all in one string, separated by \n
  252. /// characters) to the output window.
  253. /// </summary>
  254. /// <param name="text">A string containing several lines of text.</param>
  255. public void AddTextLines( string text ) {
  256. string split_on = "\n";
  257. AddText( text.Split( split_on.ToCharArray() ) );
  258. }
  259. /// <summary>
  260. /// The user has chosen Exit from the File menu.
  261. /// </summary>
  262. /// <param name="sender">What object sent this event? (not used)</param>
  263. /// <param name="e">Event arguments (not used)</param>
  264. private void menuExit_Click( object sender, System.EventArgs e ) {
  265. this.Close();
  266. }
  267. /// <summary>
  268. /// The user has chosen About... from the Help menu.
  269. ///
  270. /// Display the About dialog.
  271. /// </summary>
  272. /// <param name="sender">What object sent this event? (not used)</param>
  273. /// <param name="e">Event arguments (not used)</param>
  274. private void menuAbout_Click( object sender, System.EventArgs e ) {
  275. SamplesAbout about = new SamplesAbout();
  276. about.Activated += new EventHandler( about_Activated );
  277. about.Show();
  278. }
  279. /// <summary>
  280. /// The About window has been activated; we need to set up the strings
  281. /// that are displayed there.
  282. /// </summary>
  283. /// <param name="sender">Who sent this event?</param>
  284. /// <param name="e">Event arguments (not used)</param>
  285. private void about_Activated( object sender, EventArgs e ) {
  286. SamplesAbout about = (SamplesAbout)sender;
  287. about.applicationName = this.applicationName;
  288. about.applicationVersion = this.applicationVersion;
  289. }
  290. private static bool wasActivated = false;
  291. /// <summary>
  292. /// This window has been activated; clear out the results box.
  293. ///
  294. /// Also gets default application name and version information
  295. /// from the assembly.
  296. /// </summary>
  297. /// <param name="sender">Who sent this event? (not used)</param>
  298. /// <param name="e">Event arguments (not used)</param>
  299. private void SamplesWindow_Activated( object sender, EventArgs e ) {
  300. if( !wasActivated ) {
  301. resultsBox.Items.Clear();
  302. wasActivated = true;
  303. }
  304. }
  305. }
  306. }