亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > .NET > 正文

以增加收藏夾功能為實例,解析asp.net forums2結構流程及組件設計

2024-07-21 02:05:42
字體:
來源:轉載
供稿:網友

td id="1" class="controlpaneltabinactive" align="center" nowrap>            <a href="<%=globals.getsiteurls().myfavorites%>"><%=resourcemanager.getstring("myfavorites_title")%></a>          </td>修改:  <td colspan=11 class="controlpaneltabline"><img width="1" height=1 alt=""></td>跨躍列數五.增加相應文件表現層1,收藏夾主視圖在web/user/目錄增加myfavorites.aspx,最終用戶頁面在controls/views目錄增加myfavoritesview.cs,頁面視圖服務器控件(主要表現為頁面處理邏輯)界面視圖:在web/themes/default kins中增加view-myfavorites.ascx 收藏夾視圖(主要表現為頁面ui)組件在components目錄增加favorites.cs(相當于業務邏輯層,加s表業務處理),此例中未在子目錄components/components中增加favorite.cs(相當于業務實體層,未加s表實體),因并不需要,完整的asp.net forums模式應該還有這一層。表現層2,用戶點擊收藏按鈕后呈現的ui(這個比較簡單)在web目錄增加myfavoritesadd.aspx文件處理加入收藏時服務器控件, 在controls目錄增加myfavoritesadd.cs(頁面處理邏輯)在web/themes/default kins中增加skin-myfavoritesadd.ascx將主題加入收藏時的視圖(ui)六.數據庫增加表forums_favoritesuserid    int    4    0threadid    int    4    0favoritedate    datetime    8    0創建存儲過程forums_favorites_createdeletecreate  procedure forums_favorites_createdelete(    @userid int,    @threadid int,    @action int)asbeginif @action = 0begin    -- does the user already have the ability to see this thread?    if exists (select userid from forums_favorites where userid = @userid and threadid = @threadid)        return    insert into        forums_favorites    values        (            @userid,            @threadid,            getdate()        )    returnendif @action = 2begin    delete        forums_favorites    where        userid = @userid and        threadid = @threadid    returnendendgoset quoted_identifier off goset ansi_nulls on go七.數據處理1.components/provider/forumsdataprovider.cs增加#region 收藏夾        public abstract void createfavorites(arraylist users, int threadid);        public abstract void deletefavorites(int userid, arraylist deletelist);        #endregion2. data providers qldataprovider qldataprovider.cs增加實現方法#region #### 收藏夾 #### by venjiang 0912        /// <summary>        /// 追加主題到收藏夾        /// </summary>        /// <param name="userid">用戶id</param>        /// <param name="threadid">主題id</param>        public override void createfavorites(int userid,int threadid)         {            using( sqlconnection myconnection = getsqlconnection() )             {                sqlcommand mycommand = new sqlcommand(databaseowner + ".forums_favorites_createdelete", myconnection);                mycommand.commandtype = commandtype.storedprocedure;                mycommand.parameters.add("@action", sqldbtype.bit).value = dataprovideraction.create;                mycommand.parameters.add("@userid", sqldbtype.int);                mycommand.parameters.add("@threadid", sqldbtype.int);                myconnection.open();                mycommand.parameters["@userid"].value = userid;                mycommand.parameters["@threadid"].value = threadid;                mycommand.executenonquery();            }        }        /// <summary>        /// 從收藏夾中刪除主題        /// </summary>        /// <param name="userid">用戶id</param>        /// <param name="deletelist">刪除列表</param>        public override void deletefavorites(int userid, arraylist deletelist)         {            // create instance of connection and command object            using( sqlconnection myconnection = getsqlconnection() )             {                sqlcommand mycommand = new sqlcommand(databaseowner + ".forums_favorites_createdelete", myconnection);                mycommand.commandtype = commandtype.storedprocedure;                mycommand.parameters.add("@action", sqldbtype.int).value = dataprovideraction.delete;                mycommand.parameters.add("@userid", sqldbtype.int).value = userid;                mycommand.parameters.add("@threadid", sqldbtype.int);                // open the connection                myconnection.open();                // add multiple times                //                foreach (int threadid in deletelist)                 {                    mycommand.parameters["@threadid"].value = threadid;                    mycommand.executenonquery();                }            }        }        #endregion3.在data providers qldataprovider qldataprovider.cs修改getthreads方法,以支持收藏功能#region #### threads ####        // 增加貼子收藏 by venjiang 0911        public override threadset getthreads(                int forumid,                 int pageindex,                 int pagesize,                 int userid,                 datetime threadsnewerthan,                 sortthreadsby sortby,                 sortorder sortorder,                 threadstatus threadstatus,                 threadusersfilter userfilter,                 bool activetopics,                bool unreadonly,                 bool unansweredonly,                 bool returnrecordcount,                // 增加新參數,是否僅顯示收藏的主題                bool favoriteonly            )        {            // create instance of connection and command object            //            using( sqlconnection connection = getsqlconnection() ) {                sqlcommand command = new sqlcommand(databaseowner + ".forums_threads_getthreadset", connection);                command.commandtype = commandtype.storedprocedure;                threadset threadset             = new threadset();                stringbuilder sqlcountselect    = new stringbuilder("select count(t.threadid) ");                      stringbuilder sqlpopulateselect = new stringbuilder("select t.threadid, hasread = ");                stringbuilder fromclause        = new stringbuilder(" from " + this.databaseowner + ".forums_threads t ");                stringbuilder whereclause       = new stringbuilder(" where ");                stringbuilder orderclause       = new stringbuilder(" order by ");                // 增加收藏判斷 by venjiang 0911                if (favoriteonly == true)                {                    fromclause.append("," + this.databaseowner + ".forums_favorites fav ");                }                // ensure datetime is min value for sql                //                threadsnewerthan = sqldataprovider.getsafesqldatetime(threadsnewerthan);                // construct the clauses                #region constrain forums                // contrain the selectivness to a set of specified forums. the forumid is our                // clustered index so we want this to be first                if (forumid > 0) {                    whereclause.append("t.forumid = ");                    whereclause.append(forumid);                } else if (forumid < 0) {                    whereclause.append("(t.forumid = ");                    // get a list of all the forums the user has access to                    //                    arraylist forumlist = forums.getforums(userid, false, true);                    for (int i = 0; i < forumlist.count; i++) {                        if ( ((forum) forumlist[i]).forumid > 0 ) {                            if ( (i + 1) < forumlist.count) {                                whereclause.append( ((forum) forumlist[i]).forumid + " or t.forumid = ");                            } else {                                whereclause.append( ((forum) forumlist[i]).forumid );                                whereclause.append(")");                            }                        }                    }                } else {                    whereclause.append("t.forumid = 0 and p.userid = ");                    whereclause.append(userid);                    whereclause.append(" and p.threadid = t.threadid ");                    fromclause.append(", " + this.databaseowner + ".forums_privatemessages p ");                }                #endregion                #region constrain date                whereclause.append(" and stickydate >= '");                whereclause.append( threadsnewerthan.tostring( system.globalization.cultureinfo.currentculture.datetimeformat.sortabledatetimepattern ));                whereclause.append(" '");                #endregion                #region constain approval                whereclause.append(" and isapproved = 1");                #endregion                #region constrain read/unread                if (userid > 0) {                    sqlpopulateselect.append("(select " + this.databaseowner + ".hasreadpost(");                    sqlpopulateselect.append(userid);                    sqlpopulateselect.append(", t.threadid, t.forumid)) ");                    if (unreadonly) {                        whereclause.append(" and " + this.databaseowner + ".hasreadpost(");                        whereclause.append(userid);                        whereclause.append(", t.threadid, t.forumid) = 0");                    }                } else {                    sqlpopulateselect.append("0");                }                #endregion                #region unanswered topics                if (unansweredonly) {                    whereclause.append(" and totalreplies = 0 and islocked = 0");                }                #endregion                #region active topics                // 熱門貼子                if (activetopics) {                    whereclause.append(" and totalreplies > 2 and islocked = 0 and totalviews > 50");                }                #endregion                #region 收藏                // 盡顯示收藏的主題                if (favoriteonly)                 {                    whereclause.append(" and t.threadid = fav.threadid and fav.userid = ");                    whereclause.append(userid);                }                #endregion                #region users filter                if (userfilter != threadusersfilter.all)                 {                    if ((userfilter == threadusersfilter.hidetopicsparticipatedin) || (userfilter == threadusersfilter.hidetopicsnotparticipatedin)) {                        whereclause.append(" and ");                        whereclause.append(userid);                        if (userfilter == threadusersfilter.hidetopicsnotparticipatedin)                            whereclause.append(" not");                        whereclause.append(" in (select userid from " + this.databaseowner + ".forums_posts p where p.threadid = t.threadid)");                    } else {                        if (userfilter == threadusersfilter.hidetopicsbynonanonymoususers)                            whereclause.append(" and 0 not");                        else                            whereclause.append(" and 0");                        whereclause.append("in (select userid from " + this.databaseowner + ".forums_posts p where threadid = t.threadid and p.userid = 0)");                    }                }                #endregion                #region thread status                if (threadstatus != threadstatus.notset) {                    switch (threadstatus) {                        case threadstatus.open:                            whereclause.append(" and threadstatus = 0");                            break;                        case threadstatus.closed:                            whereclause.append(" and threadstatus = 0");                            break;                        case threadstatus.resolved:                            whereclause.append(" and threadstatus = 0");                            break;                        default:                            break;                    }                }                #endregion                #region order by                switch (sortby) {                    case sortthreadsby.lastpost:                        if (sortorder == sortorder.ascending) {                            if (activetopics || unansweredonly)                                orderclause.append("threaddate");                            else                            orderclause.append("issticky, stickydate");                        } else {                            if (activetopics || unansweredonly)                                orderclause.append("threaddate desc");                        else                            orderclause.append("issticky desc, stickydate desc");                        }                        break;                    case sortthreadsby.totalratings:                        if (sortorder == sortorder.ascending)                            orderclause.append("totalratings");                        else                            orderclause.append("totalratings desc");                        break;                                case sortthreadsby.totalreplies:                        if (sortorder == sortorder.ascending)                            orderclause.append("totalreplies");                        else                            orderclause.append("totalreplies desc");                        break;                    case sortthreadsby.threadauthor:                        if (sortorder == sortorder.ascending)                            orderclause.append("postauthor desc");                        else                            orderclause.append("postauthor");                        break;                    case sortthreadsby.totalviews:                        if (sortorder == sortorder.ascending)                            orderclause.append("totalviews");                        else                            orderclause.append("totalviews desc");                        break;                }                #endregion                // build the sql statements                sqlcountselect.append(fromclause.tostring());                sqlcountselect.append(whereclause.tostring());                sqlpopulateselect.append(fromclause.tostring());                sqlpopulateselect.append(whereclause.tostring());                sqlpopulateselect.append(orderclause.tostring());                // add parameters to sproc                //                command.parameters.add("@forumid", sqldbtype.int).value = forumid;                command.parameters.add("@pageindex", sqldbtype.int, 4).value = pageindex;                command.parameters.add("@pagesize", sqldbtype.int, 4).value = pagesize;                command.parameters.add("@sqlcount", sqldbtype.nvarchar, 4000).value = sqlcountselect.tostring();                command.parameters.add("@sqlpopulate", sqldbtype.nvarchar, 4000).value = sqlpopulateselect.tostring();                command.parameters.add("@userid", sqldbtype.int).value = userid;                command.parameters.add("@returnrecordcount", sqldbtype.bit).value = returnrecordcount;                // execute the command                connection.open();                sqldatareader dr = command.executereader();                // populate the threadset                //                while (dr.read()) {                    // add threads                    //                    if (forumid == 0)                        threadset.threads.add( forumsdataprovider.populateprivatemessagefromidatareader (dr) );                    else                        threadset.threads.add( forumsdataprovider.populatethreadfromidatareader(dr) );                }                // do we need to return record count?                //                if (returnrecordcount) {                    dr.nextresult();                    dr.read();                    // read the total records                    //                    threadset.totalrecords = (int) dr[0];                }                // get the recipients if this is a request for                // the private message list                if ((forumid == 0) && (dr.nextresult()) ) {                    hashtable recipientslookuptable = new hashtable();                    while(dr.read()) {                        int threadid = (int) dr["threadid"];                        if (recipientslookuptable[threadid] == null) {                            recipientslookuptable[threadid] = new arraylist();                        }                        ((arraylist) recipientslookuptable[threadid]).add(forumsdataprovider.populateuserfromidatareader(dr) );                    }                    // map recipients to the threads                    //                    foreach (privatemessage thread in threadset.threads) {                        thread.recipients = (arraylist) recipientslookuptable[thread.threadid];                    }                }                dr.close();                connection.close();                return threadset;            }        }        #endregion八.增加新方法在components/threads.cs增加新的重載方法,以不必修改原來的方法調用.// 為了不影響以前的程序,單獨加一個重載方法,以獲得收藏夾主題        public static threadset getthreads(int forumid, int pageindex, int pagesize, int userid, datetime threadsnewerthan, sortthreadsby sortby, sortorder sortorder, threadstatus threadstatus, threadusersfilter userfilter, bool activetopics, bool unreadonly, bool unansweredonly, bool returnrecordcount,bool favoriteonly) // 多了一個參數favoriteonly        {            forumcontext forumcontext = forumcontext.current;            string anonymouskey = "thread-" + forumid + pagesize.tostring() + pageindex.tostring() + threadsnewerthan.dayofyear.tostring() + sortby + sortorder + activetopics.tostring() + unansweredonly.tostring() + favoriteonly.tostring();            threadset threadset;            // if the user is anonymous take some load off the db            //            if (userid == 0)             {                if (forumcontext.context.cache[anonymouskey] != null)                    return (threadset) forumcontext.context.cache[anonymouskey];            }            // create instance of the idataprovider            //            forumsdataprovider dp = forumsdataprovider.instance();            // get the threads            //            threadset = dp.getthreads(forumid, pageindex, pagesize, userid, threadsnewerthan, sortby, sortorder, threadstatus, userfilter, activetopics, unreadonly, unansweredonly, returnrecordcount,favoriteonly);            if (userid == 0)                forumcontext.context.cache.insert(anonymouskey, threadset, null, datetime.now.addminutes(2), timespan.zero, cacheitempriority.low, null);            return threadset;        }九.業務邏輯層components目錄中增加favorites.cs,實現主題的增加刪除方法public static void addfavoritespost (int userid,int threadid) {            forumsdataprovider dp = forumsdataprovider.instance();            dp.createfavorites(userid, threadid);        }        /// <summary>        /// 刪除收藏        /// </summary>        /// <param name="userid">用戶id</param>        /// <param name="deletelist">刪除列表</param>        public static void deletefavorites (int userid, arraylist deletelist) {            //            forumsdataprovider dp = forumsdataprovider.instance();            dp.deletefavorites(userid, deletelist);        }十.表現層調用1.收藏夾主視圖加載收藏主題列表    threadset = threads.getthreads(forumid, pager.pageindex, pager.pagesize, users.getuser().userid, datefiltervalue, threadsortddl.selectedvalue, sortorderddl.selectedvalue, threadstatus.notset, threadusersfilter.all, false, hidereadposts.selectedvalue, false, true,true);注意最后一個參數是true,即返回收藏夾的數據集。2.增加主題到收藏夾    favorites.addfavoritespost(user.userid,post.threadid);    httpcontext.current.response.redirect(globals.applicationpath+"/myfavoritesadd.aspx",true);3.刪除收藏的主題    favorites.deletefavorites(…)
,歡迎訪問網頁設計愛好者web開發。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
日韩av综合中文字幕| 国产91色在线|| 日韩成人高清在线| 亚洲视频一区二区| 成人黄色在线播放| 日韩中文在线中文网在线观看| 日韩大片免费观看视频播放| 欧美国产日韩在线| 北条麻妃一区二区三区中文字幕| 国产精品精品视频| xx视频.9999.com| 亚洲精品美女免费| 国产精品h在线观看| 亚洲字幕在线观看| 亚洲天堂av在线免费| 国产精品扒开腿做爽爽爽视频| 一区二区成人精品| 国产原创欧美精品| 欧美黑人巨大精品一区二区| 久久综合88中文色鬼| 国产精品视频在线播放| 日本久久久久亚洲中字幕| 久久久久久尹人网香蕉| 久久久久久久香蕉网| 精品久久久久久国产| 在线视频欧美性高潮| 在线成人激情黄色| 国产美女被下药99| 国产色视频一区| 久久久精品免费| 伊人久久大香线蕉av一区二区| 7m精品福利视频导航| 国产精品黄页免费高清在线观看| 精品女厕一区二区三区| 91系列在线观看| 一区二区三欧美| 亚洲新声在线观看| 国产一区二区成人| 久久久久久这里只有精品| 亚洲视频在线观看| 国产欧美中文字幕| 91精品免费视频| 亚洲自拍偷拍色图| 亚洲激情视频网| 久久久久亚洲精品成人网小说| 色噜噜亚洲精品中文字幕| 亚洲区中文字幕| 欧美大尺度在线观看| 精品在线观看国产| 欧美精品久久久久久久久| 在线日韩欧美视频| 国产欧美亚洲精品| 亚洲风情亚aⅴ在线发布| 亚洲成人网在线观看| 国产精品日韩欧美综合| 国产一区二区免费| 国产啪精品视频| 91日本视频在线| 欧美成人中文字幕| 久久韩国免费视频| 久久av在线播放| 91夜夜揉人人捏人人添红杏| 国产香蕉一区二区三区在线视频| 九九热精品视频在线播放| 欧美午夜片欧美片在线观看| 欧美一区二区三区免费观看| 人人澡人人澡人人看欧美| 欧美日韩成人在线视频| 久久久综合av| 深夜福利日韩在线看| 4p变态网欧美系列| 亚洲欧美日韩精品久久| 亚洲午夜精品久久久久久久久久久久| 日韩亚洲第一页| 色婷婷av一区二区三区久久| 91久久嫩草影院一区二区| 国产亚洲激情视频在线| 久久精品国产69国产精品亚洲| 日韩在线免费视频| 久久国产精品久久久久久| 中文字幕久精品免费视频| 欧美在线观看网址综合| 欧美性xxxx18| 日本精品一区二区三区在线| 久久久99久久精品女同性| 91久久精品一区| 中国人与牲禽动交精品| 久久亚洲精品一区| 美女精品视频一区| 日韩欧美在线中文字幕| 在线视频免费一区二区| 日韩性生活视频| 国产大片精品免费永久看nba| 亚洲美女久久久| 在线电影av不卡网址| 中文字幕一区电影| 精品夜色国产国偷在线| 中文字幕久久亚洲| 国产精品三级久久久久久电影| 欧美xxxx18国产| 日韩欧美国产一区二区| 日韩中文字幕在线视频播放| 美女撒尿一区二区三区| 国产成人精品久久二区二区91| 亚洲伦理中文字幕| 91中文字幕一区| 亚洲欧美国产一本综合首页| 欧美亚洲第一区| 欧美天天综合色影久久精品| 亚洲精品二三区| 亚洲国产日韩一区| 91精品久久久久久综合乱菊| 成人免费视频在线观看超级碰| 亚洲国产小视频在线观看| 亚洲国产精品99久久| 久久99久国产精品黄毛片入口| 亚洲一区二区久久久久久| 久久精品国产亚洲| 午夜精品一区二区三区在线视| 亚洲精品国产精品乱码不99按摩| 日韩av影院在线观看| 国产精品视频久久久久| 精品成人在线视频| 91黑丝在线观看| 国产91色在线播放| 午夜精品一区二区三区在线视频| 日韩成人在线视频| 国产精品视频网站| 国产91色在线播放| 国产精品美乳一区二区免费| 亚洲精品一区在线观看香蕉| 91久久精品日日躁夜夜躁国产| 久久久在线免费观看| 国产在线视频欧美| 日日骚久久av| 91影视免费在线观看| 国产精品欧美日韩一区二区| 成人高清视频观看www| 国产精品视频中文字幕91| 久久97精品久久久久久久不卡| 国产午夜精品理论片a级探花| 91中文精品字幕在线视频| 欧美久久精品午夜青青大伊人| 8x海外华人永久免费日韩内陆视频| 国产精品成人在线| 日韩va亚洲va欧洲va国产| 91精品视频大全| 国产精品av网站| 色综合久久天天综线观看| 亚洲一区二区三区成人在线视频精品| 97国产成人精品视频| 欧美性猛交xxxx乱大交蜜桃| 亚洲精品久久久久久久久久久久| 成人午夜激情免费视频| 国产精品h在线观看| 久久久久女教师免费一区| 亚洲欧美制服中文字幕| 亚洲一二在线观看| 欧美高清视频在线| 亚洲天堂成人在线| 亚洲欧美国产精品va在线观看| 国产伦精品一区二区三区精品视频| 欧美成人午夜免费视在线看片| 日韩av电影院|