2014年1月26日 星期日

[.NET] 取得Server或Client IP

1. 取得Server IP語法:
using System.Net;
IPAddress ServerIP = IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address);
Response.Write("Server IP=" + ServerIP.ToString());

2. 取得Client IP
string strClientIP = Request.ServerVariables["REMOTE_ADDR"].ToString();
string strClientIP = Request.UserHostAddress;
//使用代理伺服器
string strClientIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();



參考資料:
http://blog.xuite.net/sunnysoap/r/25283108-C%23+%E5%A6%82%E4%BD%95%E5%8F%96%E5%BE%97%E6%9C%AC%E6%A9%9F(Server)%E7%9A%84IP
http://www.dotblogs.com.tw/jimmyyu/archive/2009/05/21/8493.aspx


http://bytes.com/topic/asp-net/answers/848515-how-get-client-ip-address-assigned-isp
http://dotnetstock.com/technical/how-to-get-ip-address-of-a-client-system-using-asp-net
http://csharpdotnetfreak.blogspot.com/2008/12/finding-ip-address-behind-proxy-using-c.html
http://forums.asp.net/t/1780050.aspx

[C#] 這個資料列已經屬於其他資料表

說明:
從DataTable依條件篩選出一些DataRow,想匯入另一DataTable object,卻出現Exception:這個資料列已經屬於其他資料表,例:
DataTable dtTemp = dtSource.Clone();
dtTemp.Rows.add(dr);

解決方法:
使用DataTable的ImportRow方法,例:
DataTable dtTemp = dtSource.Clone();
dtTemp.ImportRow(dr);


參考資料:
http://blog.mu1979.idv.tw/2007/10/datatabledatarowdatatable.html

[Cystal Report] DateAdd與DateDiff函式使用記錄

語法:
DateDiff (intervalType, startDateTime, endDateTime)
DateAdd (intervalType, nIntervals, startDateTime)
Year (CurrentDate) //取得Date之西元年

例:
DateDiff ("m", CDate (Mid({?Cycle}, 1, 10)), DateAdd ("d", 1, CDate (Mid({?Cycle}, 12, 10))))


參考資料:
http://pic.dhe.ibm.com/infocenter/rsawshlp/v7r5m0/index.jsp?topic=%2Fcom.businessobjects.integration.eclipse.designer.doc%2Fhtml%2Ftopic682.html


2014年1月20日 星期一

[T-SQL] REPLICATE與{fn LENGTH(string)}函數使用記錄

說明:依照table某欄位字串長度,加上某長度的特定字元。


作法:
1. 使用ODBC純量函數中的LENGTH函數。
    語法:SELECT {fn <function_name> [ (<argument>,.... n) ] }
    例: SELECT {fn LENGTH(Function_ID)}

2. 使用REPLICATE函數。
    語法:REPLICATE ( string_expression ,integer_expression )
    例:REPLICATE('=', {fn LENGTH(Function_ID)}-1)


參考資料:
http://msdn.microsoft.com/zh-tw/library/ms174383.aspx
http://jengting.blogspot.tw/2011/08/sql.html
http://www.dotblogs.com.tw/atowngit/archive/2010/10/04/18077.aspx
http://technet.microsoft.com/zh-tw/library/bb630290.aspx
http://msdn.microsoft.com/zh-tw/library/ms710249.aspx




2014年1月1日 星期三

[ASP.NET] 網頁導向Response.Redirect與Server.Transfer

說明:網頁導向有Response.Redirect與Server.Transfer兩種方法,有什麼不同?


說明:
Response.Redirect不會保留表單值,可導向外部網站,但送出兩次Request,一次給Source.aspx,一次給Destination.aspx。可用在get傳值。
例:
Response.Redirect("Destination.aspx?Value="+strValue);

Server.Transfer恰好相反,可保留表單值,但只限同一網站,Request一次效能較佳。


參考資料:
http://www.dotblogs.com.tw/jimmyyu/archive/2009/11/10/11503.aspx

2013年12月29日 星期日

[HTML] 常用tag記錄

說明:紀錄一些常用的tag

1. <!DOCTYPE>:用來告訴browser使用的HTML版本。目前HTML版本有HTML 4、XHTML 1.0與HTML 5,其中XHTML需有結束tag,並有Strict、Tradtional與Frameset 3種格式。

2. <meta>:用來描述網頁資訊,通常放在<head></head>中,有name、content與http-equiv等屬性。

3. <html></html>:標記內容為HTML碼。

4. <head></head>:描述頁面的相關資訊。

5. <title></title>:定意標題列。

6. <div></div>:將element群組起來,會另起一行(block element),常用id與class屬性搭配CSS。

7. <span></span>:為<div></div>的inline版本,常用id與class屬性搭配CSS。

8. <h1></h1>~<h6></h6>:定義標題格式,<h1>最大,<h6>最小。

9.<p></p>:開新行(block element)。

10. <br />:斷行(empty element)。

11. <hr />:水平線(empty element)。

12. <sup></sup>:顯示上標內容。

13. <sub></sub>:顯示下標內容。

14. <del></del>:刪除線。

15. <ol></ol>:編號清單,通常搭配<li></li>,預設會縮排。

16. <ul></ul>:項目清單,通常搭配<li></li>,預設會縮排。
<ul><li></li>
       <li>
          <ul>
             <li>巢狀清單</li>
          </ul>
       </li>
</ul>。

17. <a href></a>:超連結。
<a href="#top">Back to top</a>

18. <table></table>:表格。

19. <tr></tr>:開新列。

20. <td></td>:儲存格的資料,常用colspan屬性,來跨越多少欄位,rowspan來跨越多少列。

21. <th></th>:表格標題,常用屬性scope定義標題為col或row。

22. <fieldset></fieldset>:群組表單elements。常搭配<legend></legend>。

23. <!-- -->:註解。


參考資料:
ritw.com/w3school/tags/tag_comment.html
http://www.w3schools.com/tags/

2013年12月27日 星期五

[Crystal Report] 設定公式欄位

說明:有時候需要user輸入數值到報表做運算,這時可使用Crystal Report內建的公式欄位來進行後續的運算處理。
例:

原價 100
折數 user輸入
售價 100*折數並四捨五入到整數位


做法:
1. 在xxx.rpt上的欄位總管->公式欄位按右鍵->新增->輸入公式名稱->使用編輯器(個人prefer)
2. 參考Crystal Report提供之運算子或函式視窗,輸入公式:
例:Round (CDbl ({Product.Price}) * {?Rate}, 0) //使用CDbl轉換為數字型別

也可使用If then Else等流程控制函式,例:
if CDbl ({Product.Price}) > 10000
 then Round ((CDbl ({Product.Price})*0.3, 0)
else if  CDbl ({Product.Price}) > 5000
 then Round ((CDbl ({Product.Price})*0.2, 0)
else Round ((CDbl ({Product.Price})*0.1), 0)

也可使用Mid函式來分割字串,例:
Mid ({Test.Item}, 1, 5)
Item為abcdefg=>公式參數顯示為abcdf


參考資料:
http://www.blueshop.com.tw/board/show.asp?subcde=BRD20060703143341LX6
http://blog.marksgroup.net/2010/03/crystal-reports-sorting-by-substring.html