📄 frmnewstudent.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Student
{
using Aptech.Student.DataAccess;
/// <summary>
/// frmNewStudent 的摘要说明。
/// </summary>
public class frmNewStudent : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.DateTimePicker txtBirthday;
private System.Windows.Forms.ComboBox ddlClass;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtStudentNo;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.ComboBox ddlGender;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtRemark;
private System.Windows.Forms.TextBox txtStudentName;
private System.Windows.Forms.Label lblStudentNo;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnCreate;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public frmNewStudent()
{
//
// 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.btnClose = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtBirthday = new System.Windows.Forms.DateTimePicker();
this.ddlClass = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.txtStudentNo = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.ddlGender = new System.Windows.Forms.ComboBox();
this.label5 = new System.Windows.Forms.Label();
this.txtRemark = new System.Windows.Forms.TextBox();
this.txtStudentName = new System.Windows.Forms.TextBox();
this.lblStudentNo = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.btnCreate = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// btnClose
//
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnClose.Location = new System.Drawing.Point(256, 296);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 22);
this.btnClose.TabIndex = 18;
this.btnClose.Text = "关闭";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtBirthday);
this.groupBox1.Controls.Add(this.ddlClass);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.txtStudentNo);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.ddlGender);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.txtRemark);
this.groupBox1.Controls.Add(this.txtStudentName);
this.groupBox1.Controls.Add(this.lblStudentNo);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Location = new System.Drawing.Point(-8, -8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(500, 296);
this.groupBox1.TabIndex = 19;
this.groupBox1.TabStop = false;
this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
//
// txtBirthday
//
this.txtBirthday.CustomFormat = "yyyy-MM-dd HH:mm:ss";
this.txtBirthday.Location = new System.Drawing.Point(120, 112);
this.txtBirthday.Name = "txtBirthday";
this.txtBirthday.Size = new System.Drawing.Size(160, 21);
this.txtBirthday.TabIndex = 10;
//
// ddlClass
//
this.ddlClass.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.ddlClass.Location = new System.Drawing.Point(120, 144);
this.ddlClass.Name = "ddlClass";
this.ddlClass.Size = new System.Drawing.Size(160, 20);
this.ddlClass.TabIndex = 11;
//
// label3
//
this.label3.Location = new System.Drawing.Point(40, 80);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(70, 23);
this.label3.TabIndex = 3;
this.label3.Text = "性别:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtStudentNo
//
this.txtStudentNo.Location = new System.Drawing.Point(120, 16);
this.txtStudentNo.Name = "txtStudentNo";
this.txtStudentNo.Size = new System.Drawing.Size(160, 21);
this.txtStudentNo.TabIndex = 0;
this.txtStudentNo.Text = "";
this.txtStudentNo.TextChanged += new System.EventHandler(this.txtStudentNo_TextChanged);
//
// label4
//
this.label4.Location = new System.Drawing.Point(40, 112);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(70, 23);
this.label4.TabIndex = 4;
this.label4.Text = "出生日期:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// ddlGender
//
this.ddlGender.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.ddlGender.Items.AddRange(new object[] {
"男",
"女"});
this.ddlGender.Location = new System.Drawing.Point(120, 80);
this.ddlGender.Name = "ddlGender";
this.ddlGender.Size = new System.Drawing.Size(160, 20);
this.ddlGender.TabIndex = 9;
//
// label5
//
this.label5.Location = new System.Drawing.Point(40, 144);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(70, 23);
this.label5.TabIndex = 5;
this.label5.Text = "所属班级:";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtRemark
//
this.txtRemark.Location = new System.Drawing.Point(120, 176);
this.txtRemark.Multiline = true;
this.txtRemark.Name = "txtRemark";
this.txtRemark.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
this.txtRemark.Size = new System.Drawing.Size(320, 104);
this.txtRemark.TabIndex = 6;
this.txtRemark.Text = "";
//
// txtStudentName
//
this.txtStudentName.Location = new System.Drawing.Point(120, 48);
this.txtStudentName.Name = "txtStudentName";
this.txtStudentName.Size = new System.Drawing.Size(160, 21);
this.txtStudentName.TabIndex = 8;
this.txtStudentName.Text = "";
//
// lblStudentNo
//
this.lblStudentNo.Location = new System.Drawing.Point(40, 16);
this.lblStudentNo.Name = "lblStudentNo";
this.lblStudentNo.Size = new System.Drawing.Size(70, 23);
this.lblStudentNo.TabIndex = 1;
this.lblStudentNo.Text = "学号:";
this.lblStudentNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 176);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(70, 23);
this.label1.TabIndex = 7;
this.label1.Text = "备注:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(70, 23);
this.label2.TabIndex = 2;
this.label2.Text = "姓名:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// btnCreate
//
this.btnCreate.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnCreate.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnCreate.Location = new System.Drawing.Point(168, 296);
this.btnCreate.Name = "btnCreate";
this.btnCreate.Size = new System.Drawing.Size(75, 22);
this.btnCreate.TabIndex = 16;
this.btnCreate.Text = "建立";
this.btnCreate.Click += new System.EventHandler(this.btnCreate_Click);
//
// frmNewStudent
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(472, 326);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnCreate);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmNewStudent";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "frmNewStudent";
this.Load += new System.EventHandler(this.frmNewStudent_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void GetClass()
{
Classs classs = new Classs();
DataSet dataSet = new DataSet();
try
{
dataSet = classs.SelectClass(
-1,
"");
}
catch(Exception e)
{
MessageBox.Show(e.Message);
this.Close();
return;
}
ddlClass.DisplayMember = "ClassName";
ddlClass.ValueMember = "ClassId";
ddlClass.DataSource = dataSet.Tables[0];
}
private void btnCreate_Click(object sender, System.EventArgs e)
{
Students students = new Students();
students.InsertStudent(
txtBirthday.Value,
ddlGender.SelectedIndex,
Convert.ToInt32(ddlClass.SelectedValue),
0,
txtStudentNo.Text,
txtStudentName.Text,
txtRemark.Text);
MessageBox.Show("建立成功。");
this.Close();
}
private void groupBox1_Enter(object sender, System.EventArgs e)
{
}
private void frmNewStudent_Load(object sender, System.EventArgs e)
{
GetClass();
}
private void txtStudentNo_TextChanged(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -