AddReportDlg.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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.Threading;
  12. using System.Collections;
  13. using System.ComponentModel;
  14. using System.Windows.Forms;
  15. using System.Web.Services.Protocols;
  16. using SamplesCommon;
  17. using cognosdotnet_10_2;
  18. namespace AddReport
  19. {
  20. /// <summary>
  21. /// Summary description for AddReportDlg.
  22. /// </summary>
  23. public class AddReportDlg : System.Windows.Forms.Form
  24. {
  25. private System.Windows.Forms.MainMenu mainMenu1;
  26. private System.Windows.Forms.MenuItem menuItem1;
  27. private System.Windows.Forms.MenuItem menuItem3;
  28. private System.Windows.Forms.GroupBox groupBox1;
  29. private System.Windows.Forms.MenuItem menuExit;
  30. private System.Windows.Forms.MenuItem menuAbout;
  31. private IContainer components;
  32. private System.Windows.Forms.Label label1;
  33. private System.Windows.Forms.Button RunOptionButton;
  34. private System.Windows.Forms.ComboBox OptionChooserCB;
  35. private System.Windows.Forms.RichTextBox resultsDisplayWindowRTB;
  36. private System.Windows.Forms.TextBox serverUrlTB;
  37. private reportService1 cBIRS = null;
  38. private systemService1 cBISS = null;
  39. private string accountPath= "";
  40. public AddReportDlg()
  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(AddReportDlg));
  73. this.mainMenu1 = 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.groupBox1 = new System.Windows.Forms.GroupBox();
  79. this.resultsDisplayWindowRTB = new System.Windows.Forms.RichTextBox();
  80. this.label1 = new System.Windows.Forms.Label();
  81. this.serverUrlTB = new System.Windows.Forms.TextBox();
  82. this.OptionChooserCB = new System.Windows.Forms.ComboBox();
  83. this.RunOptionButton = new System.Windows.Forms.Button();
  84. this.groupBox1.SuspendLayout();
  85. this.SuspendLayout();
  86. //
  87. // mainMenu1
  88. //
  89. this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  90. this.menuItem1,
  91. this.menuItem3});
  92. //
  93. // menuItem1
  94. //
  95. this.menuItem1.Index = 0;
  96. this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  97. this.menuExit});
  98. this.menuItem1.Text = "File";
  99. //
  100. // menuExit
  101. //
  102. this.menuExit.Index = 0;
  103. this.menuExit.Text = "Exit";
  104. this.menuExit.Click += new System.EventHandler(this.menuExit_Click);
  105. //
  106. // menuItem3
  107. //
  108. this.menuItem3.Index = 1;
  109. this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  110. this.menuAbout});
  111. this.menuItem3.Text = "Help";
  112. //
  113. // menuAbout
  114. //
  115. this.menuAbout.Index = 0;
  116. this.menuAbout.Text = "About";
  117. this.menuAbout.Click += new System.EventHandler(this.menuAbout_Click);
  118. //
  119. // groupBox1
  120. //
  121. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  122. | System.Windows.Forms.AnchorStyles.Left)
  123. | System.Windows.Forms.AnchorStyles.Right)));
  124. this.groupBox1.Controls.Add(this.resultsDisplayWindowRTB);
  125. this.groupBox1.Location = new System.Drawing.Point(10, 111);
  126. this.groupBox1.Name = "groupBox1";
  127. this.groupBox1.Size = new System.Drawing.Size(568, 184);
  128. this.groupBox1.TabIndex = 8;
  129. this.groupBox1.TabStop = false;
  130. this.groupBox1.Text = "Results Display Window";
  131. //
  132. // resultsDisplayWindowRTB
  133. //
  134. this.resultsDisplayWindowRTB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  135. | System.Windows.Forms.AnchorStyles.Left)
  136. | System.Windows.Forms.AnchorStyles.Right)));
  137. this.resultsDisplayWindowRTB.BackColor = System.Drawing.SystemColors.Control;
  138. this.resultsDisplayWindowRTB.Location = new System.Drawing.Point(10, 18);
  139. this.resultsDisplayWindowRTB.Name = "resultsDisplayWindowRTB";
  140. this.resultsDisplayWindowRTB.Size = new System.Drawing.Size(549, 154);
  141. this.resultsDisplayWindowRTB.TabIndex = 0;
  142. this.resultsDisplayWindowRTB.Text = "";
  143. //
  144. // label1
  145. //
  146. this.label1.Location = new System.Drawing.Point(10, 18);
  147. this.label1.Name = "label1";
  148. this.label1.Size = new System.Drawing.Size(168, 19);
  149. this.label1.TabIndex = 9;
  150. this.label1.Text = "Server URL";
  151. this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  152. //
  153. // serverUrlTB
  154. //
  155. this.serverUrlTB.BackColor = System.Drawing.SystemColors.Control;
  156. this.serverUrlTB.Enabled = false;
  157. this.serverUrlTB.Location = new System.Drawing.Point(185, 18);
  158. this.serverUrlTB.Name = "serverUrlTB";
  159. this.serverUrlTB.Size = new System.Drawing.Size(372, 22);
  160. this.serverUrlTB.TabIndex = 10;
  161. //
  162. // OptionChooserCB
  163. //
  164. this.OptionChooserCB.Location = new System.Drawing.Point(185, 65);
  165. this.OptionChooserCB.Name = "OptionChooserCB";
  166. this.OptionChooserCB.Size = new System.Drawing.Size(266, 24);
  167. this.OptionChooserCB.TabIndex = 11;
  168. //
  169. // RunOptionButton
  170. //
  171. this.RunOptionButton.Location = new System.Drawing.Point(461, 65);
  172. this.RunOptionButton.Name = "RunOptionButton";
  173. this.RunOptionButton.Size = new System.Drawing.Size(96, 26);
  174. this.RunOptionButton.TabIndex = 12;
  175. this.RunOptionButton.Text = "Run Option";
  176. this.RunOptionButton.Click += new System.EventHandler(this.RunOptionButton_Click);
  177. //
  178. // AddReportDlg
  179. //
  180. this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
  181. this.ClientSize = new System.Drawing.Size(587, 305);
  182. this.Controls.Add(this.RunOptionButton);
  183. this.Controls.Add(this.OptionChooserCB);
  184. this.Controls.Add(this.serverUrlTB);
  185. this.Controls.Add(this.label1);
  186. this.Controls.Add(this.groupBox1);
  187. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  188. this.Menu = this.mainMenu1;
  189. this.Name = "AddReportDlg";
  190. this.Text = "Add Report Sample";
  191. this.Load += new System.EventHandler(this.AddReportDlg_Load);
  192. this.groupBox1.ResumeLayout(false);
  193. this.ResumeLayout(false);
  194. this.PerformLayout();
  195. }
  196. #endregion
  197. private void menuAbout_Click(object sender, System.EventArgs e)
  198. {
  199. SamplesAbout about = new SamplesAbout();
  200. about.applicationName = "Add Report Sample";
  201. about.applicationVersion = "1.1";
  202. about.Show();
  203. }
  204. private void menuExit_Click(object sender, System.EventArgs e)
  205. {
  206. this.Close();
  207. }
  208. private void AddReportDlg_Load(object sender, System.EventArgs e)
  209. {
  210. OptionChooserCB.Items.Add("Validate Specification");
  211. OptionChooserCB.Items.Add("Add Specification to Content Store");
  212. OptionChooserCB.SelectedIndex = 0;
  213. }
  214. private void RunOptionButton_Click(object sender, System.EventArgs e)
  215. {
  216. try
  217. {
  218. string resultMessage = "";
  219. Stream myStream;
  220. OpenFileDialog fileDialog = new OpenFileDialog();
  221. fileDialog.InitialDirectory = "../../" ;
  222. fileDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
  223. if(fileDialog.ShowDialog() == DialogResult.OK)
  224. {
  225. if((myStream = fileDialog.OpenFile())!= null)
  226. {
  227. string reportspecStr = ReadReportSpecification(fileDialog.FileName);
  228. specification spec = new specification();
  229. spec.Value = reportspecStr;
  230. myStream.Close();
  231. AddReport addReportObject = new AddReport();
  232. clearResultsWindow();
  233. reportServiceReportSpecification reportspec = new reportServiceReportSpecification();
  234. anyTypeProp reportSpecProperty = new anyTypeProp();
  235. reportSpecProperty.value = reportspecStr;
  236. reportspec.value = spec;
  237. if (0 == OptionChooserCB.Text.CompareTo("Validate Specification"))
  238. {
  239. // validate the file
  240. displayMessage("Validating the file specification : \"" + fileDialog.FileName + "\"...");
  241. addReportObject.validateReportSpec(cBIRS, reportspec, ref resultMessage);
  242. displayMessage(resultMessage);
  243. }
  244. else if (0 == OptionChooserCB.Text.CompareTo("Add Specification to Content Store"))
  245. {
  246. // add the specification
  247. SamplesInput reportNameDlg = new SamplesInput();
  248. string inputReportName = reportNameDlg.getInput("Please enter a name for the new Report","Name", "");
  249. displayMessage("Adding the file specification : \"" + fileDialog.FileName + "\"...");
  250. addReportObject.addReportSpec(cBISS, cBIRS, reportspec, inputReportName, accountPath, ref resultMessage);
  251. displayMessage(resultMessage);
  252. }
  253. }
  254. }
  255. }
  256. catch(SoapException ex)
  257. {
  258. displayMessage("\n...the operation failed.\nThe following information was returned:");
  259. displayMessage(SamplesException.getExceptionMessage( ex));
  260. return;
  261. }
  262. catch(System.Exception ex)
  263. {
  264. if (0 != ex.Message.CompareTo("INPUT_CANCELLED_BY_USER"))
  265. {
  266. SamplesException.ShowExceptionMessage( ex.Message, true, "AddReport Sample - RunOptionButton_Click()" );
  267. }
  268. return;
  269. }
  270. }
  271. private string ReadReportSpecification(string fileName)
  272. {
  273. StreamReader sr = File.OpenText(fileName);
  274. String input;
  275. string reportSpecStr = "";
  276. while ((input=sr.ReadLine())!=null)
  277. {
  278. reportSpecStr += input;
  279. }
  280. sr.Close();
  281. return reportSpecStr;
  282. }
  283. public void setConnection(reportService1 rService, string cBIUrl, string account)
  284. {
  285. cBIRS = rService;
  286. serverUrlTB.Text = cBIUrl;
  287. accountPath = account;
  288. }
  289. public string GetAccountPath()
  290. {
  291. return accountPath;
  292. }
  293. public void displayMessage(string message)
  294. {
  295. resultsDisplayWindowRTB.AppendText(message + "\n");
  296. }
  297. public void clearResultsWindow()
  298. {
  299. resultsDisplayWindowRTB.Clear();
  300. }
  301. public systemService1 CBISS
  302. {
  303. get
  304. {
  305. return cBISS;
  306. }
  307. set
  308. {
  309. cBISS = value;
  310. }
  311. }
  312. }
  313. }