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

📄 mainform.cs

📁 一个通用的数据库访问层
💻 CS
📖 第 1 页 / 共 3 页
字号:
			// 
			// gridPopup
			// 
			this.gridPopup.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.newOperationItem,
																					  this.editOperationItem,
																					  this.deleteOperationItem,
																					  this.menuItem5,
																					  this.upOperationItem,
																					  this.downOperationItem});
			this.gridPopup.Popup += new System.EventHandler(this.gridPopup_Popup);
			// 
			// newOperationItem
			// 
			this.newOperationItem.Index = 0;
			this.newOperationItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																							 this.animationOperationItem,
																							 this.talkOperationItem,
																							 this.positionOperationItem});
			this.newOperationItem.Text = "New";
			// 
			// animationOperationItem
			// 
			this.animationOperationItem.Index = 0;
			this.animationOperationItem.Text = "Animation";
			this.animationOperationItem.Click += new System.EventHandler(this.animationOperationItem_Click);
			// 
			// talkOperationItem
			// 
			this.talkOperationItem.Index = 1;
			this.talkOperationItem.Text = "Talk";
			this.talkOperationItem.Click += new System.EventHandler(this.talkOperationItem_Click);
			// 
			// positionOperationItem
			// 
			this.positionOperationItem.Index = 2;
			this.positionOperationItem.Text = "Position";
			this.positionOperationItem.Click += new System.EventHandler(this.positionOperationItem_Click);
			// 
			// editOperationItem
			// 
			this.editOperationItem.Index = 1;
			this.editOperationItem.Text = "Edit";
			this.editOperationItem.Click += new System.EventHandler(this.editOperationItem_Click);
			// 
			// deleteOperationItem
			// 
			this.deleteOperationItem.Index = 2;
			this.deleteOperationItem.Text = "Delete";
			this.deleteOperationItem.Click += new System.EventHandler(this.deleteOperationItem_Click);
			// 
			// menuItem5
			// 
			this.menuItem5.Index = 3;
			this.menuItem5.Text = "-";
			// 
			// upOperationItem
			// 
			this.upOperationItem.Index = 4;
			this.upOperationItem.Text = "Move Up";
			this.upOperationItem.Click += new System.EventHandler(this.upOperationItem_Click);
			// 
			// downOperationItem
			// 
			this.downOperationItem.Index = 5;
			this.downOperationItem.Text = "Move Down";
			this.downOperationItem.Click += new System.EventHandler(this.downOperationItem_Click);
			// 
			// dataGridTableStyle1
			// 
			this.dataGridTableStyle1.AllowSorting = false;
			this.dataGridTableStyle1.DataGrid = this.grid;
			this.dataGridTableStyle1.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
																												  this.dataGridTextBoxColumn1,
																												  this.dataGridTextBoxColumn2});
			this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridTableStyle1.MappingName = "Table";
			this.dataGridTableStyle1.ReadOnly = true;
			// 
			// dataGridTextBoxColumn1
			// 
			this.dataGridTextBoxColumn1.Format = "";
			this.dataGridTextBoxColumn1.FormatInfo = null;
			this.dataGridTextBoxColumn1.HeaderText = "Type";
			this.dataGridTextBoxColumn1.MappingName = "TypeName";
			this.dataGridTextBoxColumn1.Width = 75;
			// 
			// dataGridTextBoxColumn2
			// 
			this.dataGridTextBoxColumn2.Format = "";
			this.dataGridTextBoxColumn2.FormatInfo = null;
			this.dataGridTextBoxColumn2.HeaderText = "Description";
			this.dataGridTextBoxColumn2.MappingName = "Description";
			this.dataGridTextBoxColumn2.Width = 145;
			// 
			// imageList
			// 
			this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.imageList.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
			this.imageList.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// toolBar
			// 
			this.toolBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																					   this.toolSep0,
																					   this.toolNewButton,
																					   this.toolOpenButton,
																					   this.toolSaveButton,
																					   this.toolSep1,
																					   this.toolRunButton,
																					   this.toolSep2,
																					   this.toolDownButton,
																					   this.toolUpButton});
			this.toolBar.ButtonSize = new System.Drawing.Size(24, 23);
			this.toolBar.DropDownArrows = true;
			this.toolBar.ImageList = this.imageList;
			this.toolBar.Name = "toolBar";
			this.toolBar.ShowToolTips = true;
			this.toolBar.Size = new System.Drawing.Size(432, 25);
			this.toolBar.TabIndex = 13;
			this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);
			// 
			// toolSep0
			// 
			this.toolSep0.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// toolNewButton
			// 
			this.toolNewButton.ImageIndex = 0;
			this.toolNewButton.ToolTipText = "New";
			// 
			// toolOpenButton
			// 
			this.toolOpenButton.ImageIndex = 1;
			this.toolOpenButton.ToolTipText = "Open";
			// 
			// toolSaveButton
			// 
			this.toolSaveButton.ImageIndex = 2;
			this.toolSaveButton.ToolTipText = "Save";
			// 
			// toolSep1
			// 
			this.toolSep1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// toolRunButton
			// 
			this.toolRunButton.ImageIndex = 3;
			this.toolRunButton.ToolTipText = "Play";
			// 
			// toolSep2
			// 
			this.toolSep2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// toolDownButton
			// 
			this.toolDownButton.ImageIndex = 5;
			// 
			// toolUpButton
			// 
			this.toolUpButton.ImageIndex = 4;
			// 
			// menuItem1
			// 
			this.menuItem1.Index = -1;
			this.menuItem1.Text = "1";
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(432, 345);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.grid,
																		  this.splitter,
																		  this.tree,
																		  this.toolBar});
			this.Menu = this.mainMenu;
			this.Name = "MainForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Movie Editor";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
			this.Load += new System.EventHandler(this.MainForm_Load);
			((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		#region Static functions
		[STAThread]
		static void Main( string[] args ) 
		{
			MainForm main = new MainForm();
			if( args.Length > 0 ){
				main.workObject = AgentPlayer.LoadFromFile ( args[0] );
				main.BuildTree();
				main.SetFormCaption();
			}
			Application.Run(main);
		}
		#endregion

		#region Private functions
		private void MainForm_Load(object sender, System.EventArgs e)
		{
			this.RefreshMenuItems();
		}

		private void BuildTree()
		{
			this.tree.Nodes.Clear();
			TreeNode parentNode = new TreeNode("Movies");
			this.tree.Nodes.Add( parentNode );
			
			this.BuildMovieNode ( parentNode, "Start",		YariSoft.Utils.AgentPlayer.MovieTypeEnum.Start	);
			this.BuildMovieNode ( parentNode, "Stop",		YariSoft.Utils.AgentPlayer.MovieTypeEnum.Stop	);
			this.BuildMovieNode ( parentNode, "Error",		YariSoft.Utils.AgentPlayer.MovieTypeEnum.Error	);
			this.BuildMovieNode ( parentNode, "Question",	YariSoft.Utils.AgentPlayer.MovieTypeEnum.Question );
			this.BuildMovieNode ( parentNode, "Busy",		YariSoft.Utils.AgentPlayer.MovieTypeEnum.Busy	);
			
			parentNode.Expand();
		}
		
		private void BuildMovieNode( TreeNode ParentNode, string Name, YariSoft.Utils.AgentPlayer.MovieTypeEnum MovieType )
		{
			TreeNode Node = this.BuildNode( ParentNode, Name, MovieType );
			ArrayList MovieCollection = ( ArrayList )this.workObject.Movies[ MovieType ];
			foreach( AgentMovie agentMovie in MovieCollection ){
				this.BuildNode( Node, agentMovie.Name, agentMovie );	
			}
		}

		private TreeNode BuildNode( TreeNode ParentNode, string Name, object ConnectedObject )
		{
			TreeNode childNode	= new TreeNode( Name );
			childNode.Tag		= ConnectedObject;
			ParentNode.Nodes.Add( childNode );
			return childNode;
		}

		private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if( e.Button == this.toolNewButton ){
				this.newMenuItem_Click( this, null );
			} else if( e.Button == this.toolOpenButton ) {
				this.openMenuItem_Click( this, null );
			} else if( e.Button == this.toolSaveButton ) {
				this.saveMenuItem_Click( this, null );
			} else if( e.Button == this.toolRunButton ) {
				this.playActionItem_Click( this, null );
			} else if( e.Button == this.toolDownButton ) {
				if( this.grid.DataSource != null && this.grid.CurrentRowIndex != ((DataTable)this.grid.DataSource).Rows.Count - 1 ){
					this.downOperationItem_Click(this, null);
				}
			} else if( e.Button == this.toolUpButton ) {
				if( this.grid.DataSource != null && this.grid.CurrentRowIndex != 0 ){
					this.upOperationItem_Click(this, null);
				}
			}
		}

		private void exitMenuItem_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void newMenuItem_Click(object sender, System.EventArgs e)
		{
			if( ! this.CheckChanges() ){
				return;
			}
			this.workObject = new AgentPlayer();
			this.BuildTree();
		}

		private void openMenuItem_Click(object sender, System.EventArgs e)
		{
			if( ! this.CheckChanges() ){
				return;
			}

			OpenFileDialog Dialog = new OpenFileDialog();
			Dialog.Filter = "Agent config files(*.amv)|*.amv";
			if( Dialog.ShowDialog() == DialogResult.Cancel ){
				return;
			}
			string fileName = Dialog.FileName;
			Dialog.Dispose();

			this.workObject = AgentPlayer.LoadFromFile ( fileName );
			this.BuildTree();
			this.SetFormCaption();
		}

		private void saveMenuItem_Click(object sender, System.EventArgs e)
		{
			this.workObject.SaveToFile();
		}

		private void saveAsMenuItem_Click(object sender, System.EventArgs e)
		{
			this.workObject.SaveAsToFile();
			this.SetFormCaption();
		}

		private void newActionItem_Click(object sender, System.EventArgs e)
		{
			TreeNode node = this.tree.SelectedNode;
			if( node == null ){
				return;
			}

			if( node.Tag is AgentMovie ){
				node = node.Parent;
			}

			string name = "";
			if( this.EditValue( "Please specify movie name", "Movie name:", ref name ) ){
				AgentMovie agentMovie = new AgentMovie( name );
				YariSoft.Utils.AgentPlayer.MovieTypeEnum movieType = ( YariSoft.Utils.AgentPlayer.MovieTypeEnum )node.Tag;
				ArrayList MovieCollection = ( ArrayList )this.workObject.Movies[ movieType ];
				MovieCollection.Add( agentMovie );
				this.tree.SelectedNode = this.BuildNode( node, name, agentMovie );
				if( !node.IsExpanded ){
					node.Expand();
				}
				this.workObject.HasChanges = true;
			}
		}

		private void renameActionItem_Click(object sender, System.EventArgs e)
		{
			TreeNode node = this.tree.SelectedNode;
			if( node == null ){
				return;
			}

			AgentMovie agentMovie = (AgentMovie)node.Tag;
			if( this.EditValue( "Please specify movie name", "Movie name:", ref agentMovie.Name ) ){
				node.Text = agentMovie.Name;
				this.workObject.HasChanges = true;
			}
		}

		private void deleteAcionItem_Click(object sender, System.EventArgs e)
		{
			TreeNode node = this.tree.SelectedNode;

⌨️ 快捷键说明

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