EmailDlg.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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.Threading;
  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. //using EmailContactsDlg;
  18. namespace Email
  19. {
  20. /// <summary>
  21. /// Summary description for EmailDlg.
  22. /// </summary>
  23. public class EmailDlg : System.Windows.Forms.Form
  24. {
  25. private System.Windows.Forms.MainMenu mainMenu1;
  26. private System.Windows.Forms.MenuItem menuItemFile;
  27. private System.Windows.Forms.MenuItem menuItemExit;
  28. private System.Windows.Forms.MenuItem menuItemHelp;
  29. private System.Windows.Forms.MenuItem menuItemAbout;
  30. private System.Windows.Forms.Label ServerUrlLBL;
  31. private System.Windows.Forms.Label ReportNameLBL;
  32. private System.Windows.Forms.Button emailButton;
  33. private System.Windows.Forms.Label label1;
  34. private System.Windows.Forms.ComboBox reportListCB;
  35. private System.Windows.Forms.ComboBox emailOptionCB;
  36. private IContainer components;
  37. private System.Windows.Forms.RichTextBox resultsDisplayWindowRTB;
  38. private System.Windows.Forms.GroupBox groupBox1;
  39. private System.Windows.Forms.TextBox reportSearchPathTB;
  40. private System.Windows.Forms.TextBox serverUrlTB;
  41. private SamplesConnect cBIConnection = null;
  42. public EmailDlg()
  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. /// <summary>
  53. /// Clean up any resources being used.
  54. /// </summary>
  55. protected override void Dispose( bool disposing )
  56. {
  57. if( disposing )
  58. {
  59. if(components != null)
  60. {
  61. components.Dispose();
  62. }
  63. }
  64. base.Dispose( disposing );
  65. }
  66. #region Windows Form Designer generated code
  67. /// <summary>
  68. /// Required method for Designer support - do not modify
  69. /// the contents of this method with the code editor.
  70. /// </summary>
  71. private void InitializeComponent()
  72. {
  73. this.components = new System.ComponentModel.Container();
  74. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(EmailDlg));
  75. this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
  76. this.menuItemFile = new System.Windows.Forms.MenuItem();
  77. this.menuItemExit = new System.Windows.Forms.MenuItem();
  78. this.menuItemHelp = new System.Windows.Forms.MenuItem();
  79. this.menuItemAbout = new System.Windows.Forms.MenuItem();
  80. this.ServerUrlLBL = new System.Windows.Forms.Label();
  81. this.serverUrlTB = new System.Windows.Forms.TextBox();
  82. this.ReportNameLBL = new System.Windows.Forms.Label();
  83. this.reportListCB = new System.Windows.Forms.ComboBox();
  84. this.resultsDisplayWindowRTB = new System.Windows.Forms.RichTextBox();
  85. this.emailButton = new System.Windows.Forms.Button();
  86. this.label1 = new System.Windows.Forms.Label();
  87. this.emailOptionCB = new System.Windows.Forms.ComboBox();
  88. this.groupBox1 = new System.Windows.Forms.GroupBox();
  89. this.reportSearchPathTB = new System.Windows.Forms.TextBox();
  90. this.SuspendLayout();
  91. //
  92. // mainMenu1
  93. //
  94. this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  95. this.menuItemFile,
  96. this.menuItemHelp});
  97. //
  98. // menuItemFile
  99. //
  100. this.menuItemFile.Index = 0;
  101. this.menuItemFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  102. this.menuItemExit});
  103. this.menuItemFile.Text = "File";
  104. //
  105. // menuItemExit
  106. //
  107. this.menuItemExit.Index = 0;
  108. this.menuItemExit.Text = "Exit";
  109. this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
  110. //
  111. // menuItemHelp
  112. //
  113. this.menuItemHelp.Index = 1;
  114. this.menuItemHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  115. this.menuItemAbout});
  116. this.menuItemHelp.Text = "Help";
  117. //
  118. // menuItemAbout
  119. //
  120. this.menuItemAbout.Index = 0;
  121. this.menuItemAbout.Text = "About";
  122. this.menuItemAbout.Click += new System.EventHandler(this.menuItemAbout_Click);
  123. //
  124. // ServerUrlLBL
  125. //
  126. this.ServerUrlLBL.Location = new System.Drawing.Point(16, 16);
  127. this.ServerUrlLBL.Name = "ServerUrlLBL";
  128. this.ServerUrlLBL.Size = new System.Drawing.Size(142, 16);
  129. this.ServerUrlLBL.TabIndex = 0;
  130. this.ServerUrlLBL.Text = "Server URL";
  131. //
  132. // serverUrlTB
  133. //
  134. this.serverUrlTB.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.serverUrlTB.BackColor = System.Drawing.SystemColors.Control;
  138. this.serverUrlTB.Enabled = false;
  139. this.serverUrlTB.Location = new System.Drawing.Point(16, 32);
  140. this.serverUrlTB.Name = "serverUrlTB";
  141. this.serverUrlTB.Size = new System.Drawing.Size(496, 20);
  142. this.serverUrlTB.TabIndex = 1;
  143. this.serverUrlTB.Text = "http://localhost/crn/cgi-bin/cognos.cgi";
  144. //
  145. // ReportNameLBL
  146. //
  147. this.ReportNameLBL.Location = new System.Drawing.Point(232, 72);
  148. this.ReportNameLBL.Name = "ReportNameLBL";
  149. this.ReportNameLBL.Size = new System.Drawing.Size(72, 16);
  150. this.ReportNameLBL.TabIndex = 2;
  151. this.ReportNameLBL.Text = "Report Name";
  152. //
  153. // reportListCB
  154. //
  155. this.reportListCB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  156. | System.Windows.Forms.AnchorStyles.Left)
  157. | System.Windows.Forms.AnchorStyles.Right)));
  158. this.reportListCB.Location = new System.Drawing.Point(232, 88);
  159. this.reportListCB.Name = "reportListCB";
  160. this.reportListCB.Size = new System.Drawing.Size(280, 21);
  161. this.reportListCB.TabIndex = 3;
  162. this.reportListCB.SelectedIndexChanged += new System.EventHandler(this.reportListCB_SelectedIndexChanged);
  163. //
  164. // resultsDisplayWindowRTB
  165. //
  166. this.resultsDisplayWindowRTB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  167. | System.Windows.Forms.AnchorStyles.Left)
  168. | System.Windows.Forms.AnchorStyles.Right)));
  169. this.resultsDisplayWindowRTB.BackColor = System.Drawing.SystemColors.Control;
  170. this.resultsDisplayWindowRTB.Location = new System.Drawing.Point(24, 200);
  171. this.resultsDisplayWindowRTB.Name = "resultsDisplayWindowRTB";
  172. this.resultsDisplayWindowRTB.Size = new System.Drawing.Size(480, 136);
  173. this.resultsDisplayWindowRTB.TabIndex = 4;
  174. this.resultsDisplayWindowRTB.Text = "";
  175. //
  176. // emailButton
  177. //
  178. this.emailButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  179. this.emailButton.Location = new System.Drawing.Point(432, 144);
  180. this.emailButton.Name = "emailButton";
  181. this.emailButton.Size = new System.Drawing.Size(80, 32);
  182. this.emailButton.TabIndex = 6;
  183. this.emailButton.Text = "Email";
  184. this.emailButton.Click += new System.EventHandler(this.emailButton_Click);
  185. //
  186. // label1
  187. //
  188. this.label1.Location = new System.Drawing.Point(16, 72);
  189. this.label1.Name = "label1";
  190. this.label1.Size = new System.Drawing.Size(104, 16);
  191. this.label1.TabIndex = 7;
  192. this.label1.Text = "Select Email Option";
  193. //
  194. // emailOptionCB
  195. //
  196. this.emailOptionCB.Location = new System.Drawing.Point(16, 88);
  197. this.emailOptionCB.Name = "emailOptionCB";
  198. this.emailOptionCB.Size = new System.Drawing.Size(200, 21);
  199. this.emailOptionCB.TabIndex = 8;
  200. //
  201. // groupBox1
  202. //
  203. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  204. | System.Windows.Forms.AnchorStyles.Left)
  205. | System.Windows.Forms.AnchorStyles.Right)));
  206. this.groupBox1.Location = new System.Drawing.Point(16, 184);
  207. this.groupBox1.Name = "groupBox1";
  208. this.groupBox1.Size = new System.Drawing.Size(496, 160);
  209. this.groupBox1.TabIndex = 9;
  210. this.groupBox1.TabStop = false;
  211. this.groupBox1.Text = "Results Display Window";
  212. //
  213. // reportSearchPathTB
  214. //
  215. this.reportSearchPathTB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  216. | System.Windows.Forms.AnchorStyles.Right)));
  217. this.reportSearchPathTB.BackColor = System.Drawing.SystemColors.Control;
  218. this.reportSearchPathTB.Location = new System.Drawing.Point(16, 120);
  219. this.reportSearchPathTB.Name = "reportSearchPathTB";
  220. this.reportSearchPathTB.Size = new System.Drawing.Size(496, 20);
  221. this.reportSearchPathTB.TabIndex = 10;
  222. //
  223. // EmailDlg
  224. //
  225. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  226. this.ClientSize = new System.Drawing.Size(528, 353);
  227. this.Controls.Add(this.reportSearchPathTB);
  228. this.Controls.Add(this.serverUrlTB);
  229. this.Controls.Add(this.resultsDisplayWindowRTB);
  230. this.Controls.Add(this.groupBox1);
  231. this.Controls.Add(this.emailOptionCB);
  232. this.Controls.Add(this.label1);
  233. this.Controls.Add(this.emailButton);
  234. this.Controls.Add(this.reportListCB);
  235. this.Controls.Add(this.ReportNameLBL);
  236. this.Controls.Add(this.ServerUrlLBL);
  237. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  238. this.Menu = this.mainMenu1;
  239. this.Name = "EmailDlg";
  240. this.Text = "Email Sample";
  241. this.ResumeLayout(false);
  242. this.PerformLayout();
  243. }
  244. #endregion
  245. private void menuItemExit_Click(object sender, System.EventArgs e)
  246. {
  247. this.Close();
  248. }
  249. private void menuItemAbout_Click(object sender, System.EventArgs e)
  250. {
  251. SamplesAbout about = new SamplesAbout();
  252. about.applicationName = "Email Sample";
  253. about.applicationVersion = "1.1";
  254. about.Show();
  255. }
  256. private void emailButton_Click(object sender, System.EventArgs e)
  257. {
  258. string emailAddress = "";
  259. string emailOption = (string)emailOptionCB.SelectedItem;
  260. EmailContactsDlg ecObject = new EmailContactsDlg();
  261. Email emailObject = new Email();
  262. // 1. check the list of contacts in the content store
  263. addressSMTP[] contactList = emailObject.getContactEmails(cBIConnection.CBICMS);
  264. int nbContacts = contactList.Length;
  265. if ( (contactList != null) && (nbContacts > 0) )
  266. {
  267. // 1.1 add the list of contact to the contact list combo box.
  268. ecObject.setContactEmails(contactList);
  269. }
  270. else
  271. {
  272. // 1.2 notify there are no contacts in the content store
  273. resultsDisplayWindowRTB.Clear();
  274. resultsDisplayWindowRTB.AppendText("Please make sure a contact exists in the content store.");
  275. return;
  276. }
  277. // 2. Get the emailing option selected by the user.
  278. if (0 == emailOption.CompareTo("Email Selected User"))
  279. {
  280. ecObject.setAllUsersMode(false);
  281. ecObject.setSelectedEmailAddress(0); // default to the first in the list
  282. }
  283. else
  284. {
  285. ecObject.setAllUsersMode(true);
  286. }
  287. resultsDisplayWindowRTB.Clear();
  288. ecObject.ShowDialog();
  289. if (ecObject.isContactInfoSet == true)
  290. {
  291. emailAddress = ecObject.emailAddress;
  292. BaseClassWrapper selectedObject = (BaseClassWrapper)reportListCB.SelectedItem;
  293. string emailSubject = ecObject.emailSubject;
  294. string emailBody = ecObject.emailBody;
  295. if ( (emailAddress == null) || (0 == emailAddress.CompareTo("")) )
  296. {
  297. displayMessage("Emailing the report : \"" + selectedObject.defaultName.value + "\" to all users...");
  298. }
  299. else
  300. {
  301. displayMessage("Emailing the report : \"" + selectedObject.defaultName.value + "\" to " + emailAddress + "...");
  302. }
  303. // create a thread to still have UI control while sending email
  304. EmailArgsObject emailArgsObj = new EmailArgsObject(emailObject, selectedObject, emailAddress, emailSubject, emailBody);
  305. ThreadPool.QueueUserWorkItem(new WaitCallback(executeEmailThread), emailArgsObj);
  306. }
  307. }
  308. public void setConnection(SamplesConnect connection, string cBIUrl)
  309. {
  310. cBIConnection = connection;
  311. serverUrlTB.Text = cBIUrl;
  312. }
  313. public void setReportList(string[] reportList)
  314. {
  315. int nbReports = reportList.GetLength(0);
  316. for (int i=0;i<nbReports;i++)
  317. {
  318. reportListCB.Items.Add(reportList[i]);
  319. }
  320. }
  321. public void addEmailOptions()
  322. {
  323. emailOptionCB.Items.Add("Email Selected User");
  324. emailOptionCB.Items.Add("Email All Contacts");
  325. }
  326. public void setReportList(BaseClassWrapper[] reportAndQueryList)
  327. {
  328. reportListCB.Items.AddRange(reportAndQueryList);
  329. }
  330. public void setSelectedReportIndex(int value)
  331. {
  332. reportListCB.SelectedIndex = value;
  333. }
  334. public void setSelectedEmailOption(int value)
  335. {
  336. emailOptionCB.SelectedIndex = value;
  337. }
  338. private void executeEmailThread(Object stateInfo)
  339. {
  340. try
  341. {
  342. EmailArgsObject eaObj = (EmailArgsObject) stateInfo;
  343. string output = eaObj.emailObject.sendEmail(cBIConnection, eaObj.reportObj, eaObj.emailAddress, eaObj.emailSubject, eaObj.emailBody);
  344. displayMessage(output);
  345. }
  346. catch (SoapException ex)
  347. {
  348. displayMessage("\n...the operation failed.\nThe following information was returned:");
  349. displayMessage(SamplesException.getExceptionMessage(ex));
  350. return;
  351. }
  352. catch (System.Exception ex)
  353. {
  354. SamplesException.ShowExceptionMessage( ex.Message, true, "Email Report Sample" );
  355. return;
  356. }
  357. }
  358. public void displayMessage(string message)
  359. {
  360. resultsDisplayWindowRTB.AppendText(message + "\n");
  361. }
  362. private void reportListCB_SelectedIndexChanged(object sender, System.EventArgs e)
  363. {
  364. BaseClassWrapper selectedObject = (BaseClassWrapper)reportListCB.SelectedItem;
  365. if (selectedObject == null)
  366. {
  367. return;
  368. }
  369. reportSearchPathTB.Text = selectedObject.searchPath.value;
  370. }
  371. }
  372. }