目的:V20305E-[請料提出]鈕
1>有問題時,輸出Log檔案&顯示cookie訊息 (Response 輸出 *.txt)
2>沒問題時,直接顯示cookie訊息,沒輸出HTML/檔案( Response無內容)
--> 不可執行 Response.End() , 否則畫面會呈現空白(黑螢幕)
3>Request & Response 說明
處理說明:
0>cookie 清成空白
Ext.util.Cookies.set("Rtn_Msg", "");
1>檢核有問題時,直接顯示cookie訊息, 無任何html/檔案輸出
--> 不可用 Response.End()
1.1>*.cs
Tmp_Str = "成功: [請料提出]鈕,檢核完成!!<br>";
MyCookie = new HttpCookie("Rtn_Msg", HttpUtility.UrlEncode(Tmp_Str));
HttpContext.Current.Response.Cookies.Add(MyCookie);
--> 不可用Response.End(); 因為沒有輸出內容(html/檔案)
1.2>*.js
if (r.indexOf("成功") > -1) {
Call_V20305E_T_Email(cur_rec);
2>檢核有問題時,輸出Log檔案&顯示
cookie訊息
2.1> *.cs
MyCookie = new HttpCookie("Rtn_Msg", HttpUtility.UrlEncode(Tmp_Str));
HttpContext.Current.Response.Cookies.Add(MyCookie);
HttpContext.Current.Response.AddHeader("Content-Disposition",
"attachment;filename=\""
+ HttpUtility.UrlEncode((string)Tmp_out_FName, System.Text.Encoding.UTF8)
+ "\"");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "text/plain";
HttpContext.Current.Response.WriteFile(Tmp_out_pFName);
HttpContext.Current.Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
2.2>*.js
var r = r_cookies('Rtn_Msg');
if (r.indexOf("錯誤") > -1) {
1>*.js
Ext.util.Cookies.set("Rtn_Msg", "");
var np = {};
np["AMMNO"] = nulltoStr(Tmp_AMMNO);
np["PN"] = nulltoStr(Tmp_PN);
Tmp_url = '../../api/V20305EAPI/CHECK_TLS';
//因為會下載檔案,所以用 submit
Ext.getCmp('s_form').submit({
method: "POST",
url: Tmp_url, //更新資料庫單況
standardSubmit: true,
params: np,
async: false,
}); //end of Ext.Ajax.Request
var mask = new Ext.LoadMask(Ext.getBody(), {
msg: '[請料提出]鈕,資料檢核中, 請稍待...'
});
mask.show();//使用 mask 需手動呼叫show() 方法下
var timer = setInterval(function () {
var r = r_cookies('Rtn_Msg');
console.log("cookies Rtn_Msg =", r);
//若有傳回值,則執行下一步驟
if (!checkisnull(r)) {
mask.hide();
clearInterval(timer);
if (r.indexOf("錯誤") > -1) {
mywarnalert(r);
return; //若有錯誤,則顯示錯誤訊息, 不再執行下一步騳
}
if (r.indexOf("成功") > -1) {
mysuccessalert(r);
Call_V20305E_T_Update();
Call_V20305E_T_Email(cur_rec);
return;
}
}
}, 1000) // end of timer
} // end of function Call_V20305E_A() {
2>*.cs
[HttpPost]
public void CHECK_TLS()
{
//匯出文字
string Tmp_out_FName = "V20305_請料提出_log.txt"; //處理_log.txt
string documentPath = HttpContext.Current.Server.MapPath("~") + "document\\"; //取得實實的路徑
string Tmp_out_pFName = documentPath + Tmp_out_FName; //含 path 的Filename
HttpCookie MyCookie;
MyCookie = new HttpCookie("Rtn_Msg", HttpUtility.UrlEncode("")); //cookie 清成空白
if (File.Exists(Tmp_out_pFName))
{
File.Delete(Tmp_out_pFName);
}
Tmp_Sql = " SELECT FIXNO "
+ " FROM AMM_SRO "
+ " WHERE 1 = 1 "
+ " AND AMMNO = " + myfunc.AA(Tmp_AMMNO);
Tmp_FIXNO = myfunc.SqlValue(Tmp_Sql);
if (myfunc.checkisnull(Tmp_FIXNO))
{
Tmp_Str = "錯誤: "
+ "AMM單號(" + Tmp_AMMNO + ")\r\n"
+ "的交修單號空白(AMM_SRO.FIXNO)\r\n"
+ "敬請檢核 !!\r\n";
File.AppendAllText(Tmp_out_pFName, Tmp_Str);
break;
}
if (myfunc.checkisnull(Tmp_Str))
{
Tmp_Str = "成功: [請料提出]鈕,檢核完成!!<br>";
MyCookie = new HttpCookie("Rtn_Msg", HttpUtility.UrlEncode(Tmp_Str));
HttpContext.Current.Response.Cookies.Add(MyCookie);
// 不可用 HttpContext.Current.Response.End(); , 因為無輸 HTML/檔案
// 否則會螢幕空白,黑螢幕
}
else
{ //若有錯誤,則下載 *.txt & 加入 cookie
MyCookie = new HttpCookie("Rtn_Msg", HttpUtility.UrlEncode(Tmp_Str));
HttpContext.Current.Response.Cookies.Add(MyCookie);
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode((string)Tmp_out_FName, System.Text.Encoding.UTF8) + "\"");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "text/plain";
HttpContext.Current.Response.WriteFile(Tmp_out_pFName);
HttpContext.Current.Response.End(); //輸出 HTML/檔案
HttpContext.Current.ApplicationInstance.CompleteRequest();
}