📄 frmnewcourse.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>
/// frmNewCourse 的摘要说明。
/// </summary>
public class frmNewCourse : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtRemark;
private System.Windows.Forms.Label lblStudentNo;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.DateTimePicker txtFinishDate;
private System.Windows.Forms.DateTimePicker txtBeginDate;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnCreate;
private System.Windows.Forms.ComboBox ddlClass;
private System.Windows.Forms.ComboBox ddlSubject;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public frmNewCourse()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void GetSubject()
{
Subjects subjects = new Subjects();
DataSet dataSet = new DataSet();
try
{
dataSet = subjects.SelectSubject(
-1,
"");
}
catch(Exception e)
{
MessageBox.Show(e.Message);
this.Close();
subjects.Dispose();
return;
}
ddlSubject.DataSource = dataSet.Tables[0];
ddlSubject.ValueMember = "SubjectId";
ddlSubject.DisplayMember = "SubjectName";
}
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];
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtFinishDate = new System.Windows.Forms.DateTimePicker();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.txtRemark = 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.ddlClass = new System.Windows.Forms.ComboBox();
this.ddlSubject = new System.Windows.Forms.ComboBox();
this.txtBeginDate = new System.Windows.Forms.DateTimePicker();
this.btnClose = new System.Windows.Forms.Button();
this.btnCreate = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtBeginDate);
this.groupBox1.Controls.Add(this.ddlSubject);
this.groupBox1.Controls.Add(this.ddlClass);
this.groupBox1.Controls.Add(this.txtFinishDate);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.txtRemark);
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 = 20;
this.groupBox1.TabStop = false;
//
// txtFinishDate
//
this.txtFinishDate.CustomFormat = "yyyy-MM-dd HH:mm:ss";
this.txtFinishDate.Location = new System.Drawing.Point(120, 112);
this.txtFinishDate.Name = "txtFinishDate";
this.txtFinishDate.Size = new System.Drawing.Size(160, 21);
this.txtFinishDate.TabIndex = 10;
//
// 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;
//
// 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;
//
// txtRemark
//
this.txtRemark.Location = new System.Drawing.Point(120, 144);
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 = "";
//
// 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, 144);
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;
//
// ddlClass
//
this.ddlClass.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.ddlClass.Location = new System.Drawing.Point(120, 16);
this.ddlClass.Name = "ddlClass";
this.ddlClass.Size = new System.Drawing.Size(160, 20);
this.ddlClass.TabIndex = 12;
//
// ddlSubject
//
this.ddlSubject.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.ddlSubject.Location = new System.Drawing.Point(120, 48);
this.ddlSubject.Name = "ddlSubject";
this.ddlSubject.Size = new System.Drawing.Size(160, 20);
this.ddlSubject.TabIndex = 13;
//
// txtBeginDate
//
this.txtBeginDate.CustomFormat = "yyyy-MM-dd HH:mm:ss";
this.txtBeginDate.Location = new System.Drawing.Point(120, 80);
this.txtBeginDate.Name = "txtBeginDate";
this.txtBeginDate.Size = new System.Drawing.Size(160, 21);
this.txtBeginDate.TabIndex = 14;
//
// btnClose
//
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnClose.Location = new System.Drawing.Point(240, 296);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 22);
this.btnClose.TabIndex = 22;
this.btnClose.Text = "关闭";
//
// btnCreate
//
this.btnCreate.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnCreate.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnCreate.Location = new System.Drawing.Point(152, 296);
this.btnCreate.Name = "btnCreate";
this.btnCreate.Size = new System.Drawing.Size(75, 22);
this.btnCreate.TabIndex = 21;
this.btnCreate.Text = "建立";
this.btnCreate.Click += new System.EventHandler(this.btnCreate_Click);
//
// frmNewCourse
//
this.AcceptButton = this.btnCreate;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.btnClose;
this.ClientSize = new System.Drawing.Size(472, 326);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnCreate);
this.Controls.Add(this.groupBox1);
this.Name = "frmNewCourse";
this.Text = "frmNewCourse";
this.Load += new System.EventHandler(this.frmNewCourse_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void frmNewCourse_Load(object sender, System.EventArgs e)
{
GetSubject();
GetClass();
}
private void btnCreate_Click(object sender, System.EventArgs e)
{
Courses courses = new Courses();
courses.InsertCourse(
Convert.ToInt32(ddlClass.SelectedValue),
Convert.ToInt32(ddlSubject.SelectedValue),
txtBeginDate.Value,
txtFinishDate.Value,
txtRemark.Text);
MessageBox.Show("建立成功");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -