Beispiel #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(zs.Model.Tbl_Page model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Tbl_Page(");
            strSql.Append("name,conts,metatags,metadescription)");
            strSql.Append(" values (");
            strSql.Append("@name,@conts,@metatags,@metadescription)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@name",            SqlDbType.VarChar,  50),
                new SqlParameter("@conts",           SqlDbType.VarChar),
                new SqlParameter("@metatags",        SqlDbType.VarChar,  50),
                new SqlParameter("@metadescription", SqlDbType.VarChar, 150)
            };
            parameters[0].Value = model.name;
            parameters[1].Value = model.conts;
            parameters[2].Value = model.metatags;
            parameters[3].Value = model.metadescription;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(zs.Model.Tbl_Page model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Tbl_Page set ");
            strSql.Append("name=@name,");
            strSql.Append("conts=@conts,");
            strSql.Append("metatags=@metatags,");
            strSql.Append("metadescription=@metadescription");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@name",            SqlDbType.VarChar,   50),
                new SqlParameter("@conts",           SqlDbType.VarChar),
                new SqlParameter("@metatags",        SqlDbType.VarChar,   50),
                new SqlParameter("@metadescription", SqlDbType.VarChar,  150),
                new SqlParameter("@id",              SqlDbType.Int, 4)
            };
            parameters[0].Value = model.name;
            parameters[1].Value = model.conts;
            parameters[2].Value = model.metatags;
            parameters[3].Value = model.metadescription;
            parameters[4].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
 private void ShowInfo(int id)
 {
     zs.BLL.Tbl_Page   bll   = new zs.BLL.Tbl_Page();
     zs.Model.Tbl_Page model = bll.GetModel(id);
     this.lblid.Text              = model.id.ToString();
     this.txtname.Text            = model.name;
     this.txtconts.Text           = model.conts;
     this.txtmetatags.Text        = model.metatags;
     this.txtmetadescription.Text = model.metadescription;
 }
Beispiel #4
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtname.Text.Trim().Length == 0)
            {
                strErr += "name不能为空!\\n";
            }
            if (this.txtconts.Text.Trim().Length == 0)
            {
                strErr += "conts不能为空!\\n";
            }
            if (this.txtmetatags.Text.Trim().Length == 0)
            {
                strErr += "metatags不能为空!\\n";
            }
            if (this.txtmetadescription.Text.Trim().Length == 0)
            {
                strErr += "metadescription不能为空!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int    id              = int.Parse(this.lblid.Text);
            string name            = this.txtname.Text;
            string conts           = this.txtconts.Text;
            string metatags        = this.txtmetatags.Text;
            string metadescription = this.txtmetadescription.Text;


            zs.Model.Tbl_Page model = new zs.Model.Tbl_Page();
            model.id              = id;
            model.name            = name;
            model.conts           = conts;
            model.metatags        = metatags;
            model.metadescription = metadescription;

            zs.BLL.Tbl_Page bll = new zs.BLL.Tbl_Page();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }
Beispiel #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public zs.Model.Tbl_Page GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

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

            zs.Model.Tbl_Page model = new zs.Model.Tbl_Page();
            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]["conts"] != null && ds.Tables[0].Rows[0]["conts"].ToString() != "")
                {
                    model.conts = ds.Tables[0].Rows[0]["conts"].ToString();
                }
                if (ds.Tables[0].Rows[0]["metatags"] != null && ds.Tables[0].Rows[0]["metatags"].ToString() != "")
                {
                    model.metatags = ds.Tables[0].Rows[0]["metatags"].ToString();
                }
                if (ds.Tables[0].Rows[0]["metadescription"] != null && ds.Tables[0].Rows[0]["metadescription"].ToString() != "")
                {
                    model.metadescription = ds.Tables[0].Rows[0]["metadescription"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }