zoukankan      html  css  js  c++  java
  • asp:FileUpload 上次图片

     <asp:FileUpload ID="FileUpload附件" runat="server" Width="200px" />
    
    protected void btnEdit_Click(object sender, EventArgs e)
            {
                if (txtCarPlateNumber.Text.Trim() == "")
                {
                    ClientScript.RegisterStartupScript(GetType(), "", "alert('请输入车牌号!');", true);
                    return;
                }
                int Id = 0;
                if (string.IsNullOrEmpty(Request.Params["Id"]) == false)
                {
                    Id = int.Parse(Request.Params["Id"]);
                }
                ModelBlackWhiteList model = new ModelBlackWhiteList();
                model.Id = Id;
                model.CarPlateType = ddlCarPlateType.SelectedItem.Text;
                model.CarPlateNumber = txtCarPlateNumber.Text.Trim();
                model.Company = txtCompany.Text.Trim();
                model.BWFlag = ddlBWFlag.SelectedItem.Value;
                model.OperatorName = this.UserLogin;
                model.CreateDateTime = DateTime.Now;
    
                string CommandName = Request.Params["CommandName"].ToString();
                switch (CommandName)
                {
                    case "Upd":
                        {
                            if (FileUpload附件.PostedFile.FileName.Trim().Length != 0)
                            {
                                string savePath;
                                string fileName = DateTime.Now.ToString("yyyyMMddHHmmssms");
                                if (FileUpload附件.HasFile && FileUpload附件.PostedFile.FileName.Contains(".jpg"))
                                {
                                    savePath = Server.MapPath("~/Upload/");//指定上传文件在服务器上的保存路径
                                                                           //检查服务器上是否存在这个物理路径,如果不存在则创建
                                    if (!System.IO.Directory.Exists(savePath))
                                    {
                                        System.IO.Directory.CreateDirectory(savePath);
                                    }
                                    savePath = savePath + fileName + ".jpg";
                                    FileUpload附件.SaveAs(savePath);
                                    model.CarPicPath = "/Upload /" + fileName + ".jpg";
                                }
                                else
                                {
                                    ClientScript.RegisterStartupScript(GetType(), "", "alert('请选择JPG图片文件!');", true);
                                    return;
                                }
                            }
                            int result = SqlSugarClientHelper.SqlDBConnection.Updateable<ModelBlackWhiteList>(model).ExecuteCommand();
                            if (result > 0)
                            {
                                ClientScript.RegisterStartupScript(GetType(), "", "alert('保存成功!');window.location = 'BlackWhiteListManage.aspx';", true);
                            }
                            else
                            {
                                ClientScript.RegisterStartupScript(GetType(), "", "alert('保存失败!');", true);
                            }
                            break;
                        }
                    case "New":
                        {
                            if (FileUpload附件.PostedFile.FileName.Trim().Length != 0)
                            {
                                string savePath;
                                string fileName = DateTime.Now.ToString("yyyyMMddHHmmssms");
                                if (FileUpload附件.HasFile && FileUpload附件.PostedFile.FileName.Contains(".jpg"))
                                {
                                    savePath = Server.MapPath("~/Upload/BWFLag/");//指定上传文件在服务器上的保存路径
                                                                                  //检查服务器上是否存在这个物理路径,如果不存在则创建
                                    if (!System.IO.Directory.Exists(savePath))
                                    {
                                        System.IO.Directory.CreateDirectory(savePath);
                                    }
                                    savePath = savePath + fileName + ".jpg";
                                    FileUpload附件.SaveAs(savePath);
                                    model.CarPicPath = "/Upload/BWFLag/" + fileName + ".jpg";
                                }
                                else
                                {
                                    ClientScript.RegisterStartupScript(GetType(), "", "alert('请选择JPG图片文件!');", true);
                                    return;
                                }
                            }
                            int result = SqlSugarClientHelper.SqlDBConnection.Insertable<ModelBlackWhiteList>(model).ExecuteCommand();
                            if (result > 0)
                            {
                                ClientScript.RegisterStartupScript(GetType(), "", "alert('保存成功!');window.location = 'BlackWhiteListManage.aspx';", true);
                            }
                            else
                            {
                                ClientScript.RegisterStartupScript(GetType(), "", "alert('保存失败!');", true);
                            }
                            break;
                        }
                }
            }
    
  • 相关阅读:
    C#的ugui与XLua整合的案例
    关于C#调用XLua的函数抛出attempt to call a nil value (global 'print')
    关于文件上传的坑,tomcat一重启图片就消失
    linux服务器安装zookeeper本地项目远程连接
    使用eazyExcel读取数据结合mybatis批量保存到数据库(优化批量保存)
    jpa set值持久化解决办法
    cascade级联关系
    @JoinTable和@JoinColumn
    json操作容易出现的细微问题
    attr和prop的区别
  • 原文地址:https://www.cnblogs.com/zclaude/p/9894948.html
Copyright © 2011-2022 走看看