123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.IO;
- using System.Windows.Forms;
- using FastReport.Cloud.StorageClient;
- using FastReport.Cloud.StorageClient.Box;
- using FastReport.Cloud.StorageClient.Dropbox;
- using FastReport.Cloud.StorageClient.Ftp;
- using FastReport.Cloud.StorageClient.GoogleDrive;
- using FastReport.Cloud.StorageClient.S3;
- using FastReport.Cloud.StorageClient.SkyDrive;
- using FastReport.Design;
- using FastReport.DevComponents.DotNetBar;
- using FastReport.Export;
- using FastReport.Export.Email;
- using FastReport.Messaging;
- using FastReport.Utils;
- using Box = FastReport.Cloud.StorageClient.Box;
- using GoogleDrive = FastReport.Cloud.StorageClient.GoogleDrive;
- using SkyDrive = FastReport.Cloud.StorageClient.SkyDrive;
- #if !DEBUG
- using FastReport.Forms;
- #endif
- namespace FastReport.Preview
- {
- /// <summary>
- /// Represents a Windows Forms control used to preview a report.
- /// </summary>
- /// <remarks>
- /// To use this control, place it on a form and link it to a report using the report's
- /// <see cref="FastReport.Report.Preview"/> property. To show a report, call
- /// the <b>Report.Show</b> method:
- /// <code>
- /// report1.Preview = previewControl1;
- /// report1.Show();
- /// </code>
- /// <para>Use this control's methods such as <see cref="Print"/>, <see cref="Save()"/> etc. to
- /// handle the preview. Call <see cref="Clear"/> method to clear the preview.</para>
- /// <para>You can specify whether the standard toolbar is visible in the <see cref="ToolbarVisible"/>
- /// property. The <see cref="StatusbarVisible"/> property allows you to hide/show the statusbar.
- /// </para>
- /// </remarks>
- [ToolboxItem(true), ToolboxBitmap(typeof(Report), "Resources.PreviewControl.bmp")]
- public partial class PreviewControl : UserControl
- {
- #region Fields
- private Report report;
- private List<PreviewTab> documents;
- private bool toolbarVisible;
- private bool statusbarVisible;
- private Color pageBorderColor;
- private Color activePageBorderColor;
- private PreviewButtons buttons;
- private PreviewExports exports;
- private PreviewClouds clouds;
- private bool updatingZoom;
- private Timer updateTimer;
- private Timer uploadTimer;
- private float zoomToUpdate;
- private float defaultZoom;
- private bool locked;
- private PreviewTab currentPreview;
- private bool fastScrolling;
- private UIStyle uiStyle;
- private bool useBackColor;
- private Point pageOffset;
- private string saveInitialDirectory;
- #endregion
- #region Properties
- /// <summary>
- /// Occurs when current page number is changed.
- /// </summary>
- public event EventHandler PageChanged;
- /// <summary>
- /// Occurs when Print button clicked.
- /// </summary>
- public event EventHandler<PrintEventArgs> OnPrint;
- public class PrintEventArgs : EventArgs
- {
- private PreviewControl preview;
- public PreviewControl Preview
- {
- get { return preview; }
- }
- public PrintEventArgs(PreviewControl preview)
- {
- this.preview = preview;
- }
- }
- /// <summary>
- /// Occurs when Export button clicked.
- /// </summary>
- public event EventHandler<ExportEventArgs> OnExport;
- public class ExportEventArgs : EventArgs
- {
- private ExportBase export;
- private Report report;
- private List<PreparedPages> pagesOfTabs;
- public Report Report
- {
- get { return report; }
- }
- public ExportBase Export
- {
- get { return export; }
- }
- public List<PreparedPages> PagesOfTabs
- {
- get { return pagesOfTabs; }
- }
- public ExportEventArgs(ExportBase export, Report report, List<PreparedPages> pagesOfTabs)
- {
- this.report = report;
- this.export = export;
- this.pagesOfTabs = pagesOfTabs;
- }
- }
- /// <summary>
- /// Gets a reference to the report.
- /// </summary>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public Report Report
- {
- get { return report; }
- }
- /// <summary>
- /// Obsolete. Gets or sets the color of page border.
- /// </summary>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Color PageBorderColor
- {
- get { return pageBorderColor; }
- set { pageBorderColor = value; }
- }
- /// <summary>
- /// Gets or sets the color of active page border.
- /// </summary>
- [DefaultValue(typeof(Color), "255, 199, 60")]
- public Color ActivePageBorderColor
- {
- get { return activePageBorderColor; }
- set { activePageBorderColor = value; }
- }
- /// <summary>
- /// Gets or sets the first page offset from the top left corner of the control.
- /// </summary>
- public Point PageOffset
- {
- get { return pageOffset; }
- set { pageOffset = value; }
- }
- /// <summary>
- /// Gets a reference to the TabControl
- /// </summary>
- public DevComponents.DotNetBar.TabControl TabControl
- {
- get { return tabControl; }
- }
- /// <summary>
- /// Gets or sets a value indicating whether the toolbar is visible.
- /// </summary>
- [DefaultValue(true)]
- public bool ToolbarVisible
- {
- get { return toolbarVisible; }
- set
- {
- toolbarVisible = value;
- toolBar.Visible = value;
- }
- }
- /// <summary>
- /// Gets or sets a value indicating whether the statusbar is visible.
- /// </summary>
- [DefaultValue(true)]
- public bool StatusbarVisible
- {
- get { return statusbarVisible; }
- set
- {
- statusbarVisible = value;
- statusBar.Visible = value;
- }
- }
- /// <summary>
- /// Gets or sets a value indicating whether the outline control is visible.
- /// </summary>
- [DefaultValue(false)]
- public bool OutlineVisible
- {
- get { return outlineControl.Visible; }
- set
- {
- splitter.Visible = value;
- outlineControl.Visible = value;
- btnOutline.Checked = value;
- }
- }
- /// <summary>
- /// Specifies the set of buttons available in the toolbar.
- /// </summary>
- [DefaultValue(PreviewButtons.All)]
- public PreviewButtons Buttons
- {
- get { return buttons; }
- set
- {
- buttons = value;
- UpdateButtons();
- }
- }
- /// <summary>
- /// Specifies the set of exports that will be available in the preview's "save" menu.
- /// </summary>
- [DefaultValue(PreviewExports.All)]
- public PreviewExports Exports
- {
- get { return exports; }
- set
- {
- exports = value;
- UpdateButtons();
- }
- }
- /// <summary>
- /// Specifies the set of exports in clouds that will be available in the preview's "save" menu.
- /// </summary>
- [DefaultValue(PreviewClouds.All)]
- public PreviewClouds Clouds
- {
- get { return clouds; }
- set
- {
- clouds = value;
- UpdateButtons();
- }
- }
- /// <summary>
- /// Gets or sets a value indicating whether the fast scrolling method should be used.
- /// </summary>
- /// <remarks>
- /// If you enable this property, the gradient background will be disabled.
- /// </remarks>
- [DefaultValue(false)]
- public bool FastScrolling
- {
- get { return fastScrolling; }
- set { fastScrolling = value; }
- }
- /// <summary>
- /// Gets or sets the visual style.
- /// </summary>
- [DefaultValue(UIStyle.VisualStudio2012Light)]
- public UIStyle UIStyle
- {
- get { return uiStyle; }
- set
- {
- uiStyle = value;
- UpdateUIStyle();
- }
- }
- /// <summary>
- /// Gets or sets a value indicating that the BackColor property must be used to draw the background area.
- /// </summary>
- /// <remarks>
- /// By default, the background area is drawn using the color defined in the current <b>UIStyle</b>.
- /// </remarks>
- [DefaultValue(false)]
- public bool UseBackColor
- {
- get { return useBackColor; }
- set
- {
- useBackColor = value;
- UpdateUIStyle();
- }
- }
- /// <summary>
- /// Gets the preview window's toolbar.
- /// </summary>
- [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public Bar ToolBar
- {
- get { return toolBar; }
- }
- /// <summary>
- /// Gets the preview window's statusbar.
- /// </summary>
- [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public Bar StatusBar
- {
- get { return statusBar; }
- }
- /// <summary>
- /// Gets or sets the initial directory that is displayed by a save file dialog.
- /// </summary>
- public string SaveInitialDirectory
- {
- get { return saveInitialDirectory; }
- set { saveInitialDirectory = value; }
- }
- internal float DefaultZoom
- {
- get { return defaultZoom; }
- }
- internal PreviewTab CurrentPreview
- {
- get { return currentPreview; }
- }
- private bool IsPreviewEmpty
- {
- get { return CurrentPreview == null || CurrentPreview.Disabled; }
- }
- #endregion
- #region Private Methods
- private void UpdateDeletePageButton()
- {
- // Disable "Delete Page" button if there is only one page in preview.
- if (currentPreview != null && currentPreview.PreparedPages != null && currentPreview.PreparedPages.Count > 0)
- {
- btnDeletePage.Enabled = currentPreview.PreparedPages.Count > 1;
- }
- else
- btnDeletePage.Enabled = false;
- }
- #if !COMMUNITY
- private void CreateSaveList()
- {
- btnSave.SubItems.Clear();
- var savePrepared = new ButtonItem("", Res.Get("Preview,SaveNative"));
- btnSave.SubItems.Add(savePrepared);
- var saveLocal = new ButtonItem("", Res.Get("Preview,SaveLocal"));
- saveLocal.Click += btnSave_Click;
- var saveToCloud = new ButtonItem("", Res.Get("Preview,SaveToCloud"));
- saveToCloud.Image = this.GetImage(262);
- saveToCloud.Click += btnSaveToCloud_Click;
- savePrepared.SubItems.Add(saveLocal);
- savePrepared.SubItems.Add(saveToCloud);
- CreateExportList(btnSave, Export_Click);
- CreateCloudList(btnSave, SaveToCloud_Click);
- CreateMessengersList(btnSave, SendViaMessenger_Click);
- }
- private void CreateEmailMapiList()
- {
- btnEmailMapi.SubItems.Clear();
- var saveNative = new ButtonItem("Prepared", Res.Get("Preview,SaveNative") + "...");
- saveNative.Click += Email_Click;
- btnEmailMapi.SubItems.Add(saveNative);
- CreateExportList(btnEmailMapi, Email_Click);
- }
- private ButtonItem createButtonItem(ExportsOptions.ExportsTreeNode node)
- {
- var item = new ButtonItem("", node.ToString() + (node.IsCategory ? "" : "..."));
- item.Tag = node.Tag;
- item.Name = node.Name;
- item.Image = node.Image ?? this.GetImage(node.ImageIndex);
- return item;
- }
- private void CreateItems(ExportsOptions.ExportsTreeNode root, ButtonItem button, EventHandler handler)
- {
- foreach (var node in root.Nodes)
- {
- if (node.IsCategory)
- {
- var categoryItem = createButtonItem(node);
- CreateItems(node, categoryItem, handler);
- if (categoryItem.SubItems.Count > 0)
- button.SubItems.Add(categoryItem);
- }
- else if (node.ExportType != null)
- {
- bool enabled = node.Enabled;
- if (node.IsExport)
- {
- if (Enum.TryParse<PreviewExports>(node.Tag.Object.Name, out var res))
- enabled = (Exports & res) != 0;
- }
- else if (node.IsCloud)
- {
- if (Enum.TryParse<PreviewClouds>(node.Name, out var res))
- enabled = (Clouds & res) != 0;
- }
- /*else if (node.IsMessenger)
- {
- if (Enum.TryParse<PreviewMessengers>(node.Name, out var res))
- enabled = (Messengers & res) != 0;
- }*/
- if (enabled)
- {
- var item = createButtonItem(node);
- item.Click += handler;
- button.SubItems.Add(item);
- }
- }
- }
- }
- private void CreateExportList(ButtonItem button, EventHandler handler)
- {
- ExportsOptions options = ExportsOptions.GetInstance();
- CreateItems(options.ExportsMenu, button, handler);
- }
- private void CreateCloudList(ButtonItem button, EventHandler handler)
- {
- ExportsOptions options = ExportsOptions.GetInstance();
- var categoryItem = createButtonItem(options.CloudMenu);
- categoryItem.BeginGroup = true;
- CreateItems(options.CloudMenu, categoryItem, handler);
- if (categoryItem.SubItems.Count > 0)
- button.SubItems.Add(categoryItem);
- }
- private void CreateMessengersList(ButtonItem button, EventHandler handler)
- {
- ExportsOptions options = ExportsOptions.GetInstance();
- var categoryItem = createButtonItem(options.MessengerMenu);
- categoryItem.BeginGroup = true;
- CreateItems(options.MessengerMenu, categoryItem, handler);
- if (categoryItem.SubItems.Count > 0)
- button.SubItems.Add(categoryItem);
- }
- #endif
- private void CreateOpenList()
- {
- var openLocal = new ButtonItem("Open", Res.Get("Preview,OpenLocal"));
- openLocal.ImageIndex = 1;
- openLocal.Click += btnOpen_Click;
- var openViaCloud = new ButtonItem("OpenViaCloud", Res.Get("Preview,OpenViaCloud"));
- openViaCloud.ImageIndex = 261;
- openViaCloud.Click += btnOpenViaCloud_Click;
- btnOpen.SubItems.Add(openLocal);
- #if !COMMUNITY
- btnOpen.SubItems.Add(openViaCloud);
- #endif
- }
- private List<PreparedPages> GetPageOfTabs()
- {
- List<PreparedPages> list = new List<PreparedPages>();
- foreach (var tab in tabControl.Tabs)
- {
- if (tab is PreviewTab)
- list.Add((tab as PreviewTab).PreparedPages);
- }
- return list;
- }
- private void UpdateButtons()
- {
- #if COMMUNITY
- btnPrint.Visible = false;
- #else
- btnPrint.Visible = (Buttons & PreviewButtons.Print) != 0;
- #endif
- btnOpen.Visible = (Buttons & PreviewButtons.Open) != 0;
- btnSave.Visible = (Buttons & PreviewButtons.Save) != 0;
- #if COMMUNITY
- btnEmail.Visible = false;
- btnEmailMapi.Visible = false;
- #else
- btnEmail.Visible = (Buttons & PreviewButtons.Email) != 0 && !Config.EmailSettings.UseMAPI;
- btnEmailMapi.Visible = (Buttons & PreviewButtons.Email) != 0 && Config.EmailSettings.UseMAPI;
- #endif
- btnFind.Visible = (Buttons & PreviewButtons.Find) != 0;
- btnOutline.Visible = (Buttons & PreviewButtons.Outline) != 0;
- btnPageSetup.Visible = (Buttons & PreviewButtons.PageSetup) != 0;
- btnDesign.Visible = (Buttons & PreviewButtons.Design) != 0;
- btnEdit.Visible = (Buttons & PreviewButtons.Edit) != 0;
- btnCopyPage.Visible = (Buttons & PreviewButtons.CopyPage) != 0;
- btnDeletePage.Visible = (Buttons & PreviewButtons.DeletePage) != 0;
- btnWatermark.Visible = (Buttons & PreviewButtons.Watermark) != 0;
- btnFirst.Visible = (Buttons & PreviewButtons.Navigator) != 0;
- btnPrior.Visible = (Buttons & PreviewButtons.Navigator) != 0;
- tbPageNo.Visible = (Buttons & PreviewButtons.Navigator) != 0;
- lblTotalPages.Visible = (Buttons & PreviewButtons.Navigator) != 0;
- btnNext.Visible = (Buttons & PreviewButtons.Navigator) != 0;
- btnLast.Visible = (Buttons & PreviewButtons.Navigator) != 0;
- btnClose.Visible = (Buttons & PreviewButtons.Close) != 0;
- btnAbout.Visible = (Buttons & PreviewButtons.About) != 0;
- }
- private void Export_Click(object sender, EventArgs e)
- {
- if (IsPreviewEmpty)
- return;
- ObjectInfo info = (sender as ButtonItem).Tag as ObjectInfo;
- if (info == null)
- Save();
- else
- {
- ExportBase export = Activator.CreateInstance(info.Object) as ExportBase;
- export.CurPage = CurrentPreview.PageNo;
- export.AllowSaveSettings = true;
- export.ShowProgress = true;
- Report report = new Report();
- PreparedPages preparedPages = new PreparedPages(report);
- foreach (var item in documents)
- {
- }
- if (!string.IsNullOrEmpty(SaveInitialDirectory))
- export.SaveInitialDirectory = SaveInitialDirectory;
- try
- {
- if (OnExport != null)
- OnExport(sender, new ExportEventArgs(export, CurrentPreview.Report, GetPageOfTabs()));
- else
- export.Export(CurrentPreview.Report, GetPageOfTabs());
- }
- #if !DEBUG
- catch (Exception ex)
- {
- using (ExceptionForm form = new ExceptionForm(ex))
- {
- form.ShowDialog();
- }
- }
- #endif
- finally
- {
- }
- }
- }
- private void SaveToCloud_Click(object sender, EventArgs e)
- {
- if (IsPreviewEmpty)
- {
- return;
- }
- ObjectInfo info = (sender as ButtonItem).Tag as ObjectInfo;
- if (info != null)
- {
- CloudStorageClient client = Activator.CreateInstance(info.Object) as CloudStorageClient;
- if (client is FtpStorageClient)
- {
- XmlItem xi = Config.Root.FindItem("FtpServer").FindItem("StorageSettings");
- string server = xi.GetProp("FtpServer");
- string username = xi.GetProp("FtpUsername");
- FtpStorageClientForm form = new FtpStorageClientForm(server, username, "", Report);
- form.ShowDialog();
- }
- else if (client is BoxStorageClient)
- {
- XmlItem xi = Config.Root.FindItem("BoxCloud").FindItem("StorageSettings");
- string id = xi.GetProp("ClientId");
- string secret = xi.GetProp("ClientSecret");
- DialogResult clientInfoDialogDialogResult = DialogResult.OK;
- if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(secret))
- {
- Box.ClientInfoForm clientInfoDialog = new Box.ClientInfoForm();
- clientInfoDialog.ShowDialog();
- id = clientInfoDialog.Id;
- secret = clientInfoDialog.Secret;
- clientInfoDialogDialogResult = clientInfoDialog.DialogResult;
- }
- if (clientInfoDialogDialogResult == DialogResult.OK)
- {
- BoxStorageClientForm form = new BoxStorageClientForm(new SkyDrive.ClientInfo("", id, secret), Report);
- form.ShowDialog();
- }
- }
- else if (client is DropboxStorageClient)
- {
- XmlItem xi = Config.Root.FindItem("DropboxCloud").FindItem("StorageSettings");
- string accessToken = xi.GetProp("AccessToken");
- if (String.IsNullOrEmpty(accessToken))
- {
- ApplicationInfoForm appInfoDialog = new ApplicationInfoForm();
- appInfoDialog.ShowDialog();
- accessToken = appInfoDialog.AccessToken;
- }
- DropboxStorageClientForm form = new DropboxStorageClientForm(accessToken, Report);
- form.ShowDialog();
- }
- else if (client is GoogleDriveStorageClient)
- {
- XmlItem xi = Config.Root.FindItem("GoogleDriveCloud").FindItem("StorageSettings");
- string id = xi.GetProp("ClientId");
- string secret = xi.GetProp("ClientSecret");
- if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(secret))
- {
- GoogleDrive.ClientInfoForm clientInfoDialog = new GoogleDrive.ClientInfoForm();
- clientInfoDialog.ShowDialog();
- if (clientInfoDialog.DialogResult != DialogResult.OK)
- return;
- id = clientInfoDialog.Id;
- secret = clientInfoDialog.Secret;
- }
- GoogleDriveStorageClientForm form = new GoogleDriveStorageClientForm(new SkyDrive.ClientInfo("", id, secret), Report);
- form.ShowDialog();
- }
- else if (client is SkyDriveStorageClient)
- {
- XmlItem xi = Config.Root.FindItem("SkyDriveCloud").FindItem("StorageSettings");
- string id = xi.GetProp("ClientId");
- if (String.IsNullOrEmpty(id))
- {
- SkyDrive.ClientInfoForm appInfoDialog = new SkyDrive.ClientInfoForm();
- appInfoDialog.ShowDialog();
- id = appInfoDialog.Id;
- }
- SkyDriveStorageClientForm form = new SkyDriveStorageClientForm(new SkyDrive.ClientInfo("", id, ""), Report);
- form.ShowDialog();
- }
- else if (client is S3StorageClient)
- {
- XmlItem xi = Config.Root.FindItem("S3").FindItem("StorageSettings");
- string accessKeyId = xi.GetProp("AccessKeyId");
- string secretAccessKey = xi.GetProp("SecretAccessKey");
- string region = xi.GetProp("Region");
- string host = xi.GetProp("Host");
- Cloud.StorageClient.S3.ClientInfoForm appInfoDialog = new Cloud.StorageClient.S3.ClientInfoForm();
- appInfoDialog.AccessKeyId = accessKeyId;
- appInfoDialog.SecretAccessKey = secretAccessKey;
- appInfoDialog.Region = region;
- appInfoDialog.Host = host;
- if (appInfoDialog.ShowDialog() == DialogResult.OK)
- {
- accessKeyId = appInfoDialog.AccessKeyId;
- secretAccessKey = appInfoDialog.SecretAccessKey;
- region = appInfoDialog.Region;
- host = appInfoDialog.Host;
- }
- else
- return;
- S3ClientForm form = new S3ClientForm(accessKeyId, secretAccessKey, region, host, Report);
- form.Client.AfterUpload += PreviewControl_AfterUpload;
- form.Client.BeforeUpload += Client_BeforeUpload;
- form.ShowDialog();
- }
- }
- }
- private void Client_BeforeUpload(object sender, EventArgs e)
- {
- ShowPerformance(Res.Get("Preview,Uploading"));
- uploadTimer.Start();
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- if (lblPerformance.Text.Contains("..."))
- lblPerformance.Text = lblPerformance.Text.Replace("...", "");
- else
- lblPerformance.Text += ".";
- }
- private void PreviewControl_AfterUpload(object sender, EventArgs e)
- {
- ShowPerformance(Res.Get("Preview,UploadDone"));
- }
- private void SendViaMessenger_Click(object sender, EventArgs e)
- {
- if (IsPreviewEmpty)
- {
- return;
- }
- ObjectInfo info = (sender as ButtonItem).Tag as ObjectInfo;
- if (info != null)
- {
- MessengerBase messenger = Activator.CreateInstance(info.Object) as MessengerBase;
- //if (messenger is XmppMessenger)
- //{
- // XmlItem xi = Config.Root.FindItem("XmppMessenger").FindItem("MessengerSettings");
- // string jidFrom = xi.GetProp("JidFrom");
- // string password = xi.GetProp("Password");
- // string jidTo = xi.GetProp("JidTo");
- // XmppMessengerForm form = new XmppMessengerForm(jidFrom, password, jidTo, Report);
- // form.ShowDialog();
- //}
- //else
- //{
- // Type telegramMessenger = RegisteredObjects.FindType("TelegramMessenger");
- // if (telegramMessenger != null && messenger.GetType() == telegramMessenger)
- // try
- // {
- // MethodInfo InvokeInfoFormEditor = telegramMessenger.GetMethod("InvokeForm");
- // object[] parametrs = new object[1];
- // parametrs[0] = Report;
- // object o = Activator.CreateInstance(telegramMessenger);
- // InvokeInfoFormEditor.Invoke(o, parametrs);
- // }
- // catch (Exception ex)
- // {
- // FRMessageBox.Error(ex.Message);
- // }
- //}
- }
- }
- private void Email_Click(object sender, EventArgs e)
- {
- if (IsPreviewEmpty)
- return;
- List<string> fileNames = new List<string>();
- ObjectInfo info = (sender as ButtonItem).Tag as ObjectInfo;
- if (info == null)
- {
- using (SaveFileDialog dialog = new SaveFileDialog())
- {
- dialog.Filter = Res.Get("FileFilters,PreparedReport");
- dialog.DefaultExt = "*.fpx";
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- Save(dialog.FileName);
- fileNames.Add(dialog.FileName);
- }
- }
- }
- else
- {
- ExportBase export = Activator.CreateInstance(info.Object) as ExportBase;
- export.CurPage = CurrentPreview.PageNo;
- export.AllowOpenAfter = false;
- export.ShowProgress = true;
- export.Export(CurrentPreview.Report, GetPageOfTabs());
- fileNames = export.GeneratedFiles;
- }
- if (fileNames.Count > 0)
- {
- Form form = FindForm();
- string[] recipientAddresses = CurrentPreview.Report.EmailSettings.Recipients == null ?
- new string[] { } : CurrentPreview.Report.EmailSettings.Recipients;
- int error = MAPI.SendMail(form == null ? IntPtr.Zero : form.Handle, fileNames.ToArray(),
- CurrentPreview.Report.EmailSettings.Subject,
- CurrentPreview.Report.EmailSettings.Message, new string[] { }, recipientAddresses);
- if (error > 1)
- {
- MessageBox.Show("MAPISendMail failed! " + MAPI.GetErrorText(error));
- }
- }
- }
- private void FUpdateTimer_Tick(object sender, EventArgs e)
- {
- updatingZoom = true;
- int zoom = (int)(zoomToUpdate * 100);
- slZoom.Text = zoom.ToString() + "%";
- if (zoom < 100)
- zoom = (int)Math.Round((zoom - 25) / 0.75f);
- else if (zoom > 100)
- zoom = (zoom - 100) / 4 + 100;
- slZoom.Value = zoom;
- updatingZoom = false;
- updateTimer.Stop();
- }
- private void tabControl1_TabItemClose(object sender, TabStripActionEventArgs e)
- {
- DeleteTab(currentPreview);
- e.Cancel = true;
- tabControl.RecalcLayout();
- }
- private void tabControl1_SelectedTabChanged(object sender, FastReport.DevComponents.DotNetBar.TabStripTabChangedEventArgs e)
- {
- if (locked)
- return;
- currentPreview = tabControl.SelectedTab as PreviewTab;
- if (currentPreview != null && !currentPreview.Fake)
- {
- currentPreview.BindPreparedPages();
- UpdateOutline();
- UpdateZoom(currentPreview.Zoom);
- UpdatePageNumbers(currentPreview.PageNo, currentPreview.PageCount);
- UpdateDeletePageButton();
- }
- }
- private void tabControl_Resize(object sender, EventArgs e)
- {
- foreach (PreviewTab tab in documents)
- {
- tab.UpdatePages();
- }
- }
- private bool CanDisposeTabReport(PreviewTab tab)
- {
- if (tab == null || tab.Report == null)
- return false;
- // if the preview is owned by Report, do not dispose
- if (report == tab.Report)
- return false;
- // check if the same Report is used in other tabs
- foreach (PreviewTab t in documents)
- {
- if (t != tab && t.Report == tab.Report)
- {
- return false;
- }
- }
- return true;
- }
- private void SetToolTip(BaseItem item, string tttext)
- {
- item.Tooltip = tttext;
- //item.toolTipFont = new Font(SystemFonts.DefaultFont.Name, SystemFonts.DefaultFont.Size * ratio / DrawUtils.ScreenDpiFX, FontStyle.Regular);
- }
- private void Localize()
- {
- MyRes res = new MyRes("Preview");
- btnDesign.Text = res.Get("DesignText");
- SetToolTip(btnDesign, res.Get("Design"));
- btnPrint.Text = res.Get("PrintText");
- SetToolTip(btnPrint, res.Get("Print"));
- SetToolTip(btnOpen, res.Get("Open"));
- SetToolTip(btnSave, res.Get("Save"));
- btnOpen.Text = res.Get("OpenText");
- btnSave.Text = res.Get("SaveText");
- SetToolTip(btnEmail, res.Get("Email"));
- SetToolTip(btnEmailMapi, res.Get("Email"));
- SetToolTip(btnFind, res.Get("Find"));
- SetToolTip(btnOutline, res.Get("Outline"));
- SetToolTip(btnPageSetup, res.Get("PageSetup"));
- SetToolTip(btnEdit, res.Get("Edit"));
- SetToolTip(btnCopyPage, res.Get("CopyPage"));
- SetToolTip(btnDeletePage, res.Get("DeletePage"));
- SetToolTip(btnWatermark, res.Get("Watermark"));
- SetToolTip(btnFirst, res.Get("First"));
- SetToolTip(btnPrior, res.Get("Prior"));
- SetToolTip(btnNext, res.Get("Next"));
- lblTotalPages.Text = String.Format(Res.Get("Misc,ofM"), 1);
- SetToolTip(btnLast, res.Get("Last"));
- btnClose.Text = Res.Get("Buttons,Close");
- btnAbout.Text = new MyRes("Designer,Menu").Get("Help,About");
- }
- private void UpdateButtonImages(SubItemsCollection items)
- {
- foreach (BaseItem item in items)
- {
- ButtonItem b = item as ButtonItem;
- if (b != null && b.ImageIndex != -1)
- {
- b.Image = this.GetImage(b.ImageIndex);
- }
- UpdateButtonImages(item.SubItems);
- }
- }
- /// <summary>
- /// Opens Cloud form and shows selected prepared report.
- /// </summary>
- public void HandleCloudForm()
- {
- var stream = CloudCommands.LoadPreviewFile();
- if (stream != null)
- Load(stream);
- }
- /// <summary>
- /// Updates the control appearance and layout on dpi change.
- /// </summary>
- public void UpdateDpiDependencies()
- {
- if (DevComponents.DpiHelper.HighDpiEnabled)
- DevComponents.DpiHelper.ReInit(this.Dpi(), this);
- Font = this.LogicalToDevice(DrawUtils.DefaultFont);
- toolBar.SuspendLayout();
- statusBar.SuspendLayout();
- toolBar.Font = Font;
- statusBar.Font = Font;
- outlineControl.Font = Font;
- outlineControl.UpdateDpiDependencies();
- UpdateButtonImages(toolBar.Items);
- btnZoomPageWidth.Image = this.GetImage(235);
- btnZoomWholePage.Image = this.GetImage(236);
- btnZoom100.Image = this.GetImage(237);
- lblStatus.Width = this.LogicalToDevice(250);
- toolBar.UpdateDpiDependencies();
- statusBar.UpdateDpiDependencies();
- toolBar.ResumeLayout();
- statusBar.ResumeLayout();
- }
- private void Init()
- {
- outlineControl.SetPreview(this);
- updateTimer = new Timer();
- updateTimer.Interval = 50;
- updateTimer.Tick += FUpdateTimer_Tick;
- uploadTimer = new Timer();
- uploadTimer.Interval = 1500;
- uploadTimer.Tick += Timer_Tick;
- pageBorderColor = Color.FromArgb(80, 80, 80);
- activePageBorderColor = Color.FromArgb(255, 199, 60);
- pageOffset = new Point(10, 10);
- defaultZoom = 1;
- buttons = PreviewButtons.All;
- btnDesign.ImageIndex = 68;
- btnPrint.ImageIndex = 195;
- btnOpen.ImageIndex = 1;
- btnSave.ImageIndex = 2;
- btnEmail.ImageIndex = 200;
- btnEmailMapi.ImageIndex = 200;
- btnFind.ImageIndex = 181;
- btnOutline.ImageIndex = 196;
- btnPageSetup.ImageIndex = 13;
- btnEdit.ImageIndex = 198;
- btnCopyPage.ImageIndex = 6;
- btnDeletePage.ImageIndex = 12;
- btnWatermark.ImageIndex = 194;
- btnFirst.ImageIndex = 185;
- btnPrior.ImageIndex = 186;
- btnNext.ImageIndex = 187;
- btnLast.ImageIndex = 188;
- #if !COMMUNITY
- exports = Config.PreviewSettings.Exports;
- clouds = Config.PreviewSettings.Clouds;
- CreateOpenList();
- CreateSaveList();
- CreateEmailMapiList();
- #else
- btnOpen.Click += btnOpen_Click;
- btnSave.Click += btnSave_Click;
- #endif
- RestoreState();
- UpdateButtons();
- UpdateDpiDependencies();
- #if COMMUNITY
- this.toolBar.Items.Remove(btnSave);
- #endif
- }
- private void RestoreState()
- {
- XmlItem xi = Config.Root.FindItem("Preview");
- string zoom = xi.GetProp("Zoom");
- if (!String.IsNullOrEmpty(zoom))
- defaultZoom = (float)Converter.FromString(typeof(float), zoom);
- string width = xi.GetProp("OutlineWidth");
- if (!String.IsNullOrEmpty(width))
- outlineControl.Width = int.Parse(width);
- }
- private void SaveState()
- {
- // Clear();
- outlineControl.Hide();
- XmlItem xi = Config.Root.FindItem("Preview");
- xi.SetProp("Zoom", Converter.ToString(Zoom));
- xi.SetProp("OutlineWidth", outlineControl.Width.ToString());
- }
- private void UpdateUIStyle()
- {
- switch (UIStyle)
- {
- case UIStyle.Office2003:
- case UIStyle.Office2007Blue:
- case UIStyle.Office2010Blue:
- StyleManager.ChangeStyle(eStyle.Office2010Blue, Color.Empty);
- break;
- case UIStyle.Office2007Silver:
- case UIStyle.Office2010Silver:
- StyleManager.ChangeStyle(eStyle.Office2010Silver, Color.Empty);
- break;
- case UIStyle.Office2007Black:
- case UIStyle.Office2010Black:
- StyleManager.ChangeStyle(eStyle.Office2010Black, Color.Empty);
- break;
- case UIStyle.Office2013:
- StyleManager.ChangeStyle(eStyle.Office2013, Color.Empty);
- break;
- case UIStyle.VisualStudio2005:
- case UIStyle.VisualStudio2010:
- StyleManager.ChangeStyle(eStyle.VisualStudio2010Blue, Color.Empty);
- break;
- case UIStyle.VisualStudio2012Light:
- StyleManager.ChangeStyle(eStyle.VisualStudio2012Light, Color.Empty);
- break;
- case UIStyle.VistaGlass:
- StyleManager.ChangeStyle(eStyle.Windows7Blue, Color.Empty);
- break;
- }
- //UIStyleUtils.UpdateUIStyle();
- eDotNetBarStyle style = UIStyleUtils.GetDotNetBarStyle(UIStyle);
- toolBar.Style = style;
- statusBar.Style = style;
- tabControl.Style = UIStyleUtils.GetTabStripStyle(UIStyle);
- outlineControl.Style = UIStyle;
- foreach (PreviewTab tab in documents)
- {
- tab.Style = UIStyle;
- }
- }
- private void UpdateOutline()
- {
- try
- {
- outlineControl.PreparedPages = currentPreview.PreparedPages;
- OutlineVisible = !currentPreview.PreparedPages.Outline.IsEmpty;
- }
- catch
- {
- }
- }
- private void AddFakeTab()
- {
- PreviewTab tab = new PreviewTab(this, null, "", null);
- tab.Fake = true;
- documents.Add(tab);
- tab.AddToTabControl(tabControl);
- }
- private void UpdateTabsVisible()
- {
- tabControl.TabsVisible = documents.Count > 1 && !documents[0].Fake;
- }
- private PreviewTab FindTab(string text)
- {
- foreach (PreviewTab tab in documents)
- {
- if (tab.Text == text)
- return tab;
- }
- return null;
- }
- private PreviewTab FindTabByHyperlinkValue(string value)
- {
- foreach (PreviewTab tab in documents)
- {
- if (tab.HyperlinkValue == value)
- return tab;
- }
- return null;
- }
- #endregion
- #region Protected Methods
- /// <inheritdoc/>
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (components != null)
- components.Dispose();
- updateTimer.Dispose();
- uploadTimer.Dispose();
- SaveState();
- }
- base.Dispose(disposing);
- }
- #endregion
- #region Public Methods
- internal void SetReport(Report report)
- {
- this.report = report;
- }
- internal void UpdatePageNumbers(int pageNo, int totalPages)
- {
- lblStatus.Text = String.Format(Res.Get("Misc,PageNofM"), pageNo, totalPages);
- tbPageNo.Text = pageNo.ToString();
- lblTotalPages.Text = String.Format(Res.Get("Misc,ofM"), totalPages);
- if (PageChanged != null)
- PageChanged(this, EventArgs.Empty);
- }
- internal void UpdateZoom(float zoom)
- {
- zoomToUpdate = zoom;
- updateTimer.Start();
- }
- internal void UpdateUrl(string url)
- {
- lblUrl.Text = url;
- }
- internal void ShowPerformance(string text)
- {
- uploadTimer.Stop();
- lblPerformance.Text = text;
- }
- internal void DoClick()
- {
- OnClick(EventArgs.Empty);
- }
- // Clears all tabs except the first one. This method is used in the report.Prepare.
- // It is needed to avoid flickering when using stand-alone PreviewControl.
- // When report is prepared and ShowPrepared method is called, the "fake" tab will
- // be replaced with the new tab.
- internal void ClearTabsExceptFirst()
- {
- while (documents.Count > 1)
- {
- DeleteTab(documents[documents.Count - 1]);
- }
- if (documents.Count == 1)
- documents[0].Fake = true;
- }
- internal PreviewTab AddPreviewTab(Report report, string text, Hyperlink hyperlink, bool setActive)
- {
- PreviewTab tab = new PreviewTab(this, report, text, hyperlink);
- documents.Add(tab);
- //report.PreparedPages.ClearPageCache();
- //OutlineVisible = !report.PreparedPages.Outline.IsEmpty;
- tab.AddToTabControl(tabControl);
- tab.UnlockLayout();
- UpdateTabsVisible();
- tab.UpdatePages();
- if (setActive)
- {
- // do not stole the focus
- tabControl.TabStrip.AutoSelectAttachedControl = false;
- tabControl.SelectedTab = tab;
- tabControl.TabStrip.AutoSelectAttachedControl = true;
- }
- else
- tabControl.Refresh();
- if (documents.Count == 2 && documents[0].Fake)
- DeleteTab(documents[0]);
- return tab;
- }
- /// <summary>
- /// Adds a new report tab to the preview control.
- /// </summary>
- /// <param name="report">The <b>Report</b> object that contains the prepared report.</param>
- /// <param name="text">The title for the new tab.</param>
- /// <remarks>
- /// Prepare the report using its <b>Prepare</b> method before you pass it to the <b>report</b> parameter.
- /// </remarks>
- public void AddTab(Report report, string text)
- {
- AddTab(report, text, true);
- }
- /// <summary>
- /// Adds a new report tab to the preview control.
- /// </summary>
- /// <param name="report">The <b>Report</b> object that contains the prepared report.</param>
- /// <param name="text">The title for the new tab.</param>
- /// <param name="setActive">If <b>true</b>, makes the new tab active.</param>
- /// <remarks>
- /// Prepare the report using its <b>Prepare</b> method before you pass it to the <b>report</b> parameter.
- /// </remarks>
- public void AddTab(Report report, string text, bool setActive)
- {
- if (this.report == null)
- SetReport(report);
- AddPreviewTab(report, text, null, setActive);
- }
- /// <summary>
- /// Switches to the tab with specified text.
- /// </summary>
- /// <param name="text">Text of the tab.</param>
- /// <returns><b>true</b> if the tab with specified text exists, or <b>false</b> if there is no such tab.</returns>
- public bool SwitchToTab(string text)
- {
- PreviewTab tab = FindTab(text);
- if (tab != null)
- {
- tabControl.SelectedTab = tab;
- return true;
- }
- return false;
- }
- internal bool SwitchToTab(Hyperlink hyperlink)
- {
- PreviewTab tab = FindTabByHyperlinkValue(hyperlink.Value);
- if (tab != null)
- {
- tabControl.SelectedTab = tab;
- return true;
- }
- return false;
- }
- /// <summary>
- /// Deletes the report tab with specified text.
- /// </summary>
- /// <param name="text">The text of the tab.</param>
- public void DeleteTab(string text)
- {
- PreviewTab tab = FindTab(text);
- if (tab != null)
- DeleteTab(tab);
- }
- /// <summary>
- /// Checks if the tab with specified text exists.
- /// </summary>
- /// <param name="text">The text of the tab.</param>
- /// <returns><b>true</b> if the tab exists.</returns>
- public bool TabExists(string text)
- {
- return FindTab(text) != null;
- }
- internal void DeleteTab(PreviewTab tab)
- {
- if (CanDisposeTabReport(tab))
- tab.Report.Dispose();
- documents.Remove(tab);
- tabControl.Tabs.Remove(tab);
- tab.Dispose();
- UpdateTabsVisible();
- }
- /// <summary>
- /// Displays the text in the status bar.
- /// </summary>
- /// <param name="text">Text to display.</param>
- public void ShowStatus(string text)
- {
- lblStatus.Text = text;
- statusBar.Refresh();
- }
- internal void Lock()
- {
- locked = true;
- }
- internal void Unlock()
- {
- locked = false;
- }
- /// <summary>
- /// Sets the focus to the preview control.
- /// </summary>
- public new void Focus()
- {
- if (currentPreview != null)
- currentPreview.Focus();
- }
- #endregion
- #region Async Prepare
- internal bool IsAsyncReportRunning { get; private set; }
- // we have to call this separately before AsyncReportStart to set this flag (case: clicking reports in the reports list too fast leads to NRE)
- internal void SetAsyncReportRunning() => IsAsyncReportRunning = true;
- internal void AsyncReportStart()
- {
- Report.PreparedPages.PageAdded += AsyncReportPageAdded;
- // update buttons
- btnClose.Text = Res.Get("Buttons,Cancel");
- EnableButtons(false);
- lblStatus.Text = "";
- uploadTimer.Stop();
- lblPerformance.Text = "";
- tbPageNo.Text = "0";
- }
- private int lastTick;
- private void AsyncReportPageAdded(object sender, EventArgs e)
- {
- int tick = Environment.TickCount;
- if (tick - lastTick < 50 && Report.PreparedPages.Count > 100)
- return;
- Application.DoEvents();
- if (Report.Engine.FinalPass)
- {
- OutlineVisible = !Report.PreparedPages.Outline.IsEmpty;
- CurrentPreview.UpdatePages();
- }
- lastTick = Environment.TickCount;
- }
- internal void AsyncReportFinish()
- {
- IsAsyncReportRunning = false;
- Report.PreparedPages.PageAdded -= AsyncReportPageAdded;
- Report.PreparedPages.ClearPageCache();
- UpdateOutline();
- CurrentPreview.UpdatePages();
- // update buttons
- btnClose.Text = Res.Get("Buttons,Close");
- EnableButtons(true);
- }
- private void EnableButtons(bool enable)
- {
- foreach (BaseItem button in ToolBar.Items)
- {
- if (button == btnFirst)
- break;
- button.Enabled = enable;
- }
- }
- #endregion
- #region Event handlers
- private void btnDesign_Click(object sender, EventArgs e)
- {
- Design();
- }
- private void btnPrint_Click(object sender, EventArgs e)
- {
- if (OnPrint != null)
- OnPrint(sender, new PrintEventArgs(this));
- else
- Print();
- }
- private void btnOpen_Click(object sender, EventArgs e)
- {
- Load();
- }
- private void btnOpenViaCloud_Click(object sender, EventArgs e)
- {
- HandleCloudForm();
- }
- private void btnSave_Click(object sender, EventArgs e)
- {
- Save();
- }
- private void btnSaveToCloud_Click(object sender, EventArgs e)
- {
- CloudCommands.SavePreviewFile(currentPreview.Report);
- }
- private void btnEmail_Click(object sender, EventArgs e)
- {
- SendEmail();
- }
- private void btnFind_Click(object sender, EventArgs e)
- {
- Find();
- }
- private void slZoom_ValueChanged(object sender, EventArgs e)
- {
- if (updatingZoom)
- return;
- int val = slZoom.Value;
- if (val < 100)
- val = (int)Math.Round(val * 0.75f) + 25;
- else
- val = (val - 100) * 4 + 100;
- Zoom = val / 100f;
- slZoom.Text = val.ToString() + "%";
- }
- private void btnZoomPageWidth_Click(object sender, EventArgs e)
- {
- ZoomPageWidth();
- }
- private void btnZoomWholePage_Click(object sender, EventArgs e)
- {
- ZoomWholePage();
- }
- private void btnZoom100_Click(object sender, EventArgs e)
- {
- Zoom = 1;
- }
- private void btnEdit_Click(object sender, EventArgs e)
- {
- EditPage();
- }
- private void btnCopyPage_Click(object sender, EventArgs e)
- {
- CopyPage();
- }
- private void btnDeletePage_Click(object sender, EventArgs e)
- {
- DeletePage();
- }
- private void btnFirst_Click(object sender, EventArgs e)
- {
- First();
- }
- private void btnPrior_Click(object sender, EventArgs e)
- {
- Prior();
- }
- private void btnNext_Click(object sender, EventArgs e)
- {
- Next();
- }
- private void btnLast_Click(object sender, EventArgs e)
- {
- Last();
- }
- private void tbPageNo_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- try
- {
- PageNo = int.Parse(tbPageNo.Text);
- }
- catch
- {
- PageNo = PageCount;
- }
- CurrentPreview.Focus();
- }
- }
- private void tbPageNo_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar != '\b' && (e.KeyChar < '0' || e.KeyChar > '9'))
- e.Handled = true;
- }
- private void btnWatermark_Click(object sender, EventArgs e)
- {
- EditWatermark();
- }
- private void btnOutline_Click(object sender, EventArgs e)
- {
- OutlineVisible = btnOutline.Checked;
- }
- private void btnPageSetup_Click(object sender, EventArgs e)
- {
- PageSetup();
- }
- private void btnClose_Click(object sender, EventArgs e)
- {
- if (IsAsyncReportRunning)
- {
- Report.Abort();
- return;
- }
- if (FindForm() != null)
- FindForm().Close();
- }
- private void tbPageNo_Click(object sender, EventArgs e)
- {
- tbPageNo.SelectAll();
- }
- private void btnAbout_Click(object sender, EventArgs e)
- {
- using (Forms.AboutForm aboutForm = new Forms.AboutForm())
- {
- aboutForm.ShowDialog();
- }
- }
- #endregion
- #region Preview commands
- /// <summary>
- /// Prints the current report.
- /// </summary>
- /// <returns><b>true</b> if report was printed; <b>false</b> if user cancels the "Print" dialog.</returns>
- public bool Print()
- {
- if (CurrentPreview == null)
- return false;
- return CurrentPreview.Print();
- }
- /// <summary>
- /// Saves the current report to a .fpx file using the "Save FIle" dialog.
- /// </summary>
- public void Save()
- {
- if (CurrentPreview == null)
- return;
- if (!string.IsNullOrEmpty(SaveInitialDirectory))
- CurrentPreview.SaveInitialDirectory = SaveInitialDirectory;
- CurrentPreview.Save();
- }
- /// <summary>
- /// Saves the current report to a specified .fpx file.
- /// </summary>
- public void Save(string fileName)
- {
- if (CurrentPreview == null)
- return;
- if (!string.IsNullOrEmpty(SaveInitialDirectory))
- CurrentPreview.SaveInitialDirectory = SaveInitialDirectory;
- CurrentPreview.Save(fileName);
- }
- /// <summary>
- /// Saves the current report to a stream.
- /// </summary>
- public void Save(Stream stream)
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Save(stream);
- }
- private bool PreLoad()
- {
- if (CurrentPreview == null)
- return false;
- if (documents.Count == 1 && documents[0].Fake)
- {
- Report report = new Report();
- report.SetPreparedPages(new PreparedPages(report));
- AddTab(report, "");
- }
- return true;
- }
- private void PostLoad()
- {
- UpdateOutline();
- UpdateDeletePageButton();
- }
- /// <summary>
- /// Loads the report from a .fpx file using the "Open File" dialog.
- /// </summary>
- public new void Load()
- {
- if (!PreLoad())
- return;
- CurrentPreview.Load();
- PostLoad();
- }
- /// <summary>
- /// Loads the report from a specified .fpx file.
- /// </summary>
- public new void Load(string fileName)
- {
- if (!PreLoad())
- return;
- CurrentPreview.Load(fileName);
- PostLoad();
- }
- /// <summary>
- /// Load the report from a stream.
- /// </summary>
- /// <param name="stream">The stream to load from.</param>
- public new void Load(Stream stream)
- {
- if (!PreLoad())
- return;
- CurrentPreview.Load(stream);
- PostLoad();
- }
- /// <summary>
- /// Sends an email.
- /// </summary>
- public void SendEmail()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.SendEmail();
- }
- /// <summary>
- /// Finds the text in the current report using the "Find Text" dialog.
- /// </summary>
- public void Find()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Find();
- }
- /// <summary>
- /// Finds the specified text in the current report.
- /// </summary>
- /// <param name="text">Text to find.</param>
- /// <param name="matchCase">A value indicating whether the search is case-sensitive.</param>
- /// <param name="wholeWord">A value indicating whether the search matches whole words only.</param>
- /// <returns><b>true</b> if text found.</returns>
- public bool Find(string text, bool matchCase, bool wholeWord)
- {
- if (CurrentPreview == null)
- return false;
- return CurrentPreview.Find(text, matchCase, wholeWord);
- }
- /// <summary>
- /// Finds the next occurence of text specified in the <b>Find</b> method.
- /// </summary>
- /// <returns><b>true</b> if text found.</returns>
- public bool FindNext()
- {
- if (CurrentPreview == null)
- return false;
- return CurrentPreview.FindNext();
- }
- /// <summary>
- /// Navigates to the first page.
- /// </summary>
- public void First()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.First();
- }
- /// <summary>
- /// Navigates to the previuos page.
- /// </summary>
- public void Prior()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Prior();
- }
- /// <summary>
- /// Navigates to the next page.
- /// </summary>
- public void Next()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Next();
- }
- /// <summary>
- /// Navigates to the last page.
- /// </summary>
- public void Last()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Last();
- }
- /// <summary>
- /// Gets or sets the current page number.
- /// </summary>
- /// <remarks>
- /// This value is 1-based.
- /// </remarks>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public int PageNo
- {
- get
- {
- if (CurrentPreview == null)
- return 1;
- return CurrentPreview.PageNo;
- }
- set
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.PageNo = value;
- }
- }
- /// <summary>
- /// Gets the pages count in the current report.
- /// </summary>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public int PageCount
- {
- get
- {
- if (CurrentPreview == null)
- return 0;
- return CurrentPreview.PageCount;
- }
- }
- /// <summary>
- /// Gets or sets the zoom factor.
- /// </summary>
- /// <remarks>
- /// <b>1</b> corresponds to 100% zoom.
- /// </remarks>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public float Zoom
- {
- get
- {
- if (CurrentPreview == null)
- return 1;
- return CurrentPreview.Zoom;
- }
- set
- {
- if (CurrentPreview != null)
- CurrentPreview.Zoom = value;
- }
- }
- /// <summary>
- /// Zooms in.
- /// </summary>
- public void ZoomIn()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.ZoomIn();
- }
- /// <summary>
- /// Zooms out.
- /// </summary>
- public void ZoomOut()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.ZoomOut();
- }
- /// <summary>
- /// Zooms to fit the page width.
- /// </summary>
- public void ZoomPageWidth()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.ZoomPageWidth();
- }
- /// <summary>
- /// Zooms to fit the whole page.
- /// </summary>
- public void ZoomWholePage()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.ZoomWholePage();
- }
- /// <summary>
- /// Edits the current page in the designer.
- /// </summary>
- public void EditPage()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.EditPage();
- }
- /// <summary>
- /// Copies the current page in preview.
- /// </summary>
- public void CopyPage()
- {
- if (CurrentPreview != null)
- {
- CurrentPreview.CopyPage();
- UpdateDeletePageButton();
- }
- }
- /// <summary>
- /// Removes the current page in preview.
- /// </summary>
- public void DeletePage()
- {
- if (CurrentPreview != null)
- {
- CurrentPreview.DeletePage();
- UpdateDeletePageButton();
- }
- }
- /// <summary>
- /// Edits the current report in the designer.
- /// </summary>
- public void Design()
- {
- if (Report == null)
- return;
- using (Report designedReport = new Report())
- {
- designedReport.FileName = Report.FileName;
- if (!String.IsNullOrEmpty(Report.FileName))
- designedReport.Load(designedReport.FileName);
- else
- using (MemoryStream repStream = new MemoryStream())
- {
- Report.Save(repStream);
- repStream.Position = 0;
- designedReport.Load(repStream);
- }
- Report.Dictionary.ReRegisterData(designedReport.Dictionary);
- if (designedReport.Design())
- {
- Report.PreparedPages.Clear();
- Report.PreparedPages.ClearPageCache();
- Report.LoadFromString(designedReport.SaveToString());
- if (CurrentPreview != null)
- {
- Report.Preview = CurrentPreview.Preview;
- Report.Show();
- }
- }
- }
- }
- /// <summary>
- /// Edits the watermark.
- /// </summary>
- public void EditWatermark()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.EditWatermark();
- }
- /// <summary>
- /// Edits the page settings.
- /// </summary>
- public void PageSetup()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.PageSetup();
- }
- /// <summary>
- /// Navigates to the specified position inside a specified page.
- /// </summary>
- /// <param name="pageNo">The page number (1-based).</param>
- /// <param name="point">The position inside a page, in pixels.</param>
- public void PositionTo(int pageNo, PointF point)
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.PositionTo(pageNo, point);
- }
- /// <summary>
- /// Clears the preview.
- /// </summary>
- public void Clear()
- {
- while (documents.Count > 0)
- {
- DeleteTab(documents[0]);
- }
- lblStatus.Text = "";
- tbPageNo.Text = "";
- }
- /// <summary>
- /// Refresh the report.
- /// </summary>
- public void RefreshReport()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.RefreshReport();
- }
- #endregion
- /// <summary>
- /// Initializes a new instance of the <see cref="PreviewControl"/> class.
- /// </summary>
- public PreviewControl()
- {
- // we need this to ensure that static constructor of the Report was called.
- Report report = new Report();
- report.Dispose();
- BarUtilities.UseTextRenderer = true;
- documents = new List<PreviewTab>();
- InitializeComponent();
- toolbarVisible = true;
- statusbarVisible = true;
- OutlineVisible = false;
- UIStyle = Config.UIStyle;
- Localize();
- Init();
- AddFakeTab();
- RightToLeft = Config.RightToLeft ? RightToLeft.Yes : RightToLeft.No;
- }
- }
- }
|