SaveDlg.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. using System;
  9. using System.Drawing;
  10. using System.Collections;
  11. using System.ComponentModel;
  12. using System.Windows.Forms;
  13. using System.Web.Services.Protocols;
  14. using SamplesCommon;
  15. using cognosdotnet_10_2;
  16. namespace Save
  17. {
  18. /// <summary>
  19. /// Summary description for SaveDlg.
  20. /// </summary>
  21. public class SaveDlg : System.Windows.Forms.Form
  22. {
  23. private System.Windows.Forms.MainMenu mainMenu1;
  24. private System.Windows.Forms.MenuItem menuItemFile;
  25. private System.Windows.Forms.MenuItem menuItemExit;
  26. private System.Windows.Forms.MenuItem menuItemHelp;
  27. private System.Windows.Forms.MenuItem menuItemAbout;
  28. private System.Windows.Forms.Label label1;
  29. private System.Windows.Forms.Label label2;
  30. private System.Windows.Forms.ComboBox saveOptionsCB;
  31. private System.Windows.Forms.Label label3;
  32. private System.Windows.Forms.ComboBox reportListCB;
  33. private System.Windows.Forms.Button runOption;
  34. private System.Windows.Forms.RichTextBox resultsDisplayWindowRTB;
  35. private IContainer components;
  36. private System.Windows.Forms.GroupBox groupBox1;
  37. private System.Windows.Forms.TextBox reportSearchPathTB;
  38. private System.Windows.Forms.TextBox serverUrlTB;
  39. public static SamplesConnect cBIConnection = null;
  40. public SaveDlg()
  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(SaveDlg));
  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.label1 = new System.Windows.Forms.Label();
  79. this.serverUrlTB = new System.Windows.Forms.TextBox();
  80. this.label2 = new System.Windows.Forms.Label();
  81. this.saveOptionsCB = new System.Windows.Forms.ComboBox();
  82. this.label3 = new System.Windows.Forms.Label();
  83. this.reportListCB = new System.Windows.Forms.ComboBox();
  84. this.runOption = new System.Windows.Forms.Button();
  85. this.resultsDisplayWindowRTB = new System.Windows.Forms.RichTextBox();
  86. this.groupBox1 = new System.Windows.Forms.GroupBox();
  87. this.reportSearchPathTB = new System.Windows.Forms.TextBox();
  88. this.SuspendLayout();
  89. //
  90. // mainMenu1
  91. //
  92. this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  93. this.menuItemFile,
  94. this.menuItemHelp});
  95. //
  96. // menuItemFile
  97. //
  98. this.menuItemFile.Index = 0;
  99. this.menuItemFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  100. this.menuItemExit});
  101. this.menuItemFile.Text = "File";
  102. //
  103. // menuItemExit
  104. //
  105. this.menuItemExit.Index = 0;
  106. this.menuItemExit.Text = "Exit";
  107. this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
  108. //
  109. // menuItemHelp
  110. //
  111. this.menuItemHelp.Index = 1;
  112. this.menuItemHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  113. this.menuItemAbout});
  114. this.menuItemHelp.Text = "Help";
  115. //
  116. // menuItemAbout
  117. //
  118. this.menuItemAbout.Index = 0;
  119. this.menuItemAbout.Text = "About";
  120. this.menuItemAbout.Click += new System.EventHandler(this.menuItemAbout_Click);
  121. //
  122. // label1
  123. //
  124. this.label1.Location = new System.Drawing.Point(16, 8);
  125. this.label1.Name = "label1";
  126. this.label1.Size = new System.Drawing.Size(131, 16);
  127. this.label1.TabIndex = 0;
  128. this.label1.Text = "Server URL";
  129. //
  130. // serverUrlTB
  131. //
  132. this.serverUrlTB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  133. | System.Windows.Forms.AnchorStyles.Right)));
  134. this.serverUrlTB.BackColor = System.Drawing.SystemColors.Control;
  135. this.serverUrlTB.Enabled = false;
  136. this.serverUrlTB.Location = new System.Drawing.Point(16, 24);
  137. this.serverUrlTB.Name = "serverUrlTB";
  138. this.serverUrlTB.Size = new System.Drawing.Size(600, 20);
  139. this.serverUrlTB.TabIndex = 1;
  140. //
  141. // label2
  142. //
  143. this.label2.Location = new System.Drawing.Point(16, 64);
  144. this.label2.Name = "label2";
  145. this.label2.Size = new System.Drawing.Size(72, 16);
  146. this.label2.TabIndex = 2;
  147. this.label2.Text = "Save Options";
  148. //
  149. // saveOptionsCB
  150. //
  151. this.saveOptionsCB.Location = new System.Drawing.Point(16, 80);
  152. this.saveOptionsCB.Name = "saveOptionsCB";
  153. this.saveOptionsCB.Size = new System.Drawing.Size(256, 21);
  154. this.saveOptionsCB.TabIndex = 3;
  155. //
  156. // label3
  157. //
  158. this.label3.Location = new System.Drawing.Point(288, 64);
  159. this.label3.Name = "label3";
  160. this.label3.Size = new System.Drawing.Size(72, 16);
  161. this.label3.TabIndex = 4;
  162. this.label3.Text = "Report Name";
  163. //
  164. // reportListCB
  165. //
  166. this.reportListCB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  167. | System.Windows.Forms.AnchorStyles.Right)));
  168. this.reportListCB.Location = new System.Drawing.Point(288, 80);
  169. this.reportListCB.Name = "reportListCB";
  170. this.reportListCB.Size = new System.Drawing.Size(328, 21);
  171. this.reportListCB.TabIndex = 5;
  172. this.reportListCB.SelectedIndexChanged += new System.EventHandler(this.reportListCB_SelectedIndexChanged);
  173. //
  174. // runOption
  175. //
  176. this.runOption.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  177. this.runOption.Location = new System.Drawing.Point(528, 144);
  178. this.runOption.Name = "runOption";
  179. this.runOption.Size = new System.Drawing.Size(88, 32);
  180. this.runOption.TabIndex = 6;
  181. this.runOption.Text = "Run Option";
  182. this.runOption.Click += new System.EventHandler(this.runOption_Click);
  183. //
  184. // resultsDisplayWindowRTB
  185. //
  186. this.resultsDisplayWindowRTB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  187. | System.Windows.Forms.AnchorStyles.Left)
  188. | System.Windows.Forms.AnchorStyles.Right)));
  189. this.resultsDisplayWindowRTB.BackColor = System.Drawing.SystemColors.Control;
  190. this.resultsDisplayWindowRTB.Location = new System.Drawing.Point(24, 200);
  191. this.resultsDisplayWindowRTB.Name = "resultsDisplayWindowRTB";
  192. this.resultsDisplayWindowRTB.Size = new System.Drawing.Size(584, 152);
  193. this.resultsDisplayWindowRTB.TabIndex = 7;
  194. this.resultsDisplayWindowRTB.Text = "";
  195. //
  196. // groupBox1
  197. //
  198. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  199. | System.Windows.Forms.AnchorStyles.Left)
  200. | System.Windows.Forms.AnchorStyles.Right)));
  201. this.groupBox1.Location = new System.Drawing.Point(16, 184);
  202. this.groupBox1.Name = "groupBox1";
  203. this.groupBox1.Size = new System.Drawing.Size(600, 176);
  204. this.groupBox1.TabIndex = 8;
  205. this.groupBox1.TabStop = false;
  206. this.groupBox1.Text = "Results Display Window";
  207. //
  208. // reportSearchPathTB
  209. //
  210. this.reportSearchPathTB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  211. | System.Windows.Forms.AnchorStyles.Right)));
  212. this.reportSearchPathTB.BackColor = System.Drawing.SystemColors.Control;
  213. this.reportSearchPathTB.Location = new System.Drawing.Point(16, 112);
  214. this.reportSearchPathTB.Name = "reportSearchPathTB";
  215. this.reportSearchPathTB.Size = new System.Drawing.Size(600, 20);
  216. this.reportSearchPathTB.TabIndex = 9;
  217. //
  218. // SaveDlg
  219. //
  220. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  221. this.ClientSize = new System.Drawing.Size(632, 374);
  222. this.Controls.Add(this.reportSearchPathTB);
  223. this.Controls.Add(this.serverUrlTB);
  224. this.Controls.Add(this.resultsDisplayWindowRTB);
  225. this.Controls.Add(this.runOption);
  226. this.Controls.Add(this.reportListCB);
  227. this.Controls.Add(this.label3);
  228. this.Controls.Add(this.saveOptionsCB);
  229. this.Controls.Add(this.label2);
  230. this.Controls.Add(this.label1);
  231. this.Controls.Add(this.groupBox1);
  232. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  233. this.Menu = this.mainMenu1;
  234. this.Name = "SaveDlg";
  235. this.Text = "Save Options";
  236. this.Load += new System.EventHandler(this.SaveDlg_Load);
  237. this.ResumeLayout(false);
  238. this.PerformLayout();
  239. }
  240. #endregion
  241. private void menuItemExit_Click(object sender, System.EventArgs e)
  242. {
  243. this.Close();
  244. }
  245. private void menuItemAbout_Click(object sender, System.EventArgs e)
  246. {
  247. SamplesAbout about = new SamplesAbout();
  248. about.applicationName = "AddReport";
  249. about.applicationVersion = "1.1";
  250. about.Show();
  251. }
  252. private void SaveDlg_Load(object sender, System.EventArgs e)
  253. {
  254. saveOptionsCB.Items.Add("Save Report");
  255. saveOptionsCB.Items.Add("Save Report As");
  256. saveOptionsCB.SelectedIndex = 0;
  257. }
  258. // This method is the main entry point of this sample.
  259. private void runOption_Click(object sender, System.EventArgs e)
  260. {
  261. bool saveAsFlag = false;
  262. string newReportName = "";
  263. string resultMessage = "";
  264. string selectedOption = "";
  265. BaseClassWrapper selectedObject = null;
  266. clearResultsWindow();
  267. try
  268. {
  269. // Validate the selected report or query
  270. selectedObject = (BaseClassWrapper)reportListCB.SelectedItem;
  271. if (selectedObject == null)
  272. {
  273. MessageBox.Show("Please select a valid entry.");
  274. return;
  275. }
  276. // Validate the selected save option
  277. selectedOption = (string)saveOptionsCB.SelectedItem;
  278. if ( (selectedOption == null) || (0 == selectedOption.CompareTo("")) )
  279. {
  280. MessageBox.Show("Please select a Save Option from the list.");
  281. return;
  282. }
  283. else if (0 == selectedOption.CompareTo("Save Report"))
  284. {
  285. displayMessage("Saving the report '" + selectedObject.defaultName.value + "'...");
  286. saveAsFlag = false;
  287. }
  288. else if (0 == selectedOption.CompareTo("Save Report As"))
  289. {
  290. // Get the new report name and location
  291. SamplesInput si = new SamplesInput();
  292. newReportName = si.getInput("Report Name", "Please enter a new name for the report", selectedObject.defaultName.value + "_1");
  293. displayMessage("Saving the report '" + selectedObject.defaultName.value + "' as " + newReportName +"...");
  294. saveAsFlag = true;
  295. }
  296. // Call the function that will execute the selected option
  297. Save saveOpts = new Save();
  298. saveOpts.runOption(cBIConnection,
  299. selectedObject.searchPath.value,
  300. saveAsFlag,
  301. newReportName,
  302. ref resultMessage);
  303. displayMessage(resultMessage);
  304. }
  305. catch(SoapException ex)
  306. {
  307. displayMessage("\n...the operation failed.\nThe following information was returned:");
  308. displayMessage(SamplesException.getExceptionMessage( ex));
  309. return;
  310. }
  311. catch(System.Exception ex)
  312. {
  313. if (0 != ex.Message.CompareTo("INPUT_CANCELLED_BY_USER"))
  314. {
  315. SamplesException.ShowExceptionMessage( ex.Message, true, "CancelReport Sample" );
  316. displayMessage(ex.Message);
  317. }
  318. return;
  319. }
  320. }
  321. public void setReportList(BaseClassWrapper[] reportAndQueryList)
  322. {
  323. reportListCB.Items.AddRange(reportAndQueryList);
  324. }
  325. public void setSelectedReportIndex(int value)
  326. {
  327. reportListCB.SelectedIndex = value;
  328. }
  329. public void setConnection(SamplesConnect connection, string cBIUrl)
  330. {
  331. cBIConnection = connection;
  332. serverUrlTB.Text = cBIUrl;
  333. }
  334. public void displayMessage(string message)
  335. {
  336. resultsDisplayWindowRTB.AppendText(message + "\n");
  337. }
  338. public void clearResultsWindow()
  339. {
  340. resultsDisplayWindowRTB.Clear();
  341. }
  342. private void reportListCB_SelectedIndexChanged(object sender, System.EventArgs e)
  343. {
  344. BaseClassWrapper selectedObject = (BaseClassWrapper)reportListCB.SelectedItem;
  345. if (selectedObject == null)
  346. {
  347. return;
  348. }
  349. reportSearchPathTB.Text = selectedObject.searchPath.value;
  350. }
  351. }
  352. }