2015年8月17日 星期一

2015年5月2日 星期六

欄位變更名稱

問題:
MS - SQL 如何變更欄位名稱。

解決:

EXEC sp_rename 'TableName.OldColName','NewColName','column'

2014年10月30日 星期四

網頁轉PDF

問題:
網頁轉PDF。
解決方式:

var document = new HtmlToPdfDocument
{
GlobalSettings =
{
ProduceOutline = true,
DocumentTitle = "PDF Title", 
PaperSize = System.Drawing.Printing.PaperKind.A4, 
Orientation = TuesPechkin.GlobalSettings.PaperOrientation.Landscape, 
Margins = 
{ 
Top = 1.5, 
Right = 1, 
Bottom = 1, 
Left = 1.25, 
Unit = Unit.Centimeters 
} 
}, 
Objects = { 
new ObjectSettings { PageUrl = URL } 
} 
} 
IPechkin sc2 = Factory.Create();
var buf = sc2.Convert(document);
Response.Clear();
Response.HeaderEncoding = System.Text.Encoding.GetEncoding(950);
Response.AddHeader("Content-Disposition", "attachment; filename=Filename.pdf");
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(buf);


參考:TuesPechkin

2014年1月8日 星期三

2013年10月23日 星期三

千分位符號

問題:
貨幣或與金錢有關之數字顯示,必須格式化數字(含有千分位符號)。


解決方式:

ASP
Function MoneyFormat(ByVal value)
IF value <> "" Then
MoneyFormat = FormatNumber(value)
ELSE
MoneyFormat = value
END IF
End Function

ASP.NET
string.Format("{0:#,#}", 123456789);

2013年9月2日 星期一

ASP 網頁亂碼


問題:
 asp網頁有些字體是亂碼。

解決方式:
 以big5編碼為例, 在 asp 文檔最上面放入 <%@ codepage=950%> 並且設定 <%Response.CharSet = "big5"%>

2013年5月23日 星期四

轉換指定字串為字首大寫

問題:
轉換指定字串為字首大寫

解決方案:

TextInfo textInfo = new CultureInfo("en-US",false).TextInfo;
string propertyName = textInfo.ToTitleCase(Value);

討論:


有關字首大寫的方法很多,但不管使用哪種,建議擴充 string ,可以將 TextInfo 再包一層到 string 擴充方法中,

例如:
public static string ToTitleCase(this string value)
{
 if (value != null)
{
 StringBuilder sb = new StringBuilder();
 for (int i = 0; i < value.Length; i++)
{
  if (i == 0)
 {
   sb.Append(char.ToUpper(value[0]));
 }
 else
 {
  sb.Append(char.ToLower(value[i]));
 }
}
return sb.ToString();
}
else
{
  throw new ArgumentNullException();
 }