📄 frmbase.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace 教务管理系统
{
/// <summary>
/// frmBase 的摘要说明。
/// </summary>
public class frmBase : System.Windows.Forms.Form
{
internal System.Windows.Forms.ToolBarButton tbbSave;
internal System.Windows.Forms.ToolBarButton tbbDel;
internal System.Windows.Forms.ToolBarButton tbbUndo;
internal System.Windows.Forms.ToolBarButton tbbExit;
public System.Windows.Forms.DataGrid dgdList;
internal System.Windows.Forms.ToolBarButton tbbModify;
internal System.Windows.Forms.ToolBarButton tbbBack;
internal System.Windows.Forms.ToolBarButton tbbFirst;
internal System.Windows.Forms.ToolBarButton tbbForward;
internal System.Windows.Forms.ToolBarButton tbbNew;
internal System.Windows.Forms.ToolBarButton tbbLast;
internal System.Windows.Forms.ImageList ImageList1;
internal System.Windows.Forms.ToolBar ToolBar1;
internal System.Windows.Forms.GroupBox grbSearch;
internal System.Windows.Forms.Label Label3;
internal System.Windows.Forms.TextBox txbThree;
internal System.Windows.Forms.TextBox txbTwo;
internal System.Windows.Forms.Label Label2;
internal System.Windows.Forms.Label Label1;
protected System.Windows.Forms.TextBox txbOne;
internal System.Windows.Forms.Button btnSearch;
internal System.Windows.Forms.Label lblCount;
private System.ComponentModel.IContainer components;
// added
protected BindingManagerBase bmData;
protected DataTable dtData;
protected bool bAdd;
public frmBase()
{
//
// 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.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmBase));
this.tbbSave = new System.Windows.Forms.ToolBarButton();
this.tbbDel = new System.Windows.Forms.ToolBarButton();
this.tbbUndo = new System.Windows.Forms.ToolBarButton();
this.tbbExit = new System.Windows.Forms.ToolBarButton();
this.dgdList = new System.Windows.Forms.DataGrid();
this.tbbModify = new System.Windows.Forms.ToolBarButton();
this.tbbBack = new System.Windows.Forms.ToolBarButton();
this.tbbFirst = new System.Windows.Forms.ToolBarButton();
this.tbbForward = new System.Windows.Forms.ToolBarButton();
this.tbbNew = new System.Windows.Forms.ToolBarButton();
this.tbbLast = new System.Windows.Forms.ToolBarButton();
this.ImageList1 = new System.Windows.Forms.ImageList(this.components);
this.ToolBar1 = new System.Windows.Forms.ToolBar();
this.grbSearch = new System.Windows.Forms.GroupBox();
this.Label3 = new System.Windows.Forms.Label();
this.txbThree = new System.Windows.Forms.TextBox();
this.txbTwo = new System.Windows.Forms.TextBox();
this.Label2 = new System.Windows.Forms.Label();
this.Label1 = new System.Windows.Forms.Label();
this.txbOne = new System.Windows.Forms.TextBox();
this.btnSearch = new System.Windows.Forms.Button();
this.lblCount = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dgdList)).BeginInit();
this.grbSearch.SuspendLayout();
this.SuspendLayout();
//
// tbbSave
//
this.tbbSave.Enabled = false;
this.tbbSave.ImageIndex = 7;
this.tbbSave.Text = "保存";
this.tbbSave.ToolTipText = "保存";
//
// tbbDel
//
this.tbbDel.ImageIndex = 6;
this.tbbDel.Text = "删除";
this.tbbDel.ToolTipText = "删除";
//
// tbbUndo
//
this.tbbUndo.Enabled = false;
this.tbbUndo.ImageIndex = 8;
this.tbbUndo.Text = "取消";
this.tbbUndo.ToolTipText = "取消";
//
// tbbExit
//
this.tbbExit.ImageIndex = 9;
this.tbbExit.Text = "退出";
this.tbbExit.ToolTipText = "退出";
//
// dgdList
//
this.dgdList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dgdList.CaptionVisible = false;
this.dgdList.DataMember = "";
this.dgdList.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dgdList.Location = new System.Drawing.Point(0, 96);
this.dgdList.Name = "dgdList";
this.dgdList.Size = new System.Drawing.Size(603, 144);
this.dgdList.TabIndex = 6;
this.dgdList.CurrentCellChanged += new System.EventHandler(this.dgdList_CurrentCellChanged);
//
// tbbModify
//
this.tbbModify.ImageIndex = 5;
this.tbbModify.Text = "修改";
this.tbbModify.ToolTipText = "修改";
//
// tbbBack
//
this.tbbBack.ImageIndex = 1;
this.tbbBack.Text = "上记录";
this.tbbBack.ToolTipText = "上一条记录";
//
// tbbFirst
//
this.tbbFirst.ImageIndex = 0;
this.tbbFirst.Text = "首记录";
this.tbbFirst.ToolTipText = "首记录";
//
// tbbForward
//
this.tbbForward.ImageIndex = 2;
this.tbbForward.Text = "下记录";
this.tbbForward.ToolTipText = "下一条记录";
//
// tbbNew
//
this.tbbNew.ImageIndex = 4;
this.tbbNew.Text = "新增";
this.tbbNew.ToolTipText = "新增";
//
// tbbLast
//
this.tbbLast.ImageIndex = 3;
this.tbbLast.Text = "尾记录";
this.tbbLast.ToolTipText = "尾记录";
//
// ImageList1
//
this.ImageList1.ImageSize = new System.Drawing.Size(16, 16);
this.ImageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ImageList1.ImageStream")));
this.ImageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// ToolBar1
//
this.ToolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.tbbFirst,
this.tbbBack,
this.tbbForward,
this.tbbLast,
this.tbbNew,
this.tbbModify,
this.tbbDel,
this.tbbSave,
this.tbbUndo,
this.tbbExit});
this.ToolBar1.DropDownArrows = true;
this.ToolBar1.ImageList = this.ImageList1;
this.ToolBar1.Location = new System.Drawing.Point(0, 0);
this.ToolBar1.Name = "ToolBar1";
this.ToolBar1.ShowToolTips = true;
this.ToolBar1.Size = new System.Drawing.Size(600, 41);
this.ToolBar1.TabIndex = 4;
this.ToolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.ToolBar1_ButtonClick);
//
// grbSearch
//
this.grbSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.grbSearch.Controls.Add(this.Label3);
this.grbSearch.Controls.Add(this.txbThree);
this.grbSearch.Controls.Add(this.txbTwo);
this.grbSearch.Controls.Add(this.Label2);
this.grbSearch.Controls.Add(this.Label1);
this.grbSearch.Controls.Add(this.txbOne);
this.grbSearch.Controls.Add(this.btnSearch);
this.grbSearch.Controls.Add(this.lblCount);
this.grbSearch.Location = new System.Drawing.Point(-8, 48);
this.grbSearch.Name = "grbSearch";
this.grbSearch.Size = new System.Drawing.Size(608, 40);
this.grbSearch.TabIndex = 5;
this.grbSearch.TabStop = false;
//
// Label3
//
this.Label3.Location = new System.Drawing.Point(376, 16);
this.Label3.Name = "Label3";
this.Label3.Size = new System.Drawing.Size(56, 15);
this.Label3.TabIndex = 6;
this.Label3.Text = "班级名称";
//
// txbThree
//
this.txbThree.Location = new System.Drawing.Point(432, 11);
this.txbThree.Name = "txbThree";
this.txbThree.Size = new System.Drawing.Size(56, 21);
this.txbThree.TabIndex = 5;
this.txbThree.Text = "";
//
// txbTwo
//
this.txbTwo.Location = new System.Drawing.Point(312, 11);
this.txbTwo.Name = "txbTwo";
this.txbTwo.Size = new System.Drawing.Size(56, 21);
this.txbTwo.TabIndex = 4;
this.txbTwo.Text = "";
//
// Label2
//
this.Label2.Location = new System.Drawing.Point(256, 16);
this.Label2.Name = "Label2";
this.Label2.Size = new System.Drawing.Size(56, 15);
this.Label2.TabIndex = 3;
this.Label2.Text = " 年级";
//
// Label1
//
this.Label1.Location = new System.Drawing.Point(88, 16);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(56, 15);
this.Label1.TabIndex = 2;
this.Label1.Text = "班级编号";
//
// txbOne
//
this.txbOne.Location = new System.Drawing.Point(144, 11);
this.txbOne.Name = "txbOne";
this.txbOne.Size = new System.Drawing.Size(112, 21);
this.txbOne.TabIndex = 1;
this.txbOne.Text = "";
//
// btnSearch
//
this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnSearch.Location = new System.Drawing.Point(16, 12);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(64, 22);
this.btnSearch.TabIndex = 0;
this.btnSearch.Text = " 搜索";
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// lblCount
//
this.lblCount.Location = new System.Drawing.Point(488, 15);
this.lblCount.Name = "lblCount";
this.lblCount.Size = new System.Drawing.Size(104, 12);
this.lblCount.TabIndex = 4;
//
// frmBase
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(600, 341);
this.Controls.Add(this.ToolBar1);
this.Controls.Add(this.grbSearch);
this.Controls.Add(this.dgdList);
this.Name = "frmBase";
this.Text = "frmBase";
this.Load += new System.EventHandler(this.frmBase_Load);
((System.ComponentModel.ISupportInitialize)(this.dgdList)).EndInit();
this.grbSearch.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void btnSearch_Click(object sender, System.EventArgs e)
{
SearchResult();
}
private void ToolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch ( e.Button.Text )
{
case "首记录" :
bmData.Position = 0;
break;
case "上记录" :
if ( bmData.Position != 0 )
{
bmData.Position -= 1;
}
break;
case "下记录" :
if ( bmData.Position != bmData.Count )
bmData.Position += 1;
break;
case "尾记录" :
bmData.Position = bmData.Count;
break;
case "新增" :
dgdList.Enabled = false;
SetTextBoxState( false );
SetToolBarState( false );
bAdd = true;
Clear();
break;
case "修改" :
dgdList.Enabled = false;
SetTextBoxState( false );
SetToolBarState( false );
bAdd = false;
Clear();
break;
case "删除" :
DialogResult dlgResult = MessageBox.Show( "你确认删除此数据", "删除", MessageBoxButtons.OKCancel );
if ( dlgResult == DialogResult.OK )
DeleteData();
break;
case "保存" :
SetToolBarState( true );
SetTextBoxState( true );
if ( bAdd )
SaveForAdd();
else
SaveForUpdate();
dgdList.Enabled = true;
break;
case "取消" :
SetTextBoxState( true );
SetToolBarState( true );
dgdList.Enabled = true;
SearchResult();
break;
case "退出" :
this.Close();
break;
}
try
{
dgdList.CurrentRowIndex = bmData.Position;
SetData();
}
catch ( Exception ex )
{
MessageBox.Show( ex.ToString() );
}
}
private void SetToolBarState( bool bState )
{
// 设置Button的是否能够单击
ToolBar1.Buttons[ 0 ].Enabled = bState;
ToolBar1.Buttons[ 1 ].Enabled = bState;
ToolBar1.Buttons[ 2 ].Enabled = bState;
ToolBar1.Buttons[ 3 ].Enabled = bState;
ToolBar1.Buttons[ 4 ].Enabled = bState;
ToolBar1.Buttons[ 5 ].Enabled = bState;
ToolBar1.Buttons[ 6 ].Enabled = bState;
ToolBar1.Buttons[ 7 ].Enabled = !bState;
ToolBar1.Buttons[ 8 ].Enabled = !bState;
}
public virtual void Prepare()
{}
public virtual void SetDataGrid()
{ }
public virtual void SearchResult()
{ }
public virtual void LoadData()
{ }
public virtual void SaveForAdd()
{ }
public virtual void SaveForUpdate()
{ }
public virtual void DeleteData()
{ }
public virtual void Clear()
{ }
public virtual void SetTextBoxState( bool bState )
{ }
public virtual void SetData()
{ }
private void frmBase_Load(object sender, System.EventArgs e)
{
Prepare();
SetDataGrid();
SetTextBoxState( true );
}
private void dgdList_CurrentCellChanged(object sender, System.EventArgs e)
{
try
{
if ( bmData == null )
{ return; }
if ( bmData.Position != dgdList.CurrentCell.RowNumber )
{
bmData.Position = dgdList.CurrentCell.RowNumber;
SetData();
}
}
catch ( Exception ex )
{
MessageBox.Show( ex.ToString() );
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -