📄 frmminzu.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace 毕业生信息管理系统
{
/// <summary>
/// frmMinZu 的摘要说明。
/// </summary>
public class frmMinZu : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.LinkLabel linkLabel1;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnDel;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private OleDbDataAdapter objDataAdapter;
private OleDbConnection objSqlConn;
private DataSet objDataSet2;
private OleDbCommand objOleDbCommand;
public frmMinZu()
{
//
// 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(frmMinZu));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.btnExit = new System.Windows.Forms.Button();
this.btnDel = new System.Windows.Forms.Button();
this.btnAdd = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.groupBox1.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.BackColor = System.Drawing.Color.PaleTurquoise;
this.groupBox1.Controls.Add(this.groupBox3);
this.groupBox1.Controls.Add(this.btnExit);
this.groupBox1.Controls.Add(this.btnDel);
this.groupBox1.Controls.Add(this.btnAdd);
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.listBox1);
this.groupBox1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.groupBox1.Location = new System.Drawing.Point(8, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(264, 312);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "民族类别设置";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.linkLabel1);
this.groupBox3.Location = new System.Drawing.Point(168, 112);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(88, 136);
this.groupBox3.TabIndex = 5;
this.groupBox3.TabStop = false;
//
// linkLabel1
//
this.linkLabel1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.linkLabel1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
this.linkLabel1.LinkColor = System.Drawing.Color.Blue;
this.linkLabel1.Location = new System.Drawing.Point(16, 16);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(64, 111);
this.linkLabel1.TabIndex = 0;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "选择列表框中的条目然后点击删除按钮即可删除选中的条目!";
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(168, 272);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(88, 24);
this.btnExit.TabIndex = 4;
this.btnExit.Text = "退出";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnDel
//
this.btnDel.ForeColor = System.Drawing.Color.Magenta;
this.btnDel.Location = new System.Drawing.Point(168, 64);
this.btnDel.Name = "btnDel";
this.btnDel.Size = new System.Drawing.Size(88, 24);
this.btnDel.TabIndex = 3;
this.btnDel.Text = "删除";
this.btnDel.Click += new System.EventHandler(this.btnDel_Click);
//
// btnAdd
//
this.btnAdd.ForeColor = System.Drawing.Color.Magenta;
this.btnAdd.Location = new System.Drawing.Point(168, 24);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(88, 24);
this.btnAdd.TabIndex = 2;
this.btnAdd.Text = "增加";
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.textBox1);
this.groupBox2.ForeColor = System.Drawing.Color.Magenta;
this.groupBox2.Location = new System.Drawing.Point(8, 248);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(144, 56);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "请输入你要添加的条目";
//
// textBox1
//
this.textBox1.BackColor = System.Drawing.SystemColors.Info;
this.textBox1.Location = new System.Drawing.Point(8, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(128, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// listBox1
//
this.listBox1.BackColor = System.Drawing.SystemColors.Info;
this.listBox1.ForeColor = System.Drawing.Color.Blue;
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(8, 17);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(144, 220);
this.listBox1.TabIndex = 0;
//
// frmMinZu
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.PaleTurquoise;
this.ClientSize = new System.Drawing.Size(280, 336);
this.Controls.Add(this.groupBox1);
this.ForeColor = System.Drawing.Color.Red;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximumSize = new System.Drawing.Size(288, 368);
this.MinimumSize = new System.Drawing.Size(288, 368);
this.Name = "frmMinZu";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "民族类别设置";
this.Load += new System.EventHandler(this.frmMinZu_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void frmMinZu_Load(object sender, System.EventArgs e)
{
string strConnection="Provider=Microsoft.Jet.OLEDB.4.0;";
strConnection+=@"Data Source=Student.mdb";
objSqlConn=new OleDbConnection(strConnection);
objSqlConn.Open();
objDataSet2=new DataSet();
objDataAdapter=new OleDbDataAdapter("select * from MinZu",objSqlConn);
objDataAdapter.Fill(objDataSet2,"MinZu");
foreach(DataRow objRow in objDataSet2.Tables["MinZu"].Rows)
{
this.listBox1.Items.Add(objRow["民族"]);
}
objSqlConn.Close();
user myUser = user.InitUser();
if(myUser.isPublicUser == false)
{
this.btnAdd.Enabled=false;
this.btnDel.Enabled=false;
}
else//if(myUser.isPublicUser==true)
{
this.btnAdd.Enabled=true;
this.btnDel.Enabled=true;
//this.textBox1.ReadOnly=false;
}
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
if(this.textBox1.Text!=String.Empty)
{
string insCmd="insert into MinZu values('"+this.textBox1.Text+"')";
objOleDbCommand=new OleDbCommand(insCmd,this.objSqlConn);
try
{
this.objSqlConn.Open();
objOleDbCommand.ExecuteNonQuery();
objSqlConn.Close();
listBox1.Items.Add(this.textBox1.Text);
this.textBox1.Clear();
}
catch(OleDbException ex)
{
MessageBox.Show(ex.Message);
objSqlConn.Close();
}
}
else
{
MessageBox.Show("不能为空!请填写完整!");
this.textBox1.Focus();
}
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnDel_Click(object sender, System.EventArgs e)
{
string delCmd="delete from MinZu where 民族='"+this.listBox1.SelectedItem+"'";
objOleDbCommand=new OleDbCommand(delCmd,objSqlConn);
try
{
objSqlConn.Open();
this.objOleDbCommand.ExecuteNonQuery();
objSqlConn.Close();
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
}
catch(OleDbException ex)
{
MessageBox.Show(ex.Message);
objSqlConn.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -