public partial class Manage_BusinessmanNewP : System.Web.UI.Page
18{
19 protected void Page_Load( object sender, EventArgs e)
20 {
21 if (!IsPostBack)
22 {
23 ProductInfo info = new ProductInfo();
24
25 if (Request.Cookies[ "uname"] != null)
26 {
27 HttpCookie cookie = Request.Cookies[ "uname"];
28 string uname = Server.HtmlEncode(cookie.Value);
29 Product p = new Product();
30 string ucate = p.GetBCatebyUname(uname);
31 //拼表名
32 info.GoodsinfoName = "GoodsInfo_" + ucate;
33 info.GoodsdetailName = "GoodsDetail_" + ucate;
34 ViewState[ "ucate"] = ucate;
35 }
36 string edit = Request.QueryString[ "edit"];
37 if (edit == null)
38 {
39 DetailsView1.DefaultMode = DetailsViewMode.Edit;
40
41 }
42 else
43 {
44 DetailsView1.DefaultMode = DetailsViewMode.Insert;
45
46 }
47 }
48 }
49 protected void DropDownList1_SelectedIndexChanged( object sender, EventArgs e)
50 {
51
52 }
53 protected void DetailsView1_ItemInserted( object sender, DetailsViewInsertedEventArgs e)
54 {
55 //insert之后执行,图片上传控制
56 HttpRuntimeSection h = new HttpRuntimeSection();
57
58 FileUpload f1 = (FileUpload)DetailsView1.Rows[10].FindControl( "FileUpload1");
59 FileUpload f2 = (FileUpload)DetailsView1.Rows[10].FindControl( "FileUpload2");
60 FileUpload f3 = (FileUpload)DetailsView1.Rows[10].FindControl( "FileUpload3");
61 FileUpload f4 = (FileUpload)DetailsView1.Rows[10].FindControl( "FileUpload4");
62 FileUpload f5 = (FileUpload)DetailsView1.Rows[10].FindControl( "FileUpload5");
63
64
65 bool file1OK = false;
66 bool file2OK = false;
67 bool file3OK = false;
68 bool file4OK = false;
69 bool file5OK = false;
70 String path = Server.MapPath( "~/image/");
71 String fileExtension;
72 if (f1.HasFile)
73 {
74 fileExtension = Path.GetExtension(f1.FileName).ToLower();
75 String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
76
77 for ( int i = 0; i < allowedExtensions.Length; i++)
78 {
79 if (fileExtension == allowedExtensions[i] && h.MaxRequestLength <= 500)
80 {
81 file1OK = true;
82 }
83 }
84 }
85 if (file1OK)
86 {
87 try
88 {
89 f1.PostedFile.SaveAs(path + f1.FileName);
90 }
91 catch (Exception ex)
92 {
93 Response.Write( "<script>window.alert('图片上传失败!')<script>");
94 }
95 }
96 else
97 {
98 Response.Write( "<script>window.alert('文件类型不符或文件过大(500K以内)!')<script>");
99 }
100
101 if (f2.HasFile)
102 {
103 fileExtension = Path.GetExtension(f2.FileName).ToLower();
104 String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
105
106 for ( int i = 0; i < allowedExtensions.Length; i++)
107 {
108 if (fileExtension == allowedExtensions[i] && h.MaxRequestLength <= 500)
109 {
110 file2OK = true;
111 }
112 }
113 }
114 if (file2OK)
115 {
116 try
117 {
118 f2.PostedFile.SaveAs(path + f2.FileName);
119 }
120 catch (Exception ex)
121 {
122 Response.Write( "<script>window.alert('图片上传失败!')<script>");
123 }
124 }
125 else
126 {
127 Response.Write( "<script>window.alert('文件类型不符或文件过大(500K以内)!')<script>");
128 }
129
130 if (f3.HasFile)
131 {
132 fileExtension = Path.GetExtension(f3.FileName).ToLower();
133 String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
134
135 for ( int i = 0; i < allowedExtensions.Length; i++)
136 {
137 if (fileExtension == allowedExtensions[i] && h.MaxRequestLength <= 500)
138 {
139 file3OK = true;
140 }
141 }
142 }
143 if (file3OK)
144 {
145 try
146 {
147 f3.PostedFile.SaveAs(path + f3.FileName);
148 }
149 catch (Exception ex)
150 {
151 Response.Write( "<script>window.alert('图片上传失败!')<script>");
152 }
153 }
154 else
155 {
156 Response.Write( "<script>window.alert('文件类型不符或文件过大(500K以内)!')<script>");
157 }
158
159 if (f4.HasFile)
160 {
161 fileExtension = Path.GetExtension(f4.FileName).ToLower();
162 String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
163
164 for ( int i = 0; i < allowedExtensions.Length; i++)
165 {
166 if (fileExtension == allowedExtensions[i] && h.MaxRequestLength <= 500)
167 {
168 file4OK = true;
169 }
170 }
171 }
172 if (file4OK)
173 {
174 try
175 {
176 f4.PostedFile.SaveAs(path + f4.FileName);
177 }
178 catch (Exception ex)
179 {
180 Response.Write( "<script>window.alert('图片上传失败!')<script>");
181 }
182 }
183 else
184 {
185 Response.Write( "<script>window.alert('文件类型不符或文件过大(500K以内)!')<script>");
186 }
187
188 if (f5.HasFile)
189 {
190 fileExtension = Path.GetExtension(f5.FileName).ToLower();
191 String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
192
193 for ( int i = 0; i < allowedExtensions.Length; i++)
194 {
195 if (fileExtension == allowedExtensions[i] && h.MaxRequestLength <= 500)
196 {
197 file5OK = true;
198 }
199 }
200 }
201 if (file5OK)
202 {
203 try
204 {
205 f5.PostedFile.SaveAs(path + f5.FileName);
206 }
207 catch (Exception ex)
208 {
209 Response.Write( "<script>window.alert('图片上传失败!')<script>");
210 }
211 }
212 else
213 {
214 Response.Write( "<script>window.alert('文件类型不符或文件过大(500K以内)!')<script>");
215 }
216
217
218 }
219 /** //// <summary>
220 /// 添加附件按钮事件
221 /// </summary>
222 /// <param name="sender"></param>
223 /// <param name="e"></param>
224 protected void Button1_Click( object sender, EventArgs e)
225 {
226 //session记录用户点击次数
227 int session = Convert.ToInt32(Session[ "btnclick"]);
228 int see = session + 1;
229
230 Session[ "btnclick"] = ( object)see;
231 //HtmlTable tb = (HtmlTable)DetailsView1.Rows[10].FindControl("tb");
232 //if (session < 5)
233 //{
234 // FileUpload f = new FileUpload();
235 // f.Enabled = true;
236 // f.ID = "f" + Session["btnclick"].ToString();
237 // tb.Rows[session].Cells[1].Controls.Add(f);
238 //}
239 //else
240 //{
241 // Response.Write("<script>alert('最多只能添加5个附件!')</script>");
242 //}
243
244 //FileUpload f = (FileUpload)DetailsView1.Rows[10].FindControl("tb");
245 Button a = (Button)DetailsView1.Rows[10].FindControl( "btnaddfile1");
246 Button b = (Button)DetailsView1.Rows[10].FindControl( "btnaddfile2");
247 Button c = (Button)DetailsView1.Rows[10].FindControl( "btnaddfile3");
248 Button d = (Button)DetailsView1.Rows[10].FindControl( "btnaddfile4");
249 Label l = (Label)DetailsView1.Rows[10].FindControl( "lbladd");
250
251 FileUpload f1 = (FileUpload)DetailsView1.Rows[10].FindControl( "FileUpload1");
252 FileUpload f2 = (FileUpload)DetailsView1.Rows[10].FindControl( "FileUpload2");
253 FileUpload f3 = (FileUpload)DetailsView1.Rows[10].FindControl( "FileUpload3");
254 FileUpload f4 = (FileUpload)DetailsView1.Rows[10].FindControl( "FileUpload4");
255 FileUpload f5 = (FileUpload)DetailsView1.Rows[10].FindControl( "FileUpload5");
256
257 switch (see)
258 {
259 case 1:
260 b.Visible = true;
261 a.Visible = false;
262 f2.Visible = true;
263 break;
264 case 2:
265 c.Visible = true;
266 b.Visible = false;
267 f3.Visible = true;
268 break;
269 case 3:
270 d.Visible = true;
271 c.Visible = false;
272 f4.Visible = true;
273 break;
274 case 4:
275 l.Visible = true;
276 d.Visible = false;
277 f5.Visible = true;
278 break;
279 }
280
281
282 }
283 protected void ObjectDataSource1_Inserting( object sender, ObjectDataSourceMethodEventArgs e)
284 {
285 ProductInfo info = new ProductInfo();
286 foreach (DetailsViewRow row in DetailsView1.Rows)
287 {
288 FileUpload f1 = (FileUpload)row.FindControl( "FileUpload1");
289 FileUpload f2 = (FileUpload)row.FindControl( "FileUpload2");
290 FileUpload f3 = (FileUpload)row.FindControl( "FileUpload3");
291 FileUpload f4 = (FileUpload)row.FindControl( "FileUpload4");
292 FileUpload f5 = (FileUpload)row.FindControl( "FileUpload5");
293
294 info.GoodsImage0 = f1.FileName + "~/image/";
295 info.GoodsImage1 = f2.FileName + "~/image/";
296 info.GoodsImage2 = f3.FileName + "~/image/";
297 info.GoodsImage3 = f4.FileName + "~/image/";
298 info.GoodsImage4 = f5.FileName + "~/image/";
299 }
300 }
301 /** //// <summary>
302 /// DetailsView事件(在呈现该页前激发)
303 /// </summary>
304 /// <param name="sender"></param>
305 /// <param name="e"></param>
306
307 protected void DetailsView1_PreRender( object sender, EventArgs e)
308 {
309 Label lb = (Label)DetailsView1.Rows[1].FindControl( "lblcate");
310 lb.Text = ViewState[ "ucate"].ToString();
311 DropDownList dl = (DropDownList)DetailsView1.Rows[1].FindControl( "dl1");
312 Product p = new Product();
313 IList<ProductInfo> list = p.GetAllPbyGoodsType(lb.Text);
314 //绑定DropDownList
315 dl.DataSource = list;
316 dl.DataTextField= "BranchName";
317 dl.DataValueField = "BranchID";
318 dl.DataBind();
319
320 }
321}