public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtmajor_name.Text.Trim().Length == 0) { strErr += "名称不能为空!\\n"; } if (strErr != "") { BLL.Utils.ShowMessage(this, strErr); return; } string major_name = this.txtmajor_name.Text; string major_dept_id = this.txtmajor_dept_id.Text; int major_stat = int.Parse(this.txtmajor_stat.Text); string major_note = this.txtmajor_note.Text; Topicsys.BLL.t_major bll = new Topicsys.BLL.t_major(); Topicsys.Model.t_major model = bll.GetModel(int.Parse(Request.Params["id"])); model.major_name = major_name; model.major_dept_id = major_dept_id; model.major_stat = major_stat; model.major_note = major_note; /// 写入日志 BLL.Utils.Log(this, "修改专业:" + model.major_id); BLL.Utils.ShowMessage(this, bll.Update(model)?"保存成功!":"发生错误!"); }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtmajor_name.Text.Trim().Length == 0) { strErr += "专业名称不能为空!\\n"; } if (this.txtmajor_dept_id.Text.Trim().Length == 0) { strErr += "必须选择系别!\\n"; } if (strErr != "") { BLL.Utils.ShowMessage(this, strErr); return; } string major_name = this.txtmajor_name.Text; string major_dept_id = this.txtmajor_dept_id.Text; string major_note = this.txtmajor_note.Text; var model = new Topicsys.Model.t_major { major_name = major_name, major_dept_id = major_dept_id, major_note = major_note, }; Topicsys.BLL.t_major bll = new Topicsys.BLL.t_major(); /// 写入日志 BLL.Utils.Log(this, "添加专业:" + model.major_name); BLL.Utils.ShowMessage(this, bll.Add(model)?"保存成功!":"保存失败!"); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Topicsys.Model.t_major model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into t_major("); strSql.Append("major_id,major_name,major_dept_id,major_stat,major_note)"); strSql.Append(" values ("); strSql.Append("@major_id,@major_name,@major_dept_id,@major_stat,@major_note)"); MySqlParameter[] parameters = { new MySqlParameter("@major_id", MySqlDbType.VarChar, 40), new MySqlParameter("@major_name", MySqlDbType.VarChar, 64), new MySqlParameter("@major_dept_id", MySqlDbType.VarChar, 40), new MySqlParameter("@major_stat", MySqlDbType.Int32, 1), new MySqlParameter("@major_note", MySqlDbType.VarChar, 255) }; parameters[0].Value = model.major_id; parameters[1].Value = model.major_name; parameters[2].Value = model.major_dept_id; parameters[3].Value = model.major_stat; parameters[4].Value = model.major_note; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Topicsys.Model.t_major DataRowToModel(DataRow row) { Topicsys.Model.t_major model = new Topicsys.Model.t_major(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["major_id"] != null) { model.major_id = row["major_id"].ToString(); } if (row["major_name"] != null) { model.major_name = row["major_name"].ToString(); } if (row["major_dept_id"] != null) { model.major_dept_id = row["major_dept_id"].ToString(); } if (row["major_stat"] != null && row["major_stat"].ToString() != "") { model.major_stat = int.Parse(row["major_stat"].ToString()); } if (row["major_note"] != null) { model.major_note = row["major_note"].ToString(); } } return(model); }
private void ShowInfo(int id) { Topicsys.BLL.t_major bll = new Topicsys.BLL.t_major(); Topicsys.Model.t_major model = bll.GetModel(id); BLL.DDL.DeptDLL(txtmajor_dept_id); this.lblid.Text = model.id.ToString(); this.txtmajor_name.Text = model.major_name; this.txtmajor_dept_id.Text = model.major_dept_id; this.txtmajor_stat.Text = model.major_stat.ToString(); this.txtmajor_note.Text = model.major_note; }
private void ShowInfo(int id) { Topicsys.BLL.t_major bll = new Topicsys.BLL.t_major(); Topicsys.Model.t_major model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); var bll_dept = new BLL.t_dept(); this.lblmajor_dept_id.Text = bll_dept.GetModel(model.major_dept_id).dept_name; this.lblmajor_name.Text = model.major_name; this.lblmajor_dept_id.Text = model.major_dept_id; this.lblmajor_stat.Text = model.major_stat.ToString(); this.lblmajor_note.Text = model.major_note; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Topicsys.Model.t_major model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_major set "); strSql.Append("major_name=@major_name,"); strSql.Append("major_dept_id=@major_dept_id,"); strSql.Append("major_stat=@major_stat,"); strSql.Append("major_note=@major_note"); strSql.Append(" where id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@major_name", MySqlDbType.VarChar, 64), new MySqlParameter("@major_dept_id", MySqlDbType.VarChar, 40), new MySqlParameter("@major_stat", MySqlDbType.Int32, 1), new MySqlParameter("@major_note", MySqlDbType.VarChar, 255), new MySqlParameter("@id", MySqlDbType.Int32, 11), new MySqlParameter("@major_id", MySqlDbType.VarChar, 40) }; parameters[0].Value = model.major_name; parameters[1].Value = model.major_dept_id; parameters[2].Value = model.major_stat; parameters[3].Value = model.major_note; parameters[4].Value = model.id; parameters[5].Value = model.major_id; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Topicsys.Model.t_major GetModel(string id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id,major_id,major_name,major_dept_id,major_stat,major_note from t_major "); strSql.Append(" where major_id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@id", MySqlDbType.VarChar) }; parameters[0].Value = id; Topicsys.Model.t_major model = new Topicsys.Model.t_major(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }