<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8827818669723021586</id><updated>2024-12-18T19:26:15.968-08:00</updated><category term="rdlc"/><category term="ASP.NET"/><category term="ASP.NET ReportViwer"/><category term="Blogger"/><category term=".NET"/><category term="JavaScript"/><category term="Project Managerment"/><category term="SQL"/><category term="LINQ"/><category term="FileManager"/><category term="deploy"/><category term="生活"/><category term="CodePlex"/><category term="DLL"/><category term="Export excel"/><category term="Exports PDF"/><category term="GridView"/><category term="IIS"/><category term="Javascript ashx"/><category term="WCF"/><category term="Web Project"/><category term="hibernate"/><title type='text'>皮尼網這走</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>41</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-3386204069156136405</id><published>2012-07-04T06:08:00.000-07:00</published><updated>2012-07-04T06:08:43.451-07:00</updated><title type='text'>[JavaScript] Observer Pattern Implement</title><content type='html'>上一篇講到簡單的observer Pattern的作法，這一篇我們把它寫成一個class&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;//Observer class
function Observer() {
  var topics = [];
   
   return{
    Register:function( topic, func ) {
        if(!topics[topic])
         topics[topic]=[]; // two dimension for store callback func
        topics[topic].push(func);
    },
    
    Publish:function( topic, args ) {
        if ( !topics[topic] ) {
            console.log(&#39;no such topic&#39;);
            return false;
        }
        var subscribers = topics[topic];
        for(var i in subscribers)
         subscribers[i](topic,args);
    },
    
    UnRegister:function( topic ) {
        if ( !topics[topic] ) {
            return false;
        }
        topics[topic]=null;
    }
   }
};
&lt;/pre&gt;
如何使用呢?&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;//How to use
var observ = new  Observer();
 
 //call back signature (topic,data)
 var testHandler = function (topics, data) {
    console.log(&quot;1:&quot;+topics + &quot;: &quot; + data);
 };
 var testHandler2 = function (topics, data) {
    console.log(&quot;2:&quot;+topics + &quot;: &quot; + data);
 };
 
 observ.Register(&#39;cal1&#39;, testHandler);
 observ.Register(&#39;cal1&#39;, testHandler2);
 observ.Publish(&#39;cal1&#39;, &#39;hello world!&#39;);
 observ.Publish(&#39;cal1&#39;, [&#39;test&#39;, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;]);
 
 observ.UnRegister(&#39;example1&#39;);
 
 observ.Publish(&#39;example1&#39;, &#39;hello world!&#39;);
&lt;/pre&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
執行結果如下 &lt;br /&gt;
&lt;img alt=&quot;&quot; src=&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAI0AAABWCAIAAAB9xYIeAAAD90lEQVR4nO1bQZLDIAzr/1+2xz30P9nDznSoZQtDCMHEmhxS1wiBYjopw+v9+3Mklsfr/fuT1/rX6531FAHpUww0+PQqUAavEZb4wpdPLwOsvc+nDjubHgiPzv+EamY3UPDAB1r6pHZfdiwG7LGze2pE185kD1uHGA8E8z0+eZSdTCOt0qcx9eQkUTnLuEVFpkDIq7LhiMiQeZNyKjjzYJ9UnOngw0yCOEhs1VoufK45eVMTDPbp5+ivJ1W92Y1vRVX5CYOlk6hVZVsl5Zn35XzCuDoYK7kavKiePAlb+YSLoV9HrHXPk9bq00k0/D55blRxgkc0FPHPUMUDYTEgj2hlDU2lFZxWR0ir3ltT1IGzv098qIlRyP/3YiB9ioH0KQZynzDGlfUUA+lTDOQ+YQzM2Cfse8dqeiA8Ol/w8jsWKHjgA335PuEZraJrZ7KHrUmGH4L5Hp88ynhCt0+tHfGEzX3i9eQRhDPlXyvIFAh5VTYckUen2qScCs482CcVZzooya0IDhKbtJYLn2tO3tQEg336OSbtE6pp1Zo46ZPFVvVJ5HA9y/mEcXUwVnI1eFE9eRK28gkXQ6cOVTfG11n3PGmtPp3E5fuEVSrR9jNU8UBgJvaiklhDU2kFJxkOfsR7a4o6kPuEMZD/78VA+hQD6VMM5D5hjCvrKQbSpxjIfcIY2OQ84Vgs+Eb4oPOEzpzWzDl40HnCJhmBfeL15CRROcu4RWUxCG2EU617q1LJInHLqrjbeULOSR4Xrs3T5FLsdp7QEunsETN5HU/DbvuEnsKtxj1NJmO384SedQ/1izj5apV1T4UqXb05tAHg2iK8F5lCCWew2mIcadUeVc3W/TQ8dJ/QEkwGcu8Yn/j/XjiTjmf6FBHpUwzkPmGMK+spBtKnGMh9whjY5DzhWCz4Rvig84RNAgL7pLdvmb5un1o7OpPTmjkHm5wnRGHIqda9ValkkbhlVdztPCHntMyuavM0uRS7nSe0RDp7xExex9OQ+4Q6eWCfcDF0zqNzmqate6hfxMlXq6x7KlTp6s2hmcGpRNtyXvCj1Qu2xTjSqj2KTIvEmtCLkPuErjj/agKe+P9eOJOOZ/oUEelTDOQ+YYwr6ykG0qcYyH3CGJh0nvAKDHxvW/9pm3Ge8Dqs/MYzFpPOE16E9OnAIK8ni6RMLoNWCQp+0dbJo+pUR6GOUZmnuzFjn7CchePbSNVUzFQ/qjeCyjJD5Fj862DGPqHfJ+tbq6MhPvkHciNm7BM2+YT5pIv06cAgLobVGUcG3uqWdY/wr4NJ+4QlubiXgr7jWLXiuVFbWf2KYeJHS9XteOI+YSy1/3jc/3sRH6zjgT4FRfoUA3/CmIdJl4uWDwAAAABJRU5ErkJggg==&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
沒想到使用Javascript寫一個Observer Pattern會如此簡單 ....</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/3386204069156136405/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/3386204069156136405' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/3386204069156136405'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/3386204069156136405'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2012/07/javascript-observer-pattern-implement.html' title='[JavaScript] Observer Pattern Implement'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-7394951970865176936</id><published>2012-07-02T08:46:00.000-07:00</published><updated>2012-07-02T08:47:07.629-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>[JavaScript] Observer Pattern Cont.</title><content type='html'>續上篇&lt;br /&gt;
Observer Pattern真的是一個蠻好用的Pattern，以我工作的例子是我會去操作一個第三方的JavaScript API，操作完之後這個API只會產生一個事件，而且這個事件裡面會帶一個參數表示目前的狀態&lt;br /&gt;
如下&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;trdParty.onCallback(function(status){
   // do something you want
});

trdParty.doMethod();
&lt;/pre&gt;&lt;br /&gt;
onCallback會在每次呼叫不同的doMethod都會回傳目前的狀態，你可以透過偵測status的狀態來執行你想做的事情，最簡單的方式是透過類似HashTable的方式來做mapping，如下&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var funMap = [];
funMap[&#39;status1&#39;] = function(status)
{
   //do statu1 need to do
};
funMap[&#39;status2&#39;] = function(status)
{
   //do statu2 need to do
};

trdParty.onCallback(function(status){
   funMap[status.Text](status); //這裡就會依照status.Text的狀態類型呼叫對應的method了
});

trdParty.doMethod();
&lt;/pre&gt;透過以上的方法可以簡單的做funciton mapping呼叫。但如果針對一個status可能有好幾件事情要做呢?&lt;br /&gt;
說真的，透過JavaScript來達到二維的呼叫也是很簡單&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var funMap = [][]; //二維
funMap[&#39;status1&#39;].push(function(status)
{
   //do statu1 need to do -- 1
});
funMap[&#39;status1&#39;].push(function(status)
{
   //do statu1 need to do -- 2
});
funMap[&#39;status2&#39;].push(function(status)
{
   //do statu2 need to do -- 1
});
funMap[&#39;status2&#39;].push(function(status)
{
   //do statu2 need to do -- 2
});

trdParty.onCallback(function(status){
   for(var fn in funMap[status.Text])
   {
      funMap[status.Text][fn](status);
   }
});

trdParty.doMethod();
&lt;/pre&gt;&lt;br /&gt;
怎樣，很簡單吧。&lt;br /&gt;
&lt;br /&gt;
不過這樣寫每次沒辦法利用，時間晚了，下次再來介紹整個Observer Pattern...&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/7394951970865176936/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/7394951970865176936' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/7394951970865176936'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/7394951970865176936'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2012/07/javascript-observer-pattern-cont.html' title='[JavaScript] Observer Pattern Cont.'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-3861969313057935417</id><published>2012-06-28T08:48:00.000-07:00</published><updated>2012-06-28T17:07:04.390-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>[JavaScript] Observer Pattern</title><content type='html'>這是在我日常的工作中是一個很常被使用到的Pattern，它使用起來的方式如下&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var callback = function(topic, data){
   console.log(topic + &#39;: &#39; + data);
}

//假設observe object 已存在
observe.addCallback(&#39;MyTopic&#39;,callback);

observe.fireCallback(&#39;Mytopic&#39;, &#39;my data 1&#39;);  // Mytopic : my data 1
observe.fireCallback(&#39;Mytopic&#39;, &#39;my data 2&#39;);  // Mytopic : my data 2
observe.fireCallback(&#39;Mytopic&#39;, &#39;my data 3&#39;);  // Mytopic : my data 3

&lt;/pre&gt;&lt;br /&gt;
基本上使用起來很像.NET中event的方式&lt;br /&gt;
&lt;br /&gt;
To be continue ...</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/3861969313057935417/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/3861969313057935417' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/3861969313057935417'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/3861969313057935417'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2012/06/javascript-observer-pattern.html' title='[JavaScript] Observer Pattern'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-1877123309400677745</id><published>2012-06-28T08:14:00.000-07:00</published><updated>2012-06-28T17:06:34.941-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>[JavaScript] Advanced Object Declaration</title><content type='html'>上一篇文章中提到了幾個JavaScript class的宣告方式，以及用該class來宣告物件。而這一篇會介紹比較Advanced的物件宣告方式&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Literal&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;//object declaration with attribute and method
var person = {
 //public attribute
 name:&#39;&#39;,
 year:0,
 
 //public function
 Init:function(name, year){
  this.name=name;
  this.year=year; 
 }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Module&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;//can declare private/public attribte and method
var Person = (function(){
 //private attribute
 var name;
 
 var privateInfo=function(){
  return this.name;
 };
 
 //All public method and attribute
 return{
  //public attribute
  Nickname:&#39;Andy&#39;,
  //public method
  getInfo:function(){
   return Nickname + &quot; - &quot; + name;    
  }
 }
})();
&lt;/pre&gt;&lt;br /&gt;
目前看起來好像只有透過所謂Module的宣告方式才可以有public/private的特性，其他方式的的宣告方法看起來都沒有這個效果.&lt;br /&gt;
&lt;br /&gt;
有鑑於有我第一次看到Module的宣告方式看了好久都看不懂，還以為是所謂的新語法，其實不是，帶我一一來拆解&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;//一般方法的宣告方式
var Person = function(){ /*do what you want*/ };

//execute method
Person();
&lt;/pre&gt;&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;//如果方法裡面有回傳值
var Person = function(){ 
 /*do what you want*/ 
 
 // return a JSON object
 return{
  pubVar:&#39;&#39;,
  pubMethod:function()
  {
   // do method
  }
  
   
 }
};
//execute the same method
var obj = Person();
//get PubVar
var val = obj.pubVar;
//execute pubmethod
obj.pubMethod();
&lt;/pre&gt;那如果宣告的同時就順便執行呢?&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;//用()把整個function的宣告包起來後順便再()執行
var person = (function(){ /*do what you want */ })();

//get PubVar
var val = obj.pubVar;
//execute pubmethod
obj.pubMethod();

&lt;/pre&gt;&lt;br /&gt;
不曉得各位看官有沒有看懂了</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/1877123309400677745/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/1877123309400677745' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/1877123309400677745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/1877123309400677745'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2012/06/javascript-advanced-object-declaration.html' title='[JavaScript] Advanced Object Declaration'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-6728207878223079856</id><published>2012-06-20T08:06:00.000-07:00</published><updated>2012-06-28T17:06:50.479-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>JavaScript class 宣告方式</title><content type='html'>在JavaScript的語法中，光是class的宣告方式就有好幾種，底下列出我所知道的宣告方式&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;function Person(name,year){
 //public attribute
 this.name=name;
 this.year=year;
 
 //public method
 this.getInfo(){
  return &#39;I am &#39;+ this.name + 
      &#39;,and I am &#39; + this.year + &#39;years old&#39;;
 }
}
&lt;/pre&gt;&lt;br /&gt;
用法&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var p = new Person(&#39;Andy&#39;,&#39;18&#39;);
p.getInfo();
&lt;/pre&gt;&lt;br /&gt;
你也可以透過Prototype的方式宣告&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;function Person(name,year){
 //public property
 this.name=name;
 this.year=year;
}
//public method
//底下方法也可以宣告public property
//public method
Person.prototype.getInfo = function(){
  //public method
  return &#39;I am &#39;+ this.name + 
      &#39;,and I am &#39; + this.year + &#39;years old&#39;;
};
&lt;/pre&gt;..&lt;br /&gt;
或者這樣宣告&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var Person = function(name,year){
 //public attribute
 this.name=name;
 this.year=year;
};

//public method
Person.prototype.getInfo = function(){
  //public method
  return &#39;I am &#39;+ this.name + 
      &#39;,and I am &#39; + this.year + &#39;years old&#39;;
};
&lt;/pre&gt;另一種宣告class的方法，不過這個方法我不知道怎麼宣告constructor&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var Person = new Class;

//public method
Person.prototype.getInfo = function(){
  //public method
  return &#39;I am &#39;+ this.name + 
      &#39;,and I am &#39; + this.year + &#39;years old&#39;;
};
&lt;/pre&gt;&lt;br /&gt;
靜態方法(static method)部分，可以這樣宣告&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;//Person is class name
Person.find = function(id){/* ... */}

&lt;/pre&gt;&lt;br /&gt;
//instance method部分，也可以這樣宣告&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;//instance a Person object
var person = new Person(&#39;Andy&#39;,18);
person.find = function(id){/*  .... */}

&lt;/pre&gt;&lt;br /&gt;
下次再來介紹如何宣告物件 ....</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/6728207878223079856/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/6728207878223079856' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/6728207878223079856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/6728207878223079856'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2012/06/javascript-class.html' title='JavaScript class 宣告方式'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-5703093296532905257</id><published>2012-03-19T07:17:00.001-07:00</published><updated>2012-03-19T07:17:35.639-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Project Managerment"/><title type='text'>[讀書心得 part4] 交辦時，務必說清楚、想明白</title><content type='html'>大家好，我又來分享讀書心得啦 ^^&lt;br /&gt;
今天跟大家分享訣竅三&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;勉強他的能力，不要勉強他的意願&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;話說沒有意願，能力再好都是枉然，可見意願的重要性。所以平常一定要跟member混熟，指派工作的時候，一定要了解他的能力是否有辦法完成這個交辦，如果有辦法完成自然比較好說服，如果比較難完成，那在指派的時候也一定要想辦法說服他。我很常會用的招式是:你把這件事情完成，你就會學習到以後該怎麼處理這樣類型的工作了。目前看起來成效很爛(冏)&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;他有沒有個人目標，會影響工作成敗&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;說真的，我也覺得這點很重要，但問題要讓member有個人目標其實真的還蠻難的，我也曾經幫member訂過目標，但效果其實不符合預期，或許我該找時間好好來跟member談談他的目標到底在哪?&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;不合理的工作要求，交辦給誰最好呢?&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;我覺得交辦給誰都不好，所以如果可以把不合理的工作要求合理化，那交辦出去的機會可能會大一點。例如寫程式，一隻程式可以花一天沒架構沒規劃的方式寫出來，也可以花三天好好的規畫寫出來，當時間急的時候，你要一個很有sense的member花一天寫出來，你該如何說服他?去年我就常遇到這樣的事情。那時候跟我合作的member能力非常好，但對程式撰寫有一定程度的潔癖，說真的，要我寫出一個很糟的程式，對我來說也是一種虐待。所以我會先跟他討論，跟他說目前事情的急迫性，以及目前會跟老闆報告說現在的方式會產生的問題，日後我們需要再額外花時間來refactor目前寫的程式，讓老闆知道。還好那位member跟我交情還不錯，我們就這樣完成了大多數的程式，之後有被refactor的部分也有80%以上。&lt;/li&gt;
&lt;li&gt;所以我寧願先讓事情盡量合理化，再來做所謂的交辦，萬一不行，也跟member討論出平衡點。&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;他不是你的分身，做法不一樣，千萬別跳腳&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;話說寫程式裡有一個流程叫做code review，通常是組織裡比較資深的member幫比較資淺的member review code，review的過程中，可以提出建議的做法，以及指出有問題的地方。我覺得code review 對我來說也是練功的一種，有時候可以看到自己沒想過的作法，當然有時候也會看到讓自己氣得跳腳的寫法。從寫程式就可以知道，針對同一種需求，不同的人去寫程式，通常不太可能寫出一樣的code，但只要知道目標在哪(這真的很重要)，確定過程中都是往目標的正確路徑，我想就算中間稍微停頓看個風景也不為過。&lt;/li&gt;
&lt;/ul&gt;
&lt;/ol&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/5703093296532905257/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/5703093296532905257' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/5703093296532905257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/5703093296532905257'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2012/03/part41.html' title='[讀書心得 part4] 交辦時，務必說清楚、想明白'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-4062233880387731931</id><published>2012-03-12T07:58:00.000-07:00</published><updated>2012-03-12T07:58:43.045-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Project Managerment"/><title type='text'>[讀書心得 part3] 硬塞前，先慎選人與事</title><content type='html'>今天來跟大家分享【交辦的技術 讀書心得 Part3】&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;交辦標準，不是看他做不做得到&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;作者說交辦是指把這件事情的【責任】交付出去給member，member在接到工作的同時也同時擔負起完成這件事情的【責任】。身為Leader腦袋真的要轉過來，雖然明明知道很多事情member其實並沒有足夠的能力來完成，但如果一昧的攬在自己的身上，到頭來只是讓自己更累，團隊產出更少，而且少了培養member的機會，會讓整個團隊的競爭力降低。&lt;/li&gt;
&lt;li&gt;當member承擔這個任務成敗的【責任】後，勢必會更用心的去處理，過程中千萬別插手，一插手，事情的責任馬上就轉到自己身上了。例如，你叫member寫一個專案Deploy的SOP，過程中如果你插手給予意見，則member勢必認為只要把你的意見加入，就萬無一失，有問題的話也不是自己的問題，因為已經參照你給的意見來執行了，所以身為Leader千萬要忍住。&lt;/li&gt;
&lt;li&gt;當然還是要評估這件事情是不適合由該member來執行，如果難度太高，一樣會陷入【交辦失敗】的魔咒，所以身為Leader可能還是需要想一些方式讓Member可以較順利的執行該任務，藉由完成該任務來提升member的能力。&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;三種工作，別突然硬塞&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;陌生的工作&lt;/li&gt;
&lt;li&gt;非緊急重要事項&lt;/li&gt;
&lt;li&gt;指派人力的工作&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;針對上述三項工作，我覺得比較有趣的是【非緊急重要事項】。前陣子剛好看了某時間管理的文章，文中將事情分為四個象限，分別是【緊急】、【重要】、【非緊急】、【非重要】。將這四個象限去組合，則可以得到【非緊急重要事項】。而處理這四個現象的先後順序分別是1.【緊急重要】2.【非緊急重要】3.【緊急非重要】4.【非緊急非重要】。很多人常常把2,3處理搞混，連我都不例外，不過只要接受這個理論，就可以順利地交辦的事項一一完成。&lt;/li&gt;
&lt;li&gt;所謂【非緊急重要事項】通常是長久規畫的策略或方針，將這類的事情交辦給部屬，無疑是主管自己無能(機會高)，或者真的是member能力超好(機會低)。member對於due date還很久的事項，通常較缺乏經驗去執行，而且這類的事物通常有很多事情並非member的權責可以決定，例如:半年後的新專案開發架構。身為Leader必須將這類事務細分成多個工作包(WBS)，當細分成WBS後，即可讓每個WBS依序成為【緊急重要事項】，則member依WBS的順序去執行，則每個階段就都可以有產出，最後完成這個【非緊急重要事項】。&lt;/li&gt;
&lt;li&gt;至於另外兩個【
陌生的工作&amp;nbsp;】和【
指派人力的工作&amp;nbsp;】接導因於member對這類交辦經驗薄弱，例如
指派人力的工作，member可能連自己要完成某個交辦需花多少時間都估不出來了，你還要他去指派別人工作?&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;預防災難，你得會看人&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;其實這個部份我還很少機會用到，書上指的是要會用【領導人】，小弟我還沒機會成為可以指派【領導人】的人。不過重點還是開船著船長要知道目的地在哪，路線規劃要漂亮，相關環境變數收集齊全，才能順利帶領船員，快快樂樂的出航，平平安安且順順利利的到達目的地。&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;菜鳥和老鳥，交辦方式肯定不一樣&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;這應該是廢話，但不知道會不會有人白目到連這個都不知道。不過菜鳥分兩種【能力好的】跟【能力差的】；老鳥也分兩種【能力好的】和【能力差的】。針對菜鳥當然再交辦事項的時候要給予適當的指導，但遇到能力好的，更需要給予適當的發揮及尊重，這是我個人的感覺。而老鳥部分，能力好的就給予極度的尊重，但別忘了還是要訂一下schedule，能力差的我會跟他討論，並希望盡量藉由討論來取得他願意執行的平衡點，重點還是schedule要訂一下，不然滑掉的機會很高。&lt;/li&gt;
&lt;/ul&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/4062233880387731931/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/4062233880387731931' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/4062233880387731931'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/4062233880387731931'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2012/03/part3.html' title='[讀書心得 part3] 硬塞前，先慎選人與事'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-5149320510664509114</id><published>2012-03-07T05:03:00.000-08:00</published><updated>2012-03-07T05:03:55.066-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Project Managerment"/><title type='text'>[讀書心得 part2] 做中學你硬塞給他就對了</title><content type='html'>&lt;br /&gt;
&lt;div&gt;
今天來分享【交辦的技術 part2】&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;交辦工作，不用等到【對他有信心】&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;我覺得像我這種菜鳥leader，或者好人leader絕對想不到這一點，腦海中想到的都是怎樣把member&lt;b&gt;有辦法處理的事情&lt;/b&gt;交辦給他，所以都會自己花時間把難的部分先解決掉，剩下比較簡單的部份還會先跟member講解該怎麼處理。作者說的對，想當初人家assign給我job的時候也很少教我該怎麼去處理，或許懂得如何自己去處理的人才可以真正的成長，我覺得我腦袋沒轉過來反而阻礙了member成長的機會。&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;成長，都是勉強來的&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;同上，記得有一個理論是說，如果你針對一件task要達到至少80分，那你就要求自己或member往100分的目標去邁進，就算沒能達到100分，應該至少都有八、九十分的水準。雖然自己很討厭別人凹我，但我不去凹member，那到頭來只是讓整個團隊的績效都卡到自己身上而已，於團隊的進步跟產出沒什麼幫助。&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;你得【保障】他的失敗機會&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;作者說，當你把工作指派給member的時候，他就同時被賦予需要擔負這項工作成敗的責任了。也因為擔負了這個責任，他才能更用心地去完成這項工作；不過並不是每件事情因為擔負了責任，努力去做就一定可以順利完成，當Leader的我，通常腦海中想著該怎麼樣讓事情順利的進行不要出錯，但這卻是最要不得的想法，待我說來。&lt;/li&gt;
&lt;li&gt;首先如果自己想讓事情進行順利的想法，必定就不希望member往錯誤的方向邁進，或著允許他交出錯誤的成果，但像寫程式這種事情，不讓他去try error幾次根本就學不到經驗。我有時候會太龜毛幫member寫一個template讓他照著寫就好，孰不知這樣讓他少學習到很多，到頭來事情做完了，他還是沒學到東西，講白一點，下次一樣的事情要他做他可能還不知道從何開始，因為我的雞婆讓他少了學習的機會。&lt;/li&gt;
&lt;li&gt;唯有接受member失敗的結果才能讓他真的去學習到東西，雖然這真的很天人交戰，尤其老闆壓我schedule的時候更是難以實行。但如果不狠心讓schedule滑個幾次，永遠都沒有讓member學習的機會，永遠事情都只會壓在我自己身上而已。當member有從交辦的事項中學習到，下次處理類似的交辦工作才能真的獨立去完成，但是要在schedule與讓member學習抉擇，真的是一件很難的事。&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;想培養他，就從【分外】工作開始&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;其實作者說【分外】的工作指的是leader的工作，像是協調利害關係人相關的事務，以及做一些規劃類事情。我覺得這一點真的要睜大眼睛去看你的member是怎麼想的。如果你常把這類的工作交辦給member，正面一點的member會覺得有磨練的機會，負面一點的大概就會覺得你在凹他了，就像我常常覺得有某人在凹我一樣。這時候怎樣把交辦這類的事項用漂亮的方式包裝好再交給member就是一項學問了。&lt;/li&gt;
&lt;li&gt;講白一點，就是想辦法說服member能心甘情願的去處理這類的事物，而不要讓他覺得被凹了，我本人就很討厭被凹的感覺。但我也知道事情總是要有人處理，今天這件事情會落到我身上，大概也是凹我的人schedule嘎不過來了，但如果他能說出漂亮的理由說服我，我可能就傻傻地覺得處理這樣的事務也不錯，可以學到額外的經驗，反之，下一秒我就會跟別的同事抱怨說:【你看，XXX又那凹我了!!!】。相同的道理，身為leader有這類的事情要指派，還是要學會察言觀色比較重要。&lt;/li&gt;
&lt;/ul&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
其實在寫這些心得的同時，我也常常在想遇到相同的事情自己該怎麼處理。也希望大家能分享一下自己的經驗及想法。&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/5149320510664509114/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/5149320510664509114' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/5149320510664509114'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/5149320510664509114'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2012/03/part2.html' title='[讀書心得 part2] 做中學你硬塞給他就對了'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-4212835747342199352</id><published>2012-03-06T04:45:00.000-08:00</published><updated>2012-03-06T04:45:48.051-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Project Managerment"/><title type='text'>[讀書心得 part1] 交辦的技術</title><content type='html'>&amp;nbsp;這本書是透過博客來的eDM才看到的，剛好這陣子遇到了。看了一下書的介紹感覺還蠻有趣的就用禮券去金石堂買了(哈)。&lt;br /&gt;
&lt;br /&gt;
雖然說我不是主管，但卻一職被賦予要帶team member做事的使命，我從事軟體相關工作，從工作到現在大概六年，除了第一年沒有帶member，之後幾乎每一年都需要帶member做事，這時候member能力的好壞，以及我跟member之間的關係就嚴重地影響到工作的成果。&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://im1.book.com.tw/exep/lib/image.php?image=http://addons.books.com.tw/G/001/0/0010532260.jpg&amp;amp;width=200&amp;amp;height=280&amp;amp;quality=80&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://im1.book.com.tw/exep/lib/image.php?image=http://addons.books.com.tw/G/001/0/0010532260.jpg&amp;amp;width=200&amp;amp;height=280&amp;amp;quality=80&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
底下要分享的是我自己的心得對應書裡的章節 &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;當主管第一件要學的事 &lt;/b&gt;(先說我根本不是主管)&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;放手讓他做，他就會成材&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;我的經驗來說，要放手讓member還是要考量member的能力。如果member能力不足，放手讓他做只會造成他的壓力，但我卻一直忽略了壓力才能讓人成長，不過我個人覺得只有適當的壓力才會讓人成長，過多的壓力只會壓垮member，所以要衡量交辦一件事情對member造成多少壓力其實不好評估。我只知道能力好的壓力應該會比較低，能力差的壓力應該很大。&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;交辦失敗會摧毀一個人&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;最近一位我帶的member因為能力不太足夠，我所交辦的每一件事情感覺對他都造成了莫大的壓力，但這件事情我卻是過了一陣子才發現，喪失了讓他學習的機會，因為能力不夠的關係，應該已經讓他連學習的時間或想法都沒了，尤其我所從事的工作是需要寫程式的，寫程式這種東西會的就是很快，不會的你給他再多時間可能都不夠。如果我能早點發現他的能力不足，或許可以提早訓練他，但目前因為專案時程都很趕，有時候跟他的對話都會因為他完成事項的不足而露出不滿意的話語，我想這部份真的很值得學習。與其交辦失敗摧毀一個人，倒不如想方法讓這個member變成可用之材還比較好。&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;糾正【無法交辦】心態的訣竅&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;&lt;ul&gt;
&lt;li&gt;這裡主要是說，對於事情要不要交辦，主管的心態會去衡量說&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;這件事情太難，還是我自己來好了&lt;/li&gt;
&lt;li&gt;這件事情太簡單，我來處理比較快&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;其實身為一個leader如果不適當的把手中的事情交辦出去，最後只會造成自己生產力降低而已，對老闆來說身為leader的你的產出，不應該跟身為你member的產出是一樣的價值的。身為leader應該著重在規劃，再把規畫要做的事情交付給member，這樣才能提升團隊的績效。所以不管什麼事情，只要是可以交辦給member的應該都要盡量的交辦出去，不然最後member沒事做，自己卻因為事情太多處理不完而成為團隊的bottleneck，對團隊來說是一點幫助都沒有，所以應該要往這個方向去邁進，member也能從交辦的事項當中學習到處理事情的經驗，就由交辦事項提升能力，期望能一舉兩得。&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
其實在PMP中也有一個領域是在講Human Resource Management的談到獲得專案團隊、開發專案團隊及管理專案團隊，遇到人的問題真的去實施都是很難的。</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/4212835747342199352/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/4212835747342199352' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/4212835747342199352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/4212835747342199352'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2012/03/part1.html' title='[讀書心得 part1] 交辦的技術'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-2311502070689915672</id><published>2011-03-07T05:59:00.000-08:00</published><updated>2011-03-07T06:04:57.463-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Javascript ashx"/><title type='text'>模擬Javascript取得client IP</title><content type='html'>有朋友問在LoadBalance後的ASP.NET程式取得的Client IP都是LB的虛擬IP，這是因為後面的LB之後，Client的Request會先傳送到LB的Server，再透過LB往後傳送到真實的Server，所以透過ASP.NET的Request.UserHostAddress會抓取到的是虛擬IP。針對這個問題我想到的有兩種解決方案，第一透過RIA程式，例如Silverlight或Flex之類的程式抓取ClientIP後，再透過操作dom物件塞到html dom，這樣submit的時候就能取得;第二種做法是找一台不在LB後面的機器，也就是用IP可以直接access到的server，在這一台server提供一個模擬Javascript寫出hidden的欄位，其值再給予Client IP即可(因該Server不在LB後面所以Request.UserHostAddress可以正確抓取Client IP)，以下示範第二種做法使用ASP.NET實做。&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
撰寫一泛型處理常式 ClientIP.ashx如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE_ywfTl6LeE9TISN9PPl6gPaa2mbEZ10u4Spyn80_3tDZyJukik6GVmP5x710mis-Hkc-H2_iaaAqwxbr-F0mpQo_ttWnCP5148b_KTlV0OXDC07fdAw3k9AQM5HzSh6_vIEaYfnEDg/s1600/ClientIP_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE_ywfTl6LeE9TISN9PPl6gPaa2mbEZ10u4Spyn80_3tDZyJukik6GVmP5x710mis-Hkc-H2_iaaAqwxbr-F0mpQo_ttWnCP5148b_KTlV0OXDC07fdAw3k9AQM5HzSh6_vIEaYfnEDg/s1600/ClientIP_1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
注意第9行ContentType設定為 text/javascript，這是為了模擬Javascript，而第11行模擬Javascript的document.write的時候要注意拖曳字元的部分使用了\\兩個，第一個是給C#程式使用的，而第二個是給Javascript使用的，目的是要給C#可以印出document.write(&#39; ＜input type=\&#39;hidden\&#39; ...&lt;br /&gt;
&lt;br /&gt;
撰寫完上面的程式碼後，我們接下來看怎麼套用，新增一個aspx的網頁，內容如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdsop68y8XR4FzJlBiOAFB8hlk1bY3BHqsI0C6EDZT9Y0wpGVys7f3458UVN-f9cP3y9_MEbYKUKJNJxqDkO_Xm4lcYUVH3XsNC004H67alG-fn954k6DSBpcsys6sNktQoQDq27xk7A/s1600/ClientIP_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdsop68y8XR4FzJlBiOAFB8hlk1bY3BHqsI0C6EDZT9Y0wpGVys7f3458UVN-f9cP3y9_MEbYKUKJNJxqDkO_Xm4lcYUVH3XsNC004H67alG-fn954k6DSBpcsys6sNktQoQDq27xk7A/s1600/ClientIP_2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
注意12行的地方新增一按鈕，這是為了製造submit(PostBack)所用，13行部分使用javascript的src語法將ClientIP.ashx引入，注意這裡因為我是測試程式，都放在同一台電腦，正確來說你應該會放在一台具有獨立IP的Server，例如 &lt;i&gt;http://210.100.50.20/ClientIP.ashx&lt;/i&gt; ，最後請於該按鈕的click event中撰寫程式碼如下(注意16行需使用Request.Form[&quot;UserIP&quot;]才能抓取到透過Javascript 寫出的hidden欄位)&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga7rh9RLhTvGz18a5cu_b81l1Eu-3CYJlGVqKw3nBPScYVmReqi7SQ49qQTrbIU2fR_NplMULbpHQ7BpNR7I7P3VFLpSSQtCu0mD5F9W4a6bhnCQXHgFCpvIdPIiLfMHCFC1UYJdDubA/s1600/ClientIP_4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga7rh9RLhTvGz18a5cu_b81l1Eu-3CYJlGVqKw3nBPScYVmReqi7SQ49qQTrbIU2fR_NplMULbpHQ7BpNR7I7P3VFLpSSQtCu0mD5F9W4a6bhnCQXHgFCpvIdPIiLfMHCFC1UYJdDubA/s1600/ClientIP_4.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp;瀏覽網頁點選按鈕執行結果如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju2TJSMwV3OmWrSarJZvcUejgPtXSnmndkhIFs3qx16qP9PMzht_4Q3CuBUEcydMiKwgnxTchtvc2yY0rSqug-155P27EfRGjupXO_FLfNEHT38W64Zgwonpjfd16P82d_ayxyQMbHSA/s1600/ClientIP_3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju2TJSMwV3OmWrSarJZvcUejgPtXSnmndkhIFs3qx16qP9PMzht_4Q3CuBUEcydMiKwgnxTchtvc2yY0rSqug-155P27EfRGjupXO_FLfNEHT38W64Zgwonpjfd16P82d_ayxyQMbHSA/s1600/ClientIP_3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/2311502070689915672/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/2311502070689915672' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/2311502070689915672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/2311502070689915672'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2011/03/javascriptclient-ip.html' title='模擬Javascript取得client IP'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE_ywfTl6LeE9TISN9PPl6gPaa2mbEZ10u4Spyn80_3tDZyJukik6GVmP5x710mis-Hkc-H2_iaaAqwxbr-F0mpQo_ttWnCP5148b_KTlV0OXDC07fdAw3k9AQM5HzSh6_vIEaYfnEDg/s72-c/ClientIP_1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-4820602041935185444</id><published>2010-10-19T09:00:00.000-07:00</published><updated>2010-10-19T17:21:39.326-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><title type='text'>LINQ not in</title><content type='html'>今天因為處理繪圖需要針對集合做not in的運算，主要是因為TeeChart提供的API實在太弱了，所以有些運算只好自己土法煉鋼。故事大綱是這樣的，我有100個Point，符合條件的其中的20個我想要拿掉，如果不使用LINQ的話，做法如下&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:csharp&quot;&gt;    //針對Point的定義
    class PointF
    {
        public double X { set; get; }
        public double Y { set; get; }

        public override bool Equals(object obj)
        {
            PointF inObj = obj as PointF;
            return this.X == inObj.X &amp;amp;&amp;amp; this.Y == inObj.Y;
        }
    }

    List&lt;PointF&gt; points = new List&lt;PointF&gt;(); 
    List&lt;PointF&gt; flagPoint = new List&lt;PointF&gt;();  
    for (int i = 0; i &amp;lt; 100; i++) 
    {
       PointF point = new PointF { X = i, Y = i };
       points.Add(point);
       if (i % 5 == 0) //製造符合條件的point
          flagPoint.Add(point);
    }
    Console.WriteLine(&quot;total point {0}&quot;,points.Count.ToString());
    Console.WriteLine(&quot;flag point {0}&quot;, flagPoint.Count.ToString());
    //比對以移除符合條件的點
    for (int i = 0; i &amp;lt; points.Count; i++)
    {
       for (int j = 0; j &amp;lt; flagPoint.Count; j++)
       {
          if (points[i].X == flagPoint[j].X &amp;amp;&amp;amp; points[i].Y == flagPoint[j].Y)
          {
              points.Remove(points[i]);
              break;
          }
       }
    }
            
    Console.WriteLine(&quot;points point {0}&quot;, points.Count.ToString());
    Console.WriteLine(&quot;flag point {0}&quot;, flagPoint.Count.ToString());

    Console.ReadKey();
&lt;/pre&gt;
其結果如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOOHOC7nIa6uksO8Mbd5mtamrhCYmL8QVc0_rvWE_v2nVXWwPnM3zcz0l0s6M-Rp9mTuahDeTpq2KbzIi7nmGb9uC__UMeM6hqMZSzcYkDVi5Nmo2_cBdA5dtpzdHHr9pUJV3xThDeRg/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOOHOC7nIa6uksO8Mbd5mtamrhCYmL8QVc0_rvWE_v2nVXWwPnM3zcz0l0s6M-Rp9mTuahDeTpq2KbzIi7nmGb9uC__UMeM6hqMZSzcYkDVi5Nmo2_cBdA5dtpzdHHr9pUJV3xThDeRg/s1600/1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
改成使用LINQ的話&lt;br /&gt;
&lt;pre class=&quot;brush:csharp&quot;&gt; 
 List&lt;PointF&gt; points = new List&lt;PointF&gt;();
 List&lt;PointF&gt; flagPoint = new List&lt;PointF&gt;();
 for (int i = 0; i &amp;lt; 100; i++)
 {
     PointF point = new PointF { X = i, Y = i };
     points.Add(point);
     if (i % 5 == 0)
        flagPoint.Add(point);
  }
  Console.WriteLine(&quot;total point {0}&quot;,points.Count.ToString());
  Console.WriteLine(&quot;flag point {0}&quot;, flagPoint.Count.ToString());

  points = (from c in points
            where !flagPoint.Contains(c)
           select c).ToList&lt;PointF&gt;();

  Console.WriteLine(&quot;points point {0}&quot;, points.Count.ToString());
  Console.WriteLine(&quot;flag point {0}&quot;, flagPoint.Count.ToString());

  Console.ReadKey();
&lt;/pre&gt;
&lt;br /&gt;
結果會與上面一樣&lt;br /&gt;
&lt;br /&gt;
透過LINQ，程式碼可讀性會提高很多，不過這裡的not in的用法第一次用，所以稍微花了點時間找</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/4820602041935185444/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/4820602041935185444' title='4 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/4820602041935185444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/4820602041935185444'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2010/10/linq-not-in.html' title='LINQ not in'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOOHOC7nIa6uksO8Mbd5mtamrhCYmL8QVc0_rvWE_v2nVXWwPnM3zcz0l0s6M-Rp9mTuahDeTpq2KbzIi7nmGb9uC__UMeM6hqMZSzcYkDVi5Nmo2_cBdA5dtpzdHHr9pUJV3xThDeRg/s72-c/1.png" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-5215374008381775952</id><published>2010-08-20T20:14:00.000-07:00</published><updated>2010-08-20T20:41:01.826-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><title type='text'>Java 與 .NET 使用心得</title><content type='html'>本來下面的內容，是要寫在SCWCD考試心得的，不過看看好像有點跳Tone了，所以就另外寫一篇文章來分享吧 ^^ &lt;br /&gt;
&lt;br /&gt;
我想要分享一下J2EE跟.NET技術的心得，雖然很多年沒寫Java了，但這些年並沒有荒廢學習新的技術，可以說其實這幾年非常熟悉使用.NET的技術來開發系統了，說.NET技術可能並不會有啥大不了的感覺，但如果說用.NET的&lt;b&gt;架構&lt;/b&gt;可
能就有比較囂張一點，一直以來Java的人都有點瞧不起.NET的，認為那不過是玩具而已，年紀好像越資深越是這樣。&lt;br /&gt;
&lt;br /&gt;
我的看法是這樣，我從2000年開始
學習使用Java技術，當時還是個學生，到了2003年開始接觸.NET，當時也還是個學生，當時的我覺得.NET真是個抄襲Java抄襲的很完全的東
西，不過Tool真的做得蠻好用的，就是相關的套件(Ex: 
Collections)少了點，2005年後開始工作，也沒想太多，人家說用什麼就用什麼，所以一開始就來比較硬的Struts，當初也學到不少東西，
因為搭配Ibatis，順便在當時學到了ORM的技術，不過沒寫多久就被抓去寫.NET了，那之後寫了將近五年的.NET;也從一邊喜歡.NET的好
Tool，一邊抱怨.NET可以用的Framework太少，到現在看到.NET的大成長(WF,WCF,WPF,ORM 
EF,LINQ)，現在的我覺得.NET已經超好用了，沒想到卻要回去寫Java了，再回來看Java，這幾年幾乎沒啥大進步，實在覺得有點可惜。&lt;br /&gt;
&lt;br /&gt;
不過有老師說：［技術本身沒有好壞，只有用的人才有好壞］，我可以理解這個道理。我目前的公司已經有20幾年的歷史，資訊系統少說也有十幾年的歷
史，.NET也不過就是在這幾年才大躍進，如果在那個時間點，腦袋沒壞的人應該也都是會選Java吧(其實這裡還有很多C跟C++呢)，而身為一個IT人
員，不應該只是因為專長於某種特定的技術而自喜，反而應該站在管理者的角度去看，這個時候應該用什麼技術，用什麼Solution才是對後續的發展是有益
的。最後，如果你只是把自己定位成一個IT黑手，我相信這樣心態的人可能早晚會被時間的洪流所淘汰，但如果你是把自己定位成一個IT問題解決者，我相信你應該無時無刻都在學習新的技術、架構跟管理手法吧，時間的洪流對你來說，不會只是年紀的增加，還會有知識與經驗的成熟，希望大家能一起共勉之。&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/5215374008381775952/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/5215374008381775952' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/5215374008381775952'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/5215374008381775952'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2010/08/java-net.html' title='Java 與 .NET 使用心得'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-4921537944120886706</id><published>2010-08-20T20:11:00.000-07:00</published><updated>2010-08-20T20:41:10.736-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="生活"/><title type='text'>SCWCD 考試心得</title><content type='html'>其實今年是本人第一次換工作，長久以來已經用.NET的技術非常的習慣了，也從來沒想過會再回來接觸Java的技術，進新公司後老闆的期許就是去弄一張SCWCD的證照來，所以也只好入境隨俗去考一張來應應景。這其實已經超過我考證照的極限了，一直以來我都是一年頂多一張證照，而今年年初我就已經去弄了張微軟的BI證照了，想說以後應該可以少寫很多程式開始來玩商業智慧了，沒想到人算不如天算，進了家大公司後，其實資訊系統相當龐大且複雜，所以才發現自己會的技術便顯得相當的渺小了。&lt;br /&gt;
&lt;br /&gt;
廢話不多說，我準備SCWCD其實大概一個月，但是考試的書(猛虎)是從三個月前就已經買好擺在那了，一直以來都有斷斷續續在看，而早在大學時期其實就有寫J2EE的經驗了，剛開始工作的第一年也有寫J2EE，還是用Struts呢，所以對SCWCD的考試內容其實並不算陌生(章節都有看過，就是內容不清楚而已 ^^&quot;)，建議真的要考試的人還是要工作有用到才好，不然其實像我寫了好幾年的.NET，在看SCWCD的時候，常常會想到這個技術在.NET裡面是怎麼用的，有時候會分心，心中只是care如果用.NET來寫應該怎麼用(我承認我是來鬧的)，不過也因為這樣讓我對J2EE的技術更加的了解，這對我準備SCWCD來說是另一項收穫。&lt;br /&gt;
&lt;br /&gt;如果你已經是一個熟悉J2EE的開發者，建議你只花兩個禮拜來準備就好了。首先花一個禮拜把猛虎從頭到尾看一遍，另一個禮拜安排每天練習習題，最好到考試前能夠重複練習超過三次以上，把會答錯的問題做上記號，考試前一個小時光看那些會答錯的題目就好了，我是依循這樣的方式去考，最後雖然沒有滿分過關，但分數也不低就是了。&lt;br /&gt;
&lt;br /&gt;
如果你不是一個熟悉J2EE的開發者，建議你先買額外的書籍，在此建議買Head First系列的JSP and Servlet，不過你可能需要先花一個月K這本書，另外在花另一個月K猛虎吧，這樣是為了確保考過之後，你是真的懂SCWCD，而不是只是考過而已。&lt;br /&gt;
 &lt;br /&gt;
 我是在新竹的巨匠考的，因為剛好之前在台北的巨匠有上過課，所以在巨匠買考券有折扣(詢問過III,UUU了)，不過考試前倒是有一些小插曲，當我進入考場詢問考場人員相關注意事項的時候，考場人員丟了一句話說，如果你是背題庫的，請至少撐過半小時再出來，真是傷人阿 ;雖然我是看著題庫練習的，但被這樣說是有點不爽，不過這表示Oracle SUN的考試本來就有漏洞阿，題庫在外面就買的到了，還是最搶手的書籍，這能怪誰呢。&lt;br /&gt;
&lt;br /&gt;
前一份工作我還有機會可以面試新人，當時看到有證照的人我通常會問一些相關的問題，已確定他是否真的有實作經驗，而不是背題庫去換張證照而已，沒想到當我去考試的時候，還被這樣詢問，實在是有點不是滋味。&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/4921537944120886706/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/4921537944120886706' title='3 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/4921537944120886706'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/4921537944120886706'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2010/08/scwcd.html' title='SCWCD 考試心得'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-4265715975545432914</id><published>2010-07-21T09:25:00.000-07:00</published><updated>2010-07-21T09:31:32.352-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><category scheme="http://www.blogger.com/atom/ns#" term="IIS"/><category scheme="http://www.blogger.com/atom/ns#" term="WCF"/><title type='text'>探討ASP.NET Run Account</title><content type='html'>會寫這篇文章是因為最近使用WCF 呼叫 COM object的時候遇到了權限的問題。原本我一直以為WCF host on IIS的時候，他的Run Account就會和ASP.NET的設定一樣，由於我原本所撰寫呼叫的COM object使用WCF host在IIS上的時候，一直出現奇怪的錯誤(看不出來是權限問題)，但是host在console ap or windows service上面都是OK的，所以我還是直覺是Run Account的問題。為了解決這個問題我才知道WCF的Run Account並不是跟ASP.NET的設定一樣，而是直接聽命於Application pool的Run Account。底下做了一些實驗(PS:先確定ASP.NET的authentication mode為windows)。&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;實驗一:&lt;/b&gt;預設的Run Account (新增一個aspx的頁面，並於加入底下程式碼)&lt;br /&gt;
&lt;pre class=&quot;brush:csharp&quot;&gt;protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    }
&lt;/pre&gt;
上面的程式碼執行結果如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxyuIR4Ez952mDeqS8UNkNl_ZVVqVi5S-46j8K-Q69xadKmgru63BUwLabWbKAFhn5Bh8C9TnT3dtLk6GMRh7gLQADFvT4RIfWlUcRLmAekMrIpezIyI2vW-lZWoDKSdRJ1WP6RDeVMA/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;149&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxyuIR4Ez952mDeqS8UNkNl_ZVVqVi5S-46j8K-Q69xadKmgru63BUwLabWbKAFhn5Bh8C9TnT3dtLk6GMRh7gLQADFvT4RIfWlUcRLmAekMrIpezIyI2vW-lZWoDKSdRJ1WP6RDeVMA/s320/1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;由上圖可知，預設為NETWORK SERVICE的帳號在執行asp.net的頁面&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;實驗二:&lt;/b&gt; 當使用impersonate時&lt;br /&gt;
&lt;pre class=&quot;brush:xml&quot;&gt;&lt;identity impersonate=&quot;true&quot;&gt;
&lt;/identity&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
執行結果如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-IjUXZtpos6qldhvzGktSy9o93t2J3NOLlj9UPggLzL1caCbQsyAIBPCL19ZI48F6B7Sxtwx4tHFpQzv1_M6W0unQq3BaS259nnENAI9zZsU4jYpBFIgum_kJiV_gKgE_FxxViAYkzg/s1600/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-IjUXZtpos6qldhvzGktSy9o93t2J3NOLlj9UPggLzL1caCbQsyAIBPCL19ZI48F6B7Sxtwx4tHFpQzv1_M6W0unQq3BaS259nnENAI9zZsU4jYpBFIgum_kJiV_gKgE_FxxViAYkzg/s320/2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
由上圖可知，使用impersonate之後的Run Account改為匿名的帳號了，如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhWI79umxff89MOC8KSRf5yD34mDLaRfdrsejty7dnvHVetk3gVJqMEVbsKi8cgaNFuLUZutjcA-SRiBhF4o022zvskutXNI-qJf4p2A2i_3d9i13NFEm8U2bM14fVkNFH0DdRNQFIqQ/s1600/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhWI79umxff89MOC8KSRf5yD34mDLaRfdrsejty7dnvHVetk3gVJqMEVbsKi8cgaNFuLUZutjcA-SRiBhF4o022zvskutXNI-qJf4p2A2i_3d9i13NFEm8U2bM14fVkNFH0DdRNQFIqQ/s320/3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;實驗三:&lt;/b&gt;WCF的Run Account&lt;br /&gt;
請先新增一WCF Service，並撰寫程式碼如下&lt;br /&gt;
&lt;pre class=&quot;brush:csharp&quot;&gt;//制定ServiceContract(IWCFService.cs)
[ServiceContract]
public interface IWCFService
{
    [OperationContract]
    string GetRunAccount();
}

//實做契約
public class WCFService : IWCFService
{
    public string GetRunAccount()
    {
        //回傳Run Account
        return System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    }
}
&lt;/pre&gt;
&lt;br /&gt;
然後請先增Client proxy (這裡就不介紹怎麼新增Client Proxy了)，且在aspx中呼叫WCFService，程式碼如下&lt;br /&gt;
&lt;pre class=&quot;brush:csharp&quot;&gt;protected void Page_Load(object sender, EventArgs e)
    {
        //Label1.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
        WCFServiceReference.WCFServiceClient client = 
            new WCFServiceReference.WCFServiceClient();
        Label1.Text = client.GetRunAccount();

        client.Close();
    }
&lt;/pre&gt;
&lt;br /&gt;
期執行結果如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxyuIR4Ez952mDeqS8UNkNl_ZVVqVi5S-46j8K-Q69xadKmgru63BUwLabWbKAFhn5Bh8C9TnT3dtLk6GMRh7gLQADFvT4RIfWlUcRLmAekMrIpezIyI2vW-lZWoDKSdRJ1WP6RDeVMA/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxyuIR4Ez952mDeqS8UNkNl_ZVVqVi5S-46j8K-Q69xadKmgru63BUwLabWbKAFhn5Bh8C9TnT3dtLk6GMRh7gLQADFvT4RIfWlUcRLmAekMrIpezIyI2vW-lZWoDKSdRJ1WP6RDeVMA/s320/1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;注意&lt;/b&gt;，這裡出現的Run Account確實讓我感到非常意外，我原本以為應該是與實驗二的結果一樣才是，經過google大神的指導，我才知道這裡的Run Account是follow Application pool的，如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqTX4cNgHHN_DaRaFNaI5CPGW1LFA10khNyEu-RTDvuMyWXaTbRp0k-XpbztH02jX-Vbwp9C0JlolqiwGkqr0du84J1Iq290k6MXH_uOkqY_quteN3ApvgyGNxHj1SFAkB1A2L5HHHGw/s1600/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;201&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqTX4cNgHHN_DaRaFNaI5CPGW1LFA10khNyEu-RTDvuMyWXaTbRp0k-XpbztH02jX-Vbwp9C0JlolqiwGkqr0du84J1Iq290k6MXH_uOkqY_quteN3ApvgyGNxHj1SFAkB1A2L5HHHGw/s400/4.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;所以當我們在這裡修改程式集區的執行帳戶時&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsVa47XLoG1WYgDYuj6itOqzheYG46h3f5P7CovE7hcZamVUav-9MzzdJv94uLbn7fRZSeuleDkObIOHpWqGyUDIjF91c8JFF6RYgbWYsQiqZbsA2BQu-ke-k4zvqIK4hDAsGI9x7lPQ/s1600/5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;192&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsVa47XLoG1WYgDYuj6itOqzheYG46h3f5P7CovE7hcZamVUav-9MzzdJv94uLbn7fRZSeuleDkObIOHpWqGyUDIjF91c8JFF6RYgbWYsQiqZbsA2BQu-ke-k4zvqIK4hDAsGI9x7lPQ/s400/5.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;執行的結果如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhysvN38L4Dwv35zB_zQJssfLgk_le3dFinAQHV-xgezWPjuhC5K4nnSH8YpWb157IR1z9leApHkPy-4HxlimZvw00ZiT8GkfJkeyPUD3r7zCNsLGp20r67xvOIzgEtklV6mhyVY6fjkQ/s1600/6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhysvN38L4Dwv35zB_zQJssfLgk_le3dFinAQHV-xgezWPjuhC5K4nnSH8YpWb157IR1z9leApHkPy-4HxlimZvw00ZiT8GkfJkeyPUD3r7zCNsLGp20r67xvOIzgEtklV6mhyVY6fjkQ/s320/6.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
確實是聽從Application Pool的執行帳號&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;結論:&lt;/b&gt;&lt;br /&gt;
沒寫過不知道，寫了之後就知道。這種地方一般的WCF書籍並不會寫到，而且可能也不會有很多機會Host on IIS的時候需要調整執行帳戶的。但事情就是這麼巧，就這樣讓我碰到了，這個問題我花了兩天才找出來，從呼叫COM object開始追，最後追到這裡才追到。另外，其實在impersonate的時候，也可以指定其他帳戶，但這個其他帳戶都是屬於ASP.NET的，對WCF並不會起作用喔。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/4265715975545432914/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/4265715975545432914' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/4265715975545432914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/4265715975545432914'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2010/07/aspnet-run-account.html' title='探討ASP.NET Run Account'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxyuIR4Ez952mDeqS8UNkNl_ZVVqVi5S-46j8K-Q69xadKmgru63BUwLabWbKAFhn5Bh8C9TnT3dtLk6GMRh7gLQADFvT4RIfWlUcRLmAekMrIpezIyI2vW-lZWoDKSdRJ1WP6RDeVMA/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-222033146163926032</id><published>2010-06-14T08:20:00.000-07:00</published><updated>2010-06-19T09:00:36.451-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="hibernate"/><title type='text'>Hibernate in Eclipse</title><content type='html'>本篇文章先不介紹Hibernate的相關內容，只著重在如何搭配Eclipse plugin來產生Hibernate的相關設定檔。&lt;br /&gt;
&lt;br /&gt;
要讓Hibernate能夠work的最基本條件，就是需要有底下三種東西 &lt;br /&gt;
1.Configuration File (hibernate.cfg.xml)&lt;br /&gt;
2.Mapping File (*.hbm.xml) -&amp;gt;hibernate 3.x 可以直接使用Annotation在DTO 中描述即可&lt;br /&gt;
3.DTO&lt;br /&gt;
&lt;br /&gt;
依照下列的操作方式，一步一步即可 (注意 : 這裡亦不介紹hibernate plugin的安裝，之後的文章中再介紹)&lt;br /&gt;
&lt;br /&gt;
步驟1:注意，這裡要選擇Others(圖片抓的不好)&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheItCz73MDiZgf8Ceo06-P3RSB06RSdl9aipAwihLZIfqVjbRNgPNbDwTcYlivN1kwL5GYYexcgZ33o1JV-yCF3GfdbG_DS8Oc_PKRO_ku90cl2OqyUEpQXJ1MgeK_0SLUgh4ooL4XIQ/s1600/1.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheItCz73MDiZgf8Ceo06-P3RSB06RSdl9aipAwihLZIfqVjbRNgPNbDwTcYlivN1kwL5GYYexcgZ33o1JV-yCF3GfdbG_DS8Oc_PKRO_ku90cl2OqyUEpQXJ1MgeK_0SLUgh4ooL4XIQ/s640/1.PNG&quot; width=&quot;486&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
步驟2 : 選擇 Hibernate Configuration File (cfg.xml)，點選Next&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIpnTp7aRc8xt9d4RFfF5VfrfrQ0cSzqsyJ1zNaJE5jVAc-4HLll8z4mHPiDuud_Ye8fzXcDlWKG99Xqi3Wt-1w07dQGltO6dd6SdBr3yN1ihtSxI6siOYGSmgOikuYFz0KwKBldsYrg/s1600/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;612&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIpnTp7aRc8xt9d4RFfF5VfrfrQ0cSzqsyJ1zNaJE5jVAc-4HLll8z4mHPiDuud_Ye8fzXcDlWKG99Xqi3Wt-1w07dQGltO6dd6SdBr3yN1ihtSxI6siOYGSmgOikuYFz0KwKBldsYrg/s640/2.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
步驟3 選擇檔案的存放路徑 ，點選Next&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVSx9lWYoOf0hn2CWLc6kdbfQ7mmOZnsqn0dK72EwEhHl-HTLILau7d_EfDmRJqqiPripp8u449nJJGWeQtn_WGPo6An49Tb196JouIEc1GqS51JMFtub33pDzkeQDnW3lhuQ4v6Cj0Q/s1600/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVSx9lWYoOf0hn2CWLc6kdbfQ7mmOZnsqn0dK72EwEhHl-HTLILau7d_EfDmRJqqiPripp8u449nJJGWeQtn_WGPo6An49Tb196JouIEc1GqS51JMFtub33pDzkeQDnW3lhuQ4v6Cj0Q/s640/3.png&quot; width=&quot;596&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
步驟4 : 因為這裡使用的是MS SQL 2008為範例資料庫，請注意，該套件預設的Driver class選單中，沒有正確的Driver可以選擇，所以自行輸入(com.microsoft.sqlserver.jdbc.SQLServerDriver)如下，不知道是不是因為MS SQL的支援很差，我沒試過其他資料庫，在這裡花了我不少的時間，抱怨一下，點選Next&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSKkKQQWd4N1he5o_Zr3G7Iob3KPC3mJ83MSy2QKaVcPOiY79x0dojC8Q_s0EbdezBBOXqkubL6bddRx0WGe59oLiUG4S9mBDGpZOEJPFVP37sblnvVJLDmN9v5kfTrwct3aQy17IF-g/s1600/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSKkKQQWd4N1he5o_Zr3G7Iob3KPC3mJ83MSy2QKaVcPOiY79x0dojC8Q_s0EbdezBBOXqkubL6bddRx0WGe59oLiUG4S9mBDGpZOEJPFVP37sblnvVJLDmN9v5kfTrwct3aQy17IF-g/s640/4.png&quot; width=&quot;596&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;步驟5:請注意Project選擇的是正確的Project Name，點選Finish&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhV9IvyWl9jOUzP5ro6nUMWYFlAzk4n7nu8Sz-YDn93mqcFLbN8DzbQ-fVZ2Jc0zr4a90QnLGpjE-I5-O_gomx7nHHU9cwXWkIPQOf3mHCW8cZ0Q-pR6SCqSZgPkzP2f43zmZAonUjH5w/s1600/6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhV9IvyWl9jOUzP5ro6nUMWYFlAzk4n7nu8Sz-YDn93mqcFLbN8DzbQ-fVZ2Jc0zr4a90QnLGpjE-I5-O_gomx7nHHU9cwXWkIPQOf3mHCW8cZ0Q-pR6SCqSZgPkzP2f43zmZAonUjH5w/s640/6.png&quot; width=&quot;596&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;步驟6:產生底下的 hibernate.cfg.xml檔&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAt1Okx5bSRdPRJsj_sZfTJv3WC43Fk9mGvgjUoLMDYR57sj8_LV9xKXV3zcvaet7adSOowVojMfJL2F0_YilbCpNUR0zHDKnqvZcnh-PljrdYrINbQo-w-bwm7FaRdSH07-5YuDh30w/s1600/5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;186&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAt1Okx5bSRdPRJsj_sZfTJv3WC43Fk9mGvgjUoLMDYR57sj8_LV9xKXV3zcvaet7adSOowVojMfJL2F0_YilbCpNUR0zHDKnqvZcnh-PljrdYrINbQo-w-bwm7FaRdSH07-5YuDh30w/s640/5.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp;步驟7:先執行步驟1，然後底下選擇Hibernate reverse Engineering file (reveng.xml)，點選Next&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaJwR5aWL4ycq6aJghHggl__OS6xivlEoeHcaGCPYHcshaZF2e3dHOE1uKQwNiZeT6HoLsoawyNusR5hhW667WQAIn8fgmggGvF6xOFb8kE4Hcj04BzUWEEFHDfD1LUUKCcK8cg5I55g/s1600/7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;604&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaJwR5aWL4ycq6aJghHggl__OS6xivlEoeHcaGCPYHcshaZF2e3dHOE1uKQwNiZeT6HoLsoawyNusR5hhW667WQAIn8fgmggGvF6xOFb8kE4Hcj04BzUWEEFHDfD1LUUKCcK8cg5I55g/s640/7.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;步驟8:選擇檔案的存放路徑，點選Next&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGjv7eufpwIAz1MLmVY1z0x4OEPgajZAfPUVAQ3VJiMhluM2ZwGZ6KRR2UNn0vhZ-S3xdCpeEKcU2VmFJtxO9QUZrYTsVHfkN1zQJYIXbnE1_qSSqzElZ-CYsQ-9XIt3G5jtQyNkUowA/s1600/8.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;612&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGjv7eufpwIAz1MLmVY1z0x4OEPgajZAfPUVAQ3VJiMhluM2ZwGZ6KRR2UNn0vhZ-S3xdCpeEKcU2VmFJtxO9QUZrYTsVHfkN1zQJYIXbnE1_qSSqzElZ-CYsQ-9XIt3G5jtQyNkUowA/s640/8.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;步驟9:於Console configureationi中，請確定選擇的是正確的Project Name，這裡會去吃剛剛所產生的hibernate.cfg.xml檔，然後點選Refresh按鈕，於Database Schema中，會出現於hibernate.cfg.xml中定義的資料庫的資訊&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeywpbvDK8YRzygt1zRLnkGHdTTZrjt3vPzg2D8H4wYpi0tp7-FOz6uHTpOMWnsv0V7EiBkLN6i7Qr_-sQCeGBzbfDW2zEDz8ZRddRevTfHdMAKd6BBjWV1E8N_rVfPcGGimgp65cPQg/s1600/9.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;486&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeywpbvDK8YRzygt1zRLnkGHdTTZrjt3vPzg2D8H4wYpi0tp7-FOz6uHTpOMWnsv0V7EiBkLN6i7Qr_-sQCeGBzbfDW2zEDz8ZRddRevTfHdMAKd6BBjWV1E8N_rVfPcGGimgp65cPQg/s640/9.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;步驟10:這裡只使用Employees資料表作示範，所以於Database Schema的樹狀節點中，選擇Employee節點，然後點選按鈕include，點選Finish&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh86XqBg3S77ccEouVQESF3RqK5xzDTB088-P-edux2YexQMR7vbHYGOl4uhsWLEsY6N3zH8wncTUYNSzfQjtCtg-7jS7PpJ63JuTk1ELKUWbYliqoes2dasxqPUiAIMnAhtVbsOL-y2A/s1600/10.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;488&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh86XqBg3S77ccEouVQESF3RqK5xzDTB088-P-edux2YexQMR7vbHYGOl4uhsWLEsY6N3zH8wncTUYNSzfQjtCtg-7jS7PpJ63JuTk1ELKUWbYliqoes2dasxqPUiAIMnAhtVbsOL-y2A/s640/10.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;步驟11:產生底下檔案&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh-FhM_HWTUIdFZUqPiDBeH7Vo1cefu__qDY8-Et1mnmimHqK9f6skJWDlHTwKXQx7KBgYE6asvqn4iSEi6GlzGSTsOayHDmAAdSQeGOQ88Lfr9kPdpwF3cgIbjiqxijlMMbxOYFdvRA/s1600/11.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;136&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh-FhM_HWTUIdFZUqPiDBeH7Vo1cefu__qDY8-Et1mnmimHqK9f6skJWDlHTwKXQx7KBgYE6asvqn4iSEi6GlzGSTsOayHDmAAdSQeGOQ88Lfr9kPdpwF3cgIbjiqxijlMMbxOYFdvRA/s640/11.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;步驟12: 使用Hibernate Code Generation Configurations工具，產生*.hbm.xml及DTO檔&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTlSp_PhRvUPwyqtb3Zv8Vq_dQ4i-Kzt3Au3lBF2TWvJc-XH4so6ULof2iI4aHVJSWSWTvzOkjbDBQTkHNI89u2OWESzodnIvrkGMR_615heCWMvVJ-oDmzy-RUWCndK29ANQzVj1lmg/s1600/12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;188&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTlSp_PhRvUPwyqtb3Zv8Vq_dQ4i-Kzt3Au3lBF2TWvJc-XH4so6ULof2iI4aHVJSWSWTvzOkjbDBQTkHNI89u2OWESzodnIvrkGMR_615heCWMvVJ-oDmzy-RUWCndK29ANQzVj1lmg/s640/12.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;步驟13:確認 Console configuration中選擇的Project Name，Output directory所指定的產生路徑，定義Package Name，最重要的是記得指定步驟7~11中所產生的reveng.xml檔&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtIrQqNbsVbs2fD26uel-O6864krZZLQgrQVJ3wTYdpOGFp7uLQkH8Lrw1QjaErkCwbX1Tn1b49Hyg0njaqlAuoFk-FJKZw_Cp_lEv-cqv2ydVkCW5cL8F82vi4sPMUMBuFjxEnLxm2A/s1600/13.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;512&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtIrQqNbsVbs2fD26uel-O6864krZZLQgrQVJ3wTYdpOGFp7uLQkH8Lrw1QjaErkCwbX1Tn1b49Hyg0njaqlAuoFk-FJKZw_Cp_lEv-cqv2ydVkCW5cL8F82vi4sPMUMBuFjxEnLxm2A/s640/13.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;步驟14:確認Exporters標籤設定如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAtNo4YYJnOYDzf29HilwK18AqwxGi5e00uZGVe_cWjt7EWZJDPrvx1MtgA1mjP1euG0J_bG_DDOWoIEcbHl3F_6JXj2jcd5y6GIfPG996ez-H_nPb_mF17IzYVnM22kUqhrBjDw6mJQ/s1600/14.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;512&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAtNo4YYJnOYDzf29HilwK18AqwxGi5e00uZGVe_cWjt7EWZJDPrvx1MtgA1mjP1euG0J_bG_DDOWoIEcbHl3F_6JXj2jcd5y6GIfPG996ez-H_nPb_mF17IzYVnM22kUqhrBjDw6mJQ/s640/14.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;步驟15:確定Common標籤設定如下，點選Run按鈕&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3xe_ooaSzSxmdVxbzJ3yLPCGzFIIralpkd5aqEyh11PcAYtZ3n00fm7l6joDVQ_HbK_mqguAAryVsSnHjEDzIWUdp1spH_PGrclRBq1q6wi-wfoxVsFP5M2WlrzX0hiblgb18cYqZBw/s1600/15.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;512&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3xe_ooaSzSxmdVxbzJ3yLPCGzFIIralpkd5aqEyh11PcAYtZ3n00fm7l6joDVQ_HbK_mqguAAryVsSnHjEDzIWUdp1spH_PGrclRBq1q6wi-wfoxVsFP5M2WlrzX0hiblgb18cYqZBw/s640/15.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
步驟16:產生檔案如圖所示(com.Northwnd.model.employees,com.Northwnd.model.EmployeesHome, Employees.hbm.xml)&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj31txf-gc2yEYu3wOOSRSnJTS2LZ1nXEoJnnhxTQRqnmewJqeun3YWz9O4WY3uoH_CI0e4HWJ_y6h8EuHnT9ALLsWeJOP-lgNDHxeNNkVN9WNj8IUI69hVFHSQRbxdRZqjIYl7WPnezw/s1600/16.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj31txf-gc2yEYu3wOOSRSnJTS2LZ1nXEoJnnhxTQRqnmewJqeun3YWz9O4WY3uoH_CI0e4HWJ_y6h8EuHnT9ALLsWeJOP-lgNDHxeNNkVN9WNj8IUI69hVFHSQRbxdRZqjIYl7WPnezw/s320/16.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;步驟17:於hibernate.cfg.xml中加入Employees.hbm.xml的mapping定義如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiggArZRr4qkqAR-wvyU00M69RWX767OxvKxEuT9xCv7x_hhCXnLCuMyFNluSWrfozUVQtvRXw4-cJTD0eZ7MyZcqEZiFLrKPCQgPDqPsoKr6cbTXwNecYu_8yJ2SKqSLzlGMtegdJ-Zw/s1600/17.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;252&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiggArZRr4qkqAR-wvyU00M69RWX767OxvKxEuT9xCv7x_hhCXnLCuMyFNluSWrfozUVQtvRXw4-cJTD0eZ7MyZcqEZiFLrKPCQgPDqPsoKr6cbTXwNecYu_8yJ2SKqSLzlGMtegdJ-Zw/s640/17.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
步驟18:新增一個com.xxx.Main.java檔，並撰寫程式碼如下
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package com.xxx;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.Northwnd.model.Employees;;



public class Main {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Configuration cfg = new Configuration();
  cfg.configure();
  SessionFactory factory = cfg.buildSessionFactory();
  Session session = factory.openSession();
  
  Transaction tx = null;
  
  try
  {
   
   tx = session.beginTransaction();
   
   //query
   Query query = session.createQuery(&quot;from com.Northwnd.model.Employees&quot;);
   List&lt;employees&gt; list = (List&lt;employees&gt;)query.list();
   System.out.println(&quot;Count:&quot;+list.size());
   for(int i = 0; i &amp;lt; list.size();i++)
   {
    System.out.println(i + &quot;:&quot; +list.get(i).getFirstName() + &quot; &quot; + list.get(i).getLastName());
   }
   
   tx.commit();
   
  }catch(HibernateException ex)
  {
   if(tx != null) tx.rollback();
   System.out.println(ex.getMessage());
  }
  finally
  {
   session.close();
   factory.close();
  }
 }

}

&lt;/employees&gt;&lt;/employees&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
執行結果:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbxdpZZ9fn-hNK8E3JMYTYv5lEbBehzN1_TFW4DN3c0xqYBlmk2R-d-tXGsjlAhPGftrnLoi5pTQ5CoSoByaHNma8GQm4LNd1006zSPCa1pT50aGeT3vaHyjQiRCYkT6DDRvHilEP88g/s1600/18.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbxdpZZ9fn-hNK8E3JMYTYv5lEbBehzN1_TFW4DN3c0xqYBlmk2R-d-tXGsjlAhPGftrnLoi5pTQ5CoSoByaHNma8GQm4LNd1006zSPCa1pT50aGeT3vaHyjQiRCYkT6DDRvHilEP88g/s320/18.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
結論:&lt;br /&gt;
其實上面有幾個步驟需要些為調整，我不知道是不是因為hibernate plugin跟MS SQL不合，但這裡就先不描述，我想懂hibernate原理的人，就算code gen產生的檔案錯誤，應該也是有能力修改。本文章是為了介紹如何使用工具，來快速產生hibernate的相關程式碼，加速系統開發的效率。但這裡也不免要小小抱怨一下，雖然說是免費的工具，這要做一樣的效果，使用.NET的IDE，卻可以在一分鐘內做出一樣的結果，使用Hibernate的Eclipse plugin，花了十幾分鐘，但這是第一次，不過我想之後就算再熟練，速度都不可能比VS快，希望Java的Tool能趕快加油。</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/222033146163926032/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/222033146163926032' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/222033146163926032'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/222033146163926032'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2010/06/hibernate-in-eclipse.html' title='Hibernate in Eclipse'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheItCz73MDiZgf8Ceo06-P3RSB06RSdl9aipAwihLZIfqVjbRNgPNbDwTcYlivN1kwL5GYYexcgZ33o1JV-yCF3GfdbG_DS8Oc_PKRO_ku90cl2OqyUEpQXJ1MgeK_0SLUgh4ooL4XIQ/s72-c/1.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-2072894652965875405</id><published>2010-04-22T08:31:00.000-07:00</published><updated>2010-04-22T08:31:22.541-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="生活"/><title type='text'>要換工作了，過陣子這裡可能會出現Java的文章了吧 ^^</title><content type='html'>最近在看的書籍&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Spring 2.0&lt;/li&gt;
&lt;li&gt;ExtJS&lt;/li&gt;
&lt;li&gt;Hibernate&lt;/li&gt;
&lt;li&gt;EJB&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
過陣子來寫個Hibernate IDE教學好了 ^^</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/2072894652965875405/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/2072894652965875405' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/2072894652965875405'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/2072894652965875405'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2010/04/java.html' title='要換工作了，過陣子這裡可能會出現Java的文章了吧 ^^'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-8103712266568797570</id><published>2010-02-09T06:51:00.000-08:00</published><updated>2010-06-08T09:07:38.174-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><title type='text'>Different between Event and Delegate</title><content type='html'>&lt;ul&gt;
&lt;li&gt;Event is Arraylist of delegates .&lt;/li&gt;
&lt;li&gt;Delegate ( as its English meaning ) : Secretary or someone who connect two    persons throuh him .&lt;/li&gt;
&lt;li&gt;Delegate can fire only one method&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/8103712266568797570/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/8103712266568797570' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/8103712266568797570'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/8103712266568797570'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2010/02/different-between-event-and-deletate.html' title='Different between Event and Delegate'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-3030918472029710562</id><published>2010-02-08T08:10:00.000-08:00</published><updated>2010-06-14T06:09:42.973-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>[T-SQL] INTERSECT 交集查詢</title><content type='html'>最近寫程式遇到的一個問題需要使用到SQL的交集查詢的功能，問題內容如下，我有一群各式各樣的&quot;藥&quot;的資料，而每一個藥是由&quot;不同成分&quot;所組成，我需要知道的是同時符合某些成分的要有哪些?&lt;br /&gt;
&lt;br /&gt;
這個問題敘述乍看之下很簡單(符合某些成分的藥)，但仔細想才覺得事情不是傻人的想的那麼簡單，問題的重點在於需要同時符合某幾個成分，這樣的藥有哪些，以下面的例子來看&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:sql&quot;&gt;SELECT [MedID]
      ,[MedName]
  FROM [Northwnd].[dbo].[MedTB]
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jEZta8oERh5FKx919FIasdZvXVQXRcOrA7O6rrJka6Vxnyn5DYpwBRp2vLsX1eWEWnhD1Zcd59yumCHQHqZzt27c5VY4hnSO9tmnc6zRuG8yVAVy1Ewf5YAp4Cwztmci-l-cP3cDpw/s1600-h/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;103&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jEZta8oERh5FKx919FIasdZvXVQXRcOrA7O6rrJka6Vxnyn5DYpwBRp2vLsX1eWEWnhD1Zcd59yumCHQHqZzt27c5VY4hnSO9tmnc6zRuG8yVAVy1Ewf5YAp4Cwztmci-l-cP3cDpw/s200/3.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;pre class=&quot;brush:sql&quot;&gt;SELECT [MedID]
      ,[SubMedName]
  FROM [Northwnd].[dbo].[SubMedTB]
&lt;/pre&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4Pyfyq5_kN_s5zZ9cPlyGLNkvDHbvvC9D-SOwUnD3W4z_oYLozf9yA2N6IL_MXz1l7OEYcSZJ9nP4_7DwZFss5AyQcb7NGGzHhJGYoTLShT7g5o3idr6Q-GcYbri3NDJe8Qw7pWiY-Q/s1600-h/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4Pyfyq5_kN_s5zZ9cPlyGLNkvDHbvvC9D-SOwUnD3W4z_oYLozf9yA2N6IL_MXz1l7OEYcSZJ9nP4_7DwZFss5AyQcb7NGGzHhJGYoTLShT7g5o3idr6Q-GcYbri3NDJe8Qw7pWiY-Q/s320/4.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;pre class=&quot;brush:sql&quot;&gt;SELECT     MedTB.MedName,SubMedTB.SubMedName
FROM         SubMedTB INNER JOIN
                      MedTB ON SubMedTB.MedID = MedTB.MedID
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdzXpYiUezp01eSIG3KG7iAmkDCn8Kc61zuM1EBv8mG3Xr2BAF35u3LQzciQRxzqQTvfdRIvsDYCCdQCTAT6gOxO3XOzGD53vHxLMQc6QpDXxiH_n8P_xkIWJuJOvVlK0ImgBk9r5CWg/s1600-h/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdzXpYiUezp01eSIG3KG7iAmkDCn8Kc61zuM1EBv8mG3Xr2BAF35u3LQzciQRxzqQTvfdRIvsDYCCdQCTAT6gOxO3XOzGD53vHxLMQc6QpDXxiH_n8P_xkIWJuJOvVlK0ImgBk9r5CWg/s320/1.png&quot; /&gt;&lt;/a&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
強力丸的成分有維他命A及維他命B，還魂丹有維他命A及維他命C，而十香軟筋散則是有維他命A、維他命B及維他命C，如果我想要找有維他命A的藥，則三種藥名都符合，但如果要同時有維他命A及維他命B的則有強力丸及十香軟筋散，同理有維他命A及維他命C的有環魂丹及十香軟筋散，但同時有維他命ABC的則只剩下十香軟筋散。這樣子的SQL查詢要怎麼下呢?我首先想到使用T-SQL中 INTERSECT的語法，假設我要找&lt;b&gt;維他命A&lt;/b&gt;及&lt;b&gt;維他命C&lt;/b&gt;的，則語法如下&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:sql&quot;&gt;SELECT     MedTB.MedName
FROM         SubMedTB INNER JOIN
                      MedTB ON SubMedTB.MedID = MedTB.MedID
WHERE SubMedTB.SubMedName = N&#39;維他命A&#39;

INTERSECT 

SELECT     MedTB.MedName
FROM         SubMedTB INNER JOIN
                      MedTB ON SubMedTB.MedID = MedTB.MedID
WHERE SubMedTB.SubMedName = N&#39;維他命B&#39;
&lt;/pre&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
查詢到的結果如下&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivwfJIHQpouEGPxrAiXEgngEl3rHq7fUfao-hu0kULDJB3TuDcishmvRQnaRRxUvT7TSgKvuTvPuvDL5DxBoJqsW8AX49oLKSKrWMJobmvI4KHYtQlGsIH7o7do4LfoSTqYOtfi5R4cA/s1600-h/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivwfJIHQpouEGPxrAiXEgngEl3rHq7fUfao-hu0kULDJB3TuDcishmvRQnaRRxUvT7TSgKvuTvPuvDL5DxBoJqsW8AX49oLKSKrWMJobmvI4KHYtQlGsIH7o7do4LfoSTqYOtfi5R4cA/s320/2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
相同的道理，需要幾種成分同時符合的話，就繼續以SELECT組合INTERSECT與法即可達成，但是這樣的撰法方法，卻對於前端的程式呼叫造成極大的困擾，如果我的程式是規定不能組合SQL字串的話，那便不能用這個方法來解決(當然你可以把它寫進StoredProcedure or SQL Function也可，但一樣都需要判斷進來的成分參數來組合SQL)，我比較prefer的是前端程式可以直接丟參數給既定的SQL即可，這樣才是我心目中優良的程式撰寫方式，最後請教 pinnywu大神後，給出這樣的SQL&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:sql&quot;&gt;SELECT MedName
FROM
(
SELECT     MedTB.MedName,COUNT(1) as cnt
FROM         SubMedTB INNER JOIN
                      MedTB ON SubMedTB.MedID = MedTB.MedID
WHERE SubMedTB.SubMedName IN( N&#39;維他命B&#39; , N&#39;維他命A&#39;) --參數內容 這裡可以直接丟參數
GROUP BY MedTB.MedName
) AS TA
WHERE cnt = 2 -- IN中參數數量 這裡可以直接丟參數
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
這段SQL非常好玩，有興趣的可以先從sub select開始解讀，但我這裡要強調的是，這樣子的SQL才能避掉組SQL的方式，我只需要於前端程式中，於我註解的地方改成丟參數的方式，及可以把對應的參數傳入，例如如果我要找同時符合維他命ABC的，則會在IN的參數地方丟入維他命ABC的查詢結果，然後於cnt的地方丟恕我總共的參數數目是3，這個時候就可以查詢到十香軟筋散了，不知道各位看官懂不懂我再說什麼呢?&lt;br /&gt;
&lt;br /&gt;
有興趣的大家可以討論一下。&lt;br /&gt;
&lt;br /&gt;
註:其實如果都要組SQL了，那除了INTERSECT這種罕用關鍵字外，還有其他的方式可以解決這個問題。下次有機會再跟大家分享啦&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/3030918472029710562/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/3030918472029710562' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/3030918472029710562'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/3030918472029710562'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2010/02/t-sql-intersect.html' title='[T-SQL] INTERSECT 交集查詢'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9jEZta8oERh5FKx919FIasdZvXVQXRcOrA7O6rrJka6Vxnyn5DYpwBRp2vLsX1eWEWnhD1Zcd59yumCHQHqZzt27c5VY4hnSO9tmnc6zRuG8yVAVy1Ewf5YAp4Cwztmci-l-cP3cDpw/s72-c/3.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-89647373557220735</id><published>2010-01-28T07:23:00.000-08:00</published><updated>2010-01-28T07:34:23.211-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="deploy"/><category scheme="http://www.blogger.com/atom/ns#" term="FileManager"/><title type='text'>用 FileManager 當asp.net部署管理系統 (Part 2)</title><content type='html'>繼上&lt;a href=&quot;http://pinnynet.blogspot.com/2010/01/filemanager-aspnet-part-1.html&quot;&gt;一篇文章&lt;/a&gt;提到如何使用FileManager來部署新程式，其實步驟非常簡單，只需要把要部署的程式上傳到正確的路徑就可以了，底下示範使用一個名為 HelloToday.aspx的程式來部署，該程式aspx內容如下(只有一個Label元件)&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmAieYxbEhuH4p3C03RasE5hhfljXCX0BmOKfmqF-sKXPCTWA3XPdthVyR66g3HewG9ez1NuaqFbStqBHqB1qwI8S9erQ6hcwDOWchZfgGgAeYi9_BWgOzvhxhVxXU-_HiUGFduJxpjg/s1600-h/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;76&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmAieYxbEhuH4p3C03RasE5hhfljXCX0BmOKfmqF-sKXPCTWA3XPdthVyR66g3HewG9ez1NuaqFbStqBHqB1qwI8S9erQ6hcwDOWchZfgGgAeYi9_BWgOzvhxhVxXU-_HiUGFduJxpjg/s640/4.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;後至程式碼HelloToday.aspx.cs如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJfhV2rAmkV2fsP9h5YMaOqHYLEsxI7WCvcIVdss0vBb7YbG0CJlKR-aXu55EImb6ZLu9GZBONuZnIEr_sUJ7dB99uvbvt1UURLrPZik_Tcc-m8fvMwTOKKGCoMpHbMZtLhlFTyE-Xtg/s1600-h/5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;146&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJfhV2rAmkV2fsP9h5YMaOqHYLEsxI7WCvcIVdss0vBb7YbG0CJlKR-aXu55EImb6ZLu9GZBONuZnIEr_sUJ7dB99uvbvt1UURLrPZik_Tcc-m8fvMwTOKKGCoMpHbMZtLhlFTyE-Xtg/s640/5.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
該程式就是簡單的秀出 Hello 加上今天的日期而已，我們準備好這兩個檔案，然後開啟已經部署在IIS上面的FileManager，畫面如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8TsO7EaQN7cJd0h-DIa_f-iw62QyVhgbmXeH-tCnbB6QJurz7JM0OoQGVbIO2B5FK7QjUhFDZ0IQ6EMKmcsxmbNru02VczoQOnHF2TYpCUtBmeUEWUcHaBrcEZ0cblg-jSub7UWZtBA/s1600-h/6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;432&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8TsO7EaQN7cJd0h-DIa_f-iw62QyVhgbmXeH-tCnbB6QJurz7JM0OoQGVbIO2B5FK7QjUhFDZ0IQ6EMKmcsxmbNru02VczoQOnHF2TYpCUtBmeUEWUcHaBrcEZ0cblg-jSub7UWZtBA/s640/6.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
我們使用檔案上傳的功能，將HelloToday.aspx及HelloToday.aspx.cs上傳到此目錄下，上傳後檢視該目錄如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz0Bs_fbM1gCL_-Tl2wggVsP4tT1R0OdVzMrr-NydYDAJk1rSjfrFmi0biDtDYV9go8c0T-6CnG6inDIr24O6Xz5CBefO0AhpwS9IGCVQAsBIMOqRandheIaNPxZgK_RPKQkJ0_rhXaQ/s1600-h/7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;50&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz0Bs_fbM1gCL_-Tl2wggVsP4tT1R0OdVzMrr-NydYDAJk1rSjfrFmi0biDtDYV9go8c0T-6CnG6inDIr24O6Xz5CBefO0AhpwS9IGCVQAsBIMOqRandheIaNPxZgK_RPKQkJ0_rhXaQ/s640/7.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
確認兩個檔案已經成功上傳後，於網址中輸入 http://localhost:1038/CodePlexFM/HelloToday.aspx 即可看到結果如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3mRaWEW6dWAY0I3NLXCZ6Qxpdbl37FHQDk4i61suisUm-0Wh5gIh892Lre-QuMcA_gaigap-nMETUTx1BOxfhTGomKMg8RDNnYr1s1K-l7u9BghRfRYZaZHcvQWkaSOrIzJw_P6lFfQ/s1600-h/8.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;136&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3mRaWEW6dWAY0I3NLXCZ6Qxpdbl37FHQDk4i61suisUm-0Wh5gIh892Lre-QuMcA_gaigap-nMETUTx1BOxfhTGomKMg8RDNnYr1s1K-l7u9BghRfRYZaZHcvQWkaSOrIzJw_P6lFfQ/s640/8.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
透過這樣的方式，我們可以很簡單的部屬程式。&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;結論&lt;/b&gt;&lt;br /&gt;
雖然透過這樣的方式可以很簡單的佈署程式，但由於部署的FileManager本身並沒有受控管，也就是什麼人都可以透過該網頁影響到在Server上的程式，對駭客來說這根本是門戶大開，下篇文章中，將介紹如何透過簡單的驗證授權機制，來提高部署過程的安全性。&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/89647373557220735/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/89647373557220735' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/89647373557220735'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/89647373557220735'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2010/01/filemanager-aspnet-part-2.html' title='用 FileManager 當asp.net部署管理系統 (Part 2)'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmAieYxbEhuH4p3C03RasE5hhfljXCX0BmOKfmqF-sKXPCTWA3XPdthVyR66g3HewG9ez1NuaqFbStqBHqB1qwI8S9erQ6hcwDOWchZfgGgAeYi9_BWgOzvhxhVxXU-_HiUGFduJxpjg/s72-c/4.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-5073010959877122979</id><published>2010-01-08T05:51:00.000-08:00</published><updated>2010-01-09T08:39:26.621-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="deploy"/><category scheme="http://www.blogger.com/atom/ns#" term="FileManager"/><title type='text'>用 FileManager 當asp.net部署管理系統 (Part 1)</title><content type='html'>在上一篇文章(&lt;a href=&quot;http://pinnynet.blogspot.com/2009/12/codeplex-file-manager.html&quot;&gt;FileManager From CodePlex&lt;/a&gt;)中提到可以改善FileManager的功能，使其可以用來部署asp.net應用程式。&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;一般來說我們的應用程式開發完之後會部署在客戶端的server，而且通常不太可能可以直接透過遠端桌面的方式來進行對server的操作，因為安全性的原因，該server如果是單純只當web server的話，對外則只會開通port 80，以對http通訊使用，而且以開發廠商的角度而言，客戶端的server通常會由客戶端自行管理，環境可能都在防火牆中，更別想說透過Visual Studio提供的其它部署功能(Ftp, Http)，而開發廠商想要部署新程式的話，可能就需要進機房，或者自動化一點的話，把程式作成一個安裝檔，交由客戶端的管理人員進行安裝或更新。但是我們有時候只是想要修改一個小東西，或者時間很緊急想要馬上修改客戶端程式的話，這樣就很不方便。&lt;br /&gt;
&lt;br /&gt;
想要部署當然首先就需要有檔案上傳的功能，透過FileManager的原有功能去擴充，我們可以指定要上傳的路徑，經由這樣的功能，我們就可以把要上版的新程式部署到Server，當然也可以運用FileManager原有的功能，移動或刪除檔案，主要的步驟如下&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;透過修改FileManager程式，開放ActualPath屬性&lt;/li&gt;
&lt;li&gt;新增aspx頁面，使其成為部屬管理系統之頁面&lt;/li&gt;
&lt;li&gt;於新增之頁面中嵌入FileManager之UserControl&lt;/li&gt;
&lt;li&gt;於新增頁面中新增FileUpload控制項與一上傳之按鈕&lt;/li&gt;
&lt;li&gt;撰寫檔案上傳程式碼&lt;br /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b&gt;1.透過修改FileManager程式，開放ActualPath屬性&lt;/b&gt; &lt;br /&gt;
要將檔案上傳到指定的路徑，首先我們需要開啟FileManager 中ActualPath的屬性。首先打開FileManager.ascx.cs檔，該檔案於套件中路徑如下圖&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD974kF0kLAY6gLImcqC5mZzsiHwZ_Yx4QYTYPsX6h1aLElNaiVsLveKxufLT_gyEA7qEequZD4hYA0xuaV0Mh06D3c0V-zYuFQjAh2CVG1Z5QKEbURgOXAGVwW9vbBaIV8ZFCIxR7ag/s1600-h/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD974kF0kLAY6gLImcqC5mZzsiHwZ_Yx4QYTYPsX6h1aLElNaiVsLveKxufLT_gyEA7qEequZD4hYA0xuaV0Mh06D3c0V-zYuFQjAh2CVG1Z5QKEbURgOXAGVwW9vbBaIV8ZFCIxR7ag/s640/1.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
於其中新增一個屬性如下&lt;br /&gt;
&lt;textarea class=&quot;CSharp&quot; cols=&quot;70&quot; name=&quot;code&quot; rows=&quot;5&quot;&gt;public string ActualPath
        {
            get
            {
                return lblCurrentPath.Text;
            }
        }
&lt;/textarea&gt;
&lt;br /&gt;
透過該屬性，則可以將原FileManager中目前所瀏覽之路徑開放出來&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2.新增aspx頁面，使其成為部屬管理系統之頁面&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;3.於新增之頁面中嵌入FileManager之UserControl&lt;/b&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;4.於新增頁面中新增FileUpload控制項與一上傳之按鈕&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWi5QY2HMZzPaYVCHcSNxdgw1RHQ-LXXE1vdWas8G9l4GyyGKRJav2zQP_SmRJGErQ_mnrSQ6pG0AY6GIT0G3NE6Ih1d6YXVvXzu8fIKeJ1niDBSMfKSWqCsV8NzuxjnnqBTeddx-Fbw/s1600-h/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWi5QY2HMZzPaYVCHcSNxdgw1RHQ-LXXE1vdWas8G9l4GyyGKRJav2zQP_SmRJGErQ_mnrSQ6pG0AY6GIT0G3NE6Ih1d6YXVvXzu8fIKeJ1niDBSMfKSWqCsV8NzuxjnnqBTeddx-Fbw/s640/2.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;b&gt; &lt;/b&gt;&lt;br /&gt;
我們先瀏覽該畫面如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyHHAlbmkfJxLipgrBrI0eE-VGE3BN0qhEHYvBtVbSiMFyo6mk9FtcNcAwb1QI9xW3hS7eXXQJlmR2QANUuq4_lCGQU0GZwYjZxC-DopYUosu6f9U4ftpKCfJg6yZQAXSsK5EbFEaw8g/s1600-h/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyHHAlbmkfJxLipgrBrI0eE-VGE3BN0qhEHYvBtVbSiMFyo6mk9FtcNcAwb1QI9xW3hS7eXXQJlmR2QANUuq4_lCGQU0GZwYjZxC-DopYUosu6f9U4ftpKCfJg6yZQAXSsK5EbFEaw8g/s640/3.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;5.撰寫檔案上傳程式碼&lt;/b&gt;&lt;br /&gt;
&lt;textarea class=&quot;CSharp&quot; cols=&quot;70&quot; name=&quot;code&quot; rows=&quot;5&quot;&gt;protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.FileBytes.Length &amp;gt; 0)
        {
            //Label1.Text = FileManager1.ActualPath;
            
            FileUpload1.SaveAs(FileManager1.ActualPath + &quot;\\&quot;+FileUpload1.FileName);
        }
    }
&lt;/textarea&gt;
&lt;br /&gt;
&lt;br /&gt;
上面的程式中，主要透過FileUpload的SaveAs功能，並運用FileManager中我們剛開啟的ActualPath屬性指定上傳檔案存放的路徑。基本上這樣就就算完成了檔案部署的功能。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
下一篇文章中將在介紹，把我們擴充完的FileManager部署到Server之後，該如何部署新的程式。&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/5073010959877122979/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/5073010959877122979' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/5073010959877122979'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/5073010959877122979'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2010/01/filemanager-aspnet-part-1.html' title='用 FileManager 當asp.net部署管理系統 (Part 1)'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD974kF0kLAY6gLImcqC5mZzsiHwZ_Yx4QYTYPsX6h1aLElNaiVsLveKxufLT_gyEA7qEequZD4hYA0xuaV0Mh06D3c0V-zYuFQjAh2CVG1Z5QKEbURgOXAGVwW9vbBaIV8ZFCIxR7ag/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-3360554766789528754</id><published>2009-12-27T06:23:00.000-08:00</published><updated>2009-12-30T08:13:44.854-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><category scheme="http://www.blogger.com/atom/ns#" term="CodePlex"/><title type='text'>FileManager From CodePlex</title><content type='html'>FileManager是CodePlex下的一個套件，主要使用來管理web上面的檔案，雖然說是Manager，但是預設來說功能並不是太強大，目前我所知道的功能如下&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;瀏覽該WebAP(網站應用程式)下的所有檔案及目錄&lt;/li&gt;
&lt;li&gt;複製檔案&lt;/li&gt;
&lt;li&gt;刪除檔案&lt;/li&gt;
&lt;li&gt;移動檔案&lt;/li&gt;
&lt;li&gt;下載檔案&lt;/li&gt;
&lt;li&gt;更改檔案名稱&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
該套件裝好後，預設的畫面如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgE0RGtDdEJmFEXd2v91C1XdKtUhtME9w_ePSbGYk5_zgQSuPKUF-kc0X5Tq34Lpo9yxLE1VBfde1hQWGHE9KotcghBx8N_1BCWQyo7GC8qdThLCaAcF4vh5aqKNgRM4Jo2LrY3oSFaYw/s1600-h/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgE0RGtDdEJmFEXd2v91C1XdKtUhtME9w_ePSbGYk5_zgQSuPKUF-kc0X5Tq34Lpo9yxLE1VBfde1hQWGHE9KotcghBx8N_1BCWQyo7GC8qdThLCaAcF4vh5aqKNgRM4Jo2LrY3oSFaYw/s640/1.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
你可以使用這個套件，來快速架設一個網站應用程式的檔案管理功能(PS:瀏覽部份，基本上只要IIS設定&quot;瀏覽目錄&quot;，也可以瀏覽檔案架構)。&lt;br /&gt;
&lt;br /&gt;
這個套件讓我想到兩種應用，第一是&lt;b&gt;ASP.NET的部屬管理系統&lt;/b&gt;，第二是&lt;b&gt;網路硬碟&lt;/b&gt;。不過依照這個套件的基本功能尚不足以達到我的需求。這兩種應用至少都該有檔案上傳的機制，不過這裡我先介紹該怎麼把這個套件安裝起來。之後如果還有機會再來介紹如何修改這個套件來達到上面兩種系統的要求。&lt;br /&gt;
&lt;br /&gt;
安裝這個套件非常的簡單，首先你只需要到&amp;nbsp;&lt;a href=&quot;http://www.codeplex.com/FileManager&quot;&gt;http://www.codeplex.com/filemanager&lt;/a&gt; 下載這個&lt;a href=&quot;http://filemanager.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=4507&quot;&gt;套件&lt;/a&gt; ，目前最新的版本編號是 v0.0.1.1，下載之後是一個 FileManager v0.0.1.1.zip檔，將此壓縮檔解開後，檔案目錄如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKzUys26ZmhMLVNpxpuwmvte-_KKWDhiiJxQAk2YHX9revvnFcsF2JETlC9n9tSFWx76CgEIjkJEDkHCuiz3GdwOEi7tIsdCCg7ZTyGlqYcB0OuNamsXath4_EQQ8TJGw0O5-wQpFV5g/s1600-h/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKzUys26ZmhMLVNpxpuwmvte-_KKWDhiiJxQAk2YHX9revvnFcsF2JETlC9n9tSFWx76CgEIjkJEDkHCuiz3GdwOEi7tIsdCCg7ZTyGlqYcB0OuNamsXath4_EQQ8TJGw0O5-wQpFV5g/s640/2.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
由這個檔案可以看出，這已經是一個完整的ASP.NET網站，所以你可以直接使用Visual Studio開啟這個網站執行，或者直接把這個目錄丟到 wwwroot下，在使用IIS將其建立應用程式即可&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcXhTGecgKbGT0JAyU9TBfMJwEkkVDHaiTSy4-LSU88t6dUoYoYKUQ5BUb-s_jQE8p9FMRO8n6-397XRb6GHzgHU1hKXC3akpbtVqDxJJBOPKRIK0a4fYmNDYuwnKb2S5ABTNDShFZdQ/s1600-h/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcXhTGecgKbGT0JAyU9TBfMJwEkkVDHaiTSy4-LSU88t6dUoYoYKUQ5BUb-s_jQE8p9FMRO8n6-397XRb6GHzgHU1hKXC3akpbtVqDxJJBOPKRIK0a4fYmNDYuwnKb2S5ABTNDShFZdQ/s640/3.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
上圖示我把資料夾名稱改為CodePlexFM，然後建立應用程式之後的結果(注意:如果這個OS有安裝.net framework 1.x的話請注意上圖ASP.NET標籤的framework版本設定是否為2.0.x版)，設定完畢之後，我們開啟瀏覽器，輸入網址如下 http://localhost/CodePlex/Default.aspx，會看到畫面如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8NTmTDnh0DzYjLfDpMjcEkY5g56DEXaxhNXFdw6ZJbn8FOEfwNdD18Dxvhan-6b-U2o4mJgXzxTWE4MGIgxKmIWs3P5g44npIMSLZk2D4EOUyQAdZTsGZwS-vUpvIk9oowwsilqTDPw/s1600-h/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8NTmTDnh0DzYjLfDpMjcEkY5g56DEXaxhNXFdw6ZJbn8FOEfwNdD18Dxvhan-6b-U2o4mJgXzxTWE4MGIgxKmIWs3P5g44npIMSLZk2D4EOUyQAdZTsGZwS-vUpvIk9oowwsilqTDPw/s640/4.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
直接點選畫面中之聯結，即可進入管理畫面&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2OZKPj5WzAx58bzNv2oIpfwNjkPc0c08Ssh0PwOcfiG1mARMHZYuF9dx0ssP9L_j05Er0MqfUFgs4jEEe-CsjtC9rpFtaXO1rvLARcmQIDiA7G0sfXbFPW18SrtuMxfTj0yh7G6YI9Q/s1600-h/5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2OZKPj5WzAx58bzNv2oIpfwNjkPc0c08Ssh0PwOcfiG1mARMHZYuF9dx0ssP9L_j05Er0MqfUFgs4jEEe-CsjtC9rpFtaXO1rvLARcmQIDiA7G0sfXbFPW18SrtuMxfTj0yh7G6YI9Q/s640/5.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
是不是很簡單呢 ^^&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/3360554766789528754/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/3360554766789528754' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/3360554766789528754'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/3360554766789528754'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2009/12/codeplex-file-manager.html' title='FileManager From CodePlex'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgE0RGtDdEJmFEXd2v91C1XdKtUhtME9w_ePSbGYk5_zgQSuPKUF-kc0X5Tq34Lpo9yxLE1VBfde1hQWGHE9KotcghBx8N_1BCWQyo7GC8qdThLCaAcF4vh5aqKNgRM4Jo2LrY3oSFaYw/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-1544622952604879955</id><published>2009-12-23T19:07:00.000-08:00</published><updated>2009-12-23T19:14:10.854-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><title type='text'>LINQ 學習資源整理</title><content type='html'>&lt;br /&gt;
ScottGu&#39;s Blog: &lt;br /&gt;
LINQ to SQL Basic&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx&quot;&gt;Using LINQ to SQL (Part 1) &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2007/05/29/linq-to-sql-part-2-defining-our-data-model-classes.aspx&quot;&gt;LINQ to SQL (Part 2 - Defining our Data Model Classes) &lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2007/06/29/linq-to-sql-part-3-querying-our-database.aspx&quot;&gt;LINQ to SQL (Part 3 - Querying our Database) &lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2007/07/11/linq-to-sql-part-4-updating-our-database.aspx&quot;&gt;LINQ to SQL (Part 4 - Updating our Database) &lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx&quot;&gt;LINQ to SQL (Part 5 - Binding UI using the ASP:LinqDataSource Control) &lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx&quot;&gt;LINQ to SQL (Part 6 - Retrieving Data Using Stored Procedures) &lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2007/08/23/linq-to-sql-part-7-updating-our-database-using-stored-procedures.aspx&quot;&gt;LINQ to SQL (Part 7 - Updating our Database using Stored Procedures) &lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2007/08/27/linq-to-sql-part-8-executing-custom-sql-expressions.aspx&quot;&gt;LINQ to SQL (Part 8 - Executing Custom SQL Expressions) &lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx&quot;&gt;LINQ to SQL (Part 9 - Using a Custom LINQ Expression with the &lt;asp:linqdatasource&gt; control) &lt;/asp:linqdatasource&gt;&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/1544622952604879955/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/1544622952604879955' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/1544622952604879955'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/1544622952604879955'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2009/12/linq.html' title='LINQ 學習資源整理'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-3187989537692018358</id><published>2009-12-22T08:35:00.000-08:00</published><updated>2010-06-14T06:13:37.114-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><title type='text'>LINQ Deferred VS Immediate Data Loading</title><content type='html'>使用LINQ To SQL的時候，預設的行為是Deferred Loading，意思是說當你下了一段LINQ時，程式並不會馬上對後端的資料庫進行讀取的行為，而是等到你對LINQ的結果集進行存取的時候才會對後端資料庫進行存取。範例如下&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:csharp&quot;&gt;
       var q = from c in context.Employees
                select new { c.FirstName, c.EmployeeID, c.City, c.Country};

        
        GridView1.DataSource = q;
        GridView1.DataBind();  //執行DataBind的時候才會真的對後端資料庫進行讀取的動作
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;這樣子是為了避免不必要的資料庫Loading，但某些情況之下，你卻必須要馬上獲得LINQ To SQL的結果，這個時候最簡單的方法就是使用ToList()的功能，因為這個方法就是把結果及轉換為一個List的集合物件，所以勢必會在使用此方法的時候就馬上對資料庫進行讀取，這就是Immediate data Lodaing的功能，目前我所知道LINQ To SQL好像也只有這樣的方式是比較方便的，也比較彈性。&lt;br /&gt;
&lt;br /&gt;
今天遇到一個問題剛好需要使用這樣的功能，問題如下&lt;br /&gt;
我的資料庫資料如下(註:使用上面的程式碼結果)&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh90o0OPFI_tSwEXSJvOQNVAZdmD0vc8qOFiuH-dkbfGqQNekDv2tKOs6BQ2w0vLq5AZKgbWXMNqBg18iGvFdaL6jojwjjRPxqawoni9PcKk_yBEaHATovOwVhnk-fuplsACR1EXeTRjw/s1600-h/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh90o0OPFI_tSwEXSJvOQNVAZdmD0vc8qOFiuH-dkbfGqQNekDv2tKOs6BQ2w0vLq5AZKgbWXMNqBg18iGvFdaL6jojwjjRPxqawoni9PcKk_yBEaHATovOwVhnk-fuplsACR1EXeTRjw/s640/1.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
該資料中最後一筆資料是我所新增，而Conutry其實是null，不過我要新增一個欄位叫做Code，這個欄位是經過一個額外定義的Method經過運算而成，該方法之程式碼如下&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:csharp&quot;&gt;
public class Class1
{
    public static string GetCheckCode(string str)
    {
        if (str == null) return &quot;null&quot;;

        if (str.Length == 2)
            return &quot;A&quot;;
        else
            return &quot;B&quot;;
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
而利用LINQ To SQL的功能再透過底下程式碼我可以得到Code的欄位&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:csharp&quot;&gt; 
var q = from c in context.Employees
                select new { c.FirstName, c.EmployeeID, c.City, c.Country, Code = Class1.GetCheckCode(c.Country) };
GridView1.DataSource = q;
        GridView1.DataBind();
&lt;/pre&gt;

 &lt;br /&gt;
&lt;br /&gt;
可獲得結果如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5KagsU1TbFVQw_wBLDPPhX_lmBVFBuQWUZqU4UbslE8KOAwOP6aEqu5upGjBkZB0s2XdsKz528ejreYi6yhu6hmL4-0MB6q5OHZmv8PXvv9fQfdazmwitLQnWg8wMx_pNXqGhBXV_9Q/s1600-h/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5KagsU1TbFVQw_wBLDPPhX_lmBVFBuQWUZqU4UbslE8KOAwOP6aEqu5upGjBkZB0s2XdsKz528ejreYi6yhu6hmL4-0MB6q5OHZmv8PXvv9fQfdazmwitLQnWg8wMx_pNXqGhBXV_9Q/s640/2.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
而現在我想利用這個多餘的欄位來進行過濾，例如，我想取得Code == &quot;A&quot;的結果集，直覺上你會很自然的使用底下的程式碼&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:csharp&quot;&gt;  
var q = from c in context.Employees
                where Class1.GetCheckCode(c.Country) == &quot;A&quot;
                select new { c.FirstName, c.EmployeeID, c.City, c.Country, Code = Class1.GetCheckCode(c.Country) };

 GridView1.DataSource = q;
        GridView1.DataBind();    
&lt;/pre&gt;

 &lt;br /&gt;
但是這樣卻會發生Exception，錯誤訊息如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsoMu7jpQU-z-CqStdeJfcE6_nPZ5iRQr4O7qCQEXfonSrQR_YBMTLr0K383BrcPrOhNARkBVoadG7J33tGD5ybhHwJl8nRDiey314xokv9JGh2sVmmhjemCHzHD6sQ_pqP485qGHkfA/s1600-h/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsoMu7jpQU-z-CqStdeJfcE6_nPZ5iRQr4O7qCQEXfonSrQR_YBMTLr0K383BrcPrOhNARkBVoadG7J33tGD5ybhHwJl8nRDiey314xokv9JGh2sVmmhjemCHzHD6sQ_pqP485qGHkfA/s640/3.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
這是因為LINQ To SQL並沒有支援使用客製化方法來進行條件的過濾(有興趣的可以參考LINQ To SQL的相關轉譯介紹)，此時解決的方式就把腦筋動到LINQ To Object了，因為針對一個記憶體中結果集去執行這樣的過濾條件是很稀鬆平常的事情，所以我們再把程式修改如下&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:csharp&quot;&gt;  
//先進行LINQ To SQL查詢
var q = from c in context.Employees
                select new { c.FirstName, c.EmployeeID, c.City, c.Country, Code = Class1.GetCheckCode(c.Country) };

//利用ToList()方法，進行Immediate Data Loading
var q2 = from c in q.ToList()
                 where c.Code == &quot;A&quot;
                 select c;

 GridView1.DataSource = q2;
        GridView1.DataBind();    
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
其結果如下&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQdHM2pmH1uEW_2X6iByEAsRRLH40G89A_-EeApcjwkikEua8BqH4TEU7mtX6eTsb2ijld3Y9iwouRrRosrbMyg_ZeKICqN9P8ZHHfAx-cxL_8_1lM5rH73XPLxNZynzalengWtEoIzQ/s1600-h/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQdHM2pmH1uEW_2X6iByEAsRRLH40G89A_-EeApcjwkikEua8BqH4TEU7mtX6eTsb2ijld3Y9iwouRrRosrbMyg_ZeKICqN9P8ZHHfAx-cxL_8_1lM5rH73XPLxNZynzalengWtEoIzQ/s640/4.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
這就是我們要的結果集。&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;結論:&lt;/b&gt;&lt;br /&gt;
LINQ真的是一個必學的技能，原本我以為只是微軟從Java那抄Hibernet的一個solution，不過我大大的錯了，正確的來說Hibernet只不過符合LINQ一部分的功能而已，雖然這這個範例中使用的是LINQ To SQL，也就是MS SQL only，不過想要使用其他資料庫的話，其實只要去找相關的Provider還是可以使用(當然，這樣的方便性就降低了，不像Hibernet以一擋百)，但微軟再後面其實還有一個更強的殺手級應用Entity Framework，這就可以解決掉不同資料庫的問題，而且功能更強大。但是這還只是針對資料庫而言，以LINQ的技術來說，主要需要知道的技能應該如下&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;LINQ To SQL&lt;/li&gt;
&lt;li&gt;LINQ To Object&lt;/li&gt;
&lt;li&gt;LINQ To XML&lt;/li&gt;
&lt;/ol&gt;
其他LINQ的相關應用，都是架構再這三個上面，以本文章的例子就需要知道LINQ To SQL以及LINQ To Object方能解決，這在Hibernet上面好像沒辦法如此方便，總之LINQ贏了。 &lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/3187989537692018358/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/3187989537692018358' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/3187989537692018358'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/3187989537692018358'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2009/12/linq-deferred-vs-immediate-data-loading.html' title='LINQ Deferred VS Immediate Data Loading'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh90o0OPFI_tSwEXSJvOQNVAZdmD0vc8qOFiuH-dkbfGqQNekDv2tKOs6BQ2w0vLq5AZKgbWXMNqBg18iGvFdaL6jojwjjRPxqawoni9PcKk_yBEaHATovOwVhnk-fuplsACR1EXeTRjw/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-7916124800876896233</id><published>2009-12-12T19:31:00.000-08:00</published><updated>2009-12-12T19:33:26.933-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Project"/><title type='text'>ASP.NET WebSite VS  Web Project (WebApplication)</title><content type='html'>昨天看一篇文章的時候，作者使用WebApplication，我突然有點confuse，一般來說使用Visual Studio開發Web通常選的是建立WebSite，雖然我知道有WebApplication的選項可以選擇，不過卻一直沒去理會它，這兩個的差異到底在哪呢?&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
根據某原文書的說法是&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Project-based development :&lt;/b&gt; 當你選擇使用C#為開發語言的時候，Visual Studio會產生一個 .csproj檔，還有一些debug的設定檔，當你執行這個Project的時候，Visual Studio會先編譯這整個專案為一單一個assembly(即dll)。這個行為模式看起來跟VS 2003是一模一樣的&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Projectless development :&lt;/b&gt;使用這個模式建立WebSite，只會有網站的所需要的檔案，並不會有專案設定檔(.csproj 和一些debug設定檔)，而且當你第一次執行(指的是第一次存取網頁)的時候，ASP.NET才會編譯其內容(所以在所謂第一次執行的時候會比較慢，因為這個時候才編譯)。&lt;br /&gt;
&lt;br /&gt;
基本上只要把VS2003的觀念套到Web Project上就可以完全理解了，至於使用Web Site的方式建立網站，雖然預設上不會預先編譯(precompile)，但還是有很多解決方式可以預先編譯，甚至可以更彈性一點，所以我想微軟預設上還是希望開發人員使用WebSite的方式來建立網站就好了，WebProject的方式，是在某些開發人員強力的反應下微軟才又於Visual Studio 2008又加回來的方式。&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;結論:&lt;/b&gt; &lt;br /&gt;
雖然使用Web SIte比較方便，但是微軟在這方面的配套措施上卻沒有做的很完整，導致於在專案部署的時候預設上沒有使用Web Project方便，微軟為了解決這個問題，在Visual Studio 2005的時候就出了一個Plugin(有興趣的可以參考這篇&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx&quot;&gt;VS 2005 Web Deployment Projects&amp;nbsp; &lt;/a&gt;當然也有 &lt;a href=&quot;http://blogs.msdn.com/webdevtools/archive/2008/01/25/announcing-rtw-of-visual-studio-2008-web-deployment-projects-wdp.aspx&quot;&gt;Visual Studio 2008 Web Deployment Projects &lt;/a&gt;)，不過我比較好奇的是，在VS 2005的時候以plugin的方式加入，但到了VS 2008卻不是把它當成預設功能(這點蠻失望的，不知道VS 2010會不會有)。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/7916124800876896233/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/7916124800876896233' title='9 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/7916124800876896233'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/7916124800876896233'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2009/12/aspnet-website-vs-web-project.html' title='ASP.NET WebSite VS  Web Project (WebApplication)'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8827818669723021586.post-6392011780624191178</id><published>2009-12-11T08:33:00.000-08:00</published><updated>2009-12-11T08:53:51.819-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="GridView"/><title type='text'>GridView 的RowIndex</title><content type='html'>&lt;br /&gt;
用GridView好一陣子了，之前都會搭配ObjectDataSource一起使用，所以在使用Update Command的時候，只需要ObjectDataSource中有對應的Update Method就可以很容易執行Update的方法，這中間躲掉了一個如果我想要點選自訂Command的按鈕時，該如何才能輕鬆抓到RodIndex的問題。&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
試想一下哪些狀況會需要抓取RowIndex呢?主要情形有兩種&lt;br /&gt;
第一、當你有對GridView設定DataKeys屬性時，你可以透過這個屬性來取到該Row的鍵值，範例程式碼如下&lt;br /&gt;
&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
  {
    &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;(e.CommandName==&lt;span style=&quot;color: maroon;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;Add&quot;&lt;/span&gt;&lt;/span&gt;)
    {
      &lt;span style=&quot;color: green;&quot;&gt;// Convert the row index stored in the CommandArgument&lt;/span&gt;
      &lt;span style=&quot;color: green;&quot;&gt;// property to an Integer.&lt;/span&gt;
      &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; index = Convert.ToInt32(e.CommandArgument);&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;      string myKey = ContactsGridView.DataKeys[index]&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;.Value;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;     }&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;  }&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;上述程式碼的e.CommandArgument可以使用的前提是該按鈕設定如下&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;asp:buttonfield buttontype=&quot;Link&quot; 
                  commandname=&quot;Add&quot; 
                  text=&quot;Add&quot;
&lt;/span&gt;&lt;/pre&gt;
&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;/span&gt;&lt;br /&gt;
第二、是你想要抓取該選取列之其他欄位的值 ，範例程式碼如下&lt;br /&gt;
&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
  {
    &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;(e.CommandName==&lt;span style=&quot;color: maroon;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;Select&quot;&lt;/span&gt;&lt;/span&gt;)
    {
      &lt;span style=&quot;color: green;&quot;&gt;// Convert the row index stored in the CommandArgument&lt;/span&gt;
      &lt;span style=&quot;color: green;&quot;&gt;// property to an Integer.&lt;/span&gt;
      &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; index = Convert.ToInt32(e.CommandArgument);&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;      string TheValue = ContactsGridView.Rows[index]&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;/span&gt;.Cell[2].Text;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;     }&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;  }&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;上述程式碼的e.CommandArgument可以使用的前提是該按鈕設定如下&lt;/span&gt;&lt;/span&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;asp:buttonfield buttontype=&quot;Link&quot; 
                  commandname=&quot;Select&quot; 
                  text=&quot;Select&quot; 
&lt;/span&gt;

&lt;/pre&gt;
&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;上述兩種狀況都在說明都需要使用buttonfield則GridView才會在&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;GridViewCommandEventArgs中的CommandArgument設定該RowIndex，但這樣設定預設也會驅動GridView的&lt;b&gt;Select&lt;/b&gt;以及&lt;b&gt;Add&lt;/b&gt;事件，如果我們想要使用客製化的按鈕名稱，並不想驅動GridView中預設的事件時，則我們會在GridView中使用樣板的方式，加入自己想要的按鈕然後設定其CommandName，但經過這樣設定，CommandArgument中將不會再有RowIndex的資訊，如下&lt;/span&gt;&lt;/span&gt;







&lt;br /&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; ContactsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
  {
    &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;(e.CommandName==&lt;span style=&quot;color: maroon;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;MySelect&quot;&lt;/span&gt;&lt;/span&gt;)
    {&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;      &lt;span style=&quot;color: #38761d;&quot;&gt;//下面將取不到RowIndex&lt;/span&gt;
      &lt;span style=&quot;color: #38761d;&quot;&gt;//int index = Convert.ToInt32(e.CommandArgument);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;      &lt;span style=&quot;color: #38761d;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;      GridViewRow Selectedrow =  (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);&lt;span style=&quot;color: #38761d;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;       &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;string TheValue = Selectedrow&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;/span&gt;.Cell[2].Text;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;/span&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;     }&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;但是你可以使用CommandSource的方式，先取得該按鈕，然後經由該按鈕的NamingContainer抓到該按鈕所位處的Row。其實透過該方法，還是不會知道RowIndex，但原本想要抓取RowIndex也是想要透過該Index抓取所選取的欄位中的值，所以透過CommandSource的方式也算是能達到我們的需求。不過我個人覺得透過這樣的方式抓取未免太不直覺，而且照理說要解決這樣的方式，應該還是要想辦法把RowIndex的資訊想辦法塞到CommandArgument中。記得兩年前尋找該方法的時候，於MSDN中是採取透過GridView的RowCreated事件，在該事件中將RowIndex塞入我們要客製的按鈕的CommandArgument屬性中，不過這個方法太麻煩了，需要再多寫一個事件，如果我以後想要撰寫類似的程式，使用Copy,Past大法時就很麻煩，需要先複製aspx上面的GridView宣告，然後再複製CodeFile中實做的事件程式碼，而且如果按鈕的ID取名不一樣，那就兩邊都需要同時再做修正。&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;廢話不多說，好久總是沉甕底，今天再次尋找該方法的時候MSND裡出現了另一個解決方案(當然我不知道他什麼時候改的)，參考網址&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx&quot;&gt;GridView..::.RowCommand Event&lt;/a&gt; ，主要是在宣告區域中採用底下方法(請注意CommandArgument屬性)&lt;/span&gt;&lt;/span&gt;                            
              &lt;asp:button runat=&quot;&amp;lt;span&quot; style=&quot;color: maroon;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;server&quot;&lt;/span&gt; ID=&lt;span style=&quot;color: maroon;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;IncreaseButton&quot;&lt;/span&gt;&lt;/span&gt;
                Text=&lt;span style=&quot;color: maroon;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;Increase Price 5%&quot;&lt;/span&gt;&lt;/span&gt;
                CommandName=&lt;span style=&quot;color: maroon;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;Increase&quot;&lt;/span&gt;&lt;/span&gt;
                CommandArgument=&lt;span style=&quot;color: maroon;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&amp;lt;%# ((GridViewRow) Container).RowIndex %&amp;gt;&quot;&lt;/span&gt;&lt;/span&gt; /&amp;gt;
&lt;/asp:button&gt;&lt;asp:templatefield&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl07&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08&quot;&gt;&lt;itemtemplate&gt;&lt;/itemtemplate&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/asp:templatefield&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl07&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08&quot;&gt;透過所謂延遲繫結的方式，將RowIndex直接設定給CommandArgument，相信這種方法其實早就該有了，只不過是早想到還是晚想到的問題而已。&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl07&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08&quot;&gt;這是MDSN中Note:的區段，貼下來留念一下&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08_code&quot; space=&quot;preserve&quot; style=&quot;background-color: #cfe2f3; white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl07&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08&quot;&gt;To determine the index of the row that raised the event, use the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.commandeventargs.commandargument.aspx&quot; id=&quot;ctl00_MTCS_main_ctl63_ctl00_ctl18&quot; onclick=&quot;javascript:Track(&#39;ctl00_MTCS_main_ctl63_ctl00_contenthere|ctl00_MTCS_main_ctl63_ctl00_ctl18&#39;,this);&quot;&gt;CommandArgument&lt;/a&gt; property of the event argument that is passed to the event. The &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.buttonfield.aspx&quot; id=&quot;ctl00_MTCS_main_ctl63_ctl00_ctl19&quot; onclick=&quot;javascript:Track(&#39;ctl00_MTCS_main_ctl63_ctl00_contenthere|ctl00_MTCS_main_ctl63_ctl00_ctl19&#39;,this);&quot;&gt;ButtonField&lt;/a&gt; class automatically populates the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.commandeventargs.commandargument.aspx&quot; id=&quot;ctl00_MTCS_main_ctl63_ctl00_ctl20&quot; onclick=&quot;javascript:Track(&#39;ctl00_MTCS_main_ctl63_ctl00_contenthere|ctl00_MTCS_main_ctl63_ctl00_ctl20&#39;,this);&quot;&gt;CommandArgument&lt;/a&gt; property with the appropriate index value. For other command buttons, you must manually set the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx&quot; id=&quot;ctl00_MTCS_main_ctl63_ctl00_ctl21&quot; onclick=&quot;javascript:Track(&#39;ctl00_MTCS_main_ctl63_ctl00_contenthere|ctl00_MTCS_main_ctl63_ctl00_ctl21&#39;,this);&quot;&gt;CommandArgument&lt;/a&gt; property of the command button. For example, you can set the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx&quot; id=&quot;ctl00_MTCS_main_ctl63_ctl00_ctl22&quot; onclick=&quot;javascript:Track(&#39;ctl00_MTCS_main_ctl63_ctl00_contenthere|ctl00_MTCS_main_ctl63_ctl00_ctl22&#39;,this);&quot;&gt;CommandArgument&lt;/a&gt; to &amp;lt;%# Container.DataItemIndex %&amp;gt; when the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx&quot; id=&quot;ctl00_MTCS_main_ctl63_ctl00_ctl23&quot; onclick=&quot;javascript:Track(&#39;ctl00_MTCS_main_ctl63_ctl00_contenthere|ctl00_MTCS_main_ctl63_ctl00_ctl23&#39;,this);&quot;&gt;GridView&lt;/a&gt; control has no paging enabled.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl07&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;libCScode&quot; id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08_code&quot; space=&quot;preserve&quot; style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl07&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08&quot;&gt;&lt;b&gt;結論:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl03&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl07&quot;&gt;&lt;span id=&quot;ctl00_MTCS_main_ctl64_ctl00_ctl08&quot;&gt;延遲繫結的技巧其實我也算常常用，不過卻很少會使用GridView中預設的屬性，例如範例中的Container，所以對他真的很不熟，下面列出找到的相關參考連結。&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;


&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx&quot;&gt;GridView..::.RowCommand Event&lt;/a&gt;&lt;a href=&quot;http://www.blogger.com/goog_1260545862163&quot;&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.idataitemcontainer_members.aspx&quot;&gt;IDataItemContainer Members&lt;/a&gt;
&lt;br /&gt;
&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/858twd77%28VS.100%29.aspx&quot;&gt;How to: Access Members of a Control&#39;s Naming Container&lt;/a&gt;
&lt;br /&gt;
&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/858twd77%28VS.80%29.aspx&quot;&gt;How to: Access Members of a Web Server Control&#39;s Naming Container&lt;/a&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pinnynet.blogspot.com/feeds/6392011780624191178/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/8827818669723021586/6392011780624191178' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/6392011780624191178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8827818669723021586/posts/default/6392011780624191178'/><link rel='alternate' type='text/html' href='http://pinnynet.blogspot.com/2009/12/gridview-rowindex.html' title='GridView 的RowIndex'/><author><name>avi</name><uri>http://www.blogger.com/profile/18368334006791163238</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>