温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:WO@BIZ第一季1.2版源码
当前文件:
WOBIZ/admin/AddGroup.aspx.cs[13K,2009-6-12 11:58:35],打开代码结构图
WOBIZ/admin/AddGroup.aspx.cs[13K,2009-6-12 11:58:35],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using WoNextDll.commen; 12
using WoNextDll.component; 13
using WoNextDll.Handler; 14
using WoNextDll.Data; 15
using AjaxPro; 16
using System.Text.RegularExpressions; 17
using System.IO; 18
//该源码下载自www.51aspx.com(51aspx.com) 19
20
public partial class admin_AddGroup : System.Web.UI.Page 21
{ 22
private string Flag; 23
private string id; 24
protected string logo; 25
protected internal ConfigInfo setting = Config.Instance(); 26
27
protected void Page_Load(object sender, EventArgs e) 28
{ 29
if (Session["_AdminID"] == null) 30
{ 31
Response.Write("<script>top.location.href='admin_login.aspx';</script>"); 32
} 33
34
if (Request.QueryString["Flag"] == "") 35
{ 36
Response.Redirect("GroupCat.aspx"); 37
Response.End(); 38
} 39
else 40
Flag = Request.QueryString["Flag"].ToString(); 41
ddltype.Attributes.Add("onChange", "type1_Select();"); 42
43
Utility.RegisterTypeForAjax(typeof(admin_AddGroup)); 44
if (!IsPostBack) 45
{ 46
init(); 47
if (Flag == "Add") 48
{ 49
txttitle.Attributes.Add("onBlur", "Chk_GroupName();"); 50
txtgroupurl.Attributes.Add("onBlur", "Chk_GroupUrl();"); 51
Button1.Text = "添加"; 52
Label1.Text = "添加新群组"; 53
labweburl.Text = "GroupName-"; 54
Label2.Text = ".htm"; 55
} 56
if (Flag == "Edit") 57
{ 58
this.Title = "修改群组"; 59
Button1.Text = "修改"; 60
Label1.Text = "修改群组"; 61
id = Request.QueryString["id"].ToString(); 62
Han_Group han = new Han_Group(); 63
WoNextDll.component.Group g = han.GetGroup(int.Parse(id)); 64
txtcontent.Text = g.Content; 65
txttitle.Text = g.Name; 66
laboldname.Text = g.Name; 67
Han_GroupTags h = new Han_GroupTags(); 68
txttags.Text = h.GetTagsByGroupID(g.Id); 69
if (g.Isaudit) 70
CheckBox1.Checked = true; 71
else 72
CheckBox1.Checked = false; 73
ddlopen.SelectedValue = g.Isopen; 74
txtgroupurl.Text = g.Groupurl; 75
txtgroupurl.Attributes["readonly"] = "true"; 76
labweburl.Visible = false; 77
Label2.Visible = false; 78
ddltype.SelectedValue = g.Type1id.ToString(); 79
init2(g.Type1id); 80
ddltype2.SelectedValue = g.Type2id.ToString(); 81
Panel1.Visible = true; 82
logo = bigimg(g); 83
} 84
} 85
} 86
87
private string bigimg(WoNextDll.component.Group ymq) 88
{ 89
string str = string.Format(@"<img src=""../admin/images/PicIcon.gif"" alt="""" width=""18"" height=""18"" onmouseover=""MM_showHideLayers('imgLayer{0}','','show')""", ymq.Id); 90
str += string.Format(@"onmouseout=""MM_showHideLayers('imgLayer{0}','','hide')"" /><div id='imgLayer{1}' style=""Z-INDEX:3; VISIBILITY:hidden; WIDTH:63px; POSITION:absolute; HEIGHT:67px"",class=""shadow"" ><img src='../{2}' alt="""" /></div>", ymq.Id, ymq.Id, ymq.Logo); 91
return str; 92
} 93
94
protected void init() 95
{ 96
ddltype.Items.Add("请选择类别"); 97
string sql = "select * from Wo_GroupType where fromtypeid=0"; 98
IDataReader dr = MyDB.GetDataReader(sql); 99
while (dr.Read()) 100
{ 101
ListItem li = new ListItem(); 102
li.Text = dr["name"].ToString(); 103
li.Value = dr["id"].ToString(); 104
ddltype.Items.Add(li); 105
} 106
dr.Close(); 107
dr.Dispose(); 108
} 109
110
protected void init2(int id) 111
{ 112
ddltype2.Items.Add("请选择类别"); 113
string sql = "select * from Wo_GroupType where fromtypeid="+id+""; 114
IDataReader dr = MyDB.GetDataReader(sql); 115
while (dr.Read()) 116
{ 117
ListItem li = new ListItem(); 118
li.Text = dr["name"].ToString(); 119
li.Value = dr["id"].ToString(); 120
ddltype2.Items.Add(li); 121
} 122
dr.Close(); 123
dr.Dispose(); 124
} 125
126
[AjaxMethod()] 127
public ArrayList GetType2(string type1sel) 128
{ 129
ArrayList arr_City = new ArrayList(); 130
if (type1sel == "请选择类别") 131
return arr_City; 132
else 133
{ 134
int id = int.Parse(type1sel); 135
Han_GroupType han = new Han_GroupType(); 136
string sql = "select * from WO_GroupType where fromtypeid=" + id + " "; 137
string temp_Str = ""; 138
IDataReader dr = MyDB.GetDataReader(sql); 139
while (dr.Read()) 140
{ 141
temp_Str = dr["id"].ToString() + "|" + dr["name"].ToString(); 142
arr_City.Add(temp_Str); 143
} 144
dr.Close(); 145
dr.Dispose(); 146
return arr_City; 147
} 148
} 149
150
[AjaxMethod()] 151
public string check_GroupName(string gname) 152
{ 153
Han_Group han = new Han_Group(); 154
bool b = han.ExistsGroupName(gname); 155
if (b) 156
return "1"; 157
else 158
return "2"; 159
} 160
161
[AjaxMethod()] 162
public string check_GroupUrl(string gurl) 163
{ 164
Han_Group han = new Han_Group(); 165
bool b = han.ExistsGroupUrl(gurl); 166
if (b) 167
return "1"; 168
else 169
return "2"; 170
} 171
172
protected string imgup(FileUpload fileup) 173
{ 174
if (fileup.HasFile) 175
{ 176
FileInfo file = new FileInfo(fileup.FileName); 177
//if (file.Length > 1024 * 1024) 178
// Response.Write("上传的文件太大了!"); 179
string webFilePath = ""; 180
string fileName = DateTime.Now.ToString("yyyyMMddhhmmssfff").ToString(); 181
string exName = file.Name.Substring(file.Name.LastIndexOf(".") + 1).ToUpper();//截取图片的后缀名 182
Regex r3 = new Regex(@"(jpg)|(bmp)|(gif)|(png)|()", RegexOptions.IgnoreCase); 183
if (r3.IsMatch(exName)) 184
{ 185
fileName = fileName + "." + exName; // 文件名称 186
string path = GetSaveFilePath("upgrouplogo/"); 187
webFilePath = Server.MapPath(path + fileName); // 服务器端文件路径 188
if (!System.IO.File.Exists(webFilePath)) 189
{ 190
try 191
{ 192
fileup.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件 193
} 194
catch (Exception ex) 195
{ 196
Response.Write("提示:文件上传失败,失败原因:" + ex.Message); 197
} 198
} 199
} 200
else 201
{ 202
Response.Write("请选择图片类型的文件!"); 203
} 204
return webFilePath; 205
} 206
else 207
return ""; 208
} 209
210
private string GetSaveFilePath(string picPath) 211
{ 212
try 213
{ 214
DateTime dateTime = DateTime.Now; 215
string yearStr = dateTime.Year.ToString(); ; 216
string monthStr = dateTime.Month.ToString(); 217
string dayStr = dateTime.Day.ToString(); 218
string hourStr = dateTime.Hour.ToString(); 219
string minuteStr = dateTime.Minute.ToString(); 220
string dir = dateTime.ToString(@"\\yyyyMMdd"); 221
if (!Directory.Exists(picPath + dir)) 222
{ 223
Directory.CreateDirectory(picPath + dir); 224
} 225
return dir + dateTime.ToString("\\\\yyyyMMddhhmmssffff"); 226
} 227
catch (Exception ex) 228
{ 229
//WriteJs("parent.uploaderror();"); 230
return string.Empty; 231
} 232
} 233
234
235
protected void Button1_Click(object sender, EventArgs e) 236
{ 237
Han_Group han = new Han_Group(); 238
WoNextDll.component.Group g = new WoNextDll.component.Group(); 239
if (ddltype.SelectedIndex == 0) 240
{ 241
Response.Write(Function.msgbox("请选择类别!", "", 0, 1)); 242
Response.End(); 243
} 244
if (txttags.Text != "") 245
{ 246
string tags = txttags.Text.Replace(',', ','); 247
if (tags.EndsWith(",")) 248
tags = tags.Substring(0, tags.Length - 1); 249
string[] arr_str = tags.Split(','); 250
if (arr_str.Length > 10) 251
{ 252
Response.Write(Function.msgbox("不能超过10个标签!", "", 0, 1)); 253
Response.End(); 254
} 255
for (int i = 0; i < arr_str.Length; i++) 256
{ 257
if (arr_str[i].Length > 10) 258
{ 259
Response.Write(Function.msgbox("每个标签的长度不能超过10个字符!", "", 0, 1)); 260
Response.End(); 261
break; 262
} 263
} 264
} 265
if (txttitle.Text != laboldname.Text) 266
{ 267
bool bbb = han.ExistsGroupName(txttitle.Text); 268
if (bbb) 269
{ 270
Response.Write(Function.msgbox("你要修改的群组名称已经被人占用了,请重新输入!", "", 0, 1)); 271
Response.End(); 272
} 273
} 274
g.Content = txtcontent.Text; 275
g.Createtime = System.DateTime.Now; 276
g.Favoritenum = 0; 277
if (CheckBox1.Checked) 278
g.State = true; 279
else 280
g.State = false; 281
g.Iscommend = false; 282
g.Isopen = ddlopen.SelectedValue; 283
string logo = imgup(FileUpload1); 284
if (logo == "") 285
g.Logo = "images/group_defaultlogo.gif"; 286
else 287
g.Logo = logo; 288
g.Name = txttitle.Text; 289
g.Posts = 0; 290
g.Revertnum = 0; 291
if (CheckBox2.Checked) 292
g.Isaudit = true; 293
else 294
g.Isaudit = false; 295
g.Type1id = int.Parse(ddltype.SelectedValue); 296
g.Type2id = int.Parse(Request.Form["ddltype2"].ToString()); 297
g.Userid = int.Parse(Session["_AdminID"].ToString()); 298
g.Username = Session["_AdminUserName"].ToString(); 299
g.Groupurl = txtgroupurl.Text; 300
g.Modifytime = System.DateTime.Now; 301
g.Lastposttime = System.DateTime.Now; 302
g.Lastreverttime = System.DateTime.Now; 303
if (Flag == "Add") 304
{ 305
bool b = han.AddGroup(g); 306
if (b) 307
{ 308
//添加标签 309
Han_GroupTags h = new Han_GroupTags(); 310
int newgid = han.GetGroupIDByUserID(int.Parse(Session["_AdminID"].ToString())); 311
if (txttags.Text != "") 312
{ 313
string tags2 = txttags.Text.Replace(',', ','); 314
if (tags2.EndsWith(",")) 315
tags2 = tags2.Substring(0, tags2.Length - 1); 316
string[] arr_str2 = tags2.Split(','); 317
bool bb; 318
for (int i = 0; i < arr_str2.Length; i++) 319
{ 320
GroupTags gt = new GroupTags(); 321
gt.Groupid = newgid; 322
gt.Tagname = arr_str2[i].ToString(); 323
bb = h.AddGroupTags(gt); 324
} 325
} 326
Response.Write(Function.msgbox("群组添加成功!", "AddGroup.aspx?Flag=Add", 1, 0)); 327
Response.End(); 328
} 329
else 330
{ 331
Response.Write(Function.msgbox("群组添加出现错误!", "AddGroup.aspx?Flag=Add", 1, 0)); 332
Response.End(); 333
} 334
} 335
if (Flag == "Edit") 336
{ 337
g.Id = int.Parse(Request.QueryString["id"].ToString()); 338
if (g.Logo == "" & txtlogo.Text != "") 339
g.Logo = txtlogo.Text; 340
bool b = han.EditGroup(g); 341
if (b) 342
{ 343
//删除和添加标签 344
Han_GroupTags h = new Han_GroupTags(); 345
b = h.DelTagsByGroupID(g.Id); 346
if (txttags.Text != "") 347
{ 348
string tags2 = txttags.Text.Replace(',', ','); 349
if (tags2.EndsWith(",")) 350
tags2 = tags2.Substring(0, tags2.Length - 1); 351
string[] arr_str2 = tags2.Split(','); 352
bool bb; 353
for (int i = 0; i < arr_str2.Length; i++) 354
{ 355
GroupTags gt = new GroupTags(); 356
gt.Groupid = g.Id; 357
gt.Tagname = arr_str2[i].ToString(); 358
bb = h.AddGroupTags(gt); 359
} 360
} 361
Response.Write(Function.msgbox("群组修改成功!", "AddGroup.aspx?Flag=Edit&id=" + Request.QueryString["id"].ToString(), 1, 0)); 362
Response.End(); 363
} 364
else 365
{ 366
Response.Write(Function.msgbox("群组修改出现错误!", "AddGroup.aspx?Flag=Edit&id=" + Request.QueryString["id"].ToString(), 1, 0)); 367
Response.End(); 368
} 369
} 370
371
} 372
} 373






}
}