protected void btn_sub_Click(object sender, EventArgs e) { string webPath = Server.MapPath("~/ADIMG/"); string upname = UpFile.PostedFile.FileName.Substring(UpFile.PostedFile.FileName.LastIndexOf(".")).ToUpper(); Guid id = System.Guid.NewGuid(); string saname = id + upname; UpFile.PostedFile.SaveAs(webPath + saname); CY.HotelBooking.Core.Business.Web_Xml xml = new CY.HotelBooking.Core.Business.Web_Xml(); string type = IMGType.SelectedItem.Value; xml.AddElement(webPath, "~/ADIMG/", saname, type); }
protected void btn_Use_Click(object sender, EventArgs e) { if (IMGType.SelectedItem.Value == "img0") { for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox cb = new CheckBox(); cb = (CheckBox)GridView1.Rows[i].FindControl("cbSel"); if (cb.Checked) { string webPath = Server.MapPath("~/ADIMG/"); string upname = GridView1.DataKeys[i].Value.ToString().Substring(GridView1.DataKeys[i].Value.ToString().LastIndexOf("/") + 1).ToUpper(); Guid id = System.Guid.NewGuid(); string saname = id + upname; System.IO.FileInfo fileinfo = new System.IO.FileInfo(webPath + upname); fileinfo.CopyTo(webPath + saname); CY.HotelBooking.Core.Business.Web_Xml xml = new CY.HotelBooking.Core.Business.Web_Xml(); xml.AddElement(webPath, "~/ADIMG/", saname, lab_temp.Text); } } string tablename = IMGType.SelectedItem.Value; dataBind(tablename); } else if (IMGType.SelectedItem.Value == "img1" || IMGType.SelectedItem.Value == "img2" || IMGType.SelectedItem.Value == "img3") { if (GridView2.Rows.Count == 1) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('发布列表中已有一张图片');</script>"); } else { int j = 0; for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox cb = new CheckBox(); cb = (CheckBox)GridView1.Rows[i].FindControl("cbSel"); if (cb.Checked) { j++; } } if (j == 1) { for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox cb = new CheckBox(); cb = (CheckBox)GridView1.Rows[i].FindControl("cbSel"); if (cb.Checked) { string webPath = Server.MapPath("~/ADIMG/"); string upname = GridView1.DataKeys[i].Value.ToString().Substring(GridView1.DataKeys[i].Value.ToString().LastIndexOf("/") + 1).ToUpper(); Guid id = System.Guid.NewGuid(); string saname = id + upname; System.IO.FileInfo fileinfo = new System.IO.FileInfo(webPath + upname); fileinfo.CopyTo(webPath + saname); CY.HotelBooking.Core.Business.Web_Xml xml = new CY.HotelBooking.Core.Business.Web_Xml(); xml.AddElement(webPath, "~/ADIMG/", saname, lab_temp.Text); } } } else if (j > 1) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('只能选择一张图片');</script>"); } string tablename = IMGType.SelectedItem.Value; dataBind(tablename); } } }