📄 addstuinfo.cs
字号:
{
get{return this.cboStu_Special;}
set{this.cboStu_Special = value;}
}
public ComboBox Stu_Love
{
get{return this.cboStu_Love;}
set{this.cboStu_Love = value;}
}
public ComboBox Stu_educational
{
get{return this.cboStu_educational;}
set{this.cboStu_educational = value;}
}
//属性RadioButton
public RadioButton Stu_Female
{
get{return this.radFemale;}
set{this.radFemale = value;}
}
public RadioButton Stu_Male
{
get{return this.radMale;}
set{this.radMale = value;}
}
//属性PictureBox
public PictureBox Stu_Photo
{
get{return this.picStu_Photo;}
set{this.picStu_Photo = value;}
}
public ImageList Imglist
{
get{return this.imgObj;}
set{this.imgObj = value;}
}
public Button Exit
{
get{return this.btnExit;}
set{this.btnExit = value;}
}
public Button Reset
{
get{return this.button2;}
set{this.button2 = value;}
}
public Button Addinfo
{
get{return this.btnAddInfo;}
set{this.btnAddInfo = value;}
}
public Button OpenPhoto
{
get{return this.btnOpenPhoto;}
set{this.btnOpenPhoto = value;}
}
public OpenFileDialog Fdlg
{
get{return this.openFileDlg;}
set{this.openFileDlg = value;}
}
//初始化信息
private void AddStuinfo_Load(object sender, System.EventArgs e)
{
this.cboStu_Race.SelectedIndex = 0;
this.cboStu_educational.SelectedIndex = 0;
this.cboStu_Love.SelectedIndex = 0;
this.cboStu_Special.SelectedIndex = 0;
//this.picStu_Photo.Image = this.imgObj.Images[0];
}
//退出
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
//清楚所有的信息框
public void button2_Click(object sender, System.EventArgs e)
{
txtStu_Id_Leave(sender,e);
this.txtStu_Name.Text = "";
this.txtStu_Address.Text = "";
this.txtStu_FixTel.Text = "";
this.txtStu_Idcard.Text = "";
this.txtStu_Marks.Text = "";
this.txtStu_TelPhone.Text = "";
this.txtStu_NativePlace.Text = "";
this.radFemale.Checked = false;
this.radMale.Checked = false;
this.picStu_Photo.Image = this.imgObj.Images[0];
this.cboStu_Race.SelectedIndex = 0;
this.cboStu_educational.SelectedIndex = 0;
this.cboStu_Love.SelectedIndex = 0;
this.cboStu_Special.SelectedIndex = 0;
this.filepath = String.Empty;
}
//添加信息到数据库
public void btnAddInfo_Click(object sender, System.EventArgs e)
{
((FormMain)this.MdiParent).Status.Text = "状态: 添加学员信息";
//验证数据
DateVali dv = new DateVali(this);
if(!dv.validate())
{
return;
}
String sex = string.Empty; //性别
String path = string.Empty; //图片路径
if(this.radMale.Checked == true)
{
sex = "男";
}
else
{
sex = "女";
}
if(this.filepath == String.Empty )
{
MessageBox.Show("请选择你的头相!");
return;
}
path = "image\\"+this.filepath.Substring(this.filepath.LastIndexOf("\\")+1);
//拷贝相片到image目录
try
{
File.Copy(this.filepath,((FormMain)this.MdiParent).environmentpath+"\\"+path,true);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
Console.WriteLine(ex);
}
//连接数据库
db.Server = "Microsoft.Jet.OLEDB.4.0";
db.Database = ((FormMain)this.MdiParent).environmentpath+"\\StuInfoMgr.mdb";
db.createConn();
db.openConn();
cmd = new OleDbCommand();
cmd.Connection = db.Conn;
cmd.CommandText = "insert into stuinfo values('"+this.txtStu_Id.Text+"','"+this.txtStu_Name.Text+"','"+sex+"','"+
this.txtStu_Idcard.Text+"','"+this.cboStu_Race.SelectedItem.ToString()+"','"+this.cboStu_educational.SelectedItem.ToString()+"','"+
this.txtStu_NativePlace.Text+"','"+this.txtStu_Address.Text+"','"+this.txtStu_FixTel.Text+"','"+
this.txtStu_TelPhone.Text+"','"+this.cboStu_Love.SelectedItem.ToString()+"','"+this.cboStu_Special.SelectedItem.ToString()+"','"+
path+"','"+this.txtStu_Marks.Text+"')";
try
{
int num = cmd.ExecuteNonQuery();
if(num == -1)
{
MessageBox.Show("添加学员信息失败!请重新添加!");
}
else
{
//更新子窗体的表数据
Form[] forms = this.MdiParent.MdiChildren;
for(int i=0;i<forms.Length;i++)
{
if(forms[i].Text.Equals("查询学员信息"))
{
SelStuinfo form = ((SelStuinfo)forms[i]);
form.ds = null;
form.SelStuinfo_Load(sender,e);
form.Update();
form.Refresh();
}
}
}
((FormMain)this.MdiParent).Probar.Visible = true;
for(int i=1;i<=100;i++)
{
for(int j=1;j<=100;j++)
{
if(j%20 == 0)
{
((FormMain)this.MdiParent).Probar.Increment(i);
}
}
}
MessageBox.Show("添加成功了!");
((FormMain)this.MdiParent).Probar.Visible = false;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
Console.WriteLine(ex);
}
db.closeConn();
button2_Click(sender,e);
}
//打开相片
private void btnOpenPhoto_Click(object sender, System.EventArgs e)
{
this.openFileDlg.Filter = "图片文件 (*.jpg)|*.jpg|位图文件 (*.bmp)|*.bmp|(动画图片 (*.gif)|*.gif|PNG图片 (*.png)|*.png";
if(this.openFileDlg.ShowDialog() == DialogResult.OK)
{
this.filepath = this.openFileDlg.FileName;
this.picStu_Photo.Image = Image.FromFile(this.filepath);
}
}
//鼠标移开时发生
private void txtStu_Id_Leave(object sender, System.EventArgs e)
{
//连接数据库
db.Server = "Microsoft.Jet.OLEDB.4.0";
db.Database = ((FormMain)this.MdiParent).environmentpath+"\\StuInfoMgr.mdb";
db.createConn();
db.openConn();
OleDbCommand selcmd = new OleDbCommand();
selcmd.CommandText = "select Stu_Id from stuinfo order by Stu_Id desc";
selcmd.CommandType = CommandType.Text;
selcmd.Connection = db.Conn;
OleDbDataReader dr = selcmd.ExecuteReader();
dr.Read();
String stuid = dr.GetValue(0).ToString();
int num =Convert.ToInt32(stuid.Substring(8,3));
String strObj = null;
if((num+1) < 10)
{
strObj = "A2Q7031_00"+(num+1);
}
else if((num+1)>=10 && (num+1)<100)
{
strObj = "A2Q7031_0"+(num+1);
}
else if((num+1)>=100)
{
strObj = "A2Q7031_"+(num+1);
}
this.txtStu_Id.Text = strObj;
db.closeConn();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -