/// <summary> /// 更新一条数据 /// </summary> public bool Update(WalleProject.Model.t_picture model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_picture set "); strSql.Append("pic_cate_ID=@pic_cate_ID,"); strSql.Append("pic_date=@pic_date,"); strSql.Append("pic_name=@pic_name,"); strSql.Append("pic_valid=@pic_valid"); strSql.Append(" where pic_ID=@pic_ID"); MySqlParameter[] parameters = { new MySqlParameter("@pic_cate_ID", MySqlDbType.Int32, 10), new MySqlParameter("@pic_date", MySqlDbType.DateTime), new MySqlParameter("@pic_name", MySqlDbType.VarChar, 10), new MySqlParameter("@pic_valid", MySqlDbType.VarChar, 2), new MySqlParameter("@pic_ID", MySqlDbType.Int32, 10) }; parameters[0].Value = model.pic_cate_ID; parameters[1].Value = model.pic_date; parameters[2].Value = model.pic_name; parameters[3].Value = model.pic_valid; parameters[4].Value = model.pic_ID; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(WalleProject.Model.t_picture model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into t_picture("); strSql.Append("pic_cate_ID,pic_date,pic_name,pic_valid)"); strSql.Append(" values ("); strSql.Append("@pic_cate_ID,@pic_date,@pic_name,@pic_valid)"); MySqlParameter[] parameters = { new MySqlParameter("@pic_cate_ID", MySqlDbType.Int32, 10), new MySqlParameter("@pic_date", MySqlDbType.DateTime), new MySqlParameter("@pic_name", MySqlDbType.VarChar, 10), new MySqlParameter("@pic_valid", MySqlDbType.VarChar, 2) }; parameters[0].Value = model.pic_cate_ID; parameters[1].Value = model.pic_date; parameters[2].Value = model.pic_name; parameters[3].Value = model.pic_valid; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WalleProject.Model.t_picture DataRowToModel(DataRow row) { WalleProject.Model.t_picture model = new WalleProject.Model.t_picture(); if (row != null) { if (row["pic_cate_ID"] != null && row["pic_cate_ID"].ToString() != "") { model.pic_cate_ID = int.Parse(row["pic_cate_ID"].ToString()); } if (row["pic_ID"] != null && row["pic_ID"].ToString() != "") { model.pic_ID = int.Parse(row["pic_ID"].ToString()); } if (row["pic_date"] != null && row["pic_date"].ToString() != "") { model.pic_date = DateTime.Parse(row["pic_date"].ToString()); } if (row["pic_name"] != null) { model.pic_name = row["pic_name"].ToString(); } if (row["pic_valid"] != null) { model.pic_valid = row["pic_valid"].ToString(); } } return(model); }
private void ShowInfo(int pic_ID) { WalleProject.BLL.t_picture bll = new WalleProject.BLL.t_picture(); WalleProject.Model.t_picture model = bll.GetModel(pic_ID); this.lblpic_cate_ID.Text = model.pic_cate_ID.ToString(); this.lblpic_ID.Text = model.pic_ID.ToString(); this.lblpic_date.Text = model.pic_date.ToString(); this.lblpic_name.Text = model.pic_name; this.lblpic_valid.Text = model.pic_valid; }
/// <summary> /// 得到一个对象实体(连接两个表) /// </summary> public WalleProject.Model.t_picture GetPicturModel(int pic_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"SELECT * from t_picture inner join t_picturecategory on t_picture.pic_cate_ID=t_picturecategory.picca_ID"); strSql.Append(" where pic_ID=@pic_ID"); MySqlParameter[] parameters = { new MySqlParameter("@pic_ID", MySqlDbType.Int32) }; parameters[0].Value = pic_ID; WalleProject.Model.t_picture model = new WalleProject.Model.t_picture(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (row != null) { if (row["pic_cate_ID"] != null && row["pic_cate_ID"].ToString() != "") { model.pic_cate_ID = int.Parse(row["pic_cate_ID"].ToString()); } if (row["pic_ID"] != null && row["pic_ID"].ToString() != "") { model.pic_ID = int.Parse(row["pic_ID"].ToString()); } if (row["pic_date"] != null && row["pic_date"].ToString() != "") { model.pic_date = DateTime.Parse(row["pic_date"].ToString()); } if (row["pic_name"] != null) { model.pic_name = row["pic_name"].ToString(); } if (row["pic_valid"] != null) { model.pic_valid = row["pic_valid"].ToString(); } if (row["picca_name"] != null) { model.picturecategory.picca_name = row["picca_name"].ToString(); } } return(model); } else { return(null); } }
private void ShowInfo(int pic_ID) { WalleProject.BLL.t_picture bll = new WalleProject.BLL.t_picture(); WalleProject.Model.t_picture model = bll.GetPicturModel(pic_ID); this.lblpic_cate_ID.Text = model.picturecategory.picca_name; this.lblpic_ID.Text = model.pic_ID.ToString(); this.lblpic_date.Text = model.pic_date.ToString(); this.lblpic_name.Text = model.pic_name; this.lblpic_valid.Text = model.pic_valid; this.ddl_edit.SelectedValue = model.pic_cate_ID.ToString(); this.edit_date.Text = model.pic_date.ToString(); this.edit_name.Text = model.pic_name; this.edit_path.Text = model.pic_valid; img.Src = model.pic_valid; }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtpic_cate_ID.Text)) { strErr += "pic_cate_ID格式错误!\\n"; } if (!PageValidate.IsDateTime(txtpic_date.Text)) { strErr += "pic_date格式错误!\\n"; } if (this.txtpic_name.Text.Trim().Length == 0) { strErr += "pic_name不能为空!\\n"; } if (this.txtpic_valid.Text.Trim().Length == 0) { strErr += "pic_valid不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int pic_cate_ID = int.Parse(this.txtpic_cate_ID.Text); int pic_ID = int.Parse(this.lblpic_ID.Text); DateTime pic_date = DateTime.Parse(this.txtpic_date.Text); string pic_name = this.txtpic_name.Text; string pic_valid = this.txtpic_valid.Text; WalleProject.Model.t_picture model = new WalleProject.Model.t_picture(); model.pic_cate_ID = pic_cate_ID; model.pic_ID = pic_ID; model.pic_date = pic_date; model.pic_name = pic_name; model.pic_valid = pic_valid; WalleProject.BLL.t_picture bll = new WalleProject.BLL.t_picture(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
protected void edit_save_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(ddl_edit.SelectedValue)) { strErr += "格式错误!\\n"; } if (!PageValidate.IsDateTime(edit_date.Text)) { strErr += "时间格式错误!\\n"; } if (this.edit_name.Text.Trim().Length == 0) { strErr += " 不能为空!\\n"; } if (this.edit_path.Text.Trim().Length == 0) { strErr += " 不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int pic_cate_ID = int.Parse(this.ddl_edit.SelectedValue); DateTime pic_date = DateTime.Parse(this.edit_date.Text); string pic_name = this.edit_name.Text; string pic_valid = this.edit_path.Text; WalleProject.Model.t_picture model = new WalleProject.Model.t_picture(); model.pic_cate_ID = pic_cate_ID; model.pic_date = pic_date; model.pic_name = pic_name; model.pic_valid = pic_valid; model.pic_ID = Convert.ToInt32(Request.Params["id"]); WalleProject.BLL.t_picture bll = new WalleProject.BLL.t_picture(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "ImageView.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public WalleProject.Model.t_picture GetModel(int pic_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select pic_cate_ID,pic_ID,pic_date,pic_name,pic_valid from t_picture "); strSql.Append(" where pic_ID=@pic_ID"); MySqlParameter[] parameters = { new MySqlParameter("@pic_ID", MySqlDbType.Int32) }; parameters[0].Value = pic_ID; WalleProject.Model.t_picture model = new WalleProject.Model.t_picture(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }