• 一个指示合同到期的进度条(mvc+jquery)


    1. Mode.csl:

      

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace ProgressBar.Models
    {
        public class User
        {
            public int Id { get; set; }
    
            public string Name { get; set; }
    
            public DateTime JoinDate { get; set; }
    
            public int ContractYears { get; set; }
        }
    }

    2. HomeController.cs:

      

        public class HomeController : Controller
        {
            //
            public ActionResult Index()
            {
                return View();
            }
    
            public ActionResult GetNowProgressBarShow()
            {
                User user = new User() { Id = 1, Name = "tianqy", JoinDate = new DateTime(2014, 1, 1), ContractYears = 1 };
                //判断合同是否到期
                int expire = DateTime.Compare(DateTime.Now, user.JoinDate.AddYears(user.ContractYears));
                if (expire <= 0) //未到期
                {
                    //计算已过时间占得百分比
                    var pastDays = (DateTime.Now.Subtract(user.JoinDate)).TotalDays;
                    var totalDays = (user.JoinDate.AddYears(user.ContractYears).Subtract(user.JoinDate)).TotalDays;
                    var pastPercentage = (pastDays / totalDays) * 100;
                    //装载、返回Json数据
                    var data = new { IsExpire = false, PastPercentage = pastPercentage };
                    return Json(data,JsonRequestBehavior.AllowGet);
                }
                else //已过期
                {
                    var data = new { IsExpire = true, PastPercentage = 100 };
                    return Json(data, JsonRequestBehavior.AllowGet);
                }
            }
        }

    3. Index.cshtml:

      

    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>合同到期进度条</title>
        <link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
        <script src="~/Scripts/jquery-1.8.2.min.js"></script>
        <script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $.getJSON('@Url.Action("GetNowProgressBarShow", "Home")', function (data) {
                    if (data.IsExpire == true) {
                        $("#msg").text("已到期!");
                        $("#pastContractDays").progressbar({
                            value: parseInt(data.PastPercentage)
                        });
                    } else {
                        $("#msg").text("");
                        $("#pastContractDays").progressbar({
                            value: parseInt(data.PastPercentage)
                        });
                    }
                })
            })
        </script>
    </head>
    <body>
        <div id="pastContractDays" style="200px; height:10px;">
        </div>
        <div>
            <span id="msg"></span>
        </div>
    </body>
    </html>

    4.效果图:

      

    ************Code虽易,Debug不易,且码且珍惜************


    本博客仅用于学习记录之用,如有侵权,请Email:tianqy@live.com

  • 相关阅读:
    Linux磁盘管理之创建磁盘分区05
    Linux磁盘管理之设备文件详解04
    Linux命令行上传文件到百度网盘
    Linux磁盘管理之元数据、文件和目录、链接文件03
    std..tr1如何传递引用类型给function
    如何判断一个点是否在矩形之内及C++的操作符重载
    C++11中部分新语法说明
    物理引擎中基于AABB碰撞盒的SAP碰撞检测
    c++动态库中对于字符类型变量的格式化处理
    从tr1中function使用看converting constructor
  • 原文地址:https://www.cnblogs.com/tianqy/p/3991109.html
Copyright © 2020-2023  润新知