麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > .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開發。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 精品久久久久久综合日本 | 狠狠99| 国产精品久久久久久久av | 国产午夜亚洲精品 | 成人福利在线免费观看 | 中文字幕精品在线播放 | 九九热精| 毛片免费在线播放 | 久久免费观看一级毛片 | 亚洲视频网 | 亚洲综合视频网站 | 黄色片网站在线免费观看 | 久久久毛片视频 | 毛片av网址| 亚洲aⅴ免费在线观看 | 一级电影在线免费观看 | 欧美日韩免费在线观看视频 | h色视频网站 | 九九热精| 欧美日韩免费看 | 日本道中文字幕 | 久久久www成人免费精品 | av免费在线观看av | 久久综合久久综合久久 | 欧美aⅴ视频 | 精国品产一区二区三区有限公司 | 黄色特级视频 | 亚洲精品一区二区三区在线看 | 黄色av网站在线观看 | 精品国产一区二区久久 | 最新中文字幕免费视频 | 在线观看国产日韩 | 暴力强行进如hdxxx | 欧美精品亚洲人成在线观看 | 免费欧美精品 | 国产精品久久久久久久久粉嫩 | 青青草华人在线 | 久久tv免费国产高清 | 国产日韩在线观看一区 | 国产成人强伦免费视频网站 | 亚洲成人伊人 |