代码拉取完成,页面将自动刷新
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Design;
using System.IO;
using GrapeCity.ActiveReports.Design;
using GrapeCity.ActiveReports.Design.Resources;
using System.ComponentModel.Design;
using GrapeCity.ActiveReports.PageReportModel;
using ActiveReportsDemo.Viewers;
using ActiveReportsDemo;
namespace GrapeCity.ActiveReports.Samples.EndUserDesigner
{
public partial class EndUserDesigner : Form
{
ToolStripDropDownItem _fileMenu;
Boolean Openflag=false;
string _reportName;
DefaultViewer dfv=null;
/// <summary>
/// 当前编辑的报表名称
/// </summary>
public string CurrentReport
{ get; set; }
public EndUserDesigner()
{
InitializeComponent();
//Set the ToolBox, ReportExplorer and PropertyGrid in the Designer.
reportDesigner.Toolbox = reportToolbox;//Attaches the toolbox to the report designer
//this.reportExplorer.ReportDesigner = this.reportdesigner;Attaches the report explorer to the report designer
reportDesigner.LayoutChanged += new LayoutChangedEventHandler(OnLayoutChanged);
layerList.ReportDesigner = reportDesigner;
reportDesigner.PropertyGrid = reportPropertyGrid;//Attaches the Property Grid to the report designer
//Populate the menu.
ToolStrip toolstrip = reportDesigner.CreateToolStrips(new DesignerToolStrips[]
{
DesignerToolStrips.Menu
})[0];
_fileMenu = (ToolStripDropDownItem)toolstrip.Items[0];
CreateFileMenu(_fileMenu);
AppendToolStrips(0, new ToolStrip[]
{
toolstrip
});
AppendToolStrips(1, reportDesigner.CreateToolStrips(new DesignerToolStrips[]
{
DesignerToolStrips.Edit,
DesignerToolStrips.Undo,
DesignerToolStrips.Zoom
}));
ToolStrip item = CreateReportToolbar();
AppendToolStrips(1, new ToolStrip[]
{
item
});
AppendToolStrips(2, reportDesigner.CreateToolStrips(new DesignerToolStrips[]
{
DesignerToolStrips.Format,
DesignerToolStrips.Layout
}));
LoadTools(reportToolbox);
reportDesigner.LayoutChanged += (sender, args) => { if (args.Type == LayoutChangeType.ReportLoad || args.Type == LayoutChangeType.ReportClear) RefreshExportEnabled(); };
RefreshExportEnabled();
CreateReportExplorer();
}
private void OnLayoutChanged(object sender, LayoutChangedArgs e)
{
if (e.Type == LayoutChangeType.ReportLoad || e.Type == LayoutChangeType.ReportClear)
{
reportToolbox.Reorder(reportDesigner);
reportToolbox.EnsureCategories();
reportToolbox.Refresh();
RefreshExportEnabled();
CreateReportExplorer();
}
if (e.Type == LayoutChangeType.ReportClear)
{
_reportName = null;
}
if (e.Type == LayoutChangeType.ReportLoad)
{
if (!string.IsNullOrEmpty(_reportName))
{
if (GetIsMaster())
{
_reportName = null;
}
}
}
}
private void RefreshExportEnabled()
{
reportDesigner.ActiveTabChanged -= OnEnableExport;
reportDesigner.ActiveTabChanged += OnEnableExport;
OnEnableExport(this, EventArgs.Empty);
}
private void OnEnableExport(object sender, EventArgs eventArgs)
{
_fileMenu.DropDownItems[2].Enabled = reportDesigner.ActiveTab == DesignerTab.Preview;
}
private static void LoadTools(IToolboxService toolbox)
{
//Add Data Providers.
foreach (Type type in new Type[]
{
typeof (System.Data.DataSet),
typeof (System.Data.DataView),
typeof (System.Data.OleDb.OleDbConnection),
typeof (System.Data.OleDb.OleDbDataAdapter),
typeof (System.Data.Odbc.OdbcConnection),
typeof (System.Data.Odbc.OdbcDataAdapter),
typeof (System.Data.SqlClient.SqlConnection),
typeof (System.Data.SqlClient.SqlDataAdapter)
})
{
toolbox.AddToolboxItem(new ToolboxItem(type), ActiveReportsDemo.Properties.Resources.ToolBoxData);
}
}
//Adding DropDownItems to the ToolStripDropDownItem.
private void CreateFileMenu(ToolStripDropDownItem fileMenu)
{
fileMenu.DropDownItems.Clear();
fileMenu.DropDownItems.Add(new ToolStripMenuItem(ActiveReportsDemo.Properties.Resources.NewText, ActiveReportsDemo.Properties.Resources.CmdNewReport, new EventHandler(OnNew), (Keys.Control | Keys.N)));
fileMenu.DropDownItems.Add(new ToolStripMenuItem(ActiveReportsDemo.Properties.Resources.OpenText, ActiveReportsDemo.Properties.Resources.CmdOpen, new EventHandler(OnOpen), (Keys.Control | Keys.O)));
fileMenu.DropDownItems.Add(new ToolStripMenuItem(ActiveReportsDemo.Properties.Resources.ExportText, null, new EventHandler(OnExport), (Keys.Control | Keys.E)));
fileMenu.DropDownItems.Add(new ToolStripMenuItem(ActiveReportsDemo.Properties.Resources.SaveText, ActiveReportsDemo.Properties.Resources.CmdSave, new EventHandler(OnSave), (Keys.Control | Keys.S)));
fileMenu.DropDownItems.Add(new ToolStripMenuItem(ActiveReportsDemo.Properties.Resources.SaveAsText, ActiveReportsDemo.Properties.Resources.CmdSaveAs, new EventHandler(OnSaveAs)));
fileMenu.DropDownItems.Add(new ToolStripSeparator());
fileMenu.DropDownItems.Add(new ToolStripMenuItem(ActiveReportsDemo.Properties.Resources.ExitText, null, new EventHandler(OnExit)));
fileMenu.DropDownItems[2].Enabled = false;
}
private ToolStrip CreateReportToolbar()
{
return new ToolStrip(new ToolStripButton[]
{
CreateToolStripButton(ActiveReportsDemo.Properties.Resources.NewText,ActiveReportsDemo.Properties.Resources.CmdNewReport,new EventHandler(OnNew),ActiveReportsDemo.Properties.Resources.NewText),
CreateToolStripButton(ActiveReportsDemo.Properties.Resources.OpenText,ActiveReportsDemo.Properties.Resources.CmdOpen,new EventHandler(OnOpen),ActiveReportsDemo.Properties.Resources.OpenText),
CreateToolStripButton(ActiveReportsDemo.Properties.Resources.SaveText,ActiveReportsDemo.Properties.Resources.CmdSave,new EventHandler(OnSave),ActiveReportsDemo.Properties.Resources.SaveText)
});
}
private bool PerformSave()
{
if (string.IsNullOrEmpty(_reportName) || string.IsNullOrEmpty(Path.GetDirectoryName(_reportName)) || !File.Exists(_reportName))
{
return PerformSaveAs();
}
reportDesigner.SaveReport(new FileInfo(_reportName));
return true;
}
private bool PerformSaveAs()
{
using (SaveFileDialog dlg = new SaveFileDialog())
{
dlg.Filter = GetSaveFilter(reportDesigner.ReportType, GetIsMaster());
if (dlg.ShowDialog() == DialogResult.OK)
{
_reportName = dlg.FileName;
reportDesigner.SaveReport(new FileInfo(dlg.FileName));
return true;
}
}
return false;
}
private bool GetIsMaster()
{
bool isMaster = false;
if (reportDesigner.ReportType == DesignerReportType.Rdl)
{
var report = (Component)reportDesigner.Report;
var site = report == null ? null : report.Site;
if (site != null)
{
var host = site.GetService(typeof(IDesignerHost)) as IDesignerHost;
if (host != null)
{
var mcs = host.GetService(typeof(IMasterContentService)) as IMasterContentService;
isMaster = mcs != null && mcs.IsMaster;
}
}
}
return isMaster;
}
private string GetSaveFilter(DesignerReportType type, bool isMaster)
{
switch (type)
{
case DesignerReportType.Section:
return ActiveReportsDemo.Properties.Resources.SectionReportFilter;
case DesignerReportType.Page:
return ActiveReportsDemo.Properties.Resources.PageReportFilter;
case DesignerReportType.Rdl:
return isMaster ? ActiveReportsDemo.Properties.Resources.RDLReportFilterMaster : ActiveReportsDemo.Properties.Resources.RDLReportFilter;
default:
return ActiveReportsDemo.Properties.Resources.SectionReportFilter;
}
}
//Click "New" to open a new report.
private void OnNew(object sender, EventArgs e)
{
if (ConfirmSaveChanges())
{
reportDesigner.ExecuteAction(DesignerAction.NewReport);
EnableTabs();
}
}
//Click "Open" to open an existing report.
private void OnOpen(object sender, EventArgs e)
{
if (!ConfirmSaveChanges())
{
return;
}
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Filter = ActiveReportsDemo.Properties.Resources.OpenFileFilter;
if (dlg.ShowDialog() == DialogResult.OK)
{
_reportName = dlg.FileName;
reportDesigner.LoadReport(new FileInfo(dlg.FileName));
EnableTabs();
}
}
}
public void OnDesign(string reportName)
{
Openflag = true;
_reportName = reportName;
string filename =Application.StartupPath+ @"\Reports\" + reportName;
_reportName = filename;
reportDesigner.LoadReport(new FileInfo(filename));
}
private void OnExport(object sender, EventArgs e)
{
ExportForm exportForm = new ExportForm(reportDesigner.ReportType, reportDesigner.Report, reportDesigner.ReportViewer);
exportForm.Show();
}
//Click "Save" to save a report.
private void OnSave(object sender, EventArgs e)
{
if (Openflag == true)
{ reportDesigner.SaveReport(new FileInfo(_reportName));
MessageBox.Show(this,"保存成功");
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
else PerformSave();
}
//Click "Save as" to save a report with a name.
private void OnSaveAs(object sender, EventArgs e)
{
PerformSaveAs();
}
private void OnExit(object sender, EventArgs e)
{
Close();
}
//Checking whether modifications have been made to the report loaded to the designer.
private bool ConfirmSaveChanges()
{
if (reportDesigner.IsDirty)
{
DialogResult dialogresult = MessageBox.Show(ActiveReportsDemo.Properties.Resources.ReportDirtyMessage, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (dialogresult == DialogResult.Cancel)
{
return false;
}
if (dialogresult == DialogResult.Yes)
{
return PerformSave();
}
}
return true;
}
private void AppendToolStrips(int row, IList<ToolStrip> toolStrips)
{
ToolStripPanel topToolStripPanel = toolStripContainer.TopToolStripPanel;
int num = toolStrips.Count;
while (--num >= 0)
{
topToolStripPanel.Join(toolStrips[num], row);
}
}
private static ToolStripButton CreateToolStripButton(string text, System.Drawing.Image image, EventHandler handler, string toolTip)
{
return new ToolStripButton(text, image, handler)
{
DisplayStyle = ToolStripItemDisplayStyle.Image,
ToolTipText = toolTip,
DoubleClickEnabled = true
};
}
private void CreateReportExplorer()
{
if (reportDesigner.ReportType == DesignerReportType.Section)
{
if (explorerPropertyGridContainer.Panel1.Controls.Contains(reportExplorerTabControl))
{
reportExplorerTabControl.TabPages[0].SuspendLayout();
explorerPropertyGridContainer.Panel1.SuspendLayout();
explorerPropertyGridContainer.Panel1.Controls.Remove(reportExplorerTabControl);
explorerPropertyGridContainer.Panel1.Controls.Add(reportExplorer);
reportExplorerTabControl.TabPages[0].ResumeLayout();
explorerPropertyGridContainer.Panel1.ResumeLayout();
}
}
else if (!explorerPropertyGridContainer.Panel1.Controls.Contains(reportExplorerTabControl))
{
reportExplorerTabControl.TabPages[0].SuspendLayout();
explorerPropertyGridContainer.Panel1.SuspendLayout();
explorerPropertyGridContainer.Panel1.Controls.Remove(reportExplorer);
reportExplorerTabControl.TabPages[0].Controls.Add(reportExplorer);
explorerPropertyGridContainer.Panel1.Controls.Add(reportExplorerTabControl);
reportExplorerTabControl.TabPages[0].ResumeLayout();
explorerPropertyGridContainer.Panel1.ResumeLayout();
}
}
private void EnableTabs()
{
reportToolbox.Reorder(reportDesigner);
reportToolbox.EnsureCategories();
reportToolbox.Refresh();
}
private void EndUserDesigner_Load(object sender, EventArgs e)
{
this.OnDesign(CurrentReport);
this.Text += string.Format("({0})", CurrentReport);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。