/// <summary> /// 增加一条数据 /// </summary> public bool Add(WalleProject.Model.t_file model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into t_file("); strSql.Append("file_date,file_title,file_catefory_ID,file_Name,file_valid)"); strSql.Append(" values ("); strSql.Append("@file_date,@file_title,@file_catefory_ID,@file_Name,@file_valid)"); MySqlParameter[] parameters = { new MySqlParameter("@file_date", MySqlDbType.DateTime), new MySqlParameter("@file_title", MySqlDbType.VarChar, 20), new MySqlParameter("@file_catefory_ID", MySqlDbType.Int32, 10), new MySqlParameter("@file_Name", MySqlDbType.VarChar, 50), new MySqlParameter("@file_valid", MySqlDbType.VarChar, 2) }; parameters[0].Value = model.file_date; parameters[1].Value = model.file_title; parameters[2].Value = model.file_catefory_ID; parameters[3].Value = model.file_Name; parameters[4].Value = model.file_valid; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WalleProject.Model.t_file DataRowToModel(DataRow row) { WalleProject.Model.t_file model = new WalleProject.Model.t_file(); if (row != null) { if (row["file_ID"] != null && row["file_ID"].ToString() != "") { model.file_ID = int.Parse(row["file_ID"].ToString()); } if (row["file_date"] != null && row["file_date"].ToString() != "") { model.file_date = DateTime.Parse(row["file_date"].ToString()); } if (row["file_title"] != null) { model.file_title = row["file_title"].ToString(); } if (row["file_catefory_ID"] != null && row["file_catefory_ID"].ToString() != "") { model.file_catefory_ID = int.Parse(row["file_catefory_ID"].ToString()); } if (row["file_Name"] != null) { model.file_Name = row["file_Name"].ToString(); } if (row["file_valid"] != null) { model.file_valid = row["file_valid"].ToString(); } } return(model); }
private void ShowInfo(int file_ID) { WalleProject.BLL.t_file bll = new WalleProject.BLL.t_file(); WalleProject.Model.t_file model = bll.GetModel(file_ID); this.lblfile_ID.Text = model.file_ID.ToString(); this.txtfile_date.Text = model.file_date.ToString(); this.txtfile_title.Text = model.file_title; this.txtfile_catefory_ID.Text = model.file_catefory_ID.ToString(); this.txtfile_Name.Text = model.file_Name; this.txtfile_valid.Text = model.file_valid; }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsDateTime(txtfile_date.Text)) { strErr += "file_date格式错误!\\n"; } if (this.txtfile_title.Text.Trim().Length == 0) { strErr += "file_title不能为空!\\n"; } if (!PageValidate.IsNumber(txtfile_catefory_ID.Text)) { strErr += "file_catefory_ID格式错误!\\n"; } if (this.txtfile_Name.Text.Trim().Length == 0) { strErr += "file_Name不能为空!\\n"; } if (this.txtfile_valid.Text.Trim().Length == 0) { strErr += "file_valid不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int file_ID = int.Parse(this.lblfile_ID.Text); DateTime file_date = DateTime.Parse(this.txtfile_date.Text); string file_title = this.txtfile_title.Text; int file_catefory_ID = int.Parse(this.txtfile_catefory_ID.Text); string file_Name = this.txtfile_Name.Text; string file_valid = this.txtfile_valid.Text; WalleProject.Model.t_file model = new WalleProject.Model.t_file(); model.file_ID = file_ID; model.file_date = file_date; model.file_title = file_title; model.file_catefory_ID = file_catefory_ID; model.file_Name = file_Name; model.file_valid = file_valid; WalleProject.BLL.t_file bll = new WalleProject.BLL.t_file(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WalleProject.Model.t_file model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_file set "); strSql.Append("file_date=@file_date,"); strSql.Append("file_title=@file_title,"); strSql.Append("file_catefory_ID=@file_catefory_ID,"); strSql.Append("file_Name=@file_Name,"); strSql.Append("file_valid=@file_valid"); strSql.Append(" where file_ID=@file_ID"); MySqlParameter[] parameters = { new MySqlParameter("@file_date", MySqlDbType.DateTime), new MySqlParameter("@file_title", MySqlDbType.VarChar, 20), new MySqlParameter("@file_catefory_ID", MySqlDbType.Int32, 10), new MySqlParameter("@file_Name", MySqlDbType.VarChar, 50), new MySqlParameter("@file_valid", MySqlDbType.VarChar, 2), new MySqlParameter("@file_ID", MySqlDbType.Int32, 10) }; parameters[0].Value = model.file_date; parameters[1].Value = model.file_title; parameters[2].Value = model.file_catefory_ID; parameters[3].Value = model.file_Name; parameters[4].Value = model.file_valid; parameters[5].Value = model.file_ID; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WalleProject.Model.t_file GetModel(int file_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select file_ID,file_date,file_title,file_catefory_ID,file_Name,file_valid from t_file "); strSql.Append(" where file_ID=@file_ID"); MySqlParameter[] parameters = { new MySqlParameter("@file_ID", MySqlDbType.Int32) }; parameters[0].Value = file_ID; WalleProject.Model.t_file model = new WalleProject.Model.t_file(); 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 WalleProject.Model.t_file GetFileModel(int file_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from t_file inner join t_filecategory on t_file.file_catefory_ID=t_filecategory.filec_ID "); strSql.Append(" where file_ID=@file_ID"); MySqlParameter[] parameters = { new MySqlParameter("@file_ID", MySqlDbType.Int32) }; parameters[0].Value = file_ID; DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; WalleProject.Model.t_file model = new WalleProject.Model.t_file(); if (row != null) { if (row["file_ID"] != null && row["file_ID"].ToString() != "") { model.file_ID = int.Parse(row["file_ID"].ToString()); } if (row["file_date"] != null && row["file_date"].ToString() != "") { model.file_date = DateTime.Parse(row["file_date"].ToString()); } if (row["file_title"] != null) { model.file_title = row["file_title"].ToString(); } if (row["file_catefory_ID"] != null && row["file_catefory_ID"].ToString() != "") { model.file_catefory_ID = int.Parse(row["file_catefory_ID"].ToString()); } if (row["file_Name"] != null) { model.file_Name = row["file_Name"].ToString(); } if (row["file_valid"] != null) { model.file_valid = row["file_valid"].ToString(); } if (row["filec_name"] != null) { model.file.filec_name = row["filec_name"].ToString(); } if (row["filec_path"] != null) { model.file.filec_path = row["filec_path"].ToString(); } if (row["file_ext"] != null) { model.file.file_ext = row["file_ext"].ToString(); } } return(model); } else { return(null); } }