/// <summary> /// To get the list of Products /// </summary> /// public List <SIISAPProdDTO> GetProducts() { List <SIISAPProdDTO> objProdutsList = new List <SIISAPProdDTO>(); var rfcDestination = RfcDestinationManager.GetDestination("SIISAP"); try { if (rfcDestination != null) { var getARNRfc = rfcDestination.Repository.CreateFunction("ZEHS_MSDS_PRTL_F4_PROD"); RfcSessionManager.BeginContext(rfcDestination); getARNRfc.Invoke(rfcDestination); var GetProductsTable = getARNRfc.GetTable("PRODS"); foreach (var row in GetProductsTable) { objProdutsList.Add(new SIISAPProdDTO { Product = row[0].ToString().Substring(row[0].ToString().IndexOf("=") + 1) }); var listinfo = objProdutsList; } RfcSessionManager.EndContext(rfcDestination); rfcDestination = null; } } catch (Exception ex) { FilePath = ConfigurationManager.AppSettings["siteUrl"]; WriteLog(FilePath, ex.Message); } return(objProdutsList); }
/// <summary> /// Start a new Session/Context. /// </summary> public void StartSession() { if (SessionProvider != null) { RfcSessionManager.RegisterSessionProvider(SessionProvider); } RfcSessionManager.BeginContext(_connection.Destination); }
/// <summary> /// 物料凭证查询 /// </summary> /// <param name="I_BKTXT">凭证抬头文本(凭证号与抬头文本至少填一个)</param> /// <param name="I_MBLNR">物料凭证(凭证号与抬头文本至少填一个)</param> /// <param name="I_MJAHR">物料凭证年度(选填)</param> /// <returns></returns> public static Result ZWMS_MKPF(string I_BKTXT, string I_MBLNR = "", string I_MJAHR = "") { Result result = new Result { Success = false }; try { //RfcDestination rfcDest = RfcDestinationManager.GetDestination(GetSapServerString()); RfcDestination rfcDest = RfcDestinationManager.GetDestination(ConfigurationManager.AppSettings["sapServer"].ToString()); //选择要调用的BAPI的名称 RfcFunctionMetadata rfMD = rfcDest.Repository.GetFunctionMetadata("ZWMS_MKPF"); //新建调用该BAPI的一个“实例” IRfcFunction irF = rfMD.CreateFunction(); //****************************** //输入参数设置 //****************************** irF.SetValue("I_MBLNR", I_MBLNR); //物料凭证 irF.SetValue("I_MJAHR", I_MJAHR); //物料凭证年度 irF.SetValue("I_BKTXT", I_BKTXT); //凭证抬头文本 IRfcTable irt = irF.GetTable("O_MKPF"); RfcSessionManager.BeginContext(rfcDest); irF.Invoke(rfcDest); //irfCommit.Invoke(rfcDest); RfcSessionManager.EndContext(rfcDest); result.Success = irF.GetString("RTYPE").ToUpper() == "S"; result.Message = irF.GetValue("RTMSG").ToString(); if (result.Success && irt.RowCount > 0) { var MBLNR = ""; for (int i = 0; i < irt.RowCount; i++) { irt.CurrentIndex = i; if (MBLNR.IsNotEmpty()) { MBLNR += "/"; } MBLNR += irt.GetString("MBLNR"); } result.Message = MBLNR; } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
// Kiểm tra dữ liệu tờ khai 10/KK-TNCN public static string Prc_check_data_tk10(string p_short_name, string p_tax_code, DataRow p_dr, RfcDestination p_sap, string p_ky_chot_dl) { // Bắt đầu một session RfcSessionManager.BeginContext(p_sap); RfcRepository v_repo = p_sap.Repository; IRfcFunction v_babi = v_repo.CreateFunction("ZBAPI_DETAIL_10_CHECK"); IRfcStructure v_struc = v_babi.GetStructure("I_DATA"); v_struc.SetValue("TAXPAYER_ID", p_dr["TIN"].ToString()); v_struc.SetValue("START_PERIOD", p_dr["KYKK_TU_NGAY"].ToString()); v_struc.SetValue("END_PERIOD", p_dr["KYKK_DEN_NGAY"].ToString()); v_struc.SetValue("DUE_DATE", p_dr["KYLB_TU_NGAY"].ToString()); v_struc.SetValue("A_F08_DOANH_THU_DU_KIEN", p_dr["DTHU_DKIEN"].ToString()); v_struc.SetValue("A_F09_TY_LE_TNCT_DU_KIEN", p_dr["TL_THNHAP_DKIEN"].ToString()); v_struc.SetValue("C_F10_TNCT_DU_KIEN", p_dr["THNHAP_CTHUE_DKIEN"].ToString()); v_struc.SetValue("C_F11_GIAM_TRU_GC", p_dr["GTRU_GCANH"].ToString()); v_struc.SetValue("A_F12_GIAM_TRU_BAN_THAN", p_dr["BAN_THAN"].ToString()); v_struc.SetValue("A_F13_GIAM_TRU_NPT", p_dr["PHU_THUOC"].ToString()); v_struc.SetValue("C_F14_THU_NHAP_TINH_THUE", p_dr["THNHAP_TTHUE_DKIEN"].ToString()); v_struc.SetValue("C_F15_THUE_TNCN_DU_KIEN", p_dr["TNCN"].ToString()); v_struc.SetValue("C_F16_THUE_PN_Q1", p_dr["PB01"].ToString()); v_struc.SetValue("C_F16_KY_TINH_THUE_Q1", p_dr["KYTT01"].ToString()); v_struc.SetValue("C_F16_KY_HACH_TOAN_Q1", p_dr["HT01"].ToString()); v_struc.SetValue("C_F16_HAN_NOP_Q1", p_dr["HN01"].ToString()); v_struc.SetValue("C_F17_THUE_PN_Q2", p_dr["PB02"].ToString()); v_struc.SetValue("C_F17_KY_TINH_THUE_Q2", p_dr["KYTT02"].ToString()); v_struc.SetValue("C_F17_KY_HACH_TOAN_Q2", p_dr["HT02"].ToString()); v_struc.SetValue("C_F17_HAN_NOP_Q2", p_dr["HN02"].ToString()); v_struc.SetValue("C_F18_THUE_PN_Q3", p_dr["PB03"].ToString()); v_struc.SetValue("C_F18_KY_TINH_THUE_Q3", p_dr["KYTT03"].ToString()); v_struc.SetValue("C_F18_KY_HACH_TOAN_Q3", p_dr["HT03"].ToString()); v_struc.SetValue("C_F18_HAN_NOP_Q3", p_dr["HN03"].ToString()); v_struc.SetValue("C_F19_THUE_PN_Q4", p_dr["PB04"].ToString()); v_struc.SetValue("C_F19_KY_TINH_THUE_Q4", p_dr["KYTT04"].ToString()); v_struc.SetValue("C_F19_KY_HACH_TOAN_Q4", p_dr["HT04"].ToString()); v_struc.SetValue("C_F19_HAN_NOP_Q4", p_dr["HN04"].ToString()); v_struc.SetValue("TAX_OFFICE_CODE", p_dr["MA_CQT"].ToString()); v_struc.SetValue("ROW_NUM", p_dr["STT"].ToString()); v_struc.SetValue("F13_MST_DLT", p_dr["MST_DTK"].ToString()); v_struc.SetValue("F20_HOP_DONG_DLT_SO", p_dr["HD_DLT_SO"].ToString()); v_struc.SetValue("F_HOP_DONG_DLT_NGAY", p_dr["HD_DLT_NGAY"].ToString()); v_struc.SetValue("REVERSE_AMOUNT", p_dr["RV_SO_TIEN"].ToString()); v_babi.SetValue("I_FILE", randomFileName(p_tax_code, p_ky_chot_dl)); v_babi.Invoke(p_sap); // Kết thúc một session RfcSessionManager.EndContext(p_sap); return(v_babi.GetString("E_ERROR_CODE")); }
public FunctionResult ExecuteInsert(string functionName, List <NTable> parameters, List <string> tableNames) { try { _function = _destination.Repository.CreateFunction(functionName); for (int i = 0; i < tableNames.Count; i++) { RfcStructureMetadata metaData = _destination.Repository.GetStructureMetadata(parameters[i].StructureName); IRfcTable tblInput = _function.GetTable(tableNames[i]); foreach (DataRow row in parameters[i].Parameters.Rows) { IRfcStructure structRow = metaData.CreateStructure(); foreach (DataColumn column in parameters[i].Parameters.Columns) { object obj = row[column]; structRow.SetValue(column.ToString(), obj); } tblInput.Append(structRow); } } RfcSessionManager.BeginContext(_destination); _function.Invoke(_destination); IRfcTable returnTable = _function.GetTable("NOTESRETURN"); return(new FunctionResult { IsSuccess = true, Data = new List <object> { returnTable } }); } catch (Exception ex) { return(new FunctionResult { IsSuccess = false, ErrorMessage = ex.ToString() }); } }
public static string CheckSAPConnection() { Innovator innovator = IomFactory.CreateInnovator(connection); string result; Item queryPart = innovator.newItem("GAG_SAPInterfaceSettings", "get"); queryPart.setProperty("gag_active", "Yes"); Item queryResult = queryPart.apply(); if (queryResult.isEmpty()) { result = "No SAP Connection Found. Contact Admin"; return(result); } try { Item sapResult = queryResult.getItemByIndex(0); RfcConfigParameters parameters = new RfcConfigParameters { [RfcConfigParameters.Name] = sapResult.getProperty("gag_name"), [RfcConfigParameters.User] = ConfigurationManager.AppSettings.Get("userSAP"), [RfcConfigParameters.Password] = ConfigurationManager.AppSettings.Get("passwordSAP"), [RfcConfigParameters.PeakConnectionsLimit] = sapResult.getProperty("gag_peak_connection_limit"), [RfcConfigParameters.ConnectionIdleTimeout] = sapResult.getProperty("gag_connection_idle_time_out"), [RfcConfigParameters.Language] = sapResult.getProperty("gag_language"), [RfcConfigParameters.AppServerHost] = sapResult.getProperty("gag_app_server_host"), [RfcConfigParameters.SystemNumber] = sapResult.getProperty("gag_system_number"), [RfcConfigParameters.Client] = sapResult.getProperty("gag_client") }; destination = RfcDestinationManager.GetDestination(parameters); RfcSessionManager.BeginContext(destination); destination.Ping(); result = "Connection Successful"; return(result); } catch (RfcLogonException) { result = "SAP Log-In Failed"; return(result); } catch (RfcCommunicationException) { result = "SAP Server Connection Error"; return(result); } }
public static void initializeContext(HttpContext currentContext, String sapClientName, RfcDestination destination) { bool manualContext = isManualContext(currentContext, sapClientName); if (manualContext) { var manualContexts = (Dictionary <String, RfcDestination>)currentContext.Items[SapManualContextsKey]; if (!manualContexts.ContainsKey(sapClientName) || manualContexts[sapClientName] == null) { manualContexts[sapClientName] = destination; RfcSessionManager.BeginContext(destination); } } else if (!isStatelessRegion(currentContext, sapClientName)) { RfcSessionManager.BeginContext(destination); } }
private void Save_Database(string fingerprint) { RfcConfigParameters parameters = new RfcConfigParameters(); parameters[RfcConfigParameters.Name] = SAPFingerprint.Properties.Settings.Default.Name; parameters[RfcConfigParameters.User] = txtUser.Text; parameters[RfcConfigParameters.Password] = txtPass.Text; parameters[RfcConfigParameters.Client] = SAPFingerprint.Properties.Settings.Default.Client; parameters[RfcConfigParameters.Language] = SAPFingerprint.Properties.Settings.Default.Language; parameters[RfcConfigParameters.AppServerHost] = SAPFingerprint.Properties.Settings.Default.AppServerHost; parameters[RfcConfigParameters.SystemNumber] = SAPFingerprint.Properties.Settings.Default.SystemNumber; parameters[RfcConfigParameters.SAPRouter] = SAPFingerprint.Properties.Settings.Default.SAPRouter; parameters[RfcConfigParameters.SystemID] = SAPFingerprint.Properties.Settings.Default.SystemID; RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(parameters); RfcSessionManager.BeginContext(SapRfcDestination); SapRfcDestination.Ping(); IRfcFunction function = null; try { function = SapRfcDestination.Repository.CreateFunction("ZFM_READ_WRITE_FINGERPRINT"); function.SetValue("IM_FINGERPRINT", fingerprint); function.SetValue("IM_MODE", "R"); function.SetValue("IM_UNAME", txtUser.Text); function.Invoke(SapRfcDestination); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Error: " + ex.Message); } RfcSessionManager.EndContext(SapRfcDestination); SapRfcDestination = null; }
/// <summary> /// create bp data by job table:BUT000 /// no use /// </summary> /// <returns></returns> public string CreateBusinessPartner() { if (rfcDestination == null) { rfcDestination = RfcDestinationManager.GetDestination(WebApiApplication.destinationConfigName); } RfcRepository repo = rfcDestination.Repository; IRfcFunction _BusinessPartner = repo.CreateFunction("BAPI_BUPA_CREATE_FROM_DATA"); IRfcFunction _Commit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT"); _BusinessPartner.SetValue("PARTNERCATEGORY", 2); //2:org _BusinessPartner.SetValue("PARTNERGROUP", 1000); //1000:buyer IRfcStructure _CentralData = _BusinessPartner.GetStructure("CENTRALDATA"); _CentralData.SetValue("SEARCHTERM1", "測試國度"); _CentralData.SetValue("SEARCHTERM2", "測試資料"); // _CentralData.SetValue("PARTNERLANGUAGEISO", "EN"); IRfcStructure _CentraldataOrganization = _BusinessPartner.GetStructure("CENTRALDATAORGANIZATION"); _CentraldataOrganization.SetValue("NAME1", "LLLLL"); IRfcStructure _Address = _BusinessPartner.GetStructure("ADDRESSDATA"); _Address.SetValue("COUNTRY", "TW"); //_Address.SetValue("LANGU", "EN"); _Address.SetValue("REGION", "TPE"); RfcSessionManager.BeginContext(rfcDestination); _BusinessPartner.Invoke(rfcDestination); _Commit.Invoke(rfcDestination); RfcSessionManager.EndContext(rfcDestination); string _BusinessPartnerNumber = _BusinessPartner.GetString("BUSINESSPARTNER"); DataTable dtReturn = ConvertToDotNetTable(_BusinessPartner.GetTable("RETURN")); List <ErrorLog> _ErrorList = SetErrorLog(dtReturn, "BAPI_BUPA_CREATE_FROM_DATA", _BusinessPartnerNumber, ""); List <string> _Error = this._errorLogService.MiltiCreate(_ErrorList); return(_BusinessPartnerNumber); }
public static void PostSAPData(PlanningFunctionGroup costPlanGroup, int functionCount) { lock (m_syncObject) { if (costPlanGroup.FunctionList.Count > 0) { IRfcFunction sapPostCostPlanFunction = SapConnection.GetObject().CurrentDestination.Repository.CreateFunction("BAPI_COSTACTPLN_POSTPRIMCOST"); IRfcFunction sapCommitWorkFunction = SapConnection.GetObject().CurrentDestination.Repository.CreateFunction("BAPI_TRANSACTION_COMMIT"); IRfcTable returnTable = null; try { IRfcStructure headerInfoStructure = sapPostCostPlanFunction.GetStructure("HEADERINFO"); // HEADER_INFO headerInfoStructure.SetValue("CO_AREA", ((CostPlan)costPlanGroup.FunctionList[0]).ControllingArea); // 3 headerInfoStructure.SetValue("FISC_YEAR", ((CostPlan)costPlanGroup.FunctionList[0]).FiscalYear); // 4 headerInfoStructure.SetValue("PERIOD_FROM", ((CostPlan)costPlanGroup.FunctionList[0]).PeriodFrom); // 5 headerInfoStructure.SetValue("PERIOD_TO", ((CostPlan)costPlanGroup.FunctionList[0]).PeriodTo); // 6 headerInfoStructure.SetValue("VERSION", ((CostPlan)costPlanGroup.FunctionList[0]).Version); // 8 headerInfoStructure.SetValue("DOC_HDR_TX", ((CostPlan)costPlanGroup.FunctionList[0]).DocumentHeaderText); // 9 headerInfoStructure.SetValue("PLAN_CURRTYPE", ((CostPlan)costPlanGroup.FunctionList[0]).PlanningCurrency); // 10 sapPostCostPlanFunction.SetValue("DELTA", ((CostPlan)costPlanGroup.FunctionList[0]).Delta); // 11 foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { try { IRfcTable coObjectTable = sapPostCostPlanFunction.GetTable("COOBJECT"); // OBJECT string objectIndex = ((CostPlan)myFunction).ObjectIndex.ToString("000000"); string valueIndex = ((CostPlan)myFunction).ValueIndex.ToString("000000"); coObjectTable.Append(); try { if (coObjectTable.GetValue("OBJECT_INDEX") != null) { if (((string)coObjectTable.GetValue("OBJECT_INDEX")) != objectIndex) { coObjectTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000")); // Calculated } } else { coObjectTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000")); // Calculated } } catch (Exception ex) { coObjectTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000")); } coObjectTable.SetValue("COSTCENTER", ((CostPlan)myFunction).CostCenter); // 11 coObjectTable.SetValue("ACTTYPE", ((CostPlan)myFunction).ActivityType); // 13 coObjectTable.SetValue("ORDERID", ((CostPlan)myFunction).OrderID); // 14 coObjectTable.SetValue("WBS_ELEMENT", ((CostPlan)myFunction).WBSElement); // 15 IRfcTable totValueTable = sapPostCostPlanFunction.GetTable("TOTVALUE"); // TOT_VALUE totValueTable.Append(); totValueTable.SetValue("VALUE_INDEX", ((CostPlan)myFunction).ValueIndex.ToString("000000")); // Calculated if (((CostPlan)myFunction).FixedInputValue != string.Empty) { totValueTable.SetValue("FIX_VALUE", ((CostPlan)myFunction).FixedInputValue); // 2 } else { totValueTable.SetValue("FIX_VALUE", "0"); } totValueTable.SetValue("DIST_KEY_FIX_VAL", ((CostPlan)myFunction).DistributionKey); // 6 totValueTable.SetValue("COST_ELEM", ((CostPlan)myFunction).CostElement); // 12 totValueTable.SetValue("FUNCTION", ((CostPlan)myFunction).FunctionalArea); // 16 totValueTable.SetValue("FUND", ((CostPlan)myFunction).Fund); // 17 totValueTable.SetValue("GRANT_NBR", ((CostPlan)myFunction).Grant); // 18 totValueTable.SetValue("TRANS_CURR", ((CostPlan)myFunction).TransactionCurrency); // 19 IRfcTable indexTable = sapPostCostPlanFunction.GetTable("INDEXSTRUCTURE"); // IDX_STRUCTURE indexTable.Append(); indexTable.SetValue("OBJECT_INDEX", ((CostPlan)myFunction).ObjectIndex.ToString("000000")); indexTable.SetValue("VALUE_INDEX", ((CostPlan)myFunction).ValueIndex.ToString("000000")); indexTable.SetValue("ATTRIB_INDEX", "000000"); myFunction.Updated = true; } catch (Exception ex) { myFunction.ValidationResult = ex.Message; } } } catch (Exception exp) { foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { myFunction.ValidationResult = exp.Message; } } try { RfcSessionManager.BeginContext(SapConnection.GetObject().CurrentDestination); sapPostCostPlanFunction.Invoke(SapConnection.GetObject().CurrentDestination); sapCommitWorkFunction.Invoke(SapConnection.GetObject().CurrentDestination); RfcSessionManager.EndContext(SapConnection.GetObject().CurrentDestination); } catch (Exception ex) { DialogResult r = MessageBox.Show("SAP Authorization Error: " + ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); if (r == DialogResult.OK) { } ReturnProgressDataForm.CancelProcess(); return; } returnTable = sapPostCostPlanFunction.GetTable("RETURN"); foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { if (!SAPRequest.ReturnValuesList.ContainsKey(myFunction.Signature)) { SAPRequest.ReturnValuesList.Add(myFunction.Signature, myFunction); } } if (returnTable.RowCount > 0) { try { string logPath = LogFile.CheckCreateLogFolder() + "\\PWLogValOnly" + DateTime.Now.ToString("(dd-MMM-yyyy-HH-mm-ss-f)") + ".txt"; if (!File.Exists(logPath)) { using (TextWriter writer = File.CreateText(logPath)) { writer.WriteLine("VALIDATION AND POST: " + DateTime.Now.ToString("(dd-MMM-yyyy-HH-mm-ss-f)")); writer.WriteLine(" "); for (int y = 0; y <= (returnTable.RowCount - 1); y += 1) { for (int z = 0; z <= (returnTable[y].ElementCount - 1); z += 1) { string par = returnTable[y][z].Metadata.Name; string val = returnTable[y].GetString(z); string messageLine = par + " : " + val; writer.WriteLine(messageLine); } writer.WriteLine(" "); } } } } catch (Exception ex) { //MessageBox.Show(ex.Message) } for (int j = 0; j <= (returnTable.RowCount - 1); j++) { int row = Convert.ToInt32(returnTable[j].GetString("ROW")) - 1; string message = returnTable[j].GetString("MESSAGE"); if (row < 0) { row = 0; } string rType = string.Empty; string messageV1 = string.Empty; string messageV2 = string.Empty; string messageV3 = string.Empty; string messageV4 = string.Empty; string rNumber = string.Empty; rType = returnTable[j].GetString("TYPE"); messageV1 = returnTable[j].GetString("MESSAGE_V1"); messageV2 = returnTable[j].GetString("MESSAGE_V2"); for (int i = 0; i <= (costPlanGroup.FunctionList.Count - 1); i++) { int elementLocation = SAPRequest.GetObject().TotalProcessedBySAP + i; if (elementLocation < 0) { elementLocation = 0; } string costElement = ((CostPlan)SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation)).CostElement; string costCenter = ((CostPlan)SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation)).CostCenter; try { messageV1 = messageV1.TrimStart('0'); messageV2 = messageV2.TrimStart('0'); } catch (Exception ex) { } try { if (i == row && !string.IsNullOrEmpty(message)) { SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message; } else if (i != row && rType == "E") { try { if (messageV1 == costElement || messageV2 == costElement) { // account for incrementing batch number SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message; } else if (messageV1 != costElement && messageV1 != costCenter && row == 0) { rNumber = returnTable[j].GetString("NUMBER"); if (rNumber != string.Empty) { SAPRequest.ReturnValuesList.Values.ElementAt(elementLocation).Result = message; if (ReturnProgressDataForm.OperationCancelled) { break; } } } } catch (Exception ex) { } } else if (rType == "I") { foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { SAPRequest.ReturnValuesList[myFunction.Signature].Result = message; if (ReturnProgressDataForm.OperationCancelled) { break; } } return; } } catch (Exception ex) { } if (ReturnProgressDataForm.OperationCancelled) { break; } } if (ReturnProgressDataForm.OperationCancelled) { break; } } foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { if (SAPRequest.ReturnValuesList[myFunction.Signature].Result == null | SAPRequest.ReturnValuesList[myFunction.Signature].Result == string.Empty) { SAPRequest.ReturnValuesList[myFunction.Signature].Result = "pwValidated"; } if (ReturnProgressDataForm.OperationCancelled) { break; } } } else { foreach (IPlanningFunction myFunction in costPlanGroup.FunctionList) { SAPRequest.ReturnValuesList[myFunction.Signature].Result = "pwValidated"; if (ReturnProgressDataForm.OperationCancelled) { break; } } } } } }
/// <summary> /// no use /// </summary> /// <param name="number"></param> /// <returns></returns> public string CreateCustomer(string number) { if (rfcDestination == null) { rfcDestination = RfcDestinationManager.GetDestination(WebApiApplication.destinationConfigName); } RfcRepository repo = rfcDestination.Repository; IRfcFunction _CUSTOMER = repo.CreateFunction("BAPI_CUSTOMER_CREATEFROMDATA1"); IRfcFunction _Commit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT"); IRfcStructure _PI_COPYREFERENCE = _CUSTOMER.GetStructure("PI_COPYREFERENCE"); _PI_COPYREFERENCE.SetValue("SALESORG", "1000"); _PI_COPYREFERENCE.SetValue("DISTR_CHAN", "00"); _PI_COPYREFERENCE.SetValue("DIVISION", "00"); _PI_COPYREFERENCE.SetValue("REF_CUSTMR", "0010000003"); IRfcStructure _PI_PERSONALDATA = _CUSTOMER.GetStructure("PI_PERSONALDATA"); _PI_PERSONALDATA.SetValue("FIRSTNAME", "1234"); _PI_PERSONALDATA.SetValue("LASTNAME", "DDDD"); _PI_PERSONALDATA.SetValue("COUNTRY", "US"); _PI_PERSONALDATA.SetValue("REGION", "AK"); _PI_PERSONALDATA.SetValue("LANGU_P", "EN"); _PI_PERSONALDATA.SetValue("CURRENCY", "USD"); _PI_PERSONALDATA.SetValue("middlename", "john"); _PI_PERSONALDATA.SetValue("date_birth", "19780101"); _PI_PERSONALDATA.SetValue("langu_p", "EN"); _PI_PERSONALDATA.SetValue("district", "Hyd"); _PI_PERSONALDATA.SetValue("house_no", "11230"); _PI_PERSONALDATA.SetValue("building", "super"); _PI_PERSONALDATA.SetValue("room_no", "113"); _PI_PERSONALDATA.SetValue("title_p", "Mr.");//Invalid form of address text error you need set Mr. reference table TSAD3T _PI_PERSONALDATA.SetValue("city", "LOS_ANGELES"); //IRfcStructure _PI_OPT_PERSONALDATA = _CUSTOMER.GetStructure("PI_OPT_PERSONALDATA"); //_PI_OPT_PERSONALDATA.SetValue("SHIP_COND", "01"); //_PI_OPT_PERSONALDATA.SetValue("DELYG_PLNT", "1000"); //IRfcFunction _SdCustomer = repo.CreateFunction("SD_CUSTOMER_MAINTAIN_ALL"); //IRfcStructure _Knvv = _SdCustomer.GetStructure("I_KNVV"); //_Knvv.SetValue("KUNNR", number); //_Knvv.SetValue("VKORG", "1000"); //_Knvv.SetValue("VTWEG", "00"); //_Knvv.SetValue("SPART", "00"); //_Knvv.SetValue("KALKS", "1"); //_Knvv.SetValue("BZIRK", "US"); //_Knvv.SetValue("WAERS", "USD"); //_Knvv.SetValue("KURST", "E"); //_Knvv.SetValue("KONDA", "MSRP"); //_Knvv.SetValue("VSBED", "01"); //_Knvv.SetValue("INCO1", "DDP"); //_Knvv.SetValue("INCO2", "US"); RfcSessionManager.BeginContext(rfcDestination); _CUSTOMER.Invoke(rfcDestination); _Commit.Invoke(rfcDestination); RfcSessionManager.EndContext(rfcDestination); IRfcStructure structReturn = _CUSTOMER.GetStructure("RETURN"); string _CUSTOMERNO = _CUSTOMER.GetString("CUSTOMERNO"); string _TYPE = structReturn.GetString("TYPE"); string _MESSAGE = structReturn.GetString("MESSAGE"); DataTable dtReturn = setErrorTable(_TYPE, _MESSAGE, "PI_COPYREFERENCE"); List <ErrorLog> _ErrorList = SetErrorLog(dtReturn, "BAPI_CUSTOMER_CREATEFROMDATA1", "", ""); List <string> _Error = this._errorLogService.MiltiCreate(_ErrorList); return(""); }
public async Task BAPI_GOODSMVT_CREATE(IList <GOODSMVT_ITEM> dt) { try { RfcDestination dest = GetDestination(); RfcRepository repository = dest.Repository; RfcSessionManager.BeginContext(dest); IRfcFunction func = repository.CreateFunction("BAPI_GOODSMVT_CREATE"); string message = null; IRfcStructure rfcStructGMItem = null; IRfcTable rfcTableGMItem = func.GetTable("GOODSMVT_ITEM"); IRfcStructure stru; IRfcTable result; //set parm rfcStructGMItem = repository.GetStructureMetadata("BAPI2017_GM_ITEM_CREATE").CreateStructure(); foreach (var item in dt) { rfcStructGMItem.SetValue("MATERIAL", item.material); rfcStructGMItem.SetValue("PLANT", item.plant); rfcStructGMItem.SetValue("STGE_LOC", item.stge_loc); rfcStructGMItem.SetValue("BATCH", item.batch); rfcStructGMItem.SetValue("MOVE_TYPE", item.move_type); rfcStructGMItem.SetValue("ENTRY_QNT", item.entry_qnt); rfcStructGMItem.SetValue("COST_OBJ", item.cost_obj); rfcStructGMItem.SetValue("ENTRY_UOM", item.entry_uom); } rfcTableGMItem.Insert(rfcStructGMItem); IRfcStructure rfcStructGMCode = null; rfcStructGMCode = func.GetStructure("GOODSMVT_CODE"); if (dt.Count > 0) { if (dt[0].move_type == "291") { rfcStructGMCode.SetValue("GM_CODE", "03"); } else if (dt[0].move_type == "292") { rfcStructGMCode.SetValue("GM_CODE", "06"); } } IRfcStructure rfcStructGMHeader = null; rfcStructGMHeader = func.GetStructure("GOODSMVT_HEADER"); rfcStructGMHeader.SetValue("PSTNG_DATE", "20191028"); rfcStructGMHeader.SetValue("DOC_DATE", "20191028"); //call function log.Debug("BAPI_GOODSMVT_CREATE => Start"); func.Invoke(dest); log.Debug("BAPI_GOODSMVT_CREATE => Done"); //log result result = func.GetTable("RETURN"); for (int k = 0; k < result.RowCount; k++) { stru = result[k]; message = stru.GetValue("MESSAGE").ToString(); log.Debug(string.Format("MESSAGE:{0}", message)); } if (result.RowCount == 0) { string doc = func.GetValue("MATERIALDOCUMENT").ToString(); string year = func.GetValue("MATDOCUMENTYEAR").ToString(); func = repository.CreateFunction("BAPI_TRANSACTION_COMMIT"); func.SetValue("WAIT", "X"); func.Invoke(dest); stru = func.GetStructure("RETURN"); MessageBox.Show(doc); } else { func = repository.CreateFunction("BAPI_TRANSACTION_ROLLBACK"); func.Invoke(dest); MessageBox.Show(message); } RfcSessionManager.EndContext(dest); } catch (Exception ex) { throw ex; } }
/// <summary> /// 1. if no parameter :IV_DOCOMMIT then no effect /// 2. RUN_ID:if not same number then no effect /// 3. IT_BP_GENERAL-OBJECT_TASK: insert mode I /// </summary> /// <returns></returns> public string CreateBP() { if (rfcDestination == null) { rfcDestination = RfcDestinationManager.GetDestination(WebApiApplication.destinationConfigName); } RfcRepository repo = rfcDestination.Repository; IRfcFunction _CUSTOMER = repo.CreateFunction("RFC_CVI_EI_INBOUND_MAIN"); _CUSTOMER.SetValue("IV_DOCOMMIT", "X"); //required //IRfcFunction _Commit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT"); IRfcTable _IT_BP_GENERAL = _CUSTOMER.GetTable("IT_BP_GENERAL"); IRfcStructure _IT_BP_GENERALStruct = _IT_BP_GENERAL.Metadata.LineType.CreateStructure(); _IT_BP_GENERALStruct.SetValue("RUN_ID", "1"); _IT_BP_GENERALStruct.SetValue("OBJECT_TASK", "I"); _IT_BP_GENERALStruct.SetValue("BPARTNER", ""); _IT_BP_GENERALStruct.SetValue("NAME1", "LLLLL"); _IT_BP_GENERALStruct.SetValue("CATEGORY", 2);//required _IT_BP_GENERALStruct.SetValue("GROUPING", "1000"); _IT_BP_GENERALStruct.SetValue("SEARCHTERM1", "國度"); _IT_BP_GENERALStruct.SetValue("SEARCHTERM2", "資料"); _IT_BP_GENERALStruct.SetValue("FOUNDATIONDATE", DateTime.Now.ToString("yyyyMMdd")); _IT_BP_GENERALStruct.SetValue("TITLE_KEY", ""); _IT_BP_GENERALStruct.SetValue("AUTHORIZATIONGROUP", ""); _IT_BP_GENERALStruct.SetValue("PARTNEREXTERNAL", ""); _IT_BP_GENERAL.Append(_IT_BP_GENERALStruct); IRfcTable _IT_BP_ROLE = _CUSTOMER.GetTable("IT_BP_ROLE"); IRfcStructure _IT_BP_ROLEStruct = _IT_BP_ROLE.Metadata.LineType.CreateStructure(); IRfcStructure _IT_BP_ROLEStruct2 = _IT_BP_ROLE.Metadata.LineType.CreateStructure(); _IT_BP_ROLEStruct.SetValue("RUN_ID", "1"); //required _IT_BP_ROLEStruct.SetValue("DATA_KEY", "FLCU00"); _IT_BP_ROLEStruct.SetValue("ROLECATEGORY", "2"); _IT_BP_ROLE.Append(_IT_BP_ROLEStruct); _IT_BP_ROLEStruct2.SetValue("RUN_ID", "1");//required _IT_BP_ROLEStruct2.SetValue("DATA_KEY", "1000"); _IT_BP_ROLEStruct2.SetValue("ROLECATEGORY", "2"); _IT_BP_ROLE.Append(_IT_BP_ROLEStruct2); IRfcTable _IT_BP_ADDRESS = _CUSTOMER.GetTable("IT_BP_ADDRESS"); IRfcStructure _IT_BP_ADDRESStruct = _IT_BP_ADDRESS.Metadata.LineType.CreateStructure(); _IT_BP_ADDRESStruct.SetValue("RUN_ID", "1");//required _IT_BP_ADDRESStruct.SetValue("STANDARDADDRESS", "X"); _IT_BP_ADDRESStruct.SetValue("COUNTRY", "US"); _IT_BP_ADDRESStruct.SetValue("LANGUISO", "EN"); _IT_BP_ADDRESStruct.SetValue("LANGU", "E"); _IT_BP_ADDRESS.Append(_IT_BP_ADDRESStruct); RfcSessionManager.BeginContext(rfcDestination); _CUSTOMER.Invoke(rfcDestination); //_Commit.Invoke(rfcDestination); RfcSessionManager.EndContext(rfcDestination); DataTable dtReturn = ConvertToDotNetTable(_CUSTOMER.GetTable("CT_RETURN")); List <ErrorLog> _ErrorList = new List <ErrorLog>(); string _Number = ""; if (dtReturn.Rows.Count > 0) { _Number = dtReturn.Rows[0]["OBJECT_KEY"].ToString() == "" ? "" : dtReturn.Rows[0]["OBJECT_KEY"].ToString(); _ErrorList = SetErrorLog(dtReturn, "RFC_CVI_EI_INBOUND_MAIN", _Number, ""); } List <string> _Error = this._errorLogService.MiltiCreate(_ErrorList); //test //RfcRepository repo2 = rfcDestination.Repository; //IRfcFunction _CUSTOMER2 = repo2.CreateFunction("RFC_CVI_EI_INBOUND_MAIN"); //_CUSTOMER2.SetValue("IV_DOCOMMIT", "X"); //IRfcFunction _Commit2 = repo.CreateFunction("BAPI_TRANSACTION_COMMIT"); //IRfcTable _IT_BP_GENERAL2 = _CUSTOMER2.GetTable("IT_BP_GENERAL"); //IRfcStructure _IT_BP_GENERAL2Struct = _IT_BP_GENERAL2.Metadata.LineType.CreateStructure(); //_IT_BP_GENERAL2Struct.SetValue("RUN_ID", "1"); //_IT_BP_GENERAL2Struct.SetValue("OBJECT_TASK", "U"); //_IT_BP_GENERAL2Struct.SetValue("BPARTNER", "0010002183"); //_IT_BP_GENERAL2Struct.SetValue("SEARCHTERM1", "國度1234"); //_IT_BP_GENERAL2.Append(_IT_BP_GENERAL2Struct); //RfcSessionManager.BeginContext(rfcDestination); //_CUSTOMER2.Invoke(rfcDestination); //_Commit2.Invoke(rfcDestination); //RfcSessionManager.EndContext(rfcDestination); //DataTable dtReturn2 = ConvertToDotNetTable(_CUSTOMER2.GetTable("CT_RETURN")); return(_Number); }
protected override void DefWndProc(ref Message m) { switch (m.Msg) { case MESSAGE_CAPTURED_OK: { MemoryStream ms = new MemoryStream(); BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms); Bitmap bmp = new Bitmap(ms); this.picFPImg.Image = bmp; String strShow = zkfp2.BlobToBase64(CapTmp, cbCapTmp); if (IsRegister) { int ret = zkfp.ZKFP_ERR_OK; int fid = 0, score = 0; ret = zkfp2.DBIdentify(mDBHandle, CapTmp, ref fid, ref score); if (zkfp.ZKFP_ERR_OK == ret) { txtStatus.Text = "This finger was already register"; return; } if (RegisterCount > 0 && zkfp2.DBMatch(mDBHandle, CapTmp, RegTmps[RegisterCount - 1]) <= 0) { txtStatus.Text = "Please press the same finger 1 times for the enrollment."; return; } Array.Copy(CapTmp, RegTmps[RegisterCount], cbCapTmp); String strBase64 = zkfp2.BlobToBase64(CapTmp, cbCapTmp); byte[] blob = zkfp2.Base64ToBlob(strBase64); RegisterCount++; Save_Database(strBase64); if (RegisterCount >= REGISTER_FINGER_COUNT) { txtStatus.Text = "Enroll succesfully"; IsRegister = false; cbRegTmp = 1; return; } else { txtStatus.Text = "You need to press the " + (REGISTER_FINGER_COUNT - RegisterCount) + " times fingerprint"; } } else { if (cbRegTmp <= 0) { txtStatus.Text = "Please register your finger first!"; return; } if (bIdentify) { int ret = zkfp.ZKFP_ERR_OK; int fid = 0, score = 0; ret = zkfp2.DBIdentify(mDBHandle, CapTmp, ref fid, ref score); if (zkfp.ZKFP_ERR_OK == ret) { txtStatus.Text = "Identify succesfully, fid= " + fid + ",score=" + score + "!"; return; } else { txtStatus.Text = "Identify failed, ret= " + ret; return; } } else { RfcConfigParameters parameters = new RfcConfigParameters(); parameters[RfcConfigParameters.Name] = SAPFingerprint.Properties.Settings.Default.Name; parameters[RfcConfigParameters.User] = txtUser.Text; parameters[RfcConfigParameters.Password] = txtPass.Text; parameters[RfcConfigParameters.Client] = SAPFingerprint.Properties.Settings.Default.Client; parameters[RfcConfigParameters.Language] = SAPFingerprint.Properties.Settings.Default.Language; parameters[RfcConfigParameters.AppServerHost] = SAPFingerprint.Properties.Settings.Default.AppServerHost; parameters[RfcConfigParameters.SystemNumber] = SAPFingerprint.Properties.Settings.Default.SystemNumber; parameters[RfcConfigParameters.SAPRouter] = SAPFingerprint.Properties.Settings.Default.SAPRouter; parameters[RfcConfigParameters.SystemID] = SAPFingerprint.Properties.Settings.Default.SystemID; RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(parameters); RfcSessionManager.BeginContext(SapRfcDestination); SapRfcDestination.Ping(); IRfcFunction function = null; try { function = SapRfcDestination.Repository.CreateFunction("ZFM_READ_WRITE_FINGERPRINT"); function.SetValue("IM_MODE", "V"); IRfcTable gt_table = function.GetTable("EX_FINGERPRINT"); function.Invoke(SapRfcDestination); jj = 0; foreach (IRfcStructure row in gt_table) { jj = jj + 1; byte[] blob1 = Convert.FromBase64String(Convert.ToString(row.GetValue(0))); String strBase64 = zkfp2.BlobToBase64(CapTmp, cbCapTmp); byte[] blob2 = Convert.FromBase64String(strBase64.Trim()); int ret = zkfp2.DBMatch(mDBHandle, blob1, blob2); if (ret > 0) { txtStatus.Text = "Selamat Datang!"; vald = ret; break; } else { txtStatus.Text = "Maaf and tidak dikenali"; } zkfp2.DBClear(mDBHandle); } if (vald > 0) { // function = SapRfcDestination.Repository.CreateFunction("ZFM_READ_WRITE_FINGERPRINT"); // function.SetValue("MODE", "V"); // function.SetValue("INDX", jj); // function.Invoke(SapRfcDestination); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Error: " + ex.Message); } RfcSessionManager.EndContext(SapRfcDestination); SapRfcDestination = null; } } } break; default: base.DefWndProc(ref m); break; } }
public string CreateSalesArea(string number) { if (rfcDestination == null) { rfcDestination = RfcDestinationManager.GetDestination(WebApiApplication.destinationConfigName); } RfcRepository repo = rfcDestination.Repository; IRfcFunction _CUSTOMER = repo.CreateFunction("RFC_CVI_EI_INBOUND_MAIN"); _CUSTOMER.SetValue("IV_DOCOMMIT", "X");// required //IRfcFunction _Commit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT"); IRfcTable _IT_CUST_GENERAL = _CUSTOMER.GetTable("IT_CUST_GENERAL"); IRfcStructure _IT_CUST_GENERALStruct = _IT_CUST_GENERAL.Metadata.LineType.CreateStructure(); _IT_CUST_GENERALStruct.SetValue("RUN_ID", "2"); _IT_CUST_GENERALStruct.SetValue("KUNNR", number); _IT_CUST_GENERALStruct.SetValue("OBJECT_TASK", "I"); _IT_CUST_GENERALStruct.SetValue("BAHNE", "25"); _IT_CUST_GENERAL.Append(_IT_CUST_GENERALStruct); IRfcTable _IT_CUST_SALES = _CUSTOMER.GetTable("IT_CUST_SALES"); IRfcStructure _IT_CUST_SALESStruct = _IT_CUST_SALES.Metadata.LineType.CreateStructure(); _IT_CUST_SALESStruct.SetValue("RUN_ID", "2"); _IT_CUST_SALESStruct.SetValue("VKORG", "1000"); _IT_CUST_SALESStruct.SetValue("VTWEG", "00"); _IT_CUST_SALESStruct.SetValue("SPART", "00"); _IT_CUST_SALESStruct.SetValue("KALKS", "1"); _IT_CUST_SALESStruct.SetValue("VSBED", "01"); _IT_CUST_SALESStruct.SetValue("WAERS", "USD"); _IT_CUST_SALESStruct.SetValue("KDGRP", "02"); _IT_CUST_SALESStruct.SetValue("KURST", "E"); _IT_CUST_SALESStruct.SetValue("KONDA", "02"); _IT_CUST_SALESStruct.SetValue("BZIRK", "US"); _IT_CUST_SALESStruct.SetValue("INCO1", "EXW"); _IT_CUST_SALESStruct.SetValue("INCO2_L", "EXW"); _IT_CUST_SALES.Append(_IT_CUST_SALESStruct); IRfcTable _IT_CUST_TAX_INDICATOR = _CUSTOMER.GetTable("IT_CUST_TAX_INDICATOR"); IRfcStructure _IT_CUST_TAX_INDICATORStruct = _IT_CUST_TAX_INDICATOR.Metadata.LineType.CreateStructure(); _IT_CUST_TAX_INDICATORStruct.SetValue("RUN_ID", "2"); _IT_CUST_TAX_INDICATORStruct.SetValue("ALAND", "CN"); _IT_CUST_TAX_INDICATORStruct.SetValue("TATYP", "MWST"); _IT_CUST_TAX_INDICATORStruct.SetValue("TAXKD", "A"); _IT_CUST_TAX_INDICATOR.Append(_IT_CUST_TAX_INDICATORStruct); IRfcStructure _IT_CUST_TAX_INDICATORStruct2 = _IT_CUST_TAX_INDICATOR.Metadata.LineType.CreateStructure(); _IT_CUST_TAX_INDICATORStruct2.SetValue("RUN_ID", "2"); _IT_CUST_TAX_INDICATORStruct2.SetValue("ALAND", "TW"); _IT_CUST_TAX_INDICATORStruct2.SetValue("TATYP", "MWST"); _IT_CUST_TAX_INDICATORStruct2.SetValue("TAXKD", "6"); _IT_CUST_TAX_INDICATOR.Append(_IT_CUST_TAX_INDICATORStruct2); IRfcTable _IT_CUST_SALES_FUNCTIONS = _CUSTOMER.GetTable("IT_CUST_SALES_FUNCTIONS"); IRfcStructure _IT_CUST_SALES_FUNCTIONSStruct = _IT_CUST_SALES_FUNCTIONS.Metadata.LineType.CreateStructure(); _IT_CUST_SALES_FUNCTIONSStruct.SetValue("RUN_ID", "2"); _IT_CUST_SALES_FUNCTIONSStruct.SetValue("VKORG", "1000"); _IT_CUST_SALES_FUNCTIONSStruct.SetValue("VTWEG", "00"); _IT_CUST_SALES_FUNCTIONSStruct.SetValue("SPART", "00"); _IT_CUST_SALES_FUNCTIONSStruct.SetValue("PARVW", "SE"); _IT_CUST_SALES_FUNCTIONSStruct.SetValue("KNREF", "22"); _IT_CUST_SALES_FUNCTIONS.Append(_IT_CUST_SALES_FUNCTIONSStruct); RfcSessionManager.BeginContext(rfcDestination); _CUSTOMER.Invoke(rfcDestination); // _Commit.Invoke(rfcDestination); RfcSessionManager.EndContext(rfcDestination); DataTable dtReturn = ConvertToDotNetTable(_CUSTOMER.GetTable("CT_RETURN")); List <ErrorLog> _ErrorList = new List <ErrorLog>(); string _Number = ""; if (dtReturn.Rows.Count > 0) { _Number = dtReturn.Rows[0]["OBJECT_KEY"].ToString() == "" ? "" : dtReturn.Rows[0]["OBJECT_KEY"].ToString(); _ErrorList = SetErrorLog(dtReturn, "RFC_CVI_EI_INBOUND_MAIN", _Number, ""); } return(""); }
/// <summary> /// you need excute(se38) ABLM_MODIFY_ITEMS in sap system and set relavant parameter /// previous when you use BAPI_SALESORDER_CREATEFROMDAT2 this RFC module /// </summary> /// <param name="destinationName"></param> /// <returns></returns> public string CreateOrder(SapSalesOrder salesOrder) { if (rfcDestination == null) { rfcDestination = RfcDestinationManager.GetDestination(WebApiApplication.destinationConfigName); } RfcRepository repo = rfcDestination.Repository; IRfcFunction _SalesDoc = repo.CreateFunction("BAPI_SALESORDER_CREATEFROMDAT2"); IRfcFunction _SalesDocCommit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT"); IRfcStructure _SalesHeader = _SalesDoc.GetStructure("ORDER_HEADER_IN"); IRfcTable _SalesItems = _SalesDoc.GetTable("ORDER_ITEMS_IN"); IRfcTable _SalesPartners = _SalesDoc.GetTable("ORDER_PARTNERS"); IRfcTable _SalesSchedule = _SalesDoc.GetTable("ORDER_SCHEDULES_IN"); _SalesHeader.SetValue("DOC_TYPE", salesOrder.Header.DOC_TYPE); _SalesHeader.SetValue("SALES_ORG", salesOrder.Header.SALES_ORG); _SalesHeader.SetValue("DISTR_CHAN", salesOrder.Header.DISTR_CHAN); _SalesHeader.SetValue("DIVISION", salesOrder.Header.DIVISION); _SalesHeader.SetValue("PURCH_NO_C", salesOrder.Header.PURCH_NO_C); //test 採購日期 _SalesHeader.SetValue("PURCH_DATE", salesOrder.Header.PURCH_DATE); foreach (SalesItem si in salesOrder.ItemList) { IRfcStructure _SalesItemsStruct = _SalesItems.Metadata.LineType.CreateStructure(); _SalesItemsStruct.SetValue("ITM_NUMBER", si.ITM_NUMBER); //_SalesItemsStruct.SetValue("MATERIAL", si.MATERIAL); _SalesItemsStruct.SetValue("MATERIAL_LONG", si.MATERIAL); _SalesItemsStruct.SetValue("TARGET_QTY", si.TARGET_QTY); //test 客戶物料號碼 _SalesItemsStruct.SetValue("CUST_MAT35", si.CUST_MAT35); _SalesItems.Append(_SalesItemsStruct); } foreach (SalesPartner sp in salesOrder.PartnerList) { IRfcStructure _SalesPartnersStruct = _SalesPartners.Metadata.LineType.CreateStructure(); _SalesPartnersStruct.SetValue("PARTN_ROLE", sp.PARTN_ROLE); _SalesPartnersStruct.SetValue("PARTN_NUMB", sp.PARTN_NUMB); _SalesPartners.Append(_SalesPartnersStruct); } foreach (SalesSchedule ss in salesOrder.ScheduleList) { IRfcStructure _SalesScheduleStruct = _SalesSchedule.Metadata.LineType.CreateStructure(); _SalesScheduleStruct.SetValue("REQ_QTY", ss.REQ_QTY); _SalesScheduleStruct.SetValue("ITM_NUMBER", ss.ITM_NUMBER); _SalesScheduleStruct.SetValue("SCHED_LINE", ss.SCHED_LINE); _SalesScheduleStruct.SetValue("REQ_DATE", ss.REQ_DATE); _SalesSchedule.Append(_SalesScheduleStruct); } ////salesPartnersStruct.SetValue("PARTN_ROLE", "RE"); ////salesPartnersStruct.SetValue("PARTN_NUMB", "0010000650"); ////salesPartners.Append(salesPartnersStruct); RfcSessionManager.BeginContext(rfcDestination); _SalesDoc.Invoke(rfcDestination); _SalesDocCommit.Invoke(rfcDestination); RfcSessionManager.EndContext(rfcDestination); string _SalesCocument = _SalesDoc.GetString("SALESDOCUMENT"); DataTable dtReturn = ConvertToDotNetTable(_SalesDoc.GetTable("RETURN")); List <ErrorLog> _ErrorList = SetErrorLog(dtReturn, "BAPI_SALESORDER_CREATEFROMDAT2", _SalesCocument, salesOrder.Header.PURCH_NO_C); List <string> _Error = this._errorLogService.MiltiCreate(_ErrorList); return(_SalesCocument); }
public bool getSapFunctionToTablePara(string funName, Dictionary <string, string> lstParameters, Dictionary <string, Dictionary <string, object> > lstStructures , IRfcTable rtbIput, string tableindex , List <string> ParameterNamesForOut, out Dictionary <string, string> ParametersOutput , List <string> StructureNamesForOut, out Dictionary <string, IRfcStructure> StructureOutputs , List <string> tableNamesForOut, out Dictionary <string, IRfcTable> rtbsOutput, ref string strErrMsg) { try { RfcRepository repo = rfcrep; IRfcFunction Z_RFC_ZCOX = repo.CreateFunction(funName); RfcSessionManager.BeginContext(dest); if (lstParameters != null && lstParameters.Count > 0) { foreach (KeyValuePair <string, string> item in lstParameters) { Z_RFC_ZCOX.SetValue(item.Key, item.Value); } } if (lstStructures != null && lstStructures.Count > 0) { foreach (string item in lstStructures.Keys) { IRfcStructure _stru = Z_RFC_ZCOX.GetStructure(item); foreach (KeyValuePair <string, object> _kv in lstStructures[item]) { _stru.SetValue(_kv.Key, _kv.Value); } } } if (rtbIput != null) { Z_RFC_ZCOX.SetValue(tableindex, rtbIput); } Z_RFC_ZCOX.Invoke(dest); RfcSessionManager.EndContext(dest); //取出返回的表 if (tableNamesForOut != null && tableNamesForOut.Count > 0) { rtbsOutput = new Dictionary <string, IRfcTable>(); foreach (string item in tableNamesForOut) { IRfcTable rtb = Z_RFC_ZCOX.GetTable(item); rtbsOutput.Add(item, rtb); } } else { rtbsOutput = null; } //取出返回参数 if (ParameterNamesForOut != null && ParameterNamesForOut.Count > 0) { ParametersOutput = new Dictionary <string, string>(); foreach (string item in ParameterNamesForOut) { string retPara = Z_RFC_ZCOX.GetString(item); ParametersOutput.Add(item, retPara); } } else { ParametersOutput = null; } //取出返回的结构 if (StructureNamesForOut != null && StructureNamesForOut.Count > 0) { StructureOutputs = new Dictionary <string, IRfcStructure>(); foreach (string item in StructureNamesForOut) { IRfcStructure retStru = Z_RFC_ZCOX.GetStructure(item); StructureOutputs.Add(item, retStru); } } else { StructureOutputs = null; } char statue = Z_RFC_ZCOX.GetChar("EX_TYPE"); if ("E".Contains(statue)) { strErrMsg = Z_RFC_ZCOX.GetString("EX_MSG"); } return("S".Contains(statue)); } catch (RfcAbapRuntimeException ex) { ParametersOutput = null; rtbsOutput = null; StructureOutputs = null; throw ex; } }
public bool PostSapFunctionFromListTable(string funName, Dictionary <string, string> lstParameters , Dictionary <string, Dictionary <string, object> > lstStructures , ref Dictionary <string, string> ParametersOutputs , ref Dictionary <string, IRfcStructure> StructureOutputs , ref Dictionary <string, IRfcTable> rtbsOutputs , Dictionary <string, IRfcTable> lstTable, ref string strErrMsg) { try { RfcRepository repo = rfcrep; IRfcFunction Z_RFC_ZCOX = repo.CreateFunction(funName); RfcSessionManager.BeginContext(dest); if (lstParameters != null && lstParameters.Count > 0) { foreach (KeyValuePair <string, string> item in lstParameters) { Z_RFC_ZCOX.SetValue(item.Key, item.Value); } } if (lstStructures != null && lstStructures.Count > 0) { foreach (string item in lstStructures.Keys) { IRfcStructure _stru = Z_RFC_ZCOX.GetStructure(item); foreach (KeyValuePair <string, object> _kv in lstStructures[item]) { _stru.SetValue(_kv.Key, _kv.Value); } } } if (lstTable != null && lstTable.Count > 0) { foreach (KeyValuePair <string, IRfcTable> item in lstTable) { Z_RFC_ZCOX.SetValue(item.Key, item.Value); } } //if (rfcTable != null && rfcTable.Count > 0) //{ // Z_RFC_ZCOX.SetValue(rfcTableName, rfcTable); //} Z_RFC_ZCOX.Invoke(dest); RfcSessionManager.EndContext(dest); //取出返回的表 if (rtbsOutputs != null && rtbsOutputs.Count > 0) { for (int i = 0; i < rtbsOutputs.Count; i++) { var _item = rtbsOutputs.ElementAt(i); IRfcTable rtb = Z_RFC_ZCOX.GetTable(_item.Key); rtbsOutputs[_item.Key] = rtb; } } else { rtbsOutputs = null; } //取出返回的结构 if (StructureOutputs != null && StructureOutputs.Count > 0) { for (int i = 0; i < StructureOutputs.Count; i++) { var _item = StructureOutputs.ElementAt(i); IRfcStructure retStru = Z_RFC_ZCOX.GetStructure(_item.Key); StructureOutputs[_item.Key] = retStru; } } else { StructureOutputs = null; } return(CreateReturn(rtbsOutputs["RETURN"], ref strErrMsg)); } catch (RfcAbapRuntimeException ex) { throw ex; } }