protected void Btn_SubmitEdit_Click(object sender, EventArgs e) { Label_Grid1_State.Text = "默认数据源"; Boolean fileOk = false; if (TextBox_Edit.Text != "") { if (this.FileUploadEdit.HasFile) { //取得文件的扩展名,并转换成小写 string fileExtension = Path.GetExtension(FileUploadEdit.FileName).ToLower(); //验证上传文件是否图片格式 fileOk = IsImage(fileExtension); if (fileOk) { //对上传文件的大小进行检测,限定文件最大不超过8M if (FileUploadEdit.PostedFile.ContentLength < 8192000) { string name = Label_ImgUrl.Text; string mapname = Server.MapPath(name); System.IO.File.Delete(mapname); string filepath = "/TemplateUpload/"; if (Directory.Exists(Server.MapPath(filepath)) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(Server.MapPath(filepath)); } string virpath = filepath + FileUploadEdit.FileName; string mappath = Server.MapPath(virpath); System.IO.FileInfo fi = new System.IO.FileInfo(mappath); if (fi.Exists) { ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "alert", "alert('存在同名文件,请修改后上传!')", true); return; } FileUploadEdit.SaveAs(mappath); tempInfo.TmpUpload_ID = new Guid(Label_EditTmpID.Text.ToString()); tempInfo.TmpUpload_Name = TextBox_Edit.Text.Trim(); tempInfo.TmpUpload_ImgUrl = virpath; tempInfo.TmpUpload_Person = Session["UserName"].ToString(); tempInfo.TmpUpload_Time = DateTime.Now; upload.U_TemplatUpload(tempInfo); GridView1.DataSource = upload.SList_TemplateUpload(); GridView1.DataBind(); TextBox_Edit.Text = ""; UpdatePanel_Temp.Update(); ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "alert", "alert('模板上传且修改成功!')", true); PanelEdit.Visible = false; UpdatePanel1.Update(); PanelShowImage.Visible = false; UpdatePanel_ShowImage.Update(); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "alert", "alert('文件大小超出8M!请重新选择!')", true); return; } } else { ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "alert", "alert('上传文件类型有误!')", true); return; } } else { tempInfo.TmpUpload_ID = new Guid(Label_EditTmpID.Text.ToString()); tempInfo.TmpUpload_Name = TextBox_Edit.Text.Trim(); tempInfo.TmpUpload_ImgUrl = Label_ImgUrl.Text; tempInfo.TmpUpload_Person = Session["UserName"].ToString(); tempInfo.TmpUpload_Time = DateTime.Now; upload.U_TemplatUpload(tempInfo); GridView1.DataSource = upload.SList_TemplateUpload(); GridView1.DataBind(); TextBox_Edit.Text = ""; UpdatePanel_Temp.Update(); ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(Page), "alert", "alert('模板修改成功!')", true); PanelEdit.Visible = false; UpdatePanel1.Update(); PanelShowImage.Visible = false; UpdatePanel_ShowImage.Update(); } } else { ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "alert", "alert('模板名称不能为空!')", true); return; } }
protected void ButtonCloseImg_Click(object sender, EventArgs e) { PanelShowImage.Visible = false; UpdatePanel_ShowImage.Update(); }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Delete1") { GridViewRow row = ((LinkButton)e.CommandSource).Parent.Parent as GridViewRow; GridView1.SelectedIndex = row.RowIndex; GridView1.SelectedIndex = -1; string id = GridView1.DataKeys[row.RowIndex].Values["TmpUpload_ID"].ToString(); Guid guid_id = new Guid(id); string imgUrl = GridView1.DataKeys[row.RowIndex].Values["TmpUpload_ImgUrl"].ToString(); int i = upload.D_TemplatUpload(guid_id); if (i > 0) { System.IO.File.Delete(Server.MapPath(imgUrl)); ScriptManager.RegisterStartupScript(Page, typeof(Page), "alert", "alert('模板删除成功!')", true); } else { ScriptManager.RegisterStartupScript(Page, typeof(Page), "alert", "alert('模板删除失败!')", true); } GridView1.DataSource = upload.SList_TemplateUpload(); GridView1.DataBind(); UpdatePanel_Temp.Update(); PanelAdd.Visible = false; PanelEdit.Visible = false; PanelShowImage.Visible = false; UpdatePanel_ShowImage.Update(); UpdatePanel1.Update(); //无关信息隐藏 //Panel10.Visible = false; //UpdatePanel_AddTmp.Update(); } if (e.CommandName == "CheckProType") { Panel_PT.Visible = true; GridView2.SelectedIndex = -1; GridViewRow row = ((LinkButton)e.CommandSource).Parent.Parent as GridViewRow; GridView1.SelectedIndex = row.RowIndex; string id = GridView1.DataKeys[row.RowIndex].Values["TmpUpload_ID"].ToString(); Label_TmpID.Text = id; databind(); //无关信息隐藏 // Panel10.Visible = false; // UpdatePanel_AddTmp.Update(); Panel_Product.Visible = false; UpdatePanel_Product.Update(); } if (e.CommandName == "EditTemplate") { GridViewRow row = ((LinkButton)e.CommandSource).Parent.Parent as GridViewRow; GridView1.SelectedIndex = row.RowIndex; TextBox_Edit.Text = GridView1.DataKeys[row.RowIndex].Values["TmpUpload_Name"].ToString(); Label_ImgUrl.Text = GridView1.DataKeys[row.RowIndex].Values["TmpUpload_ImgUrl"].ToString(); Label_EditTmpID.Text = GridView1.DataKeys[row.RowIndex].Values["TmpUpload_ID"].ToString(); PanelEdit.Visible = true; UpdatePanel1.Update(); } if (e.CommandName == "CheckImage") { GridViewRow row = ((LinkButton)e.CommandSource).Parent.Parent as GridViewRow; GridView1.SelectedIndex = row.RowIndex; Label_ImgName.Text = GridView1.DataKeys[row.RowIndex].Values["TmpUpload_Name"].ToString(); Label_ShowImgUrl.Text = GridView1.DataKeys[row.RowIndex].Values["TmpUpload_ImgUrl"].ToString(); TempImage.ImageUrl = Label_ShowImgUrl.Text.ToString(); PanelShowImage.Visible = true; UpdatePanel_ShowImage.Update(); } }