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

📄 mainframe.cs

📁 是用c#实现的一个有关于报表设计的程序代码
💻 CS
📖 第 1 页 / 共 5 页
字号:
#region License
/*
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/
#endregion

using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using daReport;


namespace daReportDesigner
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class MainFrame : System.Windows.Forms.Form
	{
		#region Declarations
		DaPrintDocument mDaPrintDocument;
		//ICustomPaint[] staticObjects;
		//ICustomPaint[] dynamicObjects;
		//ArrayList parameters;
		AboutFrame aboutFrame;

		private string theFilenameToSave;

		private System.Windows.Forms.MainMenu mainMenu;
		private System.Windows.Forms.MenuItem fileMenuItem;
		private System.Windows.Forms.MenuItem exitMenuItem;
		private System.Windows.Forms.StatusBar statusBar1;
		private System.Windows.Forms.StatusBarPanel messagePanel;
		private System.Windows.Forms.PropertyGrid propertyGrid;
		private System.Windows.Forms.Panel rightPanel;
		private System.Windows.Forms.Panel propertyPanel;
		private System.Windows.Forms.Label propertyLabel;
		private System.Windows.Forms.Splitter splitter2;
		private System.Windows.Forms.Splitter splitter3;
		private System.Windows.Forms.Panel browserPanel;
		private System.Windows.Forms.Label browserLabel;
		private System.Windows.Forms.MenuItem openMenuItem;
		private System.Windows.Forms.MenuItem menuItem2;
		private daReportDesigner.ObjectBrowser objectBrowser;
		private System.Windows.Forms.ImageList browserImageList;
		private System.Windows.Forms.ContextMenu browserContextMenuStatic;
		private System.Windows.Forms.MenuItem saveAsMenuItem;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Label propertyObject;
		private System.Windows.Forms.MenuItem saveMenuItem;
		private System.Windows.Forms.StatusBarPanel selectionPanel;
		private System.Windows.Forms.MenuItem addStaticTextFieldMenuItem;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.MenuItem deleteStaticObjectMenuItem;
		private System.Windows.Forms.MenuItem newMenuItem;
		private System.Windows.Forms.MenuItem addStaticPictureBoxMenuItem;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem backOneMenuItem;
		private System.Windows.Forms.MenuItem sendToBackStaticMenuItem;
		private System.Windows.Forms.MenuItem forwardOneStaticMenuItem;
		private System.Windows.Forms.MenuItem bringForwardStaticMenuItem;
		private System.Windows.Forms.ContextMenu browserStaticRootContextMenu;
		private System.Windows.Forms.MenuItem menuItem6;
		private System.Windows.Forms.MenuItem menuItem7;
		private System.Windows.Forms.MenuItem menuItem8;
		private System.Windows.Forms.ContextMenu browserDynamicRootContextMenu;
		private System.Windows.Forms.MenuItem addTableDynamicMenuItem;
		private System.Windows.Forms.MenuItem closeDocumentMenuItem;
		private System.Windows.Forms.MenuItem menuItem12;
		private System.Windows.Forms.Panel panel3;
		private System.Windows.Forms.MenuItem menuItem11;
		private System.Windows.Forms.MenuItem aboutMenuItem;
		private System.Windows.Forms.MenuItem addPageNumberMenuItem;
		private System.Windows.Forms.ContextMenu browserContextMenuDynamic;
		private System.Windows.Forms.MenuItem menuItem13;
		private System.Windows.Forms.MenuItem menuItem15;
		private System.Windows.Forms.MenuItem menuItem16;
		private System.Windows.Forms.MenuItem menuItem18;
		private System.Windows.Forms.MenuItem deleteDynamicMenuItem;
		private System.Windows.Forms.MenuItem backOneDynamicMenuItem;
		private System.Windows.Forms.MenuItem forwardOneDynamicMenuItem;
		private System.Windows.Forms.MenuItem sendToBackDynamicMenuItem;
		private System.Windows.Forms.MenuItem bringToFrontDynamicMenuItem;
		private System.Windows.Forms.MenuItem addStaticChartMenuItem;
		private System.Windows.Forms.MenuItem addStaticChartRootMenuItem;
		private System.Windows.Forms.MenuItem duplicateStaticMenuItem;
		private System.Windows.Forms.MenuItem menuItem17;
		private System.Windows.Forms.PrintPreviewDialog printPreviewDialog;
		private System.Windows.Forms.MenuItem printPreviewMenuItem;
		private System.Windows.Forms.MenuItem menuItem19;
		private System.Windows.Forms.MenuItem menuItem14;
		private System.Windows.Forms.MenuItem duplicateDynamicMenuItem;
		private System.Windows.Forms.TabControl tabPanel;
		private System.Windows.Forms.Panel scrollPanel;
		private daReportDesigner.DesignPane designPane;
		private System.Windows.Forms.TabPage editPage;
		private System.Windows.Forms.MenuItem optionsMenuItem;
		private System.Windows.Forms.MenuItem gridMenuItem;
		private System.Windows.Forms.MenuItem addStaticLineRootMenuItem;
		private System.Windows.Forms.MenuItem addStaticLineMenuItem;
		private System.Windows.Forms.MenuItem addStaticTableMenuItem;
		private System.ComponentModel.IContainer components;
		#endregion

		#region Object and Event Handlers

		private void MainFrame_Load(object sender, System.EventArgs e)
		{
			try
			{
				if (PrinterSettings.InstalledPrinters.Count == 0)
				{
					MessageBox.Show("You do not appear to have any printers installed", "daReport");
					this.newMenuItem.Enabled = false;
					this.openMenuItem.Enabled = false;
				}
			}
			catch (Exception ex)
			{
				if (ex.Message == "The RPC server is unavailable")
				{
					MessageBox.Show("It appears the print spooler service is not running", "daReport");
				}
				else
				{
					MessageBox.Show(ex.Message);
				}
				this.newMenuItem.Enabled = false;
				this.openMenuItem.Enabled = false;
			}
		}

		
		private void designPane_OnMoveFinished(ArrayList obj)
		{
			propertyGrid.Refresh();
			//selectionPanel.Text = "X: "+obj.X.ToString() + "  Y: " + obj.Y.ToString() + "  Width: " + obj.Width.ToString() + "  Height: " + obj.Height.ToString();
		}


		private void designPane_OnMoving(ArrayList obj)
		{
			//selectionPanel.Text = "X: "+obj.X.ToString() + "  Y: " + obj.Y.ToString() + "  Width: " + obj.Width.ToString() + "  Height: " + obj.Height.ToString();
		}
		

		private void designPane_OnSelectionChanged(ArrayList obj)
		{
			ArrayList StaticNodeIndexes = new ArrayList();
			ArrayList DynamicNodeIndexes = new ArrayList();

			objectBrowser.ClearSelectedNodes();
			if (obj.Count == 0)
			{
				objectBrowser.SelectedNode = objectBrowser.Nodes[0];
				return;
			}

			if (obj.Count == 1)
			{
				int temp = FindStaticObject((ICustomPaint)obj[0]);
				if (temp != -1)
				{
					objectBrowser.SelectStaticNode(temp);
					return;
				}

				temp = FindDynamicObject((ICustomPaint)obj[0]);
				if (temp != -1)
				{
					objectBrowser.SelectDynamicNode(temp);
					return;
				}

				return;
			}

			int objNum = 0;
			foreach (ICustomPaint CurrentObject in obj)
			{
				objNum = FindStaticObject(CurrentObject);

				if (objNum>=0) 
				{
					StaticNodeIndexes.Add(objNum);
					//objectBrowser.SelectStaticNode(objNum);
				}
			}
			//int objNum = FindStaticObject(obj);

			foreach (ICustomPaint CurrentObject in obj)
			{
				objNum = FindDynamicObject(CurrentObject);
			
				if (objNum>=0) 
				{
					DynamicNodeIndexes.Add(objNum);
					//objectBrowser.SelectDynamicNode(objNum);
				}
			}
			//objNum = FindDynamicObject(obj);

			if (StaticNodeIndexes.Count > 0 || DynamicNodeIndexes.Count > 0)
				objectBrowser.SelectNodes(StaticNodeIndexes, DynamicNodeIndexes);
		}
		

		private void objectBrowser_AfterCustomSelect(System.Windows.Forms.TreeViewEventArgs e)
		{
			ArrayList SelectedObjects = new ArrayList();

			foreach (TreeNode CurrentNode in objectBrowser.SelectedNodes)
			{
				if ( objectBrowser.IsStaticNode(CurrentNode))
				{
					propertyObject.Text = CurrentNode.Text;
					objectBrowser.ContextMenu = browserContextMenuStatic;
					SelectedObjects.Add(mDaPrintDocument.StaticObjects[CurrentNode.Index]);
				}
				else if ( objectBrowser.IsDynamicNode(CurrentNode) )
				{
					propertyGrid.SelectedObject = mDaPrintDocument.DynamicObjects[CurrentNode.Index];
					objectBrowser.ContextMenu = browserContextMenuDynamic;
					SelectedObjects.Add(mDaPrintDocument.DynamicObjects[CurrentNode.Index]);
				}
				else if ( CurrentNode == objectBrowser.Nodes[0])
				{
					propertyGrid.SelectedObject = mDaPrintDocument;
					propertyObject.Text = "Print document";
				}
				else
				{
					if ( CurrentNode == objectBrowser.staticContentsNode )
						objectBrowser.ContextMenu = this.browserStaticRootContextMenu;
					else if ( CurrentNode == objectBrowser.dynamicContentsNode )
						objectBrowser.ContextMenu = this.browserDynamicRootContextMenu;

					propertyGrid.SelectedObject = null;
					propertyObject.Text = "";				
					designPane.SelectObjects(SelectedObjects);
				}
			}

			if (objectBrowser.SelectedNodes.Count > 1 && objectBrowser.SelectedNodes[0] != objectBrowser.Nodes[0])
			{
				if (SelectedObjects.Count > 1)
					propertyObject.Text = "Common Properties";
				propertyGrid.SelectedObjects = SelectedObjects.ToArray();
				designPane.SelectObjects(SelectedObjects);
			}
		}


		private void propertyGrid_PropertyValueChanged(object s, System.Windows.Forms.PropertyValueChangedEventArgs e)
		{
			TreeNode selectedNode = objectBrowser.SelectedNode;

			if ( objectBrowser.IsStaticNode(selectedNode) )
				objectBrowser.SetNodeText(mDaPrintDocument.StaticObjects[selectedNode.Index],selectedNode);
			else if ( objectBrowser.IsDynamicNode(selectedNode) )
				objectBrowser.SetNodeText(mDaPrintDocument.DynamicObjects[selectedNode.Index],selectedNode);
			else if ( objectBrowser.IsRootNode(selectedNode) )
			{
				if (e.ChangedItem.Label == "Layout")
				{
					designPane.SetSize(mDaPrintDocument.DefaultPageSettings);
				}

				objectBrowser.SetData(mDaPrintDocument.Parameters,mDaPrintDocument.StaticObjects,mDaPrintDocument.DynamicObjects);
				objectBrowser.SelectedNode = objectBrowser.Nodes[0];
			}

			propertyObject.Text = objectBrowser.SelectedNode.Text;
			designPane.Refresh();
		}
		

		private void MainFrame_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.Modifiers == Keys.Control && (e.KeyCode == Keys.Down || e.KeyCode == Keys.Up || e.KeyCode == Keys.Right || e.KeyCode == Keys.Left) )
			{
				designPane.DesignPane_KeyDown(this,e);
				e.Handled = true;
			}
			else 
				e.Handled = false;

		}


		private void MainFrame_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			designPane.DesignPane_KeyUp(this,e);
		}


		private void ParametersModified_EventHandler(object sender, ParameterModifiedEventArgs e)
		{
			objectBrowser.SetData(mDaPrintDocument.Parameters,mDaPrintDocument.StaticObjects,mDaPrintDocument.DynamicObjects);
		}


		#endregion

		#region Menu Event Handlers

		#region File Menu

		private void closeDocumentMenuItem_Click(object sender, System.EventArgs e)
		{
			CloseDocument();
		}

		
		private void exitMenuItem_Click(object sender, System.EventArgs e)
		{
			DoClose();
		}
		
		
		private void newMenuItem_Click(object sender, System.EventArgs e)
		{
			NewDocument();
			this.saveAsMenuItem.Enabled = true;
			this.saveMenuItem.Enabled = true;
			this.closeDocumentMenuItem.Enabled = true;
		}

		
		private void openMenuItem_Click(object sender, System.EventArgs e)
		{
			OpenFileDialog fod = new OpenFileDialog();
			fod.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
			fod.FilterIndex=0;
			if (DialogResult.OK == fod.ShowDialog(this))
			{
				OpenDocument(fod.FileName);
			}

⌨️ 快捷键说明

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