📄 frmaddclass.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data ;
using Aptech.Student.DataAccess;
using Aptech.Student.Common;
namespace 学生管理系统
{
/// <summary>
/// frmAddClass 的摘要说明。
/// </summary>
public class frmAddClass : System.Windows.Forms.Form
{
frmMain frm;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.TextBox txtRemark;
private System.Windows.Forms.TextBox txtClassName;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.DateTimePicker dateTimePicker1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public frmAddClass(frmMain frm)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.frm =frm;
//
// 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.btnExit = new System.Windows.Forms.Button();
this.btnAdd = new System.Windows.Forms.Button();
this.txtRemark = new System.Windows.Forms.TextBox();
this.txtClassName = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(192, 240);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(94, 32);
this.btnExit.TabIndex = 15;
this.btnExit.Text = "关闭";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnAdd
//
this.btnAdd.Location = new System.Drawing.Point(64, 240);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(87, 32);
this.btnAdd.TabIndex = 14;
this.btnAdd.Text = "建立";
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// txtRemark
//
this.txtRemark.Location = new System.Drawing.Point(160, 128);
this.txtRemark.Multiline = true;
this.txtRemark.Name = "txtRemark";
this.txtRemark.Size = new System.Drawing.Size(160, 88);
this.txtRemark.TabIndex = 13;
this.txtRemark.Text = "";
//
// txtClassName
//
this.txtClassName.Location = new System.Drawing.Point(160, 8);
this.txtClassName.Name = "txtClassName";
this.txtClassName.Size = new System.Drawing.Size(152, 21);
this.txtClassName.TabIndex = 11;
this.txtClassName.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 136);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(100, 32);
this.label3.TabIndex = 10;
this.label3.Text = "备注:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(100, 32);
this.label2.TabIndex = 9;
this.label2.Text = "入学日期:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(100, 32);
this.label1.TabIndex = 8;
this.label1.Text = "班级名称:";
//
// dateTimePicker1
//
this.dateTimePicker1.Location = new System.Drawing.Point(168, 72);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(152, 21);
this.dateTimePicker1.TabIndex = 16;
//
// frmAddClass
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.ClientSize = new System.Drawing.Size(408, 309);
this.Controls.Add(this.dateTimePicker1);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.txtRemark);
this.Controls.Add(this.txtClassName);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "frmAddClass";
this.Text = "frmAddClass";
this.ResumeLayout(false);
}
#endregion
private void btnAdd_Click(object sender, System.EventArgs e)
{
//先判断有没有输入班级名
if(this.txtClassName.Text=="")
{
MessageBox.Show ("请输入班级名称!");
return;
}
//再判断数据库中有没有存在同名班级
Classs classes=new Classs ();
System.Data .DataSet dsClass=classes.SelectClass(-1,"");
foreach(System.Data.DataRow row in dsClass.Tables [0].Rows)
{
if(this.txtClassName .Text .Trim().Equals( row[1].ToString()))
{
MessageBox.Show ("已经有这个班级了!");
return;
}
}
if( classes.InsertClass(this.txtClassName.Text,
this.dateTimePicker1 .Value ,
this.txtRemark.Text))
{
MessageBox.Show ("新班级建立成功");
this.frm.ShowClass();
}
else
{
MessageBox.Show ("新班级建立失败");
}
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close ();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -