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)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 普兰县| 互助| 凌云县| 金门县| 贡山| 班戈县| 科技| 平湖市| 滦南县| 连山| 茂名市| 西丰县| 巫溪县| 定州市| 博兴县| 历史| 兖州市| 五台县| 宁安市| 丰城市| 电白县| 宁化县| 泸州市| 循化| 绥芬河市| 灵山县| 梓潼县| 田东县| 岱山县| 永嘉县| 诏安县| 皮山县| 洛扎县| 全南县| 南陵县| 苍梧县| 万宁市| 囊谦县| 新竹县| 宿松县| 洮南市|