温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:三层班级留言本源码
当前文件路径:ClassSay/Class/AddUser.aspx.cs

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 System.IO; 12
using UserInfoLib; 13
14
public partial class AddUser : System.Web.UI.Page 15
{ 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
DateTime tnow=DateTime.Now;//现在时间 19
ArrayList AlYear=new ArrayList(); 20
int i; 21
for(i=1970;i<=2010;i++) 22
AlYear.Add(i); 23
ArrayList AlMonth=new ArrayList(); 24
for(i=1;i<=12;i++) 25
AlMonth.Add(i); 26
if (!Page.IsPostBack) 27
{ 28
this.DropDownList4.Attributes.Add("onchange", "checkImage();"); 29
this.Button2.Attributes.Add("onclick", "window.close();"); 30
this.FileUpload1.Attributes.Add("onchange","FileImage();"); 31
string[] str = Directory.GetFiles(this.Server.MapPath("images\\headpic"),"*.gif"); 32
33
for (int k = 0; k < str.Length; k++) 34
{ 35
this.DropDownList4.Items.Add(Path.GetFileName(str[k])); 36
} 37
this.DropDownList4.DataBind(); 38
39
DropDownList1.DataSource = AlYear; 40
DropDownList1.DataBind();//绑定年 41
//选择当前年 42
DropDownList1.SelectedValue = tnow.Year.ToString(); 43
DropDownList2.DataSource = AlMonth; 44
DropDownList2.DataBind();//绑定月 45
//选择当前月 46
DropDownList2.SelectedValue = tnow.Month.ToString(); 47
int year, month; 48
year = Int32.Parse(DropDownList1.SelectedValue); 49
month = Int32.Parse(DropDownList2.SelectedValue); 50
BindDays(year, month);//绑定天 51
//选择当前日期 52
DropDownList3.SelectedValue = tnow.Day.ToString(); 53
} 54
55
} 56
//判断闰年 57
private bool CheckLeap(int year) 58
{ 59
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) 60
return true; 61
else 62
return false; 63
} 64
//绑定每月的天数 65
private void BindDays(int year, int month) 66
{ 67
int i; 68
ArrayList AlDay = new ArrayList(); 69
70
switch (month) 71
{ 72
case 1: 73
74
case 3: 75
case 5: 76
case 7: 77
case 8: 78
case 10: 79
case 12: 80
for (i = 1; i <= 31; i++) 81
AlDay.Add(i); 82
break; 83
case 2: 84
if (CheckLeap(year)) 85
{ 86
for (i = 1; i <= 29; i++) 87
AlDay.Add(i); 88
} 89
else 90
{ 91
for (i = 1; i <= 28; i++) 92
AlDay.Add(i); 93
} 94
break; 95
case 4: 96
case 6: 97
case 9: 98
case 11: 99
for (i = 1; i <= 30; i++) 100
AlDay.Add(i); 101
break; 102
} 103
DropDownList3.DataSource = AlDay; 104
DropDownList3.DataBind(); 105
} 106
//选择年 107
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) 108
{ 109
int year, month; 110
year = Int32.Parse(DropDownList1.SelectedValue); 111
month = Int32.Parse(DropDownList2.SelectedValue); 112
BindDays(year, month); 113
} 114
//选择月 115
private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e) 116
{ 117
int year, month; 118
year = Int32.Parse(DropDownList1.SelectedValue); 119
month = Int32.Parse(DropDownList2.SelectedValue); 120
BindDays(year, month); 121
} 122
//提交注册信息 123
protected void Button1_Click(object sender, EventArgs e) 124
{ 125
UserInfo user = new UserInfo(); 126
user.UserName = this.TextBoxName.Text; 127
if (this.TextBoxName.Text == user.SeleUserName()) 128
{ 129
this.Response.Write("<script>alert('此用户已存在,您可以使用系统自动更改过的用户名');</script>"); 130
this.TextBoxName.Text += "_1"; 131
return; 132
} 133
if ((this.TextBoxName.Text.Length < 4) || (this.TextBoxName.Text.Length >20)) 134
{ 135
this.LabelName.Visible = true; 136
this.LabelName.Text = "用户名长度需大于4小于20 "; 137
return; 138
} 139
user.UserPassword = this.TextBoxPWD.Text; 140
if (this.TextBoxAge.Text == null || this.TextBoxAge.Text == "") 141
{ 142
user.UserAge = 0; 143
} 144
else 145
{ 146
user.UserAge = int.Parse(this.TextBoxAge.Text); 147
} 148
if (this.TextBox2.Text == null || this.TextBox2.Text == "" ) 149
{ 150
user.UserQQ = 0; 151
} 152
else 153
{ 154
user.UserQQ = int.Parse(this.TextBox2.Text); 155
} 156
if (this.TextBox1.Text == null) 157
{ 158
user.UserAddress = null; 159
} 160
else 161
{ 162
user.UserAddress = this.TextBox1.Text; 163
} 164
if (this.TextBox3.Text == null) 165
{ 166
user.UserMsn = null; 167
} 168
else 169
{ 170
user.UserMsn = this.TextBox3.Text; 171
} 172
if (this.TextBox4.Text == null) 173
user.UserEmail = null; 174
else 175
user.UserEmail = this.TextBox4.Text; 176
if (this.TextBox5.Text == null) 177
TextBox5.Text = null; 178
else 179
user.YserTel = this.TextBox5.Text; 180
if (this.TextBox6.Text == null) 181
TextBox6.Text = null; 182
else 183
user.UserImage = this.TextBox6.Text; 184
185
user.UserYeah = this.DropDownList1.Text + "-" + this.DropDownList2.Text + "-" + this.DropDownList3.Text; 186
if (this.FileUpload1.FileName != null && this.FileUpload1.FileName != "") 187
{ 188
string []FileName = this.FileUpload1.FileName.Split('.'); 189
string name = FileName[FileName.Length-1].ToLower(); 190
if (name == "jpg" || name == "gif" || name == "bmp" || name == "jpeg") 191
{ 192
193
//上传文件 194
this.FileUpload1.SaveAs(this.Server.MapPath("UPimage") + "\\" + Path.GetFileName(this.FileUpload1.PostedFile.FileName)); 195
user.UserLable = "~\\UPimage\\" + this.FileUpload1.FileName; 196
} 197
else 198
{ 199
this.Response.Write("<script>alert('图片格式不对。');</script>"); 200
return; 201
} 202
203
} 204
else 205
{ 206
user.UserLable = "~\\images\\headpic\\" + this.DropDownList4.Text; 207
} 208
209
user.User(); 210
this.Response.Redirect("index.aspx"); 211
} 212
} 213





}
}