private void saveDataTableToDataBase() { if (this.dt != null) { if (SourceSystem != null && SourceTableName != null) { try { SapTable table = new SapTable(SourceSystem, SourceTableName, "CHAR8000"); table.EventLogMessage += table_EventLogMessage; if (table.SaveDataTable(this.dt) == true) { MessageBox.Show("保存成功!!!"); } else { MessageBox.Show("保存失败!!!"); } } catch (Exception exception) { MessageBox.Show(exception.Message); // throw; } } } }
private void saveDataTableToDataBase() { if (localdt != null) { if (TableName != null && SystemName != null) { try { SapTable table = new SapTable(SystemName, TableName); if (table.SaveDataTable(localdt)) { MessageBox.Show("保存成功!!!"); } else { MessageBox.Show("保存失败!!!"); } } catch (Exception exception) { MessageBox.Show(exception.Message); // throw; } } } }
//public static rfcdestination getdestination(string sysname) //{ // return sapdestination.getdesbyname(sysname); //} /// <summary> /// 搜索SAP中所有的RFC函数,如果函数名为空,读取所有的函数列表 /// 并直接在储到数据库中 /// </summary> /// <param name="sysName"></param> /// <param name="functionName"></param> /// <returns></returns> public static bool GetRFCfunctionListAndSaveToDb(string sysName, string functionName) { try { RfcDestination destination = SAPDestination.GetDesByName(sysName); string _funame = string.Format("*{0}*", functionName); IRfcFunction RFC_FUNCTION_SEARCH = destination.Repository.CreateFunction("RFC_FUNCTION_SEARCH"); RFC_FUNCTION_SEARCH.SetValue("FUNCNAME", _funame); RFC_FUNCTION_SEARCH.Invoke(destination); IRfcTable FUNCTIONS = RFC_FUNCTION_SEARCH.GetTable("FUNCTIONS"); if (FUNCTIONS.RowCount > 0) { //保存结果到数据库。 var _table = new SapTable(sysName, "RFC_FUNCTIONS", "RFCFUNC"); _table.DbConnectionString = ConfigFileTool.SAPGlobalSettings.GetDefaultDbConnection(); _table.NewTable = true; _table.SaveDataTable(SAPFunction.RfcTableToDataTable(FUNCTIONS)); return(true); } else { return(false); } } catch (RfcAbapException rfce) { throw new SAPException(rfce.Key + rfce.Message); } catch (Exception e) { throw new SAPException(e.Message); } }
/// <summary> /// FUNCTION BAPI_USER_GETLIST /// </summary> /// <param name="ROWS">No. of users selected</param> /// <param name="MAX_ROWS">Maximum Number of Lines of Hits</param> /// <param name="WITH_USERNAME">Read User with Name</param> /// <param name="RETURN">Return Parameter</param> /// <param name="SELECTION_EXP">Search for Users with Free Selections</param> /// <param name="SELECTION_RANGE">Search for Users with a Ranges Table</param> /// <param name="USERLIST">User List</param> public static bool Invoke(ConnectionInformations ci, out string exception, out int ROWS, int MAX_ROWS, string WITH_USERNAME, ref SapTable <BAPIRET2> RETURN, ref SapTable <BAPIUSSEXP> SELECTION_EXP, ref SapTable <BAPIUSSRGE> SELECTION_RANGE, ref SapTable <BAPIUSNAME> USERLIST) { exception = ""; ROWS = default(int); try { SapConnections.Init(ci); RfcRepository rfcRep = SapConnections.Get(ci.Name).Repository; IRfcFunction function = rfcRep.CreateFunction("BAPI_USER_GETLIST"); function.SetValue("MAX_ROWS", MAX_ROWS); function.SetValue("WITH_USERNAME", WITH_USERNAME); if (RETURN != null) { function.SetValue("RETURN", RETURN.ToSapObject(ci.Name)); } if (SELECTION_EXP != null) { function.SetValue("SELECTION_EXP", SELECTION_EXP.ToSapObject(ci.Name)); } if (SELECTION_RANGE != null) { function.SetValue("SELECTION_RANGE", SELECTION_RANGE.ToSapObject(ci.Name)); } if (USERLIST != null) { function.SetValue("USERLIST", USERLIST.ToSapObject(ci.Name)); } function.Invoke(SapConnections.Get(ci.Name)); ROWS = function.GetInt("ROWS"); if (RETURN == null) { RETURN = new SapTable <BAPIRET2>(); } RETURN.FromSapObject(function.GetTable("RETURN")); if (SELECTION_EXP == null) { SELECTION_EXP = new SapTable <BAPIUSSEXP>(); } SELECTION_EXP.FromSapObject(function.GetTable("SELECTION_EXP")); if (SELECTION_RANGE == null) { SELECTION_RANGE = new SapTable <BAPIUSSRGE>(); } SELECTION_RANGE.FromSapObject(function.GetTable("SELECTION_RANGE")); if (USERLIST == null) { USERLIST = new SapTable <BAPIUSNAME>(); } USERLIST.FromSapObject(function.GetTable("USERLIST")); return(true); } catch (Exception ex) { exception = ex.Message; return(false); } }
public WsInput() { DISTRIBUTIONCHANNELSELECTION = new SapTable <BAPIMATRADC>(); MANUFACTURERPARTNUMB = new SapTable <BAPIMATMFRPN>(); MATERIALSHORTDESCSEL = new SapTable <BAPIMATRAS>(); MATNRLIST = new SapTable <BAPIMATLST>(); MATNRSELECTION = new SapTable <BAPIMATRAM>(); PLANTSELECTION = new SapTable <BAPIMATRAW>(); RETURN = new SapTable <BAPIRET2>(); SALESORGANISATIONSELECTION = new SapTable <BAPIMATRASO>(); STORAGELOCATIONSELECT = new SapTable <BAPIMATRAL>(); }
public static void IDOC_INBOUND(RfcServerContext context, IRfcFunction function) { IRfcTable control = function.GetTable("IDOC_CONTROL_REC_40"); IRfcTable data = function.GetTable("IDOC_DATA_REC_40"); DataTable dtIdocControlData = GetDataTableFromRfcTable(control); DataTable dtIdocData = GetDataTableFromRfcTable(data); for (int i = 0; i < control.RowCount; i++) { IRfcStructure tControl = control[i]; string client = ConfigFileTool.SAPGlobalSettings.GetDefaultSapCient(); string TableName = "T" + tControl["DOCNUM"].GetValue().ToString().Trim(); SapTable idoctable = new SapTable(client, TableName, "EDI_DD40"); DataTable dt = GetDataTableFromRfcTable(data); idoctable.SaveDataTable(dt); processSingleIdoc(tControl, data); } //DataTable dtcontrol = GetDataTableFromRfcTable(control); //foreach (DataRow row in dtcontrol.Rows) //{ // for (int k = 0; k < dtcontrol.Columns.Count; k++) // { // Console.WriteLine(row[k].ToString()); // } //} //DataTable dtdata = GetDataTableFromRfcTable(data); //foreach (DataRow row in dtdata.Rows) //{ // for (int k = 0; k < dtdata.Columns.Count; k++) // { // Console.WriteLine(row[k].ToString()); // } //} }
public static void Test() { string exception = ""; int ROWS = default(int); int MAX_ROWS = default(int); string WITH_USERNAME = default(string); SapTable <BAPIRET2> RETURN = new SapTable <BAPIRET2>(); SapTable <BAPIUSSEXP> SELECTION_EXP = new SapTable <BAPIUSSEXP>(); SapTable <BAPIUSSRGE> SELECTION_RANGE = new SapTable <BAPIUSSRGE>(); SapTable <BAPIUSNAME> USERLIST = new SapTable <BAPIUSNAME>(); var ci = SAPConIO.Helper.ConnectionInformations.ReadFromAppConfig(); var result = Invoke(ci, out exception, out ROWS, MAX_ROWS, WITH_USERNAME, ref RETURN, ref SELECTION_EXP, ref SELECTION_RANGE, ref USERLIST); Console.WriteLine("Result: " + result); if (!result) { Console.WriteLine("Exception: " + exception); } }
private void SaveToDb() { try { if (check()) { if (!String.IsNullOrWhiteSpace(SapSystemName) && !String.IsNullOrWhiteSpace(SapStrutureName)) { _table = new SapTable(SapSystemName, LocalTableName, SapStrutureName); _table.DbConnectionString = txtLocalDbConnection.Text.Trim(); _table.AppendToDb = radioBtAppend.Checked; _table.NewTable = radioBtNew.Checked; } else { _table = new SapTable(LocalTableName); _table.DbConnectionString = txtLocalDbConnection.Text.Trim(); _table.AppendToDb = radioBtAppend.Checked; _table.NewTable = radioBtNew.Checked; // _table.saveDataTable(_dt); } //if (!_table.saveDataTable(_dt)) //{ // MessageBox.Show(_table.ErrorMessage); //} //else //{ // MessageBox.Show("保存成功!!"); //} WriteMessage("开始新的进程........."); _table.EventLogMessage += WriteMessage; Thread thread = new Thread(new ThreadStart(saveTable)); thread.Start(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void Test() { string exception = ""; int MAXROWS = default(int); SapTable <BAPIMATRADC> DISTRIBUTIONCHANNELSELECTION = new SapTable <BAPIMATRADC>(); SapTable <BAPIMATMFRPN> MANUFACTURERPARTNUMB = new SapTable <BAPIMATMFRPN>(); SapTable <BAPIMATRAS> MATERIALSHORTDESCSEL = new SapTable <BAPIMATRAS>(); SapTable <BAPIMATLST> MATNRLIST = new SapTable <BAPIMATLST>(); SapTable <BAPIMATRAM> MATNRSELECTION = new SapTable <BAPIMATRAM>(); SapTable <BAPIMATRAW> PLANTSELECTION = new SapTable <BAPIMATRAW>(); SapTable <BAPIRET2> RETURN = new SapTable <BAPIRET2>(); SapTable <BAPIMATRASO> SALESORGANISATIONSELECTION = new SapTable <BAPIMATRASO>(); SapTable <BAPIMATRAL> STORAGELOCATIONSELECT = new SapTable <BAPIMATRAL>(); var ci = SAPConIO.Helper.ConnectionInformations.ReadFromAppConfig(); var result = Invoke(ci, out exception, MAXROWS, ref DISTRIBUTIONCHANNELSELECTION, ref MANUFACTURERPARTNUMB, ref MATERIALSHORTDESCSEL, ref MATNRLIST, ref MATNRSELECTION, ref PLANTSELECTION, ref RETURN, ref SALESORGANISATIONSELECTION, ref STORAGELOCATIONSELECT); Console.WriteLine("Result: " + result); if (!result) { Console.WriteLine("Exception: " + exception); } }
/// <summary> /// 根据IDOC编号把IDOC复制到本地。 /// </summary> /// <param name="idocNumber">IDOC编号</param> /// <param name="SystemName">远程SAP系统名称</param> public void CopyIdocFromSAP(String idocNumber, String SystemName) { try { SAPINT.Utils.ReadTable idocReadItem = null; SAPINT.Utils.ReadTable idocReadHeader = null; SAPINT.Utils.ReadTable idocReadStatus = null; //DataTable dtIdocItem = new DataTable(); //DataTable dtIdocHeder = new DataTable(); //DataTable dtIdocStatus = new DataTable(); idocNumber = idocNumber.TrimStart('0'); String criteria = idocNumber.PadLeft(16, '0'); criteria = String.Format("DOCNUM = '{0}'", criteria); String readTableFunction = ConfigFileTool.SAPGlobalSettings.GetReadTableFunction(); idocReadItem = new SAPINT.Utils.ReadTable(SystemName); idocReadItem.TableName = "EDID4"; idocReadItem.SetCustomFunctionName(readTableFunction); idocReadItem.AddCriteria(criteria); idocReadItem.Run(); idocItem = idocReadItem.Result; if (idocItem.Rows.Count == 0) { idocReadItem = new SAPINT.Utils.ReadTable(SystemName); idocReadItem.TableName = "EDID2"; idocReadItem.SetCustomFunctionName(readTableFunction); idocReadItem.AddCriteria(criteria); idocReadItem.Run(); idocItem = idocReadItem.Result; } if (idocItem.Rows.Count == 0) { idocReadItem = new SAPINT.Utils.ReadTable(SystemName); idocReadItem.TableName = "EDIDD_OLD"; idocReadItem.SetCustomFunctionName(readTableFunction); idocReadItem.AddCriteria(criteria); idocReadItem.Run(); idocItem = idocReadItem.Result; } if (idocItem.Rows.Count == 0) { throw new Exception(String.Format("无法找到IDOC{0}明细", idocNumber)); } //读取IDOC头 idocReadHeader = new SAPINT.Utils.ReadTable(SystemName); idocReadHeader.TableName = "EDIDC"; idocReadHeader.SetCustomFunctionName(readTableFunction); idocReadHeader.AddCriteria(criteria); idocReadHeader.Run(); idocHeader = idocReadHeader.Result; //if (idocHeader.Rows.Count != 1) //{ // throw new Exception(String.Format("无法找到IDOC{0}抬头定义", idocNumber)); //} //读取IDOC状态 idocReadStatus = new SAPINT.Utils.ReadTable(SystemName); idocReadStatus.TableName = "EDIDS"; idocReadStatus.SetCustomFunctionName(readTableFunction); idocReadStatus.AddCriteria(criteria); idocReadStatus.Run(); idocStatus = idocReadStatus.Result; SapTable idocTable = null; if (idocHeader.Rows.Count > 0) { idocTable = new SapTable(SystemName, "EDIDC"); idocTable.DbConnectionString = this.ConnectionName; idocTable.AppendToDb = AppendTodb; idocTable.SaveDataTable(idocHeader); } if (idocItem.Rows.Count > 0) { idocTable = new SapTable(SystemName, "EDID4", "EDID4"); idocTable.DbConnectionString = this.ConnectionName; idocTable.AppendToDb = AppendTodb; idocTable.SaveDataTable(idocItem); } if (idocStatus.Rows.Count > 0) { idocTable = new SapTable(SystemName, "EDIDS"); idocTable.DbConnectionString = this.ConnectionName; idocTable.AppendToDb = AppendTodb; idocTable.SaveDataTable(idocStatus); } } catch (Exception) { throw; } }
public bool InvokeXml(string conID, string user, string passwd, out string exception, int MAXROWS, ref SapTable <BAPIMATRADC> DISTRIBUTIONCHANNELSELECTION, ref SapTable <BAPIMATMFRPN> MANUFACTURERPARTNUMB, ref SapTable <BAPIMATRAS> MATERIALSHORTDESCSEL, ref SapTable <BAPIMATLST> MATNRLIST, ref SapTable <BAPIMATRAM> MATNRSELECTION, ref SapTable <BAPIMATRAW> PLANTSELECTION, ref SapTable <BAPIRET2> RETURN, ref SapTable <BAPIMATRASO> SALESORGANISATIONSELECTION, ref SapTable <BAPIMATRAL> STORAGELOCATIONSELECT) { exception = ""; if (String.IsNullOrEmpty(conID)) { exception = "conID is empty."; return(false); } if (!System.Web.Security.Membership.ValidateUser(user, passwd)) { exception = "user/pass validation error."; return(false); } try { var con = SAPConIO.DB.Operations.GetConnection(conID, user); if (con == null) { exception = "Wrong connection ID."; return(false); } var ci = SAPConIO.Config.ConnectionHelper.GetSapConFromDBCon(con); return(F_BAPI_MATERIAL_GETLIST.Invoke(ci, out exception, MAXROWS, ref DISTRIBUTIONCHANNELSELECTION, ref MANUFACTURERPARTNUMB, ref MATERIALSHORTDESCSEL, ref MATNRLIST, ref MATNRSELECTION, ref PLANTSELECTION, ref RETURN, ref SALESORGANISATIONSELECTION, ref STORAGELOCATIONSELECT)); } catch (Exception ex) { exception = ex.Message; return(false); } }
/// <summary> /// FUNCTION BAPI_MATERIAL_GETLIST /// </summary> /// <param name="MAXROWS">Maximum number of materials to be selected</param> /// <param name="DISTRIBUTIONCHANNELSELECTION">Selection options for distribution channel</param> /// <param name="MANUFACTURERPARTNUMB">Manufacturer and manufacturer part number</param> /// <param name="MATERIALSHORTDESCSEL">Selection options for material description</param> /// <param name="MATNRLIST">List of material numbers with material description</param> /// <param name="MATNRSELECTION">Selection options for material number</param> /// <param name="PLANTSELECTION">Selection options for plants</param> /// <param name="RETURN">Return Parameter</param> /// <param name="SALESORGANISATIONSELECTION">Selection options for sales organization</param> /// <param name="STORAGELOCATIONSELECT">Selection options for storage locations</param> public static bool Invoke(ConnectionInformations ci, out string exception, int MAXROWS, ref SapTable <BAPIMATRADC> DISTRIBUTIONCHANNELSELECTION, ref SapTable <BAPIMATMFRPN> MANUFACTURERPARTNUMB, ref SapTable <BAPIMATRAS> MATERIALSHORTDESCSEL, ref SapTable <BAPIMATLST> MATNRLIST, ref SapTable <BAPIMATRAM> MATNRSELECTION, ref SapTable <BAPIMATRAW> PLANTSELECTION, ref SapTable <BAPIRET2> RETURN, ref SapTable <BAPIMATRASO> SALESORGANISATIONSELECTION, ref SapTable <BAPIMATRAL> STORAGELOCATIONSELECT) { exception = ""; try { SapConnections.Init(ci); RfcRepository rfcRep = SapConnections.Get(ci.Name).Repository; IRfcFunction function = rfcRep.CreateFunction("BAPI_MATERIAL_GETLIST"); function.SetValue("MAXROWS", MAXROWS); if (DISTRIBUTIONCHANNELSELECTION != null) { function.SetValue("DISTRIBUTIONCHANNELSELECTION", DISTRIBUTIONCHANNELSELECTION.ToSapObject(ci.Name)); } if (MANUFACTURERPARTNUMB != null) { function.SetValue("MANUFACTURERPARTNUMB", MANUFACTURERPARTNUMB.ToSapObject(ci.Name)); } if (MATERIALSHORTDESCSEL != null) { function.SetValue("MATERIALSHORTDESCSEL", MATERIALSHORTDESCSEL.ToSapObject(ci.Name)); } if (MATNRLIST != null) { function.SetValue("MATNRLIST", MATNRLIST.ToSapObject(ci.Name)); } if (MATNRSELECTION != null) { function.SetValue("MATNRSELECTION", MATNRSELECTION.ToSapObject(ci.Name)); } if (PLANTSELECTION != null) { function.SetValue("PLANTSELECTION", PLANTSELECTION.ToSapObject(ci.Name)); } if (RETURN != null) { function.SetValue("RETURN", RETURN.ToSapObject(ci.Name)); } if (SALESORGANISATIONSELECTION != null) { function.SetValue("SALESORGANISATIONSELECTION", SALESORGANISATIONSELECTION.ToSapObject(ci.Name)); } if (STORAGELOCATIONSELECT != null) { function.SetValue("STORAGELOCATIONSELECT", STORAGELOCATIONSELECT.ToSapObject(ci.Name)); } function.Invoke(SapConnections.Get(ci.Name)); if (DISTRIBUTIONCHANNELSELECTION == null) { DISTRIBUTIONCHANNELSELECTION = new SapTable <BAPIMATRADC>(); } DISTRIBUTIONCHANNELSELECTION.FromSapObject(function.GetTable("DISTRIBUTIONCHANNELSELECTION")); if (MANUFACTURERPARTNUMB == null) { MANUFACTURERPARTNUMB = new SapTable <BAPIMATMFRPN>(); } MANUFACTURERPARTNUMB.FromSapObject(function.GetTable("MANUFACTURERPARTNUMB")); if (MATERIALSHORTDESCSEL == null) { MATERIALSHORTDESCSEL = new SapTable <BAPIMATRAS>(); } MATERIALSHORTDESCSEL.FromSapObject(function.GetTable("MATERIALSHORTDESCSEL")); if (MATNRLIST == null) { MATNRLIST = new SapTable <BAPIMATLST>(); } MATNRLIST.FromSapObject(function.GetTable("MATNRLIST")); if (MATNRSELECTION == null) { MATNRSELECTION = new SapTable <BAPIMATRAM>(); } MATNRSELECTION.FromSapObject(function.GetTable("MATNRSELECTION")); if (PLANTSELECTION == null) { PLANTSELECTION = new SapTable <BAPIMATRAW>(); } PLANTSELECTION.FromSapObject(function.GetTable("PLANTSELECTION")); if (RETURN == null) { RETURN = new SapTable <BAPIRET2>(); } RETURN.FromSapObject(function.GetTable("RETURN")); if (SALESORGANISATIONSELECTION == null) { SALESORGANISATIONSELECTION = new SapTable <BAPIMATRASO>(); } SALESORGANISATIONSELECTION.FromSapObject(function.GetTable("SALESORGANISATIONSELECTION")); if (STORAGELOCATIONSELECT == null) { STORAGELOCATIONSELECT = new SapTable <BAPIMATRAL>(); } STORAGELOCATIONSELECT.FromSapObject(function.GetTable("STORAGELOCATIONSELECT")); return(true); } catch (Exception ex) { exception = ex.Message; return(false); } }
/// <summary> /// 填充所有的参数调用SAP RFC函数后,填充所有的参数 /// </summary> /// <param name="funame">函数名</param> /// <param name="list">输入参数列表</param> /// <param name="olist">输出参数列表</param> /// <returns></returns> private static bool InvokeFunctionFromJson(string sysName, string funame, RfcInputListJson list, out RfcOutputListJson olist) { try { if (funame == "" || null == list) { olist = null; return(false); } if (!SAPFunction.CheckFunction(sysName, funame)) { olist = null; return(false); } RfcDestination destination = SAPDestination.GetDesByName(sysName); RfcFunctionMetadata MetaData = destination.Repository.GetFunctionMetadata(funame); IRfcFunction function = MetaData.CreateFunction(); //初步序列化后的参数还需要进一步进行格式化,把结构体与表格都转化成SAP格式。 list.All.Clear(); list.All.AddRange(list.Import); list.All.AddRange(list.Change); list.All.AddRange(list.Tables); foreach (var item in list.All) { if (item.Value == null) { continue; } RfcParameterMetadata p = MetaData[item.Name]; if (p == null) { continue; } //尝试把OBJECT反解析成对应的类型 if (p.DataType == RfcDataType.STRUCTURE) { Console.WriteLine(item.Value.GetType().ToString()); if (item.Value.GetType().ToString() != "Newtonsoft.Json.Linq.JArray" && item.Value.GetType().ToString() != "System.Array") { continue; } if (item.Value.GetType().ToString() != "System.Array") { // continue; } IRfcStructure str = function.GetStructure(item.Name, true); var arr = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(item.Value.ToString()); if (arr.Count == 1) { //结构使用第一行 var o = arr[0]; for (int s = 0; s < str.Metadata.FieldCount; s++) { RfcFieldMetadata field = str.Metadata[s]; str.SetValue(field.Name, o[field.Name]); } } item.Value = str; } else if (p.DataType == RfcDataType.TABLE) { if (string.IsNullOrEmpty(item.Value.ToString())) { continue; } IRfcTable tbl = function.GetTable(item.Name, true); var arr = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(item.Value.ToString()); for (int x = 0; x < arr.Count; x++) { IRfcStructure str = tbl.Metadata.LineType.CreateStructure(); for (int s = 0; s < tbl.Metadata.LineType.FieldCount; s++) { RfcFieldMetadata field = tbl.Metadata.LineType[s]; str.SetValue(field.Name, arr[x][field.Name]); } tbl.Append(str); } item.Value = tbl; } } //填充所有的参数 for (int i = 0; i < MetaData.ParameterCount; i++) { RfcParameterMetadata pMetadata = MetaData[i]; if (list.All.Exists(x => x.Name == pMetadata.Name)) { var value = list.All.Find(x => x.Name == pMetadata.Name).Value; if (value != null) { function.SetValue(pMetadata.Name, value); } } } //远程调用函数 try { function.Invoke(destination); } catch (RfcAbapException ee) { throw new Exception(ee.Key + ee.Message); } //保留调用结果。 RfcOutputListJson outlist = new RfcOutputListJson(); //循环读取结果。把所以的结果都保存到List<object>中。 for (int i = 0; i < MetaData.ParameterCount; i++) { RfcParameterMetadata pMetadata = MetaData[i]; // if (pMetadata.Direction == RfcDirection.IMPORT) { continue; } RfcKeyValueJson d = new RfcKeyValueJson(); d.Name = pMetadata.Name; if (pMetadata.DataType == RfcDataType.STRUCTURE) { //注意,在这里就算是结构体,也把放到List中,这样可以序列化成数组格式。 List <object> tb_list = new List <object>(); IRfcStructure row = function.GetStructure(pMetadata.Name); Dictionary <string, object> rowd = new Dictionary <string, object>(); for (int x = 0; x < row.Metadata.FieldCount; x++) { rowd.Add(row[x].Metadata.Name, row[x].GetValue()); } tb_list.Add(rowd); d.Value = tb_list; } else if (pMetadata.DataType == RfcDataType.TABLE) { List <object> tb_list = new List <object>(); IRfcTable table = function.GetTable(pMetadata.Name); var readItems = table.RowCount; if (readItems > 0) { try { //保存结果到数据库。 RfcTableMetadata tableMeta = pMetadata.ValueMetadataAsTableMetadata; var _table = new SapTable(sysName, funame + "_" + pMetadata.Name, tableMeta.LineType.Name); _table.DbConnectionString = ConfigFileTool.SAPGlobalSettings.GetDefaultDbConnection(); _table.NewTable = true; _table.SaveDataTable(SAPFunction.RfcTableToDataTable(table)); // RfcTableToDb dbhelper = new RfcTableToDb(funame, d.Name, tble); // dbhelper.saveTable(); } catch (Exception ee) { throw new Exception(ee.Message); } // ThreadStart threadStart = new ThreadStart(dbhelper.saveTable); // Thread thread = new Thread(threadStart); // thread.Start(); //DbHelper.saveRfcTable(funame,ref tble); } //控制100条,数据过多会序列华出错。以后再做改善, if (readItems > 10) { readItems = 10; } for (int rowc = 0; rowc < readItems; rowc++) { IRfcStructure row = table[rowc]; Dictionary <string, object> rowd = new Dictionary <string, object>(); for (int x = 0; x < row.Metadata.FieldCount; x++) { rowd.Add(row[x].Metadata.Name, row[x].GetValue()); } tb_list.Add(rowd); } d.Value = tb_list; } else { d.Value = function.GetValue(pMetadata.Name); } //存放于不同的集合也是为了序列化方便。 switch (pMetadata.Direction) { case RfcDirection.CHANGING: outlist.Change.Add(d); break; case RfcDirection.EXPORT: outlist.Export.Add(d); break; case RfcDirection.IMPORT: outlist.Import.Add(d); break; case RfcDirection.TABLES: outlist.Tables.Add(d); break; } } olist = outlist; return(true); } catch (Exception e) { throw new SAPException(e.Message); } }