CloudStorageClientForm.cs 7.3 KB

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