2009年3月31日 星期二

Sql Server Trigger: 當只有某幾欄被更新時

寫了一個 after trigger,如下

create trigger [dbo].[tr_afterUpdateTable] on [dbo].[MyTable]
after update
as
begin
	set nocount on
	//… my work
end

但是,當任何MyTable欄位的資料被更新時,這個 trigger 就會被觸發,就會跑很久。

不太妙。找到了 http://msdn.microsoft.com/zh-tw/library/ms186329.aspx ,但範例似乎不太對,因此修改了一下。如下,才能跑。

create trigger [dbo].[tr_afterUpdateTable] on [dbo].[MyTable]
create trigger [dbo].[tr_afterUpdateTable] on [dbo].[MyTable]
after update
as
begin
	set nocount on
	IF (SUBSTRING(COLUMNS_UPDATED(),1,1) & 6) > 0
	begin
		//當第2欄或第3欄被更新時
		// power(2, 2-1) + power(2, 3-1) = 6
		//… my work
	end
end

MSDN 的範例還是會有錯誤的時候哦!

不建議在 asp.net 上使用 office Interop 的原因

在Web solution 上,客戶常有一個需求。以 Excel 檔匯入資料,或匯出資料成Excel檔案。

匯出成 Excel 的方法,之前已有討論過了, 但不少的同事還是喜歡用 Interop 的方式。。

不建議。因為我之前也用過,下場蠻慘的。

見http://support.microsoft.com/kb/257757

此篇介紹微軟非常不建議直接在伺服器上安裝Microsoft Office 作為solution 的原因及建議。

Entity Framework: Database table 必須有 primary key

今天又想使用 entity framework 來計算 project server 2003 中,某一專案被專案經理審核接受的總工時。
找了一下,似乎 dbo.MSP_CUBE_ASSN_FACT 裡的資料可以使用,雖然必須 build cube 後才能讀到最新的值。

問題是,當我在 Visual Studio 2008 Entity designer ,使用 “update mode from database”,新增這個 table 時,一點作用也沒有,entity desinger 也沒有出現任何訊息。

原因呢?出在dbo.MSP_CUBE_ASSN_FACT 並沒有 primary key.

該 table 為了匯入時的效能,並沒有任何的 constraint,包括了 primary key。
但 entity desinger 也該出現一點訊息吧!

另外,這也大概是 Entity Framework 的一個缺點呢。雖然這是 by design 的。

2009年3月27日 星期五

Web Performance Turning 教學

今日無意間看到的中文 msdn 教學。

詳盡實用。開發 asp.net 的朋友們不得不看哦!

Web Performance Turning

http://msdn.microsoft.com/zh-tw/dd547432.aspx

2009年3月23日 星期一

2009年3月20日 星期五

IE 8 正式版出來了

IE 8 正式版出來了。

http://www.microsoft.com/windows/internet-explorer/worldwide-sites.aspx

自己挑一個語言吧。

2009年3月17日 星期二

Project 讀取大綱

最近又重操舊業了。又是 Project Server 2003.

原本的目的,是要讀取 Project Server 上某一專案的實際完成百分比。

下面的方法,原意是使用 Office DOM 來取得專案資訊。
這樣的方法,可以找到許多資料,但怎麼找也找不到實際完成百分比。

static void Main(string[] args)
    {
      ApplicationClass application = new ApplicationClass();
      application.Visible = true;
      bool opened = application.FileOpen(@"<>\伺服器上的專案.已發佈", 
        true, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
PjPoolOpen.pjPoolReadOnly, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

      Project p = application.ActiveProject;
      short i = (short) p.PercentComplete; //完成百分比
      short i2 = (short)p.PercentWorkComplete; //工時完成百分比

      foreach (OutlineCode item in p.OutlineCodes)
        Console.WriteLine(item.Name + item.FieldID.ToString()); //大綱
    }

注意到上面這一段程式,必須先執行 Project 2003 上連線到 Project Server 後再執行該程式。否則會有錯誤發生。

另外,Project Server 上的專案,必須以 <>\ 開頭來載入,這是比較奇怪的地方

更新!
可以讀取實際完成百分比了。而且也可以指定 status date 哦!程式片斷如下

private static short GetPhysicalPercentComplete(ApplicationClass application, string webProjName,
      DateTime statusDate)
    {
      bool opened = application.FileOpen(webProjName,
        true, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
PjPoolOpen.pjPoolReadOnly, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

      Project p = application.ActiveProject;
      p.StatusDate = statusDate;
      application.CalculateProject();
      Thread.Sleep(500);
      short physicalPercentComplete = (short)p.Tasks.get_UniqueID(0).PhysicalPercentComplete;
      application.FileClose(PjSaveType.pjDoNotSave, true);

      return physicalPercentComplete;
    }

Share with Facebook