2016年2月18日 星期四

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

要做出快速全選的表單時

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

可以這樣做...

給全選一個特殊的class : CheckALL

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

只要加個 return true; 就行了


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

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

[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 }
 };

}

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

2016年2月15日 星期一

2016年2月4日 星期四

[Android] TextView 文字置中



android:gravity="center_horizontal"

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

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


string[] ArrayNo = {"A111", "B222" , "C333" };

var tmp = db.Product.Where(x => x.Status == 1 && ArrayNo.Contains(x.No)).ToList();