public Dictionary <String, Object> TestConnection() { try { RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig); var rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName); RfcRepository rfcRep = null; rfcRep = rfcDest.Repository; } catch (RfcLogonException le) { return(new Dictionary <string, object>() { { "Response", false }, { "Message", le.Message } }); } catch (Exception ex) { return(new Dictionary <string, object>() { { "Response", false }, { "Message", ex.Message + " : " + ex.StackTrace } }); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(this.SAPConfig); } return(new Dictionary <string, object>() { { "Response", true }, { "Message", "Success" } }); }
/// <summary> /// 测试连接SAP /// </summary> /// <returns></returns> public bool ConnSap(out string message) { bool result = false; try { IDestinationConfiguration ID = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(ID); RfcDestination destination = RfcDestinationManager.GetDestination("SAPMS"); RfcRepository repository = destination.Repository; IRfcFunction rfcFunction = repository.CreateFunction("Z_TEST_CONNECTION"); rfcFunction.Invoke(destination); message = rfcFunction.GetValue("E_RETURN_MESSAGE").ToString(); result = !(rfcFunction.GetValue("E_RETURN_CODE").ToString() == "E"); } catch (Exception ex) { message = ex.Message; } finally { RfcDestinationManager.UnregisterDestinationConfiguration(ID); } return(result); }
public void InitSAP() { try { IDestinationConfiguration destinationConfig = null; destinationConfig = new SAPDestinationConfig(); destinationConfig.GetParameters(_destinationName); bool destinationFound = false; try { destinationFound = (RfcDestinationManager.GetDestination(_destinationName) != null); } catch { destinationFound = false; } if (!destinationFound) { RfcDestinationManager.RegisterDestinationConfiguration(destinationConfig); } } catch (Exception e) { throw new Exception("Errore di inizializzazione RfcDestination", e); } }
public IRfcTable Rfc_Qdt_Dal(RFC_QDT_Model qdtModel, out RFC_IN_Message rfcMessage) { rfcMessage = new RFC_IN_Message(); try { _configurationId = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(_configurationId); _dest = RfcDestinationManager.GetDestination("SAPMS"); _repository = _dest.Repository; IRfcFunction rfc = _repository.CreateFunction(qdtModel.FunctionModule); //调用函数名 IRfcTable table = rfc.GetTable(qdtModel.E_SAP_QDT); //RFC表数据 rfc.SetValue("I_MESKEY", qdtModel.I_MESKEY); //KEY随机号 不能重复 rfc.SetValue("I_USER", qdtModel.I_USER); //登录名 rfc.SetValue("I_MATNR", qdtModel.I_MATNR); rfc.SetValue("I_CHARG", qdtModel.I_CHARG); rfc.Invoke(_dest); rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString(); rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString(); rfcMessage.E_COUNT = rfc.GetInt("E_COUNT").ToString(); rfcMessage.E_SUM = rfc.GetInt("E_SUM").ToString(); return(table); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口QDT 错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
static void Main(string[] args) { try { SAPSystemConnect sapCfg = new SAPSystemConnect(); RfcDestinationManager.RegisterDestinationConfiguration(sapCfg); RfcDestination destination = RfcDestinationManager.GetDestination("ECQ"); RfcRepository repository = destination.Repository; IRfcFunction function = repository.CreateFunction("Z_SSRT_SUM"); function.SetValue("i_num1", 2); function.SetValue("i_num2", 4); function.Invoke(destination); int result = function.GetInt("e_result"); destination.Ping(); var rfcRepository = destination.Repository; var rfcFunction = rfcRepository.CreateFunction("RFC_CUSTOMER_DATA"); rfcFunction.SetValue("COUNTRY", "india"); rfcFunction.Invoke(destination); var table = rfcFunction.GetTable(0); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
public IRfcTable Rfc_Stock_dal(RFC_STOCK_Model StockModel, out RFC_IN_Message rfcMessage) { rfcMessage = new RFC_IN_Message(); try { _configurationId = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(_configurationId); _dest = RfcDestinationManager.GetDestination("SAPMS"); _repository = _dest.Repository; IRfcFunction rfc = _repository.CreateFunction(StockModel.FunctionModule); //调用函数名 IRfcTable table = rfc.GetTable(StockModel.L_MM_STOCK); //RFC表数据 rfc.SetValue("I_FLAG", "J"); rfc.Invoke(_dest); rfcMessage.E_RETURN_CODE = rfc.GetString("E_SUBRC").ToString(); rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_MESSAGE").ToString(); return(table); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口STOCK错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
public static Destination GetDestination(RfcConfigParameters configParameters) { string serverKey = ServerConfiguration.AddServerDestination(configParameters); lock (serverConfigurationRegistrationLock) { if (!serverConfigurationRegistered) { RfcDestinationManager.RegisterDestinationConfiguration(new ServerConfiguration()); serverConfigurationRegistered = true; } } if (ServerConfiguration.HasServerKey(serverKey)) { Destination destination = new Destination() { InUse = true, InUseSince = DateTime.Now, ServerKey = serverKey, Suffix = String.Empty, RfcDestination = RfcDestinationManager.GetDestination(serverKey) }; return(destination); } return(null); }
public void RegisterDestination(string destinationName) { bool destinationIsInialised = ((_rfcDestination != null) && string.Equals(_rfcDestination.Name, destinationName)); // Only register if not already initialised try { // ? destinantion already configured and initialised if (!destinationIsInialised) { RfcDestinationManager.RegisterDestinationConfiguration(new SAPIDocDestinationConfiguration(destinationName));//1 _rfcDestination = RfcDestinationManager.GetDestination(destinationName); } } // ignore as destination already configured catch (RfcInvalidStateException rfcEx) { // cascade up callstack throw rfcEx; } //System.Diagnostics.Trace.WriteLine( // String.Format("Destination Confgured to:{0}", _rfcDestination.Monitor.OriginDestinationID)); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //APERTURA CONECCION string destinationconfigname = "QA"; Application["destinationconfigname"] = destinationconfigname; IDestinationConfiguration destinationConfiguration = null; bool destinationisInialised = false; if (!destinationisInialised) { destinationConfiguration = new ECCDestinationConfig(); destinationConfiguration.GetParameters(destinationconfigname); if (RfcDestinationManager.TryGetDestination(destinationconfigname) == null) { RfcDestinationManager.RegisterDestinationConfiguration(destinationConfiguration); destinationisInialised = true; bool resultado = false; resultado = testconnection(destinationconfigname); Application["resultado"] = Convert.ToString(resultado); } } //FIN APERTURA CONECCION }
static EmployeeEntityService() { SAPSystemConnectMy sapCfg = new SAPSystemConnectMy(); RfcDestinationManager.RegisterDestinationConfiguration(sapCfg); rfcDest = RfcDestinationManager.GetDestination("K47"); }
//public static List<string> LoadSAPClientSettings() //{ // List<String> ClientList = new List<string>(); // try // { // ConfigurationSectionGroup sectionGroup = getSapSectionGroup(); // RfcGeneralConfiguration configuration2 = getSAPGeneralConfiguration(sectionGroup); // RfcDestinationCollection clientsSetting = getClientSettings(sectionGroup); // IEnumerator enumerator = clientsSetting.GetEnumerator(); // while (enumerator.MoveNext()) // { // RfcDestinationParameters current = (RfcDestinationParameters)enumerator.Current; // ClientList.Add(current.Name); // } // // RfcDestinationManager.RegisterDefaultConfiguration(new DefaultDestinationConfiguration(clientsSetting)); // } // catch (Exception) // { // throw; // } // return ClientList; //} public static bool LoadSAPClientConfig() { try { if (_clientStarted == false) { RfcDestinationCollection clientsSetting = ConfigFileTool.SAPClientServerSetting.getClientSettings(); if (clientsSetting != null) { RfcDestinationManager.RegisterDestinationConfiguration(new DefaultDestinationConfiguration(clientsSetting)); } //RfcServerCollection severSetting = ConfigFileTool.SAPClientServerSetting.getServerSettings(); //if (severSetting != null) //{ // RfcServerManager.RegisterServerConfiguration(new DefaultServerConfiguration(severSetting)); //} // RfcServerManager.loadedFromParameterFile = true; _clientStarted = true; } return(true); } catch (Exception exception) { throw new SAPException(exception.Message + "无法从配置文件加载"); } }
public Rfc_Frota() { try { SAPConnect objcon = new SAPConnect(); RfcDestinationManager.RegisterDestinationConfiguration(objcon); dest = RfcDestinationManager.GetDestination("Frota"); repo = dest.Repository; RfcDestinationManager.UnregisterDestinationConfiguration(objcon); } catch (RfcCommunicationException e) { throw e; } catch (RfcLogonException e) { throw e; } catch (RfcAbapRuntimeException e) { throw e; } catch (RfcAbapBaseException e) { throw e; } }
public IRfcTable Rfc_Del_Dal(RFC_DEL_Model delModel, out RFC_IN_Message rfcMessage) { rfcMessage = new RFC_IN_Message(); try { _configurationId = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(_configurationId); _dest = RfcDestinationManager.GetDestination("SAPMS"); _repository = _dest.Repository; IRfcFunction rfc = _repository.CreateFunction(delModel.FunctionModule); //调用函数名 IRfcTable table = rfc.GetTable(delModel.E_SAP_DEL); //RFC表数据 rfc.SetValue("I_MESKEY", delModel.I_MESKEY); //KEY随机号 不能重复 rfc.SetValue("I_DATE", delModel.I_DATE); //日期 rfc.SetValue("I_TIME", delModel.I_TIME); //时间 rfc.SetValue("I_USER", delModel.I_USER); //登录名 rfc.SetValue("I_VBELN", delModel.I_VBELN); rfc.Invoke(_dest); rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString(); //rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString(); rfcMessage.E_COUNT = rfc.GetInt("E_COUNT").ToString(); rfcMessage.E_SUM = rfc.GetInt("E_SUM").ToString(); return(table); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口DEL 错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
public RFC_OUT_Message Rfc_Rmu_Dal(List <RFC_RMU_Model.RFC_RMU_ITEM_Model> rmuItemModel, RFC_RMU_Model.RFC_RMU_HEADER_Model rmuHeaderModel) { RFC_OUT_Message rfcMessage = new RFC_OUT_Message(); try { _configurationId = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(_configurationId); _dest = RfcDestinationManager.GetDestination("SAPMS"); _repository = _dest.Repository; IRfcFunction rfc = _repository.CreateFunction("Z_PP_MES_OUT_RMU"); //调用函数名 IRfcTable table = rfc.GetTable(rmuHeaderModel.E_SAP_RMU); //RFC表数据 IRfcStructure structure = rfc.GetStructure("I_HEADER"); //RFC表头数据 structure.SetValue("ZMESKEY", rmuHeaderModel.ZMESKEY); structure.SetValue("BLDAT", rmuHeaderModel.BLDAT); structure.SetValue("BUDAT", rmuHeaderModel.BUDAT); structure.SetValue("ZCOUNT", rmuHeaderModel.ZCOUNT); structure.SetValue("ZUSER", rmuHeaderModel.ZUSER); structure.SetValue("ZUNPLAN", rmuHeaderModel.ZUNPLAN); try { structure.SetValue("BKTXT", rmuHeaderModel.BKTXT); } catch {} foreach (var _rmuItemModel in rmuItemModel) { table.Insert(); table.CurrentRow.SetValue("ZMESITEM", _rmuItemModel.ZMESITEM); table.CurrentRow.SetValue("AUFNR", _rmuItemModel.AUFNR); table.CurrentRow.SetValue("POSNR", _rmuItemModel.POSNR); table.CurrentRow.SetValue("BWART", _rmuItemModel.BWART); table.CurrentRow.SetValue("MATNR", _rmuItemModel.MATNR); table.CurrentRow.SetValue("WERKS", _rmuItemModel.WERKS); table.CurrentRow.SetValue("LGORT", _rmuItemModel.LGORT); table.CurrentRow.SetValue("MENGE", _rmuItemModel.MENGE); table.CurrentRow.SetValue("MEINS", _rmuItemModel.MEINS); table.CurrentRow.SetValue("CHARG", _rmuItemModel.CHARG); table.CurrentRow.SetValue("ITEM_TEXT", _rmuItemModel.ITEM_TEXT); // rmuHeaderModel.ZSUM += _rmuItemModel.MENGE;//所有数据全部相加,取总数 } structure.SetValue("ZSUM", rmuHeaderModel.ZSUM); rfc.Invoke(_dest); rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString(); rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString(); rfcMessage.E_EXPROC = rfc.GetString("E_MAT_DOC").ToString(); return(rfcMessage); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口RMU 错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
public Dictionary <String, Object> GetSAPIVAMat(Int64 MaterialId) { Dictionary <String, Object> response = null; try { var config = System.Configuration.ConfigurationManager.GetSection(ConfigurationName.Trim()) as NameValueCollection; var resultSeparator = config["ResultSeparator"].ToCharArray()[0]; RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig); RfcDestination rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName); RfcRepository rfcRep = null; rfcRep = rfcDest.Repository; IRfcFunction qry = rfcRep.CreateFunction("RFC_READ_TABLE"); qry.SetValue("QUERY_TABLE", "MLAN"); qry.SetValue("DELIMITER", resultSeparator); IRfcTable FIELDS = qry.GetTable("FIELDS"); FIELDS.Append(); FIELDS.SetValue("FIELDNAME", "TAXM1"); IRfcTable OPTIONS = qry.GetTable("OPTIONS"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "MATNR EQ '" + CompleteCodes(MaterialId.ToString(), 18) + "' AND"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "ALAND EQ 'CO'"); IRfcTable DATA = qry.GetTable("DATA"); qry.Invoke(rfcDest); response = new Dictionary <string, object>(); if (DATA.ToList().Count > 0) { var result = DATA.ToList().First()["WA"]; var value = result.GetValue(); response.Add("Response", true); response.Add("SAPIVAMat", value.ToString()); } else { response.Add("Response", false); } } catch (RfcLogonException le) { return(new Dictionary <string, object>() { { "Response", false }, { "Message", le.Message } }); } catch (Exception ex) { return(new Dictionary <string, object>() { { "Response", false }, { "Message", ex.Message + " : " + ex.StackTrace } }); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(this.SAPConfig); } return(response); }
/// <summary> /// /// </summary> /// <param name="logMessage"></param> /// <param name="w"></param> /// public DataTable ReadTableDW(string table, char delimiter, string fields, string filters, RfcDestination rfcDest, DataTable DT, string filters2, string filters3) { string[] field_names = fields.Split(",".ToCharArray()); RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig); // RfcDestination rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName); // RfcDestination destination = RfcDestinationManager.GetDestination(dest); IRfcFunction readTable = rfcDest.Repository.CreateFunction("BBP_RFC_READ_TABLE"); // we want to query table KNA1 readTable.SetValue("QUERY_TABLE", table); // fields will be separated by semicolon readTable.SetValue("DELIMITER", delimiter); // Parameter table FIELDS contains the columns you want to receive // here we query 2 fields, KUNNR and NAME1 IRfcTable fieldsTable = readTable.GetTable("FIELDS"); if (field_names.Length > 0) { fieldsTable.Append(field_names.Length); int i = 0; foreach (string n in field_names) { fieldsTable.CurrentIndex = i++; fieldsTable.SetValue(0, n); } } // the table OPTIONS contains the WHERE condition(s) of your query // here a single condition, KUNNR is to be 0012345600 // several conditions have to be concatenated in ABAP syntax, for instance with AND or OR IRfcTable optsTable = readTable.GetTable("OPTIONS"); optsTable.Append(); optsTable.SetValue("TEXT", filters); if (filters2 != string.Empty) { optsTable.Append(); optsTable.SetValue("TEXT", filters2); } if (filters3 != string.Empty) { optsTable.Append(); optsTable.SetValue("TEXT", filters3); } readTable.Invoke(rfcDest); rfcDest = null; IRfcTable dataTable = readTable.GetTable("DATA"); string[] columns; foreach (var dataRow in dataTable) { string data = (string)dataRow.GetValue("WA"); columns = data.Split(delimiter); DT.LoadDataRow(columns.ToArray(), true); } return(DT); }
public RfcDestination GetDestination() { if (!RfcDestinationManager.IsDestinationConfigurationRegistered()) { RfcDestinationManager.RegisterDestinationConfiguration(new DestinationConfiguration(SystemNumber, AppServerHost, Client, User, Password)); } ///參數只要不是空字串之任意字串 return(RfcDestinationManager.GetDestination("RFC")); }
public RFC_OUT_Message Rfc_Stu_Dal(List <RFC_STU_Model.RFC_STU_ITEM_Model> stuItemModel, RFC_STU_Model.RFC_STU_HEADER_Model stuHeaderModel) { RFC_OUT_Message rfcMessage = new RFC_OUT_Message(); try { _configurationId = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(_configurationId); _dest = RfcDestinationManager.GetDestination("SAPMS"); _repository = _dest.Repository; IRfcFunction rfc = _repository.CreateFunction(stuHeaderModel.FunctionModule); //调用函数名 IRfcTable table = rfc.GetTable("T_DATA"); //RFC表数据 IRfcStructure structure = rfc.GetStructure("I_HEADER"); //RFC表头数据 structure.SetValue("ZMESKEY", stuHeaderModel.ZMESKEY); structure.SetValue("BUDAT", stuHeaderModel.BUDAT); structure.SetValue("ZCOUNT", stuHeaderModel.ZCOUNT); structure.SetValue("ZSUM", stuHeaderModel.ZSUM); structure.SetValue("ZUSER", stuHeaderModel.ZUSER); structure.SetValue("BKTXT", stuHeaderModel.BKTXT); table.Clear(); foreach (var _stuItemModel in stuItemModel) { table.Insert(); table.CurrentRow.SetValue("ZMESITEM", _stuItemModel.ZMESITEM); table.CurrentRow.SetValue("BWART", _stuItemModel.BWART); table.CurrentRow.SetValue("MATNR", _stuItemModel.MATNR); table.CurrentRow.SetValue("WERKS", _stuItemModel.WERKS); table.CurrentRow.SetValue("LGORT", _stuItemModel.LGORT); table.CurrentRow.SetValue("MENGE", _stuItemModel.MENGE); table.CurrentRow.SetValue("MEINS", _stuItemModel.MEINS); table.CurrentRow.SetValue("CHARG", _stuItemModel.CHARG); table.CurrentRow.SetValue("ZEILE", _stuItemModel.ZEILE); table.CurrentRow.SetValue("UMLGO", _stuItemModel.UMLGO); table.CurrentRow.SetValue("LIFNR", _stuItemModel.LIFNR); table.CurrentRow.SetValue("SOBKZ", _stuItemModel.SOBKZ); //stuHeaderModel.ZSUM += _stuItemModel.MENGE;//所有数据全部相加,取总数 } structure.SetValue("ZSUM", stuHeaderModel.ZSUM); rfc.Invoke(_dest); rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString(); rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString(); //rfcMessage.E_PO_NUMBER = rfc.GetInt("E_COUNT").ToString(); //rfcMessage.E_EXPROC = rfc.GetInt("E_SUM").ToString(); rfcMessage.E_MAT_DOC = rfc.GetString("E_MAT_DOC").ToString(); return(rfcMessage); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口STU 错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
public RFC_OUT_Message Rfc_Gpr_Dal(List <RFC_GPR_Model.RFC_GPR_ITEM_Model> gprItemModel, RFC_GPR_Model.RFC_GPR_HEADER_Model gprHeaderModel) { RFC_OUT_Message rfcMessage = new RFC_OUT_Message(); try { _configurationId = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(_configurationId); _dest = RfcDestinationManager.GetDestination("SAPMS"); _repository = _dest.Repository; IRfcFunction rfc = _repository.CreateFunction(gprHeaderModel.FunctionModule); //调用函数名 IRfcTable table = rfc.GetTable(gprHeaderModel.E_SAP_GRP); //RFC表数据 IRfcStructure structure = rfc.GetStructure("I_HEADER"); //RFC表头数据 structure.SetValue("ZMESKEY", gprHeaderModel.ZMESKEY); structure.SetValue("EBELN", gprHeaderModel.EBELN); structure.SetValue("BUKRS", gprHeaderModel.BUKRS); structure.SetValue("BSART", gprHeaderModel.BSART); structure.SetValue("EKORG", gprHeaderModel.EKORG); structure.SetValue("AEDAT", gprHeaderModel.AEDAT); structure.SetValue("LIFNR", gprHeaderModel.LIFNR); structure.SetValue("ZCOUNT", gprHeaderModel.ZCOUNT); structure.SetValue("ZUSER", gprHeaderModel.ZUSER); foreach (var _gprItemModel in gprItemModel) { table.Insert(); table.CurrentRow.SetValue("ZMESITEM", _gprItemModel.ZMESITEM); table.CurrentRow.SetValue("EBELP", _gprItemModel.EBELP); table.CurrentRow.SetValue("LOEKZ", _gprItemModel.LOEKZ); table.CurrentRow.SetValue("MATNR", _gprItemModel.MATNR); table.CurrentRow.SetValue("WERKS", _gprItemModel.WERKS); table.CurrentRow.SetValue("LGORT", _gprItemModel.LGORT); table.CurrentRow.SetValue("MENGE", _gprItemModel.MENGE); table.CurrentRow.SetValue("MEINS", _gprItemModel.MEINS); table.CurrentRow.SetValue("EINDT", _gprItemModel.EINDT); table.CurrentRow.SetValue("LICHA", _gprItemModel.LICHA); table.CurrentRow.SetValue("ZJPSONO", _gprItemModel.ZJPSONO); table.CurrentRow.SetValue("ZJPSOITEM", _gprItemModel.ZJPSOITEM); gprHeaderModel.ZSUM += _gprItemModel.MENGE;//所有数据全部相加,取总数 } structure.SetValue("ZSUM", gprHeaderModel.ZSUM); rfc.Invoke(_dest); rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString(); //rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString(); rfcMessage.E_PO_NUMBER = rfc.GetInt("E_COUNT").ToString(); rfcMessage.E_EXPROC = rfc.GetInt("E_SUM").ToString(); return(rfcMessage); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口GPR 错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
public SapR3() { SAPSystemConnect sapCfg = new SAPSystemConnect(); RfcDestinationManager.RegisterDestinationConfiguration(sapCfg); //System Id rfcDest = RfcDestinationManager.GetDestination("DAM"); }
public RFC_OUT_Message Rfc_Fgo_Dal(List <RFC_FGO_Model.RFC_FGO_ITEM_Model> fgoItemModel, RFC_FGO_Model.RFC_FGO_HEADER_Model fgoHeaderModel) { RFC_OUT_Message rfcMessage = new RFC_OUT_Message(); try { _configurationId = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(_configurationId); _dest = RfcDestinationManager.GetDestination("SAPMS"); _repository = _dest.Repository; IRfcFunction rfc = _repository.CreateFunction("Z_PP_MES_OUT_FGO"); //调用函数名 IRfcTable table = rfc.GetTable("T_DATA"); //RFC表数据 IRfcStructure structure = rfc.GetStructure("I_HEADER"); //RFC表头数据 structure.SetValue("ZMESKEY", fgoHeaderModel.ZMESKEY); structure.SetValue("AUFNR", fgoHeaderModel.AUFNR); structure.SetValue("BUDAT", fgoHeaderModel.BUDAT); structure.SetValue("ZCOUNT", fgoHeaderModel.ZCOUNT); //structure.SetValue("ZSUM", fgoHeaderModel.ZSUM); structure.SetValue("ZUSER", fgoHeaderModel.ZUSER); fgoHeaderModel.ZSUM = 0; foreach (var _fgoItemModel in fgoItemModel) { table.Insert(); table.CurrentRow.SetValue("ZMESITEM", _fgoItemModel.ZMESITEM); table.CurrentRow.SetValue("BWART", _fgoItemModel.BWART); table.CurrentRow.SetValue("WERKS", _fgoItemModel.WERKS); table.CurrentRow.SetValue("LGORT", _fgoItemModel.LGORT); table.CurrentRow.SetValue("MENGE", _fgoItemModel.MENGE); table.CurrentRow.SetValue("MEINS", _fgoItemModel.MEINS); table.CurrentRow.SetValue("ZINBOXNO_MIN", _fgoItemModel.ZINBOXNO_MIN); table.CurrentRow.SetValue("ZINBOXNO_MAX", _fgoItemModel.ZINBOXNO_MIN); table.CurrentRow.SetValue("ZLOTNO", _fgoItemModel.ZLOTNO); table.CurrentRow.SetValue("ZINBOXNO", _fgoItemModel.ZINBOXNO); fgoHeaderModel.ZSUM += _fgoItemModel.MENGE;//所有数据全部相加,取总数 } structure.SetValue("ZSUM", fgoHeaderModel.ZSUM); rfc.Invoke(_dest); rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString(); rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString(); //rfcMessage.E_PO_NUMBER = rfc.GetInt("E_COUNT").ToString(); //rfcMessage.E_EXPROC = rfc.GetInt("E_SUM").ToString(); rfcMessage.E_MAT_DOC = rfc.GetString("E_MAT_DOC").ToString(); rfcMessage.E_EXPROC = rfc.GetString("E_EXPROC").ToString(); return(rfcMessage); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口FGO 错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
public static object getConnectionObject() { if (rfcDest == null) { SAPDotNETConnectionObject sapCfg = new SAPDotNETConnectionObject(); RfcDestinationManager.RegisterDestinationConfiguration(sapCfg); rfcDest = RfcDestinationManager.GetDestination(Constants.DestinationNum); } return(rfcDest); }
public DataTable GetCargoLogisticoSAP(Int64 ObraId) { //var TD_TZONT = P.ReadTableDW("TZONT", '~', "LAND1,ZONE1,VTEXT", "LAND1 IN ('CO')", rfcDest, DefineDT.TZONT_DataBasic(), string.Empty, string.Empty); Dictionary <String, Object> response = null; DataTable DT = new DataTable(); try { var config = System.Configuration.ConfigurationManager.GetSection(ConfigurationName.Trim()) as NameValueCollection; var resultSeparator = config["ResultSeparator"].ToCharArray()[0]; RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig); RfcDestination rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName); RfcRepository rfcRep = null; rfcRep = rfcDest.Repository; IRfcFunction qry = rfcRep.CreateFunction("RFC_READ_TABLE"); qry.SetValue("QUERY_TABLE", "KNVV"); qry.SetValue("DELIMITER", resultSeparator); IRfcTable FIELDS = qry.GetTable("FIELDS"); FIELDS.Append(); FIELDS.SetValue("FIELDNAME", "ZZFUELSURC"); FIELDS.Append(); FIELDS.SetValue("FIELDNAME", "ZZDAMX33"); IRfcTable OPTIONS = qry.GetTable("OPTIONS"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "KUNNR EQ '" + CompleteCodes(ObraId.ToString(), 10) + "' AND SPART EQ '03'"); IRfcTable DATA = qry.GetTable("DATA"); qry.Invoke(rfcDest); //DataTable DT = new DataTable(); DT.Columns.Add("CargoCombustible"); DT.Columns.Add("ZonaSuburbana"); IRfcTable dataTable = qry.GetTable("DATA"); string[] columns; foreach (var dataRow in dataTable) { string data = (string)dataRow.GetValue("WA"); columns = data.Split('|'); DT.LoadDataRow(columns.ToArray(), true); } return(DT); } catch (RfcLogonException le) { return(DT); } catch (Exception ex) { return(DT); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(this.SAPConfig); } return(DT); }
public static RfcDestination GetConnection(string DestinationName) { RfcDestination exists = null; //如果该连接已缓存,使用旧的 if (_RFCs != null) { if (_RFCs.ContainsKey(DestinationName)) { exists = _RFCs[DestinationName]; } } if (exists != null) { return(exists); } IDestinationConfiguration ID = new SaprouterConfig(); try { RfcDestinationManager.RegisterDestinationConfiguration(ID); } catch (Exception ex) { WriteLog.WebGuiInLog("创建SAP连接失败:" + ex.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, "**********************"); } exists = RfcDestinationManager.GetDestination(DestinationName); try { exists.Repository.ToString(); } catch (Exception ex) { ex.ToString(); (ID as SaprouterConfig).RemoveDestination(DestinationName); } try { RfcDestinationManager.UnregisterDestinationConfiguration(ID); } catch (Exception ex) { WriteLog.WebGuiInLog("注销SAP连接池失败:" + ex.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, "**********************"); } //缓存本次新建连接 _RFCs.Add(DestinationName, exists); return(exists); }
public RFC_OUT_Message Rfc_Fgu_Dal(List <RFC_FGU_Model.RFC_FGU_ITEM_Model> fguItemModel, RFC_FGU_Model.RFC_FGU_HEADER_Model fguHeaderModel) { RFC_OUT_Message rfcMessage = new RFC_OUT_Message(); try { _configurationId = new RFC_SetUp(); RfcDestinationManager.RegisterDestinationConfiguration(_configurationId); _dest = RfcDestinationManager.GetDestination("SAPMS"); _repository = _dest.Repository; IRfcFunction rfc = _repository.CreateFunction(fguHeaderModel.FunctionModule); //调用函数名 IRfcTable table = rfc.GetTable(fguHeaderModel.E_SAP_FGU); //RFC表数据 IRfcStructure structure = rfc.GetStructure("I_HEADER"); //RFC表头数据 structure.SetValue("ZMESKEY", fguHeaderModel.ZMESKEY); structure.SetValue("VBELN", fguHeaderModel.VBELN); structure.SetValue("WADAT_IST", fguHeaderModel.WADAT_IST); structure.SetValue("ZCOUNT", fguHeaderModel.ZCOUNT); structure.SetValue("ZSUM", fguHeaderModel.ZSUM); structure.SetValue("ZUSER", fguHeaderModel.ZUSER); structure.SetValue("ZSTEP", fguHeaderModel.ZSTEP); foreach (var _fguItemModel in fguItemModel) { table.Insert(); table.CurrentRow.SetValue("ZMESITEM", _fguItemModel.ZMESITEM); table.CurrentRow.SetValue("POSNR", _fguItemModel.POSNR); table.CurrentRow.SetValue("MATNR", _fguItemModel.MATNR); table.CurrentRow.SetValue("MENGE", _fguItemModel.MENGE); table.CurrentRow.SetValue("MEINS", _fguItemModel.MEINS); table.CurrentRow.SetValue("CHARG", _fguItemModel.CHARG); table.CurrentRow.SetValue("ZLOTNO", _fguItemModel.ZLOTNO); table.CurrentRow.SetValue("ZINBOXNO", _fguItemModel.ZINBOXNO); table.CurrentRow.SetValue("LOTQTY", _fguItemModel.LOTQTY); //fguHeaderModel.ZSUM += _fguItemModel.MENGE;//所有数据全部相加,取总数 } structure.SetValue("ZSUM", fguHeaderModel.ZSUM); rfc.Invoke(_dest); rfcMessage.E_RETURN_CODE = rfc.GetString("E_RETURN_CODE").ToString(); rfcMessage.E_RETURN_MESSAGE = rfc.GetString("E_RETURN_MESSAGE").ToString(); rfcMessage.E_MAT_DOC = rfc.GetString("E_MAT_DOC").ToString(); //rfcMessage.E_PO_NUMBER = rfc.GetInt("E_COUNT").ToString(); //rfcMessage.E_EXPROC = rfc.GetInt("E_SUM").ToString(); return(rfcMessage); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口FGU 错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
//public void Connect() //{ // IDestinationConfiguration ID = new RFCConfigg(); // RfcDestinationManager.RegisterDestinationConfiguration(ID); // destination = RfcDestinationManager.GetDestination(ABAP_AS); // TestConnect(); // Console.Write(AttributesToString()); //} public void Connect() { ID = new RFCConfigg(); RfcDestinationManager.RegisterDestinationConfiguration(ID); destination = RfcDestinationManager.GetDestination(ABAP_AS); //TestConnect(); //Console.Write(AttributesToString()); }
/// <summary> /// Metoda rejestrujaca docelowa konfiguracje /// </summary> /// <param name="cfg">Interfejs konfiguracyjny</param> public void RegisterConfig(IDestinationConfiguration cfg) { // Register config try { RfcDestinationManager.RegisterDestinationConfiguration(cfg); } catch (Exception ex) { Messenger.Default.Send(new LogMessage(ex.Message, LogType.ERROR), "Log"); } }
public void InitializeConnection() { destinationConfig = new SAPDestinationConfig(this.saplogonlanguage); //destinationConfig.GetParameters(destinationConfigName); if (RfcDestinationManager.TryGetDestination(destinationConfigName) == null) { RfcDestinationManager.RegisterDestinationConfiguration(destinationConfig); destinationIsInialised = true; } }
public void KomisyonBedeliniGetir(string musteriNumarasi, DateTime?baslangicTarihi, DateTime?bitisTarihi , out DataTable dtITAB, out DataTable dtZRETURN) { SAPDestinationConfiguration sapDestinationConfiguration = new SAPDestinationConfiguration(); IRfcFunction rfcFunction = null; try { // ishak.kulekci 24.06.2013 // Destination configuration already initialized hatasını engelleme, bunun için önce TryGetDestination kullanılır RfcDestination rfcDestination = RfcDestinationManager.TryGetDestination("SAPSYSTEM"); if (rfcDestination == null) { try { RfcDestinationManager.RegisterDestinationConfiguration(sapDestinationConfiguration); } catch (Exception ex) { } rfcDestination = RfcDestinationManager.GetDestination("SAPSYSTEM"); } //RfcDestination rfcDestination = RfcDestinationManager.GetDestination("SAPSYSTEM"); rfcFunction = rfcDestination.Repository.CreateFunction("Z_RFC_YK_BEKPRIM_TO_INTERNET"); //rfcFunction.SetValue("KUNNR", "100092"); // aygaz rfcFunction.SetValue("KUNNR", musteriNumarasi); //rfcFunction.SetValue("DATAB", "20130601"); rfcFunction.SetValue("DATAB", baslangicTarihi.Value.ToString("yyyyMMdd", CultureInfo.GetCultureInfo("tr-tr"))); //rfcFunction.SetValue("DATBI", "20130605"); rfcFunction.SetValue("DATBI", bitisTarihi.Value.ToString("yyyyMMdd", CultureInfo.GetCultureInfo("tr-tr"))); rfcFunction.Invoke(rfcDestination); } catch (Exception exception) { throw exception; } finally { try { RfcDestinationManager.UnregisterDestinationConfiguration(sapDestinationConfiguration); } catch (Exception ex) { } } dtITAB = RFCHelper.RfcTableToDataTable(rfcFunction.GetTable("ITAB"), "ITAB"); dtZRETURN = RFCHelper.RfcTableToDataTable(rfcFunction.GetTable("ZRETURN"), "ZRETURN"); }
public static void Main(string[] args) { // Verbindung mit der SAP DestConfig destCfg = new DestConfig(); //Instanz erzeugen RfcDestinationManager.RegisterDestinationConfiguration(destCfg); //registriere Instanz im DestinationManager Console.Write(" Register destination..."); // Destinationparameter setzen RfcConfigParameters configParams = new RfcConfigParameters(); configParams.Add(RfcConfigParameters.Name, "Flash"); configParams.Add(RfcConfigParameters.Language, "DE"); configParams.Add(RfcConfigParameters.Client, "100"); configParams.Add(RfcConfigParameters.AppServerHost, "mmm.nnn.ooo.3"); // configParams.Add(RfcConfigParameters.PeakConnectionsLimit, "5");// Max Anzahl gleichzeitiger Verbindungen configParams.Add(RfcConfigParameters.ConnectionIdleTimeout, "600");// 600 seconds- 10 min configParams.Add(RfcConfigParameters.SystemNumber, "00"); configParams.Add(RfcConfigParameters.User, "testexampleonly"); configParams.Add(RfcConfigParameters.Password, "testexampleonly"); destCfg.AddDestination(configParams); // RfcDestination destination = RfcDestinationManager.GetDestination(strVerb); // hole destination Parameter RfcDestination destination = RfcDestinationManager.GetDestination("Flash"); // Ausgabe der Parameter Console.WriteLine("\nConfigured Destination in main: {0} [ {1} ]", destination.Name, destination.Parameters.ToString()); //connect with D-Bus var bus = Bus.Session; ObjectPath path = new ObjectPath("/com/swissbit/sap"); SapServerQuery myserver = new SapServerQuery(); Bus.Session.Register(path, myserver); var BusName = "com.swissbit.sap"; bus.RequestName(BusName, org.freedesktop.DBus.NameFlag.None); if (bus.IsConnected) { Console.WriteLine("D-Bus connected\n"); myserver.setDestConfig(ref destCfg); myserver.setRfcDestination(ref destination); } else { Console.WriteLine("D-Bus disconnected"); } while (true) { bus.Iterate(); } }