protected void UpdateBtn_Click(object sender, EventArgs e) { if (FileUploadEdit.HasFile) { try { if (FileUploadEdit.PostedFile.ContentType == "image/jpeg" || FileUploadEdit.PostedFile.ContentType == "image/png") { if (FileUploadEdit.PostedFile.ContentLength < 102400) { var ext = Path.GetExtension(FileUploadEdit.FileName); FileUploadEdit.SaveAs(Server.MapPath("~/images/") + Img.Text + ext); } else { } } else { } } catch (Exception ex) { //StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } CatDataSetTableAdapters.CatsTableAdapter catsAdapter = new CatDataSetTableAdapters.CatsTableAdapter(); var price = int.Parse(PriceUpdate.Text); var quantity = int.Parse(QuantityUpdate.Text); var cat = int.Parse(CategoryUpdate.Text); catsAdapter.Update(IdUpdate.Text, NameUpdate.Text, ImgUpdate.Text, cat, quantity, price, DescriptionUpdate.Text, IdUpdate.Text); GridView1.DataBind(); }
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; } }