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





}
}