一個指示合約到期的進度條(mvc+jquery)

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   java   ar   資料   div   

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="width:200px; height:10px;">    </div>    <div>        <span id="msg"></span>    </div></body></html>

 

4.:

  

一個指示合約到期的進度條(mvc+jquery)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.