📄 frmaddclass.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace prjClass
{
/// <summary>
/// frmAddClass 的摘要说明。
/// </summary>
public class frmAddClass : System.Windows.Forms.Form
{
private Class1 c = new Class1();
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Button btnCancle;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.TextBox txtClassName;
private System.Windows.Forms.TextBox txtTeacher;
private System.Windows.Forms.TextBox txtRoomID;
private System.Windows.Forms.TextBox txtMemo;
private System.Windows.Forms.DateTimePicker dateTimePicker1;
private System.Windows.Forms.ComboBox cboSpc;
private System.Windows.Forms.NumericUpDown numericUpDown1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public frmAddClass()
{
//
// 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.btnOk = new System.Windows.Forms.Button();
this.btnCancle = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.txtClassName = new System.Windows.Forms.TextBox();
this.txtTeacher = new System.Windows.Forms.TextBox();
this.txtRoomID = new System.Windows.Forms.TextBox();
this.txtMemo = new System.Windows.Forms.TextBox();
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.cboSpc = new System.Windows.Forms.ComboBox();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
//
// btnOk
//
this.btnOk.Location = new System.Drawing.Point(136, 312);
this.btnOk.Name = "btnOk";
this.btnOk.TabIndex = 0;
this.btnOk.Text = "确定";
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// btnCancle
//
this.btnCancle.Location = new System.Drawing.Point(352, 312);
this.btnCancle.Name = "btnCancle";
this.btnCancle.TabIndex = 1;
this.btnCancle.Text = "取消";
this.btnCancle.Click += new System.EventHandler(this.btnCancle_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(216, 16);
this.label1.Name = "label1";
this.label1.TabIndex = 2;
this.label1.Text = "添加班级";
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 56);
this.label2.Name = "label2";
this.label2.TabIndex = 3;
this.label2.Text = "班级名称";
//
// label3
//
this.label3.Location = new System.Drawing.Point(264, 56);
this.label3.Name = "label3";
this.label3.TabIndex = 20;
this.label3.Text = "年制";
//
// label4
//
this.label4.Location = new System.Drawing.Point(24, 104);
this.label4.Name = "label4";
this.label4.TabIndex = 51;
this.label4.Text = "专业";
//
// label5
//
this.label5.Location = new System.Drawing.Point(264, 104);
this.label5.Name = "label5";
this.label5.TabIndex = 61;
this.label5.Text = "班主任";
//
// label6
//
this.label6.Location = new System.Drawing.Point(24, 152);
this.label6.Name = "label6";
this.label6.TabIndex = 71;
this.label6.Text = "教室编号";
//
// label7
//
this.label7.Location = new System.Drawing.Point(264, 152);
this.label7.Name = "label7";
this.label7.TabIndex = 81;
this.label7.Text = "入学时间";
//
// label8
//
this.label8.Location = new System.Drawing.Point(24, 200);
this.label8.Name = "label8";
this.label8.TabIndex = 91;
this.label8.Text = "备注";
//
// txtClassName
//
this.txtClassName.Location = new System.Drawing.Point(104, 56);
this.txtClassName.Name = "txtClassName";
this.txtClassName.Size = new System.Drawing.Size(152, 21);
this.txtClassName.TabIndex = 1;
this.txtClassName.Text = "";
//
// txtTeacher
//
this.txtTeacher.Location = new System.Drawing.Point(328, 104);
this.txtTeacher.Name = "txtTeacher";
this.txtTeacher.Size = new System.Drawing.Size(152, 21);
this.txtTeacher.TabIndex = 4;
this.txtTeacher.Text = "";
//
// txtRoomID
//
this.txtRoomID.Location = new System.Drawing.Point(104, 152);
this.txtRoomID.Name = "txtRoomID";
this.txtRoomID.Size = new System.Drawing.Size(152, 21);
this.txtRoomID.TabIndex = 5;
this.txtRoomID.Text = "";
//
// txtMemo
//
this.txtMemo.Location = new System.Drawing.Point(104, 200);
this.txtMemo.Multiline = true;
this.txtMemo.Name = "txtMemo";
this.txtMemo.Size = new System.Drawing.Size(376, 72);
this.txtMemo.TabIndex = 7;
this.txtMemo.Text = "";
//
// dateTimePicker1
//
this.dateTimePicker1.Location = new System.Drawing.Point(328, 152);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(152, 21);
this.dateTimePicker1.TabIndex = 6;
//
// cboSpc
//
this.cboSpc.Location = new System.Drawing.Point(104, 104);
this.cboSpc.Name = "cboSpc";
this.cboSpc.Size = new System.Drawing.Size(152, 20);
this.cboSpc.TabIndex = 3;
this.cboSpc.Text = "comboBox2";
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(328, 56);
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(88, 21);
this.numericUpDown1.TabIndex = 92;
//
// frmAddClass
//
this.AcceptButton = this.btnOk;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(522, 365);
this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.cboSpc);
this.Controls.Add(this.dateTimePicker1);
this.Controls.Add(this.txtMemo);
this.Controls.Add(this.txtRoomID);
this.Controls.Add(this.txtTeacher);
this.Controls.Add(this.txtClassName);
this.Controls.Add(this.label8);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnCancle);
this.Controls.Add(this.btnOk);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "frmAddClass";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "新建班级";
this.Load += new System.EventHandler(this.frmAddClass_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void frmAddClass_Load(object sender, System.EventArgs e)
{
string Sql = "select * from Class..SpecialtyInfo";
if(c.IsExits(Sql)==true)
{
string tableName = "SpecialtyInfo";
DataAccess da = new DataAccess();
this.cboSpc.DataSource=da.ExecuteDataTable(Sql,tableName);
this.cboSpc.DisplayMember="SpecialtyName";
this.cboSpc.SelectedIndex=0;
this.numericUpDown1.Value=4;
}
else
{
this.cboSpc.Items.Add("未添加专业");
this.cboSpc.SelectedIndex=0;
}
}
private void btnOk_Click(object sender, System.EventArgs e)
{
string Sql = "select * from Class..ClassInfo where ClassName = '"+this.txtClassName.Text+"'";
string Sql2 = "insert into Class..ClassInfo values('"+this.txtClassName.Text+"','"+this.cboSpc.Text+"','"+this.txtRoomID.Text
+"',"+this.numericUpDown1.Value.ToString()+",'"+ this.txtTeacher.Text+"','"+this.dateTimePicker1.Value.ToShortDateString().ToString()+"','"+this.txtMemo.Text+"')";
if(this.cboSpc.Text=="未添加专业")
{
MessageBox.Show("请先添加专业","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else if(this.txtClassName.Text==""||this.txtTeacher.Text==""||this.txtRoomID.Text==""||this.numericUpDown1.Value==0)
{
MessageBox.Show("请输入完整或正确信息!","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else if(c.IsExits(Sql)==true)
{
MessageBox.Show("该班级已存在!","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else
{
c.EditData(Sql2);
MessageBox.Show("添加成功!","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.txtClassName.Text="";
this.txtMemo.Text="";
this.txtRoomID.Text="";
this.txtTeacher.Text="";
this.numericUpDown1.Value=4;
}
}
private void btnCancle_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -