订餐系统:提交订单代码实现

来源:互联网 发布:淘宝无线端链接转换器 编辑:程序博客网 时间:2024/04/29 20:41

1.登录时将用户名密码写入cookie,以及从cookie中取,赋值到文本框



    代码一:写入



        function login() {            var UfromID = document.getElementById("username").value;            var PfromID = document.getElementById("userpassword").value;            if (UfromID == "cs" && PfromID == "cs") {                window.location = "../ChooseDate.aspx";                return;            }            var loginDate = new Date();            var nowhours = loginDate.getHours();            var nowminutes = loginDate.getMinutes();            var nowseconds = loginDate.getSeconds();            if (nowhours < 10) {                nowhours = '0' + nowhours;            }            if (nowminutes < 10) {                nowminutes = '0' + nowminutes;            }            if (nowseconds < 10) {                nowseconds = '0' + nowseconds;            }            var loginTime = nowhours + ':' + nowminutes + ':' + nowseconds;                        var params = '{name:"' + UfromID + '",password:"' + PfromID + '"}';            $.ajax({                url: "LoginMobile.aspx/test",                data: params,                type: "post",                dataType: 'text',                contentType: "application/json; charset=utf-8",                success: function (data) {                    if (data == '{"d":true}') {                        $.cookie('username', UfromID, { expires: 7, path: '/' });                        $.cookie('password', PfromID, { expires: 7, path: '/' });                        window.location = "../mobile/WeekOrderCell.aspx?loginSystemTime="+loginTime+"&uid="+UfromID;                    } else {                        mui.toast("用户名或密码错误!");                    }                }            });        }



    代码二:读取




            $(function () {                var UfromC = $.cookie("username");                var PfromC = $.cookie("password");                if (UfromC != undefined && PfromC != undefined) {                    $("#username").val(UfromC);                    $("#userpassword").val(PfromC);                }            })




2.当天菜谱展示




        $(document).ready(function () {            getNowDate();//显示当天日期在header上            jugeWeekday();//把将要显示的其他六个日期存入数组            //接收传过来的登陆时间,如果大于10点,就不能再预定当天的饭菜            var url = location.search;//获取url中问号符后的字符串            var loginInTime;//接收传过来的登陆时间            if (url.indexOf("?") != -1) {//判断是否有参数                var str = url.substr(1);//从第一个字符开始,因为第0个是问号,获取所有除问号的所有字符串                strs = str.split("=");//用等号进行分隔(只有一个参数用等号分隔,如果有多个参数,要用&号分隔,再用等号进行分隔)                loginInTime = strs[1];//取值                    //if (loginInTime>'10:00:00') {                //    mui.alert('超出当日订餐时间段,不可订餐!', '');                //    document.getElementById("span1LB").disabled = true;                //}                if (loginInTime > '10:00:00') {                    mui.alert('午餐超出当日订餐时间段,不可订餐!', '');                    document.getElementById("span1LB").disabled = true;                }                if (loginInTime > '17:00:00') {                    mui.alert('晚餐超出当日订餐时间段,不可订餐!', '');                    document.getElementById("span1NB").disabled = true;                }            }            var day = new Date().getDay();            switch (day) {                case 0:                    mydate.innerText = "本周日";                    if (span1L.innerText == "") {                        $.get("WeekOrderCell.aspx?aaa=" + freshDate.innerText, function (data) {                            if (data.length == 0) {                                $("#span1L").append("<div class=" + '"mui-input-row"' + "><label>" + "没有查到相关记录" + "</label></div>");                            } else {                                $.each(data, function (i, item) {                                    $("#span1L").append(                                 "<div class='mui-numbox' data-numbox-min='0' data-numbox-max='9' style='z-index:999;position:absolute;margin-left:165px;margin-right:0' >" +                                    "<button class='mui-btn mui-btn-numbox-minus' type='button'>-</button>" +                                    "<input id='" + i + "' name='span1lunch' class='mui-input-numbox' type='number' value='0' />" +                                    "<button class='mui-btn mui-btn-numbox-plus' type='button'>+</button>" +                                 "</div>" +                                 "<div class='mui-input-row'>" +                                        "<label style='width:100px;padding-right:0;padding-left:10px'>" + item.foodName +                                        "</label>" +                                        "<label style='width:40px;padding-right:0;padding-left:0'>" + item.price + "元" +                                        "</label>" +                                        "<input id='" + item.foodId + "' name='" + item.foodId + "'  type=" + "'hidden'" + " class=" + "'span1food'" + " value='" + item.price + "' />" +                                    "</div> "                                    );                                    //不加下面这句话会导致页面刚加载时,增减按钮不能使用                                    mui('.mui-numbox').numbox();                                });                            }                        }, "json");                    }                    if (span1N.innerText == "") {                        //$.post("WeekOrderCell.aspx", { bbb: mydate.innerText }, function (data) {                        $.get("WeekOrderCell.aspx?bbb=" + freshDate.innerText, function (data) {                            if (data.length == 0) {                                $("#span1N").append("<div class=" + '"mui-input-row"' + "><label>" + "没有查到相关记录" + "</label></div>");                            } else {                                $.each(data, function (i, item) {                                    $("#span1N").append(                                    "<div class='mui-numbox' data-numbox-min='0' data-numbox-max='9' style='z-index:999;position:absolute;margin-left:165px;margin-right:0'>" +                                    "<button class='mui-btn mui-btn-numbox-minus' type='button'>-</button>" +                                    "<input id='" + i + "' name='span1dinner' class='mui-input-numbox' type='number' value='0' />" +                                    "<button class='mui-btn mui-btn-numbox-plus' type='button'>+</button>" +                                    "</div>" +                                    "<div class='mui-input-row'>" +                                    "<label style='width:100px;padding-right:0;padding-left:10px'>" + item.foodName +                                    "</label>" +                                    "<label style='width:40px;padding-right:0;padding-left:0'>" + item.price + "元" +                                    "</label>" +                                    "<input id='" + item.foodId + "' name='" + item.foodId + "'  type=" + "'hidden'" + " class=" + "'span1dinnerfood'" + " value='" + item.price + "' />" +                                    "</div>"                                    );                                    mui('.mui-numbox').numbox();                                })                            }                        }, "json");                    }                    break;                          ……



3.ajax传参调用




            var params = '{orderIds:"' + fooddetail + '",isDinner:"' + isDinner + '",orderDate:"' + freshDate.innerText + '",eatTime:"中午"}';            $.ajax({                url: "WeekOrderCell.aspx/SetOrder",                type: "post",                data: params,                dataType: 'text',                contentType: "application/json; charset=utf-8",                success: function (data) {                    if (data == '{"d":true}') {                        mui.alert('午餐预定成功!详情见页面底部', '', function () {                            OrderDetailSpan4();                            for (var i = 0; i < foodnum.length; i++) {                                if (foodnum[i].value != "0") {                                    foodnum[i].value = "0";                                }                            }                        });                    } else {                        mui.alert('订餐失败!余额不足或网络连接错误', '');                        for (var i = 0; i < foodnum.length; i++) {                            if (foodnum[i].value != "0") {                                foodnum[i].value = "0";                            }                        }                    }                }            });




4.后台逻辑代码




        [WebMethod]        public static bool SetOrder(string orderIds, string isDinner, string orderDate, string eatTime)        {            bool flag = false;            T_OrderDetailSheet detailinfo = new T_OrderDetailSheet();            SelectFood selectfood = new SelectFood();            OrderSheet orderinfo = new OrderSheet();            CardBll cardb = new CardBll();            OrderBll orderB = new OrderBll();            //提交订单时需要先检查是否已经订过餐            //string cardId = Session["Admin"].ToString();            //IsOrderFood(orderDate, eatTime, cardNo);            //订单ID            orderinfo.OrderId = DateTime.Now.ToString("MMddHHmmssffff");            //将订单ID存入session            System.Web.HttpContext.Current.Session["orderId"] = orderinfo.OrderId;            //从session获取卡号                        string tmpCard = System.Web.HttpContext.Current.Session["Admin"].ToString();            orderinfo.CardNo = tmpCard;            if (tmpCard.Length == 3)            {                orderinfo.CardNo = "E000" + tmpCard;            }            if (tmpCard.Length == 4)            {                orderinfo.CardNo = "E00" + tmpCard;            }            decimal totalMoney = 0;            //获取当前订单详情集合            string[] ids = orderIds.Split(',');            if (ids.Length > 0)            {                for (var i = 0; i < ids.Length - 1; i++)                {                    string[] idandPrice = ids[i].Split(':');                    detailinfo.FoodId = idandPrice[0].ToString();                    decimal price = Convert.ToDecimal(idandPrice[1].ToString());                    detailinfo.Num = idandPrice[2].ToString();                    detailinfo.OrderId = orderinfo.OrderId;                    totalMoney += Convert.ToDecimal(price * Convert.ToInt32(detailinfo.Num));                    flag = selectfood.InsertOrderDetail(detailinfo);                    if (!flag)                    {                        break;                    }                }            }            //在这里做个判断,如果“库里已经提交的当天及以后的订单总和+将要提交的这份订单金额” > 卡内余额,则订单不能提交            //查卡内余额            List<Card> list = cardb.queryBalance(orderinfo.CardNo);            //查现有订单总金额            DataTable dt = orderB.querySum(orderinfo.CardNo,orderDate);            //加上这份订单后的全部订单金额  和  余额  作比较            decimal pastOrder;            if (dt.Rows[0][0] == DBNull.Value)            {                pastOrder = 0;            }            else            {                pastOrder = Convert.ToDecimal(dt.Rows[0][0]);            }            decimal allOrder = pastOrder + totalMoney;            if (allOrder > list[0].cash)            {                flag = false;            }            if (flag)            {                //T表示下午在食堂吃,F代表不在                if (isDinner == "Yes")                {                    orderinfo.IsDinnerEat = "T";                }                else                {                    orderinfo.IsDinnerEat = "F";                }                //向订单总表中插入数据                orderinfo.TotalCost = Convert.ToString(totalMoney);                orderinfo.OrderDate = orderDate.ToString();                orderinfo.eatTimeQuantum = eatTime.ToString();                flag = selectfood.InsertOrderhan(orderinfo);            }            return flag;        }



2 0
原创粉丝点击