Exemplo n.º 1
0
    protected void btnUp_Click(object sender, EventArgs e)
    {
        this.lblMsg.Text = "";
        this.isUpSucess = false;
        if (this.SingleLimit == "1" && this.selectedFiles.Items.Count > 0)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"本次文件上传只允许选择单个文件!\");", true);
            return;
        }

        int userId = this.currentUser.empId;
        int fileID = 0;
        string preFileNm = "";
        SFileData model = new SFileData();
        SSpaceBC spaceBC = new SSpaceBC();
         FileInfo file =null;
        try
        {
            //判断文件格式(0无限制、1图片)
            switch (this.FileType)
            {
                case "0":
                    break;
                case "1":
                    file=new FileInfo(this.File1.PostedFile.FileName);
                    string extension = file.Extension;
                    //查看文件格式是否存在与系统表“图片文件格式”中
                    SCommBB commBB = new SCommBB();
                    try
                    {
                        if (commBB.Query("select 1 from SImageFileType where fileExtension='" + extension + "'").Tables[0].Rows.Count == 0)
                        {
                            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"本次附件上传要求为图片格式文件,请重新选择!\");", true);
                            return;
                        }
                    }
                    finally
                    {
                        commBB.Dispose();
                    }
                    break;
                default:
                    break;
            }

            string  newfilenm="";
               // custno+"_"+ materialno+"_" +Size+file.Extension;

            if (materialno.ToString().Trim() == "")
            {
                newfilenm = custno + "_" + Size + file.Extension;
            }
            else
            {
                newfilenm=custno + "_" + materialno + "_" + Size + file.Extension;
            }
            fileID = spaceBC.UploadCustFile(model, this.File1.PostedFile, "upCustTag", userId, this.FileType == "1", newfilenm);

            if (fileID != 0)
            {
                preFileNm = newfilenm;
            }

            ListItem item = new ListItem();
            item.Text = preFileNm;
            item.Value = fileID.ToString();
            this.selectedFiles.Items.Add(item);

            this.isUpSucess = true;
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",1);", true);
            return;
        }
        finally
        {
            spaceBC.Dispose();
        }
    }