﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-</title><link>http://www.cnblogs.com/ltjabc/</link><description /><language>zh-cn</language><lastBuildDate>Sat, 06 Sep 2008 02:17:58 GMT</lastBuildDate><pubDate>Sat, 06 Sep 2008 02:17:58 GMT</pubDate><ttl>60</ttl><item><title>XNA Game Studio 2.0安装问题，崩溃了 </title><link>http://www.cnblogs.com/ltjabc/archive/2008/04/25/1170776.html</link><dc:creator>Liu</dc:creator><author>Liu</author><pubDate>Fri, 25 Apr 2008 03:37:00 GMT</pubDate><guid>http://www.cnblogs.com/ltjabc/archive/2008/04/25/1170776.html</guid><wfw:comment>http://www.cnblogs.com/ltjabc/comments/1170776.html</wfw:comment><comments>http://www.cnblogs.com/ltjabc/archive/2008/04/25/1170776.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnblogs.com/ltjabc/comments/commentRss/1170776.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/ltjabc/services/trackbacks/1170776.html</trackback:ping><description><![CDATA[<div class="postTitle"><a id="AjaxHolder_ctl01_TitleUrl" href="http://www.cnblogs.com/ltjabc/articles/1170765.html"></a>&nbsp;</div>
<div class="postText">安装后给了个提示:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<p><font face="Verdana">Microsoft XNA Game Studio 2.0 Setup ended prematurely due to an error.Your system has not been modified.To install this </font></p>
<p><font face="Verdana">program at a later time,please run the installation again.</font></p>
<br />
&nbsp;&nbsp; 不知道杂搞了，VS2005+Sp1都重装过，好几天了。</div>
<img src ="http://www.cnblogs.com/ltjabc/aggbug/1170776.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42116/" target="_blank">[新闻]消息称MySQL创始人已向Sun提交辞呈</a>]]></description></item><item><title>基于AJAX .net的地图</title><link>http://www.cnblogs.com/ltjabc/archive/2006/03/10/347081.html</link><dc:creator>Liu</dc:creator><author>Liu</author><pubDate>Fri, 10 Mar 2006 04:43:00 GMT</pubDate><guid>http://www.cnblogs.com/ltjabc/archive/2006/03/10/347081.html</guid><wfw:comment>http://www.cnblogs.com/ltjabc/comments/347081.html</wfw:comment><comments>http://www.cnblogs.com/ltjabc/archive/2006/03/10/347081.html#Feedback</comments><slash:comments>11</slash:comments><wfw:commentRss>http://www.cnblogs.com/ltjabc/comments/commentRss/347081.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/ltjabc/services/trackbacks/347081.html</trackback:ping><description><![CDATA[http://my.edushi.com<BR>正在测试中，大家评论一下。<img src ="http://www.cnblogs.com/ltjabc/aggbug/347081.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42115/" target="_blank">[新闻]谷歌Chrome浏览器即将更换LOGO颜色？</a>]]></description></item><item><title>好玩的地图</title><link>http://www.cnblogs.com/ltjabc/archive/2006/03/03/342013.html</link><dc:creator>Liu</dc:creator><author>Liu</author><pubDate>Fri, 03 Mar 2006 05:18:00 GMT</pubDate><guid>http://www.cnblogs.com/ltjabc/archive/2006/03/03/342013.html</guid><wfw:comment>http://www.cnblogs.com/ltjabc/comments/342013.html</wfw:comment><comments>http://www.cnblogs.com/ltjabc/archive/2006/03/03/342013.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnblogs.com/ltjabc/comments/commentRss/342013.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/ltjabc/services/trackbacks/342013.html</trackback:ping><description><![CDATA[&lt;script language="javascript" src="<A href="http://www.edushi.com/api/api.js?isMark=1&amp;z=2&amp;v=3&amp;x=5174&amp;y=9564&amp;w=600&amp;h=350&amp;city=hz&amp;sitename">http://www.edushi.com/api/api.js?isMark=1&amp;z=2&amp;v=3&amp;x=5174&amp;y=9564&amp;w=600&amp;h=350&amp;city=hz&amp;sitename</A>=我的位置"&gt;&lt;/script&gt;<img src ="http://www.cnblogs.com/ltjabc/aggbug/342013.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42101/" target="_blank">[新闻]淘宝网合并阿里妈妈 专家称阿里巴巴或有新战略</a>]]></description></item><item><title>Lion的发送E-mail的类 </title><link>http://www.cnblogs.com/ltjabc/archive/2005/12/14/296741.html</link><dc:creator>Liu</dc:creator><author>Liu</author><pubDate>Wed, 14 Dec 2005 01:29:00 GMT</pubDate><guid>http://www.cnblogs.com/ltjabc/archive/2005/12/14/296741.html</guid><wfw:comment>http://www.cnblogs.com/ltjabc/comments/296741.html</wfw:comment><comments>http://www.cnblogs.com/ltjabc/archive/2005/12/14/296741.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/ltjabc/comments/commentRss/296741.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/ltjabc/services/trackbacks/296741.html</trackback:ping><description><![CDATA[<P>using System;<BR>using System.Text;<BR>using System.IO;<BR>using System.Net;<BR>using System.Net.Sockets;<BR>using System.Collections;</P>
<P>namespace Lion.Web.Mail<BR>{<BR>&nbsp;/*&nbsp; <BR>&nbsp;Create By lion&nbsp; <BR>&nbsp;2004-04-23 19:00&nbsp;&nbsp;<BR><BR>&nbsp;Support <a title="" href="http://ltjabc.cnblogs.com" >C#</a> Framework Beta 2&nbsp; <BR>&nbsp;*/&nbsp; <BR>&nbsp;#region AspNetPager Server Control</P>
<P>&nbsp;/// &lt;summary&gt;<BR>&nbsp;/// 邮件可以通过 Microsoft Windows 2000 中内置的 SMTP 邮件服务或任意 SMTP 服务器来传送<BR>&nbsp;/// &lt;/summary&gt;<BR>&nbsp;public class SmtpMail<BR>&nbsp;{</P>
<P>&nbsp; private string enter="\r\n";</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 设定语言代码，默认设定为GB2312，如不需要可设置为""<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private string _charset="GB2312";</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 发件人地址<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private string _from="";</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 发件人姓名<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private string _fromName="";</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 回复邮件地址<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; ///public string ReplyTo="";</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 收件人姓名<BR>&nbsp; /// &lt;/summary&gt; <BR>&nbsp; private string _recipientName="";</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 收件人列表<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private Hashtable Recipient=new Hashtable();</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 邮件服务器域名<BR>&nbsp; /// &lt;/summary&gt; <BR>&nbsp; private string mailserver="";</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 邮件服务器端口号<BR>&nbsp; /// &lt;/summary&gt; <BR>&nbsp; private int mailserverport=25;</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// SMTP认证时使用的用户名<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private string username="";</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// SMTP认证时使用的密码<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private string password="";</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 是否需要SMTP验证<BR>&nbsp; /// &lt;/summary&gt;&nbsp; <BR>&nbsp; private bool ESmtp=false;</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 是否Html邮件<BR>&nbsp; /// &lt;/summary&gt;&nbsp; <BR>&nbsp; private bool _html=false;</P>
<P><BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 邮件附件列表<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private IList Attachments;</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 邮件发送优先级，可设置为"High","Normal","Low"或"1","3","5"<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private string priority="Normal";</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 邮件主题<BR>&nbsp; /// &lt;/summary&gt;&nbsp; <BR>&nbsp; private string _subject;</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 邮件正文<BR>&nbsp; /// &lt;/summary&gt;&nbsp; <BR>&nbsp; private string _body;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 密送收件人列表<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; ///private Hashtable RecipientBCC=new Hashtable();</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 收件人数量<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private int RecipientNum=0;</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 最多收件人数量<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private int recipientmaxnum=5;</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 密件收件人数量<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; ///private int RecipientBCCNum=0;</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 错误消息反馈<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private string errmsg;</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// TcpClient对象，用于连接服务器<BR>&nbsp; /// &lt;/summary&gt; <BR>&nbsp; private TcpClient tc;</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// NetworkStream对象<BR>&nbsp; /// &lt;/summary&gt; <BR>&nbsp; private NetworkStream ns;<BR>&nbsp; <BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 服务器交互记录<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private string logs="";</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// SMTP错误代码哈希表<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private Hashtable ErrCodeHT = new Hashtable();</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// SMTP正确代码哈希表<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private Hashtable RightCodeHT = new Hashtable();<BR>&nbsp; </P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 初始化 &lt;see cref="Lion.Web.Mail.SmtpMail"/&gt; 类的新实例<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public SmtpMail()<BR>&nbsp; {<BR>&nbsp;&nbsp; Attachments = new System.Collections.ArrayList();<BR>&nbsp; }</P>
<P>&nbsp; #region Properties</P>
<P><BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 邮件主题<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public string Subject<BR>&nbsp; {<BR>&nbsp;&nbsp; get<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return this._subject;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; this._subject = value;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 邮件正文<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public string Body<BR>&nbsp; {<BR>&nbsp;&nbsp; get<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return this._body;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; this._body = value;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; <BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 发件人地址<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public string From<BR>&nbsp; {<BR>&nbsp;&nbsp; get<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return _from;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; this._from = value;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 设定语言代码，默认设定为GB2312，如不需要可设置为""<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public string Charset<BR>&nbsp; {<BR>&nbsp;&nbsp; get<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return this._charset;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; this._charset = value;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 发件人姓名<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public string FromName<BR>&nbsp; {<BR>&nbsp;&nbsp; get<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return this._fromName;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; this._fromName = value;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 收件人姓名<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public string RecipientName<BR>&nbsp; {<BR>&nbsp;&nbsp; get<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return this._recipientName;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; this._recipientName = value;<BR>&nbsp;&nbsp; }<BR>&nbsp; }<BR>&nbsp; <BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 邮件服务器域名和验证信息<BR>&nbsp; /// 形如："user:pass@www.server.com:25"，也可省略次要信息。如"user:pass@www.server.com"或"<A href="http://www.server.com/">www.server.com</A>"<BR>&nbsp; /// &lt;/summary&gt; <BR>&nbsp; public string MailDomain<BR>&nbsp; {<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; string maidomain=value.Trim();<BR>&nbsp;&nbsp;&nbsp; int tempint;</P>
<P>&nbsp;&nbsp;&nbsp; if(maidomain!="")<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; tempint=maidomain.IndexOf("@");<BR>&nbsp;&nbsp;&nbsp;&nbsp; if(tempint!=-1)<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string str=maidomain.Substring(0,tempint);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MailServerUserName=str.Substring(0,str.IndexOf(":"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MailServerPassWord=str.Substring(str.IndexOf(":")+1,str.Length-str.IndexOf</P>
<P>(":")-1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maidomain=maidomain.Substring(tempint+1,maidomain.Length-tempint-1);<BR>&nbsp;&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; tempint=maidomain.IndexOf(":");<BR>&nbsp;&nbsp;&nbsp;&nbsp; if(tempint!=-1)<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mailserver=maidomain.Substring(0,tempint);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mailserverport=System.Convert.ToInt32(maidomain.Substring</P>
<P>(tempint+1,maidomain.Length-tempint-1));<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mailserver=maidomain;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp;</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 邮件服务器端口号<BR>&nbsp; /// &lt;/summary&gt; <BR>&nbsp; public int MailDomainPort<BR>&nbsp; {<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; mailserverport=value;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp;</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// SMTP认证时使用的用户名<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public string MailServerUserName<BR>&nbsp; {<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; if(value.Trim()!="")<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; username=value.Trim();<BR>&nbsp;&nbsp;&nbsp;&nbsp; ESmtp=true;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; username="";<BR>&nbsp;&nbsp;&nbsp;&nbsp; ESmtp=false;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// SMTP认证时使用的密码<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public string MailServerPassWord<BR>&nbsp; {<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; password=value;<BR>&nbsp;&nbsp; }<BR>&nbsp; } </P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 邮件发送优先级，可设置为"High","Normal","Low"或"1","3","5"<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public string Priority<BR>&nbsp; {<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; switch(value.ToLower())<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; case "high":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; priority="High";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; case "1":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; priority="High";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; case "normal":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; priority="Normal";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; case "3":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; priority="Normal";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; case "low":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; priority="Low";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; case "5":<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; priority="Low";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; default:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; priority="Normal";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; ///&nbsp; 是否Html邮件<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public bool Html<BR>&nbsp; {<BR>&nbsp;&nbsp; get<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return this._html;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; this._html = value;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P><BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 错误消息反馈<BR>&nbsp; /// &lt;/summary&gt;&nbsp; <BR>&nbsp; public string ErrorMessage<BR>&nbsp; {<BR>&nbsp;&nbsp; get<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return errmsg;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 服务器交互记录，如发现本组件不能使用的SMTP服务器，请将出错时的Logs发给我（<A href="mailto:lion-a@sohu.com">lion-a@sohu.com</A>），我将尽快查明</P>
<P>原因。<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public string Logs<BR>&nbsp; {<BR>&nbsp;&nbsp; get<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return logs;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 最多收件人数量<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public int RecipientMaxNum<BR>&nbsp; {<BR>&nbsp;&nbsp; set<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; recipientmaxnum = value;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; <BR>&nbsp; #endregion</P>
<P>&nbsp; #region Methods</P>
<P><BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 添加邮件附件<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; /// &lt;param name="FilePath"&gt;附件绝对路径&lt;/param&gt;<BR>&nbsp; public void AddAttachment(params string[] FilePath)<BR>&nbsp; {<BR>&nbsp;&nbsp; if(FilePath==null)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; throw(new ArgumentNullException("FilePath"));<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; for(int i=0;i&lt;FilePath.Length;i++)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; Attachments.Add(FilePath[i]);<BR>&nbsp;&nbsp; }<BR>&nbsp; }<BR>&nbsp; <BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 添加一组收件人（不超过recipientmaxnum个），参数为字符串数组<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; /// &lt;param name="Recipients"&gt;保存有收件人地址的字符串数组（不超过recipientmaxnum个）&lt;/param&gt; <BR>&nbsp; public bool AddRecipient(params string[] Recipients)<BR>&nbsp; {<BR>&nbsp;&nbsp; if(Recipient==null)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; Dispose();<BR>&nbsp;&nbsp;&nbsp; throw(new ArgumentNullException("Recipients"));<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; for(int i=0;i&lt;Recipients.Length;i++)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; string recipient = Recipients[i].Trim();<BR>&nbsp;&nbsp;&nbsp; if(recipient==String.Empty)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp; throw(new ArgumentNullException("Recipients["+ i +"]"));<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; if(recipient.IndexOf("@")==-1)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp; throw(new ArgumentException(<A>"Recipients.IndexOf(\"@\")==-1","Recipients</A>"));<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; if(!AddRecipient(recipient))<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; return true;<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 发送邮件方法，所有参数均通过属性设置。<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; public bool Send()<BR>&nbsp; {<BR>&nbsp;&nbsp; if(mailserver.Trim()=="")<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; throw(new ArgumentNullException("Recipient","必须指定SMTP服务器"));<BR>&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp; return SendEmail();<BR>&nbsp;&nbsp; <BR>&nbsp; }</P>
<P><BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 发送邮件方法<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; /// &lt;param name="smtpserver"&gt;smtp服务器信息，如"username:password@www.smtpserver.com:25"，也可去掉部分次要信</P>
<P>息，如"<A href='http://www.smtpserver.com"</param'>www.smtpserver.com"&lt;/param</A>&gt;<BR>&nbsp; public bool Send(string smtpserver)<BR>&nbsp; {&nbsp;&nbsp; <BR>&nbsp;&nbsp; MailDomain=smtpserver;<BR>&nbsp;&nbsp; return Send();<BR>&nbsp; }</P>
<P><BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 发送邮件方法<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; /// &lt;param name="smtpserver"&gt;smtp服务器信息，如"username:password@www.smtpserver.com:25"，也可去掉部分次要信</P>
<P>息，如"<A href='http://www.smtpserver.com"</param'>www.smtpserver.com"&lt;/param</A>&gt;<BR>&nbsp; /// &lt;param name="from"&gt;发件人mail地址&lt;/param&gt;<BR>&nbsp; /// &lt;param name="fromname"&gt;发件人姓名&lt;/param&gt;<BR>&nbsp; /// &lt;param name="to"&gt;收件人地址&lt;/param&gt;<BR>&nbsp; /// &lt;param name="toname"&gt;收件人姓名&lt;/param&gt;<BR>&nbsp; /// &lt;param name="html"&gt;是否HTML邮件&lt;/param&gt;<BR>&nbsp; /// &lt;param name="subject"&gt;邮件主题&lt;/param&gt;<BR>&nbsp; /// &lt;param name="body"&gt;邮件正文&lt;/param&gt;<BR>&nbsp; public bool Send(string smtpserver,string from,string fromname,string to,string toname,bool html,string </P>
<P>subject,string body)<BR>&nbsp; {<BR>&nbsp;&nbsp; MailDomain=smtpserver;<BR>&nbsp;&nbsp; From=from;<BR>&nbsp;&nbsp; FromName=fromname;<BR>&nbsp;&nbsp; AddRecipient(to);<BR>&nbsp;&nbsp; RecipientName=toname;<BR>&nbsp;&nbsp; Html=html;<BR>&nbsp;&nbsp; Subject=subject;<BR>&nbsp;&nbsp; Body=body;<BR>&nbsp;&nbsp; return Send();<BR>&nbsp; }<BR>&nbsp; </P>
<P>&nbsp; #endregion</P>
<P>&nbsp; #region Private Helper Functions</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 添加一个收件人<BR>&nbsp; /// &lt;/summary&gt; <BR>&nbsp; /// &lt;param name="Recipients"&gt;收件人地址&lt;/param&gt;<BR>&nbsp; private bool AddRecipient(string Recipients)<BR>&nbsp; {<BR>&nbsp;&nbsp; if(RecipientNum&lt;recipientmaxnum)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; Recipient.Add(RecipientNum,Recipients);<BR>&nbsp;&nbsp;&nbsp; RecipientNum++;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; return true;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; Dispose();<BR>&nbsp;&nbsp;&nbsp; throw(new ArgumentOutOfRangeException("Recipients","收件人过多不可多于 "+ recipientmaxnum&nbsp; +" </P>
<P>个"));<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; void Dispose()<BR>&nbsp; {<BR>&nbsp;&nbsp; if(ns!=null)ns.Close();<BR>&nbsp;&nbsp; if(tc!=null)tc.Close();<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// SMTP回应代码哈希表<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private void SMTPCodeAdd()<BR>&nbsp; {<BR>&nbsp;&nbsp; ErrCodeHT.Add("500","邮箱地址错误");<BR>&nbsp;&nbsp; ErrCodeHT.Add("501","参数格式错误");<BR>&nbsp;&nbsp; ErrCodeHT.Add("502","命令不可实现");<BR>&nbsp;&nbsp; ErrCodeHT.Add("503","服务器需要SMTP验证");<BR>&nbsp;&nbsp; ErrCodeHT.Add("504","命令参数不可实现");<BR>&nbsp;&nbsp; ErrCodeHT.Add("421","服务未就绪，关闭传输信道");<BR>&nbsp;&nbsp; ErrCodeHT.Add("450","要求的邮件操作未完成，邮箱不可用（例如，邮箱忙）");<BR>&nbsp;&nbsp; ErrCodeHT.Add("550","要求的邮件操作未完成，邮箱不可用（例如，邮箱未找到，或不可访问）");<BR>&nbsp;&nbsp; ErrCodeHT.Add("451","放弃要求的操作；处理过程中出错");<BR>&nbsp;&nbsp; ErrCodeHT.Add("551","用户非本地，请尝试&lt;forward-path&gt;");<BR>&nbsp;&nbsp; ErrCodeHT.Add("452","系统存储不足，要求的操作未执行");<BR>&nbsp;&nbsp; ErrCodeHT.Add("552","过量的存储分配，要求的操作未执行");<BR>&nbsp;&nbsp; ErrCodeHT.Add("553","邮箱名不可用，要求的操作未执行（例如邮箱格式错误）");<BR>&nbsp;&nbsp; ErrCodeHT.Add("432","需要一个密码转换");<BR>&nbsp;&nbsp; ErrCodeHT.Add("534","认证机制过于简单");<BR>&nbsp;&nbsp; ErrCodeHT.Add("538","当前请求的认证机制需要加密");<BR>&nbsp;&nbsp; ErrCodeHT.Add("454","临时认证失败");<BR>&nbsp;&nbsp; ErrCodeHT.Add("530","需要认证");</P>
<P>&nbsp;&nbsp; RightCodeHT.Add("220","服务就绪");<BR>&nbsp;&nbsp; RightCodeHT.Add("250","要求的邮件操作完成");<BR>&nbsp;&nbsp; RightCodeHT.Add("251","用户非本地，将转发向&lt;forward-path&gt;");<BR>&nbsp;&nbsp; RightCodeHT.Add("354","开始邮件输入，以&lt;enter&gt;.&lt;enter&gt;结束");<BR>&nbsp;&nbsp; RightCodeHT.Add("221","服务关闭传输信道");<BR>&nbsp;&nbsp; RightCodeHT.Add("334","服务器响应验证Base64字符串");<BR>&nbsp;&nbsp; RightCodeHT.Add("235","验证成功");<BR>&nbsp; }</P>
<P><BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 将字符串编码为Base64字符串<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; /// &lt;param name="str"&gt;要编码的字符串&lt;/param&gt;<BR>&nbsp; private string Base64Encode(string str)<BR>&nbsp; {<BR>&nbsp;&nbsp; byte[] barray;<BR>&nbsp;&nbsp; barray=Encoding.Default.GetBytes(str);<BR>&nbsp;&nbsp; return Convert.ToBase64String(barray);<BR>&nbsp; }</P>
<P><BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 将Base64字符串解码为普通字符串<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; /// &lt;param name="str"&gt;要解码的字符串&lt;/param&gt;<BR>&nbsp; private string Base64Decode(string str)<BR>&nbsp; {<BR>&nbsp;&nbsp; byte[] barray;<BR>&nbsp;&nbsp; barray=Convert.FromBase64String(str);<BR>&nbsp;&nbsp; return Encoding.Default.GetString(barray);<BR>&nbsp; }</P>
<P>&nbsp; <BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 得到上传附件的文件流<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; /// &lt;param name="FilePath"&gt;附件的绝对路径&lt;/param&gt;<BR>&nbsp; private string GetStream(string FilePath)<BR>&nbsp; {<BR>&nbsp;&nbsp; //建立文件流对象<BR>&nbsp;&nbsp; System.IO.FileStream FileStr=new System.IO.FileStream(FilePath,System.IO.FileMode.Open);<BR>&nbsp;&nbsp; byte[] by=new byte[System.Convert.ToInt32(FileStr.Length)];<BR>&nbsp;&nbsp; FileStr.Read(by,0,by.Length);<BR>&nbsp;&nbsp; FileStr.Close();<BR>&nbsp;&nbsp; return(System.Convert.ToBase64String(by));<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 发送SMTP命令<BR>&nbsp; /// &lt;/summary&gt; <BR>&nbsp; private bool SendCommand(string str)<BR>&nbsp; {<BR>&nbsp;&nbsp; byte[]&nbsp; WriteBuffer;<BR>&nbsp;&nbsp; if(str==null||str.Trim()==String.Empty)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return true;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; logs+=str;<BR>&nbsp;&nbsp; WriteBuffer = Encoding.Default.GetBytes(str);<BR>&nbsp;&nbsp; try<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; ns.Write(WriteBuffer,0,WriteBuffer.Length);<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; catch<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; errmsg="网络连接错误";<BR>&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; return true;<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 接收SMTP服务器回应<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; private string RecvResponse()<BR>&nbsp; {<BR>&nbsp;&nbsp; int StreamSize;<BR>&nbsp;&nbsp; string ReturnValue = String.Empty;<BR>&nbsp;&nbsp; byte[]&nbsp; ReadBuffer = new byte[1024] ;<BR>&nbsp;&nbsp; try<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; StreamSize=ns.Read(ReadBuffer,0,ReadBuffer.Length);<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; catch<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; errmsg="网络连接错误";<BR>&nbsp;&nbsp;&nbsp; return "false";<BR>&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp; if (StreamSize==0)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return ReturnValue ;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; ReturnValue = Encoding.Default.GetString(ReadBuffer).Substring(0,StreamSize);<BR>&nbsp;&nbsp;&nbsp; logs+=ReturnValue+this.enter;<BR>&nbsp;&nbsp;&nbsp; return&nbsp; ReturnValue;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 与服务器交互，发送一条命令并接收回应。<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; /// &lt;param name="str"&gt;一个要发送的命令&lt;/param&gt;<BR>&nbsp; /// &lt;param name="errstr"&gt;如果错误，要反馈的信息&lt;/param&gt;<BR>&nbsp; private bool Dialog(string str,string errstr)<BR>&nbsp; {<BR>&nbsp;&nbsp; if(str==null||str.Trim()=="")<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return true;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; if(SendCommand(str))<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; string RR=RecvResponse();<BR>&nbsp;&nbsp;&nbsp; if(RR=="false")<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; string RRCode=RR.Substring(0,3);<BR>&nbsp;&nbsp;&nbsp; if(RightCodeHT[RRCode]!=null)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; return true;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; if(ErrCodeHT[RRCode]!=null)<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errmsg+=(RRCode+ErrCodeHT[RRCode].ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errmsg+=enter;<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errmsg+=RR;<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp; errmsg+=errstr;<BR>&nbsp;&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp; }</P>
<P>&nbsp; }</P>
<P><BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 与服务器交互，发送一组命令并接收回应。<BR>&nbsp; /// &lt;/summary&gt;</P>
<P>&nbsp; private bool Dialog(string[] str,string errstr)<BR>&nbsp; {<BR>&nbsp;&nbsp; for(int i=0;i&lt;str.Length;i++)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; if(!Dialog(str[i],""))<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; errmsg+=enter;<BR>&nbsp;&nbsp;&nbsp;&nbsp; errmsg+=errstr;<BR>&nbsp;&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp; return true;<BR>&nbsp; }</P>
<P>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// SendEmail<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; /// &lt;returns&gt;&lt;/returns&gt;<BR>&nbsp; private bool SendEmail()<BR>&nbsp; {<BR>&nbsp;&nbsp; //连接网络<BR>&nbsp;&nbsp; try<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; tc=new TcpClient(mailserver,mailserverport);<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; catch(Exception e)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; errmsg=e.ToString();<BR>&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp; ns = tc.GetStream();<BR>&nbsp;&nbsp; SMTPCodeAdd();</P>
<P>&nbsp;&nbsp; //验证网络连接是否正确<BR>&nbsp;&nbsp; if(RightCodeHT[RecvResponse().Substring(0,3)]==null)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; errmsg="网络连接失败";<BR>&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp; }</P>
<P><BR>&nbsp;&nbsp; string[] SendBuffer;<BR>&nbsp;&nbsp; string SendBufferstr;</P>
<P>&nbsp;&nbsp; //进行SMTP验证<BR>&nbsp;&nbsp; if(ESmtp)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; SendBuffer=new String[4];<BR>&nbsp;&nbsp;&nbsp; SendBuffer[0]="EHLO " + mailserver + enter;<BR>&nbsp;&nbsp;&nbsp; SendBuffer[1]="AUTH LOGIN" + enter;<BR>&nbsp;&nbsp;&nbsp; SendBuffer[2]=Base64Encode(username) + enter;<BR>&nbsp;&nbsp;&nbsp; SendBuffer[3]=Base64Encode(password) + enter;<BR>&nbsp;&nbsp;&nbsp; if(!Dialog(SendBuffer,"SMTP服务器验证失败，请核对用户名和密码。"))<BR>&nbsp;&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; SendBufferstr="HELO " + mailserver + enter;<BR>&nbsp;&nbsp;&nbsp; if(!Dialog(SendBufferstr,""))<BR>&nbsp;&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp; //<BR>&nbsp;&nbsp; SendBufferstr="MAIL FROM:&lt;" + From + "&gt;" + enter;<BR>&nbsp;&nbsp; if(!Dialog(SendBufferstr,"发件人地址错误，或不能为空"))<BR>&nbsp;&nbsp;&nbsp; return false;</P>
<P>&nbsp;&nbsp; //<BR>&nbsp;&nbsp; SendBuffer=new string[recipientmaxnum];<BR>&nbsp;&nbsp; for(int i=0;i&lt;Recipient.Count;i++)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; SendBuffer[i]="RCPT TO:&lt;" + Recipient[i].ToString() +"&gt;" + enter;</P>
<P>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; if(!Dialog(SendBuffer,"收件人地址有误"))<BR>&nbsp;&nbsp;&nbsp; return false;</P>
<P>&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SendBuffer=new string[10];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i=0;i&lt;RecipientBCC.Count;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SendBuffer[i]="RCPT TO:&lt;" + RecipientBCC[i].ToString() +"&gt;" + enter;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!Dialog(SendBuffer,"密件收件人地址有误"))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp; */<BR>&nbsp;&nbsp; SendBufferstr="DATA" + enter;<BR>&nbsp;&nbsp; if(!Dialog(SendBufferstr,""))<BR>&nbsp;&nbsp;&nbsp; return false;</P>
<P>&nbsp;&nbsp; SendBufferstr="From:" + FromName + "&lt;" + From +"&gt;" +enter;</P>
<P>&nbsp;&nbsp; //if(ReplyTo.Trim()!="")<BR>&nbsp;&nbsp; //{<BR>&nbsp;&nbsp; // SendBufferstr+="Reply-To: " + ReplyTo + enter;<BR>&nbsp;&nbsp; //}</P>
<P>&nbsp;&nbsp; //SendBufferstr+="To:" + RecipientName + "&lt;" + Recipient[0] +"&gt;" +enter;<BR>&nbsp;&nbsp; SendBufferstr += "To:=?"+Charset.ToUpper()+"?B?"+Base64Encode(RecipientName)+"?="+"&lt;"+Recipient[0]</P>
<P>+"&gt;"+enter;<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; SendBufferstr+="CC:";<BR>&nbsp;&nbsp; for(int i=0;i&lt;Recipient.Count;i++)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; SendBufferstr+=Recipient[i].ToString() + "&lt;" + Recipient[i].ToString() +"&gt;,";<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; SendBufferstr+=enter;</P>
<P>&nbsp;&nbsp; SendBufferstr+=((Subject==String.Empty || Subject==null)?"Subject:":((Charset=="")?("Subject:" + </P>
<P>Subject):("Subject:" + "=?" + Charset.ToUpper() + "?B?" + Base64Encode(Subject) +"?="))) + enter;<BR>&nbsp;&nbsp; SendBufferstr+="X-Priority:" + priority + enter;<BR>&nbsp;&nbsp; SendBufferstr+="X-MSMail-Priority:" + priority + enter;<BR>&nbsp;&nbsp; SendBufferstr+="Importance:" + priority + enter;<BR>&nbsp;&nbsp; SendBufferstr+="X-Mailer: Lion.Web.Mail.SmtpMail Pubclass [cn]" + enter;<BR>&nbsp;&nbsp; SendBufferstr+="MIME-Version: 1.0" + enter;<BR>&nbsp;&nbsp; if(Attachments.Count!=0)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; SendBufferstr+="Content-Type: multipart/mixed;" + enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr += " boundary=\"====="+</P>
<P>(Html?"001_Dragon520636771063_":"001_Dragon303406132050_")+"=====\""+enter+enter;<BR>&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp; if(Html)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; if(Attachments.Count==0)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += "Content-Type: multipart/alternative;"+enter;//内容格式和分隔符<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += " boundary=\"=====003_Dragon520636771063_=====\""+enter+enter;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += "This is a multi-part message in MIME format."+enter+enter;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr +="This is a multi-part message in MIME format."+enter+enter;<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += "--=====001_Dragon520636771063_====="+enter;<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += "Content-Type: multipart/alternative;"+enter;//内容格式和分隔符<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += " boundary=\"=====003_Dragon520636771063_=====\""+enter+enter; </P>
<P>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; SendBufferstr += "--=====003_Dragon520636771063_====="+enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr += "Content-Type: text/plain;"+ enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr += ((Charset=="")?(" charset=\"iso-8859-1\""):(" charset=\"" + </P>
<P>Charset.ToLower() + "\"")) + enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr+="Content-Transfer-Encoding: base64" + enter + enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr+= Base64Encode("邮件内容为HTML格式，请选择HTML方式查看") + enter + enter;</P>
<P>&nbsp;&nbsp;&nbsp; SendBufferstr += "--=====003_Dragon520636771063_====="+enter;</P>
<P>&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp; SendBufferstr+="Content-Type: text/html;" + enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr+=((Charset=="")?(" charset=\"iso-8859-1\""):(" charset=\"" + </P>
<P>Charset.ToLower() + "\"")) + enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr+="Content-Transfer-Encoding: base64" + enter + enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr+= Base64Encode(Body) + enter + enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr += "--=====003_Dragon520636771063_=====--"+enter;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; if(Attachments.Count!=0)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += "--=====001_Dragon303406132050_====="+enter;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; SendBufferstr+="Content-Type: text/plain;" + enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr+=((Charset=="")?(" charset=\"iso-8859-1\""):(" charset=\"" + </P>
<P>Charset.ToLower() + "\"")) + enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr+="Content-Transfer-Encoding: base64" + enter + enter;<BR>&nbsp;&nbsp;&nbsp; SendBufferstr+= Base64Encode(Body) + enter;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; //SendBufferstr += "Content-Transfer-Encoding: base64"+enter;</P>
<P>&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp; <BR>&nbsp;&nbsp; if(Attachments.Count!=0)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; for(int i=0;i&lt;Attachments.Count;i++)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; string filepath = (string)Attachments[i];<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += "--====="+ </P>
<P>(Html?"001_Dragon520636771063_":"001_Dragon303406132050_") +"====="+enter;<BR>&nbsp;&nbsp;&nbsp;&nbsp; //SendBufferstr += "Content-Type: application/octet-stream"+enter;<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += "Content-Type: text/plain;"+enter;<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += " name=\"=?"+Charset.ToUpper()+"?B?"+Base64Encode</P>
<P>(filepath.Substring(filepath.LastIndexOf("<A href="file://%22)+1))+%22%3F=/%22%22+enter">\\")+1))+"?=\""+enter</A>;<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += "Content-Transfer-Encoding: base64"+enter;<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += "Content-Disposition: attachment;"+enter;<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += " filename=\"=?"+Charset.ToUpper()+"?B?"+Base64Encode</P>
<P>(filepath.Substring(filepath.LastIndexOf("<A href="file://%22)+1))+%22%3F=/%22%22+enter+enter">\\")+1))+"?=\""+enter+enter</A>;<BR>&nbsp;&nbsp;&nbsp;&nbsp; SendBufferstr += GetStream(filepath)+enter+enter;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; SendBufferstr += "--====="+ (Html?"001_Dragon520636771063_":"001_Dragon303406132050_") </P>
<P>+"=====--"+enter+enter;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; SendBufferstr += enter + "." + enter;</P>
<P>&nbsp;&nbsp; if(!Dialog(SendBufferstr,"错误信件信息"))<BR>&nbsp;&nbsp;&nbsp; return false;</P>
<P><BR>&nbsp;&nbsp; SendBufferstr="QUIT" + enter;<BR>&nbsp;&nbsp; if(!Dialog(SendBufferstr,"断开连接时错误"))<BR>&nbsp;&nbsp;&nbsp; return false;</P>
<P><BR>&nbsp;&nbsp; ns.Close();<BR>&nbsp;&nbsp; tc.Close();<BR>&nbsp;&nbsp; return true;<BR>&nbsp; }</P>
<P><BR>&nbsp; #endregion</P>
<P>&nbsp; #region<BR>&nbsp; /*<BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 添加一个密件收件人<BR>&nbsp; /// &lt;/summary&gt;<BR>&nbsp; /// &lt;param name="str"&gt;收件人地址&lt;/param&gt;<BR>&nbsp; public bool AddRecipientBCC(string str)<BR>&nbsp; {<BR>&nbsp;&nbsp; if(str==null||str.Trim()=="")<BR>&nbsp;&nbsp;&nbsp; return true;<BR>&nbsp;&nbsp; if(RecipientBCCNum&lt;10)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; RecipientBCC.Add(RecipientBCCNum,str);<BR>&nbsp;&nbsp;&nbsp; RecipientBCCNum++;<BR>&nbsp;&nbsp;&nbsp; return true;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; errmsg+="收件人过多";<BR>&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp; }<BR>&nbsp; }</P>
<P><BR>&nbsp; /// &lt;summary&gt;<BR>&nbsp; /// 添加一组密件收件人（不超过10个），参数为字符串数组<BR>&nbsp; /// &lt;/summary&gt; <BR>&nbsp; /// &lt;param name="str"&gt;保存有收件人地址的字符串数组（不超过10个）&lt;/param&gt;<BR>&nbsp; public bool AddRecipientBCC(string[] str)<BR>&nbsp; {<BR>&nbsp;&nbsp; for(int i=0;i&lt;str.Length;i++)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; if(!AddRecipientBCC(str[i]))<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; return false;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; return true;<BR>&nbsp; }</P>
<P>&nbsp; */&nbsp;&nbsp; <BR>&nbsp; #endregion <BR>&nbsp;}</P>
<P>&nbsp;#endregion<BR>}</P><img src ="http://www.cnblogs.com/ltjabc/aggbug/296741.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42096/" target="_blank">[新闻]微软研究院发布 AutoCollage - 整理并融合照片</a>]]></description></item><item><title>[转]WEB2.0中AJAX应用的详细探讨 </title><link>http://www.cnblogs.com/ltjabc/archive/2005/12/08/292878.html</link><dc:creator>Liu</dc:creator><author>Liu</author><pubDate>Thu, 08 Dec 2005 02:10:00 GMT</pubDate><guid>http://www.cnblogs.com/ltjabc/archive/2005/12/08/292878.html</guid><wfw:comment>http://www.cnblogs.com/ltjabc/comments/292878.html</wfw:comment><comments>http://www.cnblogs.com/ltjabc/archive/2005/12/08/292878.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/ltjabc/comments/commentRss/292878.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/ltjabc/services/trackbacks/292878.html</trackback:ping><description><![CDATA[最近互联网上比较火热的话题当然是关于WEB2.0的应用，其中AJAX又是WEB2.0的核心之一。AJAX是Asynchronous JavaScript and XML 的缩写。它并不是一门新的语言或技术，它实际上是几项技术按一定的方式组合在一在同共的协作中发挥各自的作用，它包括<BR>　　使用XHTML和CSS标准化呈现；<BR>　　使用DOM实现动态显示和交互；<BR>　　使用XML和XSLT进行数据交换与处理；<BR>　　使用XMLHttpRequest进行异步数据读取；<BR>　　最后用JavaScript绑定和处理所有数据；<BR>　　Ajax的工作原理相当于在用户和服务器之间加了—个中间层，使用户操作与服务器响应异步化。这样把以前的一些服务器负担的工作转嫁到客户端，利于客户端闲置的处理能力来处理，减轻服务器和带宽的负担，从而达到节约ISP的空间及带宽租用成本的目的。<BR><BR>我们以两个验证通行证帐号是否存在的例子来讲述AJAX在实际中的应用：<BR><BR><B>(1)&nbsp;&nbsp;&nbsp;&nbsp;用文本字符串的方式返回服务器的响应来验证网易通行证帐号是否存在；</B> <BR><B>(2)&nbsp;&nbsp;&nbsp;&nbsp;以XMLDocument对象方式返回响应来验证金山通行证帐号是否存在；</B><BR><BR>首先，我们需要用JavaScript来创建XMLHttpRequest 类向服务器发送一个HTTP请求， XMLHttpRequest 类首先由Internet Explorer以ActiveX对象引入，被称为XMLHTTP。 后来Mozilla﹑Netscape﹑Safari 和其他浏览器也提供了XMLHttpRequest类，不过它们创建XMLHttpRequest类的方法不同。<BR><BR>对于Internet Explorer浏览器，创建XMLHttpRequest 方法如下：<BR><PRE class=CodeSamp>xmlhttp_request = new ActiveXObject("Msxml2.XMLHTTP.3.0"); //3.0或4.0, 5.0        
xmlhttp_request = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp_request = new ActiveXObject("Microsoft.XMLHTTP");
</PRE><BR>由于在不同Internet Explorer浏览器中XMLHTTP版本可能不一致，为了更好的兼容不同版本的Internet Explorer浏览器，因此我们需要根据不同版本的Internet Explorer浏览器来创建XMLHttpRequest类，上面代码就是根据不同的Internet Explorer浏览器创建XMLHttpRequest类的方法。<BR><BR>对于Mozilla﹑Netscape﹑Safari等浏览器，创建XMLHttpRequest 方法如下：<BR><PRE class=CodeSamp>                xmlhttp_request = new XMLHttpRequest();
</PRE><BR><BR>如果服务器的响应没有XML mime-type header，某些Mozilla浏览器可能无法正常工作。 为了解决这个问题，如果服务器响应的header不是text/xml，可以调用其它方法修改该header。<BR><BR><PRE class=CodeSamp>xmlhttp_request = new XMLHttpRequest();
xmlhttp_request.overrideMimeType('text/xml');
</PRE><BR><BR>在实际应用中，为了兼容多种不同版本的浏览器，一般将创建XMLHttpRequest类的方法写成如下形式：<BR><BR><PRE class=CodeSamp>    try{
        if( window.ActiveXObject ){
            for( var i = 5; i; i-- ){
                try{
                    if( i == 2 ){
xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP" );    
                    }else{
xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );	
                    }
xmlhttp_request.setRequestHeader("Content-Type","text/xml");
xmlhttp_request.setRequestHeader("Content-Type","gb2312");
break;}
                catch(e){                        
                    xmlhttp_request = false;
                }
            }
        }else if( window.XMLHttpRequest ){
            xmlhttp_request = new XMLHttpRequest();
            if (xmlhttp_request.overrideMimeType) {
                xmlhttp_request.overrideMimeType('text/xml');
            }
        }
    }catch(e){
        xmlhttp_request = false;
    }
</PRE><BR><BR>在定义了如何处理响应后，就要发送请求了。可以调用HTTP请求类的open()和send()方法，如下所示：<BR><BR><PRE class=CodeSamp>xmlhttp_request.open('GET', URL, true);
xmlhttp_request.send(null);
</PRE><BR><BR>open()的第一个参数是HTTP请求方式—GET，POST或任何服务器所支持的您想调用的方式。 按照HTTP规范，该参数要大写；否则，某些浏览器(如Firefox)可能无法处理请求。 <BR>第二个参数是请求页面的URL。<BR>第三个参数设置请求是否为异步模式。如果是TRUE，JavaScript函数将继续执行，而不等待服务器响应。这就是"AJAX"中的"A"。 <BR>　<BR>用JavaScript来创建XMLHttpRequest 类向服务器发送一个HTTP请求后，接下来要决定当收到服务器的响应后，需要做什么。这需要告诉HTTP请求对象用哪一个JavaScript函数处理这个响应。可以将对象的onreadystatechange属性设置为要使用的JavaScript的函数名，如下所示：<BR><BR><PRE class=CodeSamp>xmlhttp_request.onreadystatechange =FunctionName;
</PRE><BR><BR>FunctionName是用JavaScript创建的函数名，注意不要写成FunctionName()，当然我们也可以直接将JavaScript代码创建在onreadystatechange之后，例如：<BR><BR><PRE class=CodeSamp>xmlhttp_request.onreadystatechange = function(){
    // JavaScript代码段
};
</PRE><BR><BR>在这个函数中。首先要检查请求的状态。只有当一个完整的服务器响应已经收到了，函数才可以处理该响应。XMLHttpRequest 提供了readyState属性来对服务器响应进行判断。<BR><BR>readyState的取值如下： <BR>　　0 (未初始化) <BR>　　1 (正在装载) <BR>　　2 (装载完毕) <BR>　　3 (交互中) <BR>　　4 (完成)<BR><BR>所以只有当readyState=4时，一个完整的服务器响应已经收到了，函数才可以处理该响应。具体代码如下：<BR><BR><PRE class=CodeSamp>if (http_request.readyState == 4) {
    // 收到完整的服务器响应
} else {
    // 没有收到完整的服务器响应
}
</PRE><BR><BR>当readyState=4时，一个完整的服务器响应已经收到了，接着，函数会检查HTTP服务器响应的状态值。完整的状态取值可参见W3C文档。当HTTP服务器响应的值为200时，表示状态正常。<BR><BR>在检查完请求的状态值和响应的HTTP状态值后，就可以处理从服务器得到的数据了。有两种方式可以得到这些数据：<BR><BR><B>(1)&nbsp;&nbsp;&nbsp;&nbsp;以文本字符串的方式返回服务器的响应 </B><BR><B>(2)&nbsp;&nbsp;&nbsp;&nbsp;以XMLDocument对象方式返回响应</B> <BR><BR><B>实例一： 用文本字符串的方式返回服务器的响应来验证网易通行证帐号是否存在</B><BR><BR>首先，我们登陆网易通行证注册页面，可以看到检测用户名是否存在是将用户名提交给checkssn.jsp页面进行判断，格式为：<BR><A href="http://reg.163.com/register/checkssn.jsp?username" target=_blank><U><FONT color=#0000ff>reg.163.com/register/checkssn.jsp?username</FONT></U></A>=用户名 <BR><BR>根据上面讲到的方法，我们可以利用AJAX技术对网易通行证用户名进行检测：<BR><BR>第一步：新建一个基于Xhtml标准的网页，在&lt;head&gt;区域插入Javascript函数如下：<BR><BR><PRE class=CodeSamp>&lt;script type="text/javascript" language="javascript"&gt;
function getXMLRequester( ){
    var xmlhttp_request = false;
    try{
        if( window.ActiveXObject ){
            for( var i = 5; i; i-- ){
                try{
                    if( i == 2 ){
xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP" );    
                    }else{
xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );	
xmlhttp_request.setRequestHeader("Content-Type","text/xml");
xmlhttp_request.setRequestHeader("Content-Type","gb2312");
                 }
break;}
                catch(e){                        
                    xmlhttp_request = false;
                }
            }
        }else if( window.XMLHttpRequest ){
            xmlhttp_request = new XMLHttpRequest();
            if (xmlhttp_request.overrideMimeType) {
                xmlhttp_request.overrideMimeType('text/xml');
            }
        }
    }catch(e){
        xmlhttp_request = false;
    }
    return xmlhttp_request ;
}

    function IDRequest(n) {//定义收到服务器的响应后需要执行的JavaScript函数
url=n+document.getElementById('163id').value;//定义网址参数
        xmlhttp_request=getXMLRequester();//调用创建XMLHttpRequest的函数
        xmlhttp_request.onreadystatechange = doContents;//调用doContents函数
        xmlhttp_request.open('GET', url, true);
        xmlhttp_request.send(null);
    }
    function doContents() {
        if (xmlhttp_request.readyState == 4) {// 收到完整的服务器响应
            if (xmlhttp_request.status == 200) {//HTTP服务器响应的值OK
document.getElementById('message').innerHTML = xmlhttp_request.responseText;
//将服务器返回的字符串写到页面中ID为message的区域
            } else {
                alert(http_request.status);
            }
        }
    }
&lt;/script&gt;
</PRE><BR><BR>在&lt;body&gt;区域建立一个文本框，id为163id<BR><BR><PRE class=CodeSamp>&lt;input type="text" id="163id" onpropertychange="IDRequest('http://reg.163.com/register/checkssn.jsp?username=')" /&gt;
</PRE><BR><BR>再建一个id为messsge的空白区域用来显示返回字符串(也可以通过Javascript函数截取一部分字符串显示)：<BR><BR>&lt;div id="message"&gt;&lt;/div&gt;<BR><BR>这样，一个基于AJAX技术的用户名检测页面就做好了，不过这个页面将返回服务器响应生成页面的所有字符串，当然还可以对返回的字符串进行一些操作，便于应用到不同的需要当中。<BR><BR><B>实例二： 以XMLDocument对象方式返回响应来验证金山通行证帐号是否存在</B><BR><BR>在上面的例子中，当服务器对HTTP请求的响应被收到后，我们会调用请求对象的reponseText属性。该属性包含了服务器返回响应文件的内容。现在我们以XMLDocument对象方式返回响应，此时将不再需要reponseText属性而使用responseXML属性。<BR><BR>首先登陆金山通行证注册页面，我们发现金山通行证用户名的检测方式为：<BR><A href="http://pass.kingsoft.com/ksgweb/jsp/login/uid.jsp?uid=用户名,并且返回XML" target=_blank><U><FONT color=#0000ff>pass.kingsoft.com/ksgweb/jsp/login/uid.jsp?uid=用户名,并且返回XML</FONT></U></A>数据:<BR><PRE class=CodeSamp>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes" ?&gt; 
&lt;response&gt;
&lt;method&gt;isExistedUid&lt;/method&gt; 
&lt;result&gt;-2&lt;/result&gt; 
&lt;/response&gt;
</PRE><BR><BR>当result值为-1时表示此用户名已被注册，当result值为-2时表示此用户名尚未注册，因此通过对result值的判断可以知道用户名是否被注册。<BR><BR>对上例代码进行修改：<BR><BR>首先找到<BR><PRE class=CodeSamp>document.getElementById('message').innerHTML = xmlhttp_request.responseText;
</PRE><BR><BR>改为:<BR><BR><PRE class=CodeSamp>var response = xmlhttp_request.responseXML.documentElement;
var result = response.getElementsByTagName('result')[0].firstChild.data;//返回result节点数据
if(result ==-2){
document.getElementById('message').innerHTML = "用户名"+document.getElementById('163id').value+"尚未注册";
}
else if(result ==-1){
document.getElementById('message').innerHTML = "对不起,用户名"+document.getElementById('163id').value+"已经注册";
}
</PRE><BR><BR>通过以上两个实例说明了AJAX的客户端基础应用，采用的是网易和金山现成的服务器端程序，当然为了开发合适自己页面的程序，还需要对自己编写服务器端程序，这设计到程序语言及数据库的操作，对于有一定程序基础的读者一定不是很难的事情，本文着重讨论了客户端AJAX的应用体验，广大读者可以根据本文讲的原理结合各种样式表现手法作出绚丽多彩的应用，希望本文能够起到抛砖引玉的作用。<BR><BR><FONT color=#ff0000><B>演示地址:</B></FONT><BR><BR>网易通行证查询演示(AJAX): <A href="http://www.xiacong.com/test/163.htm" target=_blank><U><FONT color=#800080>www.xiacong.com/test/163.htm</FONT></U></A><BR>金山通行证查询演示(AJAX): <A href="http://www.xiacong.com/test/j3.htm" target=_blank><U><FONT color=#0000ff>www.xiacong.com/test/j3.htm</FONT></U></A><BR><BR><B>附录</B><BR><BR>(一) HTTP 1.1支持的状态代码<BR><BR>100 Continue 初始的请求已经接受，客户应当继续发送请求的其余部分<BR>101 Switching Protocols 服务器将遵从客户的请求转换到另外一种协议<BR>200 OK 一切正常，对GET和POST请求的应答文档跟在后面。<BR>201 Created 服务器已经创建了文档，Location头给出了它的URL。 <BR>202 Accepted 已经接受请求，但处理尚未完成。 <BR>203 Non-Authoritative Information 文档已经正常地返回，但一些应答头可能不正确，因为使用的是文档的拷贝 <BR>204 No Content 没有新文档，浏览器应该继续显示原来的文档。如果用户定期地刷新页面，而Servlet可以确定用户文档足够新，这个状态代码是很有用的<BR>205 Reset Content 没有新的内容，但浏览器应该重置它所显示的内容。用来强制浏览器清除表单输入内容<BR>206 Partial Content 客户发送了一个带有Range头的GET请求，服务器完成了它<BR>300 Multiple Choices 客户请求的文档可以在多个位置找到，这些位置已经在返回的文档内列出。如果服务器要提出优先选择，则应该在Location应答头指明。 <BR>301 Moved Permanently 客户请求的文档在其他地方，新的URL在Location头中给出，浏览器应该自动地访问新的URL。 <BR>302 Found 类似于301，但新的URL应该被视为临时性的替代，而不是永久性的。 <BR>303 See Other 类似于301/302，不同之处在于，如果原来的请求是POST，Location头指定的重定向目标文档应该通过GET提取<BR>304 Not Modified 客户端有缓冲的文档并发出了一个条件性的请求（一般是提供If-Modified-Since头表示客户只想比指定日期更新的文档）。服务器告诉客户，原来缓冲的文档还可以继续使用。 <BR>305 Use Proxy 客户请求的文档应该通过Location头所指明的代理服务器提取<BR>307 Temporary Redirect 和302（Found）相同。许多浏览器会错误地响应302应答进行重定向，即使原来的请求是POST，即使它实际上只能在POST请求的应答是303时才能重定向。由于这个原因，HTTP 1.1新增了307，以便更加清除地区分几个状态代码：当出现303应答时，浏览器可以跟随重定向的GET和POST请求；如果是307应答，则浏览器只能跟随对GET请求的重定向。 <BR>400 Bad Request 请求出现语法错误。 <BR>401 Unauthorized 客户试图未经授权访问受密码保护的页面。应答中会包含一个WWW-Authenticate头，浏览器据此显示用户名字/密码对话框，然后在填写合适的Authorization头后再次发出请求。 <BR>403 Forbidden 资源不可用。<BR>404 Not Found 无法找到指定位置的资源<BR>405 Method Not Allowed 请求方法（GET、POST、HEAD、DELETE、PUT、TRACE等）对指定的资源不适用。<BR>406 Not Acceptable 指定的资源已经找到，但它的MIME类型和客户在Accpet头中所指定的不兼容<BR>407 Proxy Authentication Required 类似于401，表示客户必须先经过代理服务器的授权。<BR>408 Request Timeout 在服务器许可的等待时间内，客户一直没有发出任何请求。客户可以在以后重复同一请求。 <BR>409 Conflict 通常和PUT请求有关。由于请求和资源的当前状态相冲突，因此请求不能成功。<BR>410 Gone 所请求的文档已经不再可用，而且服务器不知道应该重定向到哪一个地址。它和404的不同在于，返回407表示文档永久地离开了指定的位置，而404表示由于未知的原因文档不可用。 <BR>411 Length Required 服务器不能处理请求，除非客户发送一个Content-Length头。 <BR>412 Precondition Failed 请求头中指定的一些前提条件失败<BR>413 Request Entity Too Large 目标文档的大小超过服务器当前愿意处理的大小。如果服务器认为自己能够稍后再处理该请求，则应该提供一个Retry-After头 <BR>414 Request URI Too Long URI太长 <BR>416 Requested Range Not Satisfiable 服务器不能满足客户在请求中指定的Range头<BR>500 Internal Server Error 服务器遇到了意料不到的情况，不能完成客户的请求<BR>501 Not Implemented 服务器不支持实现请求所需要的功能。例如，客户发出了一个服务器不支持的PUT请求 <BR>502 Bad Gateway 服务器作为网关或者代理时，为了完成请求访问下一个服务器，但该服务器返回了非法的应答 <BR>503 Service Unavailable 服务器由于维护或者负载过重未能应答。例如，Servlet可能在数据库连接池已满的情况下返回503。服务器返回503时可以提供一个Retry-After头 <BR>504 Gateway Timeout 由作为代理或网关的服务器使用，表示不能及时地从远程服务器获得应答 <BR>505 HTTP Version Not Supported 服务器不支持请求中所指明的HTTP版本<BR><BR>(二) XMLHttpRequest 对象方法 <BR><BR><PRE class=CodeSamp>abort()		停止当前请求
getAllResponseHeaders()	作为字符串返问完整的headers
getResponseHeader("headerLabel")	作为字符串返问单个的header标签
open("method","URL"[,asyncFlag[,"userName"[, "password"]]])	设置未决的请求的目标 URL, 方法, 和其他参数
send(content)	发送请求
setRequestHeader("label", "value")		设置header并和请求一起发送
</PRE><BR><BR>(三) XMLHttpRequest 对象属性<BR><BR><PRE class=CodeSamp>onreadystatechange			状态改变的事件触发器
readyState				对象状态(integer):
				0 = 未初始化
				1 = 读取中
				2 = 已读取
				3 = 交互中
				4 = 完成
responseText		服务器进程返回数据的文本版本
responseXML		服务器进程返回数据的兼容DOM的XML文档对象
status			服务器返回的状态码, 如：404 = "文件末找到" 、200 ="成功"
statusText		服务器返回的状态文本信息</PRE><img src ="http://www.cnblogs.com/ltjabc/aggbug/292878.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42100/" target="_blank">[新闻]2008年9月5日科技博客精选</a>]]></description></item><item><title>Ajax资源列表 </title><link>http://www.cnblogs.com/ltjabc/archive/2005/10/26/262273.html</link><dc:creator>Liu</dc:creator><author>Liu</author><pubDate>Wed, 26 Oct 2005 02:39:00 GMT</pubDate><guid>http://www.cnblogs.com/ltjabc/archive/2005/10/26/262273.html</guid><wfw:comment>http://www.cnblogs.com/ltjabc/comments/262273.html</wfw:comment><comments>http://www.cnblogs.com/ltjabc/archive/2005/10/26/262273.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/ltjabc/comments/commentRss/262273.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/ltjabc/services/trackbacks/262273.html</trackback:ping><description><![CDATA[<DIV class=post>
<DIV class=posthead>
<H2><A class=singleposttitle id=viewpost1_TitleUrl href="/articles/262262.html">Ajax资源列表</A> </H2>Posted on 2005-10-26 10:29 <A href="http://ltjabc.cnblogs.com/">Liu</A> 阅读(1) <A href="http://ltjabc.cnblogs.com/articles/262262.html#Post">评论(0)</A> &nbsp;<A href="http://ltjabc.cnblogs.com/admin/EditArticles.aspx?postid=262262">编辑</A>&nbsp;<A href="http://ltjabc.cnblogs.com/AddToFavorite.aspx?id=262262">收藏</A> <A title=功能强大的网络收藏夹，一秒钟操作就可以轻松实现保存带来的价值、分享带来的快乐 href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();">收藏至365Key</A> <IMG height=1 src="/aggbug/262262.html?webview=1" width=1> <BR><BR><BR><A href="http://ajax.schwarz-interactive.de/csharpsample/default.aspx//">http://ajax.schwarz-interactive.de/csharpsample/default.aspx//</A>&nbsp; development of the Ajax.NET library&nbsp; for ASP.net<BR><BR><!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="http://ltjabc.cnblogs.com/articles/262262.html"
dc:identifier="http://ltjabc.cnblogs.com/articles/262262.html"
dc:title="Ajax资源列表"
trackback:ping="http://ltjabc.cnblogs.com/services/trackbacks/262262.aspx" />
</rdf:RDF>
--></DIV>
<DIV class=postbody>
<LI><A href="http://ltjabc.cnblogs.com/accesine960/archive/2005/04/05/337543.aspx"><FONT size=4></FONT></A>&nbsp; <FONT size=4><A href="http://www.dragonson.com/doc/ajax.html">http://www.dragonson.com/doc/ajax.html</A><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ajax内部交流文档</FONT> 
<P><FONT size=4><A href="http://info96.k12studio.com/~nio/comments.php?id=242_0_1_0_C">http://info96.k12studio.com/~nio/comments.php?id=242_0_1_0_C</A><BR>简单地对 Ajax 进行描述介绍</FONT> </P>
<LI><FONT size=4><A href="http://www.adaptivepath.com/publications/essays/archives/000385.php">http://www.adaptivepath.com/publications/essays/archives/000385.php</A><BR><B>Ajax: A New Approach to Web Applications</B></FONT> 
<P><FONT size=4><A href="http://jibbering.com/2002/4/httprequest.html">http://jibbering.com/2002/4/httprequest.html</A><BR>Using the XML HTTP Request object</FONT> </P>
<LI><FONT size=4><A href="http://ltjabc.cnblogs.com/accesine960/archive/2005/04/05/337543.aspx">小叮咚机器人Web版发布（体验使用Ajax）</A></FONT> 
<LI><FONT size=4><A href="http://developer.apple.com/internet/webcontent/xmlhttpreq.html">http://developer.apple.com/internet/webcontent/xmlhttpreq.html</A></FONT><FONT size=4><BR>Dynamic HTML and XML: The XMLHttpRequest Object</FONT> 
<P><FONT size=4><A href="http://del.icio.us/popular/ajax">http://del.icio.us/popular/ajax</A><BR>del.icio.us / popular / ajax</FONT> </P>
<LI><FONT size=4><A href="http://www.fiftyfoureleven.com/resources/programming/xmlhttprequest/examples">http://www.fiftyfoureleven.com/resources/programming/xmlhttprequest/examples</A><BR><B>XMLHttpRequest &amp; Ajax Working Examples</B></FONT> 
<P><FONT size=4><A href="http://www.xml.com/lpt/a/2005/02/09/xml-http-request.html">http://www.xml.com/lpt/a/2005/02/09/xml-http-request.html</A><BR>Very Dynamic Web Interfaces</FONT> </P>
<LI><FONT size=4><A href="http://www.standards-schmandards.com/index.php?2005/03/01/16-ajax-and-accessibility">http://www.standards-schmandards.com/index.php?2005/03/01/16-ajax-and-accessibility</A><BR>AJAX and Accessibility</FONT> 
<P><FONT size=4><A href="http://www.fayland.org/journal/Ajax_preview.html">http://www.fayland.org/journal/Ajax_preview.html</A></FONT> </P>
<LI><PRE><FONT size=4><TT><A href="https://bpcatalog.dev.java.net/nonav/ajax/ajax.html" target=_blank>https://bpcatalog.dev.java.net/nonav/ajax/ajax.html</A></TT></FONT></PRE>
<LI><PRE><FONT size=4><TT><A href="https://bpcatalog.dev.java.net/nonav/ajax/index.html" target=_blank>https://bpcatalog.dev.java.net/nonav/ajax/index.html</A></TT></FONT></PRE>
<LI><PRE><FONT size=4><TT><A href="http://www.theserverside.com/news/thread.tss?thread_id=33319" target=_blank>http://www.theserverside.com/news/thread.tss?thread_id=33319</A><BR></TT></FONT></PRE></LI></DIV></DIV><img src ="http://www.cnblogs.com/ltjabc/aggbug/262273.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42099/" target="_blank">[新闻]SNS网站风靡影响工作效率 公司下令封杀</a>]]></description></item><item><title>delegate FROM MSDN</title><link>http://www.cnblogs.com/ltjabc/archive/2005/08/23/220750.html</link><dc:creator>Liu</dc:creator><author>Liu</author><pubDate>Tue, 23 Aug 2005 02:52:00 GMT</pubDate><guid>http://www.cnblogs.com/ltjabc/archive/2005/08/23/220750.html</guid><wfw:comment>http://www.cnblogs.com/ltjabc/comments/220750.html</wfw:comment><comments>http://www.cnblogs.com/ltjabc/archive/2005/08/23/220750.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/ltjabc/comments/commentRss/220750.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/ltjabc/services/trackbacks/220750.html</trackback:ping><description><![CDATA[<P>&nbsp; //加重部分 定义代理<BR>using System;<BR>using System.Drawing;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Windows.Forms;<BR>using System.Data;</P>
<P>namespace Calculator<BR>{<BR>&nbsp;public class Form1 : System.Windows.Forms.Form<BR>&nbsp;{<BR>&nbsp;&nbsp;#region DETAILS...<BR>&nbsp;&nbsp;private System.Windows.Forms.Label label1;<BR>&nbsp;&nbsp;private System.Windows.Forms.Label label2;<BR>&nbsp;&nbsp;private System.Windows.Forms.TextBox txtNumber1;<BR>&nbsp;&nbsp;private System.Windows.Forms.Button cmdAdd;<BR>&nbsp;&nbsp;private System.Windows.Forms.TextBox txtNumber2;<BR>&nbsp;&nbsp;private System.Windows.Forms.Button cmdEnable;<BR>&nbsp;&nbsp;private System.Windows.Forms.Button cmdDisable;<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// Required designer variable.<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR><STRONG>&nbsp;<SPAN style="BACKGROUND-COLOR: yellow">&nbsp;private System.ComponentModel.Container components = null;</SPAN></STRONG></P>
<P>&nbsp;&nbsp;public Form1()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// Required for Windows Form Designer support<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;InitializeComponent();</P>
<P>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;&nbsp;// TODO: Add any constructor code after InitializeComponent call<BR>&nbsp;&nbsp;&nbsp;//<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// Clean up any resources being used.<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;protected override void Dispose( bool disposing )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if( disposing )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (components != null) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.Dispose();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;base.Dispose( disposing );<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;#region Windows Form Designer generated code<BR>&nbsp;&nbsp;/// &lt;summary&gt;<BR>&nbsp;&nbsp;/// Required method for Designer support - do not modify<BR>&nbsp;&nbsp;/// the contents of this method with the code editor.<BR>&nbsp;&nbsp;/// &lt;/summary&gt;<BR>&nbsp;&nbsp;private void InitializeComponent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.label1 = new System.Windows.Forms.Label();<BR>&nbsp;&nbsp;&nbsp;this.label2 = new System.Windows.Forms.Label();<BR>&nbsp;&nbsp;&nbsp;this.txtNumber1 = new System.Windows.Forms.TextBox();<BR>&nbsp;&nbsp;&nbsp;this.txtNumber2 = new System.Windows.Forms.TextBox();<BR>&nbsp;&nbsp;&nbsp;this.cmdAdd = new System.Windows.Forms.Button();<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable = new System.Windows.Forms.Button();<BR>&nbsp;&nbsp;&nbsp;this.cmdDisable = new System.Windows.Forms.Button();<BR>&nbsp;&nbsp;&nbsp;this.SuspendLayout();<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// label1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.label1.Location = new System.Drawing.Point(24, 24);<BR>&nbsp;&nbsp;&nbsp;this.label1.Name = "label1";<BR>&nbsp;&nbsp;&nbsp;this.label1.Size = new System.Drawing.Size(120, 32);<BR>&nbsp;&nbsp;&nbsp;this.label1.TabIndex = 0;<BR>&nbsp;&nbsp;&nbsp;this.label1.Text = "Number 1:";<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// label2<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.label2.Location = new System.Drawing.Point(24, 72);<BR>&nbsp;&nbsp;&nbsp;this.label2.Name = "label2";<BR>&nbsp;&nbsp;&nbsp;this.label2.Size = new System.Drawing.Size(120, 32);<BR>&nbsp;&nbsp;&nbsp;this.label2.TabIndex = 2;<BR>&nbsp;&nbsp;&nbsp;this.label2.Text = "Number 2:";<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// txtNumber1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.txtNumber1.Location = new System.Drawing.Point(152, 24);<BR>&nbsp;&nbsp;&nbsp;this.txtNumber1.Name = "txtNumber1";<BR>&nbsp;&nbsp;&nbsp;this.txtNumber1.Size = new System.Drawing.Size(160, 29);<BR>&nbsp;&nbsp;&nbsp;this.txtNumber1.TabIndex = 1;<BR>&nbsp;&nbsp;&nbsp;this.txtNumber1.Text = "";<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// txtNumber2<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.txtNumber2.Location = new System.Drawing.Point(152, 72);<BR>&nbsp;&nbsp;&nbsp;this.txtNumber2.Name = "txtNumber2";<BR>&nbsp;&nbsp;&nbsp;this.txtNumber2.Size = new System.Drawing.Size(160, 29);<BR>&nbsp;&nbsp;&nbsp;this.txtNumber2.TabIndex = 3;<BR>&nbsp;&nbsp;&nbsp;this.txtNumber2.Text = "";<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// cmdAdd<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.cmdAdd.Location = new System.Drawing.Point(168, 120);<BR>&nbsp;&nbsp;&nbsp;this.cmdAdd.Name = "cmdAdd";<BR>&nbsp;&nbsp;&nbsp;this.cmdAdd.Size = new System.Drawing.Size(128, 56);<BR>&nbsp;&nbsp;&nbsp;this.cmdAdd.TabIndex = 4;<BR>&nbsp;&nbsp;&nbsp;this.cmdAdd.Text = "Add";<BR>&nbsp;&nbsp;&nbsp;this.cmdAdd.Click += new System.EventHandler(this.cmdAdd_Click);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// cmdEnable<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.CausesValidation = false;<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.Location = new System.Drawing.Point(24, 280);<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.Name = "cmdEnable";<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.Size = new System.Drawing.Size(272, 48);<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.TabIndex = 6;<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.TabStop = false;<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.Text = "Enable Validation";<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.Click += new System.EventHandler(this.cmdEnable_Click);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// cmdDisable<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.cmdDisable.CausesValidation = false;<BR>&nbsp;&nbsp;&nbsp;this.cmdDisable.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));<BR>&nbsp;&nbsp;&nbsp;this.cmdDisable.Location = new System.Drawing.Point(24, 216);<BR>&nbsp;&nbsp;&nbsp;this.cmdDisable.Name = "cmdDisable";<BR>&nbsp;&nbsp;&nbsp;this.cmdDisable.Size = new System.Drawing.Size(272, 48);<BR>&nbsp;&nbsp;&nbsp;this.cmdDisable.TabIndex = 5;<BR>&nbsp;&nbsp;&nbsp;this.cmdDisable.TabStop = false;<BR>&nbsp;&nbsp;&nbsp;this.cmdDisable.Text = "Disable Validation";<BR>&nbsp;&nbsp;&nbsp;this.cmdDisable.Click += new System.EventHandler(this.cmdDisable_Click);<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;// Form1<BR>&nbsp;&nbsp;&nbsp;// <BR>&nbsp;&nbsp;&nbsp;this.AutoScaleBaseSize = new System.Drawing.Size(10, 22);<BR>&nbsp;&nbsp;&nbsp;this.ClientSize = new System.Drawing.Size(338, 352);<BR>&nbsp;&nbsp;&nbsp;this.Controls.AddRange(new System.Windows.Forms.Control[] {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.cmdDisable,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.cmdEnable,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.cmdAdd,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.txtNumber2,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.txtNumber1,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.label2,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.label1});<BR>&nbsp;&nbsp;&nbsp;this.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));<BR>&nbsp;&nbsp;&nbsp;this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;<BR>&nbsp;&nbsp;&nbsp;this.MaximizeBox = false;<BR>&nbsp;&nbsp;&nbsp;this.Name = "Form1";<BR>&nbsp;&nbsp;&nbsp;this.Text = "Calculator";<BR>&nbsp;&nbsp;&nbsp;this.Load += new System.EventHandler(this.Form1_Load);<BR>&nbsp;&nbsp;&nbsp;this.ResumeLayout(false);</P>
<P>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;#endregion</P>
<P>&nbsp;&nbsp;[STAThread]<BR>&nbsp;&nbsp;static void Main() <BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Application.Run(new Form1());<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void cmdAdd_Click(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;int&nbsp; num1, num2, result;</P>
<P>&nbsp;&nbsp;&nbsp;num1 = int.Parse(this.txtNumber1.Text);<BR>&nbsp;&nbsp;&nbsp;num2 = int.Parse(this.txtNumber2.Text);</P>
<P>&nbsp;&nbsp;&nbsp;result = num1 + num2;</P>
<P>&nbsp;&nbsp;&nbsp;MessageBox.Show("The sum = " + result, "Calculator");<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void Form1_Load(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;<STRONG style="BACKGROUND-COLOR: yellow">this.txtNumber1.Validating += new System.ComponentModel.CancelEventHandler(Validation.IsInteger);<BR>&nbsp;&nbsp;&nbsp;this.txtNumber2.Validating += new System.ComponentModel.CancelEventHandler(Validation.IsInteger);</STRONG></P>
<P>&nbsp;&nbsp;&nbsp;// validation is already enabled, so prevent user from adding more validation handlers<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.Enabled = false;&nbsp; <BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void cmdDisable_Click(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.txtNumber1.Validating -= new System.ComponentModel.CancelEventHandler(Validation.IsInteger);<BR>&nbsp;&nbsp;&nbsp;this.txtNumber2.Validating -= new System.ComponentModel.CancelEventHandler(Validation.IsInteger);</P>
<P>&nbsp;&nbsp;&nbsp;// toggle buttons so user can enable later...<BR>&nbsp;&nbsp;&nbsp;this.cmdDisable.Enabled = false;<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.Enabled&nbsp; = true;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;private void cmdEnable_Click(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;this.txtNumber1.Validating += new System.ComponentModel.CancelEventHandler(Validation.IsInteger);<BR>&nbsp;&nbsp;&nbsp;this.txtNumber2.Validating += new System.ComponentModel.CancelEventHandler(Validation.IsInteger);</P>
<P>&nbsp;&nbsp;&nbsp;// toggle buttons so user can disable later...<BR>&nbsp;&nbsp;&nbsp;this.cmdEnable.Enabled&nbsp; = false;<BR>&nbsp;&nbsp;&nbsp;this.cmdDisable.Enabled = true;<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;}<BR>}<BR><BR>//定义代理函数<BR>using System;<BR>using SWF = System.Windows.Forms;</P>
<P>namespace Calculator<BR>{</P>
<P>&nbsp;public class Validation<BR>&nbsp;{</P>
<P>&nbsp;&nbsp;public static void IsInteger(object sender, System.ComponentModel.CancelEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;SWF.TextBox&nbsp; txt;<BR>&nbsp;&nbsp;&nbsp;txt = (SWF.TextBox) sender;</P>
<P>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;int.Parse(txt.Text);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch(FormatException)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;SWF.MessageBox.Show("Please enter a numeric value.", "Calculator");<BR>&nbsp;&nbsp;&nbsp;&nbsp;e.Cancel = true;&nbsp; // cancel validation, returns focus<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch(OverflowException)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;SWF.MessageBox.Show("Please enter an integer in the range " + int.MinValue + " ... " + int.MaxValue, "Calculator");<BR>&nbsp;&nbsp;&nbsp;&nbsp;e.Cancel = true;&nbsp; // cancel validation, returns focus<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch(Exception ex)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;SWF.MessageBox.Show("Unknown error: " + ex.Message, "Calculator");<BR>&nbsp;&nbsp;&nbsp;&nbsp;e.Cancel = true;&nbsp; // cancel validation, returns focus<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;<BR>&nbsp;}//class<BR>}//namespace<BR></P><img src ="http://www.cnblogs.com/ltjabc/aggbug/220750.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42098/" target="_blank">[新闻]《孢子》正式发布</a>]]></description></item><item><title>为DataGrid行添加事件</title><link>http://www.cnblogs.com/ltjabc/archive/2005/08/14/214647.html</link><dc:creator>Liu</dc:creator><author>Liu</author><pubDate>Sun, 14 Aug 2005 05:34:00 GMT</pubDate><guid>http://www.cnblogs.com/ltjabc/archive/2005/08/14/214647.html</guid><wfw:comment>http://www.cnblogs.com/ltjabc/comments/214647.html</wfw:comment><comments>http://www.cnblogs.com/ltjabc/archive/2005/08/14/214647.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/ltjabc/comments/commentRss/214647.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/ltjabc/services/trackbacks/214647.html</trackback:ping><description><![CDATA[<P>private void grid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(e.Item.ItemType != ListItemType.Header &amp;&amp; e.Item.ItemType != ListItemType.Footer )<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;e.Item.Attributes.Add("onmouseover","this.setAttribute('BKC',this.style.backgroundColor);this.style.backgroundColor='#FF0000'");<BR>&nbsp;&nbsp;&nbsp;&nbsp;e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('BKC');");</P>
<P><BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;}<BR><BR><BR><SPAN style="COLOR: #000000">private&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;OnItemDataBound(object&nbsp;sender,&nbsp;System.Web.UI.WebControls.DataGridItemEventArgs&nbsp;e)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(e.Item.ItemType&nbsp;</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">&nbsp;ListItemType.Header&nbsp;</SPAN><SPAN style="COLOR: #000000">&amp;&amp;</SPAN><SPAN style="COLOR: #000000">&nbsp;e.Item.ItemType&nbsp;</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">&nbsp;ListItemType.Footer&nbsp;)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LinkButton&nbsp;btnSave&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(LinkButton)e.Item.Cells[</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">].Controls[</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">];<BR>　　&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;strClientID&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;btnSave.ClientID;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">得到该控件的客户端ID，可供JavaScript调用</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btnSave.Attributes.Add(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">onclick</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Javascript:return&nbsp;confirm('Are&nbsp;you&nbsp;sure&nbsp;to&nbsp;save?');</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>}</SPAN></P><img src ="http://www.cnblogs.com/ltjabc/aggbug/214647.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42097/" target="_blank">[新闻]微软CFO:仍对收购雅虎搜索业务感兴趣</a>]]></description></item><item><title>Observer 模式 From MSDN</title><link>http://www.cnblogs.com/ltjabc/archive/2005/08/08/209731.html</link><dc:creator>Liu</dc:creator><author>Liu</author><pubDate>Mon, 08 Aug 2005 02:06:00 GMT</pubDate><guid>http://www.cnblogs.com/ltjabc/archive/2005/08/08/209731.html</guid><wfw:comment>http://www.cnblogs.com/ltjabc/comments/209731.html</wfw:comment><comments>http://www.cnblogs.com/ltjabc/archive/2005/08/08/209731.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/ltjabc/comments/commentRss/209731.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/ltjabc/services/trackbacks/209731.html</trackback:ping><description><![CDATA[<DIV>
<DIV class=text4>Observer模式简介</DIV>
<DIV class=text4>为了让更多的人能够看明白本文，所以在此之前，我们先来了解一下Observer模式的基本概念。</DIV>
<DIV class=text4><B>模式名称：Observer </B></DIV>
<DIV class=text4><B>结构图： </B></DIV>
<DIV><SPAN class=text6><IMG height=252 hspace=5 src="http://www.cnblogs.com/images/cnblogs_com/ltjabc/68-1.gif" width=637 align=baseline></SPAN></DIV>
<DIV class=text4><B>意图：</B></DIV>
<DIV class=text4>定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时, 所有依赖于它的对象都得到通知并被自动更新。</DIV>
<DIV class=text4><B>适用性：</B></DIV>
<DIV class=text4>当一个抽象模型有两个方面, 其中一个方面依赖于另一方面。将这二者封装在独立的对象中以使它们可以各自独立地改变和复用。 </DIV>
<DIV class=text4>当对一个对象的改变需要同时改变其它对象, 而不知道具体有多少对象有待改变。 </DIV>
<DIV class=text4>当一个对象必须通知其它对象，而它又不能假定其它对象是谁。换言之, 你不希望这些对象是紧密耦合的。 </DIV>
<DIV class=text4>应用实例</DIV>
<DIV class=text4>在编写多层应用程序时，我们通常将表示层和数据逻辑层分隔开，比如很常见的View/Document结构，这种设计方式的好处带来的结果通常是使用多视图同时表示单一数据源，比如一个Web网站可以方便的同时拥有针对电脑的Html页面和针对手机的WAP页面。使用这种结构时，为了保持数据显示的一致性，必须要求数据源在数据发生改变时能及时的逐一通知每一个和它绑定的表示层进行更新。但是问题在于数据层本身并不知道到底有多少个不同的表示层正在反映着它的数据内容。因此需要设计一套有效的机制来完成这个目标。</DIV>
<DIV class=text4>模式实现</DIV>
<DIV class=text4>我们先看看来自《设计模式迷你手册》的常规的C#实现代码。</DIV>
<DIV class=text4><B>Subject(抽象目标）：</B></DIV>
<DIV class=text4>目标知道它的观察者。可以有任意多个观察者观察同一个目标。</DIV>
<DIV style="BACKGROUND-COLOR: #eeeeee"><PRE class=text5>//实现代码
class Subject
{
	//由于不知道有多少个观察者，所以建立了一个观察者链表 
	private ArrayList list = new ArrayList();
	private string strImportantSubjectData = "Initial";
	public string ImportantSubjectData 
	{
		get 
		{
		return strImportantSubjectData;
		}
		set 
		{
		strImportantSubjectData = value;
		}
	}
	public void Attach(Observer o)
	{
	list.Add(o);
	o.ObservedSubject = this;
	}
	public void Detach(Observer o)
	{
	}
	public void Notify()
	{
		//在数据发生改变后遍历列表通知观察者
		foreach (Observer o in list) 
		{
			o.Update();
		}
	}
}
</PRE></DIV>
<DIV class=text4><B>Observer(抽象观察者）：</B></DIV>
<DIV class=text4>为那些在目标发生改变时需要获得通知的对象定义一个更新接口。</DIV>
<DIV style="BACKGROUND-COLOR: #eeeeee"><PRE class=text5>abstract class Observer 
{
//内置一个需要观察的对象 
protected Subject s;
public Subject ObservedSubject 
{
	get 
	{
	return s; 
	}
	set 
	{
	s = value;
	}
} 
abstract public void Update();
}
</PRE></DIV>
<DIV class=text4><B>ConcreteSubject（实体目标，在这里相当于数据逻辑层）：</B></DIV>
<DIV class=text4>将有关状态存入各ConcreteSubject对象。</DIV>
<DIV class=text4>当它的状态发生改变时，向它的各个观察者发出通知。</DIV>
<DIV style="BACKGROUND-COLOR: #eeeeee"><PRE class=text5>//在这里基本上什么都没有做，数据的获取可以放到GetState()里面
class ConcreteSubject : Subject
{
	public void GetState()
	{
	}
	public void SetState()
	{
	} 
}
</PRE></DIV>
<DIV class=text4><B>ConcreteObserver(实体观察者，在这里就相当于表示层)：</B></DIV>
<DIV class=text4>维护一个指向ConcreteSubject的引用。</DIV>
<DIV class=text4>储存有关状态，这些状态应与目标的状态保持一致。</DIV>
<DIV class=text4>实现Observer的更新接口以使自身状态与目标状态保持一致。</DIV>
<DIV style="BACKGROUND-COLOR: #eeeeee"><PRE class=text5>class ConcreteObserver : Observer 
{
	private string observerName;
	public ConcreteObserver(string name)
	{
	observerName = name;
	}
	override public void Update()
	{
	//将数据显示出来 
	Console.WriteLine("In Observer {0}: data from subject = {1}", 
	observerName, s.ImportantSubjectData);
	} 
}
</PRE></DIV>
<DIV class=text4><B>主函数：</B></DIV>
<DIV style="BACKGROUND-COLOR: #eeeeee"><PRE class=text5>public class Client
{ 
	public static int Main(string[] args)
	{ 
	ConcreteSubject s = new ConcreteSubject();
	ConcreteObserver o1 = new ConcreteObserver("first observer");
	ConcreteObserver o2 = new ConcreteObserver("second observer");
	//注册观察者
	s.Attach(o1);
	s.Attach(o2);
	s. ImportantSubjectData = "This is important subject data";
	s.Notify(); 
	return 0;
	}
}
</PRE></DIV>
<DIV class=text4>模式分析</DIV>
<DIV class=text4>Observer模式的优点是实现了表示层和数据逻辑层的分离，并定义了稳定的更新消息传递机制，类别清晰，并抽象了更新接口，使得可以有各种各样不同的表示层（观察者）。但是其缺点是每个外观对象必须继承这个抽像出来的接口类，这样就造成了一些不方便，比如有一个别人写的外观对象，并没有继承该抽象类，或者接口不对，我们又希望不修改该类直接使用它。虽然可以再应用Adapter模式来一定程度上解决这个问题，但是会造成更加复杂烦琐的设计，增加出错几率。</DIV>
<DIV class=text4>C#作为一种先进的现代面向对象语言，不但吸收了许多语言的精华，并创造了一些非常有用的新特性。在学习了C#语言之后，我发现利用C#独有的Delegate可以来较好的解决这个问题。</DIV>
<DIV class=text4>改进后的Observer模式实现</DIV>
<DIV class=text4>先定义一个Delegate:</DIV>
<DIV style="BACKGROUND-COLOR: #eeeeee"><PRE class=text5>delegate void UpdateDelegate(string SubjectData); 
</PRE></DIV>
<DIV class=text4><B>Subject(抽象目标）：</B></DIV>
<DIV style="BACKGROUND-COLOR: #eeeeee"><PRE class=text5>class Subject
{
	private string strImportantSubjectData = "Initial";
	//定义一个事件容器，代替前面的观察者对象列表
	public event UpdateDelegate UpdateHandle;
	public string ImportantSubjectData 
	{
	get 
	{
	return strImportantSubjectData;
	}
	set 
	{
	strImportantSubjectData = value;
	}
	}
	public void Notify()
	{
	//发出事件 
	if(UpdateHandle != null) UpdateHandle(strImportantSubjectData);
	}
}
</PRE></DIV>
<DIV class=text4><B>Observer(抽象观察者）：</B></DIV>
<DIV class=text4>无，因为不需要抽象接口类了，所以可以省去抽象观察者类。</DIV>
<DIV class=text4><B>ConcreteSubject（实体目标）：</B></DIV>
<DIV style="BACKGROUND-COLOR: #eeeeee"><PRE class=text5>//没有任何改变 
class ConcreteSubject : Subject
{
	public void GetState()
	{
	}
	public void SetState()
	{
	} 
}
</PRE></DIV>
<DIV class=text4><B>ConcreteObserver(实体观察者)：</B></DIV>
<DIV style="BACKGROUND-COLOR: #eeeeee"><PRE class=text5>//为了能更加清楚的说明问题，这里定义了两个实体观察者，注意，它们之间并没有任何关系
class Observer1
{
	private string observerName;
	public Observer1(string name)
	{
		observerName = name;
	}
	public void Update1(string ImportantSubjectData)
	{
		Console.WriteLine("In Observer {0}: data from subject = {1}", 
		observerName, ImportantSubjectData);
	} 
}
class Observer2
{
	private string observerName;
	public Observer2(string name)
	{
		observerName = name;
	}
	public void Update2(string ImportantSubjectData)
	{
		Console.WriteLine("In Observer {0}: data from subject = {1}", 
		observerName, ImportantSubjectData);
	} 
}
</PRE></DIV>
<DIV class=text4><B>主函数：</B></DIV>
<DIV style="BACKGROUND-COLOR: #eeeeee"><PRE class=text5>public class Client
{ 
	public static int Main(string[] args)
	{ 
	ConcreteSubject s = new ConcreteSubject();
	Observer1 o1 = new Observer1("first observer");
	Observer2 o2 = new Observer2("second observer");
	//向目标注册对象两个观察者，请注意，这里仅仅只是添加了两个方法，
	//不需要关心方法从何而来，也不需要关心目标类如何去调用他们。
	s.UpdateHandle += new UpdateDelegate(o1.Update1);
	s.UpdateHandle += new UpdateDelegate(o2.Update2);
	s.ImportantSubjectData = "This is important subject data";
	s.Notify();
	return 0;
	}
}
</PRE></DIV>
<DIV class=text4>在这段代码里，没有看到链表，没有看到遍历操作，没有看到更新的方法是如何被调用，甚至没有看到那些被联系到一起的类的抽象类和抽象接口，但是目标对象却能将数据更新信息逐一发送到每个观察者对象，并且还能更加容易的增加新的不同的观察者对象，根本不需要知道它从何处继承而来，也不需要统一他们的接口调用方法。这一切都归功于灵活强大的C#。</DIV>
<DIV class=text4>完整的源码</DIV>
<DIV class=text4>以下是完整的源码：</DIV>
<DIV style="BACKGROUND-COLOR: #eeeeee"><PRE class=text5>namespace Observer_DesignPattern
{
	using System;
	delegate void UpdateDelegate(string SubjectData);
	class Subject
	{
		private string strImportantSubjectData = "Initial";
		public event UpdateDelegate UpdateHandle;
		public string ImportantSubjectData 
		{
			get 
			{
			return strImportantSubjectData;
			}
			set 
			{
			strImportantSubjectData = value;
			}
		}
		public void Notify()
		{
		if(UpdateHandle != null) UpdateHandle(strImportantSubjectData);
		}
	}
	class ConcreteSubject : Subject
	{
		public void GetState()
		{
		}
		public void SetState()
		{
		} 
	}
	class Observer1
	{
		private string observerName;
		public Observer1(string name)
		{
			observerName = name;
		}
		public void Update1(string ImportantSubjectData)
		{
			Console.WriteLine("In Observer {0}: data from subject = {1}", 
			observerName, ImportantSubjectData);
		} 
	}
	class Observer2
	{
		private string observerName;
		public Observer2(string name)
		{
			observerName = name;
		}
		public void Update2(string ImportantSubjectData)
		{
			Console.WriteLine("In Observer {0}: data from subject = {1}", 
			observerName, ImportantSubjectData);
		} 
	}
	public class Client
	{ 
		public static int Main(string[] args)
		{ 
			ConcreteSubject s = new ConcreteSubject();
			Observer1 o1 = new Observer1("first observer");
			Observer2 o2 = new Observer2("second observer");
			s.UpdateHandle += new UpdateDelegate(o1.Update1);
			s.UpdateHandle += new UpdateDelegate(o2.Update2);
			s.ImportantSubjectData = "This is important subject data";
			s.Notify();
			return 0;
		}
	}
}
</PRE></DIV></DIV><img src ="http://www.cnblogs.com/ltjabc/aggbug/209731.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42095/" target="_blank">[新闻]SQL Server2008十月亮相 标榜智能数据平台</a>]]></description></item><item><title>控件继承</title><link>http://www.cnblogs.com/ltjabc/archive/2005/08/06/208843.html</link><dc:creator>Liu</dc:creator><author>Liu</author><pubDate>Sat, 06 Aug 2005 05:32:00 GMT</pubDate><guid>http://www.cnblogs.com/ltjabc/archive/2005/08/06/208843.html</guid><wfw:comment>http://www.cnblogs.com/ltjabc/comments/208843.html</wfw:comment><comments>http://www.cnblogs.com/ltjabc/archive/2005/08/06/208843.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/ltjabc/comments/commentRss/208843.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/ltjabc/services/trackbacks/208843.html</trackback:ping><description><![CDATA[<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000">&nbsp;System;<BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000">&nbsp;System.Windows.Forms;<BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">namespace</SPAN><SPAN style="COLOR: #000000">&nbsp;Northwind<BR><IMG id=Codehighlighter1_63_360_Open_Image onclick="this.style.display='none'; Codehighlighter1_63_360_Open_Text.style.display='none'; Codehighlighter1_63_360_Closed_Image.style.display='inline'; Codehighlighter1_63_360_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_63_360_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_63_360_Closed_Text.style.display='none'; Codehighlighter1_63_360_Open_Image.style.display='inline'; Codehighlighter1_63_360_Open_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_63_360_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_63_360_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_66_140_Open_Image onclick="this.style.display='none'; Codehighlighter1_66_140_Open_Text.style.display='none'; Codehighlighter1_66_140_Closed_Image.style.display='inline'; Codehighlighter1_66_140_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_66_140_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_66_140_Closed_Text.style.display='none'; Codehighlighter1_66_140_Open_Image.style.display='inline'; Codehighlighter1_66_140_Open_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_66_140_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_66_140_Open_Text><SPAN style="COLOR: #808080">///</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #808080">&lt;summary&gt;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #808080">///</SPAN><SPAN style="COLOR: #008000">&nbsp;Summary&nbsp;description&nbsp;for&nbsp;NumericTextBox.<BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #808080">///</SPAN><SPAN style="COLOR: #008000">&nbsp;</SPAN><SPAN style="COLOR: #808080">&lt;/summary&gt;</SPAN><SPAN style="COLOR: #808080"></SPAN></SPAN><BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;NumericTextBox&nbsp;&nbsp;:&nbsp;TextBox<BR><IMG id=Codehighlighter1_182_358_Open_Image onclick="this.style.display='none'; Codehighlighter1_182_358_Open_Text.style.display='none'; Codehighlighter1_182_358_Closed_Image.style.display='inline'; Codehighlighter1_182_358_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_182_358_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_182_358_Closed_Text.style.display='none'; Codehighlighter1_182_358_Open_Image.style.display='inline'; Codehighlighter1_182_358_Open_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_182_358_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_182_358_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;NumericTextBox()<BR><IMG id=Codehighlighter1_212_220_Open_Image onclick="this.style.display='none'; Codehighlighter1_212_220_Open_Text.style.display='none'; Codehighlighter1_212_220_Closed_Image.style.display='inline'; Codehighlighter1_212_220_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_212_220_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_212_220_Closed_Text.style.display='none'; Codehighlighter1_212_220_Open_Image.style.display='inline'; Codehighlighter1_212_220_Open_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_212_220_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_212_220_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">protected</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">override</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;OnKeyPress(KeyPressEventArgs&nbsp;e)<BR><IMG id=Codehighlighter1_285_354_Open_Image onclick="this.style.display='none'; Codehighlighter1_285_354_Open_Text.style.display='none'; Codehighlighter1_285_354_Closed_Image.style.display='inline'; Codehighlighter1_285_354_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_285_354_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_285_354_Closed_Text.style.display='none'; Codehighlighter1_285_354_Open_Image.style.display='inline'; Codehighlighter1_285_354_Open_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_285_354_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_285_354_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #000000">!</SPAN><SPAN style="COLOR: #0000ff">char</SPAN><SPAN style="COLOR: #000000">.IsDigit(e.KeyChar))<BR><IMG id=Codehighlighter1_323_350_Open_Image onclick="this.style.display='none'; Codehighlighter1_323_350_Open_Text.style.display='none'; Codehighlighter1_323_350_Closed_Image.style.display='inline'; Codehighlighter1_323_350_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_323_350_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_323_350_Closed_Text.style.display='none'; Codehighlighter1_323_350_Open_Image.style.display='inline'; Codehighlighter1_323_350_Open_Text.style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_323_350_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_323_350_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Handled&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV><BR>使用该继承的控件,可以实现只允许输入数字.<img src ="http://www.cnblogs.com/ltjabc/aggbug/208843.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42091/" target="_blank">[新闻]淘宝将与阿里妈妈合并 大淘宝战略启动</a>]]></description></item></channel></rss>