温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:唐唐企业管理网站源码
当前文件:
TangCompany/Manager/Ad.aspx.cs,打开代码结构图
TangCompany/Manager/Ad.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.Data.SqlClient; 12
using System.IO; 13
14
public partial class Manager_Ad : System.Web.UI.Page 15
{ 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
if (!Page.IsPostBack) { 19
20
BindAD(); 21
22
} 23
} 24
private void BindAD() { 25
26
ADDataList.DataSource = SqlHelper.ExcuteReadApdater("sys_SelectAd", CommandType.StoredProcedure, null); 27
ADDataList.DataKeyField = "Id"; 28
ADDataList.DataBind(); 29
30
31
} 32
protected string IsBool(string Isbool) { 33
34
string nId = string.Empty; 35
if (Isbool.ToLower()=="true") 36
{ 37
38
nId = "1"; 39
40
} 41
else { 42
43
nId = "0"; 44
45
} 46
return nId; 47
48
} 49
protected void ADDataList_CancelCommand(object source, DataListCommandEventArgs e) 50
{ 51
ADDataList.EditItemIndex = -1; 52
BindAD(); 53
} 54
protected void ADDataList_DeleteCommand(object source, DataListCommandEventArgs e) 55
{ 56
int nId = int.Parse(ADDataList.DataKeys[e.Item.ItemIndex].ToString()); 57
SqlParameter[] paras ={ new SqlParameter("@Id", SqlDbType.Int, 4) }; 58
paras[0].Value = nId; 59
SqlHelper.ExcuteNonQurey("DELETE FROM [Ad] WHERE Id=@Id", CommandType.Text, paras); 60
BindAD(); 61
} 62
protected void ADDataList_EditCommand(object source, DataListCommandEventArgs e) 63
{ 64
ADDataList.EditItemIndex = e.Item.ItemIndex; 65
BindAD(); 66
} 67
protected void ADDataList_UpdateCommand(object source, DataListCommandEventArgs e) 68
{ 69
string txtName = ((TextBox)ADDataList.Items[e.Item.ItemIndex].FindControl("EditName")).Text.ToString(); 70
int txtSelect = int.Parse(((DropDownList)ADDataList.Items[e.Item.ItemIndex].FindControl("SelectVis")).SelectedValue.ToString()); 71
int nId = int.Parse(ADDataList.DataKeys[e.Item.ItemIndex].ToString()); 72
FileUpload fi = (FileUpload)ADDataList.Items[e.Item.ItemIndex].FindControl("EditImage"); 73
string ff = Path.GetFileName(fi.PostedFile.FileName); 74
string fileName = string.Empty; 75
76
if (string.IsNullOrEmpty(ff) || ff.Length < 1) 77
{ 78
SqlParameter[] paras ={ new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.NVarChar, 30),new SqlParameter("@Vis",SqlDbType.Bit) }; 79
paras[0].Value = nId; 80
paras[1].Value = txtName; 81
paras[2].Value = txtSelect; 82
SqlHelper.ExcuteNonQurey("UPDATE [Ad] set Name=@Name,Vis=@Vis WHERE Id=@Id", CommandType.Text, paras); 83
BindAD(); 84
85
} 86
else { 87
88
fileName = "e_" + GetMaxId() + ff.Substring(ff.LastIndexOf(".")); 89
string Imgpath = Server.MapPath("../flpicture/") + fileName; 90
fi.PostedFile.SaveAs(Imgpath); 91
string sqlPath = "flpicture\\" + fileName; 92
SqlParameter[] paras ={ new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.NVarChar, 30), new SqlParameter("@Vis", SqlDbType.Bit), new SqlParameter("@Image", SqlDbType.NVarChar, 80) }; 93
paras[0].Value = nId; 94
paras[1].Value = txtName; 95
paras[2].Value = txtSelect; 96
paras[3].Value = sqlPath; 97
SqlHelper.ExcuteNonQurey("UPDATE [Ad] set Name=@Name,Vis=@Vis,Image=@Image WHERE Id=@Id", CommandType.Text, paras); 98
99
100
} 101
ADDataList.EditItemIndex = -1; 102
BindAD(); 103
} 104
protected string GetMaxId() 105
{ 106
107
object obj = SqlHelper.ExcuteSclare("SelectAD_MaxId", CommandType.StoredProcedure, null); 108
string getMaxId = string.Empty; 109
if (obj == null) 110
{ 111
112
getMaxId = "00"; 113
114
} 115
else 116
{ 117
118
getMaxId = "00" + obj.ToString(); 119
120
} 121
return getMaxId; 122
123
} 124
protected void bntAd_Click(object sender, EventArgs e) 125
{ 126
string txtName = AddName.Text.ToString(); 127
string ff = Path.GetFileName(AddImage.PostedFile.FileName); 128
string file = GetMaxId() + ff.Substring(ff.LastIndexOf('.')); 129
int nVis = int.Parse(AddShow.SelectedValue.ToString()); 130
if (file.Length < 1) 131
{ 132
133
Response.Write("<script>alert('请上传图片或flash')</script>"); 134
135
} 136
else { 137
138
string txtPath = Server.MapPath("../flpicture/") + file; 139
AddImage.PostedFile.SaveAs(txtPath); 140
string sqlPath = "flpicture\\" + file; 141
SqlParameter[] paras ={ new SqlParameter("@Name", SqlDbType.NVarChar, 30), new SqlParameter("@Image", SqlDbType.NVarChar, 80),new SqlParameter("@Vis",SqlDbType.Bit) }; 142
paras[0].Value = txtName; 143
paras[1].Value = sqlPath; 144
paras[2].Value = nVis; 145
SqlHelper.ExcuteNonQurey("INSERT INTO [Ad](Name,Image,Vis) VALUES(@Name,@Image,@Vis)", CommandType.Text, paras); 146
BindAD(); 147
148
} 149
} 150
} 151





}
}