麥克斯做個不宅的工程師

Maxi’s idiotic programming.

Remembering ListView page index and restoring it.

I am using ListView with DataPager to get a paging feature of my list.
I want to redirect my page when I click on an entry in the list view, show some detail information.
When I am done, I want to go back and view the exact same list of information.
That is, remembering the page index.

我是用DataPager幫我的ListView做分頁功能.我想要在使用者點選列表上某一條目後,
轉跳到別的頁面,顯示一些詳細資訊後,完成後回到剛才的列表頁面,要能看到剛才的那一個分頁.
就是說,要記住之前的頁碼.

Inside your ItemCommand handler method, use the following code snippet to find the correct startRowIndex
在你的ItemCommand處理程序裡面,用下面的程式片段去找出正確的startRowIndex

//index of the clicked item within the whole list
int l_dataIndex = ((ListViewDataItem)e.Item).DataItemIndex;
//minus the index of the item in that page = startRowIndex
int l_startRowIndex = l_dataIndex - ((ListViewDataItem)e.Item).DisplayIndex;
Store this index whatever you want, I store it by using GET method.
把索引值存在你喜歡的地方,我把它儲存在GET方法裡

Why do I call the above correct startRowIndex and not using the DataPager.startRowIndex?
Because we are going to use DataPager.SetPageProperties() in Page_Load() to restore the page we previously looking at.
為甚麼我會說上面的是正確的startRowIndex還有不去用DataPager.startRowIndex呢?
因為我們將會在Page_Load()裡用DataPager.SetPageProperties()去顯示之前我們在看的分頁

dataPager.SetPageProperties(l_startRowIndex, dpg_dataPager.MaximumRows, true);

This will bring you back to the page as we expect. But after this call.
The startRowIndex won’t update now even though you click next/previous to change your page.
That is why I said this is not the correct startRowIndex. You can try this youself ^^.
這個調用會把你帶到之前的分頁,正如我們預期.但在這個調用後,
startRowIndex就會停止更新,就算你點選上一頁/下一頁也不會改變.
這就是為甚麼我說上面的才是正確的startRowIndex.你可以自己試一試 ^^.

It turns out that I have done something stupid. The SetPageProperties() have to be inside IsPostBack to work correctly.
Result in something like this.

//in ItemCommand handler
url += "&startRowIndex=" + dataPager.startRowIndex;

//in Page_Load
if (!IsPostBack)
{
dataPager.SetPageProperties(startRowIndex, dataPager.MaximumRows, true);
}

June 16, 2009 , Tuesday Posted by maxi326 | Programming | , , , , | No Comments Yet

Javascript little technique in browser url

You can run a little piece of javascript code on a webpage.
Type “javascript:” and the follow by your javascript code in the url space.
Then you code snippet will run and return the value on the browser.

I use this to call getCenter() when using google map to figure out where I am now.

June 16, 2009 , Tuesday Posted by maxi326 | Programming | , | No Comments Yet

What the hell is SOA?

SOA stand for service oriented architecture, has nothing to do with technology being used.
只是一種架構規範,與技術無關.

Define :
Unit – a unit can provide many service, for example a school department is a unit.
Service – an independent logic/process, such as registration service of administration department.
定義 :
單位 – 可以提供多種服務,例如學校行政組
服務 – 一個獨立的邏輯/流程,例如行政組的入學登記服務

SOA purpose is to let those services continuously being developed and accumulate, running separately. Cluster into new service.
In developer point of view. They should think of how to develop service instead of application. Think of stacking old services
to create new service. And the terminal of this is applications which consume services. In other word, think in the service oriented way.
SOA目的,讓服務可以持續累積/發展,分散運行.結合並產生新服務.
對於開發人員,應該去想開發甚麼服務,組合既有服務去建立新服務,到開發終端應用程式時去消耗這些服務.就是用服務導向的思維去想事情.

About the technology, we need to use open standards, such as web service, xml, ODBC, HTTP, etc.
Different web servers provide different services. When creating new application or service, you can consume multiple services from different source,
and then combine them into your new application or service.
關於技術,需要透過開放標準來組合服務,例如web service, xml, ODBC, HTTP 等.
不同的伺服器提供不同的服務,要開發新應用或服務時,可以從不同的來源找尋你需要的服務,再整合成你的新應用或新服務

Advantages
– service can explicitly reuse and accumulate
– integrate resources from different sources
– easily introduce redundancy
好處
– 服務可以較明確的重用/累積
– 整合不同來源的資源(前述的服務)
– 更容易做redundancy

OASIS defines SOA as the following:
A paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. It provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations.

總結 : 在投入大量資源做SOA後,最難的就是怎樣去Discover那些service和安全性問題

June 16, 2009 , Tuesday Posted by maxi326 | Computer Science Knowledge | | No Comments Yet

資料庫正規化簡介(前四階段)

第一正規化(1NF) – 1. 排除重複群,即每欄位只放單一值 2. 每筆記錄都要有主鍵, 3. 同類事物只能用一個欄位

第二正規化(2NF) – 1. 1NF, 2. 每個欄都要跟整個主鍵有相依關係,而不是主鍵的部份有關,如果不是用複合主鍵,就一定是2NF

第三正規化(3NF) – 1. 2NF, 2. 非主鍵,屬性之間需互相完全無關

Boyce-Codd正規化(BCNF) – 1. 3NF, 2. 非候選鍵或候選鍵superset的欄位,限制了其他欄位的值,即存在欄位X->欄位Y的關係,就違反BCNF.如果表單裡沒有互相重疊的候選鍵,就必定BCNF

補充: 候選鍵即可唯一找出一筆資料的欄位組合,有可以作為鍵值潛力

還有四階NF, 4NF, 5NF, DKNF, 6NF, 通常用來處理特殊情況, 例如key不統一, 通常沒必要用到

June 16, 2009 , Tuesday Posted by maxi326 | Computer Science Knowledge | , | No Comments Yet