﻿<?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>BlogJava-&lt;h1&gt;编程之道&lt;/h1&gt;-随笔分类-项目</title><link>http://www.blogjava.net/yuanhuaming/category/2649.html</link><description>无论是批评的，赞扬的，指着的都请EMAIL给我，你的建议将是我前进的动力!   &lt;A href=mailto:yuanhuaming@56.com &gt;联系我&lt;/A&gt;</description><language>zh-cn</language><lastBuildDate>Fri, 02 Mar 2007 07:42:02 GMT</lastBuildDate><pubDate>Fri, 02 Mar 2007 07:42:02 GMT</pubDate><ttl>60</ttl><item><title>写程序的时候需要注意的地方。</title><link>http://www.blogjava.net/yuanhuaming/archive/2006/09/27/72195.html</link><dc:creator>疯流成性</dc:creator><author>疯流成性</author><pubDate>Wed, 27 Sep 2006 02:03:00 GMT</pubDate><guid>http://www.blogjava.net/yuanhuaming/archive/2006/09/27/72195.html</guid><wfw:comment>http://www.blogjava.net/yuanhuaming/comments/72195.html</wfw:comment><comments>http://www.blogjava.net/yuanhuaming/archive/2006/09/27/72195.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yuanhuaming/comments/commentRss/72195.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yuanhuaming/services/trackbacks/72195.html</trackback:ping><description><![CDATA[
		<ol>
				<li>异常捕获（包括IO异常，DB异常，主要注意的就这2个异常）</li>
				<li>类型转换（在开发的时候如果不注意，后期很难发现。比如字符串和数字型的比较，如果字符串是数字OK，但是也可能是字母，那么肯定会抱错）</li>
				<li>对象的释放。有些语言已经不需要考虑的问题，不过在意识上要有这个概念。</li>
				<li>在一个方法里面实现一个功能，不要同时做N多事情。好处多多，对我来说主要是方便测试，单功能扩展重用都比较方便。</li>
				<li>注释。项目比较紧时候可能会忽略注释，但是再怎么忙，每个方法的功能，返回值，参数必须准确无误。</li>
				<li>字符转义。这问题我想碰到过1~2次就终身难忘了吧。</li>
		</ol>
		<p>
				<br />        写代码的时候应该时时考虑以上几点，后期考虑的话很容易把代码改错，该乱，造成进度上的紧张，所以强烈建议写代码时候注意。</p>
<img src ="http://www.blogjava.net/yuanhuaming/aggbug/72195.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yuanhuaming/" target="_blank">疯流成性</a> 2006-09-27 10:03 <a href="http://www.blogjava.net/yuanhuaming/archive/2006/09/27/72195.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>log,exception最佳实践 </title><link>http://www.blogjava.net/yuanhuaming/archive/2006/02/24/32330.html</link><dc:creator>疯流成性</dc:creator><author>疯流成性</author><pubDate>Fri, 24 Feb 2006 09:52:00 GMT</pubDate><guid>http://www.blogjava.net/yuanhuaming/archive/2006/02/24/32330.html</guid><wfw:comment>http://www.blogjava.net/yuanhuaming/comments/32330.html</wfw:comment><comments>http://www.blogjava.net/yuanhuaming/archive/2006/02/24/32330.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yuanhuaming/comments/commentRss/32330.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yuanhuaming/services/trackbacks/32330.html</trackback:ping><description><![CDATA[<STRONG><FONT size=6>1 <SPAN lang=EN-US>log</SPAN></FONT></STRONG>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>1.1 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>log.error</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">表示系统级错误</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>1.2 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>log.warn</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">表示应用级错误</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><o:p></o:p></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>1.3 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">服务初始化或结束用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>log.info<o:p></o:p></FONT></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>1.4 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>log.debug</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">替代</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>out</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>debug</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">要判断</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>isDebugEnable<o:p></o:p></FONT></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>1.5 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>log.warn("",e)</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">替代</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>e.printstack<o:p></o:p></FONT></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>1.6 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>log4e</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">生成</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>log</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">相关代码</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><o:p></o:p></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><FONT face=Arial><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore">1.7 </SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%">Log</SPAN></FONT><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">信息要保证可读性，需记录现场信息，如当前处理</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>id</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">等</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><o:p></o:p></SPAN></STRONG></P>
<P class=MMTopic1 style="MARGIN: 17pt 0cm 16.5pt; TEXT-INDENT: 0cm"><FONT size=6><STRONG><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">2 </SPAN></SPAN><SPAN lang=EN-US>exception</SPAN></STRONG></FONT></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><FONT face=Arial><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore">2.1 </SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%">try catch</SPAN></FONT><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">内的代码不要太长</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><o:p></o:p></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>2.2 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">因为性能原因，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>try catch</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">少放循环内</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><o:p></o:p></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>2.3 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">尽量避免</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>catch(Exception)</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">这样的写法</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><o:p></o:p></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>2.4 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">不同模块定义不同的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>exception<o:p></o:p></FONT></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>2.5 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">建议创建应用的基类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>exception</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">，特别是有定义</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>error code</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">需要的应用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><o:p></o:p></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>2.6 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">只要</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>catch</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">就要</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>log error message<o:p></o:p></FONT></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><FONT face=Arial><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore">2.7 </SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%">catch</SPAN></FONT><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">并封装成另一种</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>exception</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">，如果不</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>nest</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">原来的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>exception</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">就要</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>log stackTrace<o:p></o:p></FONT></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>2.8 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">持久层</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>throw dataAccessException</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">，业务层</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>throw checked exception</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">，展现层只显示</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>exception</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">信息</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><o:p></o:p></SPAN></STRONG></P>
<P class=MMTopic2 style="MARGIN: 13pt 0cm; TEXT-INDENT: 0cm"><STRONG><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"><SPAN style="mso-list: Ignore"><FONT face=Arial>2.9 </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">规范的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><FONT face=Arial>exception</FONT></SPAN><SPAN style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%; FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">流程定义如下：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 14pt; LINE-HEIGHT: 173%"><o:p></o:p></SPAN></STRONG></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">业务层不需处理的</SPAN><SPAN lang=EN-US>runtime exception</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，由展现层定义的</SPAN><SPAN lang=EN-US>exception controller</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">捕获，交给相应的</SPAN><SPAN lang=EN-US>error</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">页面显示并记录</SPAN><SPAN lang=EN-US>stack</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">信息。业务层捕获下层的</SPAN><SPAN lang=EN-US>exception</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，并封装成业务层的</SPAN><SPAN lang=EN-US>checked exception</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，如果</SPAN><SPAN lang=EN-US>nest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所捕获的</SPAN><SPAN lang=EN-US>exception</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，则仅</SPAN><SPAN lang=EN-US>log error message</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，如果不</SPAN><SPAN lang=EN-US>nest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就需要用</SPAN><SPAN lang=EN-US>log.warn(“”,e)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">记录</SPAN><SPAN lang=EN-US>stack</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">信息。展现层捕获业务层的</SPAN><SPAN lang=EN-US>exception</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，应由处理业务层</SPAN><SPAN lang=EN-US>exception</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>error</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">页面来处理。<BR><BR>转载：<A HREF="/pesome/archive/2006/01/20/28502.html#28814">http://www.blogjava.net/pesome/archive/2006/01/20/28502.html#28814</A></SPAN></P><img src ="http://www.blogjava.net/yuanhuaming/aggbug/32330.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yuanhuaming/" target="_blank">疯流成性</a> 2006-02-24 17:52 <a href="http://www.blogjava.net/yuanhuaming/archive/2006/02/24/32330.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>毕业设计，基于3层的.net论坛设计思路</title><link>http://www.blogjava.net/yuanhuaming/archive/2005/08/20/10601.html</link><dc:creator>疯流成性</dc:creator><author>疯流成性</author><pubDate>Sat, 20 Aug 2005 14:40:00 GMT</pubDate><guid>http://www.blogjava.net/yuanhuaming/archive/2005/08/20/10601.html</guid><wfw:comment>http://www.blogjava.net/yuanhuaming/comments/10601.html</wfw:comment><comments>http://www.blogjava.net/yuanhuaming/archive/2005/08/20/10601.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/yuanhuaming/comments/commentRss/10601.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yuanhuaming/services/trackbacks/10601.html</trackback:ping><description><![CDATA[<SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">&nbsp;&nbsp;&nbsp; 这个项目我在分析设计的时候采用了</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">3</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">层构架。我的基本思想是只要和数据库交互的字段和控件，我都把它当作参数传给中间层，然后中间层调用数据层的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">runCommand()</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">方法，从而达到了各层分工明细的目的。在验证表单方面，我使用了</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">JS</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">，在客户端验证，可以减低服务器压力。<BR><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">下面是一段注册用户的代码：<BR></SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"></SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">&nbsp;
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900"><FONT face="Times New Roman">//register.cs<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900"><FONT face="Times New Roman">//</FONT></SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">通过一个提交事件，将控件值传入业务层</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><FONT face="Times New Roman">private void Submit_ServerClick(object sender, System.EventArgs e)<o:p></o:p></FONT></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><FONT face="Times New Roman">{<o:p></o:p></FONT></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>UserInfo user=new UserInfo();<SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user.AddUser(this.UserName.Value,this.PasswordR.Value,this.Email.Value,this.Homepage.Value,<o:p></o:p></FONT></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><FONT face="Times New Roman"><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>this.show_face.Src);<o:p></o:p></FONT></SPAN></B></P><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">}<BR><BR>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900">//UserInfo.cs<SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt">public void AddUser(string username,string passwords,string email,<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>string homepage,string face)<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt">{<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Database data = new Database();<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>OleDbParameter[] prams={<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>data.MakeInParam("@username",OleDbType.VarChar,16),<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 10.05pt; TEXT-INDENT: -10.05pt; mso-char-indent-count: -1.0; mso-char-indent-size: 10.05pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 7">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>data.MakeInParam("@passwords",OleDbType.VarChar,12),<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>data.MakeInParam("@email",OleDbType.VarChar,50),<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>data.MakeInParam("@homepage",OleDbType.VarChar,50),<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>data.MakeInParam("@face",OleDbType.VarChar,50)<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>};<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #ffcc00"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN style="COLOR: #ff9900">//SQL</SPAN></SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语句</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 20.1pt; TEXT-INDENT: -20.1pt; mso-char-indent-count: -2.0; mso-char-indent-size: 10.05pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>strcmd="insert into Users(username,passwords,email,homepage,face) values (@username, @passwords, @email, @homepage, @face)";<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #ff9900">//</SPAN></SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将传入的参数放进数组里</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>string[] values={username,passwords, email, homepage, face};<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #ff9900">//</SPAN></SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将数据库相对应每个字段的变量放进数组</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>string[] datacolumn={"@username","@passwords", "@email", "@homepage", "@face"};<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #ff9900">//</SPAN></SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">调用数据层的</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900">runCommand()</SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>data.runCommand(strcmd,prams,datacolumn,values);<SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></B></P><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">}<BR></SPAN></B><BR></SPAN></B></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900">//Database.cs<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900">//</SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">返回一个</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900">OleDbParameter</SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt">public OleDbParameter MakeInParam(string ParamName, OleDbType DbType,int size) <o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt">{<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>OleDbParameter param;<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return param=new OleDbParameter(ParamName,DbType,size);<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt">}<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt">&nbsp;<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt">public void runCommand(string strcmd,OleDbParameter[] prams,string[] datacolumn,string[] values)<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt">{<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>OleDbDataAdapter cmd = new OleDbDataAdapter(strcmd, conn);<SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>this.Open();<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (prams != null) <o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: #ff9900"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//2</SPAN></SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个循环主要是为了创建</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>// cmd.SelectCommand.Parameters.Add(new OleDbParameter ("@username",OleDbType.VarChar,16));<o:p></o:p><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40.05pt; mso-char-indent-count: 3.99; mso-char-indent-size: 10.0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900">//</SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">赋值</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40.05pt; mso-char-indent-count: 3.99; mso-char-indent-size: 10.0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900">// cmd.SelectCommand.Parameters[@username].Value=username;</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40.05pt; mso-char-indent-count: 3.99; mso-char-indent-size: 10.0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900">//</SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我这样设计主要是为了考虑如果以后要添加或删除用户信息的话，</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40.05pt; mso-char-indent-count: 3.99; mso-char-indent-size: 10.0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #ff9900">//</SPAN></B><B><SPAN style="FONT-SIZE: 10pt; COLOR: #ff9900; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我只要修改业务层</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>foreach (OleDbParameter parameter in prams)<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>cmd.SelectCommand.Parameters.Add(parameter);<SPAN style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for(int i=0;i&lt;values.Length;i++)<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>cmd.SelectCommand.Parameters[datacolumn[i]].Value=values[i];<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>cmd.SelectCommand.ExecuteNonQuery();<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN lang=EN-US style="FONT-SIZE: 10pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>this.Close();<SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></B></P>
<P><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">}</SPAN></B></P>
<P><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">
<HR>
</SPAN></B></P>
<P><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;完成项目后，我发现了很多问题，试着想去改，怕破坏原来的结构，总的来说还是失败了，我总结了以下经验和问题：<BR>1.在多表操作的时候应该使用存储过程，因为句子一长很容易错，而且调试后才能知道结果，如果是存储过程的话可以在MSSQL中验证语句是否错误。当然存储过程还有其他优点。<BR>2.用JS脚本验证表单。我觉得比.NET提供的验证控件方便多了，而且本地验证减少网络传输中这样那样的问题。<BR>3.我有次在别人机子上调试的出了问题：老是报：“该操作不是一个可更新的操作。”我郁闷了好久，最后在别人帖子了找到了答案，原来是WINDOWS权限问题，那机子用的是WINDOWS2003。<BR>4.我觉得象我这样普通的毕业生，软件工程对我来说太渺茫了，根本就没法达到自己预期的理想，就算是分析时设计到的功能，但在代码实现时被自己设计的框架而卡住。所以我就有个疑问：是拿别人的设计书写好，还是自己设计自己写好？虽然我时常偷窥某人设计书，但是终不得精髓。（就像有了内功新法确缺少套路一样）<BR>5.戒骄戒躁。我觉得骄傲烦躁这是编程大忌。林锐博士一本书写到他同学编程的时候，说他编程的时候简直不是人，就是个指针。可能这就是高手和普通人的区别把<BR></SPAN></B></P><img src ="http://www.blogjava.net/yuanhuaming/aggbug/10601.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yuanhuaming/" target="_blank">疯流成性</a> 2005-08-20 22:40 <a href="http://www.blogjava.net/yuanhuaming/archive/2005/08/20/10601.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>