/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.Courses model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Courses set "); strSql.Append("couName=@couName,"); strSql.Append("couTime=@couTime,"); strSql.Append("couPoint=@couPoint"); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@couName", SqlDbType.VarChar, 20), new SqlParameter("@couTime", SqlDbType.Int, 4), new SqlParameter("@couPoint", SqlDbType.Float, 8), new SqlParameter("@ID", SqlDbType.VarChar, 15) }; parameters[0].Value = model.couName; parameters[1].Value = model.couTime; parameters[2].Value = model.couPoint; parameters[3].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.Courses model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Courses("); strSql.Append("ID,couName,couTime,couPoint)"); strSql.Append(" values ("); strSql.Append("@ID,@couName,@couTime,@couPoint)"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.VarChar, 15), new SqlParameter("@couName", SqlDbType.VarChar, 20), new SqlParameter("@couTime", SqlDbType.Int, 4), new SqlParameter("@couPoint", SqlDbType.Float, 8) }; parameters[0].Value = model.ID; parameters[1].Value = model.couName; parameters[2].Value = model.couTime; parameters[3].Value = model.couPoint; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void btConfirm_Click(object sender, EventArgs e) { string ID = tbID.Text.Trim(), couName = tbCouName.Text.Trim(); decimal couTime = nudCouTime.Value, couPoint = nudCouPoint.Value; if (couName == "" || couName == null || ID == "" || ID == null) { MessageBox.Show("不能有空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (couTime > 0 && couPoint > 0) { if (new Maticsoft.BLL.Courses().Exists(ID)) { MessageBox.Show("课程已存在!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Maticsoft.Model.Courses course = new Maticsoft.Model.Courses(); course.ID = ID; course.couName = couName; course.couTime = Convert.ToInt32(couTime); course.couPoint = couPoint; Maticsoft.Common.StaticDataClass.course = course; Main main = (Main)this.Owner; if (main.AddCourse()) { MessageBox.Show("添加成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); main.LoadData_Course(); this.Close(); } else { MessageBox.Show("添加失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("学时和学分都应大于零!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Courses DataRowToModel(DataRow row) { Maticsoft.Model.Courses model = new Maticsoft.Model.Courses(); if (row != null) { if (row["ID"] != null) { model.ID = row["ID"].ToString(); } if (row["couName"] != null) { model.couName = row["couName"].ToString(); } if (row["couTime"] != null && row["couTime"].ToString() != "") { model.couTime = int.Parse(row["couTime"].ToString()); } if (row["couPoint"] != null && row["couPoint"].ToString() != "") { model.couPoint = decimal.Parse(row["couPoint"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Courses GetModel(string ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,couName,couTime,couPoint from Courses "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.VarChar, 15) }; parameters[0].Value = ID; Maticsoft.Model.Courses model = new Maticsoft.Model.Courses(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }