常常會遇到一個問題,當塞資料到一個資料表欄位格式為日期,卻沒有給予任何資料(Null)時,

model.ListingDate = formdata.ListingDate; //(傳入null)

會發生這個例外Exception

SqlDateTime 溢位。必須在 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之間

而讚取一個日期欄位為Null,View裡面使用ToString("yyyy/MM/dd")會顯示成0001/01/01,

baechang 發表在 痞客邦 留言(0) 人氣()

先建立一個空的Web應用程式

image


然後在這個專案中  [加入] [新增項目]

baechang 發表在 痞客邦 留言(0) 人氣()

檔案下載

https://mega.co.nz/#!kUsGSCBB!eCw5SHQWiSFd5TpflztTSoETTUtteKvK309wZJlGbK4

安裝完成後執行程式

02


baechang 發表在 痞客邦 留言(0) 人氣()

form 先設定 enctype 是 multipart/form-data 如下

<form name="form1" id="form1" enctype="multipart/form-data">

抓取表單時使用FormData

var postData = new FormData($("#form1")[0]); 

這樣丟到 Controller 就不會造成HttpPostedFileBase 會是null

文章標籤

baechang 發表在 痞客邦 留言(0) 人氣()

先增一個類別, 注意NameSpace 讓之後要運用此自訂修飾詞的類別可以參考到

假設所有的NameSpace都在同一層

public class MyAttAttribute : Attribute {

}

這樣我要撰寫的類別的前置屬性就可以使用

baechang 發表在 痞客邦 留言(0) 人氣()

Unix TimeStamp 代表從 1970年1月1日0時0分0秒 為基準點(0) 開始以秒為單位的時間計量單位

總之就是秒… 一個小時有 3600秒   一天有86400秒

從基準時間點之後的就是以秒累進, 所以要用甚麼樣的數值型態來儲存與運算Unix TimeStamp沒有一定準則.

16位元整數 或是 32 位元整數 抑或是XX位元長整數, 在地球沒有毀滅的時候這個數值是會無限延展的,

不過也不需要考慮到全方位的週全, 畢竟. 開發一套系統能夠用多少年, 我想這也不是可以直下評斷的,

baechang 發表在 痞客邦 留言(0) 人氣()

假設有一到題目的回答就是想看到勾選的樣子, 而不是Radio圈圈的樣子, 而且是要單選

使用jQuery很簡單可以達到

範例

html內容如下:

<div id="checkboxGroup"><ul>

文章標籤

baechang 發表在 痞客邦 留言(0) 人氣()

NameSpace System.Collections

ArrayList可以存放多樣的型態,陣列內元素可以是任何Object可接受的資料型別

且永遠都是"一維陣列",常用在存放混合各種資料型別以及存放的個數不確定之情形

(ps.陣列須明確知道存放資料個數,以及資料型別都要相同)


宣告:

System.Collections.ArrayList Msg = new System.Collections.ArrayList();


baechang 發表在 痞客邦 留言(0) 人氣()

組成T-SQL Page分頁查詢字串

1: public string PageSql(string Condition, int CurrentPage, int PageSize, string SortSql, string TableName, string SelectField)

   2: {
   3:     string sql = string.Empty;
   4:     int PageStart = PageSize * (CurrentPage - 1) + 1;
   5:     int PageEnd = PageStart + PageSize - 1;
   6:     if (CurrentPage <= 1)
   7:     {
   8:         string Top = PageSize > 0 ? " top " + PageSize : "";
   9:         sql = string.Format("Select " + Top + " {0} From {1} {2} {3}", SelectField, TableName, Condition, SortSql);
  10:     }
  11:     else
  12:     {
  13:         sql = "select {0} from(select {1}, ROW_NUMBER() OVER ( {2} ) as Pos from {3} {4}) as RowID where RowID.Pos between " + PageStart + " and " + PageEnd;
  14:         sql = string.Format(sql, Regex.Replace(SelectField, "([a-zA-Z0-9_]+\\.)", ""), SelectField, SortSql, TableName, Condition);
  15:     }
  16:     return sql;
  17: }

baechang 發表在 痞客邦 留言(0) 人氣()

抓取圖片html tag

   1: private List<string> GetImagesInHTMLString(string htmlString)
   2: {
   3:     List<string> images = new List<string>();
   4:     string pattern = @"<(img)\b[^>]*>";
   5:  
   6:     Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
   7:     MatchCollection matches = rgx.Matches(htmlString);
   8:  
   9:     for (int i = 0, l = matches.Count; i < l; i++)
  10:     {
  11:         images.Add(matches[i].Value);
  12:     }
  13:  
  14:     return images;
  15: }

抓取圖片 URL

   1: public List<string> FetchLinksFromSource(string htmlSource) {
   2:  
   3:     List<string> links = new List<string>(); 
   4:     string regexImgSrc = @"<img[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>";
   5:     MatchCollection matchesImgSrc = Regex.Matches(htmlSource, regexImgSrc, RegexOptions.IgnoreCase | RegexOptions.Singleline);
   6:     foreach (Match m in matchesImgSrc) 
   7:     { 
   8:         string href = m.Groups[1].Value; 
   9:         links.Add(href);
  10:     } 
  11:     return links; 
  12: }

baechang 發表在 痞客邦 留言(0) 人氣()