|
|
@ -307,6 +307,123 @@ namespace EasyBL.WEBAPP.SYS |
|
|
|
|
|
|
|
#endregion Upload 上傳文件
|
|
|
|
|
|
|
|
#region Upload 上傳匯款單
|
|
|
|
|
|
|
|
public HttpResponseMessage UploadRemittance(HttpContext c, string OrgID, string Account, string BookingID) |
|
|
|
{ |
|
|
|
|
|
|
|
SuccessResponseMessage srm = null; |
|
|
|
string sError = null; |
|
|
|
try |
|
|
|
{ |
|
|
|
//首先先确定请求里夹带的文件数量
|
|
|
|
var req = c.Request; |
|
|
|
var sSource = "MembersBooking"; |
|
|
|
var sOrgID = OrgID; //要帶token內的資料
|
|
|
|
var sUserID = Account; //要帶token內的資料
|
|
|
|
var sParentID = Guid.NewGuid().ToString(); |
|
|
|
var sServerPath = c.Server.MapPath("/"); |
|
|
|
var sRoot = sServerPath + "Document\\EurotranFile"; |
|
|
|
Common.FnCreateDir(sRoot + "\\" + sSource);//如果沒有該目錄就創建目錄
|
|
|
|
|
|
|
|
if (req.Files.Count > 0) |
|
|
|
{ |
|
|
|
|
|
|
|
var saFilesAdd = new List<OTB_SYS_Files>(); |
|
|
|
|
|
|
|
for (int index = 0; index < req.Files.Count; index++) |
|
|
|
{ |
|
|
|
var file = req.Files[index]; |
|
|
|
var sFileSizeName = ""; |
|
|
|
var sFileID = Guid.NewGuid().ToString();//檔案ID
|
|
|
|
var sFileName = Path.GetFileName(file.FileName);//檔案名稱+文件格式名稱
|
|
|
|
var sFileType = file.ContentType; //檔案類型
|
|
|
|
var iFileSize = file.ContentLength; //檔案大小
|
|
|
|
|
|
|
|
var KBSize = Math.Round((decimal)iFileSize / 1024, 1);//單位KB
|
|
|
|
|
|
|
|
if (KBSize < 1024) |
|
|
|
{ |
|
|
|
sFileSizeName = KBSize + "KB"; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var ComparisonSize = Math.Round((decimal)KBSize / 1024, 1);//單位MB
|
|
|
|
sFileSizeName = ComparisonSize + "MB"; |
|
|
|
} |
|
|
|
|
|
|
|
var sfileName = sFileName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); |
|
|
|
var sSubFileName = sfileName.LastOrDefault(); //副檔名
|
|
|
|
var sNewFileName = sFileID + '.' + sSubFileName; |
|
|
|
|
|
|
|
var sOutputPath = sRoot + "/" + sSource + "/" + sNewFileName; |
|
|
|
sOutputPath = System.Text.RegularExpressions.Regex.Replace(sOutputPath, @"//|/", @"\"); |
|
|
|
file.SaveAs(sOutputPath); |
|
|
|
|
|
|
|
var oFile = new OTB_SYS_Files |
|
|
|
{ |
|
|
|
OrgID = sOrgID, |
|
|
|
FileID = sFileID, |
|
|
|
ParentID = sParentID, |
|
|
|
SourceFrom = sSource, |
|
|
|
FileName = sFileName, |
|
|
|
SubFileName = sSubFileName, |
|
|
|
FilePath = sOutputPath.Replace(sServerPath, ""), |
|
|
|
FileType = sFileType, |
|
|
|
FileSize = iFileSize, |
|
|
|
FileSizeName = sFileSizeName, |
|
|
|
CreateUser = sUserID, |
|
|
|
CreateDate = DateTime.Now, |
|
|
|
ModifyUser = sUserID, |
|
|
|
ModifyDate = DateTime.Now |
|
|
|
}; |
|
|
|
saFilesAdd.Add(oFile); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var db = SugarBase.DB; |
|
|
|
var iRes = db.Insertable(saFilesAdd).ExecuteCommand(); |
|
|
|
|
|
|
|
//var userAccount = db.Queryable<SETB_SAL_BookingOnline>()
|
|
|
|
// .Where(x => x.BookingID == BookingID && x.Account == Account)
|
|
|
|
// .Single();
|
|
|
|
|
|
|
|
var userPic = db.Updateable<SETB_SAL_Payment>() |
|
|
|
.UpdateColumns(x => new SETB_SAL_Payment { Remittance = sParentID }) |
|
|
|
.Where(x => x.BookingID == BookingID) |
|
|
|
.ExecuteCommand(); |
|
|
|
|
|
|
|
if (iRes > 0) |
|
|
|
{ |
|
|
|
var rp = c.Response; |
|
|
|
var sJsonText = ServiceBase.JsonToString(saFilesAdd); |
|
|
|
rp.Write(sJsonText); |
|
|
|
rp.End(); |
|
|
|
} |
|
|
|
srm = new SuccessResponseMessage(null, null); |
|
|
|
srm.DATA.Add(BLWording.REL, iRes); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
sError = Util.GetLastExceptionMsg(ex); |
|
|
|
srm = new SuccessResponseMessage(null, null) |
|
|
|
{ |
|
|
|
STATUSCODE = (int)StatusCodeEnum.Error, |
|
|
|
MSG = StatusCodeEnum.Error.GetEnumText() |
|
|
|
}; |
|
|
|
srm.DATA.Add(BLWording.REL, ""); |
|
|
|
} |
|
|
|
return HttpResponseExtension.ToJson(JsonConvert.SerializeObject(srm)); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion Upload 上傳匯款單
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |