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