private void btnDel_Click(object sender, EventArgs e) { int i = dataGridView1.SelectedRows.Count; if (i == 0) { MessageBox.Show("请先选中你要删除的一行"); } else { if (DialogResult.Yes == MessageBox.Show("真的要删除吗?", "确认退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { for (int j = 0; j < dataGridView1.SelectedRows.Count; j++) { string strTeaNo = dataGridView1.SelectedRows[j].Cells["教师编号"].Value.ToString(); string strErr = ""; string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Teacher.Teacher objTea = new Manage.Teacher.Teacher(strConnection); int iRent = objTea.DelTea(strTeaNo, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } } MessageBox.Show("删除成功"); } BindDataGridView(); } }
private void btnSave_Click(object sender, EventArgs e) { string strErr = ""; Model.Teacher.Teacher objTeacher = new Model.Teacher.Teacher(); string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Teacher.Teacher objTea = new Manage.Teacher.Teacher(strConnection); objTeacher.TeaNo = txtTeaNo.Text.Replace("'", "''"); objTeacher.TeaNo = objTeacher.TeaNo.Trim(); objTeacher.TeaName = txtTeaName.Text.Replace("'", "''"); objTeacher.TeaName = objTeacher.TeaName.Trim(); if (objTeacher.TeaNo == "" || objTeacher.TeaName == "") { MessageBox.Show("请将信息填写完整!"); } else { if (rabMan.Checked == true) { objTeacher.Sex = "男"; } else { objTeacher.Sex = "女"; } objTeacher.Age = int.Parse(nudAge.Value.ToString()); objTeacher.Rank = cmbRank.SelectedItem.ToString(); objTeacher.Degree = cmbDegree.SelectedItem.ToString(); objTeacher.TeaAddress = txtAddress.Text.Replace("'", "''"); objTeacher.TeaTel = txtTel.Text.Replace("'", "''"); objTeacher.Remark = txtRemark.Text.Replace("'", "''"); int iTeaNo = objTea.JudgeTeaNo(objTeacher.TeaNo); //判断教师编号间是否重复 int iR = objTea.JudgeTeaNoLikeStuNo(objTeacher.TeaNo); //判断教师编号与学生编号是否重复 if (iTeaNo == 0) { MessageBox.Show("此编号的教师已经存在,添加失败"); } else if (iR == 0) { MessageBox.Show("存在一个此编号的学生,教师编号不能和学生编号相同"); } else { int iRent = objTea.AddTea(objTeacher, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { MessageBox.Show("添加成功"); this.Visible = false; } } } }
void BindDataGridView2() { string strErr = ""; DataTable objDataTable = new DataTable(); string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Teacher.Teacher objTea = new Manage.Teacher.Teacher(strConnection); int iRent = objTea.StuSearchAllTea(strUserNo, out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { dataGridView1.DataSource = objDataTable; } }
private void menuSearchTea_Click(object sender, EventArgs e) { string strErr = ""; DataTable objDataTable = new DataTable(); string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Manage.Teacher.Teacher objTea = new Manage.Teacher.Teacher(strConnection); string strTeaNo = txtTeaNo.Text; strTeaNo = strTeaNo.Replace("%", @"\%"); strTeaNo = strTeaNo.Replace("_", @"\_"); strTeaNo = strTeaNo.Replace("'", @"\''"); strTeaNo = strTeaNo.Trim(); string strTeaName = txtTeaName.Text; strTeaName = strTeaName.Replace("%", @"\%"); strTeaName = strTeaName.Replace("_", @"\_"); strTeaName = strTeaName.Replace("'", @"\''"); strTeaName = strTeaName.Trim(); if (iRight != 3) { int iRent = objTea.SearchTea(strTeaNo, strTeaName, out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { if (objDataTable.Rows.Count == 0) { MessageBox.Show("没有符合你要查询的记录"); } else { dataGridView1.DataSource = objDataTable; } txtTeaName.Text = ""; txtTeaNo.Text = ""; } } else { int iRent = objTea.StuSearchOneTeaNo(strTeaNo, strTeaName, strUserNo, out objDataTable, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { if (objDataTable.Rows.Count == 0) { MessageBox.Show("没有符合你要查询的记录"); } else { dataGridView1.DataSource = objDataTable; } txtTeaName.Text = ""; txtTeaNo.Text = ""; } } }
private void btnSave_Click(object sender, EventArgs e) { string strErr; string strConnection = System.Configuration.ConfigurationManager.ConnectionStrings["StudentManager"].ConnectionString; Model.Teacher.Teacher objTea = new Model.Teacher.Teacher(); Manage.Teacher.Teacher objTeaManage = new Manage.Teacher.Teacher(strConnection); objTea.TeaNo = txtTeaNo.Text.Replace("'", "''"); objTea.TeaNo = txtTeaNo.Text.Trim(); objTea.TeaName = txtTeaName.Text.Replace("'", "''"); objTea.TeaName = txtTeaName.Text.Trim(); objTea.Age = int.Parse(nudAge.Value.ToString()); objTea.Rank = cmbRank.Text; objTea.TeaTel = txtTel.Text.Replace("'", "''"); objTea.TeaTel = txtTel.Text.Trim(); objTea.TeaAddress = txtAddress.Text.Replace("'", "''"); objTea.TeaAddress = txtAddress.Text.Trim(); objTea.Degree = cmbDegree.Text; objTea.Remark = txtRemark.Text.Replace("'", "''"); objTea.Remark = txtRemark.Text.Trim(); if (rdbMan.Checked == true) { objTea.Sex = "男"; } else { objTea.Sex = "女"; } if (txtTeaNo.Text == "" || txtTeaName.Text == "") { MessageBox.Show("教师编号和姓名不能为空"); txtTeaNo.Text = strTeaNo; txtTeaName.Text = strTeaName; } else if (objTea.TeaNo == strTeaNo) { int iRent = objTeaManage.ModifyTea(strTeaNo, objTea, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { MessageBox.Show("修改成功"); this.Visible = false; } } else { int j = objTeaManage.JudgeTeaNo(objTea.TeaNo); int i = objTeaManage.JudgeTeaNoLikeStuNo(objTea.TeaNo); if (i == 1 && j == 1) { int iRent = objTeaManage.ModifyTea(strTeaNo, objTea, out strErr); if (iRent == 0) { MessageBox.Show(strErr); return; } else { MessageBox.Show("修改成功"); this.Visible = false; } } else { MessageBox.Show("已经存在一个编号相同的教师或者学生,修改失败"); txtTeaNo.Text = strTeaNo; } } }