/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.LogList model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update LogList set "); strSql.Append("LogTitle=@LogTitle,"); strSql.Append("LogType=@LogType,"); strSql.Append("LogDate=@LogDate,"); strSql.Append("logData=@logData"); strSql.Append(" where LogID=@LogID"); SqlParameter[] parameters = { new SqlParameter("@LogTitle", SqlDbType.VarChar, 3000), new SqlParameter("@LogType", SqlDbType.VarChar, 50), new SqlParameter("@LogDate", SqlDbType.DateTime), new SqlParameter("@logData", SqlDbType.VarChar, 4500), new SqlParameter("@LogID", SqlDbType.Int, 4) }; parameters[0].Value = model.LogTitle; parameters[1].Value = model.LogType; parameters[2].Value = model.LogDate; parameters[3].Value = model.logData; parameters[4].Value = model.LogID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WebDemo.Model.WebDemo.LogList model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into LogList("); strSql.Append("LogTitle,LogType,LogDate,logData)"); strSql.Append(" values ("); strSql.Append("@LogTitle,@LogType,@LogDate,@logData)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@LogTitle", SqlDbType.VarChar, 3000), new SqlParameter("@LogType", SqlDbType.VarChar, 50), new SqlParameter("@LogDate", SqlDbType.DateTime), new SqlParameter("@logData", SqlDbType.VarChar, 4500) }; parameters[0].Value = model.LogTitle; parameters[1].Value = model.LogType; parameters[2].Value = model.LogDate; parameters[3].Value = model.logData; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.LogList DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.LogList model = new WebDemo.Model.WebDemo.LogList(); if (row != null) { if (row["LogID"] != null && row["LogID"].ToString() != "") { model.LogID = int.Parse(row["LogID"].ToString()); } if (row["LogTitle"] != null) { model.LogTitle = row["LogTitle"].ToString(); } if (row["LogType"] != null) { model.LogType = row["LogType"].ToString(); } if (row["LogDate"] != null && row["LogDate"].ToString() != "") { model.LogDate = DateTime.Parse(row["LogDate"].ToString()); } if (row["logData"] != null) { model.logData = row["logData"].ToString(); } } return(model); }
private void ShowInfo(int LogID) { WebDemo.BLL.WebDemo.LogList bll = new WebDemo.BLL.WebDemo.LogList(); WebDemo.Model.WebDemo.LogList model = bll.GetModel(LogID); this.lblLogID.Text = model.LogID.ToString(); this.lblLogTitle.Text = model.LogTitle; this.lblLogType.Text = model.LogType; this.lblLogDate.Text = model.LogDate.ToString(); this.lbllogData.Text = model.logData; }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtLogTitle.Text.Trim().Length == 0) { strErr += "LogTitle不能为空!\\n"; } if (this.txtLogType.Text.Trim().Length == 0) { strErr += "LogType不能为空!\\n"; } if (!PageValidate.IsDateTime(txtLogDate.Text)) { strErr += "LogDate格式错误!\\n"; } if (this.txtlogData.Text.Trim().Length == 0) { strErr += "logData不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int LogID = int.Parse(this.lblLogID.Text); string LogTitle = this.txtLogTitle.Text; string LogType = this.txtLogType.Text; DateTime LogDate = DateTime.Parse(this.txtLogDate.Text); string logData = this.txtlogData.Text; WebDemo.Model.WebDemo.LogList model = new WebDemo.Model.WebDemo.LogList(); model.LogID = LogID; model.LogTitle = LogTitle; model.LogType = LogType; model.LogDate = LogDate; model.logData = logData; WebDemo.BLL.WebDemo.LogList bll = new WebDemo.BLL.WebDemo.LogList(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.LogList GetModel(int LogID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 LogID,LogTitle,LogType,LogDate,logData from LogList "); strSql.Append(" where LogID=@LogID"); SqlParameter[] parameters = { new SqlParameter("@LogID", SqlDbType.Int, 4) }; parameters[0].Value = LogID; WebDemo.Model.WebDemo.LogList model = new WebDemo.Model.WebDemo.LogList(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }