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

📄 selectinfos.cs

📁 聊天系统的经
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;


namespace 学生信息管理
{
	/// <summary>
	/// SelectInfos 的摘要说明。
	/// </summary>
	public class SelectInfos : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ComboBox cboTitle;
		private System.Windows.Forms.Label lblSelectTitle;
		private System.Windows.Forms.ComboBox cboEques;
		private System.Windows.Forms.ComboBox cboInsert;
		private System.Windows.Forms.Button btnSaveSelect;
		private System.Windows.Forms.LinkLabel linlblSelect;
		private System.Windows.Forms.ComboBox cboYiyouSelect;
		private System.Windows.Forms.Button btnYiyouSelect;
		private System.Windows.Forms.Button btnSelect;
		private System.Windows.Forms.Button btnExit;

		private bool flag = true;
		private DataSet ds = null;
		private OleDbDataAdapter adapter = null;
		private DBManagers db = new DBManagers();
		private String sql = string.Empty;			 //保存的sql语句
		
		private System.Windows.Forms.Label lblselectname;
		private System.Windows.Forms.GroupBox groupBox1;

		
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public SelectInfos()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SelectInfos));
			this.cboTitle = new System.Windows.Forms.ComboBox();
			this.lblSelectTitle = new System.Windows.Forms.Label();
			this.cboEques = new System.Windows.Forms.ComboBox();
			this.cboInsert = new System.Windows.Forms.ComboBox();
			this.btnSaveSelect = new System.Windows.Forms.Button();
			this.linlblSelect = new System.Windows.Forms.LinkLabel();
			this.lblselectname = new System.Windows.Forms.Label();
			this.cboYiyouSelect = new System.Windows.Forms.ComboBox();
			this.btnYiyouSelect = new System.Windows.Forms.Button();
			this.btnSelect = new System.Windows.Forms.Button();
			this.btnExit = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.SuspendLayout();
			// 
			// cboTitle
			// 
			this.cboTitle.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboTitle.Items.AddRange(new object[] {
														  "学号",
														  "姓名",
														  "身份证号码",
														  "民族",
														  "最高学历",
														  "籍贯",
														  "爱好",
														  "特长"});
			this.cboTitle.Location = new System.Drawing.Point(52, 20);
			this.cboTitle.Name = "cboTitle";
			this.cboTitle.Size = new System.Drawing.Size(156, 20);
			this.cboTitle.TabIndex = 0;
			this.cboTitle.SelectedIndexChanged += new System.EventHandler(this.cboTitle_SelectedIndexChanged);
			// 
			// lblSelectTitle
			// 
			this.lblSelectTitle.Location = new System.Drawing.Point(16, 24);
			this.lblSelectTitle.Name = "lblSelectTitle";
			this.lblSelectTitle.Size = new System.Drawing.Size(40, 16);
			this.lblSelectTitle.TabIndex = 1;
			this.lblSelectTitle.Text = "选择:";
			// 
			// cboEques
			// 
			this.cboEques.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboEques.Items.AddRange(new object[] {
														  "等于",
														  "模糊"});
			this.cboEques.Location = new System.Drawing.Point(216, 20);
			this.cboEques.Name = "cboEques";
			this.cboEques.Size = new System.Drawing.Size(104, 20);
			this.cboEques.TabIndex = 2;
			// 
			// cboInsert
			// 
			this.cboInsert.Location = new System.Drawing.Point(328, 20);
			this.cboInsert.Name = "cboInsert";
			this.cboInsert.Size = new System.Drawing.Size(156, 20);
			this.cboInsert.TabIndex = 3;
			this.cboInsert.Click += new System.EventHandler(this.cboInsert_Click);
			// 
			// btnSaveSelect
			// 
			this.btnSaveSelect.Enabled = false;
			this.btnSaveSelect.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.btnSaveSelect.Location = new System.Drawing.Point(216, 64);
			this.btnSaveSelect.Name = "btnSaveSelect";
			this.btnSaveSelect.Size = new System.Drawing.Size(112, 40);
			this.btnSaveSelect.TabIndex = 5;
			this.btnSaveSelect.Text = "保存查询结果";
			this.btnSaveSelect.Click += new System.EventHandler(this.btnSaveSelect_Click);
			// 
			// linlblSelect
			// 
			this.linlblSelect.Location = new System.Drawing.Point(16, 88);
			this.linlblSelect.Name = "linlblSelect";
			this.linlblSelect.Size = new System.Drawing.Size(72, 16);
			this.linlblSelect.TabIndex = 6;
			this.linlblSelect.TabStop = true;
			this.linlblSelect.Text = "以前的查询";
			this.linlblSelect.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linlblSelect_LinkClicked);
			// 
			// lblselectname
			// 
			this.lblselectname.Location = new System.Drawing.Point(16, 128);
			this.lblselectname.Name = "lblselectname";
			this.lblselectname.Size = new System.Drawing.Size(72, 16);
			this.lblselectname.TabIndex = 7;
			this.lblselectname.Text = "选择查询名:";
			// 
			// cboYiyouSelect
			// 
			this.cboYiyouSelect.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboYiyouSelect.Location = new System.Drawing.Point(88, 124);
			this.cboYiyouSelect.Name = "cboYiyouSelect";
			this.cboYiyouSelect.Size = new System.Drawing.Size(392, 20);
			this.cboYiyouSelect.TabIndex = 8;
			this.cboYiyouSelect.SelectedIndexChanged += new System.EventHandler(this.cboYiyouSelect_SelectedIndexChanged);
			// 
			// btnYiyouSelect
			// 
			this.btnYiyouSelect.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.btnYiyouSelect.Location = new System.Drawing.Point(126, 160);
			this.btnYiyouSelect.Name = "btnYiyouSelect";
			this.btnYiyouSelect.Size = new System.Drawing.Size(72, 32);
			this.btnYiyouSelect.TabIndex = 9;
			this.btnYiyouSelect.Text = "查看";
			this.btnYiyouSelect.Click += new System.EventHandler(this.btnYiyouSelect_Click);
			// 
			// btnSelect
			// 
			this.btnSelect.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.btnSelect.Location = new System.Drawing.Point(126, 64);
			this.btnSelect.Name = "btnSelect";
			this.btnSelect.Size = new System.Drawing.Size(72, 40);
			this.btnSelect.TabIndex = 4;
			this.btnSelect.Text = "查询";
			this.btnSelect.Click += new System.EventHandler(this.btnSelect_Click);
			// 
			// btnExit
			// 
			this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.btnExit.Location = new System.Drawing.Point(346, 64);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(72, 40);
			this.btnExit.TabIndex = 10;
			this.btnExit.Text = "退出";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Location = new System.Drawing.Point(0, 108);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(496, 8);
			this.groupBox1.TabIndex = 11;
			this.groupBox1.TabStop = false;
			// 
			// SelectInfos
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(490, 117);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.btnYiyouSelect);
			this.Controls.Add(this.cboYiyouSelect);
			this.Controls.Add(this.lblselectname);
			this.Controls.Add(this.btnSelect);
			this.Controls.Add(this.linlblSelect);
			this.Controls.Add(this.btnSaveSelect);
			this.Controls.Add(this.cboInsert);
			this.Controls.Add(this.cboEques);
			this.Controls.Add(this.cboTitle);
			this.Controls.Add(this.lblSelectTitle);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "SelectInfos";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "自定义查询";
			this.Load += new System.EventHandler(this.SelectInfos_Load);
			this.ResumeLayout(false);

		}
		#endregion


		//单击打开
		private void cboInsert_Click(object sender, System.EventArgs e)
		{	
			
		}

		//保存查询结果
		private void btnSaveSelect_Click(object sender, System.EventArgs e)
		{
			InsertSQLName isqlform = new InsertSQLName();
			if(isqlform.ShowDialog() == DialogResult.OK)
			{
				//连接数据库
				db.Server = "Microsoft.Jet.OLEDB.4.0";
				db.Database = FormMain.path+"\\StuInfoMgr.mdb";
			

				db.createConn();
				db.openConn();

				sql = this.sql.Replace("'","\\");

				OleDbCommand cmd = new OleDbCommand("insert into selector(Sel_Name,Sel_Content) values('"+isqlform.SqlName.Text.ToString()+"','"+sql+"')",db.Conn);
				
				try
				{
					int num = cmd.ExecuteNonQuery();

					if(num == -1)
					{
						MessageBox.Show("保存失败,请重新保存!");
					}
					else
					{
						MessageBox.Show("保存成功了!");
					}
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.Message);
					Console.WriteLine(ex);
				}
				finally
				{
					db.closeConn();
					SelectInfos_Load(sender,e);
				}
			}


		}

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

		//初始化信息
		private void SelectInfos_Load(object sender, System.EventArgs e)
		{

			this.cboTitle.SelectedIndex = 0;
			this.cboEques.SelectedIndex = 0;
			//连接数据库
			db.Server = "Microsoft.Jet.OLEDB.4.0";
			db.Database = FormMain.path+"\\StuInfoMgr.mdb";
			

			db.createConn();
			db.openConn();

			try
			{
				this.ds = new DataSet("Stu");
				this.adapter = new OleDbDataAdapter();
				this.adapter.SelectCommand = new OleDbCommand("select Sel_Name from selector",db.Conn);

				this.adapter.Fill(this.ds,"selector");

				this.cboYiyouSelect.DataSource = this.ds.Tables["selector"].DefaultView;
				this.cboYiyouSelect.DisplayMember = "Sel_Name";
				//this.cboYiyouSelect.ValueMember = "Sel_Content";	
				
				
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
				Console.WriteLine(ex);
			}

			
			
		}

⌨️ 快捷键说明

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