private void btConfirm_Click(object sender, EventArgs e) { if (couID == "" || couID == null) { MessageBox.Show("请先选择一行记录!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (new Maticsoft.BLL.CS().Exists(couID, Maticsoft.Common.StaticDataClass.student.ID)) { MessageBox.Show("本门课程已选!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (MessageBox.Show("确认选择教师 " + teaName + " 讲授的 《" + couName + "》 课程?", "信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { Maticsoft.Model.CS model = new Maticsoft.Model.CS(); model.stuID = Maticsoft.Common.StaticDataClass.student.ID; model.couID = couID; model.teaID = teaID; if (new Maticsoft.BLL.CS().Add(model)) { MessageBox.Show("选课成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); ((StuCou)this.Owner).LoadData_SC(); } else { MessageBox.Show("选课失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
private void btDeleteSelCou_Click(object sender, EventArgs e) { if (couID == "" || couID == null) { MessageBox.Show("请先选择一行记录!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (MessageBox.Show("确认删除 课程号为 " + couID + " 的选课记录?", "信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { Maticsoft.Model.CS model = new Maticsoft.Model.CS(); model.stuID = Maticsoft.Common.StaticDataClass.student.ID; model.teaID = teaID; model.couID = couID; if (new Maticsoft.BLL.CS().Delete(model)) { MessageBox.Show("删除成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); couID = ""; teaID = ""; LoadData_SC(); } else { MessageBox.Show("删除失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.CS model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CS set "); strSql.Append("score=@score"); strSql.Append(" where couID=@couID and stuID=@stuID and teaID = @teaID "); SqlParameter[] parameters = { new SqlParameter("@score", SqlDbType.Float, 8), new SqlParameter("@couID", SqlDbType.VarChar, 15), new SqlParameter("@stuID", SqlDbType.VarChar, 15), new SqlParameter("@teaID", SqlDbType.VarChar, 15) }; parameters[0].Value = model.score; parameters[1].Value = model.couID; parameters[2].Value = model.stuID; parameters[3].Value = model.teaID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.CS model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CS("); strSql.Append("couID,stuID,teaID,score)"); strSql.Append(" values ("); strSql.Append("@couID,@stuID,@teaID,@score)"); SqlParameter[] parameters = { new SqlParameter("@couID", SqlDbType.VarChar, 15), new SqlParameter("@stuID", SqlDbType.VarChar, 15), new SqlParameter("@teaID", SqlDbType.VarChar, 15), new SqlParameter("@score", SqlDbType.Float, 8) }; parameters[0].Value = model.couID; parameters[1].Value = model.stuID; parameters[2].Value = model.teaID; parameters[3].Value = model.score; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.CS GetModel(string couID, string stuID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 couID,stuID,score from CS "); strSql.Append(" where couID=@couID and stuID=@stuID "); SqlParameter[] parameters = { new SqlParameter("@couID", SqlDbType.VarChar, 15), new SqlParameter("@stuID", SqlDbType.VarChar, 15) }; parameters[0].Value = couID; parameters[1].Value = stuID; Maticsoft.Model.CS model = new Maticsoft.Model.CS(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void btConfirm_Click(object sender, EventArgs e) { string score = tbScore.Text.Trim(); Maticsoft.Model.CS model = new Maticsoft.Model.CS(); model.couID = TeaCou.couID; model.stuID = TeaStu.stuID; model.teaID = Maticsoft.Common.StaticDataClass.teacher.ID; if (score != "" && score != null) { decimal scoreF = decimal.Parse(score); if (scoreF >= 0 && scoreF <= 100) { model.score = scoreF; } else { MessageBox.Show("成绩应在 0 ~ 100 之间!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else { if (score == null) { MessageBox.Show("成绩出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } model.score = null; } if (new Maticsoft.BLL.CS().Update(model)) { MessageBox.Show("修改成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); ((TeaStu)this.Owner).LoadData_TS(); this.Close(); } else { MessageBox.Show("修改失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.CS DataRowToModel(DataRow row) { Maticsoft.Model.CS model = new Maticsoft.Model.CS(); if (row != null) { if (row["couID"] != null) { model.couID = row["couID"].ToString(); } if (row["stuID"] != null) { model.stuID = row["stuID"].ToString(); } if (row["score"] != null && row["score"].ToString() != "") { model.score = decimal.Parse(row["score"].ToString()); } } return(model); }