温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:商务维基网源码
当前文件:
MerchantViki/WriteArticle.aspx.cs,打开代码结构图
MerchantViki/WriteArticle.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Data.SqlClient; 4
using System.Configuration; 5
using System.Collections; 6
using System.Web; 7
using System.Web.Security; 8
using System.Web.UI; 9
using System.Web.UI.WebControls; 10
using System.Web.UI.WebControls.WebParts; 11
using System.Web.UI.HtmlControls; 12
13
public partial class WriteArticle : System.Web.UI.Page 14
{ 15
protected void Page_Load(object sender, EventArgs e) 16
{ 17
this.Header.Title = Application.Get("siteName") + "---" + this.Header.Title; 18
19
if (!IsPostBack) 20
{ 21
BindData(); 22
} 23
24
//Response.Write(StrToCode(" 刘 ")); 25
} 26
27
private void BindData() 28
{ 29
try 30
{ 31
string conStr = Application.Get("conStr").ToString(); 32
SqlConnection sqlCon = new SqlConnection(conStr); 33
34
sqlCon.Open(); 35
string cmdStr = "select name,id from edition order by click desc"; 36
SqlCommand sqlCmd = new SqlCommand(cmdStr, sqlCon); 37
SqlDataReader sqlDR = sqlCmd.ExecuteReader(); 38
39
EdList.DataSource = sqlDR; 40
EdList.DataTextField = "name"; 41
EdList.DataValueField = "id"; 42
EdList.DataBind(); 43
44
sqlDR.Close(); 45
sqlCon.Close(); 46
} 47
catch (Exception ex) 48
{ 49
//throw new Exception(ex.Message, ex); 50
info.Text = "数据绑定错误:" + ex.Message; 51
} 52
} 53
54
public void AddArticleBtn_Click(object sender, EventArgs e) 55
{ 56
if (Page.IsValid) 57
{ 58
try 59
{ 60
string conStr = Application.Get("conStr").ToString(); 61
SqlConnection sqlCon = new SqlConnection(conStr); 62
sqlCon.Open(); 63
64
string haveImg = "否"; 65
int userID = -1; 66
string contentStr = StringFilter(contentTxt.Text); 67
68
contentStr = StrProc(contentStr); 69
70
string cmdStr = "insert into article(edID,title,click,commentNum,lastTime,createTime,haveImg,userID,contentText) values('" + EdList.SelectedValue + "','" + StringFilter(titleTxt.Text) + "','0','0','" + DateTime.Now.ToShortDateString() + "','" + DateTime.Now.ToShortDateString() + "','" + haveImg + "','" + userID + "','" + contentStr + "')"; 71
SqlCommand sqlCmd = new SqlCommand(cmdStr, sqlCon); 72
sqlCmd.ExecuteNonQuery(); 73
74
cmdStr = "select articleNum from edition where id = '"+ EdList.SelectedValue +"'"; 75
sqlCmd.CommandText = cmdStr; 76
sqlCmd.Connection = sqlCon; 77
SqlDataReader sqlDR = sqlCmd.ExecuteReader(); 78
if(sqlDR.Read()) 79
{ 80
int articleNum = int.Parse(sqlDR.GetValue(0).ToString()) + 1; 81
sqlDR.Close(); 82
cmdStr = "update edition set articleNum = '"+ articleNum +"' where id = '"+ EdList.SelectedValue +"'"; 83
sqlCmd.CommandText = cmdStr; 84
sqlCmd.Connection = sqlCon; 85
sqlCmd.ExecuteNonQuery(); 86
//info.Text = "文章发表成功。"; 87
info.Text = contentStr; 88
} 89
else 90
{ 91
sqlDR.Close(); 92
info.Text = "修改文章数量失败。但文章发表成功。"; 93
} 94
95
sqlCon.Close(); 96
} 97
catch (Exception ex) 98
{ 99
//throw new Exception(ex.Message, ex); 100
info.Text = "操纵错误:" + ex.Message; 101
} 102
} 103
} 104
105
private string StrProc(string inStr) 106
{ 107
int i = 0; 108
int c1 = 0, c2 = 0; 109
string outStr = null; 110
for (i = 0; i < inStr.Length; i++) 111
{ 112
c1 = inStr[i]; 113
if(c1 == 13) 114
{ 115
c2 = inStr[i+1]; 116
if(c2 == 10) 117
{ 118
outStr += "<br />"; 119
i++; 120
} 121
} 122
else if (c1 == 32) 123
{ 124
outStr += " "; 125
} 126
else 127
{ 128
outStr += inStr[i]; 129
} 130
} 131
return outStr; 132
} 133
134
private string StringFilter(string inStr) 135
{ 136
string outStr; 137
outStr = inStr.Trim().Replace("\'",""); 138
return outStr; 139
} 140
141
public void AddImgBtn_Click(object sender, EventArgs e) 142
{ 143
//contentTxt.Text += "<img>"; 144
} 145
} 146





}
}