訂單提醒功能

 

  //五秒刷新數據庫,有新訂單提醒
        if (!GetMessageCount) {

            var GetMessageCount = {};
        }

        $(document).ready(
        function () {
            //GetMessageCount.FindMessage();
            go();//計時器
        }
        );

        GetMessageCount.FindMessage = function () {
            $.ajax({
                //處理ajax請求
                type: "get",
                dataType: "json",
                url: "ajaxMesg.ashx",
                cache: false,
                success: function (response) {
                    //alert(response.MerchantName);
                    if (response.Num != 0) {
                        //alert(response.Num);
                        var context = "你有" + response.Num + "條新訂單";
                        stop();
                        ymPrompt.alert({ message: context, title: '訂單提醒', handler: myFun, btn: ['OK'], okTxt: ' 詳   情 ', autoClose: true, winPos: 'rb', useSlide: true, slideCfg: { increment: 0.1, interval: 100} });   //這裏是使用的一個 第三方 控件 可以在我網上找到!
                    }
                },
                error: function (data) {
                    alert("加載失敗");
                }
            });
            //每隔5 秒遞歸調用一次,刷新未讀短信數目
//            show();


        }  
        //開始計時

        var timerID;
        var time = 0;
        function show() {
            time++;
            //alert('time:' + time + '  timerID:' + timerID);
            timerID = setTimeout("show(" + time + ")", 5000);

            if (time > 10)  //n * (5000/1000)
            {
                //alert('>200):' + time);
                time = 0;
                GetMessageCount.FindMessage(); //核心語句
            }
        }
        //暫停
        function stop() {
            window.clearTimeout(timerID);
        }
        //繼續
        function go() {
            window.clearTimeout(timerID);
            show();
        }

        function myFun(tp) {
            if (tp == 'ok') {
                addTab('發貨訂單查看', 'StoreMange/SentGoodsCheck.aspx', 'icon icon-nav', true)
            }
            go();
        }

 

//引用一般處理程序,使用IRequiresSessionState  這個接口

//必須有using System.Web.SessionState; 這個命名空間!

 public class ajaxMesg : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string sql = "";
            string num = "";
            int number = 0;
            using (SqlConnection con = new SqlConnection(SqlHelper.ConnectionString))
            {
                con.Open();
                PageBase pb = new PageBase(); //記錄當前登錄用戶的類
                
                string userId = pb.UserId; //獲取當前登錄用戶Id
                string sqll = string.Format("select count(Name) from dbo.PUB_User"
                                + " where UserID = '{0}' and IsView = '0'", userId);

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;

                cmd.CommandText = sqll;
                number = Convert.ToInt32(cmd.ExecuteScalar().ToString());
                //以上是判斷那些人可以提醒!
            }
            if (number > 0)
            {
                using (SqlConnection con = new SqlConnection(SqlHelper.ConnectionString))
                {
                    con.Open();
                    sql = "select count(*) as Num from Match_SendGood where RemindOrNot='0'";

                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = con;
                    cmd.CommandText = sql;

                    num = "{\"Num\":\"" + cmd.ExecuteScalar().ToString() + "\"}";
                }
                context.Response.Write(num);
                //提醒的內容
            }
            else
            {
                num = "{\"Num\":\"" + "0" + "\"}";
                context.Response.Write(num);
            }
        }

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章