在網上發現了一個.NET代碼產生器,可以自動產生網站,包括前台頁面,還可以按關係產生相應的代碼,以及資料庫等。這個軟體是ZAP,而且更重要的是他開放原始碼,不知道大家用過沒有。下面我簡單介紹一下。
安裝方法:
1、軟體及原始碼:http://www.superexpert.com/Code/ZAP/ZAPInstall_032307.zip。
2、下載後將其解壓到你的硬碟上。
3、大開VS2005 在工具菜單中選擇外部工具。在外部工具對話方塊中點擊添加。
4、將加入的新工具標題命名為“ZAP”,然後選擇命令的可執行檔,這裡在你的硬碟上選擇 ZAPTool\ZAP.exe,並將初時目錄修改為“$(ProjectDir)”,選中輸出視窗對話方塊,確定即可。如所示:
使用方法:
1、 開啟VS2005 建立網站,選擇空項目。
2、 選擇工具中的ZAP,執行產生網站。
網站產生後.NET IDE 不會自動重新整理項目目錄,要查看ZAP產生的結果,請在“解決資源管理員”中點擊重新整理按鈕。結果如:
ZAP的這些類都是按照zap.config中的配置產生的,我們可以修改他,讓他來產生我們所需要的類和控制項。預設的zap.config代碼如下:
<project
xmlns="http://superexpert.com/zap"
name="Project1">
<classes>
<class id="Class1">
<properties>
<property
name="id"
type="Int32"
isPrimaryKey="true"
isIdentity="true" />
<property name="title"/>
</properties>
</class>
</classes>
</project>
下面是修改後的zap.config代碼:
<project
xmlns="http://superexpert.com/zap"
name="Project1">
<classes>
<class id="MovieCategory">
<properties>
<property
name="id"
type="Int32"
isPrimaryKey="true"
isIdentity="true" />
<property name="name" label="Name"/>
</properties>
</class>
<class id="Movie">
<properties>
<property
name="id"
type="Int32"
isPrimaryKey="true"
isIdentity="true" />
<property
name="title"
label="Title"/>
<property
name="director"
label="Director"/>
<property
name="categoryId"
widget="DropDownList"
foreignClassId="MovieCategory"
foreignValuePropertyName="id"
foreignTextPropertyName="name" />
</properties>
</class>
</classes>
</project>
修改完畢後重新整理解決資源管理員,看ZAP為我們產生的程式碼、頁面和控制項,相信會讓你大吃一驚的,如:
開啟ZAP下的MovieCategoryList.aspx檔案,按Ctrl + F5運行項目,向系統中加入電影的分類,然後運行MovieList.aspx,結果如:
關於ZAP 的配置以及更多資訊請參見http://www.superexpert.com/Blog/Archive/17.aspx