📄 addclass.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
/// <summary>
/// xjbj 的摘要说明。
/// </summary>
public class AddClass : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.DateTimePicker dateTimePicker1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label8;
private System.Data.OleDb.OleDbConnection oleDbConnection1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label label4;
/// <summary>
/// 必需的设计器变量。
/// </summary>
[DllImport("User32.dll")]
public static extern int MessageBox(int h,string m,string c,int type);
private System.ComponentModel.Container components = null;
public AddClass()
{
//
// 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.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = 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.textBox3 = new System.Windows.Forms.TextBox();
this.textBox5 = new System.Windows.Forms.TextBox();
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label8 = new System.Windows.Forms.Label();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
this.label1.Location = new System.Drawing.Point(9, 51);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(67, 21);
this.label1.TabIndex = 0;
this.label1.Text = "班级名称";
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.textBox1.Location = new System.Drawing.Point(96, 51);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(171, 25);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.ForeColor = System.Drawing.SystemColors.ControlText;
this.label2.Location = new System.Drawing.Point(40, 103);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(36, 21);
this.label2.TabIndex = 2;
this.label2.Text = "专业";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label3.ForeColor = System.Drawing.SystemColors.ControlText;
this.label3.Location = new System.Drawing.Point(9, 154);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(67, 21);
this.label3.TabIndex = 3;
this.label3.Text = "教室编号";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label5.ForeColor = System.Drawing.SystemColors.ControlText;
this.label5.Location = new System.Drawing.Point(308, 51);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(36, 21);
this.label5.TabIndex = 5;
this.label5.Text = "年制";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label6.ForeColor = System.Drawing.SystemColors.ControlText;
this.label6.Location = new System.Drawing.Point(292, 103);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(52, 21);
this.label6.TabIndex = 6;
this.label6.Text = "办主任";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label7.ForeColor = System.Drawing.SystemColors.ControlText;
this.label7.Location = new System.Drawing.Point(277, 154);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(67, 21);
this.label7.TabIndex = 7;
this.label7.Text = "入学时间";
//
// textBox3
//
this.textBox3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.textBox3.Location = new System.Drawing.Point(96, 154);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(171, 25);
this.textBox3.TabIndex = 9;
this.textBox3.Text = "";
//
// textBox5
//
this.textBox5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.textBox5.Location = new System.Drawing.Point(363, 103);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(181, 25);
this.textBox5.TabIndex = 11;
this.textBox5.Text = "";
//
// dateTimePicker1
//
this.dateTimePicker1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.dateTimePicker1.Location = new System.Drawing.Point(363, 154);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(181, 25);
this.dateTimePicker1.TabIndex = 13;
//
// button1
//
this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.Location = new System.Drawing.Point(128, 298);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 31);
this.button1.TabIndex = 14;
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.Location = new System.Drawing.Point(395, 298);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(74, 31);
this.button2.TabIndex = 15;
this.button2.Text = "退出";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label8
//
this.label8.AutoSize = true;
this.label8.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label8.ForeColor = System.Drawing.SystemColors.ControlText;
this.label8.Location = new System.Drawing.Point(235, 10);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(67, 21);
this.label8.TabIndex = 16;
this.label8.Text = "添加班级";
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = "Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet." +
"OLEDB.4.0;";
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.comboBox1.Location = new System.Drawing.Point(96, 103);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(171, 23);
this.comboBox1.TabIndex = 17;
//
// textBox2
//
this.textBox2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.textBox2.Location = new System.Drawing.Point(96, 206);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(448, 72);
this.textBox2.TabIndex = 18;
this.textBox2.Text = "";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label4.ForeColor = System.Drawing.SystemColors.ControlText;
this.label4.Location = new System.Drawing.Point(40, 206);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(36, 21);
this.label4.TabIndex = 19;
this.label4.Text = "备注";
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(363, 51);
this.numericUpDown1.Maximum = new System.Decimal(new int[] {
10,
0,
0,
0});
this.numericUpDown1.Minimum = new System.Decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.ReadOnly = true;
this.numericUpDown1.Size = new System.Drawing.Size(96, 25);
this.numericUpDown1.TabIndex = 20;
this.numericUpDown1.Value = new System.Decimal(new int[] {
3,
0,
0,
0});
//
// AddClass
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(578, 348);
this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.label4);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label8);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.dateTimePicker1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "AddClass";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "新建班级";
this.Load += new System.EventHandler(this.AddClass_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
if (textBox1.Text.Trim()=="" || comboBox1.Text.Trim()=="" || textBox3.Text.Trim()=="" || textBox5.Text.Trim()=="")
MessageBox(0,"请输入完整的班级信息","提示",0);
else if(numericUpDown1.Value.ToString()=="")
MessageBox(0,"年制应为数字或可接受的范围","提示",0);
else
{
oleDbConnection1.Open();
OleDbCommand cmd=new OleDbCommand("select * from classinfo where classname='"+textBox1.Text.Trim()+"'",oleDbConnection1);
if (null!=cmd.ExecuteScalar())
MessageBox(0,"班级名称发生重复","提示",0);
else
{
string sql,sql1,sql2;
sql1="insert into classinfo (classname,specialtyname,classnumber,length,teacher,enrolmenttime";
sql2="values ('"+textBox1.Text.ToString()+"','"+comboBox1.Text.ToString()+"','"+textBox3.Text.ToString()+"',"+numericUpDown1.Value.ToString()+",'"+textBox5.Text.ToString()+"','"+dateTimePicker1.Text+"'";
if (textBox2.Text!="")
{
sql1=sql1+",remark";
sql2=sql2+",'"+textBox2.Text.ToString()+"'";
}
sql=sql1+") "+sql2+")";
cmd.CommandText=sql;
cmd.ExecuteNonQuery();
MessageBox(0,"班级信息添加成功","提示",0);
}
oleDbConnection1.Close();
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void AddClass_Load(object sender, System.EventArgs e)
{
string sql="select specialtyid,specialtyname from specialtyinfo";
OleDbDataAdapter adp=new OleDbDataAdapter(sql,oleDbConnection1);
//oleDbConnection1.ConnectionString="Data Source=.\\..\\..\\xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;";
DataSet ds=new DataSet();
adp.Fill(ds,"specialtyinfo");
comboBox1.DataSource=ds.Tables["specialtyinfo"].DefaultView;
comboBox1.DisplayMember="specialtyname";
comboBox1.ValueMember="specialtyid";
}
private void textBox4_TextChanged(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -