Example #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(zs.Model.Tbl_User model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Tbl_User set ");
            strSql.Append("userName=@userName,");
            strSql.Append("userPsw=@userPsw");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@userName", SqlDbType.VarChar, 50),
                new SqlParameter("@userPsw",  SqlDbType.VarChar, 70),
                new SqlParameter("@id",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.userName;
            parameters[1].Value = model.userPsw;
            parameters[2].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(zs.Model.Tbl_User model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Tbl_User(");
            strSql.Append("userName,userPsw)");
            strSql.Append(" values (");
            strSql.Append("@userName,@userPsw)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@userName", SqlDbType.VarChar, 50),
                new SqlParameter("@userPsw",  SqlDbType.VarChar, 70)
            };
            parameters[0].Value = model.userName;
            parameters[1].Value = model.userPsw;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #3
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtuserName.Text.Trim().Length == 0)
            {
                strErr += "userName不能为空!\\n";
            }
            if (this.txtuserPsw.Text.Trim().Length == 0)
            {
                strErr += "userPsw不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int    id       = int.Parse(this.lblid.Text);
            string userName = this.txtuserName.Text;
            string userPsw  = this.txtuserPsw.Text;


            zs.Model.Tbl_User model = new zs.Model.Tbl_User();
            model.id       = id;
            model.userName = userName;
            model.userPsw  = userPsw;

            zs.BLL.Tbl_User bll = new zs.BLL.Tbl_User();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }
Example #4
0
 private void ShowInfo(int id)
 {
     zs.BLL.Tbl_User   bll   = new zs.BLL.Tbl_User();
     zs.Model.Tbl_User model = bll.GetModel(id);
     this.lblid.Text       = model.id.ToString();
     this.txtuserName.Text = model.userName;
     this.txtuserPsw.Text  = model.userPsw;
 }
Example #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public zs.Model.Tbl_User GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,userName,userPsw from Tbl_User ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            zs.Model.Tbl_User model = new zs.Model.Tbl_User();
            DataSet           ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["userName"] != null && ds.Tables[0].Rows[0]["userName"].ToString() != "")
                {
                    model.userName = ds.Tables[0].Rows[0]["userName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["userPsw"] != null && ds.Tables[0].Rows[0]["userPsw"].ToString() != "")
                {
                    model.userPsw = ds.Tables[0].Rows[0]["userPsw"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }