private void btnSaveTitle_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.cmbAction.Text)) { MessageBox.Show("请输入描述信息"); return; } ALS.BLL.actiontitle bllat = new ALS.BLL.actiontitle(); if (bllat.GetModel(this.cmbAction.Text, GetmethodStyle(_method)) == null) { ALS.Model.actiontitle mat = new ALS.Model.actiontitle(); mat.info = this.cmbAction.Text.Trim(); mat.method = GetmethodStyle(_method); if (bllat.Add(mat)) { GetActionInfoList(this.cmbAction, GetmethodStyle(_method)); MessageBox.Show("保存成功!"); } } else { MessageBox.Show("已存在的描述信息!"); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ALS.Model.actiontitle model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_actiontitle set "); strSql.Append("info=@info,"); strSql.Append("method=@method"); strSql.Append(" where ID=@ID"); MySqlParameter[] parameters = { new MySqlParameter("@info", MySqlDbType.VarChar, 255), new MySqlParameter("@method", MySqlDbType.VarChar, 255), new MySqlParameter("@ID", MySqlDbType.Int32, 11) }; parameters[0].Value = model.info; parameters[1].Value = model.method; parameters[2].Value = model.ID; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ALS.Model.actiontitle model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_actiontitle("); strSql.Append("info,method)"); strSql.Append(" values ("); strSql.Append("@info,@method)"); MySqlParameter[] parameters = { new MySqlParameter("@info", MySqlDbType.VarChar, 255), new MySqlParameter("@method", MySqlDbType.VarChar, 255), }; parameters[0].Value = model.info; parameters[1].Value = model.method; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ALS.Model.actiontitle GetModel(string info, string method) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ID,info,method from tb_actiontitle "); strSql.Append(" where info=@info and method=@method "); MySqlParameter[] parameters = { new MySqlParameter("@info", MySqlDbType.VarChar), new MySqlParameter("@method", MySqlDbType.VarChar), }; parameters[0].Value = info; parameters[1].Value = method; ALS.Model.actiontitle model = new ALS.Model.actiontitle(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ALS.Model.actiontitle DataRowToModel(DataRow row) { ALS.Model.actiontitle model = new ALS.Model.actiontitle(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["info"] != null) { model.info = row["info"].ToString(); } if (row["method"] != null) { model.info = row["method"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public ALS.Model.actiontitle GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ID,info,method from tb_actiontitle "); strSql.Append(" where ID=@ID"); MySqlParameter[] parameters = { new MySqlParameter("@ID", MySqlDbType.Int32) }; parameters[0].Value = ID; ALS.Model.actiontitle model = new ALS.Model.actiontitle(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }