2016年2月18日 星期四

[JQuery].eachcheckbox 全選 略過特定條件

要做出快速全選的表單時

第一個項目 口全選 被打勾,但是我又不要他的屬性

可以這樣做...

給全選一個特殊的class : CheckALL

在each時,發現class=CheckALL 就略過,繼續執行

只要加個 return true; 就行了


  1. var No = "";
  2. if ($(".chk").is(":checked")) {
  3. $("#Product input:checked").each(function () {
  4. if ($(this).attr("class") == "CheckALL")
  5. {
  6. return true;
  7. }
  8. No += $(this).attr("id").split("_")[1] + ",";
  9. });

2016年2月16日 星期二

在ActionResult中呼叫ActionResult的Function,並接到Json


就是吧! 當我要新增資料 發現 資料庫已經有這筆資料存在時,就改作Update的動作

Update這個Function 已經存在了,所以就想著直接CALL....


喔!!! 這件事就這麼發生了

介紹一下兩個Funtion

新增 --> ActionResult AddNewProduct ,傳回 bool success, String ErroMsg

Update --> ActionResult ProductUpdate 傳回 bool iResult , String Msg

傳回的東西都是 JsonResult , 我想要抓到 ProductUpdate 的Json 回到 AddNewProduct 傳出去


具體怎麼做剛開始還覺得有可能嗎?真的能成嗎?

一方面又覺得若不行 那真的太笨了 =__=

然後我就問了...行呀! 真的能~~


看看片段的實作 CODE

  1. [HttpPost]
  2. public ActionResult AddNewProduct(string ID)
  3. {
  4. bool iResult = true;
  5. string msg="";
  6. bool update = true;
  7. if (update)
  8. {
  9. //把要呼叫的Function ActionResult 轉型成 JsonResult
  10. JsonResult r = (JsonResult)ProductUpdate(ID,true);
  11.  
  12. //因為拿到的r是object 所以再轉一次
  13. dynamic resultData = r.Data;
  14. //要用的時候,也要給他型別才行
  15. iResult = (bool)resultData.success;
  16. if(iResult)
  17. {
  18. msg = (String)resultData.FinishMsg;
  19. msg = msg.Replace("更新", "匯入");
  20. }else
  21. {
  22. msg = (String)resultData.ErrorMsg;
  23. msg = msg.Replace("更新", "匯入") + "請重新新增商品";
  24. }
  25. }
  26. else
  27. {
  28. //新增資料
  29. }
  30. return new JsonResult()
  31. {
  32. Data = new { success = iResult , Msg = msg }
  33. };
  34.  
  35. }

附上 stackoverflow
還是GOOGLE的高亮程式碼漂亮阿!
其實每次要把CODE放上來我都會腦抽忘了怎麼弄ORZ

2016年2月15日 星期一

2016年2月4日 星期四

[Android] TextView 文字置中



android:gravity="center_horizontal"

[Lambda]Contains 一次搜尋多筆資料

Lambda 語句中,進行類似 SQL in 的搜尋方法


  1. string[] ArrayNo = {"A111", "B222" , "C333" };
  2.  
  3. var tmp = db.Product.Where(x => x.Status == 1 && ArrayNo.Contains(x.No)).ToList();
  4.