欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp:FileUpload 上次图片

程序员文章站 2023-02-21 21:42:10
protected void btnEdit_Click(object sender, EventArgs e) { if (txtCarPlateNumber.Text.Trim() == "") { ClientScript.RegisterStartupScript(GetType(), ..... ......
 <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;
                    }
            }
        }