• 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;
                        }
                }
            }
    
  • 相关阅读:
    spring boot三种方式设置跨域
    完整卸载Mysql
    【OBIEE】OBIEE集成Echarts作图
    【OBIEE】BIEE培训(一)
    【Oracle】Oracle物化视图
    【Oracle】oracle11g安装过程提示swap size 检查失败问题
    【Linux】centOS7下安装GUI图形界面
    【Nginx】Linux环境搭建nginx负载
    【oracle】Oracle创建带参数视图
    抢票:搭建github最火的12306项目
  • 原文地址:https://www.cnblogs.com/zclaude/p/9894948.html
Copyright © 2020-2023  润新知