• 列表中数据的上下移动


    aspx页面代码:

    <%#(Convert.ToInt32(Eval("sortindex")) == nMaxIndex) ? "" : "<td class='wenzi'>
    <a href='#' onclick=\"sortInformation(" + Eval("fid") + "," + ",'up'," + Eval("sortindex") + ")\">上移</a></td>"%>
    
    <%#(Convert.ToInt32(Eval("sortindex")) == nMinIndex) ? "" : "<td class='wenzi'>
    <a href='#' onclick=\"sortInformation(" + Eval("fid") + "," + ",'down'," + Eval("sortindex") + ")\">下移</a></td>"%>

    上述三元表达式,保证当是列表中第一条数据时,没有上移链接,当是列表中最后一条数据时候,没有下移链接;

    aspx.cs文件代码:

    protected int nMaxIndex = FooterBLL.GetMaxIndex();  //获得最大索引
    protected int nMinIndex = FooterBLL.GetMinIndex();  //获得最小索引

      

    JS文件代码:

    //上下移动
    function sortInformation(keyID,optype,sortindex) {
        if (keyID <= 0) {
            alert("无效的信息ID参数,操作终止。");
            return;
        }
        if (sortindex <= 0) {
            alert("无效的索引值,操作终止。");
            return;
        }
        if (optype != ‘up’ && optype != 'down') {
            alert("无效的操作类型,操作终止。");
            return;
        }
    
        $.ajax({
            type: 'POST',
            url: 'UserControl/SetInfoSort.ashx',
            data: {
                KeyID: keyID,
                SortIndex: sortindex,
                OpType: optype
            },
            success: function (res) {
                if (res == 1) {
                    window.location.reload();
                } else {
                    alert("移动操作失败,请重试。");
                }
            },
            error: function () {
                alert("移动请求发送失败,请重试。");
            }
        });
    }

    ashx文件代码: 

    public class SetInfoSort : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
    
            string strRescult = "0";   //1:成功 0:失败
    
            string strKeyID = context.Request.Form["KeyID"];
            int nKeyID = 0;
            if (!int.TryParse(strKeyID, out nKeyID) || nKeyID <= 0)
            {
                context.Response.Write(strRescult);
                return;
            }
    
            string strSortIndex = context.Request.Form["SortIndex"];
            int nSortIndex = 0;
            if (!int.TryParse(strSortIndex, out nSortIndex) || nSortIndex <= 0)
            {
                context.Response.Write(strRescult);
                return;
            }
    
            string strCateID = context.Request.Form["CateID"];
            int nCateID = 0;
            if (!int.TryParse(strCateID, out nCateID) || nCateID <= 0)
            {
                context.Response.Write(strRescult);
                return;
            }
    
            string strOpType = context.Request.Form["OpType"];
         if(strOpType != "up" && strOpType != "down") { context.Response.Write(strRescult); return; } if (InformationBLL.SetInformationSort(nKeyID,nSortIndex,nOpType)) strRescult = "1"; context.Response.Write(strRescult); } public bool IsReusable { get { return false; } } }

    SQL存储过程:

    ALTER PROCEDURE [dbo].[Footer_Sort] 
        @UPKEYID    INT, --改变排序之前,序号较大者
        @DOWNKEYID  INT, --改变排序之前,序号较小者
    
        @RESCULT    INT OUTPUT   --1:成功 0:失败
    AS
    BEGIN
        SET @RESCULT = 0
    
        BEGIN TRAN T
            DECLARE @TEMPUP INT
            DECLARE @TEMPDOWN INT
            SELECT @TEMPUP = SORTINDEX FROM FOOTER WHERE FID = @UPKEYID
            SELECT @TEMPDOWN = SORTINDEX FROM FOOTER WHERE FID = @DOWNKEYID
    
            UPDATE FOOTER SET SORTINDEX = @TEMPDOWN WHERE FID = @UPKEYID
                IF(@@ERROR <> 0)
                BEGIN
                    ROLLBACK TRAN T
                END
    
            UPDATE FOOTER SET SORTINDEX = @TEMPUP WHERE FID = @DOWNKEYID
                IF(@@ERROR <> 0)
                BEGIN
                    ROLLBACK TRAN T
                END
            SET @RESCULT = 1
        COMMIT TRAN T
    
    END
  • 相关阅读:
    调优Java virtual machine常见问题汇总整理
    Social Media POC KT Session
    框架Hibernate笔记系列 基础Session
    JVM相关命题的博客整理及总结
    项目总结笔记系列 wsTax KT Session1
    项目总结笔记系列 Autonomy IDOL Server KT Session1
    项目总结笔记系列 Maven Session2
    项目总结笔记系列 Maven Session1
    Data Structures/Algorithms 小甲鱼99讲笔记系列(1~~15讲)
    循环有序数组查找
  • 原文地址:https://www.cnblogs.com/wxh19860528/p/2856526.html
Copyright © 2020-2023  润新知