目的: V80202D – 下載撤銷附加檔 - downloadFile2 – Cookie - 並顯示下載完成/失敗訊息
處理說明: 1>下載檔案(AMM_DFILES.DBLOB)
var Tmp_url = "../api/myAPI/downloadFile2?aTbl=" + Tmp_TblNM + "&Flds=" + Tmp_Flds + "&aCnd=" + Tmp_Cnd;
document.location = Tmp_url;
2> 下載完成,顯示訊息
var mask = new Ext.LoadMask(Ext.getBody(), {
msg: '檔案下載中, 請稍待...'
});
- var Tmp_Str = r_cookies('Rtn_Msg');
msg: '檔案下載中, 請稍待...'
});
- var Tmp_Str = r_cookies('Rtn_Msg');
1>*.js
/*
*SELECT AMMNO,DFNAME,DBLOB
FROM AMM_DFILES
WHERE 1=1;
*/
var Tmp_TblNM = "AMM_DFILES";
var Tmp_Flds = "DFNAME,DBLOB"
var Tmp_Cnd = " AND AMMNO=" + AA(cur_rec.data["AMMNO"]);
try {
var Tmp_url = "../api/myAPI/downloadFile2?aTbl=" + Tmp_TblNM + "&Flds=" + Tmp_Flds + "&aCnd=" + Tmp_Cnd;
document.location = Tmp_url;
var mask = new Ext.LoadMask(Ext.getBody(), {
msg: '檔案下載中, 請稍待...'
});
mask.show();//使用 mask 需手動呼叫show() 方法下
var timer = setInterval(function () {
//timer = null;
//若資料庫已更新完成, 則 Email 委約==6 & Email 委約<>6
var Tmp_Str = r_cookies('Rtn_Msg');
console.log("cookies Rtn_Msg =", Tmp_Str);
if (!checkisnull(Tmp_Str)) {
mask.hide();
mysuccessalert(Tmp_Str);
clearInterval(timer); //不再重覆執行
}
}, 1000) // end of timer
} // end of try
catch (e)
{
var Tmp_Str = "下載檔案失敗!!<br>"
+ "AMM單號(" + cur_rec.data["AMMNO"] + ")<br>";
throw Tmp_Str;
} //檔案無法讀取,仍會下載 byte=0
2>*.cs
//取得 Table 的 FILEBODY 欄位值 - 不含 SQL
[HttpGet]
public void downloadFile2(string aTbl, string Flds, string aCnd)
{
string[] Ary = Flds.Split(',');
string fnm = Ary[0]; //檔案名 稱
string fbdy = Ary[1]; //檔案內容
string cnd = Repltag_vch(aCnd);
string Strsql = "select " + Flds + " from " + aTbl + " where 1=1 " + cnd;
string Tmp_CntSql = "select count(*) from " + aTbl + " where 1=1 " + cnd;
string Tmp_Str;
int Tmp_cnt;
HttpCookie MyCookie;
try
{
Tmp_cnt = int.Parse(myfunc.SqlValue(Tmp_CntSql));
if (Tmp_cnt>=0)
{
//必需先加入 Cookie , 再 downloadFile
//--> 因 downloadFile 會 HttpContext.Current.Response.End(); ,
//所以 要先加 Cookie , 再 downloadFile
Tmp_Str = "檔案下載完成!!<br>";
MyCookie = new HttpCookie("Rtn_Msg", HttpUtility.UrlEncode(Tmp_Str));
HttpContext.Current.Response.Cookies.Add(MyCookie);
HttpContext.Current.ApplicationInstance.CompleteRequest();
downloadFile(Strsql, fnm, fbdy);
}
else
{
Tmp_Str = "檔案不存在,請檢核!!<br>";
MyCookie = new HttpCookie("Rtn_Msg", HttpUtility.UrlEncode(Tmp_Str));
HttpContext.Current.Response.Cookies.Add(MyCookie);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
catch (Exception ex)
{
Tmp_Str = ex.Message;
if (Tmp_Str.IndexOf("DBNull") > -1)
Tmp_Str = "檔案內容為空白,敬請檢核!!<br>";
MyCookie = new HttpCookie("Rtn_Msg", HttpUtility.UrlEncode(Tmp_Str));
HttpContext.Current.Response.Cookies.Add(MyCookie);
HttpContext.Current.ApplicationInstance.CompleteRequest();
// throw ex;
} //檔案無法讀取,仍會下載 byte=0
finally
{ }
}
沒有留言:
張貼留言