using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using FastReport.Forms; using FastReport.Export; using FastReport.Utils; using FastReport.Cloud.OAuth; namespace FastReport.Cloud.StorageClient { /// /// Represents form of Dropbox storage client. /// public partial class CloudStorageClientForm : BaseDialogForm { #region Fields private Report report; private List exports; #endregion // Fields #region Properties /// /// Gets or sets the report template. /// public Report Report { get { return report; } set { report = value; } } /// /// Gets or sets the list of exports. /// public List Exports { get { return exports; } set { exports = value; } } #endregion // Properties #region Constructors /// /// Initializes a new instance of the class. /// public CloudStorageClientForm() : this(new Report()) { } /// /// Initializes a new instance of the class. /// /// The report template. public CloudStorageClientForm(Report report) { this.report = report; InitializeComponent(); } #endregion // Constructors #region Protected Methods /// /// Initializes the list of exports. /// protected void InitExports() { exports = new List(); List list = new List(); cbFileType.Items.Clear(); RegisteredObjects.Exports.EnumItems(list); cbFileType.Items.Add(Res.Get("Preview,SaveNative")); exports.Add(null); foreach (ObjectInfo info in list) { if (info.Object != null) { cbFileType.Items.Add(Res.TryGet(info.Text)); exports.Add(Activator.CreateInstance(info.Object) as ExportBase); } } cbFileType.SelectedIndex = 0; } /// /// Gets the proxy settings. /// /// The proxy settings. protected CloudProxySettings GetProxySettings() { CloudProxySettings proxySettings = null; if (!String.IsNullOrEmpty(tbServer.Text)) { int port = 0; if (!IsNumeric(tbPort.Text)) { FRMessageBox.Error(Res.Get("Cloud,CloudStorage,PortError")); } else { port = Convert.ToInt32(tbPort.Text); } proxySettings = new CloudProxySettings(ProxyType.Http, tbServer.Text, port, tbUsername.Text, tbPassword.Text); } return proxySettings; } /// /// Initializes the component. /// protected virtual void Init() { InitExports(); } /// /// Checks is the string numeric. /// /// The checking string. /// True if string is numeric, otherwise false. protected bool IsNumeric(string str) { if (!String.IsNullOrEmpty(str)) { try { Convert.ToInt32(str); } catch { return false; } } return true; } /// /// Finishes the form work. /// /// Returns true if work has been successfully finished, otherwise false. protected virtual bool Done() { if (!String.IsNullOrEmpty(tbPort.Text)) { if (!IsNumeric(tbPort.Text)) { FRMessageBox.Error(Res.Get("Cloud,CloudStorage,PortError")); tbPort.Focus(); return false; } } return true; } #endregion // Protected Methods #region Public Methods /// public override void Localize() { base.Localize(); MyRes res = new MyRes("Cloud,CloudStorage"); this.Text = res.Get(""); pgFile.Text = res.Get("File"); pgProxy.Text = res.Get("Proxy"); labelFileType.Text = res.Get("FileType"); buttonSettings.Text = res.Get("Settings"); labelServer.Text = res.Get("Server"); labelUsername.Text = res.Get("Username"); labelPassword.Text = res.Get("Password"); } #endregion // Public Methods #region Events Handlers /// /// SelectedIndexChanged event handler for ComboBox File Type. /// /// Event sender. /// Event args. protected void cbFileType_SelectedIndexChanged(object sender, EventArgs e) { buttonSettings.Enabled = cbFileType.SelectedIndex != 0; } /// /// Click event handler for Button Settings. /// /// Event sender. /// Event args. protected void buttonSettings_Click(object sender, EventArgs e) { ExportBase export = exports[cbFileType.SelectedIndex]; export.SetReport(report); export.ShowDialog(); } /// /// Shows a dialog window. /// /// Modal result. public new DialogResult ShowDialog() { Init(); Localize(); UIUtils.CheckRTL(this); return base.ShowDialog(); } /// /// FormClosing event handler for CloudStorageClientForm. /// /// Event sender. /// Event args. protected void CloudStorageClientForm_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult == DialogResult.OK) { if (!Done()) { e.Cancel = true; } } } /// /// Click event handler for button OK. /// /// Event sender. /// Event args. protected virtual void btnOk_Click(object sender, EventArgs e) { DialogResult = DialogResult.OK; Close(); } #endregion // Events Handlers } }