SlowX的网站评论功能的代码摘要

2017-01-31 18:10:53  访问(3110) 赞(0) 踩(0)



  • 一、几个文件

    1、/Ajax/Common/CmPLList.ashx 实现网站评论内容的加载

    2、/Ajax/Common/CmPLSave.ashx 实现网站评论内容的保存

    3、/UserControls/WebComment.ascx 自定义控件实现评论功能

    4、codedetail.aspx 引用WebComment实现评论功能


    二、相关代码

    codedetail.aspx

    <uc1:WebComment runat="server" ID="WebCommentV" />


    codedetail.aspx.cs



    // 给评论提供指定的ID

    WebCommentV.Item_Id = theResult.ID;

    // 对应的表 

    WebCommentV.EmTableV = SlowX.WebLib.Enums.Table.EmTable.UTB_WEB_CODE_ITEM;


    三、几个关键代码

    1、通过<%=this.ClientID %>防止输出的HTML的ID有重复(考虑引用两个WebComment.ascx)的情况,相关代码见WebComment.ascx 

    2、通过showDataRequest异步加载评论内容,赋值给div(id="<%=this.ClientID %>div_PL")

    3、通过$.ajax的post实现评论的ajax保存

    4、通过data: {TheContent:textValue} 指定保存数据


  • 
    create table dbo.UTB_WEB_CM_PL
    (
    	ID bigint not null primary key,	-- 评论 --
    	TheName nvarchar(255) not null,	-- 名称 --
    	TheContent ntext,				-- 内容 --
    	EmTableV	int not null,		-- 对应表单 --
    	Item_Id		bigint	not null,	-- 对应记录 --
    	PID	bigint not null,			-- 上一评论 --
    	EmPLTypeV int not null,		-- 类型 --
    	EmPLShowV int not null,		-- 显示 --
    	PostUserId bigint not null,	-- 发布人 --
    	PostUserName nvarchar(255) not null,	-- 发布帐号 --
    	PostTheName nvarchar(255),	-- 发布人姓名 --
    	PostTel nvarchar(255),	-- 发布人联系方式 --
    	PostDatetime datetime default getdate() not null,	-- 发布时间 --
    	EmPLAuditV int not null,	-- 审核状态 --
    	AuditText ntext,	-- 审核内容 --
    	AuditUserId bigint	not null,	-- 审核用户 --
    	AuditUserName nvarchar(255) not null,	-- 审核用户帐号 --
    	AuditTime datetime not null,	-- 审核时间 --
    	FromIP nvarchar(50) not null,	-- 来源IP --
    	IPAddress nvarchar(1000) not null,	-- IP地址 --
    	SessionID	nvarchar(255)	not null,			-- 当时Session --
    	VisitWeb	nvarchar(255)	not null,			-- 访问页面 --
    	UrlReferrer nvarchar(255)	not null,			-- 上一访问来源 --
    	BrowserInfo nvarchar(255)	not null,			-- 浏览器信息 --
    	BrowserVersion nvarchar(255)	not null,			-- 浏览器版本 --
    	ClientLanguage nvarchar(255)	not null,			-- 语音 --
    	Platform nvarchar(255)	not null,					-- 平台 --
    	CreateTime datetime default getdate() not null,	-- 创建时间 --
    	UpdateTime datetime default getdate() not null	-- 修改时间 --
    ); 
    
    --+ [表]UTB_WEB_CM_PL:评论 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'评论', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', NULL, NULL;
    
    --+ ID:评论 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'评论', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'ID';
    
    --+ TheName:名称 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'名称', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'TheName';
    
    --+ TheContent:内容 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'内容', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'TheContent';
    
    --+ EmTableV:对应表单 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'对应表单', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'EmTableV';
    
    --+ Item_Id:对应记录 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'对应记录', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'Item_Id';
    
    --+ PID:上一评论 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'上一评论', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'PID';
    
    --+ EmPLTypeV:类型 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'类型', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'EmPLTypeV';
    
    --+ EmPLShowV:显示 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'显示', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'EmPLShowV';
    
    --+ PostUserId:发布人 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'发布人', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'PostUserId';
    
    --+ PostUserName:发布帐号 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'发布帐号', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'PostUserName';
    
    --+ PostTheName:发布人姓名 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'发布人姓名', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'PostTheName';
    
    --+ PostTel:发布人联系方式 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'发布人联系方式', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'PostTel';
    
    --+ PostDatetime:发布时间 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'发布时间', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'PostDatetime';
    
    --+ EmPLAuditV:审核状态 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'审核状态', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'EmPLAuditV';
    
    --+ AuditText:审核内容 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'审核内容', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'AuditText';
    
    --+ AuditUserId:审核用户 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'审核用户', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'AuditUserId';
    
    --+ AuditUserName:审核用户帐号 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'审核用户帐号', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'AuditUserName';
    
    --+ AuditTime:审核时间 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'审核时间', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'AuditTime';
    
    --+ FromIP:来源IP |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'来源IP', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'FromIP';
    
    --+ IPAddress:IP地址 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'IP地址', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'IPAddress';
    
    --+ SessionID:当时Session |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'当时Session', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'SessionID';
    
    --+ VisitWeb:访问页面 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'访问页面', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'VisitWeb';
    
    --+ UrlReferrer:上一访问来源 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'上一访问来源', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'UrlReferrer';
    
    --+ BrowserInfo:浏览器信息 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'浏览器信息', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'BrowserInfo';
    
    --+ BrowserVersion:浏览器版本 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'浏览器版本', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'BrowserVersion';
    
    --+ ClientLanguage:语音 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'语音', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'ClientLanguage';
    
    --+ Platform:平台 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'平台', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'Platform';
    
    --+ CreateTime:创建时间 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'创建时间', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'CreateTime';
    
    --+ UpdateTime:修改时间 |-- 
    EXECUTE sp_addextendedproperty N'MS_Description', N'修改时间', N'user', N'dbo', N'table', N'UTB_WEB_CM_PL', 'column', 'UpdateTime';
    
    
    
    -- 创建[表格:UTB_WEB_CM_PL] seq_web_cm_pl -- 
    insert into utb_sys_dual (SequenceName, ID, CreateTime, UpdateTime, TableName) values 
        (
            'seq_web_cm_pl', 1, getdate(), getdate(), 'UTB_WEB_CM_PL'
        );
     
    
  • <%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebComment.ascx.cs" Inherits="UserControls_WebComment" %>
    <h3>
        相关评论</h3>
    <div id="<%=this.ClientID %>div_PL">
        评论加载中……
    </div>
    <div class="cleardiv">
    </div>
    <div class="height5px">
        &nbsp;</div>
    <h3>
        发表评论</h3>
    <table class="gzTableItem" cellspacing="0" cellpadding="5" border="0" style="width: 99%;
        font-size: 14px;">
        <tbody>
            <tr class="gzTrItem">
                <td class="gzTdLeftItem" align="right" style="height: 30px; width: 100px;">
                    类型:
                </td>
                <td class="gzTdRightItem" colspan="5">
                    <asp:RadioButtonList runat="server" ID="rbl_EmPLTypeV" RepeatDirection="Horizontal"
                        RepeatLayout="Table" CellSpacing="5">
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr class="gzTrItem">
                <td class="gzTdLeftItem" align="right" style="height: 30px;">
                    内容:
                </td>
                <td class="gzTdRightItem" colspan="5">
                    <asp:TextBox runat="server" ID="txt_TheContent" TextMode="MultiLine" Width="99%"
                        Height="100px"></asp:TextBox>
                </td>
            </tr>
            <tr class="gzTrItem">
                <td class="gzTdRightItem" align="right" style="height: 30px;">
                    &nbsp;
                </td>
                <td class="gzTdRightItem" colspan="5">
                    <asp:Button ID="btn_Save" runat="server" Text="提交" OnClick="btn_Save_Click" />
                </td>
            </tr>
        </tbody>
    </table>
    <div class="height5px">
        &nbsp;</div>
    
    <script language="javascript" type="text/javascript">
    
        function <%=this.ClientID %>GetRadioButtonListValue(clientID) {
    
            var idx = 0;
    
            var theCtrl = null;
            
            while (true) {
    
                theCtrl = document.getElementById(clientID + "_" + idx);
    
                if (theCtrl == null)
                    return null;
    
                if (theCtrl.checked)
                    return theCtrl.value;
    
                idx = idx + 1;
            }
    
        }
    
        
        // 
        function <%=btn_Save.ClientID %>Click()
        {
            var ctrlText = document.getElementById("<%=txt_TheContent.ClientID %>");
            var textValue = ctrlText.value;
        
            textValue = $.trim(textValue);
            
            if(textValue=="")
            {
                alert("请输入评论内容");
                ctrlText.focus();
                ctrlText.select();
                return false;
            }
            
            var rmPL = <%=this.ClientID %>GetRadioButtonListValue("<%=rbl_EmPLTypeV.ClientID %>");
            
            var ajaxUrl = "<%=AjaxSaveUrl %>" + "&EmPLTypeV="+rmPL + "&dt="+new Date();
    
            $.ajax({
                cache: false,
                async: true,
                url: ajaxUrl,
                type: "post",
                data: {TheContent:textValue},
                success: function(data) {
                    if(data!="")
                    {
                        alert(data);
                        return false;
                    }
                    
                    document.getElementById("<%=txt_TheContent.ClientID %>").value = "";
                    <%=this.ClientID %>ShowList();
                    
                    return false;
                }
            });
    
            return false;
        }
        
        function <%=this.ClientID %>ShowList()
        {
            showDataRequest("<%=strPhyPath %>/Ajax/Common/CmPLList.ashx?<%=AjaxParams %>&dt="+new Date(), "<%=this.ClientID %>div_PL", "");
        }
        
        // 加载列表 //
        <%=this.ClientID %>ShowList();
         
    </script>
    
    
    
  • using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using SlowX.DAL.Helpers;
    using SlowX.WebLib.Helpers;
    using SlowX.WebSite.Classes;
    using SlowX.Core.ICoreClasses;
    using SlowX.Core.Model;
    using SlowX.WebLib.Classes.Items;
    
    public partial class UserControls_WebComment 
        :
        SlowXWebUserControlBase
    {
    
        #region AjaxSaveUrl ~ Ajax保存
    
        /// <summary>
        /// AjaxSaveUrl ~ Ajax保存
        /// </summary>
        public string AjaxSaveUrl
        {
            get
            {
                object o = ViewState["AjaxSaveUrl"];
    
    
                if (o == null)
                    return "";
    
                return o.ToString();
    
    
            }
    
            set
            {
                ViewState["AjaxSaveUrl"] = value;
            }
        }
    
        #endregion AjaxSaveUrl ~ Ajax保存
    
        #region AjaxParams ~ Ajax参数
    
        /// <summary>
        /// AjaxParams ~ Ajax参数
        /// </summary>
        public string AjaxParams
        {
            get
            {
                object o = ViewState["AjaxParams"];
    
    
                if (o == null)
                    return "";
    
                return o.ToString();
    
    
            }
    
            set
            {
                ViewState["AjaxParams"] = value;
            }
        }
    
        #endregion AjaxParams ~ Ajax参数
    
        #region EmTableV ~ 对应表格
    
        /// <summary>
        /// EmTableV ~ 对应表格
        /// </summary>
        protected SlowX.WebLib.Enums.Table.EmTable m_EmTableV 
            = 
            SlowX.WebLib.Enums.Table.EmTable.UTB_WEB_CODE_ITEM;
    
        /// <summary>
        /// EmTableV ~ 对应表格
        /// </summary>
        public SlowX.WebLib.Enums.Table.EmTable EmTableV
        {
            get
            {
                return m_EmTableV;
            }
            set
            {
                m_EmTableV = value;
            }
        }
    
        #endregion EmTableV ~ 对应表格
    
        #region Item_Id ~ 对应记录
    
        /// <summary>
        /// Item_Id ~ 对应记录
        /// </summary>
        protected long m_Item_Id = 0;
    
        /// <summary>
        /// Item_Id ~ 对应记录
        /// </summary>
        public long Item_Id
        {
            get
            {
                return m_Item_Id;
            }
            set
            {
                m_Item_Id = value;
            }
        }
    
        #endregion Item_Id ~ 对应记录
    
        /// <summary>
        /// 通过枚举绑定RadioButtonList
        /// </summary>
        /// <param name="xdbHelper"></param>
        protected void DataBindTheControls(DBHelper xdbHelper)
        {
            
            SlowX.WebLib.Enums.PLType.EmPLType[] emA
                =
                SlowX.WebLib.Enums.PLType.EmArray;
    
            RadioButtonList rbl = rbl_EmPLTypeV;
            foreach (SlowX.WebLib.Enums.PLType.EmPLType em in emA)
            {
                rbl.Items.Add(new ListItem(em.ToString(), ((int)em).ToString()));
            }
    
            rbl.SelectedIndex = 0; 
        }
    
    
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            
        }
    
    
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                DataBindTheControls(null);
    
                this.btn_Save.OnClientClick = "return " + btn_Save.ClientID + "Click();";
    
                AjaxParams = CmPLParamItem.StaticToParam(Item_Id, EmTableV);
    
                AjaxSaveUrl = strPhyPath + "/Ajax/Common/CmPLSave.ashx?" + AjaxParams;
            }
        }
    }
    
  • 
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Text;
    using SlowX.Core.Helpers;
    using SlowX.WebLib.IHelpers;
    using SlowX.DAL.Helpers;
    using SlowX.WebLib.Classes;
    using System.IO;
    using SlowX.Functions.Functions;
    using SlowX.Core.ICoreClasses;
    using SlowX.WebLib.Classes.Items;
    using SlowX.Core.Model;
    using System.Web;
    using SlowX.DAL.Utils;
    
    namespace SlowX.WebLib.Helpers
    { 
        public partial class SlowXWebLibHelper
        {
            /// <summary>
            /// 
            /// </summary>
            /// <param name="context"></param>
            /// <param name="strTheContent"></param>
            /// <param name="EmTableV"></param>
            /// <param name="Item_Id"></param>
            /// <param name="PID"></param>
            /// <param name="EmPLTypeV"></param>
            /// <param name="xdbHelper"></param>
            public void CmPLSave
                (
                    HttpContext context,
                    string strTheContent,
                    SlowX.WebLib.Enums.Table.EmTable EmTableV,
                    long Item_Id,
                    long PID,
                    SlowX.WebLib.Enums.PLType.EmPLType EmPLTypeV,
                    long postUserId,
                    string postTheName,
                    DBHelper xdbHelper
                )
            {
                bool bIsCreate = true;
    
                if (xdbHelper == null)
                {
                    xdbHelper
                        =
                        SlowX.DAL.Helpers.DBHelper.CreateDBHelper();
                }
                else
                {
                    // 没有打开链接 //
                    bIsCreate = xdbHelper.IsNotOpen();
                }
    
                try
                {
                    if (bIsCreate)
                        xdbHelper.OpenDBHelper();
    
                    SlowX.WebLib.Business.UTB_WEB_CM_PL
                        bll
                        =
                        SlowX.WebLib.Business.UTB_WEB_CM_PL.instance;
    
                    SlowX.WebLib.Entity.UTB_WEB_CM_PL
                        entity
                        =
                        new SlowX.WebLib.Entity.UTB_WEB_CM_PL();
    
                    ISaveDriver isave = entity;
                    long newId = bll.GetNewLongID(xdbHelper);
                    DateTime dtNow = DateTime.Now;
    
    
                    BrowserInfoClass info
                        =
                        BrowserInfoClass.GetBrowserInfoClass(context, false);
    
                    string ipAddress = null;
    
                    ipAddress
                        =
                        IpAddressUtil.IpAddressReturn(info.FromIP, xdbHelper);
    
                    if (ipAddress == null)
                    {
                        ipAddress = "-";
                    }
    
    
                    isave.AddISaveItem(entity._ID, newId);
                    isave.AddISaveItem(entity._TheName, "-");
                    isave.AddISaveItem(entity._TheContent, strTheContent);
                    isave.AddISaveItem(entity._EmTableV, (int)EmTableV);
                    isave.AddISaveItem(entity._Item_Id, Item_Id);
                    isave.AddISaveItem(entity._PID, PID);
                    isave.AddISaveItem(entity._EmPLTypeV, (int)EmPLTypeV);
                    isave.AddISaveItem(entity._EmPLShowV, (int)SlowX.WebLib.Enums.PLShow.EmPLShow.显示);
                    isave.AddISaveItem(entity._PostUserId, postUserId);
                    isave.AddISaveItem(entity._PostUserName, postTheName);
                    isave.AddISaveItem(entity._PostTheName, postTheName);
                    isave.AddISaveItem(entity._PostTel, "-");
                    isave.AddISaveItem(entity._PostDatetime, dtNow);
                    isave.AddISaveItem(entity._EmPLAuditV, (int)SlowX.WebLib.Enums.PLAudit.EmPLAudit.待审核);
                    isave.AddISaveItem(entity._AuditText, "-");
                    isave.AddISaveItem(entity._AuditUserId, 0);
                    isave.AddISaveItem(entity._AuditUserName, "-");
                    isave.AddISaveItem(entity._AuditTime, dtNow);
                    isave.AddISaveItem(entity._FromIP, info.FromIP);
                    isave.AddISaveItem(entity._IPAddress, ipAddress);
                    isave.AddISaveItem(entity._SessionID, info.SessionID);
                    isave.AddISaveItem(entity._VisitWeb, info.VisitWeb);
                    isave.AddISaveItem(entity._UrlReferrer, info.UrlReferrer);
                    isave.AddISaveItem(entity._BrowserInfo, info.BrowserInfo);
                    isave.AddISaveItem(entity._BrowserVersion, info.BrowserVersion);
                    isave.AddISaveItem(entity._ClientLanguage, info.ClientLanguage);
                    isave.AddISaveItem(entity._Platform, info.Platform);
                    isave.AddISaveItem(entity._CreateTime, dtNow);
                    isave.AddISaveItem(entity._UpdateTime, dtNow);
    
                    bll.Insert(entity, xdbHelper);
    
                    if (bIsCreate)
                        xdbHelper.EndDBHelper();
    
                }
                catch (Exception err)
                {
                    if (bIsCreate)
                        xdbHelper.TranDBHelper();
    
                    throw err;
                }
                finally
                {
                    if (bIsCreate)
                        xdbHelper.FinallyDBHelper();
                }
            }
        }
    }
    
    
    
  • using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    
    namespace SlowX.WebLib.Classes.Items
    {
        /// <summary>
        /// 
        /// </summary>
        [Serializable]
        public class CmPLParamItem
        {
            internal class CmNameInfo
            {
                public readonly static CmNameInfo instance = new CmNameInfo();
    
                public CmNameInfo()
                {
                }
    
                #region EmTableV ~ 对应表格
    
    
                /// <summary>
                /// EmTableV ~ 对应表格
                /// </summary>
                public string EmTableV
                {
                    get
                    {
                        return "EmTableV";
                    }
                }
    
                #endregion EmTableV ~ 对应表格
    
    
                #region Item_Id ~ 对应记录
    
                /// <summary>
                /// Item_Id ~ 对应记录
                /// </summary>
                public string Item_Id
                {
                    get
                    {
                        return "Item_Id";
                    }
                }
    
                #endregion Item_Id ~ 对应记录
            }
    
            /// <summary>
            /// 
            /// </summary>
            public CmPLParamItem()
            {
    
            }
    
            #region EmTableV ~ 对应表格
    
            /// <summary>
            /// EmTableV ~ 对应表格
            /// </summary>
            protected SlowX.WebLib.Enums.Table.EmTable m_EmTableV
                =
                SlowX.WebLib.Enums.Table.EmTable.UTB_WEB_CODE_ITEM;
    
            /// <summary>
            /// EmTableV ~ 对应表格
            /// </summary>
            public SlowX.WebLib.Enums.Table.EmTable EmTableV
            {
                get
                {
                    return m_EmTableV;
                }
                set
                {
                    m_EmTableV = value;
                }
            }
    
            #endregion EmTableV ~ 对应表格
    
    
            #region Item_Id ~ 对应记录
    
            /// <summary>
            /// Item_Id ~ 对应记录
            /// </summary>
            protected long m_Item_Id = 0;
    
            /// <summary>
            /// Item_Id ~ 对应记录
            /// </summary>
            public long Item_Id
            {
                get
                {
                    return m_Item_Id;
                }
                set
                {
                    m_Item_Id = value;
                }
            }
    
            #endregion Item_Id ~ 对应记录
    
            /// <summary>
            /// 通过str获得long值
            /// </summary>
            /// <param name="str"></param>
            /// <param name="defaultValue"></param>
            /// <returns></returns>
            private static long LongByStr(string str, long defaultValue)
            {
                if (str == null)
                    return defaultValue;
    
                if (str.Length == 0)
                    return defaultValue;
    
                long theResult = 0;
    
                if (long.TryParse(str, out theResult))
                    return theResult;
    
                return defaultValue;
            }
    
    
    
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="hc"></param>
            /// <returns></returns>
            public static CmPLParamItem Create(HttpContext hc)
            {
                CmNameInfo ni = CmNameInfo.instance;
    
                CmPLParamItem theResult = new CmPLParamItem();
                theResult.Item_Id = LongByStr(hc.Request.QueryString[ni.Item_Id], 0);
                theResult.EmTableV = SlowX.WebLib.Enums.Table.GetDefaultEmByString
                    (
                        hc.Request.QueryString[ni.EmTableV]
                    );
    
                return theResult;
    
            }
    
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="hc"></param>
            /// <returns></returns>
            public string ToParam()
            {
                CmNameInfo ni = CmNameInfo.instance;
    
                return ni.Item_Id + "=" + Item_Id.ToString() + "&" + ni.EmTableV + "=" +
                    ((int)EmTableV).ToString();
    
            }
    
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="hc"></param>
            /// <returns></returns>
            public static string StaticToParam(long p_Item_Id, SlowX.WebLib.Enums.Table.EmTable p_EmTableV)
            {
                CmNameInfo ni = CmNameInfo.instance;
    
                return ni.Item_Id + "=" + p_Item_Id.ToString() + "&" + ni.EmTableV + "=" +
                    ((int)p_EmTableV).ToString();
    
            }
        }
    }
    
    
  • <%@ WebHandler Language="C#" Class="CmPLList" %>
    
    using System;
    using System.Web;
    using SlowX.Core.ICoreClasses;
    using SlowX.Core.Model;
    
    /// <summary>
    /// 评论列表
    /// </summary>
    public class CmPLList 
        : 
        IHttpHandler 
    {
         /// <summary>
        /// 相关方法
        /// </summary>
        public SlowX.Utils.Helpers.UtilHelper UH
        {
            get
            {
                return SlowX.Utils.Helpers.UtilHelper.instance;
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        public SlowX.Utils.IHelpers.DataBindUtil.IDataBindUtil IDBU
        {
            get
            {
                return SlowX.Utils.Helpers.UtilHelper.instance;
            }
        }
    
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            context.Response.ContentEncoding
                       =
                       System.Text.Encoding.GetEncoding("gb2312"); 
            try
            {
               string theResult = ToResult(context,null);
                
                context.Response.Write(theResult);
            }
            catch (Exception err)
            {
                context.Response.Write("发生异常:" + err.Message);
            }
        }
        
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="rowIndex"></param>
        /// <returns></returns>
        protected string GetLiCssClass(int rowIndex)
        {
    
            bool bFlag = (rowIndex % 2 == 0);
    
     
            if (bFlag)
            {
                return "list"  ;
            }
            else
            {
                return "list_a" ;
            }
        }
    
        /// <summary>
        /// 获得结果
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected string ToResult(HttpContext context, SlowX.DAL.Helpers.DBHelper xdbHelper)
        {
            SlowX.WebLib.Classes.Items.CmPLParamItem
                cmp
                = 
                SlowX.WebLib.Classes.Items.CmPLParamItem.Create(context);
    
    
            bool bIsCreate = true;
    
            if (xdbHelper == null)
            {
                xdbHelper
                    =
                    SlowX.DAL.Helpers.DBHelper.CreateDBHelper();
            }
            else
            {
                // 没有打开链接 //
                bIsCreate = xdbHelper.IsNotOpen();
            }
    
            try
            {
                if (bIsCreate)
                    xdbHelper.OpenDBHelper();
    
                SlowX.WebLib.Business.UTB_WEB_CM_PL
                    bll
                    =
                    SlowX.WebLib.Business.UTB_WEB_CM_PL.instance;
    
                SlowX.WebLib.Entity.UTB_WEB_CM_PL
                    entity
                    =
                    new SlowX.WebLib.Entity.UTB_WEB_CM_PL();
    
                IOrderByDriver iorder = entity;
                IQueryDriver iq = entity;
    
                iorder.AddIOrderByItem(entity._CreateTime, SlowX.Core.Enums.OrderBy.EmOrderBy.DESC);
                iorder.AddIOrderByItem(entity._ID, SlowX.Core.Enums.OrderBy.EmOrderBy.DESC);
    
                iq.AddIQueryItemWithEntityFieldInfo(entity._Item_Id, cmp.Item_Id);
                iq.AddIQueryItemWithEntityFieldInfo(entity._EmTableV, (int)cmp.EmTableV);
                
                System.Collections.Generic.List<BaseModel> theList
                    =
                    bll.ListBaseModel(entity, xdbHelper);
                
                int iCount = theList.Count;
    
                if (iCount == 0)
                {
                    if (bIsCreate)
                        xdbHelper.EndDBHelper();
    
                    return "沙发很寂寞……";
                }
    
                SlowX.WebLib.Model.UTB_WEB_CM_PL
                    model = null;
    
    
    
    
                SlowX.WebLib.Enums.PLType.EmPLType emPLT
                    = SlowX.WebLib.Enums.PLType.EmPLType.留言;
    
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
    
                sb.Append(@"<ul class=""list"">");
    
                for (int i = 0; i < iCount; ++i)
                {
    
                    model = theList[i] as SlowX.WebLib.Model.UTB_WEB_CM_PL;
    
    
                    emPLT = SlowX.WebLib.Enums.PLType.GetEmByInt(model.EmPLTypeV);
    
                    sb.Append(@"<li class=""" + GetLiCssClass(i) + @""">
                        <div>
                            <span class=""showmain"">" + IDBU.StringDataBindHtml(model.TheContent) + @"
                            </span><span class=""showdatetime"" style=""width:300px; text-align:right;"">
                                " + IDBU.StringDataBindShowIp(model.FromIP, model.IPAddress) + @"</span>
                        </div>
                        <div class=""cleardiv"">
                        </div>
                        <div>
                            " + (iCount - i).ToString() + "#&nbsp;" + emPLT.ToString() + @"
                            <span class=""showdatetime"">" + IDBU.DateTimeDataBindShow(model.CreateTime) + @"</span>
                        </div>
                        <div class=""cleardiv"">
                        </div>
                    </li>");
    
                }
    
                sb.Append("</ul>");
    
                if (bIsCreate)
                    xdbHelper.EndDBHelper();
    
                return sb.ToString();
    
            }
            catch (Exception err)
            {
                if (bIsCreate)
                    xdbHelper.TranDBHelper();
    
                throw err;
            }
            finally
            {
                if (bIsCreate)
                    xdbHelper.FinallyDBHelper();
            }
        }
    
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
    
  • <%@ WebHandler Language="C#" Class="CmPLSave" %>
    
    using System;
    using System.Web;
    using SlowX.Core.ICoreClasses;
    using SlowX.Core.Model;
    
    public class CmPLSave 
        : 
        IHttpHandler,
        System.Web.SessionState.IRequiresSessionState
    {
         /// <summary>
        /// 相关方法
        /// </summary>
        public SlowX.Utils.Helpers.UtilHelper UH
        {
            get
            {
                return SlowX.Utils.Helpers.UtilHelper.instance;
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        public SlowX.Utils.IHelpers.DataBindUtil.IDataBindUtil IDBU
        {
            get
            {
                return SlowX.Utils.Helpers.UtilHelper.instance;
            }
        }
    
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            context.Response.ContentEncoding
                       =
                       System.Text.Encoding.GetEncoding("gb2312"); 
            
            try
            {
                string theResult = ToResult(context, null);
                
                context.Response.Write(theResult);
            }
            catch (Exception err)
            {
                context.Response.Write("发生异常:" + err.Message);
            }
        }
        
       
        /// <summary>
        /// 获得结果
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected string ToResult(HttpContext context, SlowX.DAL.Helpers.DBHelper xdbHelper)
        {
            SlowX.WebLib.Classes.Items.CmPLParamItem
                cmp = SlowX.WebLib.Classes.Items.CmPLParamItem.Create(context);
    
    
            string strEmPLTypeV = context.Request.QueryString["EmPLTypeV"];
            string strTheContent = context.Request.Form["TheContent"];
            
            SlowX.WebLib.Helpers.SlowXWebLibHelper
                SH
                =
                SlowX.WebLib.Helpers.SlowXWebLibHelper.cInstance;
    
            SlowX.WebLib.Enums.PLType.EmPLType
                emPLT 
                = 
                SlowX.WebLib.Enums.PLType.GetDefaultEmByString
                (
                    strEmPLTypeV
                );
    
            WebSiteBLL wi
                =
                WebSiteBLL.instance;
    
            SlowX.WebSite.Classes.UserSessionInfo su= wi.GetUserSessionInfo( xdbHelper);
    
            long userId = 0;
            string userName = "-";
    
            if (su != null)
            {
                userId = su.ID;
                userName = su.UserName;
            }
    
            SH.CmPLSave
                (
                    HttpContext.Current,
                    strTheContent,
                    cmp.EmTableV,
                    cmp.Item_Id,
                    0,
                    emPLT,
                    userId,
                    userName,
                    xdbHelper
                );
    
            return "";
                    
        } 
    
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
    

标签:C#    Asp.Net    Ajax    $.ajax    网站评论    逻辑实现代码 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)