private void button1_Click(object sender, EventArgs e) { string Cno = textBox1.Text.Trim(); string Cname = textBox2.Text; string Chour = textBox3.Text; string Ccredit = textBox4.Text; Course.CourseInfoData data = new Course.CourseInfoData(); data.Cno = Cno; data.Cname = Cname; data.Chour = Chour; data.Ccredit = Ccredit; try { ds = Course.CourseInfoOperation.getCourseInfo(data); this.dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ex) { ex.ToString(); } finally { Course_overview_Load(sender, e); } }
private void button3_Click(object sender, EventArgs e) { int index = this.dataGridView1.CurrentRow.Index; if (index < 0) { MessageBox.Show("请选择要删除的记录!", "提示"); return; } else { if (MessageBox.Show("确定要删除吗?", "删除后无法撤回", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { string cno = ds.Tables[0].Rows[index]["课程号"].ToString(); try { if (Course.CourseInfoOperation.deleteCourseInfo(cno)) { MessageBox.Show("删除成功!", "提示"); //binddatagrid string Cno = textBox1.Text.Trim(); string Cname = textBox2.Text; string Chour = textBox3.Text; string Ccredit = textBox4.Text; Course.CourseInfoData data = new Course.CourseInfoData(); data.Cno = Cno; data.Cname = Cname; data.Chour = Chour; data.Ccredit = Ccredit; try { ds = Course.CourseInfoOperation.getCourseInfo(data); this.dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ex) { ex.ToString(); } } else { MessageBox.Show("删除失败", "错误"); } } catch (Exception ex) { ex.ToString(); MessageBox.Show("删除失败", "错误"); } finally { Course_overview_Load(sender, e); } } } }
private void button1_Click(object sender, EventArgs e) { string Cno = textBox1.Text.Trim(); string Cname = textBox2.Text; string Chour = textBox3.Text; string Ccredit = textBox4.Text; if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "" || textBox4.Text.Trim() == "") { MessageBox.Show("请输入完整信息!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBox1.Text.Trim() == null || textBox2.Text.Trim() == null || textBox3.Text.Trim() == null || textBox4.Text.Trim() == null) { MessageBox.Show("请输入完整信息!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } Course.CourseInfoData data = new Course.CourseInfoData(); data.Cno = Cno; data.Cname = Cname; data.Chour = Chour; data.Ccredit = Ccredit; try { if (FLAG == "") { if (Course.CourseInfoOperation.insertCourseInfo(data)) { MessageBox.Show("添加成功", "提示"); this.textBox1.Text = ""; this.textBox2.Text = ""; this.textBox3.Text = ""; this.textBox4.Text = ""; } else { MessageBox.Show("添加失败", "提示"); } } else { if (Course.CourseInfoOperation.updateCourseInfo(data)) { MessageBox.Show("修改成功", "提示"); } else { MessageBox.Show("修改失败", "提示"); } } } catch (Exception ex) { ex.ToString(); MessageBox.Show("保存失败", "错误"); } }
public Insert_Course(string flag) { InitializeComponent(); this.FLAG = flag; if (flag != "") { Course.CourseInfoData data = new Course.CourseInfoData(); data.Cno = flag; DataSet ds = Course.CourseInfoOperation.getCourseInfo(data); this.textBox1.Text = flag; this.textBox2.Text = ds.Tables[0].Rows[0]["课程名"].ToString(); this.textBox3.Text = ds.Tables[0].Rows[0]["课时"].ToString(); this.textBox4.Text = ds.Tables[0].Rows[0]["学分"].ToString(); this.textBox1.Enabled = false; this.Text = "Update"; } }
//获取查询课程信息 public static DataSet getCourseInfo(Course.CourseInfoData data) { string condition = ""; if (data.Cno != null && data.Cno != "") { condition += "and Cno='" + data.Cno + "'"; } if (data.Cname != null && data.Cname != "") { condition += "and Cname='" + data.Cname + "'"; } if (data.Chour != null && data.Chour != "") { condition += "and Chour='" + data.Chour + "'"; } if (data.Ccredit != null && data.Ccredit != "") { condition += "and Ccredit='" + data.Ccredit + "'"; } string sql = "select Cno 课程号,Cname 课程名, Chour 课时,Ccredit 学分 from Course where 2=2 " + condition; return(dataAccess.GetDataSet(sql, "Course")); }
private void Course_overview_Load(object sender, EventArgs e) { Course.CourseInfoData data = new Course.CourseInfoData(); ds = Course.CourseInfoOperation.getCourseInfo(data); this.dataGridView1.DataSource = ds.Tables[0]; }
//修改课程信息 public static bool updateCourseInfo(Course.CourseInfoData data) { string sql = "update Course set Cname='" + data.Cname + "',Chour=" + data.Chour + ",Ccredit=" + data.Ccredit + " where Cno='" + data.Cno + "'"; return(dataAccess.ExecuteSQL(sql)); }
//插入课程记录 public static bool insertCourseInfo(Course.CourseInfoData data) { string sql = "insert into Course(Cno,Cname,Chour,Ccredit) values('" + data.Cno + "','" + data.Cname + "'," + data.Chour + "," + data.Ccredit + ")"; return(dataAccess.ExecuteSQL(sql)); }