• 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;
                        }
                }
            }
    
  • 相关阅读:
    【习题 6-10 UVA
    【习题 6-9 UVA
    【习题 6-8 UVA
    【NOIP2016练习】T1 挖金矿(二分答案)
    O(n)求1-n的逆元
    【NOIP2016练习】T1 string (计数)
    【NOIP2016练习】T2 跑跑步 (数论)
    【NOIP2016练习】T3 tree (树形DP)
    【CF679B】Theseus and labyrinth(数学,贪心)
    【NOIP2016练习】T2 旅行(树形DP,换根)
  • 原文地址:https://www.cnblogs.com/zclaude/p/9894948.html
Copyright © 2020-2023  润新知