国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

利用c#制作簡單的留言板

2024-07-21 02:20:21
字體:
來源:轉載
供稿:網友
首先要感謝bigeagle的幫助,這個也是參考她的bbs做成的
留言板分三個模塊:列出留言列表、顯示詳細內容、發表留言
notepage.cs
namespace notpage
{
    using system;
    using system.data.sql ;
    using system.data ;
    using system.collections ;
    

        
    ////////////////////////////////////////////////////////////////////
    //
    // class name :       留言板
    //
    // description:       構造一個留言板對象
    //
    // date:              2000/06/06
    //
    // 作者:              天啦
    /// ////////////////////////////////////////////////////////////////


    /// <summary>
    ///    summary description for notepage.
    /// </summary>
    
     
    public class notepage
    {
        //私有變量
    
        private int       n_intid    ;            //id編號
        private string n_strtitle ;            //主題
        private string n_strauthor ;        //留言人
        private string n_strcontent ;        //留言內容
        private datetime n_datetime ;        //留言時間

        
        //屬性
    

        public int id
        {
            get
            {
                return n_intid ;
            }
            set
            {
                n_intid = value;
            }
        }

        public string title
        {
            get
            {
                return n_strtitle ;
            }
            set
            {
                n_strtitle = value;
            }
        }

        public string author
        {
            get
            {
                return n_strauthor ;
            }
            set
            {
                n_strauthor = value ;
            }
        }
        public string content
        {
            get
            {
                return n_strcontent ;
            }
            set
            {
                n_strcontent = value ;
            }
        }
        public datetime adddate
        {
            
            get
            {
                return n_datetime;
            }
            set
            {
                n_datetime = value;
            }
        }
        //構造函數
          public notepage()
        {
            //
            // todo: add constructor logic here
            //
            this.n_intid = 0 ;
            this.n_strtitle = "" ;
            this.n_strauthor = "" ;
            this.n_strcontent = "" ;
            this.n_datetime = system.datetime.now;
            
        }

        /// <summary>
        ///
        /// 取得留言的內容
        ///
        /// </summary>
        /// <param name="a_intid"> </param>
        public notepage gettopic(int a_intid)
        {
            //
            // todo: add constructor logic here
            //
            


            //讀取數據庫
            myconn myconn = new myconn();
            
            sqlcommand mycommand = new sqlcommand() ;
            mycommand.activeconnection = myconn ;
            mycommand.commandtext = "n_gettopicinfo" ;    //調用存儲過程
            mycommand.commandtype = commandtype.storedprocedure ;
            mycommand.parameters.add(new sqlparameter("@a_inttopicid" , sqldatatype.int)) ;
            mycommand.parameters["@a_inttopicid"].value = a_intid ;

            notepage objnp = new notepage();
            try
            {    
                
                myconn.open() ;
                sqldatareader myreader ;
                mycommand.execute(out myreader) ;
                if (myreader.read())
                {
                    objnp.id = (int)myreader["id"] ;
                    objnp.title = (string)myreader["title"] ;
                    objnp.author  = (string)myreader["author"] ;
                    objnp.content = (string)myreader["content"];
                    objnp.adddate = (datetime)myreader["adddate"];
                }
                

                
                //清場
                myreader.close();
                myconn.close() ;

            }
            catch(exception e)
            {
                throw(new exception("取貼子失敗:" + e.tostring())) ;
            }
            return objnp;
            
        }

        /// <summary>
        ///
        /// 目的:將留言的內容入庫
        ///
        /// 利用構造函數來傳遞信息
        ///
        /// </summary>
        /// <param name="n_topic"> </param>
        public bool addtopic(notepage n_topic)
        {
            //
            // todo: add constructor logic here
            //
            
            //讀取數據庫
            myconn myconn = new myconn();
            
            sqlcommand mycommand = new sqlcommand() ;
            mycommand.activeconnection = myconn ;
            mycommand.commandtext = "n_addtopic" ;    //調用存儲過程
            mycommand.commandtype = commandtype.storedprocedure ;
            mycommand.parameters.add(new sqlparameter("@a_strtitle" , sqldatatype.varchar,100)) ;
            mycommand.parameters["@a_strtitle"].value = n_topic.title ;

            mycommand.parameters.add(new sqlparameter("@a_strauthor" , sqldatatype.varchar,50)) ;
            mycommand.parameters["@a_strauthor"].value = n_topic.author ;

            mycommand.parameters.add(new sqlparameter("@a_strcontent" , sqldatatype.varchar,2000)) ;
            mycommand.parameters["@a_strcontent"].value = n_topic.content ;

            try
            {    
                
                myconn.open() ;
                mycommand.executenonquery() ;
                                
                //清場
                
                myconn.close() ;

            }
            catch(exception e)
            {
                throw(new exception("取貼子失敗:" + e.tostring())) ;
            }
            return true;
                
        

        }


        /// <summary>
        /// 取的貼子列表
        /// </summary>
        /// <remarks>
        /// 返回一個topic數組
        /// </remarks>
        public arraylist gettopiclist()
        {
            //定義一個forum數組做為返回值
            arraylist arrforumlist =new arraylist() ;

            //從數據庫中讀取留言列表
            myconn myconn = new myconn();
            sqlcommand mycommand = new sqlcommand() ;
            mycommand.activeconnection = myconn ;
            mycommand.commandtext = "n_gettopiclist" ;    //調用存儲過程
            mycommand.commandtype = commandtype.storedprocedure ;

            try
            {
                myconn.open() ;
                sqldatareader myreader ;
                mycommand.execute(out myreader) ;

                for (int i = 0 ; myreader.read() ; i++)
                {
                    notepage objitem = new notepage() ;
                    objitem.id = myreader["id"].tostring().toint32() ;
                    objitem.title = myreader["title"].tostring() ;
                    objitem.author = myreader["author"].tostring() ;
                    objitem.adddate = myreader["adddate"].tostring().todatetime();    
                    objitem.content = myreader["content"].tostring();
                                                        
                    arrforumlist.add(objitem) ;
                }

                
                //清場
                myreader.close();
                myconn.close() ;

            }
            catch(sqlexception e)
            {
                throw(new exception("數據庫出錯:" + e.tostring())) ;
                //return null ;
            }

            return arrforumlist ;
        }
            
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 瑞金市| 彩票| 奉贤区| 兰州市| 洱源县| 孙吴县| 宕昌县| 五指山市| 南木林县| 水富县| 福贡县| 米林县| 潼关县| 济宁市| 舒兰市| 元朗区| 桂平市| 巨野县| 阿拉尔市| 铅山县| 申扎县| 武鸣县| 古交市| 句容市| 横峰县| 星子县| 灵璧县| 于都县| 绍兴县| 浦城县| 鹤岗市| 阿合奇县| 郁南县| 肇源县| 独山县| 新沂市| 临武县| 达尔| 丹棱县| 晴隆县| 盈江县|