using System;
          using System.Collections.Generic;
          using System.Text;
          using System.Data;
          using System.Data.SqlClient;
          using domain.SQLDB;
          namespace domain.SQLDB
          {

          public class News{
          private string _Gid;
          private string _TypeId;
          private string _Title;
          private string _Keyword;
          private string _ComeFrom;
          private string _Author;
          private string _Content;
          private string _Pic;
          private string _IsCommand;
          private string _commandTime;
          private string _IsTop;
          private string _topTime;
          private string _AddTime;
          public string Gid{set{this._Gid=value;}get{return this._Gid;}}

          public string TypeId { set { this._TypeId = value; } get { return this._TypeId; } }
          public string Title { set { this._Title = value; } get { return this._Title; } }
              public string Keyword { set { this._Keyword = value; } get { return this._Keyword; } }
          public string ComeFrom{set{this._ComeFrom=value;}get{return this._ComeFrom;}}
          public string Author{set{this._Author=value;}get{return this._Author;}}
          public string Content{set{this._Content=value;}get{return this._Content;}}
          public string Pic{set{this._Pic=value;}get{return this._Pic;}}
          public string IsCommand{set{this._IsCommand=value;}get{return this._IsCommand;}}
          public string commandTime{set{this._commandTime=value;}get{return this._commandTime;}}
          public string IsTop{set{this._IsTop=value;}get{return this._IsTop;}}
          public string topTime{set{this._topTime=value;}get{return this._topTime;}}
          public string AddTime{set{this._AddTime=value;}get{return this._AddTime;}}

          DbAccess db = new DbAccess();
          public bool Add(){
          string sql = "insert into News([Gid],[Title],[ComeFrom],[Author],[Content],[Pic],[IsCommand],[commandTime],[IsTop],[topTime],[AddTime]) values(@Gid,@Title,@ComeFrom,@Author,@Content,@Pic,@IsCommand,@commandTime,@IsTop,@topTime,@AddTime)";
          SqlParameter[] pas = {new SqlParameter("@Gid",Gid),new SqlParameter("@Title",Title),new SqlParameter("@ComeFrom",ComeFrom),new SqlParameter("@Author",Author),new SqlParameter("@Content",Content),new SqlParameter("@Pic",Pic),new SqlParameter("@IsCommand",IsCommand),new SqlParameter("@commandTime",commandTime),new SqlParameter("@IsTop",IsTop),new SqlParameter("@topTime",topTime),new SqlParameter("@AddTime",AddTime)};
          return db.GetState(sql,pas);
          }

          public bool Update()
          {
              string sql = "if exists(select Gid from News where Gid=@Gid) begin  update News set [TypeId]=@TypeId,[Title]=@Title,[Keyword]=@keyword,[ComeFrom]=@ComeFrom,[Author]=@Author,[Content]=@Content,[Pic]=case when len(@Pic)>0 then @Pic else Pic end,[IsCommand]=@IsCommand,[commandTime]=@commandTime,[IsTop]=@IsTop,[topTime]=@topTime where Gid=@Gid end else begin insert into News([TypeId],[Title],[keyword],[ComeFrom],[Author],[Content],[Pic],[IsCommand],[commandTime],[IsTop],[topTime]) values(@TypeId,@Title,@keyword,@ComeFrom,@Author,@Content,@Pic,@IsCommand,@commandTime,@IsTop,@topTime) end";
              SqlParameter[] pas = { new SqlParameter("@Gid", Gid), new SqlParameter("@TypeId", TypeId), new SqlParameter("@Title", Title), new SqlParameter("@keyword", Keyword), new SqlParameter("@ComeFrom", ComeFrom), new SqlParameter("@Author", Author), new SqlParameter("@Content", Content), new SqlParameter("@Pic", Pic), new SqlParameter("@IsCommand", IsCommand), new SqlParameter("@commandTime", commandTime), new SqlParameter("@IsTop", IsTop), new SqlParameter("@topTime", topTime) };
          return db.GetState(sql,pas);
          }

          public bool Delete()
          {string sql = "delete News where [Gid]=@Gid";
          SqlParameter[] pas = {new SqlParameter("@Gid",Gid)};
          return db.GetState(sql,pas);
          }
          public DataTable Select()
          {
          DataTable dt = db.GetTable("select * from News")??new DataTable();
          return dt;
          }
          //查詢
          public News SelectById(){
          News  news = new News();
          string sql = "select * from News where Gid=@Gid";
          SqlParameter[] pas = {new SqlParameter("@Gid",Gid)};
          DataTable dt = db.GetTable(sql,pas);
            if(dt.Rows.Count>0)
              {
                news.Gid=Convert.ToString(dt.Rows[0]["Gid"]);
                news.TypeId = Convert.ToString(dt.Rows[0]["TypeId"]);
                news.Title=Convert.ToString(dt.Rows[0]["Title"]);
                news.Keyword = Convert.ToString(dt.Rows[0]["Keyword"]);     
                news.ComeFrom=Convert.ToString(dt.Rows[0]["ComeFrom"]);
                news.Author=Convert.ToString(dt.Rows[0]["Author"]);
                news.Content=Convert.ToString(dt.Rows[0]["Content"]);
                news.Pic=Convert.ToString(dt.Rows[0]["Pic"]);
                news.IsCommand=Convert.ToString(dt.Rows[0]["IsCommand"]);
                news.commandTime=Convert.ToString(dt.Rows[0]["commandTime"]);
                news.IsTop=Convert.ToString(dt.Rows[0]["IsTop"]);
                news.topTime=Convert.ToString(dt.Rows[0]["topTime"]);
                news.AddTime=Convert.ToString(dt.Rows[0]["AddTime"]);

              }
          return news;
          }

          }
          }

          posted on 2009-06-10 18:20 sanmao 閱讀(100) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 岳阳县| 丰城市| 隆德县| 达日县| 察雅县| 孟连| 衢州市| 杂多县| 托克托县| 洛南县| 舒兰市| 岳普湖县| 山西省| 建瓯市| 崇仁县| 阳春市| 湘乡市| 章丘市| 榆社县| 金乡县| 安福县| 岱山县| 长治市| 大埔区| 习水县| 景德镇市| 繁峙县| 泸州市| 安岳县| 延津县| 淮安市| 琼海市| 芮城县| 邻水| 土默特右旗| 吴忠市| 秀山| 都昌县| 五指山市| 山丹县| 沅江市|