2014年3月9日 星期日

取月份最後一天

找玩資料發現用不到..XD" 記下來當memo

轉路自十一的.net 部落


'做法都是用隔月的第一天減一天

'VB

Private Sub Command1_Click()
    Dim d As Date
        d = "2006/05/03"
        MsgBox (DateAdd("M", 1, Format(d, "YYYY/MM") & "/01") - 1)
End Sub
'VB.NET

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim d As Date
        d = "2006/05/03"
        MsgBox(Date.Parse(d.AddMonths(1).ToString("yyyy/MM") & "/01").AddDays(-1))

End Sub





'SQL

在SQL 有LASTDATE() 可以用

2012年12月4日 星期二

VB 字串轉時間格式


將字串轉為時間格式的三種方法

1.
Dim dt As DateTime
DateTime.TryParse("2003/8/15 上午 03:03:00", dt)

2.
Dim dt As DateTime
dt = DateTime.Parse("2003/8/15 上午 03:03:00")

3.
Dim dt As DateTime
dt = Convert.ToDateTime("2003/8/15 上午 03:03:00")

速度也是由1到3~~~1.最快但是2005才有

2012年11月12日 星期一

vb.程式間隔一段時間執行一次

剛好看到...雖然不符合要用的需求但或許之後用的到..先記錄下來



Private Sub Form_Load()
Timer1.Interval = 1000'把timer1設置成每隔一秒种觸發一次timer事件
End Sub

Private Sub Timer1_Timer()
Static a As Integer, b As Integer'全局變量
a = 1
If a = 60 Then b = 1:a=0'如果a=60了,就證明已經過了一分鐘了。那麼b再加上+1,如果b=5那麼就已經過了5分鐘了。
If b = 5 Then
'這後面寫你想執行的代碼
end if
End Sub

2012年11月9日 星期五

asp網頁編碼big5->utf8處理辦法


處理很久搞不定的big5 透過post將資料傳到utf-8的頁面會出現中文亂碼問題...
總算找到個解決方法..記錄起來
轉錄自:Itano Tomomi

asp網頁採用的編碼(encoding)是用系統預設的語系,在windows 2003底下是big5。那該如何將big5轉成utf8呢?這很簡單(不是團結的故事),使用Session.CodePage跟Server.UrlEncode()就可以了。
sourceURL = "http://itanotomomi.akb48/板野友美.htm"
dim i,utf8URL,tmp,encodingStr

for i=1 to Len(sourceUrl)
  tmp = mid(sourceUrl, i, 1)
  if asc(tmp) < 0 or asc(tmp) > 128 then  '將ascii碼在1~128以外的字元當成中文編成utf8
    Session.CodePage="65001" '先將網頁設成utf8
    encodingStr = Server.UrlEncode(tmp) '將中文編成utf8
    Session.CodePage="950" '再將網頁設為Big5
    utf8URL = utf8URL & encodingStr
  else
    utf8URL = utf8URL & tmp
  end if
next
為什麼要這樣做呢?因為asp使用Server.UrlEncode()進行編碼是採用系統預設的語系,若不更改網頁的語系為utf8,直接使用Server.UrlEncode()的話,會編成big5。而且千萬記得,編成utf8後,要再將Session.CodePage指定回big5,不然以big5為主的asp網站會整個亂掉。
不過若到上面為止,就想直接將encodingStr用response.redirect送出的話,會發現還是找不到網頁。那是因為response.redirect在導向的過程會採用系統預設的語系再編碼過一次...orz...
我目前解決的方式是不用response.redirect,改使用javascript的window.open()。不過缺點是會被瀏覽器擋住。
response.write "<script type='text/javascript'>window.open('" & utf8URL & "');</script>"
以上是純ASP的解決方法,接著介紹透過ASP.NET的解法。
首先是ASP端,將url編碼丟給ASP.NET。這邊採用預設編成big5就可以了,反正主要處理在ASP.NET端。 
sourceURL = "http://itanotomomi.akb48/板野友美.htm"
Response.Redirect "http://itanotomomi.akb48/passUTF8.aspx?q=" & Server.UrlEncode(sourceUrl)
接著在passUTF8.aspx.cs的Page_Load(若使用VB則是passUTF8.aspx.vb)中撰寫下面的語法。
string sourceURL = Request.Url.Query;
sourceURL = HttpUtility.UrlDecode(sourceURL, Encoding.GetEncoding("big5")); //將asp用big5傳來的url decode
sourceURL = sourceURL.Replace("?q=", "");
Response.Redirect(sourceURL);
因為ASP.NET使用utf8,所以將asp傳來的url編成utf8後就可以直接使用Response.Redirect()丟出去了。

2012年10月10日 星期三

Youtube iframe影片蓋住網頁浮動div elem

之前用時就有發現此問題,但當初youtube還可以選舊版程式碼,所以沒特別注意去處理。

最近客戶使用時沒辦法點選舊版程式碼(object),只好用iframe的方式卻發現會蓋住div圖層。

網路上找到了方法,只能說youtube不可能沒發現這問題,但大概就是懶得幫你加這句上去-.-

轉錄自:YIJEN'S BLOG

bug fixed code demo


Before

<iframe width="420" height="315" src="http://www.youtube.com/embed/678uZ7S_tKs" frameborder="0" allowfullscreen=""></iframe>

After

<iframe width="420" height="315" src="http://www.youtube.com/embed/678uZ7S_tKs?wmode=opaque" frameborder="0" allowfullscreen=""></iframe>

2012年9月23日 星期日

asp.net 抓取本月第一天&本月最後一天日期


百度知識家找到的 很實用 筆記起來..

// 本月的第一天           
DateTime firstDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
//本月的最后一天
DateTime lastDate = firstDate.AddMonths(1).AddDays(-1);
 
int weekDay = (short)DateTime.Today.DayOfWeek;
 
//本周一的日期
DateTime monday = DateTime.Today.AddDays(1 - weekDay);
//本周六的日期
DateTime saturday = DateTime.Today.AddDays(6 - weekDay);

2012年9月11日 星期二

ASP.NET 如何取得 Request URL 的各個部分


轉自:

我們在開發網頁應用程式,時常需要去解析網址(Request.Url)的每個片段,進行一些判斷。例如說 "http://localhost:1897/News/Press/Content.aspx/123?id=1#toc ",我們想要取得網址裡第一層目錄的名字(News)用以判斷不同的頁面標題(Page Title)。
我看很多人都用字串的 IndexOf 方法與 Substring 方法:
Request.Url.PathAndQuery.Substring(1, Request.Url.PathAndQuery.IndexOf("/", 1)-1)
這實在太埋沒 .NET 的強大設計了,事實上在 Request 物件就已經提供很多方便的屬性(Property)可供取得網址的片段。
底下這張表就是各種跟 Browser Request 的網址相關的屬性與用法:
網址:http://localhost:1897/News/Press/Content.aspx/123?id=1#toc
Request.ApplicationPath/
Request.PhysicalPathD:\Projects\Solution\web\News\Press\Content.aspx
System.IO.Path.GetDirectoryName(Request.PhysicalPath)D:\Projects\Solution\web\News\Press
Request.PhysicalApplicationPathD:\Projects\Solution\web\
System.IO.Path.GetFileName(Request.PhysicalPath)Content.aspx
Request.CurrentExecutionFilePath/News/Press/Content.aspx
Request.FilePath/News/Press/Content.aspx
Request.Path/News/Press/Content.aspx/123
Request.RawUrl/News/Press/Content.aspx/123?id=1
Request.Url.AbsolutePath/News/Press/Content.aspx/123
Request.Url.AbsoluteUrihttp://localhost:1897/News/Press/Content.aspx/123?id=1
Request.Url.Schemehttp
Request.Url.Hostlocalhost
Request.Url.Port1897
Request.Url.Authoritylocalhost:1897
Request.Url.LocalPath/News/Press/Content.aspx/123
Request.PathInfo/123
Request.Url.PathAndQuery/News/Press/Content.aspx/123?id=1
Request.Url.Query?id=1
Request.Url.Fragment 
Request.Url.Segments/
News/
Press/
Content.aspx/
123
所以當你看了這張表之後,你還會想用 Request.Url.PathAndQuery.Substring(1, Request.Url.PathAndQuery.IndexOf("/", 1)-1) 這種寫法嗎?
用這樣寫 Request.Url.Segments[1].Replace("/", "") 不是又短又直覺嗎? ^_^
以下是產生以上表格的程式碼:
protected void Page_Load(object sender, EventArgs e)
{ 

    StringBuilder sb = new StringBuilder(); 

    sb.Append("<table cellpadding=3 cellspacing=0 border=1>"); 

    sb.Append("<tr><td colspan=2>");
    sb.Append("網址:http://localhost:1897/News/Press/Content.aspx/123?id=1#toc");
    sb.Append("</td></tr>"); 

    // Request.ApplicationPath
    sb.Append("<tr><td>");
    sb.Append("Request.ApplicationPath");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.ApplicationPath + "</b>");
    sb.Append("</td></tr>"); 

    // Request.PhysicalPath
    sb.Append("<tr><td>");
    sb.Append("Request.PhysicalPath");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.PhysicalPath + "</b>");
    sb.Append("</td></tr>"); 

    // System.IO.Path.GetDirectoryName(Request.PhysicalPath)
    sb.Append("<tr><td>");
    sb.Append("System.IO.Path.GetDirectoryName(Request.PhysicalPath)");
    sb.Append("</td><td>");
    sb.Append("<b>" + System.IO.Path.GetDirectoryName(Request.PhysicalPath) + "</b>");
    sb.Append("</td></tr>"); 

    // Request.PhysicalApplicationPath
    sb.Append("<tr><td>");
    sb.Append("Request.PhysicalApplicationPath");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.PhysicalApplicationPath + "</b>");
    sb.Append("</td></tr>"); 

    // System.IO.Path.GetFileName(Request.PhysicalPath)
    sb.Append("<tr><td>");
    sb.Append("System.IO.Path.GetFileName(Request.PhysicalPath)");
    sb.Append("</td><td>");
    sb.Append("<b>" + System.IO.Path.GetFileName(Request.PhysicalPath) + "</b>");
    sb.Append("</td></tr>"); 

    // Request.CurrentExecutionFilePath
    sb.Append("<tr><td>");
    sb.Append("Request.CurrentExecutionFilePath");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.CurrentExecutionFilePath + "</b>");
    sb.Append("</td></tr>"); 

    // Request.FilePath
    sb.Append("<tr><td>");
    sb.Append("Request.FilePath");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.FilePath + "</b>");
    sb.Append("</td></tr>"); 

    // Request.Path
    sb.Append("<tr><td>");
    sb.Append("Request.Path");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.Path + "</b>");
    sb.Append("</td></tr>"); 

    // Request.RawUrl
    sb.Append("<tr><td>");
    sb.Append("Request.RawUrl");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.RawUrl + "</b>");
    sb.Append("</td></tr>"); 

    // Request.Url.AbsolutePath
    sb.Append("<tr><td>");
    sb.Append("Request.Url.AbsolutePath");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.Url.AbsolutePath + "</b>");
    sb.Append("</td></tr>"); 

    // Request.Url.AbsoluteUri
    sb.Append("<tr><td>");
    sb.Append("Request.Url.AbsoluteUri");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.Url.AbsoluteUri + "</b>");
    sb.Append("</td></tr>"); 

    // Request.Url.Scheme
    sb.Append("<tr><td>");
    sb.Append("Request.Url.Scheme");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.Url.Scheme + "</b>");
    sb.Append("</td></tr>"); 

    // Request.Url.Host
    sb.Append("<tr><td>");
    sb.Append("Request.Url.Host");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.Url.Host + "</b>");
    sb.Append("</td></tr>"); 

    // Request.Url.Port
    sb.Append("<tr><td>");
    sb.Append("Request.Url.Port");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.Url.Port + "</b>");
    sb.Append("</td></tr>"); 

    // Request.Url.Authority
    sb.Append("<tr><td>");
    sb.Append("Request.Url.Authority");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.Url.Authority + "</b>");
    sb.Append("</td></tr>"); 

    // local Request.Url.LocalPath
    sb.Append("<tr><td>");
    sb.Append("Request.Url.LocalPath");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.Url.LocalPath + "</b>");
    sb.Append("</td></tr>"); 

    // Request.PathInfo
    sb.Append("<tr><td>");
    sb.Append("Request.PathInfo");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.PathInfo + "</b>");
    sb.Append("</td></tr>"); 

    // Request.Url.PathAndQuery
    sb.Append("<tr><td>");
    sb.Append("Request.Url.PathAndQuery");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.Url.PathAndQuery + "</b>");
    sb.Append("</td></tr>"); 

    // Request.Url.Query
    sb.Append("<tr><td>");
    sb.Append("Request.Url.Query");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.Url.Query + "</b>");
    sb.Append("</td></tr>"); 

    // Request.Url.Fragment
    // 原則上你應該無法從 Request.Url.Fragment 取得任何資料,因為通常 Browser 不會送出 #toc 這個部分
    sb.Append("<tr><td>");
    sb.Append("Request.Url.Fragment");
    sb.Append("</td><td>");
    sb.Append("<b>" + Request.Url.Fragment + "</b>");
    sb.Append("</td></tr>"); 

    // Request.Url.Segments
    sb.Append("<tr>");
    sb.Append("<td>");
    sb.Append("Request.Url.Segments");
    sb.Append("</td>");
    sb.Append("<td>");
    string[] segments = Request.Url.Segments;
    foreach (string s in segments)
    {
        sb.Append("<b>" + s + "</b>");
        sb.Append("<br/>");
    }
    sb.Append("</td>");
    sb.Append("</tr>"); 

    sb.Append("</table>"); 

    ltlTable.Text = sb.ToString();
}
注意事項
  • 當程式部署(Deploy)到 IIS 6 之後,假設你的網址是http://localhost:1897/News/Press/Content.aspx/123 ? ,IIS 不知為何會將問號 ( ? ) 給刪除掉,以致於 ASP.NET 使用 Request.Url.Query 是空字串!如果你的程式有判斷到這部分時就要特別注意,因為照理說應該會抓到才對!不知道是不是 IIS 6 的 Bug ?