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

📄 frmtablewizard.cs

📁 北大青鸟内部资料
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Example_1
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class frmTableWizard : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblSampleTables;
		private System.Windows.Forms.Label lblSampleFields;
		private System.Windows.Forms.Label lblNewFields;
		private System.Windows.Forms.ComboBox cboSampleTables;
		private System.Windows.Forms.ListBox lstNewFields;
		private System.Windows.Forms.ListBox lstSampleFields;
		private System.Windows.Forms.Button btnAdd;
		private System.Windows.Forms.Button btnAddAll;
		private System.Windows.Forms.Button btnRemove;
		private System.Windows.Forms.Button btnRemoveAll;
		private System.Windows.Forms.Button btnRename;
		private System.Windows.Forms.Button btnCancel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public static string renameFieldValue="";

		public frmTableWizard()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.lblSampleTables = new System.Windows.Forms.Label();
			this.lblSampleFields = new System.Windows.Forms.Label();
			this.lblNewFields = new System.Windows.Forms.Label();
			this.cboSampleTables = new System.Windows.Forms.ComboBox();
			this.lstNewFields = new System.Windows.Forms.ListBox();
			this.lstSampleFields = new System.Windows.Forms.ListBox();
			this.btnAdd = new System.Windows.Forms.Button();
			this.btnAddAll = new System.Windows.Forms.Button();
			this.btnRemove = new System.Windows.Forms.Button();
			this.btnRemoveAll = new System.Windows.Forms.Button();
			this.btnRename = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// lblSampleTables
			// 
			this.lblSampleTables.Location = new System.Drawing.Point(8, 16);
			this.lblSampleTables.Name = "lblSampleTables";
			this.lblSampleTables.Size = new System.Drawing.Size(88, 23);
			this.lblSampleTables.TabIndex = 0;
			this.lblSampleTables.Text = " 示例表:";
			// 
			// lblSampleFields
			// 
			this.lblSampleFields.Location = new System.Drawing.Point(136, 16);
			this.lblSampleFields.Name = "lblSampleFields";
			this.lblSampleFields.Size = new System.Drawing.Size(88, 23);
			this.lblSampleFields.TabIndex = 1;
			this.lblSampleFields.Text = "示例字段:";
			// 
			// lblNewFields
			// 
			this.lblNewFields.Location = new System.Drawing.Point(304, 16);
			this.lblNewFields.Name = "lblNewFields";
			this.lblNewFields.Size = new System.Drawing.Size(120, 23);
			this.lblNewFields.TabIndex = 1;
			this.lblNewFields.Text = " 新表中的字段:";
			// 
			// cboSampleTables
			// 
			this.cboSampleTables.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboSampleTables.Items.AddRange(new object[] {
																 "客户",
																 "职员",
																 "产品"});
			this.cboSampleTables.Location = new System.Drawing.Point(8, 40);
			this.cboSampleTables.Name = "cboSampleTables";
			this.cboSampleTables.TabIndex = 2;
			this.cboSampleTables.SelectedIndexChanged += new System.EventHandler(this.cboSampleTables_SelectedIndexChanged);
			// 
			// lstNewFields
			// 
			this.lstNewFields.DisplayMember = "0";
			this.lstNewFields.Location = new System.Drawing.Point(304, 40);
			this.lstNewFields.Name = "lstNewFields";
			this.lstNewFields.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
			this.lstNewFields.Size = new System.Drawing.Size(120, 121);
			this.lstNewFields.TabIndex = 3;
			// 
			// lstSampleFields
			// 
			this.lstSampleFields.Location = new System.Drawing.Point(136, 40);
			this.lstSampleFields.Name = "lstSampleFields";
			this.lstSampleFields.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
			this.lstSampleFields.Size = new System.Drawing.Size(120, 121);
			this.lstSampleFields.TabIndex = 4;
			// 
			// btnAdd
			// 
			this.btnAdd.Location = new System.Drawing.Point(264, 40);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new System.Drawing.Size(32, 23);
			this.btnAdd.TabIndex = 5;
			this.btnAdd.Text = ">";
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
			// 
			// btnAddAll
			// 
			this.btnAddAll.Location = new System.Drawing.Point(264, 72);
			this.btnAddAll.Name = "btnAddAll";
			this.btnAddAll.Size = new System.Drawing.Size(32, 23);
			this.btnAddAll.TabIndex = 5;
			this.btnAddAll.Text = ">>";
			this.btnAddAll.Click += new System.EventHandler(this.btnAddAll_Click);
			// 
			// btnRemove
			// 
			this.btnRemove.Location = new System.Drawing.Point(264, 104);
			this.btnRemove.Name = "btnRemove";
			this.btnRemove.Size = new System.Drawing.Size(32, 23);
			this.btnRemove.TabIndex = 5;
			this.btnRemove.Text = "<";
			this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
			// 
			// btnRemoveAll
			// 
			this.btnRemoveAll.Location = new System.Drawing.Point(264, 136);
			this.btnRemoveAll.Name = "btnRemoveAll";
			this.btnRemoveAll.Size = new System.Drawing.Size(32, 23);
			this.btnRemoveAll.TabIndex = 5;
			this.btnRemoveAll.Text = "<<";
			this.btnRemoveAll.Click += new System.EventHandler(this.btnRemoveAll_Click);
			// 
			// btnRename
			// 
			this.btnRename.Enabled = false;
			this.btnRename.Location = new System.Drawing.Point(320, 168);
			this.btnRename.Name = "btnRename";
			this.btnRename.Size = new System.Drawing.Size(104, 23);
			this.btnRename.TabIndex = 6;
			this.btnRename.Text = "重命名字段(&R)...";
			this.btnRename.Click += new System.EventHandler(this.btnRename_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(216, 168);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(96, 23);
			this.btnCancel.TabIndex = 6;
			this.btnCancel.Text = "取消(&C)";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// frmTableWizard
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.ClientSize = new System.Drawing.Size(440, 205);
			this.Controls.Add(this.btnRename);
			this.Controls.Add(this.btnAdd);
			this.Controls.Add(this.lstSampleFields);
			this.Controls.Add(this.lstNewFields);
			this.Controls.Add(this.cboSampleTables);
			this.Controls.Add(this.lblSampleFields);
			this.Controls.Add(this.lblSampleTables);
			this.Controls.Add(this.lblNewFields);
			this.Controls.Add(this.btnAddAll);
			this.Controls.Add(this.btnRemove);
			this.Controls.Add(this.btnRemoveAll);
			this.Controls.Add(this.btnCancel);
			this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Name = "frmTableWizard";
			this.Text = "表向导";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmTableWizard());
		}

		private void cboSampleTables_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.lstSampleFields.Items.Clear();
			this.lstNewFields.Items.Clear();
			if(String.Compare(this.cboSampleTables.SelectedItem.ToString(),"客户")==0)
			{
				string[] custFields = {"客户标识","公司名称","城市","邮政编码"};

				for(int count = 0 ;count < custFields.Length;count++)
				{
					this.lstSampleFields.Items.Add(custFields[count]);
				}
				
			}
		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			for(int count = 0; count < this.lstSampleFields.SelectedItems.Count;count++)					{
				this.lstNewFields.Items.Add(this.lstSampleFields.SelectedItems[count]);
			}
			this.btnRename.Enabled = true;
			this.lstNewFields.SelectedIndex = 0;
		}

		private void btnAddAll_Click(object sender, System.EventArgs e)
		{
			for(int count = 0; count <this.lstSampleFields.Items.Count;count++)			
			{
				this.lstNewFields.Items.Add(this.lstSampleFields.Items[count]);
			}
			this.btnRename.Enabled = true;
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			if(MessageBox.Show("是否要退出此应用程序? ","退出",MessageBoxButtons.YesNo)==DialogResult.Yes)
			{
				this.Close();
			}
		}

		private void btnRemove_Click(object sender, System.EventArgs e)
		{
			this.lstNewFields.Items.Remove(this.lstNewFields.SelectedItem);
			this.RenameEnableDisable();
		}

		private void btnRemoveAll_Click(object sender, System.EventArgs e)
		{
			this.lstNewFields.Items.Clear();
			this.btnRename.Enabled = false;
		}

		private void btnRename_Click(object sender, System.EventArgs e)
		{
			frmRenameField objRenameField = new frmRenameField(this.lstNewFields.SelectedItem.ToString());
			objRenameField.ShowDialog();
			int a = this.lstNewFields.SelectedIndex;
			this.lstNewFields.Items.RemoveAt(this.lstNewFields.SelectedIndex);
			this.lstNewFields.Items.Insert(a,renameFieldValue);
			this.lstNewFields.SelectedIndex = 0;
		}

		private void RenameEnableDisable()
		{
			if(lstNewFields.Items.Count > 0)
			{
				this.btnRename.Enabled = true;
			}
			else
			{
				this.btnRename.Enabled = false;
			}
		}

	}
}

⌨️ 快捷键说明

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