コード例 #1
0
ファイル: Student.cs プロジェクト: MingXingTeam/rbac
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Ncu.jsj.Model.Student model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Student set ");
            strSql.Append("name=@name,");
            strSql.Append("age=@age,");
            strSql.Append("pictureurl=@pictureurl");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@name",       SqlDbType.NChar, 20),
                new SqlParameter("@age",        SqlDbType.Int,    4),
                new SqlParameter("@pictureurl", SqlDbType.NChar, 30),
                new SqlParameter("@id",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.name;
            parameters[1].Value = model.age;
            parameters[2].Value = model.pictureurl;
            parameters[3].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: Student.cs プロジェクト: MingXingTeam/rbac
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Ncu.jsj.Model.Student model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Student(");
            strSql.Append("name,age,pictureurl,sex)");
            strSql.Append(" values (");
            strSql.Append("@name,@age,@pictureurl,@sex)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@name",       SqlDbType.NChar, 20),
                new SqlParameter("@age",        SqlDbType.Int,    4),
                new SqlParameter("@pictureurl", SqlDbType.NChar, 30),
                new SqlParameter("@sex",        SqlDbType.Bit)
            };
            parameters[0].Value = model.name;
            parameters[1].Value = model.age;
            parameters[2].Value = model.pictureurl;
            parameters[3].Value = model.sex;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtname.Text.Trim().Length == 0)
            {
                strErr += "name不能为空!\\n";
            }
            if (!PageValidate.IsNumber(txtage.Text))
            {
                strErr += "age格式错误!\\n";
            }
            if (this.txtpictureurl.Text.Trim().Length == 0)
            {
                strErr += "pictureurl不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string name       = this.txtname.Text;
            int    age        = int.Parse(this.txtage.Text);
            string pictureurl = this.txtpictureurl.Text;

            Ncu.jsj.Model.Student model = new Ncu.jsj.Model.Student();
            model.name       = name;
            model.age        = age;
            model.pictureurl = pictureurl;

            Ncu.jsj.BLL.Student bll = new Ncu.jsj.BLL.Student();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }
コード例 #4
0
ファイル: Show.aspx.cs プロジェクト: MingXingTeam/rbac
 private void ShowInfo(int id)
 {
     Ncu.jsj.BLL.Student   bll   = new Ncu.jsj.BLL.Student();
     Ncu.jsj.Model.Student model = bll.GetModel(id);
     this.lblid.Text         = model.id.ToString();
     this.lblname.Text       = model.name;
     this.lblage.Text        = model.age.ToString();
     this.lblpictureurl.Text = model.pictureurl;
 }
コード例 #5
0
ファイル: Student.cs プロジェクト: MingXingTeam/rbac
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Ncu.jsj.Model.Student GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

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

            Ncu.jsj.Model.Student model = new Ncu.jsj.Model.Student();
            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]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "")
                {
                    model.name = ds.Tables[0].Rows[0]["name"].ToString();
                }
                if (ds.Tables[0].Rows[0]["age"] != null && ds.Tables[0].Rows[0]["age"].ToString() != "")
                {
                    model.age = int.Parse(ds.Tables[0].Rows[0]["age"].ToString());
                }
                if (ds.Tables[0].Rows[0]["pictureurl"] != null && ds.Tables[0].Rows[0]["pictureurl"].ToString() != "")
                {
                    model.pictureurl = ds.Tables[0].Rows[0]["pictureurl"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }