一、股票在线查询项目(http://dr.788111.com/)
这个项目用到的知识点并不是很多,主要表现为:webservice、cookie、session、xml、文件的压缩和解压操作等等。
其中,登陆、注册用到cookie是出现了一些问题,经过一些时间的处理调试最终正常,读写cookie操作如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
//
存储cookie信息
HttpCookie cookie = HttpContext.Current.Request.Cookies[ " name " ];
if (cookie == null )
{
cookie = new HttpCookie( " name " );
}
cookie.Value = Mobile;
cookie.Domain = " 788111.com " ;
cookie.Expires = DateTime.Now.AddDays( 1 ); HttpContext.Current.Response.AppendCookie(cookie);
// 读取cookie信息
HttpCookie usercookie = HttpContext.Current.Request.Cookies[ " user " ];
/// <summary>
/// 清除cookie
/// </summary>
/// <param name="strName"> cookie名称 </param>
public void ClearCookie( string strName)
{
if (HttpContext.Current.Request.Cookies[strName] != null )
{
HttpContext.Current.Response.Cookies[strName].Value = null ; HttpContext.Current.Response.Cookies[strName].Domain = " 788111.com " ;
HttpContext.Current.Response.Cookies[strName].Expires = new DateTime( 1999 , 10 , 12 );
}
}
HttpCookie cookie = HttpContext.Current.Request.Cookies[ " name " ];
if (cookie == null )
{
cookie = new HttpCookie( " name " );
}
cookie.Value = Mobile;
cookie.Domain = " 788111.com " ;
cookie.Expires = DateTime.Now.AddDays( 1 ); HttpContext.Current.Response.AppendCookie(cookie);
// 读取cookie信息
HttpCookie usercookie = HttpContext.Current.Request.Cookies[ " user " ];
/// <summary>
/// 清除cookie
/// </summary>
/// <param name="strName"> cookie名称 </param>
public void ClearCookie( string strName)
{
if (HttpContext.Current.Request.Cookies[strName] != null )
{
HttpContext.Current.Response.Cookies[strName].Value = null ; HttpContext.Current.Response.Cookies[strName].Domain = " 788111.com " ;
HttpContext.Current.Response.Cookies[strName].Expires = new DateTime( 1999 , 10 , 12 );
}
}
1
///
<summary>
2 /// 日志记录类
3 /// </summary>
4 public static class Log
5 {
6 public static string GetLogDirectory( string category)
7 {
8
9 string baseDirectory = string .Empty;
10
11 if ((HttpContext.Current != null ) && (HttpContext.Current.Server != null ))
12
13 {
14
15 baseDirectory = HttpContext.Current.Server.MapPath( " ~ " );
16 }
17
18 else
19 {
20 baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
21
22 }
23
24 if ((baseDirectory[baseDirectory.Length - 1 ] != ' / ' ) && (baseDirectory[baseDirectory.Length - 1 ] != ' \\ ' ))
25
26 {
27
28 baseDirectory = baseDirectory + @" \ " ;
29
30 }
31
32 baseDirectory = string .Format( @" {0}Log\{1}\ " , baseDirectory, category);
33
34 if ( ! Directory.Exists(baseDirectory))
35
36 {
37
38 Directory.CreateDirectory(baseDirectory);
39 }
40
41 return baseDirectory;
42 }
43
44
45 /// <summary>
46 /// </summary>
47 /// <param name="e"></param>
48 public static void SaveException(Exception e)
49 {
50 SaveException(e, string .Empty);
51
52 }
53
54 public static void SaveException(Exception e, string memo)
55 {
56 FileStream stream = new FileStream(GetLogDirectory( " Common " ) + DateTime.Now.ToString( " yyyy-MM-dd " ) + " .txt " , FileMode.Append, FileAccess.Write, FileShare.Delete | FileShare.ReadWrite);
57
58 StreamWriter writer = new StreamWriter(stream);
59
60 writer.WriteLine( " ======================================== " );
61 writer.WriteLine( string .Format( " Memo:\t{0} " , memo));
62 writer.WriteLine( string .Format( " DateTime:\t{0} " , DateTime.Now.ToShortTimeString()));
63
64 writer.WriteLine( string .Format( " Message:\t{0} " , e.Message));
65 writer.WriteLine( string .Format( " StackTrace:\r\n----------\r\n{0}\r\n----------\r\n\r\n\r\n " , e.StackTrace));
66 stream.Flush();
67 writer.Close();
68 stream.Close();
69 stream.Dispose();
70 writer.Dispose();
71 }
72
73 public static void SaveNote( string note)
74 {
75
76 FileStream stream = new FileStream(GetLogDirectory( " Common " ) + DateTime.Now.ToString( " yyyy-MM-dd " ) + " .txt " , FileMode.Append, FileAccess.Write, FileShare.Delete | FileShare.ReadWrite);
77 StreamWriter writer = new StreamWriter(stream);
78 writer.WriteLine( " ========================================= " );
79 writer.WriteLine( string .Format( " Note:\t{0} " , note)); writer.WriteLine( string .Format( " DateTime:\t{0}\r\n\r\n " ,DateTime.Now.ToShortTimeString()));
80 stream.Flush();
81 writer.Close();
82 stream.Close();
83 tream.Dispose();
84 writer.Dispose();
85 }
86 }
87
88
2 /// 日志记录类
3 /// </summary>
4 public static class Log
5 {
6 public static string GetLogDirectory( string category)
7 {
8
9 string baseDirectory = string .Empty;
10
11 if ((HttpContext.Current != null ) && (HttpContext.Current.Server != null ))
12
13 {
14
15 baseDirectory = HttpContext.Current.Server.MapPath( " ~ " );
16 }
17
18 else
19 {
20 baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
21
22 }
23
24 if ((baseDirectory[baseDirectory.Length - 1 ] != ' / ' ) && (baseDirectory[baseDirectory.Length - 1 ] != ' \\ ' ))
25
26 {
27
28 baseDirectory = baseDirectory + @" \ " ;
29
30 }
31
32 baseDirectory = string .Format( @" {0}Log\{1}\ " , baseDirectory, category);
33
34 if ( ! Directory.Exists(baseDirectory))
35
36 {
37
38 Directory.CreateDirectory(baseDirectory);
39 }
40
41 return baseDirectory;
42 }
43
44
45 /// <summary>
46 /// </summary>
47 /// <param name="e"></param>
48 public static void SaveException(Exception e)
49 {
50 SaveException(e, string .Empty);
51
52 }
53
54 public static void SaveException(Exception e, string memo)
55 {
56 FileStream stream = new FileStream(GetLogDirectory( " Common " ) + DateTime.Now.ToString( " yyyy-MM-dd " ) + " .txt " , FileMode.Append, FileAccess.Write, FileShare.Delete | FileShare.ReadWrite);
57
58 StreamWriter writer = new StreamWriter(stream);
59
60 writer.WriteLine( " ======================================== " );
61 writer.WriteLine( string .Format( " Memo:\t{0} " , memo));
62 writer.WriteLine( string .Format( " DateTime:\t{0} " , DateTime.Now.ToShortTimeString()));
63
64 writer.WriteLine( string .Format( " Message:\t{0} " , e.Message));
65 writer.WriteLine( string .Format( " StackTrace:\r\n----------\r\n{0}\r\n----------\r\n\r\n\r\n " , e.StackTrace));
66 stream.Flush();
67 writer.Close();
68 stream.Close();
69 stream.Dispose();
70 writer.Dispose();
71 }
72
73 public static void SaveNote( string note)
74 {
75
76 FileStream stream = new FileStream(GetLogDirectory( " Common " ) + DateTime.Now.ToString( " yyyy-MM-dd " ) + " .txt " , FileMode.Append, FileAccess.Write, FileShare.Delete | FileShare.ReadWrite);
77 StreamWriter writer = new StreamWriter(stream);
78 writer.WriteLine( " ========================================= " );
79 writer.WriteLine( string .Format( " Note:\t{0} " , note)); writer.WriteLine( string .Format( " DateTime:\t{0}\r\n\r\n " ,DateTime.Now.ToShortTimeString()));
80 stream.Flush();
81 writer.Close();
82 stream.Close();
83 tream.Dispose();
84 writer.Dispose();
85 }
86 }
87
88
这个日志记录类主要是便于记录错误信息,以及一些重要的信息。
这个项目中还用到了一个比较重要的资源,即图表控件,如图所示信息:
图表控件是用的的一个免费FusionCharts控件,可以生成许多类型的图表,能够满足一般的业务需求。具体应用方式方法这里就不再多说明,主要是提醒自己有这样一个应用,方便日后使用。
这个项目虽然比较小,但上线后出现了不少的问题。总结了一下,主要表现为:代码编写不够规范,可读写差、思路不够严谨、可扩展性不强。其中突出表现为:代码编写不够规范。希望自己能清醒的注意到这个问题的严重性,认真规范编码,严谨编码。一步步提高个人分析、编码能力……