挂单查询
This commit is contained in:
@@ -222,34 +222,42 @@ public class ShuWenController : ApiController
|
||||
[Route("api/shuwen/download")]
|
||||
public HttpResponseMessage DownloadShuWenWord(int? activitynum)
|
||||
{
|
||||
var data = _db.ShuWen.Where(a => a.ActivityNum == activitynum).FirstOrDefault();
|
||||
if (data == null)
|
||||
try
|
||||
{
|
||||
//return;
|
||||
}
|
||||
string json = data.ShuWenList;
|
||||
string ActivityName = _db.activities.Where(a => a.num == data.ActivityNum).FirstOrDefault().subject;
|
||||
if (json == null)
|
||||
{
|
||||
//return;
|
||||
}
|
||||
string fileName = $"疏文名單_{DateTime.Now:yyyyMMddHHmmss}.docx";
|
||||
|
||||
var stream = new MemoryStream();
|
||||
GenerateShuWenWord_OpenXml(json, stream, ActivityName);
|
||||
stream.Position = 0;
|
||||
var response = new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StreamContent(stream)
|
||||
};
|
||||
response.Content.Headers.ContentType =
|
||||
new System.Net.Http.Headers.MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||
response.Content.Headers.ContentDisposition =
|
||||
new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
|
||||
var data = _db.ShuWen.Where(a => a.ActivityNum == activitynum).FirstOrDefault();
|
||||
if (data == null)
|
||||
{
|
||||
FileName = fileName
|
||||
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "活動編號不能為空");
|
||||
}
|
||||
string json = data.ShuWenList;
|
||||
string ActivityName = _db.activities.Where(a => a.num == data.ActivityNum).FirstOrDefault().subject;
|
||||
if (json == null)
|
||||
{
|
||||
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "疏文列表为空,无法生成 Word");
|
||||
}
|
||||
string fileName = $"疏文名單_{DateTime.Now:yyyyMMddHHmmss}.docx";
|
||||
|
||||
var stream = new MemoryStream();
|
||||
GenerateShuWenWord_OpenXml(json, stream, ActivityName);
|
||||
stream.Position = 0;
|
||||
var response = new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StreamContent(stream)
|
||||
};
|
||||
return response;
|
||||
response.Content.Headers.ContentType =
|
||||
new System.Net.Http.Headers.MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||
response.Content.Headers.ContentDisposition =
|
||||
new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
|
||||
{
|
||||
FileName = fileName
|
||||
};
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void GenerateShuWenWord_OpenXml(string json, Stream outputStream, string ActivityName ="")
|
||||
|
||||
Reference in New Issue
Block a user