/// <summary> /// 增加一条数据 /// </summary> public bool Add(Topicsys.Model.t_class model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into t_class("); strSql.Append("class_id,class_name,class_major_id,class_note,class_stat)"); strSql.Append(" values ("); strSql.Append("@class_id,@class_name,@class_major_id,@class_note,@class_stat)"); MySqlParameter[] parameters = { new MySqlParameter("@class_id", MySqlDbType.VarChar, 40), new MySqlParameter("@class_name", MySqlDbType.VarChar, 64), new MySqlParameter("@class_major_id", MySqlDbType.VarChar, 40), new MySqlParameter("@class_note", MySqlDbType.VarChar, 255), new MySqlParameter("@class_stat", MySqlDbType.Int32, 1) }; parameters[0].Value = model.class_id; parameters[1].Value = model.class_name; parameters[2].Value = model.class_major_id; parameters[3].Value = model.class_note; parameters[4].Value = model.class_stat; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Topicsys.Model.t_class DataRowToModel(DataRow row) { Topicsys.Model.t_class model = new Topicsys.Model.t_class(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["class_id"] != null) { model.class_id = row["class_id"].ToString(); } if (row["class_name"] != null) { model.class_name = row["class_name"].ToString(); } if (row["class_major_id"] != null) { model.class_major_id = row["class_major_id"].ToString(); } if (row["class_note"] != null) { model.class_note = row["class_note"].ToString(); } if (row["class_stat"] != null && row["class_stat"].ToString() != "") { model.class_stat = int.Parse(row["class_stat"].ToString()); } } return(model); }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtclass_name.Text.Trim().Length == 0) { strErr += "名称不能为空!\\n"; } if (this.ddlMajor_id.Text.Trim().Length == 0) { strErr += "专业不能为空!\\n"; } if (strErr != "") { BLL.Utils.ShowMessage(this, strErr); return; } string class_name = this.txtclass_name.Text; string class_major_id = this.ddlMajor_id.Text; string class_note = this.txtclass_note.Text; int class_stat = int.Parse(this.ddlStat.Text); Topicsys.BLL.t_class bll = new Topicsys.BLL.t_class(); Topicsys.Model.t_class model = bll.GetModel(int.Parse(Request.Params["id"])); model.class_name = class_name; model.class_major_id = class_major_id; model.class_note = class_note; model.class_stat = class_stat; /// 写入日志 BLL.Utils.Log(this, "修改班级:" + model.class_id); BLL.Utils.ShowMessage(this, bll.Update(model)?"保存成功!":"发生错误!"); }
private void ShowInfo(int id) { Topicsys.BLL.t_class bll = new Topicsys.BLL.t_class(); Topicsys.Model.t_class model = bll.GetModel(id); this.txtclass_name.Text = model.class_name; this.ddlMajor_id.Text = model.class_major_id; this.txtclass_note.Text = model.class_note; this.ddlStat.Text = model.class_stat.ToString(); }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.ddlDept_id.Text.Trim().Length == 0) { strErr += "系别不能为空!\\n"; } if (this.txtclass_name.Text.Trim().Length == 0) { strErr += "名称不能为空!\\n"; } if (this.ddlMajor_id.Text.Trim().Length == 0) { strErr += "专业不能为空!\\n"; } if (strErr != "") { BLL.Utils.ShowMessage(this, strErr); return; } string class_name = this.txtclass_name.Text; string class_major_id = this.ddlMajor_id.Text; string class_note = this.txtclass_note.Text; Topicsys.Model.t_class model = new Topicsys.Model.t_class(); model.class_name = class_name; model.class_major_id = class_major_id; model.class_note = class_note; Topicsys.BLL.t_class bll = new Topicsys.BLL.t_class(); /// 写入日志 BLL.Utils.Log(this, "添加班级:" + model.class_name); BLL.Utils.ShowMessage(this, bll.Add(model)?"保存成功!":"保存失败!"); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Topicsys.Model.t_class model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_class set "); strSql.Append("class_name=@class_name,"); strSql.Append("class_major_id=@class_major_id,"); strSql.Append("class_note=@class_note,"); strSql.Append("class_stat=@class_stat"); strSql.Append(" where id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@class_name", MySqlDbType.VarChar, 64), new MySqlParameter("@class_major_id", MySqlDbType.VarChar, 40), new MySqlParameter("@class_note", MySqlDbType.VarChar, 255), new MySqlParameter("@class_stat", MySqlDbType.Int32, 1), new MySqlParameter("@id", MySqlDbType.Int32, 11), new MySqlParameter("@class_id", MySqlDbType.VarChar, 40) }; parameters[0].Value = model.class_name; parameters[1].Value = model.class_major_id; parameters[2].Value = model.class_note; parameters[3].Value = model.class_stat; parameters[4].Value = model.id; parameters[5].Value = model.class_id; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Topicsys.Model.t_class GetModel(string id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id,class_id,class_name,class_major_id,class_note,class_stat from t_class "); strSql.Append(" where class_id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@id", MySqlDbType.VarChar) }; parameters[0].Value = id; Topicsys.Model.t_class model = new Topicsys.Model.t_class(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }