2014年10月23日 星期四

Javascript 正規表示法

之前web from時代都是用c#功能來做
網路上能找到一堆已經寫好的表示法如驗證身份證...
所以也只是照著copy沒有很懂
最近開始用比較前端的方式去開發程式
所以JS變的特別重要
看了兩篇文章後發覺好像懂了正規表達如何寫了
以下圖片來自正規表示法圖說

以上備忘改天比較好查
參考網址
正規表示法圖說

2014年10月2日 星期四

Bootstrap ColorSelector for Bootstrap

很少使用colorpicker,找了許多jquery的UI有點麻煩
有的有圈圈看起來很酷,但很占畫面空間
於是找了一個超簡單的ColorSelector for Bootstrap

2014年9月30日 星期二

c# Entity Framework ConnectionString 不支援關鍵字: 'data source'。

時代在進步從ado到Entity Framework
不變的都是有connection string 只是寫法不一樣
今天問題的發生點是公司"希望"connection string 需要加密
以下為EF的conn我想大部份的人憑空也寫不出來吧當然咪兔
原本使用工具產生的connectionstring
metadata=res://*/Models.Model.csdl|res://*/Models.Model.ssdl|res://*/Models.Model.msl;provider=System.Data.SqlClient;provider connection string=&Quot;Data Source=192.168.1.1;initial catalog=test;user id=sa;password=1234;multipleactiveresultsets=True;App=EntityFramework&Quot;
寫一個function
  public static string getEntitiesConn()
        {
            string test = CodeClass.Decrypt(System.Configuration.ConfigurationManager.ConnectionStrings["testEntities"].ToString());
            return test;
        }
解密出來
metadata=res://*/Models.Model.csdl|res://*/Models.Model.ssdl|res://*/Models.Model.msl;provider=System.Data.SqlClient;provider connection string=&Quot;Data Source=192.168.1.1;initial catalog=test;user id=sa;password=1234;multipleactiveresultsets=True;App=EntityFramework&Quot;
看起來一樣吧
testEntities db = new testEntities(Conn.getEntitiesConn());
不支援關鍵字: 'data source'。
是那裡有問題阿仔細一下 &Quot;這東西不就是雙引號嗎
後來把要加密的connectionstring裡的 &Quot;改成雙引號再加密讀出來就OK有沒有那麼神阿@@
在此記錄一下希望以後類似問題能不被卡住

2014年9月26日 星期五

Google Map V3以地址或經偉度抓取Json資料

之前有寫一個類似目前位置到公司所在地的網頁
雖然後來沒正試上線,所以程式碼就凍結在備份碟中
昨日拿出來看了一下有點看不懂了哈,花一點時間才了解
一開始先不直接使用地圖,先抓目前所提供的API 地理編碼&反向地理編碼
只需使用連結就能取回json資料相當方便
地理編碼
http://maps.googleapis.com/maps/api/geocode/json?address=地址&sensor=true_or_false
反向地理編碼
http://maps.googleapis.com/maps/api/geocode/json?latlng=經,緯&sensor=true_or_false
參考網址: 點我前往

2014年8月27日 星期三

jQuery 如何判斷選擇的物件在不在

通常都會先把jQuery每個物件的功能都寫好
但有時在asp.net webform visable = false時就會找不到物件
因為dom裡並沒有所以要判斷一下物件是否存在
var aTag = $('#abc');
if (!aTag.length)
    return;
參考網址
點我前往

2014年8月20日 星期三

jQuery Table Scroll freeze

一整天都測試凍結視窗
試了快六種但都不太好套
StickyTableHeaders這個算不錯但不能凍結column
目前找到最好用的gridviewscroll使用簡單

2014年7月14日 星期一

jQuery window.opener寫法

相信跨頁傳值或控制父頁的元件都是用
window.opener.getElementById("abc").value  = 'abc';
那用jQeury怎麼做??
$('#abc', opener.document).attr("value",txt);
參考網址 點我前往

2014年7月9日 星期三

Bootstrap cannot call methods on button prior to initialization

在Bootstrap中使用button地'load'功能
btn.button('loading');
發生下列問題
cannot call methods on button prior to initialization
網路查了一下,主要是jQuery UI的js檔錯誤,
檢查一下jquery ui的js是不是放於bootstrap的js上面

2014年7月3日 星期四

c# Parameters.AddWithValue DBNull

在Inser or Update時難免遇到的問題
第一個想法會寫個function來判斷DBNull 或是文字
或者是用三元運算子
今天看到更短的寫法順便學一下
cmd.Parameters.AddWithValue("@abc", (object)item.abc ?? DBNull.Value);
參考網址
cmd.Parameters.AddWithValue("@param1",param1 ?? DbNull.Value)

2014年6月26日 星期四

jQueryUI Autocomplete Combobox 修改寬度

jQuery UI 點我進入
找了很多方法居然都改不了
結果只到最簡單的方式才能改
$('.ui-autocomplete-input').css('width', '90%');
參考網址
How to set the width of jQuery ComboBoxes

2014年6月9日 星期一

Visual Studio 2013 Express 只有原始檔無設計

雖然html有些跟本不需看設計畫面
但有些原件必需要看設計畫面才知道怎麼做
工具 > 選項 > HTML設計工具 > 啟用HTML設計工具

參考網址
點我前往

2014年5月28日 星期三

Asp.net MVC Html.ActionLink & Url.Action https(SSL)(18)

記錄一下摟
@Html.ActionLink("關於", "About", "Home", "https", "", "", new { id = "1" ,test="000"}, new { @class="abc"})
@Url.Action("About","Home",null,"https","")

jQuery 將網頁導到https(SSL)

最近都在架構的網站都會走SSL
所以記來以後來會用到
  
        $(function () {
            if (window.location.protocol != "https:") {
                var sslUrl = location.href.replace(/^http/i, "https");
                window.location.href = sslUrl;
                return;
            }
        });
 
參考網站
Detect HTTP or HTTPS then force HTTPS in JavaScript

IIS 免費SSL(StartSSL)

以下兩篇保哥的文章已經算超詳細了
我也是看這兩篇就攪定摟感謝保哥
免費申請 StartSSL™ 個人數位簽章與網站 SSL 憑證完全攻略
如何在 IIS7 / IIS7.5 安裝 SSL 憑證(含 IIS7 匯入憑證的 Bug)

2014年5月12日 星期一

Javascript 呼叫c#function

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"></asp:LinkButton>
 javascript: __doPostBack('<%= LinkButton1.UniqueID %>', '');
參考網址
jQuery call __doPostBack on LinkButton

2014年5月9日 星期五

c# 遮罩電話 xxx

這function效能非最佳只不過目前剛好用到
所以隨手寫了一下
如有更好的方式可提供喔謝謝!!
   /// <summary>
        /// 遮罩電話 (十個字 手機市話)(九個字 市話)(十個字以上前四後三)(四個字以下回傳空白)
        /// </summary>
        /// <param name="pStr">字串</param>    
        /// <returns>string</returns>
        public static string MaskString(string pStr)
        {
            string mReturn = "";

            if (pStr.Length == 9 && pStr.StartsWith("0")) //9碼的如高雄
            {
                mReturn = pStr.Substring(0,2) + "-XXX-" + pStr.Substring(5,4);
            }
            else if (pStr.Length == 10 && pStr.StartsWith("09"))//手機
            {             

                mReturn = pStr.Substring(0, 4) + "-XXX-" + pStr.Substring(7, 3);

            }
            else if (pStr.Length == 10 && pStr.StartsWith("0"))//台北市話
            {
                mReturn = pStr.Substring(0, 2) + "-XXXX-" + pStr.Substring(6, 4);
            }
            else
            {
                if (pStr.Length > 10)//十個字以上
                {
                    for (int i = 0; i < pStr.Length ; i++)
                    {
                        if ((i == 0 || i <= 3) || (i >= pStr.Length - 3)) //前四個字 後三個字出現
                        {
                            mReturn += pStr.Substring(i,  1);
                        }
                        else
                        {
                            mReturn += "X";
                        
                        }
                    }                   
                }
                else  if(pStr.Length >= 4)//四個字以上才會做
                {
                    for (int i = 0; i < pStr.Length; i++)
                    {
                        if (i >= pStr.Length - 3) //後三個字出現
                        {
                            mReturn += pStr.Substring(i, 1);
                        }
                        else
                        {
                            mReturn += "X";
                        }
                    }
                }            
            }
            return mReturn;
        }

2014年4月14日 星期一

T-SQL MS SQL日期相關

以下這篇寫的超清楚的請參考
點我前往
點我前往
以下記錄自己會常用
==========================
日期是否正確
SELECT ISDATE('日')
回傳0錯誤1正確
==========================
目前時間
select GETDATE()
格林威治時間
select GETUTCDATE()
==========================
取得星期幾
SELECT Right(datename(weekday,getdate()),1)
==========================
取得幾天前或幾天後
SELECT DATEADD(day, -3, '2014-08-14')
SELECT DATEADD(day, 3, '2014-08-14')

2014年4月11日 星期五

Asp.net 使用Resource.resx檔 + MVC

我想多國語言大多數的人都會用這個做法吧寫在資源檔
如何叫用如下
在.cs
 Label1.Text = Resources.Resource.名稱;
在aspx
  Text='<%$ Resources:Resource, 名稱%>'
在js or 網頁中
 var StringTimeFormatError = "<%= Resources.Resource.名稱 %>";
alert(StringTimeFormatError );
在MVC 網頁中
@Resources.Resource.名稱 
<system.web>
   <globalization culture="auto" uiCulture="auto" enableClientBasedCulture="true"/>
</system.web>
參考網址
Set the Resource String in javascript
如何讓 App_GlobalResources 裡的全域資源檔變成公開類別

2014年4月3日 星期四

jQueryUI datepicker自訂日期不能選擇

原本以回很難的
因為要用jQuery UI 去指訂某些日期不能選擇
還好網路很方變找的個方法
在beforeShowDay時設定不能用的日期即可範例如下
$("#datae").datepicker({               
        beforeShowDay: setDisableDate //設定日期的function
   });  

   var DisableDate = [];//日期陣列 

 
  //可以用ajax post之類來帶入資料
  //todo

  //設定的function Elaine Wu
  function setDisableDate(date) {
        var strDate = date.getFullYear() + "-" + toTen(date.getMonth() + 1) + "-" + toTen(date.getDate());
        var aryReturn = [true, ""];
        $.each(DisableDate, function (key, value) {
             if (value == strDate) {
                 aryReturn = [false, "", "已設定不能選擇"];
             }
        });
        return aryReturn;
   }

   function toTen(s) {
            return s < 10 ? '0' + s : s;
   }
參考來源
Elaine Wu如何讓datepicker中某些特定日期不可選?
jQuery Datepicker 选择指定日期【转】