📄 browsespecialty.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data;
namespace WindowsApplication1
{
/// <summary>
/// zyll 的摘要说明。
/// </summary>
public class BrowseSpecialty : System.Windows.Forms.Form
{
private System.Data.OleDb.OleDbConnection oleDbConnection1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button button3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public BrowseSpecialty()
{
//
// 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()
{
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.button3 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = "Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet." +
"OLEDB.4.0;";
//
// button1
//
this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.ForeColor = System.Drawing.SystemColors.ControlText;
this.button1.Location = new System.Drawing.Point(405, 319);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(86, 31);
this.button1.TabIndex = 2;
this.button1.Text = "退出";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button2.ForeColor = System.Drawing.SystemColors.ControlText;
this.button2.Location = new System.Drawing.Point(75, 319);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(85, 31);
this.button2.TabIndex = 3;
this.button2.Text = "修改";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// dataGrid1
//
this.dataGrid1.AllowSorting = false;
this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Control;
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(11, 21);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.PreferredColumnWidth = 110;
this.dataGrid1.PreferredRowHeight = 30;
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(512, 288);
this.dataGrid1.TabIndex = 4;
//
// button3
//
this.button3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button3.ForeColor = System.Drawing.SystemColors.ControlText;
this.button3.Location = new System.Drawing.Point(235, 319);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(85, 31);
this.button3.TabIndex = 5;
this.button3.Text = "删除";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// BrowseSpecialty
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(533, 356);
this.Controls.Add(this.button3);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "BrowseSpecialty";
this.Text = "专业信息浏览";
this.Load += new System.EventHandler(this.BrowseSpecialtyl_Load);
this.Closed += new System.EventHandler(this.BrowseSpecialty_Closed);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
DataSet ds;
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
public ModifySpecialty modifyspecialty;
private void button2_Click(object sender, System.EventArgs e)
{
if (dataGrid1[dataGrid1.CurrentCell]!=null)
{
modifyspecialty=new ModifySpecialty();
modifyspecialty.Tag=ds.Tables[0].Rows[dataGrid1.CurrentRowIndex][0].ToString().Trim();
modifyspecialty.textBox1.Text=ds.Tables[0].Rows[dataGrid1.CurrentRowIndex][1].ToString().Trim();
modifyspecialty.textBox2.Text=ds.Tables[0].Rows[dataGrid1.CurrentRowIndex][2].ToString().Trim();
modifyspecialty.ShowDialog();
}
}
private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
dataGrid1.CaptionText=dataGrid1[dataGrid1.CurrentRowIndex,1].ToString();
}
private void BrowseSpecialty_Closed(object sender, System.EventArgs e)
{
if(modifyspecialty!=null)
modifyspecialty.Close();
oleDbConnection1.Close();
}
private void button3_Click(object sender, System.EventArgs e)
{
if (dataGrid1[dataGrid1.CurrentCell]!=null)
{
string sql="select specialtyname from specialtyinfo where specialtyid="+ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][0].ToString().Trim()+" and specialtyid not in (select distinct specialtyinfo.specialtyid from classinfo inner join specialtyinfo on classinfo.specialtyname=specialtyinfo.specialtyname)";
OleDbCommand cmd=new OleDbCommand(sql,oleDbConnection1);
OleDbDataReader dr;
dr=cmd.ExecuteReader();
if (!dr.Read())
{
MessageBox.Show("删除专业'"+ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim()+"'失败,请先删除与此专业相关的班级","提示");
dr.Close();
}
else
{
dr.Close();
sql="delete * from specialtyinfo where specialtyname not in (select distinct specialtyname from classinfo) and specialtyid="+ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][0].ToString().Trim();
cmd.CommandText=sql;
cmd.ExecuteNonQuery();
MessageBox.Show("删除专业'"+ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim()+"'成功","提示");
}
}
}
private void BrowseSpecialtyl_Load(object sender, System.EventArgs e)
{
oleDbConnection1.Open();
string sql="select specialtyid as 编号,specialtyname as 专业名称,remark as 专业描述 from specialtyinfo";
OleDbDataAdapter adp=new OleDbDataAdapter(sql,oleDbConnection1);
ds=new DataSet();
adp.Fill(ds,"specialty");
dataGrid1.DataSource=ds.Tables[0].DefaultView;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -