예제 #1
0
    protected void btnUploadPhoto_Click(object sender, ImageClickEventArgs e)
    {
        //string companyCD = string.Empty;
        //获取公司代码
        try
        {
            companyCD = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD;
        }
        catch
        {
            companyCD = "AAAAAA";
        }
        //获取公司文件相关信息
        DataTable dtFileInfo = UploadFileBus.GetCompanyUploadFileInfo();

        //
        if (dtFileInfo == null || dtFileInfo.Rows.Count < 1)
        {
        }
        //文件个数
        //int docNum = GetSafeData.ValidateDataRow_Int(dtFileInfo.Rows[0], "MaxDocNum");
        //文件总大小
        //long totalSize = GetSafeData.ValidateDataRow_Long(dtFileInfo.Rows[0], "MaxDocSize");
        //单个文件大小
        long singleSize = GetSafeData.ValidateDataRow_Long(dtFileInfo.Rows[0], "SingleDocSize");
        //文件保存路径
        string savePath = Server.MapPath("~/Images/Photo/" + companyCD);//GetSafeData.ValidateDataRow_String(dtFileInfo.Rows[0], "DocSavePath");


        //获取控件上的文件对象
        HttpPostedFile hpFile = flLocalFile.PostedFile;


        string docName = hpFile.FileName.Substring(hpFile.FileName.LastIndexOf("\\") + 1);

        //校验文件大小
        string checkResult = CheckCompanyFile(hpFile, singleSize);//, savePath, totalSize,  docNum);

        //大小超过允许范围时
        if (!string.IsNullOrEmpty(checkResult))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "UploadFaild", "<script language=javascript>popMsgObj.ShowMsg('"
                                               + checkResult + "');</script>");
            return;
        }
        //上传文件并获取文件相对路径
        string fileName = SaveUploadPhoto(hpFile, savePath);

        //上传未成功
        if (string.IsNullOrEmpty(fileName))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "UploadFaild", "<script language=javascript>popMsgObj.ShowMsg('"
                                               + ConstUtil.UPLOAD_FILE_ERROR_TYPE + "');</script>");
            return;
        }
        //隐藏域中写入文件相对路径
        uploadFileUrl.Value = fileName;
        //上传文件名
        uploadDocName.Value = docName;
        //执行返回函数
        ClientScript.RegisterStartupScript(this.GetType(), "UploadSucc", "<script language=javascript>DoConfirm();</script>");
    }