/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.tb_UserLoginRecords model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_UserLoginRecords set "); strSql.Append("UserID=@UserID,"); strSql.Append("Action=@Action,"); strSql.Append("DateTime=@DateTime,"); strSql.Append("WorkType=@WorkType"); strSql.Append(" where "); SqlParameter[] parameters = { new SqlParameter("@UserID", SqlDbType.VarChar, 50), new SqlParameter("@Action", SqlDbType.VarChar, 10), new SqlParameter("@DateTime", SqlDbType.VarChar, 50), new SqlParameter("@WorkType", SqlDbType.VarChar, 50) }; parameters[0].Value = model.UserID; parameters[1].Value = model.Action; parameters[2].Value = model.DateTime; parameters[3].Value = model.WorkType; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.tb_UserLoginRecords model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_UserLoginRecords("); strSql.Append("UserID,Action,DateTime,WorkType)"); strSql.Append(" values ("); strSql.Append("@UserID,@Action,@DateTime,@WorkType)"); SqlParameter[] parameters = { new SqlParameter("@UserID", SqlDbType.VarChar, 50), new SqlParameter("@Action", SqlDbType.VarChar, 10), new SqlParameter("@DateTime", SqlDbType.VarChar, 50), new SqlParameter("@WorkType", SqlDbType.VarChar, 50) }; parameters[0].Value = model.UserID; parameters[1].Value = model.Action; parameters[2].Value = model.DateTime; parameters[3].Value = model.WorkType; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void ShowInfo() { Maticsoft.BLL.tb_UserLoginRecords bll = new Maticsoft.BLL.tb_UserLoginRecords(); Maticsoft.Model.tb_UserLoginRecords model = bll.GetModel(); this.lblUserID.Text = model.UserID; this.lblAction.Text = model.Action; this.lblDateTime.Text = model.DateTime; this.lblWorkType.Text = model.WorkType; }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtUserID.Text.Trim().Length == 0) { strErr += "UserID不能为空!\\n"; } if (this.txtAction.Text.Trim().Length == 0) { strErr += "Action不能为空!\\n"; } if (this.txtDateTime.Text.Trim().Length == 0) { strErr += "DateTime不能为空!\\n"; } if (this.txtWorkType.Text.Trim().Length == 0) { strErr += "WorkType不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string UserID = this.txtUserID.Text; string Action = this.txtAction.Text; string DateTime = this.txtDateTime.Text; string WorkType = this.txtWorkType.Text; Maticsoft.Model.tb_UserLoginRecords model = new Maticsoft.Model.tb_UserLoginRecords(); model.UserID = UserID; model.Action = Action; model.DateTime = DateTime; model.WorkType = WorkType; Maticsoft.BLL.tb_UserLoginRecords bll = new Maticsoft.BLL.tb_UserLoginRecords(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.tb_UserLoginRecords GetModel() { //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 UserID,Action,DateTime,WorkType from tb_UserLoginRecords "); strSql.Append(" where "); SqlParameter[] parameters = { }; Maticsoft.Model.tb_UserLoginRecords model = new Maticsoft.Model.tb_UserLoginRecords(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.tb_UserLoginRecords DataRowToModel(DataRow row) { Maticsoft.Model.tb_UserLoginRecords model = new Maticsoft.Model.tb_UserLoginRecords(); if (row != null) { if (row["UserID"] != null) { model.UserID = row["UserID"].ToString(); } if (row["Action"] != null) { model.Action = row["Action"].ToString(); } if (row["DateTime"] != null) { model.DateTime = row["DateTime"].ToString(); } if (row["WorkType"] != null) { model.WorkType = row["WorkType"].ToString(); } } return(model); }