Пример #1
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (!PageValidate.IsNumber(txtid.Text))
            {
                strErr += "id格式错误!\\n";
            }
            if (this.txttitle.Text.Trim().Length == 0)
            {
                strErr += "title不能为空!\\n";
            }
            if (this.txtthumb.Text.Trim().Length == 0)
            {
                strErr += "thumb不能为空!\\n";
            }
            if (this.txtconts.Text.Trim().Length == 0)
            {
                strErr += "conts不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtaddtime.Text))
            {
                strErr += "addtime格式错误!\\n";
            }
            if (this.txtauthor.Text.Trim().Length == 0)
            {
                strErr += "author不能为空!\\n";
            }
            if (!PageValidate.IsNumber(txtleiid.Text))
            {
                strErr += "leiid格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int      id      = int.Parse(this.txtid.Text);
            string   title   = this.txttitle.Text;
            string   thumb   = this.txtthumb.Text;
            string   conts   = this.txtconts.Text;
            DateTime addtime = DateTime.Parse(this.txtaddtime.Text);
            string   author  = this.txtauthor.Text;
            int      leiid   = int.Parse(this.txtleiid.Text);


            zs.Model.Tbl_Video model = new zs.Model.Tbl_Video();
            model.id      = id;
            model.title   = title;
            model.thumb   = thumb;
            model.conts   = conts;
            model.addtime = addtime;
            model.author  = author;
            model.leiid   = leiid;

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

            strSql.Append("select  top 1 id,title,thumb,videourl,conts,addtime,author,leiid from Tbl_Video ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            zs.Model.Tbl_Video model = new zs.Model.Tbl_Video();
            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]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "")
                {
                    model.title = ds.Tables[0].Rows[0]["title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["thumb"] != null && ds.Tables[0].Rows[0]["thumb"].ToString() != "")
                {
                    model.thumb = ds.Tables[0].Rows[0]["thumb"].ToString();
                }
                if (ds.Tables[0].Rows[0]["videourl"] != null && ds.Tables[0].Rows[0]["videourl"].ToString() != "")
                {
                    model.videourl = ds.Tables[0].Rows[0]["videourl"].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]["addtime"] != null && ds.Tables[0].Rows[0]["addtime"].ToString() != "")
                {
                    model.addtime = DateTime.Parse(ds.Tables[0].Rows[0]["addtime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["author"] != null && ds.Tables[0].Rows[0]["author"].ToString() != "")
                {
                    model.author = ds.Tables[0].Rows[0]["author"].ToString();
                }
                if (ds.Tables[0].Rows[0]["leiid"] != null && ds.Tables[0].Rows[0]["leiid"].ToString() != "")
                {
                    model.leiid = int.Parse(ds.Tables[0].Rows[0]["leiid"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
 private void ShowInfo()
 {
     zs.BLL.Tbl_Video   bll   = new zs.BLL.Tbl_Video();
     zs.Model.Tbl_Video model = bll.GetModel();
     this.lblid.Text      = model.id.ToString();
     this.lbltitle.Text   = model.title;
     this.lblthumb.Text   = model.thumb;
     this.lblconts.Text   = model.conts;
     this.lbladdtime.Text = model.addtime.ToString();
     this.lblauthor.Text  = model.author;
     this.lblleiid.Text   = model.leiid.ToString();
 }
Пример #4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(zs.Model.Tbl_Video model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Tbl_Video set ");
            strSql.Append("title=@title,");
            strSql.Append("thumb=@thumb,");
            strSql.Append("videourl=@videourl,");
            strSql.Append("conts=@conts,");
            strSql.Append("addtime=@addtime,");
            strSql.Append("author=@author,");
            strSql.Append("leiid=@leiid");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@title",    SqlDbType.VarChar,   150),
                new SqlParameter("@thumb",    SqlDbType.VarChar,   150),
                new SqlParameter("@videourl", SqlDbType.VarChar,   150),
                new SqlParameter("@conts",    SqlDbType.VarChar),
                new SqlParameter("@addtime",  SqlDbType.DateTime),
                new SqlParameter("@author",   SqlDbType.VarChar,    50),
                new SqlParameter("@leiid",    SqlDbType.Int,         4),
                new SqlParameter("@id",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.title;
            parameters[1].Value = model.thumb;
            parameters[2].Value = model.videourl;
            parameters[3].Value = model.conts;
            parameters[4].Value = model.addtime;
            parameters[5].Value = model.author;
            parameters[6].Value = model.leiid;
            parameters[7].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #5
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(zs.Model.Tbl_Video model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Tbl_Video(");
            strSql.Append("title,thumb,videourl,conts,addtime,author,leiid)");
            strSql.Append(" values (");
            strSql.Append("@title,@thumb,@videourl,@conts,@addtime,@author,@leiid)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@title",    SqlDbType.VarChar,   150),
                new SqlParameter("@thumb",    SqlDbType.VarChar,   150),
                new SqlParameter("@videourl", SqlDbType.VarChar,   150),
                new SqlParameter("@conts",    SqlDbType.VarChar),
                new SqlParameter("@addtime",  SqlDbType.DateTime),
                new SqlParameter("@author",   SqlDbType.VarChar,    50),
                new SqlParameter("@leiid",    SqlDbType.Int, 4)
            };
            parameters[0].Value = model.title;
            parameters[1].Value = model.thumb;
            parameters[2].Value = model.videourl;
            parameters[3].Value = model.conts;
            parameters[4].Value = model.addtime;
            parameters[5].Value = model.author;
            parameters[6].Value = model.leiid;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }