简单评论系统开发过程(六)
看看还有什么丢下的没有,对了,还有个函数类,也贴上吧。
com.cs
还有CSS没贴上吧,下面:
style.css
到此一个简单的评论系统就完事了,写的比较仓促,有错误之类请指出,欢迎您提出好的建议和意见。
com.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Web;
5
using System.Text.RegularExpressions;
6
7
namespace BLL
8
{
9
public class com
10
{
11
/// <summary>
12
/// 获取客户端IP
13
/// </summary>
14
/// <returns></returns>
15
public string GetClientIP()
16
{
17
string result = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
18
if (null == result || result == String.Empty)
19
{
20
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
21
}
22
23
if (null == result || result == String.Empty)
24
{
25
result = HttpContext.Current.Request.UserHostAddress;
26
}
27
return result;
28
}
29
/// <summary>
30
/// 截断字符
31
/// </summary>
32
/// <param name="str"></param>
33
/// <param name="length"></param>
34
/// <param name="endstr"></param>
35
/// <returns></returns>
36
public static string cutStr(string str, int length, string endstr)
37
{
38
//判断字串是否为空
39
if (str == null)
40
{
41
return "";
42
}
43
Regex title_regex = new Regex("(?(title)<([^>]*)>)");
44
Match m = title_regex.Match(str);
45
str = Regex.Replace(str, m.Groups["title"].Value, "", RegexOptions.IgnoreCase);
46
if (System.Text.Encoding.Default.GetByteCount(str) > length)
47
{
48
//初始化
49
int i = 0, j = 0;
50
//为汉字或全脚符号长度加2否则加1
51
foreach (char Char in str)
52
{
53
if ((int)Char > 127)
54
{
55
i += 2;
56
}
57
else
58
{
59
i++;
60
}
61
if (i > length)
62
{
63
str = str.Substring(0, j - 1) + endstr;
64
break;
65
}
66
j++;
67
}
68
}
69
return str;
70
}
71
/// <summary>
72
/// MD5加密
73
/// </summary>
74
/// <param name="str"></param>
75
/// <param name="code"></param>
76
/// <returns></returns>
77
public static string Md5(string str, int code)
78
{
79
if (code == 16)
80
{
81
//16位MD5加密(取32位加密的9~25字符)
82
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
83
}
84
else
85
{
86
//32位加密
87
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
88
}
89
}
90
/// <summary>
91
/// 截断IP
92
/// </summary>
93
/// <param name="str"></param>
94
/// <returns></returns>
95
public static string cutIP(string str)
96
{
97
return str.Replace(str.Substring(str.LastIndexOf("."), str.Length), "*");
98
}
99
}
100
}
101
using System;2
using System.Collections.Generic;3
using System.Text;4
using System.Web;5
using System.Text.RegularExpressions;6

7
namespace BLL8
{9
public class com10
{11
/// <summary>12
/// 获取客户端IP13
/// </summary>14
/// <returns></returns>15
public string GetClientIP()16
{17
string result = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];18
if (null == result || result == String.Empty)19
{20
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];21
}22

23
if (null == result || result == String.Empty)24
{25
result = HttpContext.Current.Request.UserHostAddress;26
}27
return result;28
}29
/// <summary>30
/// 截断字符31
/// </summary>32
/// <param name="str"></param>33
/// <param name="length"></param>34
/// <param name="endstr"></param>35
/// <returns></returns>36
public static string cutStr(string str, int length, string endstr)37
{38
//判断字串是否为空39
if (str == null)40
{41
return "";42
}43
Regex title_regex = new Regex("(?(title)<([^>]*)>)");44
Match m = title_regex.Match(str);45
str = Regex.Replace(str, m.Groups["title"].Value, "", RegexOptions.IgnoreCase);46
if (System.Text.Encoding.Default.GetByteCount(str) > length)47
{48
//初始化49
int i = 0, j = 0;50
//为汉字或全脚符号长度加2否则加151
foreach (char Char in str)52
{53
if ((int)Char > 127)54
{55
i += 2;56
}57
else58
{59
i++;60
}61
if (i > length)62
{63
str = str.Substring(0, j - 1) + endstr;64
break;65
}66
j++;67
}68
}69
return str;70
}71
/// <summary>72
/// MD5加密73
/// </summary>74
/// <param name="str"></param>75
/// <param name="code"></param>76
/// <returns></returns>77
public static string Md5(string str, int code)78
{79
if (code == 16)80
{81
//16位MD5加密(取32位加密的9~25字符)82
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);83
}84
else85
{86
//32位加密87
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();88
}89
}90
/// <summary>91
/// 截断IP92
/// </summary>93
/// <param name="str"></param>94
/// <returns></returns>95
public static string cutIP(string str)96
{97
return str.Replace(str.Substring(str.LastIndexOf("."), str.Length), "*");98
}99
}100
}101

还有CSS没贴上吧,下面:
style.css
1
body {
2
font-family: 宋体,Verdana;
3
font-size: 12px;
4
}
5
#dl comment {
6
border-bottom: 1px dotted #ccc;
7
}
8
.name {
9
float: left;
10
}
11
.time {
12
float: right;
13
}
14
.content {
15
height: 80px;
16
padding: 10px;
17
clear: both;
18
}
19
.flag {
20
text-align: right;
21
padding: 5px 0;
22
}
23
#comm_add {
24
border: 1px solid #ccc;
25
padding: 10px;
26
}
27
#comm_add username {
28
background-color: #F8FCFF;
29
}
30
#comm_add info {
31
background-color: #E7E7E7;
32
}
33
.dot {
34
border-bottom: 1px dotted #ccc;
35
}
36
.line {
37
border-bottom: 1px solid #999;
38
}
39
.agree {
40
color: #BC2931;
41
text-align: right;
42
line-height: 20px;
43
}
44
.hang {
45
height: 30px;
46
line-height: 30px;
47
}
48
#pager a, a:link, a:visited {
49
border: 1px solid #ccc;
50
padding: 3px 5px;
51
background-color: #eee;
52
text-decoration: none;
53
}
54
#pager a:hover {
55
text-decoration: none;
56
background-color: #F8FCFF;
57
}
58
body {2
font-family: 宋体,Verdana;3
font-size: 12px;4
}5
#dl comment {6
border-bottom: 1px dotted #ccc;7
}8
.name {9
float: left;10
}11
.time {12
float: right;13
}14
.content {15
height: 80px;16
padding: 10px;17
clear: both;18
}19
.flag {20
text-align: right;21
padding: 5px 0;22
}23
#comm_add {24
border: 1px solid #ccc;25
padding: 10px;26
}27
#comm_add username {28
background-color: #F8FCFF;29
}30
#comm_add info {31
background-color: #E7E7E7;32
}33
.dot {34
border-bottom: 1px dotted #ccc;35
}36
.line {37
border-bottom: 1px solid #999;38
}39
.agree {40
color: #BC2931;41
text-align: right;42
line-height: 20px;43
}44
.hang {45
height: 30px;46
line-height: 30px;47
}48
#pager a, a:link, a:visited {49
border: 1px solid #ccc;50
padding: 3px 5px;51
background-color: #eee;52
text-decoration: none;53
}54
#pager a:hover {55
text-decoration: none;56
background-color: #F8FCFF;57
}58

到此一个简单的评论系统就完事了,写的比较仓促,有错误之类请指出,欢迎您提出好的建议和意见。


浙公网安备 33010602011771号