report.cs

来自「SharpDevelop2.0.0 c#开发免费工具」· CS 代码 · 共 472 行 · 第 1/2 页

CS
472
字号
/*
 * Created by SharpDevelop.
 * Date: 09/10/2004
 * Time: 9.12
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;


using ICSharpCode.Core;

using SharpReportCore;

using SharpReport.ReportItems;


namespace SharpReport.Designer{
	/// <summary>
	/// Description of Report1.
	/// </summary>
	public class Report : System.Windows.Forms.UserControl
	{
		private SharpReport.Designer.ReportHeader visualReportHeader;
		private SharpReport.Designer.ReportPageHeader visualPageHeader;
		private SharpReport.Designer.ReportFooter visualFooter;
		private SharpReport.Designer.ReportPageFooter visualPageFooter;
		private SharpReport.Designer.ReportDetail visualDetail;
		

		
		// Generic selected object in report
		private IBaseRenderer	selectedObject;

		// Section selected in report
		private ReportSection	selectedSection;
		
		private ReportSection header;
		private ReportSection pageHeader;
		private ReportSection detail;
		private ReportSection footer;
		private ReportSection pageFooter;
		
		private ReportSectionCollection sectionCollection;
		
		private ReportSettings reportSettings;
		
		private NameService nameService;
		
		[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
		
		
		public event EventHandler <EventArgs> ObjectSelected;
		public event EventHandler <SectionChangedEventArgs> SectionChanged;
		public event  ItemDragDropEventHandler DesignViewChanged;

		public Report(){
			InitializeComponent();
			this.SetStyle(ControlStyles.DoubleBuffer |
			              ControlStyles.UserPaint |
			              ControlStyles.AllPaintingInWmPaint |
			              ControlStyles.ResizeRedraw,
			              true);
			this.UpdateStyles();
			InitSectionCollection();
			Localise();
			this.nameService = new NameService();
		}
		
		public void Localise() {
			this.visualReportHeader.Caption = ResourceService.GetString("SharpReport.Designer.ReportHeader");
			this.visualPageHeader.Caption = ResourceService.GetString("SharpReport.Designer.PageHeader");
			this.visualDetail.Caption = ResourceService.GetString("SharpReport.Designer.DetailSection");
			this.visualPageFooter.Caption = ResourceService.GetString("SharpReport.Designer.PageFooter");
			this.visualFooter.Caption = ResourceService.GetString("SharpReport.Designer.ReportFooter");
		}
		
		protected override void Dispose(bool disposing) {
			if( disposing ){
				
			}
			this.visualReportHeader.Dispose();
			this.visualPageHeader.Dispose();
			this.visualDetail.Dispose();
			this.visualPageFooter.Dispose();
			this.visualFooter.Dispose();
			
			base.Dispose(disposing);
		}
		
		private void SetDefaultValues() {
			foreach (BaseSection sec in this.sectionCollection) {
				sec.SectionMargin = this.reportSettings.DefaultMargins.Left;
				sec.Parent = null;
			}
		}
		
		private void InitSectionCollection () {
			sectionCollection = new ReportSectionCollection();
			header = new ReportSection( visualReportHeader);
			pageHeader = new ReportSection(visualPageHeader);
			detail = new ReportSection(visualDetail);
			pageFooter = new ReportSection(visualPageFooter);
			footer = new ReportSection(visualFooter);
			
			header.Name = header.VisualControl.GetType().Name;
			pageHeader.Name = pageHeader.VisualControl.GetType().Name;
			detail.Name = detail.VisualControl.GetType().Name;
			footer.Name = footer.VisualControl.GetType().Name;
			pageFooter.Name = pageFooter.VisualControl.GetType().Name;
			
			sectionCollection.Add(header);
			sectionCollection.Add(pageHeader);
			sectionCollection.Add(detail);
			sectionCollection.Add(pageFooter);
			sectionCollection.Add(footer);
			
			header.Selected += new EventHandler <EventArgs>(this.SectionSelected);
			pageHeader.Selected += new EventHandler <EventArgs>(this.SectionSelected);
			detail.Selected += new EventHandler <EventArgs>(this.SectionSelected);
			footer.Selected += new EventHandler <EventArgs>(this.SectionSelected);
			pageFooter.Selected += new EventHandler <EventArgs>(this.SectionSelected);
			
			header.ItemSelected += new EventHandler <EventArgs>(this.ItemSelected);
			pageHeader.ItemSelected += new EventHandler <EventArgs>(this.ItemSelected);
			detail.ItemSelected += new EventHandler <EventArgs>(this.ItemSelected);
			footer.ItemSelected += new EventHandler <EventArgs>(this.ItemSelected);
			pageFooter.ItemSelected += new EventHandler <EventArgs>(this.ItemSelected);
			
			//This events are from DragDropp
			visualReportHeader.ReportItemsHandling += new ItemDragDropEventHandler (OnAddReportItem);
			visualPageHeader.ReportItemsHandling += new ItemDragDropEventHandler (OnAddReportItem);
			visualDetail.ReportItemsHandling += new ItemDragDropEventHandler (OnAddReportItem);
			visualPageFooter.ReportItemsHandling += new ItemDragDropEventHandler (OnAddReportItem);
			visualFooter.ReportItemsHandling += new ItemDragDropEventHandler (OnAddReportItem);
		}
		
		private Rectangle SectionClientArea (SharpReport.Designer.ReportSectionControlBase ctrl) {
			Rectangle rect = new Rectangle();
			rect.X = ctrl.Location.X;
			rect.Y = ctrl.Location.Y + ctrl.Head.Height;
			rect.Width = ctrl.Width;
			rect.Height = ctrl.Body.Height;
			return rect;
		}
		
		private  void SetParent(BaseReportItem child,Point pointOf) {
			foreach (BaseReportItem i in this.SelectedSection.Items) {
				Rectangle r = new Rectangle (i.Location,i.Size);
				if (r.Contains(pointOf)) {
					child.Parent = i as IContainerItem;
					return;
				}
			}
			child.Parent = this.SelectedSection;
		}
		
		
		private IContainerItem FindParent(ItemDragDropEventArgs iddea) {
			foreach (BaseReportItem i in this.SelectedSection.Items) {
				Rectangle r = new Rectangle (i.Location,i.Size);
				if (r.Contains(iddea.ItemAtPoint)) {
					return i as IContainerItem;
				}
			}
			return null;
		}
		
		
		private BaseReportItem BuildDraggedItem (ItemDragDropEventArgs iddea) {
			GlobalEnums.ReportItemType rptType = (GlobalEnums.ReportItemType)
				GlobalEnums.StringToEnum(typeof(GlobalEnums.ReportItemType),iddea.ItemName);
			
			SharpReport.Designer.IDesignableFactory gf = new SharpReport.Designer.IDesignableFactory();
			return gf.Create (rptType.ToString());
		}
		
		private void CustomizeItem ( ItemDragDropEventArgs iddea,
		                            ReportItemCollection itemCollection,
		                            BaseReportItem baseReportItem) {
			
			GlobalEnums.ReportItemType rptType = (GlobalEnums.ReportItemType)
				GlobalEnums.StringToEnum(typeof(GlobalEnums.ReportItemType),iddea.ItemName);
			
			baseReportItem.Name = nameService.CreateName(itemCollection,
			                                             baseReportItem.Name);
			

			if (baseReportItem.Parent == this.selectedSection) {
				baseReportItem.Location = new Point(iddea.ItemAtPoint.X,iddea.ItemAtPoint.Y);
			} else {
				BaseReportItem br = (BaseReportItem)this.FindParent(iddea);
				baseReportItem.Location = new Point(iddea.ItemAtPoint.X - br.Location.X,10);
			}
			baseReportItem.ResumeLayout();
		}
		
		
		private void AdjustDesignable (BaseReportItem item) {
			IDesignable designable = item as IDesignable;
			designable.VisualControl.Name = item.Name;
		}
		
		
		private void SetVisualControl (BaseReportItem item){
			Control ctrl = null;
			if (item.Parent == null) {
				ctrl = this.selectedSection.VisualControl.Body;
			} else {
				if (item.Parent is ReportControlBase) {
					ReportControlBase rb = item.Parent as ReportControlBase;
					ctrl = rb.Body;
				}
			}
			
			if (ctrl != null) {
				IDesignable designable = item as IDesignable;
				if (designable != null) {
					ctrl.Controls.Add(designable.VisualControl);
					this.AdjustControl(designable);
					ctrl.Invalidate();
				}
			}
		}
		
		private ReportSection SectionByName ( ReportSectionControlBase item) {
			if (item != null) {
				return  (ReportSection)sectionCollection.Find(item.GetType().Name);
			}
			throw new NullReferenceException("No Section in Report.OnAddReportItem");
		}
		
		private void AdjustControl (IDesignable ctrl) {

⌨️ 快捷键说明

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