📄 frmadd.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using ExamSystem.BusinessFacade.TeacherFac;
using System.Data;
using ExamSystem.Common;
namespace TeachersClient.StuManFrm
{
/// <summary>
/// FrmAdd1 的摘要说明。
/// </summary>
public class FrmAdd : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lbl;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.NumericUpDown nudNum;
private System.Windows.Forms.ComboBox cmbSex;
private System.Windows.Forms.DateTimePicker dtpBirday;
private System.Windows.Forms.ComboBox cmbClass;
private System.Windows.Forms.RichTextBox rtbRemark;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.PictureBox pbHead;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.OpenFileDialog ofdPic;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private bool hasAdd;
/// <summary>
/// 判断是否有插入过学生
/// </summary>
public bool HasAdd
{
get
{
return hasAdd;
}
}
/// <summary>
/// 把班级填充到选择框
/// </summary>
private void fillClass()
{
ClassFac clsFac=new ClassFac();
DataSet dsClass=clsFac.getClass(-1,"",-1);
cmbClass.DataSource=dsClass.Tables[0];
cmbClass.ValueMember="ClassID";
cmbClass.DisplayMember="ClassName";
}
/// <summary>
/// 判断是否有必填项没填
/// </summary>
/// <returns></returns>
private bool hasEmpty()
{
if(this.txtName.Text.Trim()=="")
{
MessageBox.Show("姓名不能为空!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
txtName.Focus();
return true;
}
return false;
}
private void fillSex(ComboBox cmb)
{
cmb.Items.Add("男");
cmb.Items.Add("女");
}
public FrmAdd()
{
//
// 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.lbl = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.pbHead = new System.Windows.Forms.PictureBox();
this.label5 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.dtpBirday = new System.Windows.Forms.DateTimePicker();
this.txtName = new System.Windows.Forms.TextBox();
this.cmbSex = new System.Windows.Forms.ComboBox();
this.cmbClass = new System.Windows.Forms.ComboBox();
this.rtbRemark = new System.Windows.Forms.RichTextBox();
this.nudNum = new System.Windows.Forms.NumericUpDown();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.ofdPic = new System.Windows.Forms.OpenFileDialog();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudNum)).BeginInit();
this.SuspendLayout();
//
// lbl
//
this.lbl.Location = new System.Drawing.Point(40, 24);
this.lbl.Name = "lbl";
this.lbl.Size = new System.Drawing.Size(56, 24);
this.lbl.TabIndex = 0;
this.lbl.Text = "学号:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 23);
this.label1.TabIndex = 1;
this.label1.Text = "姓名";
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 96);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 23);
this.label2.TabIndex = 2;
this.label2.Text = "性别";
//
// label3
//
this.label3.Location = new System.Drawing.Point(40, 144);
this.label3.Name = "label3";
this.label3.TabIndex = 3;
this.label3.Text = "出生日期";
//
// label4
//
this.label4.Location = new System.Drawing.Point(40, 192);
this.label4.Name = "label4";
this.label4.TabIndex = 4;
this.label4.Text = "所属班级";
//
// pbHead
//
this.pbHead.Location = new System.Drawing.Point(392, 24);
this.pbHead.Name = "pbHead";
this.pbHead.Size = new System.Drawing.Size(120, 120);
this.pbHead.TabIndex = 5;
this.pbHead.TabStop = false;
//
// label5
//
this.label5.Location = new System.Drawing.Point(40, 240);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(40, 16);
this.label5.TabIndex = 6;
this.label5.Text = "备注";
//
// panel1
//
this.panel1.Controls.Add(this.panel2);
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel1.Location = new System.Drawing.Point(0, 365);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(544, 40);
this.panel1.TabIndex = 7;
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
//
// panel2
//
this.panel2.Controls.Add(this.button1);
this.panel2.Controls.Add(this.button2);
this.panel2.Dock = System.Windows.Forms.DockStyle.Right;
this.panel2.Location = new System.Drawing.Point(320, 0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(224, 40);
this.panel2.TabIndex = 2;
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 24);
this.button1.TabIndex = 0;
this.button1.Text = "建立";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(136, 8);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 24);
this.button2.TabIndex = 1;
this.button2.Text = "关闭";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// dtpBirday
//
this.dtpBirday.Location = new System.Drawing.Point(104, 144);
this.dtpBirday.Name = "dtpBirday";
this.dtpBirday.Size = new System.Drawing.Size(120, 21);
this.dtpBirday.TabIndex = 8;
this.dtpBirday.Value = new System.DateTime(1980, 1, 1, 0, 0, 0, 0);
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(104, 56);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(240, 21);
this.txtName.TabIndex = 10;
this.txtName.Text = "";
//
// cmbSex
//
this.cmbSex.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbSex.Location = new System.Drawing.Point(104, 96);
this.cmbSex.Name = "cmbSex";
this.cmbSex.Size = new System.Drawing.Size(64, 20);
this.cmbSex.TabIndex = 11;
//
// cmbClass
//
this.cmbClass.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbClass.Location = new System.Drawing.Point(104, 192);
this.cmbClass.Name = "cmbClass";
this.cmbClass.Size = new System.Drawing.Size(120, 20);
this.cmbClass.TabIndex = 12;
//
// rtbRemark
//
this.rtbRemark.Location = new System.Drawing.Point(104, 240);
this.rtbRemark.Name = "rtbRemark";
this.rtbRemark.Size = new System.Drawing.Size(304, 72);
this.rtbRemark.TabIndex = 13;
this.rtbRemark.Text = "";
//
// nudNum
//
this.nudNum.Location = new System.Drawing.Point(104, 24);
this.nudNum.Minimum = new System.Decimal(new int[] {
1,
0,
0,
0});
this.nudNum.Name = "nudNum";
this.nudNum.Size = new System.Drawing.Size(64, 21);
this.nudNum.TabIndex = 14;
this.nudNum.Value = new System.Decimal(new int[] {
1,
0,
0,
0});
//
// label6
//
this.label6.Location = new System.Drawing.Point(376, 160);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(156, 14);
this.label6.TabIndex = 15;
this.label6.Text = "照片最好为120×120的图片";
//
// label7
//
this.label7.Location = new System.Drawing.Point(428, 4);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(32, 16);
this.label7.TabIndex = 16;
this.label7.Text = "照片";
//
// button3
//
this.button3.Location = new System.Drawing.Point(412, 184);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(90, 24);
this.button3.TabIndex = 17;
this.button3.Text = "浏览";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// FrmAdd
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(544, 405);
this.Controls.Add(this.button3);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.nudNum);
this.Controls.Add(this.rtbRemark);
this.Controls.Add(this.cmbClass);
this.Controls.Add(this.cmbSex);
this.Controls.Add(this.txtName);
this.Controls.Add(this.dtpBirday);
this.Controls.Add(this.panel1);
this.Controls.Add(this.label5);
this.Controls.Add(this.pbHead);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.lbl);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FrmAdd";
this.Text = "FrmAdd";
this.Load += new System.EventHandler(this.FrmAdd_Load);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.nudNum)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void FrmAdd_Load(object sender, System.EventArgs e)
{
fillClass();
fillSex(this.cmbSex);
if(cmbClass.Items.Count>0)
{
cmbClass.SelectedIndex=0;
}
cmbSex.SelectedIndex=0;
this.hasAdd=false;
}
private void button1_Click(object sender, System.EventArgs e)
{
if(hasEmpty())
{
return;
}
StudentFac stuFac=new StudentFac();
byte[] pic=null;
if(this.pbHead.Image!=null)
{
PictureMan.getBytes(pbHead.Image);
}
SearchBooleans sex=SearchBooleans.NULL;
if(cmbSex.Text=="男")
{
sex=SearchBooleans.False;
}else if(cmbSex.Text=="女")
{
sex=SearchBooleans.True;
}
if(stuFac.insertStudent((int)this.nudNum.Value,txtName.Text,(int)this.cmbClass.SelectedValue,this.dtpBirday.Value,sex,pic,this.rtbRemark.Text))
{
MessageBox.Show("添加完毕\n默认密码是:111111","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
hasAdd=true;
}
else
{
MessageBox.Show("该班已经有同一学号的学生","添加失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void button3_Click(object sender, System.EventArgs e)
{
if(ofdPic.ShowDialog()==DialogResult.OK)
{
Image img=PictureMan.loadImage(ofdPic.FileName,this.pbHead.Width,this.pbHead.Height);
if(img==null)
{
MessageBox.Show("无法读取图片","读取失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
{
if(pbHead.Image!=null)
{
pbHead.Image.Dispose();
}
pbHead.Image=img;
}
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -