/// <summary> /// 增加一条数据 /// </summary> public bool Add(WalleProject.Model.t_menu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into t_menu("); strSql.Append("menu_Cate_ID,menu_name,menu_sort,menu_path,menu_valid)"); strSql.Append(" values ("); strSql.Append("@menu_Cate_ID,@menu_name,@menu_sort,@menu_path,@menu_valid)"); MySqlParameter[] parameters = { new MySqlParameter("@menu_Cate_ID", MySqlDbType.Int32, 10), new MySqlParameter("@menu_name", MySqlDbType.VarChar, 10), new MySqlParameter("@menu_sort", MySqlDbType.Int32, 10), new MySqlParameter("@menu_path", MySqlDbType.VarChar, 50), new MySqlParameter("@menu_valid", MySqlDbType.VarChar, 2) }; parameters[0].Value = model.menu_Cate_ID; parameters[1].Value = model.menu_name; parameters[2].Value = model.menu_sort; parameters[3].Value = model.menu_path; parameters[4].Value = model.menu_valid; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WalleProject.Model.t_menu DataRowToModel(DataRow row) { WalleProject.Model.t_menu model = new WalleProject.Model.t_menu(); if (row != null) { if (row["menu_ID"] != null && row["menu_ID"].ToString() != "") { model.menu_ID = int.Parse(row["menu_ID"].ToString()); } if (row["menu_Cate_ID"] != null && row["menu_Cate_ID"].ToString() != "") { model.menu_Cate_ID = int.Parse(row["menu_Cate_ID"].ToString()); } if (row["menu_name"] != null) { model.menu_name = row["menu_name"].ToString(); } if (row["menu_sort"] != null && row["menu_sort"].ToString() != "") { model.menu_sort = int.Parse(row["menu_sort"].ToString()); } if (row["menu_path"] != null) { model.menu_path = row["menu_path"].ToString(); } if (row["menu_valid"] != null) { model.menu_valid = row["menu_valid"].ToString(); } } return(model); }
private void ShowInfo(int menu_ID) { WalleProject.BLL.t_menu bll = new WalleProject.BLL.t_menu(); WalleProject.Model.t_menu model = bll.GetModel(menu_ID); this.lblmenu_ID.Text = model.menu_ID.ToString(); this.lblmenu_Cate_ID.Text = model.menu_Cate_ID.ToString(); this.lblmenu_name.Text = model.menu_name; this.lblmenu_sort.Text = model.menu_sort.ToString(); this.lblmenu_path.Text = model.menu_path; this.lblmenu_valid.Text = model.menu_valid; }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtmenu_Cate_ID.Text)) { strErr += "menu_Cate_ID格式错误!\\n"; } if (this.txtmenu_name.Text.Trim().Length == 0) { strErr += "menu_name不能为空!\\n"; } if (!PageValidate.IsNumber(txtmenu_sort.Text)) { strErr += "menu_sort格式错误!\\n"; } if (this.txtmenu_path.Text.Trim().Length == 0) { strErr += "menu_path不能为空!\\n"; } if (this.txtmenu_valid.Text.Trim().Length == 0) { strErr += "menu_valid不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int menu_Cate_ID = int.Parse(this.txtmenu_Cate_ID.Text); string menu_name = this.txtmenu_name.Text; int menu_sort = int.Parse(this.txtmenu_sort.Text); string menu_path = this.txtmenu_path.Text; string menu_valid = this.txtmenu_valid.Text; WalleProject.Model.t_menu model = new WalleProject.Model.t_menu(); model.menu_Cate_ID = menu_Cate_ID; model.menu_name = menu_name; model.menu_sort = menu_sort; model.menu_path = menu_path; model.menu_valid = menu_valid; WalleProject.BLL.t_menu bll = new WalleProject.BLL.t_menu(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WalleProject.Model.t_menu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_menu set "); strSql.Append("menu_Cate_ID=@menu_Cate_ID,"); strSql.Append("menu_name=@menu_name,"); strSql.Append("menu_sort=@menu_sort,"); strSql.Append("menu_path=@menu_path,"); strSql.Append("menu_valid=@menu_valid"); strSql.Append(" where menu_ID=@menu_ID"); MySqlParameter[] parameters = { new MySqlParameter("@menu_Cate_ID", MySqlDbType.Int32, 10), new MySqlParameter("@menu_name", MySqlDbType.VarChar, 10), new MySqlParameter("@menu_sort", MySqlDbType.Int32, 10), new MySqlParameter("@menu_path", MySqlDbType.VarChar, 50), new MySqlParameter("@menu_valid", MySqlDbType.VarChar, 2), new MySqlParameter("@menu_ID", MySqlDbType.Int32, 10) }; parameters[0].Value = model.menu_Cate_ID; parameters[1].Value = model.menu_name; parameters[2].Value = model.menu_sort; parameters[3].Value = model.menu_path; parameters[4].Value = model.menu_valid; parameters[5].Value = model.menu_ID; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WalleProject.Model.t_menu GetModel(int menu_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select menu_ID,menu_Cate_ID,menu_name,menu_sort,menu_path,menu_valid from t_menu "); strSql.Append(" where menu_ID=@menu_ID"); MySqlParameter[] parameters = { new MySqlParameter("@menu_ID", MySqlDbType.Int32) }; parameters[0].Value = menu_ID; WalleProject.Model.t_menu model = new WalleProject.Model.t_menu(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }