温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:狂龙通讯录管理系统2.0源码
当前文件:
KuangLongCommunicationV2/AmendPhoto.aspx.cs[4K,2009-6-12 11:46:37],打开代码结构图
KuangLongCommunicationV2/AmendPhoto.aspx.cs[4K,2009-6-12 11:46:37],打开代码结构图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.Data.SqlClient; 12
using System.IO; 13
14
public partial class AmendPhoto : System.Web.UI.Page 15
{ 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
if (!IsPostBack) 19
{ 20
dataBind(); 21
lblphoto.Visible = false; 22
Uploadpri.Visible = false; 23
this.BtnPhoto.Visible = false; 24
this.lblmsg.Visible = false; 25
this.lblfrdinf.Visible = false; 26
this.lblupdata.Visible = false; 27
28
} 29
} 30
private void dataBind() 31
{ 32
33
string ID = Session["userId"].ToString(); 34
string sql = "select * from addresslist where userId='" + ID + "' order by id desc"; 35
DataBase DB = new DataBase(); 36
DataSet ds = DB.DataAll(sql); 37
GridView1.DataSource = ds; 38
GridView1.DataKeyNames = new string[] { "id" }; 39
GridView1.DataBind(); 40
return; 41
42
43
} 44
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) 45
{ 46
//ViewState["id"] = GridView1.DataKeys[GridView1.SelectedIndex].ToString(); 47
lblphoto.Visible = true; 48
Uploadpri.Visible = true; 49
this.BtnPhoto.Visible = true; 50
this.lblmsg.Visible = true; 51
this.lblfrdinf.Visible = true; 52
this.lblupdata.Visible = true; 53
int uid = Convert.ToInt32(GridView1.SelectedValue.ToString()); 54
string frdname = DataBase.Getfield("select frdname from addresslist where id=" + uid, "frdname"); 55
lblfrdinf.Text = frdname.ToString(); 56
lblfrdinf.Style["color"] = "red"; 57
58
} 59
protected void BtnPhoto_Click(object sender, EventArgs e) 60
{ 61
62
63
SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); 64
int uid = Convert.ToInt32(GridView1.SelectedValue.ToString()); 65
66
string imgname = DataBase.Getfield("select frdImageUrl from AddressList where id=" + uid, "frdImageUrl"); 67
if (imgname != "") 68
{ 69
imgname = imgname.Substring(imgname.LastIndexOf("/") + 1); 70
File.Delete(Server.MapPath("./Pictures") + "//" + imgname); 71
} 72
73
string fileName = Uploadpri.PostedFile.FileName; 74
string fileName2 = Uploadpri.PostedFile.FileName.Substring(fileName.LastIndexOf("\\") + 1); 75
string type1 = fileName2.Substring(fileName2.LastIndexOf(".") + 1); 76
string typeToLower = type1.ToLower(); 77
if (typeToLower == "bmp" || typeToLower == "gif" || typeToLower == "jpg"||typeToLower=="") 78
{ 79
80
//DateTime time = new DateTime(); 81
82
string newtime = System.DateTime.Now.ToString(); 83
84
85
86
string uploadName = Uploadpri.Value.Trim(); 87
string pictureName = ""; 88
89
90
91
if (uploadName != "") 92
{ 93
int idx = uploadName.LastIndexOf("."); 94
string suffix = uploadName.Substring(idx); 95
pictureName = System.DateTime.Now.Ticks.ToString() + suffix; 96
97
} 98
99
string sql2 = "update addresslist set frdImageUrl='" + pictureName + "',CreateDate='" + newtime + "' where id=" + uid; 100
101
SqlCommand cmd = new SqlCommand(sql2, conn1); 102
conn1.Open(); 103
try 104
{ 105
cmd.ExecuteNonQuery(); 106
GridView1.EditIndex = -1; 107
lblmsg.Text = "更新成功!"; 108
lblmsg.Style["color"] = "red"; 109
110
} 111
catch (SqlException) 112
{ 113
lblmsg.Text = "更新失败!"; 114
lblmsg.Style["color"] = "red"; 115
116
} 117
conn1.Close(); 118
dataBind(); 119
if (uploadName != "") 120
{ 121
string path = Server.MapPath(".\\Pictures\\"); 122
Uploadpri.PostedFile.SaveAs(path + pictureName); 123
} 124
125
} 126
else 127
{ 128
Response.Write("<script language=javascirpt type='text/javascript'>"); 129
Response.Write("window.alert('请上传正确文件格式!')"); 130
Response.Write("</script>"); 131
132
} 133
} 134
protected void Btninf_Click(object sender, EventArgs e) 135
{ 136
Response.Redirect("Showfriendinf.aspx"); 137
} 138
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 139
{ 140
this.GridView1.PageIndex = e.NewPageIndex; 141
dataBind(); 142
} 143
} 144






}
}