修改webservice

This commit is contained in:
2023-05-04 19:17:56 +08:00
parent 873a92c078
commit 8bf83936b2
11 changed files with 486 additions and 19 deletions
+88
View File
@@ -93,6 +93,51 @@ namespace BLL
}
}
public static void FileMoreInsert(byte[][] fileContextList, string attachUrl)
{
if (fileContextList != null && fileContextList.Count() > 0)
{
if (fileContextList.Length > 0)
{
string[] strs = attachUrl.Trim().Split(',');
int i = 0;
foreach (var item in fileContextList)
{
if (strs.Count() > i)
{
string physicalpath = Funs.RootPath;
//HttpContext.Current.Request.PhysicalApplicationPath;
string fullPath = physicalpath + strs[i];
if (!File.Exists(fullPath))
{
byte[] fileContext = item;
int index = fullPath.LastIndexOf("\\");
string filePath = fullPath.Substring(0, index);
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
//string savePath = fullPath + fileName;
//文件读写模式
System.IO.FileMode fileMode = System.IO.FileMode.Create;
//写入文件
using (System.IO.FileStream fs = new System.IO.FileStream(fullPath, fileMode, System.IO.FileAccess.Write))
{
fs.Write(fileContext, 0, fileContext.Length);
}
}
i++;
}
}
}
}
}
/// <summary>
/// 数据和附件插入到多附件表
/// </summary>
@@ -134,5 +179,48 @@ namespace BLL
}
}
}
public static void InsertAttachFile(string attachFileId, string dataId, string attachSource, string attachUrl, byte[][] fileContext)
{
var getAtt = Funs.DB.AttachFile.FirstOrDefault(x => x.AttachFileId == attachFileId);
if (getAtt != null)
{
Funs.DB.AttachFile.DeleteOnSubmit(getAtt);
Funs.DB.SubmitChanges();
}
//多附件
var attachFile = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == dataId);
if (attachFile == null && !string.IsNullOrEmpty(attachSource))
{
Model.AttachFile newAttachFile = new Model.AttachFile
{
AttachFileId = attachFileId,
ToKeyId = dataId,
AttachSource = attachSource,
AttachUrl = attachUrl
};
Funs.DB.AttachFile.InsertOnSubmit(newAttachFile);
Funs.DB.SubmitChanges();
////插入附件文件
BLL.FileInsertService.FileMoreInsert(fileContext, attachUrl);
}
else
{
if (attachFile.AttachUrl != attachUrl)
{
///删除附件文件
BLL.UploadAttachmentService.DeleteFile(Funs.RootPath, attachFile.AttachUrl);
////插入附件文件
BLL.FileInsertService.FileMoreInsert(fileContext, attachUrl);
attachFile.AttachSource = attachSource;
attachFile.AttachUrl = attachUrl;
Funs.DB.SubmitChanges();
}
}
}
}
}
+50
View File
@@ -103,5 +103,55 @@ namespace BLL
}
return fileContext;
}
public static byte[][] GetMoreFileArrayStructByAttachUrl(string attachUrl)
{
List<byte[]> fileContext = new List<byte[]>();
if (!String.IsNullOrEmpty(attachUrl))
{
string[] strs = attachUrl.Trim().Split(',');
foreach (var item in strs)
{
string filePath = string.Empty;
string physicalpath = Funs.RootPath;
//HttpContext.Current.Request.PhysicalApplicationPath;
filePath = physicalpath + item;
if (File.Exists(filePath))
{
FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo != null)
{
Stream stream = fileInfo.OpenRead();
if (stream != null)
{
//读取指定大小的文件流内容到uploadFile.Context以便上传
int b;
while (stream.Position > -1 && stream.Position < stream.Length)
{
if (stream.Length - stream.Position >= 20000000)
{
b = 20000000;
}
else
{
b = (int)(stream.Length - stream.Position);
}
byte[] filebyte = new byte[b];
stream.Read(filebyte, 0, b);
fileContext.Add(filebyte);
}
}
stream.Close();
}
}
}
}
return fileContext.ToArray();
}
}
}