using System; using System.Collections.Generic; using System.Windows.Forms; using FastReport.Forms; using FastReport.Export; using FastReport.Utils; namespace FastReport.Messaging { /// /// Represents form of messenger. /// public partial class MessengerForm : 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 MessengerForm() { this.report = new Report(); InitializeComponent(); Localize(); Init(); } /// /// Initializes a new instance of the class. /// /// The report template. public MessengerForm(Report report) { this.report = report; InitializeComponent(); Localize(); Init(); } #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 ProxySettings GetProxySettings() { ProxySettings proxySettings = null; if (!String.IsNullOrEmpty(tbProxyServer.Text)) { int port = 0; if (!IsNumeric(tbProxyPort.Text)) { FRMessageBox.Error(Res.Get("Messaging,MessengerForm,PortError")); } else { port = Convert.ToInt32(tbProxyPort.Text); } proxySettings = new ProxySettings(tbProxyServer.Text, port, tbProxyUsername.Text, tbProxyPassword.Text, ProxyType.Http); } 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(tbProxyPort.Text)) { if (!IsNumeric(tbProxyPort.Text)) { FRMessageBox.Error(Res.Get("Messaging,MessengerForm,PortError")); tbProxyPort.Focus(); return false; } } return true; } #endregion // Protected Methods #region Public Methods /// public override void Localize() { base.Localize(); MyRes res = new MyRes("Messaging,MessengerForm"); this.Text = res.Get(""); pgFile.Text = res.Get("File"); pgProxy.Text = res.Get("Proxy"); labelFileType.Text = res.Get("FileType"); buttonSettings.Text = res.Get("Settings"); labelProxyServer.Text = res.Get("Server"); labelProxyUsername.Text = res.Get("Username"); labelProxyPassword.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(); } /// /// FormClosing event handler for CloudStorageClientForm. /// /// Event sender. /// Event args. protected void MessengerForm_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 } }