📄 frmteacherinfo.cs
字号:
"门巴族",
"珞巴族",
"基诺族",
"",
""});
this.cboTeaNation.Location = new System.Drawing.Point(112, 240);
this.cboTeaNation.Name = "cboTeaNation";
this.cboTeaNation.Size = new System.Drawing.Size(168, 20);
this.cboTeaNation.TabIndex = 26;
//
// grpTeaSex
//
this.grpTeaSex.Controls.Add(this.radFemale);
this.grpTeaSex.Controls.Add(this.radMale);
this.grpTeaSex.Location = new System.Drawing.Point(112, 136);
this.grpTeaSex.Name = "grpTeaSex";
this.grpTeaSex.Size = new System.Drawing.Size(168, 48);
this.grpTeaSex.TabIndex = 29;
this.grpTeaSex.TabStop = false;
//
// grpTeaIn_Service
//
this.grpTeaIn_Service.Controls.Add(this.radNo);
this.grpTeaIn_Service.Controls.Add(this.radYes);
this.grpTeaIn_Service.Location = new System.Drawing.Point(392, 176);
this.grpTeaIn_Service.Name = "grpTeaIn_Service";
this.grpTeaIn_Service.Size = new System.Drawing.Size(184, 48);
this.grpTeaIn_Service.TabIndex = 30;
this.grpTeaIn_Service.TabStop = false;
//
// radNo
//
this.radNo.Location = new System.Drawing.Point(80, 16);
this.radNo.Name = "radNo";
this.radNo.Size = new System.Drawing.Size(48, 24);
this.radNo.TabIndex = 25;
this.radNo.Text = "否";
//
// radYes
//
this.radYes.Checked = true;
this.radYes.Location = new System.Drawing.Point(16, 16);
this.radYes.Name = "radYes";
this.radYes.Size = new System.Drawing.Size(48, 24);
this.radYes.TabIndex = 24;
this.radYes.TabStop = true;
this.radYes.Text = "是";
//
// lblTeaID
//
this.lblTeaID.AutoSize = true;
this.lblTeaID.BackColor = System.Drawing.Color.WhiteSmoke;
this.lblTeaID.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lblTeaID.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lblTeaID.Location = new System.Drawing.Point(112, 24);
this.lblTeaID.Name = "lblTeaID";
this.lblTeaID.Size = new System.Drawing.Size(68, 20);
this.lblTeaID.TabIndex = 31;
this.lblTeaID.Text = "教师编号:";
//
// btnUpdate
//
this.btnUpdate.Location = new System.Drawing.Point(72, 352);
this.btnUpdate.Name = "btnUpdate";
this.btnUpdate.Size = new System.Drawing.Size(104, 32);
this.btnUpdate.TabIndex = 32;
this.btnUpdate.Text = "更新(&U)";
this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
//
// btnReStart
//
this.btnReStart.Location = new System.Drawing.Point(336, 352);
this.btnReStart.Name = "btnReStart";
this.btnReStart.Size = new System.Drawing.Size(104, 32);
this.btnReStart.TabIndex = 33;
this.btnReStart.Text = "复位(&R)";
this.btnReStart.Click += new System.EventHandler(this.btnReStart_Click);
//
// btnOpen
//
this.btnOpen.Location = new System.Drawing.Point(544, 152);
this.btnOpen.Name = "btnOpen";
this.btnOpen.Size = new System.Drawing.Size(32, 24);
this.btnOpen.TabIndex = 34;
this.btnOpen.Text = "…";
this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
//
// grpTeacherInfo
//
this.grpTeacherInfo.Controls.Add(this.cboTeaLimit);
this.grpTeacherInfo.Controls.Add(this.lblTeaLimit);
this.grpTeacherInfo.Controls.Add(this.txtTeaRemark);
this.grpTeacherInfo.Controls.Add(this.txtTeaPicture);
this.grpTeacherInfo.Controls.Add(this.txtTeaPostcode);
this.grpTeacherInfo.Controls.Add(this.txtTeaAddress);
this.grpTeacherInfo.Controls.Add(this.txtTeaTelephone);
this.grpTeacherInfo.Controls.Add(this.txtTeaOrigin);
this.grpTeacherInfo.Controls.Add(this.txtTeaName);
this.grpTeacherInfo.Controls.Add(this.lblTeaRemark);
this.grpTeacherInfo.Controls.Add(this.lblTeaIn_Service);
this.grpTeacherInfo.Controls.Add(this.lblTeaPicture);
this.grpTeacherInfo.Controls.Add(this.labTeaPostcode);
this.grpTeacherInfo.Controls.Add(this.lblTeaAddress);
this.grpTeacherInfo.Controls.Add(this.lblTeaTelephone);
this.grpTeacherInfo.Controls.Add(this.lblTeaNation);
this.grpTeacherInfo.Controls.Add(this.lblTeaOrigin);
this.grpTeacherInfo.Controls.Add(this.lblTeaSex);
this.grpTeacherInfo.Controls.Add(this.lblTeaName);
this.grpTeacherInfo.Controls.Add(this.lblTeacherID);
this.grpTeacherInfo.Controls.Add(this.lblTeaID);
this.grpTeacherInfo.Controls.Add(this.btnOpen);
this.grpTeacherInfo.Controls.Add(this.grpTeaIn_Service);
this.grpTeacherInfo.Controls.Add(this.grpTeaSex);
this.grpTeacherInfo.Controls.Add(this.cboTeaNation);
this.grpTeacherInfo.Location = new System.Drawing.Point(8, 32);
this.grpTeacherInfo.Name = "grpTeacherInfo";
this.grpTeacherInfo.Size = new System.Drawing.Size(608, 296);
this.grpTeacherInfo.TabIndex = 35;
this.grpTeacherInfo.TabStop = false;
this.grpTeacherInfo.Text = "教师基本信息";
//
// cboTeaLimit
//
this.cboTeaLimit.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboTeaLimit.Items.AddRange(new object[] {
"授课教师",
"班主任教师",
"主任教师"});
this.cboTeaLimit.Location = new System.Drawing.Point(112, 64);
this.cboTeaLimit.Name = "cboTeaLimit";
this.cboTeaLimit.Size = new System.Drawing.Size(168, 20);
this.cboTeaLimit.TabIndex = 36;
//
// lblTeaLimit
//
this.lblTeaLimit.Location = new System.Drawing.Point(24, 63);
this.lblTeaLimit.Name = "lblTeaLimit";
this.lblTeaLimit.Size = new System.Drawing.Size(72, 23);
this.lblTeaLimit.TabIndex = 35;
this.lblTeaLimit.Text = "教师类别:";
//
// frmTeacherInfo
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(634, 416);
this.Controls.Add(this.grpTeacherInfo);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.btnReStart);
this.Controls.Add(this.btnUpdate);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "frmTeacherInfo";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "添加教师基本信息";
this.Load += new System.EventHandler(this.frmTeacherInfo_Load);
this.grpTeaSex.ResumeLayout(false);
this.grpTeaIn_Service.ResumeLayout(false);
this.grpTeacherInfo.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//获得实例化好的用户实例
public Teacher User
{
get
{
if(Ateacher != null)
{
return Ateacher;
}
else if(Mteacher != null)
{
return Mteacher;
}
else
{
return Pteacher;
}
}
}
//窗体加载事件
private void frmTeacherInfo_Load(object sender, System.EventArgs e)
{
if(teaID == 10000)
{
btnUpdate.Enabled = false;
lblTeaID.Text = Ateacher.GetNewTeaID().ToString();
cboTeaNation.Text = "汉族";
cboTeaLimit.SelectedIndex = 0;
return;
}
this.Text = "修改教师信息";
lblTeaID.Text = teaID.ToString();
//建立教师实体
teacher = new Teacher(teaID);
TakeTeacherInfo();
}
//订阅“邮递员”
private void Post_EventSendLoginedID(object obj,object teacher,string formName)
{
teaID = (int)obj;
if(teacher.GetType().ToString().Equals("BusinessRule.AdminTeacher"))
{
this.Ateacher = (AdminTeacher)teacher;
}
else if(teacher.GetType().ToString().Equals("BusinessRule.MasterTeacher"))
{
this.Mteacher = (MasterTeacher)teacher;
}
else
{
this.Pteacher = (PrelectTeacher)teacher;
}
Post.EventSendLoginedID -= new DataAccess.Post.SendMsgDelegate(Post_EventSendLoginedID);
}
//根据teacher为窗体控件填入教师信息
//教师编号在窗体初始化时已经确定,并且不可更改,所以不需要处理
private void TakeTeacherInfo()
{
if(teacher.TeaLimit == 'A')
{
cboTeaLimit.SelectedIndex = 2;
}
else if(teacher.TeaLimit == 'M')
{
cboTeaLimit.SelectedIndex = 1;
}
else
{
cboTeaLimit.SelectedIndex = 0;
}
this.txtTeaName.Text = this.teacher.TeaName;
if(teacher.TeaSex)
{
this.radFemale.Checked = true;
}
else
{
this.radMale.Checked = true;
}
this.txtTeaOrigin.Text = teacher.TeaOrigin;
this.cboTeaNation.Text = teacher.TeaNation;
this.txtTeaTelephone.Text = teacher.TeaTelephone;
this.txtTeaAddress.Text = teacher.TeaAddress;
this.txtTeaPostcode.Text = teacher.TeaPostcode;
this.txtTeaPicture.Text = teacher.TeaPicture;
if(teacher.TeaIn_Service)
{
this.radYes.Checked = true;
}
else
{
this.radNo.Checked = true;
}
this.txtTeaRemark.Text = teacher.TeaRemark;
}
//根据窗体控件为teacher填入信息
private void SetTeacherInfo()
{
if(cboTeaLimit.Text.Equals("授课教师"))
{
teacher.TeaLimit = 'T';
}
else if(cboTeaLimit.Text.Equals("班主任教师"))
{
teacher.TeaLimit = 'M';
}
else
{
teacher.TeaLimit = 'A';
}
teacher.TeaName = this.txtTeaName.Text.Trim();
teacher.TeaSex = (this.radFemale.Checked)? true : false;
teacher.TeaOrigin = this.txtTeaOrigin.Text.Trim();
teacher.TeaNation = this.cboTeaNation.Text;
teacher.TeaTelephone = this.txtTeaTelephone.Text.Trim();
teacher.TeaAddress = this.txtTeaAddress.Text.Trim();
teacher.TeaPostcode = this.txtTeaPostcode.Text.Trim();
teacher.TeaPicture = this.txtTeaPicture.Text.Trim();
teacher.TeaIn_Service = (this.radYes.Checked)? true : false;
teacher.TeaRemark = this.txtTeaRemark.Text.Trim();
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
string teaSex = (this.radFemale.Checked)? "女" : "男";
string teaIn_Service = (this.radYes.Checked)? "在职" : "离职";
if(MessageBox.Show("教师信息如下:\n\n教师编号:\t" + lblTeaID.Text +
"\n教师类别:\t" + cboTeaLimit.Text + "\n教师姓名:\t" + txtTeaName.Text.Trim() +
"\n性别:\t\t" + teaSex + "\n籍贯:\t\t" + txtTeaOrigin.Text.Trim() +
"\n民族:\t\t" + cboTeaNation.Text + "\n联系电话:\t" + txtTeaTelephone.Text.Trim() +
"\n地址:\t\t" + txtTeaAddress.Text.Trim() + "\n邮政编码:\t" + txtTeaPostcode.Text.Trim() +
"\n图片目录:\t" + txtTeaPicture.Text.Trim() + "\n是否在职:\t" + teaIn_Service +
"\n备注:\t\t" + txtTeaRemark.Text.Trim() + "\n\n是否保存?","请确认",
MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)
{
teacher = new Teacher();
SetTeacherInfo();
try
{
this.Ateacher.InsertTeacherInfo(teacher);
MessageBox.Show("教师信息已被成功写入数据库!","成功",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Close();
}
catch(Exception ex)
{
MessageBox.Show("添加失败!\n\n" + ex.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
//更新按键
private void btnUpdate_Click(object sender, System.EventArgs e)
{
SetTeacherInfo();
try
{
this.Ateacher.UpdateTeacherInfo(teacher);
MessageBox.Show("数据库更新成功!教师信息已保存","成功",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception ex)
{
MessageBox.Show("更新失败!\n\n" + ex.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
//复位按键
private void btnReStart_Click(object sender, System.EventArgs e)
{
if(teacher != null)
{
TakeTeacherInfo();
}
else
{
foreach(Control ctl in this.grpTeacherInfo.Controls)
{
if(ctl is TextBox)
{
TextBox myTextBox = (TextBox)ctl;
myTextBox.Text = "";
}
}
cboTeaNation.Text = "汉族";
cboTeaLimit.SelectedIndex = 0;
this.radMale.Checked = true;
this.radYes.Checked = true;
}
}
//取消按键
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
//图片选择按键
private void btnOpen_Click(object sender, System.EventArgs e)
{
openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "JPEG and GIF Images(*.jpg;*.gif)|*.jpg;*.gif";
if( openFileDialog.ShowDialog() == DialogResult.OK)
{
txtTeaPicture.Text = openFileDialog.FileName;
}
txtTeaPicture.Focus();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -