2007年8月23日 星期四

如何使用 .Net 2.0 的 ConfigurationManager

你必須要先reference System.Configuration.dll,才可以用 ConfigurationManager,否則編譯時會出現
The name 'ConfigurationManager' does not exist in the current context
的錯誤。

2007年7月20日 星期五

瘋狂的點子

http://www.scaryideas.com/


BookPlus: A book will never let you down
BookPlus Radio Sport: Who said men can't multi-task? Can't multi-task? Apple T-Shirts from the '80s
Apple '80sTshirts



BookPlus: A book will never let you down
BookPlus Sony PSP: Fake book - The Divine Comedy PSP: Fake book
Neunkircher Zoologischen Garten: The Croc-eats-dog Promotion
Croc-eats-dog



MacGyver Multitool
MacGyver Mumbai Traffic Police: Blood Coasters Bloody Coasters Capriccio
Capriccio



Guinness: Balancing Glasses
Guinness: Balance Wonderbra Wonder Bra
Chopstix: You can't hate everything
Chopstix Wonderbra Wonder Bra
Wonderbra
Wonder Bra Wonderbra Wonder Bra



Chopstix: You can't hate everything
Chopstix Wonderbra Wonder Bra Manix Gel Manix Gel


使用 iTextSharp 做PDF套版

iTextSharp 是一套讓.Net可以處理PDF 的 library,它是從java 版的 iText衍生過來的,官方網站在http://itextsharp.sourceforge.net/ , 下面的範例示範如何讀取當範本的PDF,然後在上面加上中文字及Barcode39 。

值得注意的是 PDF 的座標系統跟螢幕是不一樣的,PDF 是從左下開始算,而螢幕是從左上開始算,只是我目前還不曉得 SetTextMatrix(x,y) 這個Method其中的x,y單位是什麼,另外範例中的這個 PDF範本,有一個很奇怪的地方,它的座標原點並不是在左下角,而是在文件中間?????

using System;
using System.IO;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace PDF1
{

/// <summary>
/// Class1 的摘要描述。
/// </summary>
class Class1
{
/// <summary>
/// 應用程式的主進入點。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此加入啟動應用程式的程式碼
//
PdfReader reader = new PdfReader("c:\\960621officer_fee.pdf");
int n = reader.NumberOfPages;
PdfStamper stamp = new PdfStamper(reader, new FileStream("c:\\sample2.pdf", FileMode.OpenOrCreate));

PdfContentByte over;
BaseFont bfChinese = BaseFont.CreateFont("C:\\windows\\fonts\\KAIU.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

over = stamp.GetOverContent(1);
over.BeginText();
over.SetFontAndSize(bfChinese, 18);
over.SetTextMatrix(-325, -340);
over.ShowText("ˇ");

over.SetFontAndSize(bfChinese, 26);
over.SetTextMatrix(-210, 145);
over.ShowText("游 錫 堃");

over.SetFontAndSize(bfChinese, 18);
over.SetTextMatrix(33, 148);
over.ShowText("A 1 2 0 4 3 5 X X X");
over.EndText();

Barcode39 barcode = new Barcode39();
barcode.Code = "0123456789";
barcode.PlaceBarcode(over,Color.BLACK,Color.BLUE);

// over.SetLineWidth(1f);
// over.SetColorStroke(Color.ORANGE);
// over.MoveTo(-320,-335);
// over.LineTo(-300, -335);
// over.Stroke();

stamp.Close();

}
}
}


2007年7月18日 星期三

用一張圖來解釋 Class ,Object, Instace 之間的關係

http://www.asp101.com/articles/sample_chapters/sitepoint_byoaspnet/chapter3.asp
Classes
You can think of a class as a template for building as many objects as you like of a particular type. When you create an instance of a class, you are creating an object of that class, and the new object has all the characteristics and behaviors (properties and methods) defined by the class.In our dog example, Rayne was an instance of the Dog class as shown in Figure 3.4.




2007年7月13日 星期五

使用Javascript複製 HTML格式的資料到剪貼簿

在工作上有遇到一個需求,就是要將網頁上的部分內容,讓使用者剪貼到Blog的HTML 編輯器,

原本很單純的想法就是使用 :
window.clipboardData.setData("Text", "HTML code goes here");

將網頁內容的HTML Copy 到 clipboard,但後來測試才發現這樣貼到 Blog的HTML 編輯器後,只是顯示出HTML 原始碼而已,而不是我要的網頁內容,google 了一下發現 window.clipboardData.setData 的第一個參數只有 "Text" 跟 "URL" 這兩種,並不支援 Copy HTML 格式的資料到剪貼簿,後來是試了好一陣子,終於找到下面的方法:

function CopyContent(sContenID)
{
var ctrlRange = document.body.createControlRange();
ctrlRange.add(document.all(sContenID));
ctrlRange.execCommand("Copy");
alert("已複製到剪貼簿");
}

這個function 可以將傳進來的的 tag 裡面的內容,用 HTML format copy到 Clipboard ,但有以下的限制:

  • 只能在IE 使用 :(
  • 如果該 tag 是 那要設成 可編輯才可以
  • <a href="http://www.blogger.com/...">是不能傳進去的

2007年7月10日 星期二

解決 window.open 開新視窗時, 原來的視窗會置換成 [object] 的問題

之前的同事遇到當User 點連結,新開一個視窗後,原本的視窗會被置換成只出現[object]的網頁,他原始的Tag 如下:

<a href="javascript:window.open('http://www.microsoft.com');">Click
here</a>

 



解決之道就是在後面加上 void(0)

<a href="javascript:window.open('http://www.microsoft.com');void(0);">Click
here</a>

 



原來window.open 會回傳一個window object,所以當User 點連結後,原本的視窗會被置換成只出現[object]的網頁,只要後面加上 void(0),告訴browser沒有回傳值,這樣就解決了。

請參考:

提供各種DB Connections String 範例的網站

http://www.connectionstrings.com/