目的: V20305M – 匯入PDM_BOM需求物料
–呼叫WebService WS_PDM02
–傳回文字檔*.TXT
-*.TXT文字格式(左靠/右靠)
-*.TXT文字格式(左靠/右靠)
處理說明: 1>呼叫 WebService - myfunc.getWS_PDM02
DataSet ds = myfunc.getWS_PDM02(Tmp_PN, Tmp_ECNO, Tmp_CDCODE,..);
DataTable Tmp_dt1 = ds.Tables["T1"];
2>*.TXT 檔 文字格式 - 固定長度_左靠
Tmp_Str = "AMM單號".PadRight(16, ' ')+"件號".PadRight(16,' ')+..+ "\n\r";
File.AppendAllText(Tmp_out_pFName, Tmp_Str);
Tmp_Str = "=============================================" + "\n\r";
File.AppendAllText(Tmp_out_pFName, Tmp_Str);
3>傳回 *.TXT 檔 -下載 *.TXT 檔案
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();
1>myfunc.cs 呼叫WebService WS_PDM02 - getWS_PDM02
/*
// 函式名稱: getWS_PDM02
1>傳入參數:
itm_id: 件號 ec_id: ECNO status: 情況碼
prodid: 機種 numberS: 機號 config: 專案配置 workloc: 生產工廠
2>傳回參數: ds
cmp_id: 子件號 itm_name: 子件號 qty: 需求數量
units: 單位 mroutinetype: 製程 mroutinetype_name: 製程名稱
*/
public static dynamic getWS_PDM02(string par_itm_id, string par_ec_id,string par_status,string par_prodid,string par_numberS, string par_config,string par_workloc)
{
//DataSet ds=new DataSet();
DataSet ds = null; //接收 WebService 的回傳值
if (!myfunc.checkisnull(par_itm_id))
{
PLM_WS.ServiceSoapClient PLM_WS = new PLM_WS.ServiceSoapClient();
try
{
ds = PLM_WS.AMM_PDM02(par_itm_id, par_ec_id, par_status, par_prodid, par_numberS, par_config, par_workloc);
myfunc.ds2T1C(ds);
}
catch (Exception ex)
{
throw ex;
} //throw ex;
finally
{ };
}
return ds;
}
2>*.cs
DataSet ds = myfunc.getWS_PDM02(Tmp_PN, Tmp_ECNO, Tmp_CDCODE,..);
DataTable Tmp_dt1 = ds.Tables["T1"];
//匯出文字
string Tmp_out_FName = "V20305_匯入PDM_BOM結果_log.txt"; //處理_log.txt
string documentPath = HttpContext.Current.Server.MapPath("~") + "document\\"; //取得實實的路徑
string Tmp_out_pFName = documentPath + Tmp_out_FName; //含 path 的Filename
if (File.Exists(Tmp_out_pFName))
{
File.Delete(Tmp_out_pFName);
}
string Tmp_Str;
Tmp_Str = "AMM單號".PadRight(16, ' ')+"件號".PadRight(16,' ')
+"匯入情況(Y/N)".PadRight(16,' ')+"匯入說明".PadRight(40,' ')
+ "\n\r";
File.AppendAllText(Tmp_out_pFName, Tmp_Str); //不用 sw , 改用 File.AppendAllText
Tmp_Str ="==================================================" + "\n\r";
File.AppendAllText(Tmp_out_pFName, Tmp_Str); //不用 sw , 改用 File.AppendAllText
3>*.js
//匯入PDM_BOM資料
function V20305M_OK() {
var cur_recs = Ext.getCmp('grid_M').getSelectionModel().getSelection();
if (cur_recs.length == 0) {
mywarnalert("請先選擇要匯入PDM_BOM的資料");
return false;
}
var cur_rec;
let Tmp_DataAry1 = [];
for (let i = 0; i <= cur_recs.length - 1; i++) {
console.log("i:", i);
cur_rec = cur_recs[i];
Tmp_DataAry1.push(cur_rec.data);
} // for i=0 to
let Tmp_DataString1 = JSON.stringify(Tmp_DataAry1);
var np1 = {};
np1["DataString1"] = Tmp_DataString1;
np1["AMMNO"] = Tmp_AMMNO;
np1["RPNOAF"] = Tmp_RPNOAF;
np1["EIAC"] = Tmp_EIAC;
np1["sub_PN"] = Ext.getCmp("sub_PN").getValue(); //件號
//np1["sub_EONO"] = Ext.getCmp("sub_EONO").getValue(); //EONO
//np1["sub_CDCODE"] = Ext.getCmp("sub_CDCODE").getValue(); //情況碼
//?? 測試用
np1["sub_EONO"] = ""; //EONO
np1["sub_CDCODE"] =""; //情況碼
np1["sub_PDM_CONFIG"] = Ext.getCmp("sub_PDM_CONFIG").getValue(); //專案配置
np1["sub_PDMPDTP"] = Ext.getCmp("sub_PDMPDTP").getValue(); //機種
np1["sub_ACNO"] = Ext.getCmp("sub_ACNO").getValue(); //機號
np1["sub_rd_TYPE"] = (Ext.getCmp("sub_rd_TYPE").getValue()).sub_rd_TYPE;
np1["sub_rd_SYS"] = (Ext.getCmp("sub_rd_SYS").getValue()).sub_rd_SYS;
//因為要傳回 *_log.txt ..所以改用 submit , 由 cookie 傳回訊息
var Tmp_url = '../../api/V20305MAPI/INS_AMM_UOC_AMM_UOCD'
Ext.getCmp('s_form').submit({
method: "POST",
url: Tmp_url, //更新資料庫單況
standardSubmit: true,
params: np1,
async: false,
}); //end of Ext.Ajax.Request
//顯示結果訊息..
var Tmp_Str = '資料處理中..<br>'
+ '可能需要數十分鐘<br> '
+ ' 請稍待...<br>';
var mask = new Ext.LoadMask(Ext.getBody(), {
msg: Tmp_Str
});
mask.show();//使用 mask 需手動呼叫show() 方法下
//每1秒檢核一次,是否已完成, 若已完成,則不再檢核
var timer = setInterval(function () {
var r = r_cookies('Rtn_Msg');
if (!checkisnull(r)) {
mysuccessalert(r);
clearInterval(timer);
mask.hide();
timer = null;
}
}, 1000); //1000ms = 1sec
} // end of function V20305M_OK()
沒有留言:
張貼留言