功能:
1.抓取外匯資料
2.預設顯示 美金 英鎊 日圓 RMB
3.可供選顯示/隱藏 其他外幣資料
using PagedList; using PageList.Models;
public ActionResult Index(int page =1) { //page用來記憶目前是哪一頁 int currentPage = page < 1 ? 1 : page; //資料必須先經過排序 var product = db.Product.Where(x => x.Status == 1).OrderBy(x => x.ID); //分頁資料使用 ToPagedList() //參數分別是傳入所要分頁的頁碼以及分頁資料量 //此範例就是每一頁會有10筆資料 var PageResult = product.ToPagedList(currentPage, 10); return View(PageResult); }
@Html.PagedListPager((IPagedList)Model, page => Url.Action("Index", new { page = page}))
//設定PagedListRenderOptions 可更改樣式 @Html.PagedListPager((IPagedList)Model, page => Url.Action("Index", new { page = page}) ,PagedListRenderOptions.MinimalWithPageCountText)
//也可以自由設定顯示物件 @Html.PagedListPager((IPagedList)Model, page => Url.Action("Index", new { page = page}), new PagedListRenderOptions { DisplayLinkToIndividualPages=false, DisplayLinkToFirstPage =PagedListDisplayMode.IfNeeded, DisplayLinkToLastPage= PagedListDisplayMode.IfNeeded, DisplayLinkToNextPage = PagedListDisplayMode.IfNeeded, DisplayLinkToPreviousPage = PagedListDisplayMode.IfNeeded, DisplayPageCountAndCurrentLocation = true, PageCountAndCurrentLocationFormat ="第{0}頁 / 共{1}頁" })
[HttpPost] public ActionResult AddNewProduct(string ID) { bool iResult = true; string msg=""; bool update = true; if (update) { //把要呼叫的Function ActionResult 轉型成 JsonResult JsonResult r = (JsonResult)ProductUpdate(ID,true); //因為拿到的r是object 所以再轉一次 dynamic resultData = r.Data; //要用的時候,也要給他型別才行 iResult = (bool)resultData.success; if(iResult) { msg = (String)resultData.FinishMsg; msg = msg.Replace("更新", "匯入"); }else { msg = (String)resultData.ErrorMsg; msg = msg.Replace("更新", "匯入") + "請重新新增商品"; } } else { //新增資料 } return new JsonResult() { Data = new { success = iResult , Msg = msg } }; }
// Tab名稱的全選和取消 $("#AllTab").change(function () { if ($(this).is(":checked")) { $("[id*=chkTab] input").prop("checked", true); } else { $("[id*=chkTab] input").removeAttr("checked"); } }); $("[id*=chkTab] input").on("change", function () { //全部都選到了,"全部"這個選項打勾,反之,則取消 if ($("[id*=chkTab] input").length == $("[id*=chkTab] input:checked").length) { $("#AllTab").prop("checked", true); } else { $("#AllTab").removeAttr("checked"); } });View 順便講一下好了,checkList 這個是用來記錄CheckBox選取的狀態 MVC 才可以這樣用......
//這段程式碼可以不用理他,是POSTBACK 回來時 //想讓畫面保留勾選的項目 @{ string[] checkList = new string[7];//最後一個存放 全部 的狀態 if (splitFilter[1] != null) { string[] splitck = splitFilter[1].TrimEnd(',').Split(','); if (splitck[0] != "-1") { foreach (string i in splitck) { checkList[int.Parse(i) - 1] = "checked"; } } } }
if (Tag != "-1") { ListTagCondition = new List (); foreach (var t in Tag.Substring(0, Tag.Length - 1).Split(',')) { TagCondition.Add(Convert.ToInt32(t)); } product = product.Where(x =>TagCondition.Contains(x.TabName)); }
IListproperties = typeof(ProductSize).GetProperties().ToList(); foreach (var p in properties) { if (p.GetValue(create) == null && p.PropertyType == typeof(string)) { p.SetValue(create, ""); } }
var PTryReport = db.ProductTryReport.Where(x => x.ProductSize_ID == Check.ID); if (PTryReport.Any()) { //原本這樣寫 會出錯交易失敗錯誤 //因為刪除del就會改變PTryReport的值 foreach (var del in PTryReport) { db.ProductTryReport.Remove(del); db.SaveChanges(); } } //理想的寫法 用 RemoveRange 一次刪除全部資料 if (PTryReport.Any()) { db.ProductTryReport.RemoveRange(PTryReport); db.SaveChanges(); }