ExecuteReportDlg.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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.IO;
  10. using System.Drawing;
  11. using System.Collections;
  12. using System.ComponentModel;
  13. using System.Windows.Forms;
  14. using System.Web.Services.Protocols;
  15. using SamplesCommon;
  16. using cognosdotnet_10_2;
  17. namespace ExecuteReport
  18. {
  19. /// <summary>
  20. /// Summary description for ExecuteReportDlg.
  21. /// </summary>
  22. public class ExecuteReportDlg : System.Windows.Forms.Form
  23. {
  24. private System.Windows.Forms.MainMenu mainMenu1;
  25. private System.Windows.Forms.MenuItem menuItemFile;
  26. private System.Windows.Forms.MenuItem menuItemExit;
  27. private System.Windows.Forms.MenuItem menuItemHelp;
  28. private System.Windows.Forms.MenuItem menuItemAbout;
  29. private IContainer components;
  30. private System.Windows.Forms.Button buttonExecuteReport;
  31. private System.Windows.Forms.Label label1;
  32. private System.Windows.Forms.Label reportNameLBL;
  33. private System.Windows.Forms.ComboBox reportListCB;
  34. private AxSHDocVw.AxWebBrowser outputBrowser;
  35. private System.Windows.Forms.TextBox reportSearchPathTB;
  36. private System.Windows.Forms.TextBox serverUrlTB;
  37. private static contentManagerService1 cBIServer = null;
  38. private static reportService1 cBIRS = null;
  39. private static SamplesConnect cBIConnection = null;
  40. public ExecuteReportDlg()
  41. {
  42. //
  43. // Required for Windows Form Designer support
  44. //
  45. InitializeComponent();
  46. //
  47. // TODO: Add any constructor code after InitializeComponent call
  48. //
  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(ExecuteReportDlg));
  73. this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
  74. this.menuItemFile = new System.Windows.Forms.MenuItem();
  75. this.menuItemExit = new System.Windows.Forms.MenuItem();
  76. this.menuItemHelp = new System.Windows.Forms.MenuItem();
  77. this.menuItemAbout = new System.Windows.Forms.MenuItem();
  78. this.buttonExecuteReport = new System.Windows.Forms.Button();
  79. this.label1 = new System.Windows.Forms.Label();
  80. this.serverUrlTB = new System.Windows.Forms.TextBox();
  81. this.reportNameLBL = new System.Windows.Forms.Label();
  82. this.reportListCB = new System.Windows.Forms.ComboBox();
  83. this.reportSearchPathTB = new System.Windows.Forms.TextBox();
  84. this.outputBrowser = new AxSHDocVw.AxWebBrowser();
  85. ((System.ComponentModel.ISupportInitialize)(this.outputBrowser)).BeginInit();
  86. this.SuspendLayout();
  87. //
  88. // mainMenu1
  89. //
  90. this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  91. this.menuItemFile,
  92. this.menuItemHelp});
  93. //
  94. // menuItemFile
  95. //
  96. this.menuItemFile.Index = 0;
  97. this.menuItemFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  98. this.menuItemExit});
  99. this.menuItemFile.Text = "File";
  100. //
  101. // menuItemExit
  102. //
  103. this.menuItemExit.Index = 0;
  104. this.menuItemExit.Text = "Exit";
  105. this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
  106. //
  107. // menuItemHelp
  108. //
  109. this.menuItemHelp.Index = 1;
  110. this.menuItemHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  111. this.menuItemAbout});
  112. this.menuItemHelp.Text = "Help";
  113. //
  114. // menuItemAbout
  115. //
  116. this.menuItemAbout.Index = 0;
  117. this.menuItemAbout.Text = "About";
  118. this.menuItemAbout.Click += new System.EventHandler(this.menuItemAbout_Click);
  119. //
  120. // buttonExecuteReport
  121. //
  122. this.buttonExecuteReport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  123. this.buttonExecuteReport.Location = new System.Drawing.Point(584, 72);
  124. this.buttonExecuteReport.Name = "buttonExecuteReport";
  125. this.buttonExecuteReport.Size = new System.Drawing.Size(104, 40);
  126. this.buttonExecuteReport.TabIndex = 0;
  127. this.buttonExecuteReport.Text = "Execute Report";
  128. this.buttonExecuteReport.Click += new System.EventHandler(this.buttonExecuteReport_Click);
  129. //
  130. // label1
  131. //
  132. this.label1.Location = new System.Drawing.Point(16, 16);
  133. this.label1.Name = "label1";
  134. this.label1.Size = new System.Drawing.Size(138, 16);
  135. this.label1.TabIndex = 1;
  136. this.label1.Text = "Server URL";
  137. //
  138. // serverUrlTB
  139. //
  140. this.serverUrlTB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  141. | System.Windows.Forms.AnchorStyles.Right)));
  142. this.serverUrlTB.BackColor = System.Drawing.SystemColors.Control;
  143. this.serverUrlTB.Location = new System.Drawing.Point(16, 32);
  144. this.serverUrlTB.Name = "serverUrlTB";
  145. this.serverUrlTB.Size = new System.Drawing.Size(672, 20);
  146. this.serverUrlTB.TabIndex = 2;
  147. //
  148. // reportNameLBL
  149. //
  150. this.reportNameLBL.Location = new System.Drawing.Point(16, 72);
  151. this.reportNameLBL.Name = "reportNameLBL";
  152. this.reportNameLBL.Size = new System.Drawing.Size(80, 16);
  153. this.reportNameLBL.TabIndex = 3;
  154. this.reportNameLBL.Text = "Report Name";
  155. //
  156. // reportListCB
  157. //
  158. this.reportListCB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  159. | System.Windows.Forms.AnchorStyles.Right)));
  160. this.reportListCB.Location = new System.Drawing.Point(16, 88);
  161. this.reportListCB.Name = "reportListCB";
  162. this.reportListCB.Size = new System.Drawing.Size(552, 21);
  163. this.reportListCB.TabIndex = 4;
  164. this.reportListCB.SelectedIndexChanged += new System.EventHandler(this.reportListCB_SelectedIndexChanged);
  165. //
  166. // reportSearchPathTB
  167. //
  168. this.reportSearchPathTB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  169. | System.Windows.Forms.AnchorStyles.Right)));
  170. this.reportSearchPathTB.BackColor = System.Drawing.SystemColors.Control;
  171. this.reportSearchPathTB.Location = new System.Drawing.Point(16, 120);
  172. this.reportSearchPathTB.Name = "reportSearchPathTB";
  173. this.reportSearchPathTB.Size = new System.Drawing.Size(672, 20);
  174. this.reportSearchPathTB.TabIndex = 6;
  175. //
  176. // outputBrowser
  177. //
  178. this.outputBrowser.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  179. | System.Windows.Forms.AnchorStyles.Left)
  180. | System.Windows.Forms.AnchorStyles.Right)));
  181. this.outputBrowser.Enabled = true;
  182. this.outputBrowser.Location = new System.Drawing.Point(16, 160);
  183. this.outputBrowser.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("outputBrowser.OcxState")));
  184. this.outputBrowser.Size = new System.Drawing.Size(672, 412);
  185. this.outputBrowser.TabIndex = 5;
  186. //
  187. // ExecuteReportDlg
  188. //
  189. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  190. this.ClientSize = new System.Drawing.Size(704, 586);
  191. this.Controls.Add(this.reportSearchPathTB);
  192. this.Controls.Add(this.serverUrlTB);
  193. this.Controls.Add(this.outputBrowser);
  194. this.Controls.Add(this.reportListCB);
  195. this.Controls.Add(this.reportNameLBL);
  196. this.Controls.Add(this.label1);
  197. this.Controls.Add(this.buttonExecuteReport);
  198. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  199. this.Menu = this.mainMenu1;
  200. this.Name = "ExecuteReportDlg";
  201. this.Text = "Execute Report Sample";
  202. ((System.ComponentModel.ISupportInitialize)(this.outputBrowser)).EndInit();
  203. this.ResumeLayout(false);
  204. this.PerformLayout();
  205. }
  206. #endregion
  207. private void menuItemExit_Click(object sender, System.EventArgs e)
  208. {
  209. this.Close();
  210. }
  211. private void menuItemAbout_Click(object sender, System.EventArgs e)
  212. {
  213. SamplesAbout about = new SamplesAbout();
  214. about.applicationName = "ExecuteReport Sample";
  215. about.applicationVersion = "1.1";
  216. about.Show();
  217. }
  218. private void buttonExecuteReport_Click(object sender, System.EventArgs e)
  219. {
  220. string output = "";
  221. BaseClassWrapper selectedObject = (BaseClassWrapper)reportListCB.SelectedItem;
  222. try
  223. {
  224. if (selectedObject == null)
  225. {
  226. MessageBox.Show("Please select a valid entry.");
  227. return;
  228. }
  229. ExecuteReport executeRep = new ExecuteReport();
  230. output = executeRep.doExecuteReport(cBIConnection, selectedObject.searchPath.value);
  231. displayPage(output);
  232. }
  233. catch(SoapException ex)
  234. {
  235. displayPage("<br>...the operation failed.<br>The following information was returned:<br><br>" +
  236. SamplesException.getExceptionMessage( ex));
  237. return;
  238. }
  239. catch(System.Exception ex)
  240. {
  241. if (0 != ex.Message.CompareTo("INPUT_CANCELLED_BY_USER"))
  242. {
  243. SamplesException.ShowExceptionMessage( ex.Message, true, "ExecuteReport Sample" );
  244. displayPage("\n...the operation failed.\nThe page could not be displayed.");
  245. }
  246. return;
  247. }
  248. }
  249. public void setReportList(BaseClassWrapper[] reportAndQueryList)
  250. {
  251. reportListCB.Items.AddRange(reportAndQueryList);
  252. }
  253. public void setSelectedReportIndex(int value)
  254. {
  255. reportListCB.SelectedIndex = value;
  256. }
  257. public void setConnection(SamplesConnect connection, string cBIUrl)
  258. {
  259. cBIConnection = connection;
  260. cBIServer = connection.CBICMS;
  261. cBIRS = connection.CBIRS;
  262. serverUrlTB.Text = cBIUrl;
  263. }
  264. public void displayPage(string currentPage)
  265. {
  266. string outputFile = "";
  267. object nullObject = null;
  268. CommonFunctions cf = new CommonFunctions();
  269. outputFile = cf.getSamplesPath();
  270. if (!Directory.Exists(outputFile))
  271. {
  272. // could not access the ...\webcontent\samples directory
  273. // use the current directory instead
  274. outputFile = Directory.GetCurrentDirectory();
  275. }
  276. outputFile += "executeReportOutput.htm";
  277. if (File.Exists(outputFile))
  278. {
  279. File.Delete(outputFile);
  280. }
  281. StreamWriter sw = new StreamWriter(outputFile);
  282. sw.WriteLine(currentPage);
  283. sw.Flush();
  284. sw.Close();
  285. outputBrowser.Navigate(outputFile, ref nullObject, ref nullObject, ref nullObject, ref nullObject);
  286. }
  287. private void reportListCB_SelectedIndexChanged(object sender, System.EventArgs e)
  288. {
  289. BaseClassWrapper selectedObject = (BaseClassWrapper)reportListCB.SelectedItem;
  290. if (selectedObject == null)
  291. {
  292. return;
  293. }
  294. reportSearchPathTB.Text = selectedObject.searchPath.value;
  295. }
  296. }
  297. }