⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sharpreportview.cs

📁 c#源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
/*
 * Created by SharpDevelop.
 * User: Forstmeier Peter
 * Date: 10.01.2005
 * Time: 10:04
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
// one line to give the program's name and an idea of what it does.
// Copyright (C) 2005  peter.forstmeier@t-online.de

using System;
using System.IO;
using System.Globalization;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Data;

using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Gui.Pads;
using ICSharpCode.Core;
using ICSharpCode.Core.Services;
using ICSharpCode.SharpDevelop.Services;
using ICSharpCode.SharpDevelop.Gui.Components;	 //SideBar

using SharpReport;
using SharpReportCore;
using SharpReport.Designer;

namespace SharpReportAddin{
	/// <summary>
	/// Description of the view content
	/// </summary>
	public class SharpReportView : AbstractViewContent,IPrintable
	{
		
		private SharpReportManager reportManager = null;
		
		private BaseDesignerControl designerControl;
		private	TabControl tabControl;
		private TabPage designerPage;
		private TabPage previewPage;
		
		private PropertyService propertyService = null;
		private ResourceService resourceService = null;
		private IMessageService messageService = null;
		
		// SideBar
		private AxSideTab sideTabItem = null;
		private AxSideTab sideTabFunctions = null;
		private Panel panel = new Panel();
	
		#region privates
		void GrapServices() {
			propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
			resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(ResourceService));
			messageService =(IMessageService)ServiceManager.Services.GetService(typeof(IMessageService));
		}
		void InitView() {
			try {
				reportManager = new SharpReportManager();
				panel.AutoScroll = true;
				CreateTabControl();
				BuildToolBarItems();
				base.UntitledName = GlobalValues.SharpReportPlainFileName;
				base.FileName = GlobalValues.SharpReportPlainFileName;
				PropertyPad.Grid.SelectedObject = designerControl.ReportModel.ReportSettings;
				PropertyPad.Grid.Refresh();
			} catch (Exception e) {
				IMessageService messageService =(IMessageService)ServiceManager.Services.GetService(typeof(IMessageService));
				messageService.ShowError(e,e.Message);
				throw e;
			}
		}
		
		
		// when the model is build, grap these events, otherwise we get permanent
		// changes of IsDirty
		
		private void SetOnPropertyChangedEvents () {
			try {
				ReportModel model = designerControl.ReportModel;
				model.ReportSettings.PropertyChanged += new EventHandler (OnSettingsChanged);
				model.ReportHeader.PropertyChange += new PropertyChangeEventHandler (OnPropertyChanged);
				model.PageHeader.PropertyChange += new PropertyChangeEventHandler (OnPropertyChanged);
				model.DetailSection.PropertyChange += new PropertyChangeEventHandler (OnPropertyChanged);
				model.PageFooter.PropertyChange += new PropertyChangeEventHandler (OnPropertyChanged);
				model.ReportFooter.PropertyChange += new PropertyChangeEventHandler (OnPropertyChanged);
				//watch for FileName change from Reportsettings as well
				model.ReportSettings.FileNameChanged += new EventHandler(OnModelFileNameChanged);
			} catch (Exception) {
				throw;
			}
		}
		
		///<summary>
		/// We have to tell the FieldsdsExplorer that we have loaded or created a new report
		/// </summary>
		/// 
		private void SetFieldsExplorer() {
			try {
				Type type = typeof(FieldsExplorer);
				SharpReportAddin.FieldsExplorer fe = (SharpReportAddin.FieldsExplorer)WorkbenchSingleton.Workbench.GetPad(type);
				if (fe != null) {
					fe.UpdateExplorer();
				}
			} catch (Exception) {
			}
		}
		#endregion
		
	
		
		#region SideBar Handling
		
		private bool SharpReportIsRunning () {
			// Did we already exist
			foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) {
				SharpReportView view = content as SharpReportView;
				if (view != null) {
					return true;
				}
			}
			return false;
		}
		
		private SharpDevelopSideBar GetSideBar () {
			SideBarView v = (SideBarView)WorkbenchSingleton.Workbench.GetPad (typeof(SideBarView));
			SharpDevelopSideBar sb =(SharpDevelopSideBar) v.Control;
			return sb;
		}
		
		private void BuildToolBarItems() {

			SharpDevelopSideBar	sideBar = GetSideBar();
			

			if (!this.SharpReportIsRunning()) {
				sideBar.DoAddTab = true;
				sideTabItem = sideBar.SideTabFactory.CreateSideTab (sideBar,
				                                                   resourceService.GetString("SharpReport.Toolbar.Controls"));
				sideBar.Tabs.Add (sideTabItem);
				sideTabItem.CanDragDrop = true;
				this.sideTabItem.CanSaved = false;
				AddReportElements();
				sideBar.ActiveTab = sideTabItem;
				
				//SideBar Functions
				this.sideTabFunctions = sideBar.SideTabFactory.CreateSideTab (sideBar,
				                                                              resourceService.GetString("SharpReport.Toolbar.Functions"));
				this.sideTabFunctions.CanDragDrop = true;
				this.sideTabFunctions.CanSaved = false;
				AddFunctionElements();
				sideBar.Tabs.Add (this.sideTabFunctions);
				sideBar.Refresh();
			}
		}
		
		
		void AddFunctionElements () {
			
			AxSideTabItem t = sideTabItem.SideTabItemFactory.CreateSideTabItem(resourceService.GetString("SharpReport.Toolbar.Pointer"),
			                                                                   "pointer",
			                                                                   resourceService.GetBitmap("Icons.16x16.FormsDesigner.PointerIcon"));
			
			FunctionFactory ff = new FunctionFactory();
			string localise = "SharpReport.Toolbar.Functions.";
	
			this.sideTabFunctions.Items.Add (t);
			
// TODO  make this more generic, use a loop to fill the SidebarItems, and, each function
			
			t = sideTabFunctions.SideTabItemFactory.CreateSideTabItem(resourceService.GetString(localise + ff.AvailableTypes[0]) ,
                                                          ff.AvailableTypes[0].ToString(),
			                                                          GlobalValues.FunctionBitmap());
			
			this.sideTabFunctions.Items.Add (t);
		

			t = sideTabFunctions.SideTabItemFactory.CreateSideTabItem (resourceService.GetString(localise + ff.AvailableTypes[1]),
			                                                           ff.AvailableTypes[1],
			                                                          GlobalValues.FunctionBitmap());
			
			this.sideTabFunctions.Items.Add (t);
		
		}
		
		
		void AddReportElements () {
			AxSideTabItem t = sideTabItem.SideTabItemFactory.CreateSideTabItem(resourceService.GetString("SharpReport.Toolbar.Pointer"),
			                                                                   "pointer",
			                                                                   resourceService.GetBitmap("Icons.16x16.FormsDesigner.PointerIcon"));
// TODO abjust resourcestrings to classnames
// SharpReport.Toolbar.TextBox -> SharpReport.Toolbar.ReportTextItem
			sideTabItem.Items.Add (t);
			t = sideTabItem.SideTabItemFactory.CreateSideTabItem(resourceService.GetString("SharpReport.Toolbar.TextBox"),
			                                                     GlobalEnums.ReportItemType.ReportTextItem.ToString(),
			                                                     GlobalValues.TextBoxBitmap());
		

			sideTabItem.Items.Add (t);
			t = sideTabItem.SideTabItemFactory.CreateSideTabItem( resourceService.GetString("SharpReport.Toolbar.DataField"),
			                                                     GlobalEnums.ReportItemType.ReportDataItem.ToString(),
			                                                     resourceService.GetBitmap("Icons.16x16.SharpQuery.Column"));
			sideTabItem.Items.Add (t);
			

			Icon icon = resourceService.GetIcon("Icons.16x16.ResourceEditor.bmp");
			t = sideTabItem.SideTabItemFactory.CreateSideTabItem( "Image",
			                                                     GlobalEnums.ReportItemType.ReportImageItem.ToString(),
			                                                     icon.ToBitmap());
			sideTabItem.Items.Add (t);
			
			t = sideTabItem.SideTabItemFactory.CreateSideTabItem( resourceService.GetString("SharpReport.Toolbar.Rectangle"),
			                                                     GlobalEnums.ReportItemType.ReportRectangleItem.ToString(),
			                                                     GlobalValues.RectangleBitmap());
			sideTabItem.Items.Add (t);
			
			t = sideTabItem.SideTabItemFactory.CreateSideTabItem( resourceService.GetString("SharpReport.Toolbar.Line"),
			                                                     GlobalEnums.ReportItemType.ReportLineItem.ToString(),
			                                                     GlobalValues.LineBitmap());
			sideTabItem.Items.Add (t);
			t = sideTabItem.SideTabItemFactory.CreateSideTabItem(resourceService.GetString("SharpReport.Toolbar.Circle"),
			                                                     GlobalEnums.ReportItemType.ReportCircleItem.ToString(),
			                                                     GlobalValues.CircleBitmap());
			sideTabItem.Items.Add (t);
		}
		
		
		void RemoveSideBarItem() {

			if (!this.SharpReportIsRunning()) {
				if (sideTabItem != null) {
					SharpDevelopSideBar	sideBar = GetSideBar();
					sideBar.Tabs.Remove (sideTabItem);
				}
				if (this.sideTabFunctions != null) {
					SharpDevelopSideBar	sideBar = GetSideBar();
					sideBar.Tabs.Remove(this.sideTabFunctions);
				}
				SideBarView v = (SideBarView)WorkbenchSingleton.Workbench.GetPad (typeof(SideBarView));
				SharpDevelopSideBar sb =(SharpDevelopSideBar) v.Control;
				
				AxSideTab s;
				for (int i = SideBarView.sideBar.Tabs.Count -1; i > 0;i -- ) {
					s = SideBarView.sideBar.Tabs[i];
					if (s.Name.IndexOf("Report") > 0) {
						SideBarView.sideBar.Tabs.Remove(s);
					}
				}
			}
		}
		
		#endregion
		
		
		#region Control
		
		void CreateTabControl() {
			tabControl = new TabControl();
			tabControl.SelectedIndexChanged += new EventHandler (OnTabPageChanged);
			
			designerPage = new TabPage();

			designerControl = CreateDesignerControl();
			designerPage.Controls.Add (designerControl);
			//create only the TabPage, no Controls are added
			previewPage = new TabPage ();
			tabControl.TabPages.Add (designerPage);
			tabControl.TabPages.Add (previewPage);
			
			tabControl.Alignment = TabAlignment.Bottom;
			
			panel.Dock = DockStyle.Fill;
			panel.AutoScroll = true;
			
			tabControl.Dock = DockStyle.Fill;

			panel.Controls.Add (tabControl);
			SetHeadLines();
			
		}
		//We set all captions in one method, so we can react much easier on changing of lanuages
		void SetHeadLines(){
			designerPage.Text = resourceService.GetString("SharpReport.Design");
			previewPage.Text = resourceService.GetString("SharpReport.Preview");
			this.OnTabPageChanged (this,EventArgs.Empty);
			this.designerControl.Localise();
		}
		
		private BaseDesignerControl CreateDesignerControl() {
			BaseDesignerControl ctrl = reportManager.BaseDesignControl;
			ctrl.ReportControl.Width = ctrl.ReportModel.ReportSettings.PageSettings.Bounds.Width;
			ctrl.ReportControl.AutoScroll = true;
			ctrl.Dock = DockStyle.Fill;
			
			ctrl.ReportControl.ObjectSelected += new SelectedEventHandler (OnObjectSelected);
			ctrl.ReportControl.DesignViewChanged += new ItemDragDropEventHandler (OnItemDragDrop);
			ctrl.DesignerDirty += new PropertyChangeEventHandler (OnPropertyChanged);
			return ctrl;
		}
		
		#endregion
		
		
		#region Preview handling
		private void RunPreview() {
			base.OnSaving(EventArgs.Empty);
			try {
				switch (designerControl.ReportModel.ReportSettings.DataModel) {
					case GlobalEnums.enmPushPullModel.FormSheet : {
						PreviewStandartReport();
						break;
					}
					case GlobalEnums.enmPushPullModel.PullData:{
						PreviewStandartReport();
						break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -