移动单据,附件下载成功,但有些单据页面不显示图片。
金蝶云社区-Flong
Flong
0人赞赏了该文章 945次浏览 未经作者许可,禁止转载编辑于2017年03月21日 23:59:55

开发了移动单据,显示单据详细信息,将单据中附件也显示到移动端页面中。 测试发现,有些单据的附件,在移动端是正常显示,但有些单据的附件不显示。
附件保存在数据库中,查询数据库T_BAS_ATTACHMENT,该单据ID是有记录的。

在本地调试代码发现,单据的附件已经下载到本地临时目录,只是执行完绑定到附件后,页面并没有显示附件。


为什么有些单据的附件显示,有些不显示?这种情况是什么原因造成的?

以下是下载并绑定到控件的代码:
[code] // 获取文件上传的临时目录

string tempDirPath = HttpContext.Current.Request.PhysicalApplicationPath + KeyConst.TEMPFILEPATH;

string interID = (dynamicObject as DynamicObject)["ID"].ToString();// "D00001";// 继《移动附件入门_上传篇》中的关联单据/基础资料ID

// 加载数据库中附件数据

var filter = OQLFilter.CreateHeadEntityFilter(string.Format("FInterID = '{0}'", interID));
var dyns = BusinessDataServiceHelper.Load(this.Context, FormIdConst.BOS_Attachment, null, filter);

List fileList = new List();
StringBuilder sb = new StringBuilder();

foreach (var dyn in dyns)
{

byte[] dataBuff = null;

if (Convert.ToInt16(dyn["FileStorage"]) == 1)
{

// 判断是否启用文件服务器

if (Kingdee.BOS.ServiceHelper.FileServer.FileServerHelper.UsedFileServer(this.Context))
{
// 采用文件服务器存储

var service = new UpDownloadService();

TFileInfo tFile = new TFileInfo()
{
FileId = dyn["FileId"].ToString(),
CTX = this.Context
};
dataBuff = service.GetFileData(tFile);
}
}
else
{
// 不是采用文件服务器存储,则尝试直接取数据
if (dyn["Attachment"] != null)
{
dataBuff = (byte[])dyn["Attachment"];
}
}

if (dataBuff == null)
{

sb.AppendLine("未能下载附件:" + dyn["AttachmentName"]);

continue;

}
// 拼接文件名
string fullName = System.IO.Path.Combine(tempDirPath, string.Format("{0}_{1}_{2}", this.Context.DBId, dyn["Id"], dyn["AttachmentName"]));
// 将附件保存至临时文件夹
System.IO.File.WriteAllBytes(fullName, dataBuff);
fileList.Add(new File() { Name = dyn["AttachmentName"].ToString(), Type = dyn["ExtName"].ToString() });
}

AccessoryData data = new AccessoryData()
{
FormId = this.View.BusinessInfo.GetForm().Id,
BillId = "PBUR_MobileSaleOrder",
Data = fileList
};

//将图片 绑定到附件控件
this.View.GetControl("F_PAEZ_FileUpdate").SetValue(data);

[/code]