📄 frmupdateclass.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;
using Aptech.Student.Business;
/// <summary>
/// frmUpdateClass 的摘要说明。
/// </summary>
public class frmUpdateClass : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnSubmit;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox txtRemark;
private System.Windows.Forms.DateTimePicker txtEntranceDate;
private System.Windows.Forms.TextBox txtClassName;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button btnDelete;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ListView lstCourse;
private int m_iClassId;
public frmUpdateClass()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
public frmUpdateClass(
int iClassId)
{
m_iClassId = iClassId;
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.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmUpdateClass));
this.btnClose = new System.Windows.Forms.Button();
this.btnSubmit = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.lstCourse = new System.Windows.Forms.ListView();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.txtRemark = new System.Windows.Forms.TextBox();
this.txtEntranceDate = new System.Windows.Forms.DateTimePicker();
this.txtClassName = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.btnDelete = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(320, 296);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 22);
this.btnClose.TabIndex = 5;
this.btnClose.Text = "关闭";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// btnSubmit
//
this.btnSubmit.Location = new System.Drawing.Point(152, 296);
this.btnSubmit.Name = "btnSubmit";
this.btnSubmit.Size = new System.Drawing.Size(75, 22);
this.btnSubmit.TabIndex = 4;
this.btnSubmit.Text = "更改";
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.lstCourse);
this.groupBox1.Controls.Add(this.txtRemark);
this.groupBox1.Controls.Add(this.txtEntranceDate);
this.groupBox1.Controls.Add(this.txtClassName);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(-8, -8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(488, 296);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
//
// lstCourse
//
this.lstCourse.BackColor = System.Drawing.SystemColors.HighlightText;
this.lstCourse.CheckBoxes = true;
this.lstCourse.GridLines = true;
this.lstCourse.LargeImageList = this.imageList1;
this.lstCourse.Location = new System.Drawing.Point(120, 176);
this.lstCourse.Name = "lstCourse";
this.lstCourse.Size = new System.Drawing.Size(320, 97);
this.lstCourse.SmallImageList = this.imageList1;
this.lstCourse.TabIndex = 6;
this.lstCourse.View = System.Windows.Forms.View.List;
//
// imageList1
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// txtRemark
//
this.txtRemark.Location = new System.Drawing.Point(120, 80);
this.txtRemark.Multiline = true;
this.txtRemark.Name = "txtRemark";
this.txtRemark.Size = new System.Drawing.Size(320, 84);
this.txtRemark.TabIndex = 5;
this.txtRemark.Text = "";
//
// txtEntranceDate
//
this.txtEntranceDate.Location = new System.Drawing.Point(120, 48);
this.txtEntranceDate.Name = "txtEntranceDate";
this.txtEntranceDate.Size = new System.Drawing.Size(160, 21);
this.txtEntranceDate.TabIndex = 4;
//
// txtClassName
//
this.txtClassName.Location = new System.Drawing.Point(120, 16);
this.txtClassName.Name = "txtClassName";
this.txtClassName.Size = new System.Drawing.Size(160, 21);
this.txtClassName.TabIndex = 3;
this.txtClassName.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 80);
this.label3.Name = "label3";
this.label3.TabIndex = 2;
this.label3.Text = "备注:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 48);
this.label2.Name = "label2";
this.label2.TabIndex = 1;
this.label2.Text = "入学日期:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "名称:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// btnDelete
//
this.btnDelete.Location = new System.Drawing.Point(232, 296);
this.btnDelete.Name = "btnDelete";
this.btnDelete.Size = new System.Drawing.Size(75, 22);
this.btnDelete.TabIndex = 6;
this.btnDelete.Text = "删除";
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
//
// frmUpdateClass
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(472, 326);
this.Controls.Add(this.btnDelete);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnSubmit);
this.Controls.Add(this.groupBox1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmUpdateClass";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "更新班信息";
this.Load += new System.EventHandler(this.frmUpdateClass_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void btnSubmit_Click(object sender, System.EventArgs e)
{
Classs classs = new Classs();
try
{
classs.UpdateClass(
m_iClassId,
txtClassName.Text,
txtEntranceDate.Value,
txtRemark.Text);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
MessageBox.Show("更改成功");
}
private void btnClose_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnDelete_Click(object sender, System.EventArgs e)
{
StudentSystem studentSystem = new StudentSystem();
try
{
studentSystem.DeleteClass(
m_iClassId);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
MessageBox.Show("删除成功。");
this.Close();
}
private void frmUpdateClass_Load(object sender, System.EventArgs e)
{
GetClassInfo();
GetCourse();
}
private void GetClassInfo()
{
Classs classs = new Classs();
DataSet dataSet = new DataSet();
try
{
dataSet = classs.SelectClass(
m_iClassId,
"");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
this.Close();
}
if(dataSet.Tables[0].Rows.Count == 0)
{
MessageBox.Show("班信息不存在。");
this.Close();
}
DataRow row = dataSet.Tables[0].Rows[0];
this.txtClassName.Text = row["ClassName"].ToString();
this.txtRemark.Text = row["Remark"].ToString();
this.txtEntranceDate.Value = Convert.ToDateTime(row["EntranceDate"]);
}
private void CreateCourseTemp()
{
ColumnHeader columnHeader = new ColumnHeader();
columnHeader.Text = "课程名称";
lstCourse.Columns.Add(columnHeader);
columnHeader = new ColumnHeader();
columnHeader.Text = "CourseId";
lstCourse.Columns.Add(columnHeader);
columnHeader = new ColumnHeader();
columnHeader.Text = "SubjectId";
lstCourse.Columns.Add(columnHeader);
}
private void GetCourse()
{
Classs classs = new Classs();
DataSet dataSet = new DataSet();
dataSet = classs.SelectClassCourse(
m_iClassId);
for(int i = 0; i < dataSet.Tables[0].Rows.Count; i ++)
{
DataRow row = dataSet.Tables[0].Rows[i];
string[] sItems = new string[3];
sItems[0] = row["SubjectName"].ToString();
sItems[1] = row["SubjectId"].ToString();
sItems[2] = row["CourseId"].ToString();
ListViewItem item = new ListViewItem(sItems, 2);
item.Checked = (row["CourseId"] != System.DBNull.Value);
lstCourse.Items.Add(item);
}
classs.Dispose();
}
private void groupBox1_Enter(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -