?? frmaddstudent.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Aptech.Student.DataAccess;
using Aptech.Student.Common;
namespace 學生管理系統
{
/// <summary>
/// frmAddStudent 的摘要說明。
/// </summary>
public class frmAddStudent : 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.ComboBox cmbClass;
private System.Windows.Forms.ComboBox cmbSex;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.TextBox txtNo;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label4;
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 frmAddStudent(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.cmbClass = new System.Windows.Forms.ComboBox();
this.cmbSex = new System.Windows.Forms.ComboBox();
this.txtName = new System.Windows.Forms.TextBox();
this.txtNo = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
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(392, 152);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(80, 40);
this.btnExit.TabIndex = 27;
this.btnExit.Text = "退出";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnAdd
//
this.btnAdd.Location = new System.Drawing.Point(392, 104);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(80, 40);
this.btnAdd.TabIndex = 26;
this.btnAdd.Text = "添加";
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// txtRemark
//
this.txtRemark.Location = new System.Drawing.Point(144, 272);
this.txtRemark.Multiline = true;
this.txtRemark.Name = "txtRemark";
this.txtRemark.Size = new System.Drawing.Size(312, 104);
this.txtRemark.TabIndex = 25;
this.txtRemark.Text = "";
//
// cmbClass
//
this.cmbClass.Location = new System.Drawing.Point(144, 224);
this.cmbClass.Name = "cmbClass";
this.cmbClass.Size = new System.Drawing.Size(192, 20);
this.cmbClass.TabIndex = 24;
//
// cmbSex
//
this.cmbSex.Items.AddRange(new object[] {
"男",
"女"});
this.cmbSex.Location = new System.Drawing.Point(144, 120);
this.cmbSex.Name = "cmbSex";
this.cmbSex.Size = new System.Drawing.Size(192, 20);
this.cmbSex.TabIndex = 22;
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(144, 72);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(192, 21);
this.txtName.TabIndex = 21;
this.txtName.Text = "";
//
// txtNo
//
this.txtNo.Location = new System.Drawing.Point(144, 24);
this.txtNo.Name = "txtNo";
this.txtNo.Size = new System.Drawing.Size(192, 21);
this.txtNo.TabIndex = 20;
this.txtNo.Text = "";
//
// label6
//
this.label6.Location = new System.Drawing.Point(24, 272);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(80, 16);
this.label6.TabIndex = 19;
this.label6.Text = "備注:";
//
// label5
//
this.label5.Location = new System.Drawing.Point(24, 224);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(80, 16);
this.label5.TabIndex = 18;
this.label5.Text = "所屬班級:";
//
// label4
//
this.label4.Location = new System.Drawing.Point(24, 168);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(80, 24);
this.label4.TabIndex = 17;
this.label4.Text = "出生年月:";
//
// label3
//
this.label3.Location = new System.Drawing.Point(24, 120);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 24);
this.label3.TabIndex = 16;
this.label3.Text = "性別:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 24);
this.label2.TabIndex = 15;
this.label2.Text = "姓名:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 24);
this.label1.TabIndex = 14;
this.label1.Text = "學號:";
//
// dateTimePicker1
//
this.dateTimePicker1.Location = new System.Drawing.Point(144, 160);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(192, 21);
this.dateTimePicker1.TabIndex = 28;
//
// frmAddStudent
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(544, 422);
this.Controls.Add(this.dateTimePicker1);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.txtRemark);
this.Controls.Add(this.cmbClass);
this.Controls.Add(this.cmbSex);
this.Controls.Add(this.txtName);
this.Controls.Add(this.txtNo);
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.Name = "frmAddStudent";
this.Text = "frmAddStudent";
this.Load += new System.EventHandler(this.frmAddStudent_Load);
this.ResumeLayout(false);
}
#endregion
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close ();
}
private void frmAddStudent_Load(object sender, System.EventArgs e)
{//窗體加載
//性別默認為男
this.cmbSex.SelectedIndex=0;
//讀出數據庫中所有的班級寫到cmbClass中
Classs classes=new Classs ();
System.Data .DataSet dsClass=classes.SelectClass(-1,"");
foreach(System.Data.DataRow row in dsClass.Tables [0].Rows)
{
this.cmbClass.Items .Add (row[1].ToString());
this.cmbClass.SelectedIndex=0;
}
}
private void btnAdd_Click(object sender, System.EventArgs e)
{//添加
string sNo=this.txtNo.Text.Trim () ;
string sName=this.txtName.Text .Trim ();
string sSex=this.cmbSex.SelectedItem.ToString();
DateTime sTime=this.dateTimePicker1 .Value ;
string sClass=this.cmbClass.SelectedItem .ToString();
string sRemark=this.txtRemark.Text;
if(sNo==""||sName=="")
{
MessageBox.Show ("請輸入學生信息!");
return;
}
//判斷男女轉換為int
int sex;
if(sSex.Equals("男"))
{
sex=0;
}
else
{
sex=1;
}
//根據班級名得到班級id
Aptech.Student.DataAccess .Classs classes=new Classs ();
System.Data .DataSet dsClass=classes.SelectClass(-1,sClass);
int classId=(int)dsClass.Tables[0].Rows [0][0];
Aptech.Student.DataAccess.Students students=new Students ();
if(students.InsertStudent(sTime,sex,classId,0,sNo,sName,sRemark))
{
MessageBox.Show ("添加新學生成功");
this.frm.ShowStudent (-1,"","",classId);
}
else
{
MessageBox.Show ("添加新學生失敗");
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -