MessengerForm.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms;
  4. using FastReport.Forms;
  5. using FastReport.Export;
  6. using FastReport.Utils;
  7. namespace FastReport.Messaging
  8. {
  9. /// <summary>
  10. /// Represents form of messenger.
  11. /// </summary>
  12. public partial class MessengerForm : BaseDialogForm
  13. {
  14. #region Fields
  15. private Report report;
  16. private List<ExportBase> exports;
  17. #endregion // Fields
  18. #region Properties
  19. /// <summary>
  20. /// Gets or sets the report template.
  21. /// </summary>
  22. public Report Report
  23. {
  24. get { return report; }
  25. set { report = value; }
  26. }
  27. /// <summary>
  28. /// Gets or sets the list of exports.
  29. /// </summary>
  30. public List<ExportBase> Exports
  31. {
  32. get { return exports; }
  33. set { exports = value; }
  34. }
  35. #endregion // Properties
  36. #region Constructors
  37. /// <summary>
  38. /// Initializes a new instance of the <see cref="MessengerForm"/> class.
  39. /// </summary>
  40. public MessengerForm()
  41. {
  42. this.report = new Report();
  43. InitializeComponent();
  44. Localize();
  45. Init();
  46. }
  47. /// <summary>
  48. /// Initializes a new instance of the <see cref="MessengerForm"/> class.
  49. /// </summary>
  50. /// <param name="report">The report template.</param>
  51. public MessengerForm(Report report)
  52. {
  53. this.report = report;
  54. InitializeComponent();
  55. Localize();
  56. Init();
  57. }
  58. #endregion // Constructors
  59. #region Protected Methods
  60. /// <summary>
  61. /// Initializes the list of exports.
  62. /// </summary>
  63. protected void InitExports()
  64. {
  65. exports = new List<ExportBase>();
  66. List<ObjectInfo> list = new List<ObjectInfo>();
  67. cbFileType.Items.Clear();
  68. RegisteredObjects.Exports.EnumItems(list);
  69. cbFileType.Items.Add(Res.Get("Preview,SaveNative"));
  70. exports.Add(null);
  71. foreach (ObjectInfo info in list)
  72. {
  73. if (info.Object != null)
  74. {
  75. cbFileType.Items.Add(Res.TryGet(info.Text));
  76. exports.Add(Activator.CreateInstance(info.Object) as ExportBase);
  77. }
  78. }
  79. cbFileType.SelectedIndex = 0;
  80. }
  81. /// <summary>
  82. /// Gets the proxy settings.
  83. /// </summary>
  84. /// <returns>The proxy settings.</returns>
  85. protected ProxySettings GetProxySettings()
  86. {
  87. ProxySettings proxySettings = null;
  88. if (!String.IsNullOrEmpty(tbProxyServer.Text))
  89. {
  90. int port = 0;
  91. if (!IsNumeric(tbProxyPort.Text))
  92. {
  93. FRMessageBox.Error(Res.Get("Messaging,MessengerForm,PortError"));
  94. }
  95. else
  96. {
  97. port = Convert.ToInt32(tbProxyPort.Text);
  98. }
  99. proxySettings = new ProxySettings(tbProxyServer.Text, port, tbProxyUsername.Text, tbProxyPassword.Text, ProxyType.Http);
  100. }
  101. return proxySettings;
  102. }
  103. /// <summary>
  104. /// Initializes the component.
  105. /// </summary>
  106. protected virtual void Init()
  107. {
  108. InitExports();
  109. }
  110. /// <summary>
  111. /// Checks is the string numeric.
  112. /// </summary>
  113. /// <param name="str">The checking string.</param>
  114. /// <returns>True if string is numeric, otherwise false.</returns>
  115. protected bool IsNumeric(string str)
  116. {
  117. if (!String.IsNullOrEmpty(str))
  118. {
  119. try
  120. {
  121. Convert.ToInt32(str);
  122. }
  123. catch
  124. {
  125. return false;
  126. }
  127. }
  128. return true;
  129. }
  130. /// <summary>
  131. /// Finishes the form work.
  132. /// </summary>
  133. /// <returns>Returns true if work has been successfully finished, otherwise false.</returns>
  134. protected virtual bool Done()
  135. {
  136. if (!String.IsNullOrEmpty(tbProxyPort.Text))
  137. {
  138. if (!IsNumeric(tbProxyPort.Text))
  139. {
  140. FRMessageBox.Error(Res.Get("Messaging,MessengerForm,PortError"));
  141. tbProxyPort.Focus();
  142. return false;
  143. }
  144. }
  145. return true;
  146. }
  147. #endregion // Protected Methods
  148. #region Public Methods
  149. /// <inheritdoc/>
  150. public override void Localize()
  151. {
  152. base.Localize();
  153. MyRes res = new MyRes("Messaging,MessengerForm");
  154. this.Text = res.Get("");
  155. pgFile.Text = res.Get("File");
  156. pgProxy.Text = res.Get("Proxy");
  157. labelFileType.Text = res.Get("FileType");
  158. buttonSettings.Text = res.Get("Settings");
  159. labelProxyServer.Text = res.Get("Server");
  160. labelProxyUsername.Text = res.Get("Username");
  161. labelProxyPassword.Text = res.Get("Password");
  162. }
  163. #endregion // Public Methods
  164. #region Events Handlers
  165. /// <summary>
  166. /// SelectedIndexChanged event handler for ComboBox File Type.
  167. /// </summary>
  168. /// <param name="sender">Event sender.</param>
  169. /// <param name="e">Event args.</param>
  170. protected void cbFileType_SelectedIndexChanged(object sender, EventArgs e)
  171. {
  172. buttonSettings.Enabled = cbFileType.SelectedIndex != 0;
  173. }
  174. /// <summary>
  175. /// Click event handler for Button Settings.
  176. /// </summary>
  177. /// <param name="sender">Event sender.</param>
  178. /// <param name="e">Event args.</param>
  179. protected void buttonSettings_Click(object sender, EventArgs e)
  180. {
  181. ExportBase export = exports[cbFileType.SelectedIndex];
  182. export.SetReport(report);
  183. export.ShowDialog();
  184. }
  185. /// <summary>
  186. /// FormClosing event handler for CloudStorageClientForm.
  187. /// </summary>
  188. /// <param name="sender">Event sender.</param>
  189. /// <param name="e">Event args.</param>
  190. protected void MessengerForm_FormClosing(object sender, FormClosingEventArgs e)
  191. {
  192. if (DialogResult == DialogResult.OK)
  193. {
  194. if (!Done())
  195. {
  196. e.Cancel = true;
  197. }
  198. }
  199. }
  200. /// <summary>
  201. /// Click event handler for button OK.
  202. /// </summary>
  203. /// <param name="sender">Event sender.</param>
  204. /// <param name="e">Event args.</param>
  205. protected virtual void btnOk_Click(object sender, EventArgs e)
  206. {
  207. DialogResult = DialogResult.OK;
  208. Close();
  209. }
  210. #endregion // Events Handlers
  211. }
  212. }