我現在參與的是一個multilingual ,multi-culture 基於web的項目。
要滿足英語,德語,法語等不同語種和文化客戶的需要。
資料庫要同時滿足Oracle和 MSSQL.
雖然說我們用了ASP.NET,但是我覺得並不是正宗的ASP.NET
我們只用到了其中的幾個feature,很多的可以說是ASP.NET精髓的東西都沒有用。
我們的Leader以前做ASP,PHP的經驗比較豐富,所以對ASP.NET的一些新功能不是高度興趣.
所以一些coding的要求也很有意思.
1. 我們用VS.NET 開發項目,code-behind,這點還不錯,沒讓用EditPlus.
2. 我們不用ASP.NET的Event,delegate機制.
Leader認為Http協議本身就Requst,Response,引入event是把簡單的事情複雜化了.
所以我們只在Page_Load()裡面寫代碼.
3. 我們不用ViewState. EnableViewState=“false“
4. 我們盡量不用ASP.NET Server Control,當然不用DataGrid,盡量用html 元素和Html Controls.
如果是GUI相關元素,或者這個元素需要在Post以後恢複或者賦值,就把這個元素的屬性設為 runat=server
5. 所有Form元素的值用Requst.Form[]取得.
我以前php,asp,jsp都有一定的經驗,所以下面的代碼結構我還是很快熟悉並習慣了.
我們用的最多的runat=server.和html control的動態輸出.
我們的代碼結構如下:
Page_Load()
{
//fetch configuration
//fetch the GUI element for the current culture
doInit();
//check and get the URL parameter values;
checkParameterElements();
if the page is post back then
//check and get the posted Form values;
checkFormElements();
if need to write to database then
writeToDatabase();
if no error happen then
//The non-GUI related data are retrieved from the database and render here.
renderDataUI();
if no error happen then
//GUI element render here
renderGUI();
}
常用的表格輸出代碼:
System.Web.UI.HtmlControls.HtmlTableRow tr;
System.Web.UI.HtmlControls.HtmlTableCell td;
foreach(DataRow dataRow in sortedTable.Rows)
{
tr = new HtmlTableRow();
td = new HtmlTableCell();
td.innerHtml="some stuff";
tr.cells.add(td);
table.rows.add(tr);
}
對於多語言介面和多資料庫支援.我們用了同樣的方法.
不同語言的text和不同資料庫的sqlstring都放在資料庫裡面.
只是text表裡面多了一個語言id欄位,區分不同語言的text
sqlstring表裡多了一個資料庫id欄位,區分不同的資料庫 sqlstring
沒有用到預存程序什麼的.
我也看了PetShop 3裡面的Present Layer ,Business Logic Layer, Data Access Layer劃分.
經過一段的程式設計的體驗,我慢慢習慣了我們目前的這種設計
也算是一種Framwork or Architecture 吧.
不知道各位朋友在類似項目或者ASP.NET項目中的設計體驗如何?
歡迎交流!