private void btnPO_Click(object sender, EventArgs e) { sapConnClass sc = new sapConnClass(); var rfcPara = sc.setParaToConn(connClient); var rfcDest = RfcDestinationManager.GetDestination(rfcPara); var rfcRepo = rfcDest.Repository; IRfcFunction getPORFC = null; // rfc 函數名稱 getPORFC = rfcRepo.CreateFunction(getPODetail); //輸入參數:工單號碼 getPORFC.SetValue("P_AUFNR", txtAufnr.Text.ToString().Trim()); // Call function. getPORFC.Invoke(rfcDest); //回傳內表 IRfcTable ITAB = getPORFC.GetTable("ITAB"); DataTable dt = new DataTable(); dt.Columns.Add("作業號碼"); dt.Columns.Add("作業短文"); dt.Columns.Add("報工數量"); for (int i = 0; i <= ITAB.RowCount - 1; i++) { DataRow dr = dt.NewRow(); ITAB.CurrentIndex = i; dr["作業號碼"] = ITAB.GetString("VORNR").ToString(); dr["作業短文"] = ITAB.GetString("LTXA1").ToString(); dr["報工數量"] = ITAB.GetString("GMNGA").ToString(); dt.Rows.Add(dr); } dataGridView1.DataSource = dt.DefaultView; dataGridView1.ReadOnly = true; // rfc 回傳參數 string KDAUF = getPORFC.GetValue("KDAUF").ToString().TrimStart('0'); string KDPOS = getPORFC.GetValue("KDPOS").ToString().TrimStart('0'); string PSMNG = getPORFC.GetValue("PSMNG").ToString().TrimEnd('0').TrimEnd('.'); string DGLTS = getPORFC.GetValue("DGLTS").ToString(); string USER_LINE = getPORFC.GetValue("USER_LINE").ToString(); lblQty.Text = "工單數量:" + PSMNG; lblStatus.Text = "使用者自定狀態:" + USER_LINE; lblSoitme.Text = "銷售訂單/項次:" + KDAUF + " / " + KDPOS; lblEnddate.Text = "工單排程結束日期:" + DGLTS; }
private void Form1_Load(object sender, EventArgs e) { dt.Clear(); lblCusName.Text = lblCusNum.Text = lblEstDeliveryDate.Text = lblOrderNum.Text = ""; lbSalesText.Items.Clear(); if (isTesting) { this.Text += winFormVersion + " 測試版 " + "/ MSSQL: " + packingDB + " / SAP資料環境: " + sapDB; } else { this.Text += winFormVersion; } sapConn = new sapConnClass(); rfcPara = sapConn.setParaToConn(sapDB); rfcDest = RfcDestinationManager.GetDestination(rfcPara); rfcRepo = rfcDest.Repository; userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name; packingKey = DateTime.Now.ToString("yyyyMMdd").Trim() + DateTime.Now.ToString("HHmmss").Trim(); }
private void btnSubmin_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; string windowsAccount = Environment.UserName; sapConnClass sc = new sapConnClass(); var rfcPara = sc.setParaToConn(connClient); var rfcDest = RfcDestinationManager.GetDestination(rfcPara); var rfcRepo = rfcDest.Repository; var rfcMessageTypeDesc = ""; IRfcFunction confirmRFC = null; //函數名稱 confirmRFC = rfcRepo.CreateFunction(confirmCommit); //設置輸入參數 //工單號碼 confirmRFC.SetValue("AUFNR", txtAufnr.Text); //作業 confirmRFC.SetValue("OPERATION", txtOperation.Text); //確認良品率 confirmRFC.SetValue("YIELD", txtYield.Text); //廢品 confirmRFC.SetValue("SCRAP", txtScrap.Text); //重工 confirmRFC.SetValue("REWORK", txtRework.Text); //差異原因 confirmRFC.SetValue("REASON", comboBox1.SelectedValue); //數量單位 confirmRFC.SetValue("QUANUNIT", txtQuanunit.Text); //整備 confirmRFC.SetValue("ACTIVITY1", txtActivity1.Text); //整備單位 confirmRFC.SetValue("ACTIUNIT1", txtActiunit1.Text); //機器 confirmRFC.SetValue("ACTIVITY2", txtActivity2.Text); //機器單位 confirmRFC.SetValue("ACTIUNIT2", txtActiunit2.Text); //人工 confirmRFC.SetValue("ACTIVITY3", txtActivity3.Text); //人工單位 confirmRFC.SetValue("ACTIUNIT3", txtActiunit3.Text); //製造費用-其他 confirmRFC.SetValue("ACTIVITY4", txtActivity4.Text); //製造費用-其他單位 confirmRFC.SetValue("ACTIUNIT4", txtActiunit4.Text); //製造費用-間接人工 confirmRFC.SetValue("ACTIVITY5", txtActivity5.Text); //製造費用-間接人工單位 confirmRFC.SetValue("ACTIUNIT5", txtActiunit5.Text); //製造費用-折舊 confirmRFC.SetValue("ACTIVITY6", txtActivity6.Text); //製造費用-折舊單位 confirmRFC.SetValue("ACTIUNIT6", txtActiunit6.Text); //過帳日期 confirmRFC.SetValue("POSTG_DATE", Convert.ToDateTime(dtpPostgdate.Value.Date).ToString("yyyyMMdd")); //開時執行日期 confirmRFC.SetValue("START_DATE", txtStart_Date.Text); //開始執行時間 if (txtStart_Time.Text != "") { confirmRFC.SetValue("START_TIME", txtStart_Time.Text + "00"); } //完成執行日期 confirmRFC.SetValue("FIN_DATE", txtEnd_Date.Text); //完成執行時間 if (txtEnd_Time.Text != "") { confirmRFC.SetValue("FIN_TIME", txtEnd_Time.Text + "00"); } //休息時間 confirmRFC.SetValue("BREAK_TIME", txtBreakTime.Text); //休息時間單位 confirmRFC.SetValue("BREAK_UNIT", txtBreak_Unit.Text); //確認內文 confirmRFC.SetValue("CONF_TEXT", txtConf_Text.Text); //外部確認者 confirmRFC.SetValue("EX_CREATED_BY", windowsAccount); //送出報工資料 confirmRFC.Invoke(rfcDest); //回傳報工結果 var rfcMessageType = confirmRFC.GetValue("STYPE").ToString(); var rfcStatus = confirmRFC.GetValue("STATUS").ToString(); //檢查錯誤的物料異動 var dt = checkAFFW(txtAufnr.Text); var caRfcMessageType = ""; var caRfcStatus = ""; if (dt.Rows.Count > 0) { foreach (DataRow item in dt.Rows) { //回傳檢查結果 caRfcMessageType = item[0].ToString(); caRfcStatus = item[1].ToString() + item[2].ToString(); } } if (!string.IsNullOrEmpty(caRfcMessageType)) { rfcMessageType = caRfcMessageType; } switch (rfcMessageType) { case "S": rfcMessageTypeDesc = "成功"; break; case "E": rfcMessageTypeDesc = "錯誤"; if (!string.IsNullOrEmpty(caRfcStatus)) { rfcStatus = "物料異動有問題" + Environment.NewLine + caRfcStatus + Environment.NewLine + "請通知生管人員!!"; } break; case "W": rfcMessageTypeDesc = "警告"; break; case "I": rfcMessageTypeDesc = "資訊"; break; case "A": rfcMessageTypeDesc = "取消"; break; } if (rfcMessageType == "E" || rfcMessageType == "A") { btnSubmin.Enabled = false; MessageBox.Show(rfcStatus, rfcMessageTypeDesc); } else { MessageBox.Show(rfcStatus, rfcMessageTypeDesc); btnClear.PerformClick(); } Cursor.Current = Cursors.Default; }