📄 prjeditspec.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace prjClass
{
/// <summary>
/// prjEditSpec 的摘要说明。
/// </summary>
public class prjEditSpec : System.Windows.Forms.Form
{
private Class1 c = new Class1();
private bool flag = true;
private Specialty sp = new Specialty();
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnUpdate;
private System.Windows.Forms.Button btnDel;
private System.Windows.Forms.Button btnCancle;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public prjEditSpec()
{
//
// 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.dataGrid1 = new System.Windows.Forms.DataGrid();
this.panel1 = new System.Windows.Forms.Panel();
this.btnCancle = new System.Windows.Forms.Button();
this.btnDel = new System.Windows.Forms.Button();
this.btnUpdate = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 0);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(592, 365);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.GotFocus += new System.EventHandler(this.dataGrid1_GotFocus);
this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
//
// panel1
//
this.panel1.Controls.Add(this.btnCancle);
this.panel1.Controls.Add(this.btnDel);
this.panel1.Controls.Add(this.btnUpdate);
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel1.Location = new System.Drawing.Point(0, 293);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(592, 72);
this.panel1.TabIndex = 1;
//
// btnCancle
//
this.btnCancle.Location = new System.Drawing.Point(424, 24);
this.btnCancle.Name = "btnCancle";
this.btnCancle.TabIndex = 2;
this.btnCancle.Text = "取消";
this.btnCancle.Click += new System.EventHandler(this.btnCancle_Click);
//
// btnDel
//
this.btnDel.Location = new System.Drawing.Point(248, 24);
this.btnDel.Name = "btnDel";
this.btnDel.TabIndex = 1;
this.btnDel.Text = "删除";
this.btnDel.Click += new System.EventHandler(this.btnDel_Click);
//
// btnUpdate
//
this.btnUpdate.Location = new System.Drawing.Point(64, 24);
this.btnUpdate.Name = "btnUpdate";
this.btnUpdate.TabIndex = 0;
this.btnUpdate.Text = "修改";
this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
//
// prjEditSpec
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(592, 365);
this.Controls.Add(this.panel1);
this.Controls.Add(this.dataGrid1);
this.Name = "prjEditSpec";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "专业信息浏览";
this.Load += new System.EventHandler(this.prjEditSpec_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void prjEditSpec_Load(object sender, System.EventArgs e)
{
SetBookTableStyle();
LoadData();
}
private void LoadData()
{
DataAccess da = new DataAccess();
string Sql = "select * from Class..SpecialtyInfo";
string TableName = "SpecialtyInfo";
DataTable dt = da.ExecuteDataTable(Sql,TableName);
this.dataGrid1.DataSource=dt;
if(c.IsExits(Sql)==false)
{
this.flag=false;
}
}
/// <summary>
/// Lend表的DataGrid样式设定
/// </summary>
private void SetBookTableStyle()
{
DataGridTableStyle dgs = new DataGridTableStyle();
dgs.MappingName = "SpecialtyInfo";
this.dataGrid1.TableStyles.Add(dgs);
DataGridColumnStyle dgs1 = new DataGridTextBoxColumn();
dgs1.HeaderText="编号";
dgs1.MappingName="SpecialtyId";
dgs1.Width=100;
DataGridColumnStyle dgs2 = new DataGridTextBoxColumn();
dgs2.HeaderText="专业名称";
dgs2.MappingName="SpecialtyName";
dgs2.Width=100;
DataGridColumnStyle dgs3 = new DataGridTextBoxColumn();
dgs3.HeaderText="专业描述";
dgs3.MappingName="Memo";
dgs3.Width=350;
dgs.GridColumnStyles.Add(dgs1);
dgs.GridColumnStyles.Add(dgs2);
dgs.GridColumnStyles.Add(dgs3);
}
private void btnCancle_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnDel_Click(object sender, System.EventArgs e)
{
string Sql = "select * from Class..ClassInfo where SpecialtyName = '"+this.dataGrid1.CaptionText+"'";
if(this.dataGrid1.CaptionText=="")
{
MessageBox.Show("请选择要删除的专业?","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else if(c.IsExits(Sql)==true)
{
MessageBox.Show("请先删除与此专业相关的班级?","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else
{
if(MessageBox.Show("确认删除此专业?","提示信息!",MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2)==DialogResult.OK)
{
string Sql1 = "delete from Class..SpecialtyInfo where SpecialtyName = '"+this.dataGrid1.CaptionText+"'";
c.EditData(Sql1);
LoadData();
}
}
}
private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
{
if(this.flag==true)
{
this.dataGrid1.CaptionText=this.dataGrid1[this.dataGrid1.CurrentRowIndex,1].ToString();
this.sp.ID=this.dataGrid1[this.dataGrid1.CurrentRowIndex,0].ToString();
this.sp.Name=this.dataGrid1[this.dataGrid1.CurrentRowIndex,1].ToString();
this.sp.Memo=this.dataGrid1[this.dataGrid1.CurrentRowIndex,2].ToString();
}
}
private void dataGrid1_GotFocus(object sender, EventArgs e)
{
if(this.flag==true)
{
this.dataGrid1.CaptionText=this.dataGrid1[this.dataGrid1.CurrentRowIndex,1].ToString();
this.sp.ID=this.dataGrid1[this.dataGrid1.CurrentRowIndex,0].ToString();
this.sp.Name=this.dataGrid1[this.dataGrid1.CurrentRowIndex,1].ToString();
this.sp.Memo=this.dataGrid1[this.dataGrid1.CurrentRowIndex,2].ToString();
}
}
private void btnUpdate_Click(object sender, System.EventArgs e)
{
if(this.dataGrid1.CaptionText=="")
{
MessageBox.Show("请选择要修改的专业?","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else
{
frmUpdateSpc f = new frmUpdateSpc(this.sp);
f.UpdateSpeEvent+=new UpdatSpeHandler(f_UpdateSpeEvent);
f.ShowDialog();
}
}
private void f_UpdateSpeEvent()
{
LoadData();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -