private void cboSubjectName_SelectedIndexChanged(object sender, EventArgs e) { string subjectName = this.cboSubjectName.SelectedItem.ToString(); DataAccess.Subject objSubject = DataAccess.Subject.CreateInstance(subjectName); this.txtPeriod.Text = objSubject.Period.ToString(); this.txtRemark.Text = objSubject.Remark; }
//修改科目 public void Update(string subjectName, int period, string remark) { DataAccess.Subject objSubject = new DataAccess.Subject(subjectName); objSubject.Period = period; objSubject.Remark = remark; if (objSubject.Update() > 0) { UpdateDataGrid(); MessageBox.Show("修改科目资料成功!", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("更新科目操作失败,请重试!", "操作失败", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//删除科目 public void Delete() { string subjectName = this._dgvSubject.CurrentRow.Cells["SubjectName"].Value.ToString(); DialogResult result = MessageBox.Show("真的要删除科目' " + subjectName + " '吗?", "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult.Yes == result) { DataAccess.Subject objSubject = new DataAccess.Subject(subjectName); if (objSubject.Delete() > 0) { UpdateDataGrid(); MessageBox.Show("成功删除科目' " + subjectName + " '!", "操作成功", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("删除操作失败,请重试!", "操作失败", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }