156 lines
5.4 KiB
C#
156 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using Weee.DAL;
|
|
using Weee.Models;
|
|
|
|
namespace Weee.Service
|
|
{
|
|
public class WeeeUserTemplatesService : WeeeDataAuthorizeService
|
|
{
|
|
private readonly EmailService.Service service = DependencyResolver.Current.GetService<EmailService.Service>();
|
|
|
|
|
|
public WeeeUserTemplatesService(WeeeDataContext d)
|
|
: base(d)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存用戶清冊和報告書
|
|
/// </summary>
|
|
/// <param name="fileName"></param>
|
|
|
|
public void SaveUserTemplate(string userId, string fileName)
|
|
{
|
|
int templateID = 0;
|
|
var fileInfo = _db.DocExcelTemplates.FirstOrDefault(f => f.FileName == fileName);
|
|
//if(fileInfo == null)
|
|
{
|
|
templateID = this.SaveDocExcelTemplate(fileName);
|
|
|
|
var userTemplateInfo = _db.UserLCADocExcelTemplates.FirstOrDefault(ut => ut.UserID == userId && ut.TemplateID == templateID);
|
|
if(userTemplateInfo == null)
|
|
{
|
|
var newUserTemplate = new UserLCADocExcelTemplate();
|
|
newUserTemplate.UserID = userId;
|
|
newUserTemplate.TemplateID = templateID;
|
|
|
|
_db.UserLCADocExcelTemplates.Add(newUserTemplate);
|
|
|
|
_db.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
public int SaveDocExcelTemplate(string fileName)
|
|
{
|
|
var newFile = new DocExcelTemplate();
|
|
newFile.FileName = fileName;
|
|
if(fileName.EndsWith(".docx") || fileName.EndsWith(".doc"))
|
|
{
|
|
newFile.IsDocDefaultTemplate = true;
|
|
}
|
|
if(fileName.EndsWith(".xlsx") || fileName.EndsWith("xls"))
|
|
{
|
|
newFile.IsExcelDefaultTemplate = true;
|
|
}
|
|
|
|
_db.DocExcelTemplates.Add(newFile);
|
|
_db.SaveChanges();
|
|
|
|
return newFile.ID;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 記錄盤查單位上傳的壓縮檔
|
|
/// </summary>
|
|
/// <param name="lcaId"></param>
|
|
/// <param name="fileName"></param>
|
|
internal void SaveUploadZipRreport(int lcaId, string fileName)
|
|
{
|
|
if(lcaId >0)
|
|
{
|
|
var lcaInfo = _db.LCAs.FirstOrDefault(l => l.ID == lcaId);
|
|
if(lcaInfo != null)
|
|
{
|
|
lcaInfo.UploadZipReportUrl = fileName;
|
|
//_db.LCAs.Attach(lcaInfo);
|
|
_db.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 獲取查證單位回覆壓縮檔
|
|
/// </summary>
|
|
/// <param name="lcaId"></param>
|
|
internal string DownloadZipReplyReport(int lcaId, string baseUrl)
|
|
{
|
|
string url = "";
|
|
try
|
|
{
|
|
if (lcaId > 0)
|
|
{
|
|
var lcaInfo = _db.LCAs.FirstOrDefault(l => l.ID == lcaId);
|
|
if (lcaInfo != null)
|
|
{
|
|
string relativeUrl = lcaInfo.CertificationFeedbackZipUrl != null && lcaInfo.CertificationFeedbackZipUrl.Trim() != "" ? lcaInfo.CertificationFeedbackZipUrl.Trim() : "";
|
|
string actPath = System.Web.HttpContext.Current.Request.Url.Authority;
|
|
string fullPath = HttpContext.Current.Request.Url.ToString();
|
|
string protocolName = fullPath.Substring(0, fullPath.IndexOf("//") + 2);
|
|
actPath = protocolName + actPath;
|
|
if (relativeUrl != "")
|
|
{
|
|
url = actPath + baseUrl + relativeUrl;
|
|
}
|
|
return url;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return url;
|
|
throw;
|
|
}
|
|
return url;
|
|
}
|
|
/// <summary>
|
|
/// 下載原上傳給查證單位的壓縮檔
|
|
/// </summary>
|
|
/// <param name="lcaId"></param>
|
|
internal string DownloadZipReport(int lcaId, string baseUrl)
|
|
{
|
|
string url = "";
|
|
try
|
|
{
|
|
if (lcaId > 0)
|
|
{
|
|
var lcaInfo = _db.LCAs.FirstOrDefault(l => l.ID == lcaId);
|
|
if (lcaInfo != null)
|
|
{
|
|
string tmpS = lcaInfo.UploadZipReportUrl + "";
|
|
tmpS = tmpS.Trim();
|
|
string relativeUrl = tmpS;// lcaInfo.UploadZipReportUrl != null && lcaInfo.UploadZipReportUrl.Trim() != "" ? lcaInfo.UploadZipReportUrl.Trim() : "";
|
|
string actPath = System.Web.HttpContext.Current.Request.Url.Authority;
|
|
string fullPath = HttpContext.Current.Request.Url.ToString();
|
|
string protocolName = fullPath.Substring(0, fullPath.IndexOf("//") + 2);
|
|
actPath = protocolName + actPath;
|
|
if (relativeUrl != "")
|
|
{
|
|
url = actPath + baseUrl+ relativeUrl;
|
|
}
|
|
return url;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return url;
|
|
throw;
|
|
}
|
|
return url;
|
|
}
|
|
}
|
|
} |