经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » C# » 查看文章
asp:FileUpload 上次图片 - hi-latolo
来源:cnblogs  作者:hi-latolo  时间:2018/11/3 10:08:44  对本文有异议
  1. <asp:FileUpload ID="FileUpload附件" runat="server" Width="200px" />
  2.  
  3. protected void btnEdit_Click(object sender, EventArgs e)
  4. {
  5. if (txtCarPlateNumber.Text.Trim() == "")
  6. {
  7. ClientScript.RegisterStartupScript(GetType(), "", "alert('请输入车牌号!');", true);
  8. return;
  9. }
  10. int Id = 0;
  11. if (string.IsNullOrEmpty(Request.Params["Id"]) == false)
  12. {
  13. Id = int.Parse(Request.Params["Id"]);
  14. }
  15. ModelBlackWhiteList model = new ModelBlackWhiteList();
  16. model.Id = Id;
  17. model.CarPlateType = ddlCarPlateType.SelectedItem.Text;
  18. model.CarPlateNumber = txtCarPlateNumber.Text.Trim();
  19. model.Company = txtCompany.Text.Trim();
  20. model.BWFlag = ddlBWFlag.SelectedItem.Value;
  21. model.OperatorName = this.UserLogin;
  22. model.CreateDateTime = DateTime.Now;
  23.  
  24. string CommandName = Request.Params["CommandName"].ToString();
  25. switch (CommandName)
  26. {
  27. case "Upd":
  28. {
  29. if (FileUpload附件.PostedFile.FileName.Trim().Length != 0)
  30. {
  31. string savePath;
  32. string fileName = DateTime.Now.ToString("yyyyMMddHHmmssms");
  33. if (FileUpload附件.HasFile && FileUpload附件.PostedFile.FileName.Contains(".jpg"))
  34. {
  35. savePath = Server.MapPath("~/Upload/");//指定上传文件在服务器上的保存路径
  36. //检查服务器上是否存在这个物理路径,如果不存在则创建
  37. if (!System.IO.Directory.Exists(savePath))
  38. {
  39. System.IO.Directory.CreateDirectory(savePath);
  40. }
  41. savePath = savePath + fileName + ".jpg";
  42. FileUpload附件.SaveAs(savePath);
  43. model.CarPicPath = "/Upload /" + fileName + ".jpg";
  44. }
  45. else
  46. {
  47. ClientScript.RegisterStartupScript(GetType(), "", "alert('请选择JPG图片文件!');", true);
  48. return;
  49. }
  50. }
  51. int result = SqlSugarClientHelper.SqlDBConnection.Updateable<ModelBlackWhiteList>(model).ExecuteCommand();
  52. if (result > 0)
  53. {
  54. ClientScript.RegisterStartupScript(GetType(), "", "alert('保存成功!');window.location = 'BlackWhiteListManage.aspx';", true);
  55. }
  56. else
  57. {
  58. ClientScript.RegisterStartupScript(GetType(), "", "alert('保存失败!');", true);
  59. }
  60. break;
  61. }
  62. case "New":
  63. {
  64. if (FileUpload附件.PostedFile.FileName.Trim().Length != 0)
  65. {
  66. string savePath;
  67. string fileName = DateTime.Now.ToString("yyyyMMddHHmmssms");
  68. if (FileUpload附件.HasFile && FileUpload附件.PostedFile.FileName.Contains(".jpg"))
  69. {
  70. savePath = Server.MapPath("~/Upload/BWFLag/");//指定上传文件在服务器上的保存路径
  71. //检查服务器上是否存在这个物理路径,如果不存在则创建
  72. if (!System.IO.Directory.Exists(savePath))
  73. {
  74. System.IO.Directory.CreateDirectory(savePath);
  75. }
  76. savePath = savePath + fileName + ".jpg";
  77. FileUpload附件.SaveAs(savePath);
  78. model.CarPicPath = "/Upload/BWFLag/" + fileName + ".jpg";
  79. }
  80. else
  81. {
  82. ClientScript.RegisterStartupScript(GetType(), "", "alert('请选择JPG图片文件!');", true);
  83. return;
  84. }
  85. }
  86. int result = SqlSugarClientHelper.SqlDBConnection.Insertable<ModelBlackWhiteList>(model).ExecuteCommand();
  87. if (result > 0)
  88. {
  89. ClientScript.RegisterStartupScript(GetType(), "", "alert('保存成功!');window.location = 'BlackWhiteListManage.aspx';", true);
  90. }
  91. else
  92. {
  93. ClientScript.RegisterStartupScript(GetType(), "", "alert('保存失败!');", true);
  94. }
  95. break;
  96. }
  97. }
  98. }

 

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号