public void ZFI_VENDOR_CREATION(CaseDetail caseTobeProcess) { RfcDestination rfcDestination = GetParameters(); RfcRepository repoVendor = rfcDestination.Repository; bool isLawyer = false; if (caseTobeProcess.Entity.ParticipantType.ParticipantType1.ToUpper().Equals("ABOGADO", StringComparison.InvariantCultureIgnoreCase)) { isLawyer = true; } IRfcFunction docVendor = repoVendor.CreateFunction("ZFI_VENDOR_CREATION"); docVendor.SetValue("IM_INTERFACE_CODE", "ITF-GLPROC"); docVendor.SetValue("IM_FLATFILE", "N"); IRfcTable idTable = docVendor.GetTable("TBL_SOURCE_DATA"); idTable.Insert(); idTable.SetValue("LIFNR", String.Format("{0}{1}", caseTobeProcess.CaseNumber, caseTobeProcess.CaseKey)); idTable.SetValue("BUKRS", "1000"); idTable.SetValue("KTOKK", isLawyer ? "ZABO" : "ZCOM"); idTable.SetValue("NAME1", caseTobeProcess.Entity.FirstName); idTable.SetValue("NAME2", caseTobeProcess.Entity.MiddleName); idTable.SetValue("LNAME1", caseTobeProcess.Entity.LastName); idTable.SetValue("LNAME2", caseTobeProcess.Entity.SecondLastName); idTable.SetValue("SORT1", isLawyer ? "HONORARIOS" : "COMPENSACIONES"); var currentAddress = caseTobeProcess.Entity.Addresses.Where(a => a.AddressType.AddressType1.ToUpper().Equals("POSTAL", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); idTable.SetValue("STREET", currentAddress.IsNull()? string.Empty: currentAddress.Line1); idTable.SetValue("STR_SUPPL1", currentAddress.IsNull() ? string.Empty : currentAddress.Line2); idTable.SetValue("CITY", currentAddress.IsNull() ? string.Empty : (currentAddress.City.IsNull() ? string.Empty : currentAddress.City.City1)); idTable.SetValue("ZIP_CODE", currentAddress.IsNull() ? string.Empty : currentAddress.ZipCode); idTable.SetValue("COUNTRY", currentAddress.IsNull() ? string.Empty : (currentAddress.Country.IsNull() ? string.Empty : currentAddress.Country.Country1)); idTable.SetValue("REGION", currentAddress.IsNull() ? string.Empty : (currentAddress.State.IsNull() ? string.Empty : currentAddress.State.State1)); idTable.SetValue("LANGU", "E"); idTable.SetValue("AKONT", isLawyer ? "2030050090" : "2010010010"); idTable.SetValue("ZTERM", "0001"); idTable.SetValue("ZWELS", "0001"); var currentPhone = caseTobeProcess.Entity.Phones.Where(p => !p.PhoneNumber.IsNullOrEmpty()).FirstOrDefault(); idTable.SetValue("TEL_NUMBER", currentPhone.IsNull()? string.Empty: currentPhone.PhoneNumber); idTable.SetValue("STCD1", caseTobeProcess.Entity.SSN); idTable.SetValue("WAERS", "USD"); idTable.SetValue("WITHT", isLawyer ? "A7" : string.Empty); idTable.SetValue("WT_WITHCD", isLawyer ? "07" : string.Empty); idTable.SetValue("QLAND", isLawyer ? "PR" : string.Empty); idTable.SetValue("WT_SUBJCT", isLawyer ? "X" : string.Empty); idTable.SetValue("FDGRV", isLawyer ? "A010" : "A029"); docVendor.Invoke(rfcDestination); }
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 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); } }
private IRfcTable CreateIrfcTableForMaterialInfo(SAP_Common.SAP_Common sap_comm, string strMaterialNo, string functionName, string strRfcTableName) { IRfcTable rfcTable = sap_comm.CreateIrfcTable(functionName, strRfcTableName); rfcTable.Insert(); rfcTable.CurrentRow.SetValue("MATNR", strMaterialNo); return(rfcTable); }
public RFC_OUT_Message Rfc_Rmu_Ly_Dal(List <RFC_RMU_LY_Model.RFC_RMU_LY_ITEM_Model> rmuLyItemModels, RFC_RMU_LY_Model.RFC_RMU_LY_HEADER_Model rmuLyHeaderModel) { 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(rmuLyHeaderModel.FunctionModule); //调用函数名 IRfcTable table = rfc.GetTable("T_DATA"); //RFC表数据 IRfcStructure structure = rfc.GetStructure("I_HEADER"); //RFC表头数据 structure.SetValue("ZMESKEY", rmuLyHeaderModel.ZMESKEY); structure.SetValue("BLDAT", rmuLyHeaderModel.BLDAT); structure.SetValue("BUDAT", rmuLyHeaderModel.BUDAT); structure.SetValue("ZCOUNT", rmuLyHeaderModel.ZCOUNT); structure.SetValue("ZSUM", rmuLyHeaderModel.ZSUM); structure.SetValue("ZUSER", rmuLyHeaderModel.ZUSER); structure.SetValue("ZUNPLAN", rmuLyHeaderModel.ZUNPLAN); foreach (var _rmuLyItemModels in rmuLyItemModels) { table.Insert(); table.CurrentRow.SetValue("ZMESITEM", _rmuLyItemModels.ZMESITEM); table.CurrentRow.SetValue("RSNUM", _rmuLyItemModels.RSNUM); table.CurrentRow.SetValue("RSPOS", _rmuLyItemModels.RSPOS); table.CurrentRow.SetValue("BWART", _rmuLyItemModels.BWART); table.CurrentRow.SetValue("MATNR", _rmuLyItemModels.MATNR); table.CurrentRow.SetValue("WERKS", _rmuLyItemModels.WERKS); table.CurrentRow.SetValue("LGORT", _rmuLyItemModels.LGORT); table.CurrentRow.SetValue("MENGE", _rmuLyItemModels.MENGE); table.CurrentRow.SetValue("MEINS", _rmuLyItemModels.MEINS); table.CurrentRow.SetValue("CHARG", _rmuLyItemModels.CHARG); table.CurrentRow.SetValue("ITEM_TEXT", _rmuLyItemModels.ITEM_TEXT); //rmuLyHeaderModel.ZSUM += _rmuLyItemModels.MENGE;//所有数据全部相加,取总数 } structure.SetValue("ZSUM", rmuLyHeaderModel.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.GetString("E_MAT_DOC").ToString(); return(rfcMessage); } catch (Exception exception) { rfcMessage.E_RETURN_MESSAGE = "接口RMU_LY 错误:" + exception.ToString(); return(null); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(_configurationId); } }
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); } }
/// <summary> /// set command parameter values from the dao /// </summary> /// <param name="parameterList">SAPParameterList</param> /// <returns></returns> private void SetCommandParameter(SAPParameterList parameterList) { foreach (SAPParameter parameter in parameterList.Parameters) { if (parameter.Value == null) { continue; } if (parameter.Value.GetType() == typeof(DefaultSAPParameterList)) { IRfcTable irfcTable = rfcFunction.GetTable(parameter.Name); SAPParameterList tableParameterList = (SAPParameterList)parameter.Value; if (tableParameterList.ParameterLists.Length > 0) { foreach (SAPParameterList tableParameterLists in tableParameterList.ParameterLists) { irfcTable.Insert(); foreach (SAPParameter tableParameter in tableParameterLists.Parameters) { irfcTable.CurrentRow.SetValue(tableParameter.Name, tableParameter.Value); } } } else { irfcTable.Insert(); foreach (SAPParameter tableParameter in tableParameterList.Parameters) { irfcTable.SetValue(tableParameter.Name, tableParameter.Value); } } } else { rfcFunction.SetValue(parameter.Name, parameter.Value); } } }
public static IRfcTable CreateRFCStructure(List <Dictionary <string, object> > dictionaryList, RfcDestination destination, IRfcFunction rfc, string structureName, string tableName) { IRfcTable table = rfc.GetTable(tableName); foreach (var item in dictionaryList) { IRfcStructure structure = CreateRFCStructure(item, destination, structureName); table.Insert(structure); } return(table); }
public IRfcTable ToSapObject(string name) { Type type = typeof(T); RfcStructureMetadata sMeta = SapConnections.Get(name).Repository.GetStructureMetadata(typeof(T).Name); RfcTableMetadata tMeta = new RfcTableMetadata("", sMeta); IRfcTable t = tMeta.CreateTable(); for (int i = 0; i < this.Count; i++) { t.Insert(((ISapStructure)this[i]).ToSapObject(name)); } return(t); }
private void createBtn_Click(object sender, EventArgs e) { try { RfcRepository rfcRepository = rfcDestination.Repository; var create = rfcRepository.CreateFunction("BAPI_INTERNALORDRGRP_CREATE"); create.Invoke(rfcDestination); var hierarchyTable = create.GetTable("HIERARCHYNODES"); hierarchyTable.Append(); String groupName = createGridView.Rows[0].Cells[0].Value.ToString(); String hierLevel = "0"; String valcount = createGridView.Rows[0].Cells[1].Value.ToString(); String descript = createGridView.Rows[0].Cells[2].Value.ToString(); hierarchyTable.SetValue("GROUPNAME", groupName); hierarchyTable.SetValue("HIERLEVEL", hierLevel); hierarchyTable.SetValue("VALCOUNT", valcount); hierarchyTable.SetValue("DESCRIPT", descript); IRfcTable hierarchyValuesTable = create.GetTable("HIERARCHYVALUES"); hierarchyValuesTable.Append(); for (int i = 0; i + 1 < valueDataGrid.RowCount; i++) { hierarchyValuesTable.Insert(); hierarchyValuesTable.CurrentIndex = hierarchyValuesTable.Count - 1; hierarchyValuesTable[i].SetValue("VALFROM", valueDataGrid.Rows[i].Cells[0].Value.ToString()); hierarchyValuesTable[i].SetValue("VALTO", valueDataGrid.Rows[i].Cells[1].Value.ToString()); } for (int i = 0; i + 1 < valueDataGrid.RowCount; i++) { Console.Out.WriteLine(hierarchyValuesTable[i].GetString("VALFROM")); } create.SetValue("HIERARCHYNODES", hierarchyTable); create.SetValue("HIERARCHYVALUES", hierarchyValuesTable); create.Invoke(rfcDestination); this.Close(); } catch (Exception ex) { Console.Out.WriteLine(ex.Message); Console.Out.WriteLine(ex.StackTrace); } }
/// <summary> /// set command parameter values to sap irfc table from the dao /// </summary> /// <param name="parameterList">SAPParameterList</param> /// <returns></returns> private void SetCommandParameterTable(SAPParameterList parameterList) { foreach (SAPParameter parameter in parameterList.Parameters) { IRfcTable irfcTable = rfcFunction.GetTable(parameter.Name); irfcTable.Insert(); SAPParameterList tableParameterList = (SAPParameterList)parameter.Value; foreach (SAPParameter tableParameter in tableParameterList.Parameters) { irfcTable.SetValue(tableParameter.Name, tableParameter.Value); } } }
private IRfcTable CreateIrfcTableForMaterialInfo(SAP_Common.SAP_Common sap_comm, List <Barcode_Model> lstBarCode, string functionName, string strRfcTableName) { IRfcTable rfcTable = sap_comm.CreateIrfcTable(functionName, strRfcTableName); if (rfcTable != null) { foreach (var item in lstBarCode) { rfcTable.Insert(); rfcTable.CurrentRow.SetValue("MATNR", item.MATERIALNO); } } return(rfcTable); }
private IRfcTable CreateIrfcTableForMaterialInfo(SAP_Common.SAP_Common sap_comm, List <OutStockDetails_Model> lstOutStockDetails, string functionName, string strRfcTableName) { IRfcTable rfcTable = sap_comm.CreateIrfcTable(functionName, strRfcTableName); if (rfcTable != null) { foreach (var item in lstOutStockDetails) { rfcTable.Insert(); rfcTable.CurrentRow.SetValue("MATNR", item.MaterialNo); } } return(rfcTable); }
private IRfcTable CreateIrfcTableForMaterialInfo(SAP_Common.SAP_Common sap_comm, OutStock_Model outStockModel, string functionName, string strRfcTableName) { IRfcTable rfcTable = sap_comm.CreateIrfcTable(functionName, strRfcTableName); string[] ArrayVoucherNo = outStockModel.VoucherNo.Split(','); if (rfcTable != null) { for (int i = 0; i < ArrayVoucherNo.Count(); i++) { rfcTable.Insert(); rfcTable.CurrentRow.SetValue("BEDNR", ArrayVoucherNo[i]); } } return(rfcTable); }
//edited by Serena.Shi at 2011-09-27 #region 把DataSet的值转换成RFCTable的值 public IRfcTable ConvertDataTabletoRFCTable(DataTable dt, string tableName) { try { IRfcFunction function = null; function = destination.Repository.CreateFunction(FunctionName); IRfcTable ROFTable = function.GetTable(tableName); for (int i = 0; i < dt.Rows.Count; i++) { ROFTable.Insert(); for (int j = 0; j < dt.Columns.Count; j++) { ROFTable.CurrentRow.SetValue(dt.Columns[j].ColumnName, dt.Rows[i][j].ToString()); } } return(ROFTable); } catch (RfcCommunicationException e) { // network problem... //throw new Exception("network problem", e); throw new Exception(e.Message, e); } catch (RfcAbapRuntimeException e) { // serious problem on ABAP system side... //throw new Exception("serious problem on ABAP system side", e); throw new Exception(e.Message, e); } catch (RfcAbapBaseException e) { // The function module returned an ABAP exception, an ABAP message // or an ABAP class-based exception... //throw new Exception("The function module returned an ABAP exception, an ABAP message or an ABAP class-based exception...",e); throw new Exception(e.Message, e); } catch (RfcBaseException e) { throw e; } catch (Exception ex) { throw new Exception(message + ex.Message); } }
public string ConfirmTO(DataVM entity, string confirm) { try { RfcConfigParameters rfcParam = Connector3SapRfcConnGroup(_SAPConnectionString); RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcParam); RfcRepository rfcRepository = rfcDest.Repository; IRfcFunction rfcFunction = rfcRepository.CreateFunction("L_TO_CONFIRM"); rfcFunction.SetValue("I_LGNUM", "049"); rfcFunction.SetValue("I_TANUM", entity.TO); rfcFunction.SetValue("I_QNAME", "RFCSHARE02"); rfcFunction.SetValue("I_ENAME", "RFCSHARE02"); rfcFunction.SetValue("I_COMMIT_WORK", "X"); rfcFunction.SetValue("I_QUKNZ", confirm); IRfcTable table = rfcFunction.GetTable("T_LTAP_CONF"); table.Insert(); table.SetValue("TANUM", Convert.ToInt32(entity.TO)); table.SetValue("TAPOS", entity.TO_ORDER); table.SetValue("ALTME", entity.UNIT);//unit of material code table.SetValue("NISTA", entity.QTY); //table.SetValue("NDIFA", "");//blank //table.SetValue("NLPLA", "");//blank rfcFunction.Invoke(rfcDest); return("Ok"); } catch (RfcCommunicationException ex) { return("Error: " + ex.Message.ToString()); } catch (RfcAbapException ex) { return("Error: " + ex.Message.ToString()); } catch (RfcLogonException ex) { return("Error: " + ex.Message.ToString()); } catch (Exception ex) { return("Error: " + ex.Message.ToString()); } }
/// <summary> /// 给空内部赋值,返回一个带数据的IRfcTable /// </summary> /// <param name="conn"></param> /// <param name="rfcName"></param> /// <param name="IRfcTableName"></param> /// <param name="valueTable"></param> /// <returns></returns> public IRfcTable GetRfcTableWithValue(string conn, string rfcName, string IRfcTableName, DataTable valueTable) { //获取空的内部结构 IRfcTable itb = GetRfcTable(conn, rfcName, IRfcTableName); //根据传入valueTable,给内表赋值(字段名必须一致) if (valueTable.Rows.Count > 0) { for (int r = 0; r < valueTable.Rows.Count; r++) { itb.Insert(); for (int c = 0; c < valueTable.Columns.Count; c++) { itb.CurrentRow.SetValue(valueTable.Columns[c].ColumnName.ToString(), valueTable.Rows[r][c].ToString()); } } } return(itb); }
private IRfcTable CreateIrfcTableForProductionInfo(SAP_Common.SAP_Common sap_comm, DeliveryReceive_Model ProductionModel, UserInfo userModel, string functionName, string strRfcTableName) { IRfcTable rfcTable = sap_comm.CreateIrfcTable(functionName, strRfcTableName); //过账前,过滤掉收货数量为零的数据 var lstDeliveryDetail = ProductionModel.lstDeliveryDetail.Where(t => t.CurrentPostQty > 0).ToList(); foreach (var item in lstDeliveryDetail) { rfcTable.Insert(); rfcTable.CurrentRow.SetValue("ORDERID", item.VoucherNo.PadLeft(12, '0')); rfcTable.CurrentRow.SetValue("MATERIAL", item.MaterialNo); rfcTable.CurrentRow.SetValue("PLANT", item.Plant); rfcTable.CurrentRow.SetValue("STGE_LOC", item.StorageLoc); rfcTable.CurrentRow.SetValue("MOVE_TYPE", "101"); rfcTable.CurrentRow.SetValue("ENTRY_QNT", item.CurrentPostQty); rfcTable.CurrentRow.SetValue("BASE_UOM", item.Unit); rfcTable.CurrentRow.SetValue("MVT_IND", "F");//TODO:移动标识填什么 rfcTable.CurrentRow.SetValue("GR_RCPT", string.Empty); } return(rfcTable); }
private IRfcTable CreateIrfcTableForDeliveryInfo(SAP_Common.SAP_Common sap_comm, DeliveryReceive_Model DeliveryInfo, UserInfo userModel, string functionName, string strRfcTableName) { IRfcTable rfcTable = sap_comm.CreateIrfcTable(functionName, strRfcTableName); //过账前,过滤掉收货数量为零的数据 var lstDeliveryDetail = DeliveryInfo.lstDeliveryDetail.Where(t => t.ReceiveQty > 0).ToList(); foreach (var item in lstDeliveryDetail) { rfcTable.Insert(); rfcTable.CurrentRow.SetValue("MATERIAL", item.MaterialNo); rfcTable.CurrentRow.SetValue("PLANT", item.Plant); rfcTable.CurrentRow.SetValue("STGE_LOC", item.StorageLoc); rfcTable.CurrentRow.SetValue("PO_NUMBER", item.VoucherNo); rfcTable.CurrentRow.SetValue("PO_ITEM", item.RowNo); rfcTable.CurrentRow.SetValue("MOVE_TYPE", "101"); rfcTable.CurrentRow.SetValue("ENTRY_QNT", item.ReceiveQty); rfcTable.CurrentRow.SetValue("BASE_UOM", item.Unit); rfcTable.CurrentRow.SetValue("MVT_IND", "B"); rfcTable.CurrentRow.SetValue("GR_RCPT", string.Empty); } return(rfcTable); }
private IRfcTable CreateIrfcTableForProductionReturnInfo(SAP_Common.SAP_Common sap_comm, DeliveryReceive_Model prdReturnInfo, UserInfo userModel, string functionName, string strRfcTableName) { IRfcTable rfcTable = sap_comm.CreateIrfcTable(functionName, strRfcTableName); //过账前,过滤掉收货数量为零的数据 var lstDeliveryDetail = prdReturnInfo.lstDeliveryDetail.Where(t => t.CurrentPostQty > 0).ToList(); foreach (var item in lstDeliveryDetail) { rfcTable.Insert(); rfcTable.CurrentRow.SetValue("ORDERID", item.TrackNo.PadLeft(12, '0')); rfcTable.CurrentRow.SetValue("MATERIAL", item.MaterialNo); rfcTable.CurrentRow.SetValue("PLANT", item.Plant); rfcTable.CurrentRow.SetValue("STGE_LOC", item.StorageLoc); rfcTable.CurrentRow.SetValue("MOVE_TYPE", prdReturnInfo.MoveType); rfcTable.CurrentRow.SetValue("ENTRY_QNT", item.CurrentPostQty); rfcTable.CurrentRow.SetValue("BASE_UOM", item.Unit); rfcTable.CurrentRow.SetValue("MOVE_REAS", item.PrdReturnReason); rfcTable.CurrentRow.SetValue("RESERV_NO", item.ReserveNumber); rfcTable.CurrentRow.SetValue("RES_ITEM", item.ReserveRowNo); rfcTable.CurrentRow.SetValue("XSTOB", prdReturnInfo.MoveType == "262"?"X":string.Empty); } return(rfcTable); }
public async Task BAPI_PRODORD_CLOSE(IList <string> dt) { RfcDestination dest = GetDestination(); RfcRepository repository = dest.Repository; IRfcFunction func = repository.CreateFunction("BAPI_PRODORD_CLOSE"); IRfcStructure rfcStruct = null; IRfcTable rfcTable = func.GetTable("ORDERS"); IRfcStructure stru; IRfcTable result; //set parm rfcStruct = repository.GetStructureMetadata("BAPI_ORDER_KEY").CreateStructure(); foreach (var item in dt) { rfcStruct.SetValue("ORDER_NUMBER", item); } rfcTable.Insert(rfcStruct); //call function log.Debug("BAPI_PRODORD_CLOSE => Start"); func.Invoke(dest); log.Debug("BAPI_PRODORD_CLOSE => Done"); //log result result = func.GetTable("DETAIL_RETURN"); for (int k = 0; k < result.RowCount; k++) { stru = result[k]; log.Debug(string.Format("SYSTEM:{0},PPNUMBER:{1},Type:{2},Message:{3}", stru.GetValue("SYSTEM").ToString(), stru.GetValue("ORDER_NUMBER").ToString(), stru.GetValue("TYPE").ToString(), stru.GetValue("MESSAGE").ToString()) ); } rfcTable.Clear(); }
public void WriteToSAP() { //function parameters param.Clear(); // SAP function funct = sap.getFunction(sap.rfcDest, "ZF_INTERFAZ_IVEND_SAP2", param); // detail structure IRfcTable tDetail = funct.GetTable("T_DETALLES"); tDetail.Insert(); // This adds a new row to the table: tDetail.CurrentIndex = tDetail.Count - 1; // assign value to table tDetail.SetValue("SOCIEDAD", 2000); tDetail.SetValue("TIENDA", "tienda"); tDetail.SetValue("FECHA", DateTime.Today); // call function to insert the record funct.Invoke(sap.rfcDest); // This table returns information about the transaction on IRfcTable tReturn = funct.GetTable("T_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; } }
private void createBtn_Click(object sender, EventArgs e) { try { RfcRepository rfcRepository = rfcDestination.Repository; var create = rfcRepository.CreateFunction("BAPI_COSTCENTERGROUP_CREATE"); create.Invoke(rfcDestination); String contrArea = createGridView.Rows[0].Cells[0].Value.ToString(); var hierarchyTable = create.GetTable("HIERARCHYNODES"); hierarchyTable.Append(); String groupName = createGridView.Rows[0].Cells[1].Value.ToString(); String hierLevel = "0"; String valcount = createGridView.Rows[0].Cells[2].Value.ToString(); String descript = createGridView.Rows[0].Cells[3].Value.ToString(); hierarchyTable.SetValue("GROUPNAME", groupName); hierarchyTable.SetValue("HIERLEVEL", hierLevel); hierarchyTable.SetValue("VALCOUNT", valcount); hierarchyTable.SetValue("DESCRIPT", descript); IRfcTable hierarchyValuesTable = create.GetTable("HIERARCHYVALUES"); //Ohne Append können die Values nicht gesetzt werden hierarchyValuesTable.Append(); for (int i = 0; i + 1 < valueDataGrid.RowCount; i++) { hierarchyValuesTable.Insert(); hierarchyValuesTable.CurrentIndex = hierarchyValuesTable.Count - 1; hierarchyValuesTable[i].SetValue("VALFROM", valueDataGrid.Rows[i].Cells[0].Value.ToString()); hierarchyValuesTable[i].SetValue("VALTO", valueDataGrid.Rows[i].Cells[1].Value.ToString()); } for (int i = 0; i + 1 < valueDataGrid.RowCount; i++) { Console.Out.WriteLine(hierarchyValuesTable[i].GetString("VALFROM")); } create.SetValue("HIERARCHYNODES", hierarchyTable); create.SetValue("HIERARCHYVALUES", hierarchyValuesTable); create.SetValue("CONTROLLINGAREAIMP", contrArea); create.Invoke(rfcDestination); this.Close(); } /*catch (RfcCommunicationException ex) * { * Console.Out.WriteLine(ex.Message); * } * catch (RfcLogonException ex) * { * Console.Out.WriteLine(ex.Message); * } * catch (RfcAbapRuntimeException ex) * { * Console.Out.WriteLine(ex.Message); * }*/ catch (Exception ex) { Console.Out.WriteLine(ex.Message); Console.Out.WriteLine(ex.StackTrace); } }
/// <summary> /// 调用SAP提供的RFC函数ZPSRFC03传递项目信息和wbs信息给SAP /// </summary> /// <param name="project">项目信息</param> /// <param name="wbsInfo">wbs信息</param> public List <ReturnMessage> InvokeRFCFunctionZPSRFC03(Project project, WBSInfo wbsInfo) { IRfcFunction function = null; List <ReturnMessage> returnMessage = new List <ReturnMessage>(); try { try { function = _rfcDestination.Repository.CreateFunction("ZPSRFC03"); // function.Invoke(_rfcDestination); // IRfcStructure itb = function.GetStructure("ZSPS_003"); IRfcTable projectTable = function.GetTable("LT_XMDY"); projectTable.Insert(); //IRfcStructure struSAP = projectTable.Metadata.LineType.CreateStructure(); //struSAP.SetValue("POSID", project.ProjectUniqueID);//传入项目编码 //struSAP.SetValue("POST1", project.ProjectName);//传入项目名称 //struSAP.SetValue("PROFL", project.ProjectTypeID);//传入项目编码 //struSAP.SetValue("VERNR", project.ProjectManager);//传入项目经理 //struSAP.SetValue("PXMDH", project.ProjectCodeName);//传入项目代号 //struSAP.SetValue("PXMLX", project.ProjectType);//传入项目类型 //struSAP.SetValue("PWTBM", project.DelegateDepartment);//传入委托部门 //struSAP.SetValue("PCDBM", project.UnderTaskDepartment);//传入承担部门 //struSAP.SetValue("FZDDJ", project.ProjectComplexLevel);//传入项目复杂度等级 //struSAP.SetValue("PXYXJ", project.ProjectPriority);//传入项目优先级 //struSAP.SetValue("ESTAT", project.ProjectStatus);//传入项目状态 //projectTable.Append(struSAP); //function.SetValue("LT_XMDY", projectTable); //function.Invoke(_rfcDestination); projectTable.CurrentRow.SetValue("POSID", project.ProjectUniqueID); //传入项目编码 //projectTable.CurrentRow.SetValue("POSID", "B1909007");//传入项目编码 projectTable.CurrentRow.SetValue("POST1", project.ProjectName); //传入项目名称 projectTable.CurrentRow.SetValue("PROFL", project.ProjectTypeID); //传入项目编码 //projectTable.CurrentRow.SetValue("VERNR", project.ProjectManager);//传入项目经理(20190926讨论后,决定不需要传项目经理) //projectTable.CurrentRow.SetValue("VERNR", 00000002);//传入项目经理 projectTable.CurrentRow.SetValue("PXMDH", project.ProjectCodeName); //传入项目代号 projectTable.CurrentRow.SetValue("PXMLX", project.ProjectType); //传入项目类型 projectTable.CurrentRow.SetValue("PWTBM", project.DelegateDepartment); //传入委托部门 //projectTable.CurrentRow.SetValue("PWTBM", "10000010");//传入委托部门 projectTable.CurrentRow.SetValue("PCDBM", project.UnderTaskDepartment); //传入承担部门 //projectTable.CurrentRow.SetValue("PCDBM", "10000010");//传入承担部门 projectTable.CurrentRow.SetValue("FZDDJ", project.ProjectComplexLevel); //传入项目复杂度等级 projectTable.CurrentRow.SetValue("PXYXJ", project.ProjectPriority); //传入项目优先级 projectTable.CurrentRow.SetValue("ESTAT", project.ProjectStatus); //传入项目状态 // function = _rfcDestination.Repository.CreateFunction("ZPSRFC03"); function.SetValue("LT_XMDY", projectTable); // function.Invoke(_rfcDestination); IRfcTable wbsTable = function.GetTable("LT_WBSD"); //for (int i = 0; i < wbsInfo.WbsFolders.Count(); i++) //{ // IRfcStructure struSAP2 = wbsTable.Metadata.LineType.CreateStructure(); // struSAP2.SetValue("ZPOSID", wbsInfo.WbsFolders[i].WBSUniqueNo);//传入wbs的DS 阶段 ID // struSAP2.SetValue("POSIDNAME", wbsInfo.WbsFolders[i].WBSName);//传入wbs的DS 阶段名称 // struSAP2.SetValue("PSPID", wbsInfo.ProjectUniqueID); // wbsTable.Append(struSAP2); //} for (int i = 0; i < wbsInfo.WbsFolders.Count(); i++) { wbsTable.Insert(); wbsTable.CurrentRow.SetValue("ZPOSID", wbsInfo.WbsFolders[i].WBSUniqueNo); //传入wbs的DS 阶段 ID wbsTable.CurrentRow.SetValue("POSIDNAME", wbsInfo.WbsFolders[i].WBSName); //传入wbs的DS 阶段名称 wbsTable.CurrentRow.SetValue("PSPID", wbsInfo.ProjectUniqueID); //wbsTable.CurrentRow.SetValue("PSPID", "B1909007"); } // function = _rfcDestination.Repository.CreateFunction("ZPSRFC03"); function.SetValue("LT_WBSD", wbsTable); // function.SetParameterActive(0, true); function.Invoke(_rfcDestination); } catch (Exception ex) { //LogHelper.WriteLog("连接SAP远程服务器出错:" + ex.Message); LogHelper.Error("连接SAP远程服务器出错:" + ex.Message, ex); } // function.GetElementMetadata(2).ValueMetadataAsTableMetadata.LineType.Name.ElementAt.SetValue("POSID", project.ProjectUniqueID);//传入项目编码 //function.SetValue("POSID", project.ProjectUniqueID);//传入项目编码 //function.SetValue("POST1", project.ProjectName);//传入项目名称 //function.SetValue("PROFL", project.ProjectTypeID);//传入项目编码 //function.SetValue("VERNR", project.ProjectManager);//传入项目经理 //function.SetValue("PXMDH", project.ProjectCodeName);//传入项目代号 //function.SetValue("PXMLX", project.ProjectType);//传入项目类型 //function.SetValue("PWTBM", project.DelegateDepartment);//传入委托部门 //function.SetValue("PCDBM", project.UnderTaskDepartment);//传入承担部门 //function.SetValue("FZDDJ", project.ProjectComplexLevel);//传入项目复杂度等级 //function.SetValue("PXYXJ", project.ProjectPriority);//传入项目优先级 //function.SetValue("ESTAT", project.ProjectStatus);//传入项目状态 // var Nos = from c in wbsInfo.WbsFolders select c.WBSUniqueNo; // var Names = from n in wbsInfo.WbsFolders select n.WBSName; // string wbsUniqueNos = string.Join("、",Nos.ToArray()); //string wbsNames = string.Join("、",Names.ToArray()); //foreach (var item in wbsInfo.WbsFolders) //{ // function.SetValue("ZPOSID", item.WBSUniqueNo);//传入wbs的DS 阶段 ID // function.SetValue("POSIDNAME", item.WBSName);//传入wbs的DS 阶段名称 //} //function.SetValue("PSPID", wbsInfo.ProjectUniqueID);//传入项目编码 //function.SetParameterActive(0,true); //function.Invoke(_rfcDestination); //获取调用SAP的ZPSRFC03返回值到DataTable IRfcTable myrfcTable = function.GetTable("LT_RETURN");//rfc server function 返回值table结构名称 int liElement = 0; for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++) { RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement); dtr.Columns.Add(metadata.Name); //循环创建列 } foreach (IRfcStructure dr in myrfcTable) //循环table结构表 { DataRow row = dtr.NewRow(); //创建新行 for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++) { RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement); row[metadata.Name] = dr.GetString(metadata.Name).Trim(); } dtr.Rows.Add(row); } //输出调用返回日志 for (int i = 0; i < dtr.Rows.Count; i++) { returnMessage.Add(new ReturnMessage() { Type = dtr.Rows[i]["TYPE"].ToString(), Message = dtr.Rows[i]["MESSAGE"].ToString(), }); LogHelper.WriteLog("SAP返回结果:消息类型:" + dtr.Rows[i]["TYPE"].ToString() + "\t消息文本" + dtr.Rows[i]["MESSAGE"].ToString()); } } catch (Exception ex) { // LogHelper.WriteLog("调用SAP函数ZPSRFC03出错:" + ex.Message); LogHelper.Error("调用SAP函数ZPSRFC03出错:" + ex.Message, ex); } return(returnMessage); }
public void InvokeRFCFunctionZPSRFC04(WBSInfo wbsInfo) { IRfcFunction function = null; try { try { function = _rfcDestination.Repository.CreateFunction("ZPSRFC04"); IRfcTable wbsTable = function.GetTable("LT_GSDATA"); for (int i = 0; i < wbsInfo.WbsFolders.Count(); i++) { for (int j = 0; j < wbsInfo.WbsFolders[i].TimeCosts.Count(); j++) { wbsTable.Insert(); wbsTable.CurrentRow.SetValue("PSPID", wbsInfo.ProjectUniqueID); //项目定义编码 wbsTable.CurrentRow.SetValue("ZPOSID", wbsInfo.WbsFolders[i].WBSUniqueNo); //传入wbs的DS 阶段 ID wbsTable.CurrentRow.SetValue("SYGID", wbsInfo.WbsFolders[i].TimeCosts[j].LoginName); //员工ID 00000002 wbsTable.CurrentRow.SetValue("MJAHR", wbsInfo.WbsFolders[i].TimeCosts[j].Yeart); //年 wbsTable.CurrentRow.SetValue("SGSYF", wbsInfo.WbsFolders[i].TimeCosts[j].Montht); //月 wbsTable.CurrentRow.SetValue("SJGSZ", wbsInfo.WbsFolders[i].TimeCosts[j].TotalTime); } } function.SetValue("LT_GSDATA", wbsTable); function.Invoke(_rfcDestination); } catch (Exception ex) { //LogHelper.WriteLog("连接SAP远程服务器出错:" + ex.Message); LogHelper.Error("连接SAP远程服务器出错:" + ex.Message, ex); } //获取调用SAP的ZPSRFC04返回值到DataTable IRfcTable myrfcTable = function.GetTable("LT_RETURN");//rfc server function 返回值table结构名称 int liElement = 0; for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++) { RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement); dtr.Columns.Add(metadata.Name); //循环创建列 } foreach (IRfcStructure dr in myrfcTable) //循环table结构表 { DataRow row = dtr.NewRow(); //创建新行 for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++) { RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement); row[metadata.Name] = dr.GetString(metadata.Name).Trim(); } dtr.Rows.Add(row); } //输出调用返回日志 for (int i = 0; i < dtr.Rows.Count; i++) { LogHelper.WriteLog("SAP返回结果:消息类型:" + dtr.Rows[i]["TYPE"].ToString() + "\t消息文本" + dtr.Rows[i]["MESSAGE"].ToString()); } } catch (Exception ex) { // LogHelper.WriteLog("调用SAP函数ZPSRFC04出错:" + ex.Message); LogHelper.Error("调用SAP函数ZPSRFC04出错:" + ex.Message, ex); } }
public void get_integracao() { List <Classes.ParametroRFC> parametros = new List <Classes.ParametroRFC> { new Classes.ParametroRFC() { TIPO_REGISTRO = "1" }, new Classes.ParametroRFC() { TIPO_REGISTRO = "2" }, new Classes.ParametroRFC() { TIPO_REGISTRO = "3" } }; // Cria parametros de conexão RfcConfigParameters meusap = new RfcConfigParameters(); // Alimenta parametros SAP Logon meusap.Add(RfcConfigParameters.Name, txt_name.Text); meusap.Add(RfcConfigParameters.AppServerHost, txt_host.Text); meusap.Add(RfcConfigParameters.SystemNumber, txt_number.Text); // Alimenta parametros SAP GUI meusap.Add(RfcConfigParameters.Client, txt_client.Text); meusap.Add(RfcConfigParameters.User, txt_user.Text); meusap.Add(RfcConfigParameters.Password, txt_pass.Text); meusap.Add(RfcConfigParameters.SAPRouter, txt_sao_router.Text); // Cria destino RfcDestination meurfc = RfcDestinationManager.GetDestination(meusap); try { if (meurfc != null) { // Verifica conexão meurfc.Ping(); lbl_status.Text = "SAP - Conectado com sucesso."; // Lê tabela RfcRepository repo = meurfc.Repository; // Define função de exportação de textos IRfcFunction funcaoRT = repo.CreateFunction("ZSD_RFC_INTEGRACAO"); // Define parametros da função IRfcTable tab_parametro = funcaoRT.GetTable("T_PARAMETER"); IRfcStructure p_estrutura = funcaoRT.GetStructure("P_ESTRUTURA"); foreach (Classes.ParametroRFC item in parametros) { tab_parametro.Insert(); tab_parametro[tab_parametro.CurrentIndex].SetValue("TIPO_REGISTRO", item.TIPO_REGISTRO.ToString()); p_estrutura.SetValue("TIPO_REGISTRO", item.TIPO_REGISTRO.ToString()); } //funcaoRT.SetValue("TABELA", parametros); // Chama função funcaoRT.Invoke(meurfc); // Recupera Dados cru, você precisa trata-los para // que sejam humanamente legivelif IRfcStructure tabela = funcaoRT.GetStructure("P_RETURN"); // Recupera texto string dados = tabela.GetValue(3).ToString(); // Workaround para limpar tabela // Existem métodos mais eficientes // Este é apenas um caminho rápido para exemplo // Também há possibilidades em diferentes funções e BAPis // Converter um set de dados da função em um set de dados .NET dados = dados.Replace("TABLE [STRUCTURE TAB512 { FIELD WA=", ""); dados = dados.Replace("[STRUCTURE TAB512 { FIELD WA=", ""); dados = dados.Replace("}]", "\n"); // alimenta GUI txt_return.AppendText(dados.TrimStart()); } } catch (Exception ex) { // Erro ao conectar lbl_status.Text = "SAP - Problema de Conexão"; MessageBox.Show(ex.Message.ToString(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
///// <summary> ///// 获取物料状态 ///// </summary> ///// <param name="MatCode">物料编号</param> ///// <param name="rList"></param> ///// <returns></returns> //public List<MaterialStatus> ZRFC_GETMATORDER(string MatCode) //{ // List<MaterialStatus> rList = new List<MaterialStatus>(); // try // { // RfcRepository repo = Conn.Repository; // IRfcFunction rfcfunc = repo.CreateFunction("ZRFC_GETMATORDER"); // rfcfunc.SetValue("MATNR", MatCode); // rfcfunc.Invoke(Conn); // IRfcTable RfcTable = rfcfunc.GetTable("MATNRDATA"); // for (int i = 0; i < RfcTable.Count(); i++) // { // MaterialStatus model = new MaterialStatus(); // //model.MATNR = RfcTable[i].GetValue("MATNR").ToString(); // //model.ZCANORDER = RfcTable[i].GetValue("ZCANORDER").ToString(); // //model.ZREPROD = RfcTable[i].GetValue("ZREPROD").ToString(); // rList.Add(model); // } // } // catch // { // rList = null; // } // return rList; //} public SapRetrun CREATE_BAPI_ACC_DOCUMENT_POST(SapUpload model) { try { RfcRepository repo = Conn.Repository; IRfcFunction Fun = repo.CreateFunction("ZBAPI_ACC_DOCUMENT_POST"); //结构体doc IRfcStructure tb = Fun.GetStructure("DOCUMENTHEADER"); DOCUMENTHEADER doc = model.结构体DOC; tb.SetValue("USERNAME", doc.USERNAME); tb.SetValue("HEADER_TXT", doc.HEADER_TXT); tb.SetValue("COMP_CODE", doc.COMP_CODE); tb.SetValue("DOC_DATE", doc.DOC_DATE); tb.SetValue("PSTNG_DATE", doc.PSTNG_DATE); tb.SetValue("TRANS_DATE", doc.TRANS_DATE); tb.SetValue("DOC_TYPE", doc.DOC_TYPE); tb.SetValue("BUS_ACT", doc.BUS_ACT); tb.SetValue("OBJ_TYPE", doc.OBJ_TYPE); tb.SetValue("REF_DOC_NO", doc.REF_DOC_NO); //一般性总账科目 if (model.一般性总账 != null && model.一般性总账.Count > 0) { IRfcTable tb1 = Fun.GetTable("ACCOUNTGL"); foreach (var item in model.一般性总账) { tb1.Insert(); tb1.CurrentRow.SetValue("ITEMNO_ACC", item.ITEMNO_ACC); tb1.CurrentRow.SetValue("GL_ACCOUNT", item.GL_ACCOUNT); tb1.CurrentRow.SetValue("ITEM_TEXT", item.ITEM_TEXT); tb1.CurrentRow.SetValue("ALLOC_NMBR", item.ALLOC_NMBR); tb1.CurrentRow.SetValue("COSTCENTER", item.COSTCENTER); tb1.CurrentRow.SetValue("PROFIT_CTR", item.PROFIT_CTR); tb1.CurrentRow.SetValue("ACCT_TYPE", item.ACCT_TYPE); if (!string.IsNullOrEmpty(item.ASSET_NO)) { tb1.CurrentRow.SetValue("ASSET_NO", item.ASSET_NO); tb1.CurrentRow.SetValue("SUB_NUMBER", "0000"); tb1.CurrentRow.SetValue("ACCT_TYPE", "A"); } } } //科目D if (model.科目D != null && model.科目D.Count > 0) { IRfcTable tb1 = Fun.GetTable("ACCOUNTRECEIVABLE"); foreach (var item in model.科目D) { tb1.Insert(); tb1.CurrentRow.SetValue("ITEMNO_ACC", item.ITEMNO_ACC); tb1.CurrentRow.SetValue("CUSTOMER", item.CUSTOMER); tb1.CurrentRow.SetValue("ITEM_TEXT", item.ITEM_TEXT); tb1.CurrentRow.SetValue("ALLOC_NMBR", item.ALLOC_NMBR); tb1.CurrentRow.SetValue("PROFIT_CTR", item.PROFIT_CTR); } } //科目K if (model.科目K != null && model.科目K.Count > 0) { IRfcTable tb1 = Fun.GetTable("ACCOUNTPAYABLE"); foreach (var item in model.科目K) { tb1.Insert(); tb1.CurrentRow.SetValue("ITEMNO_ACC", item.ITEMNO_ACC); tb1.CurrentRow.SetValue("VENDOR_NO", item.VENDOR_NO); tb1.CurrentRow.SetValue("ITEM_TEXT", item.ITEM_TEXT); tb1.CurrentRow.SetValue("ALLOC_NMBR", item.ALLOC_NMBR); if (!string.IsNullOrEmpty(item.PO_NUMBER)) { tb1.CurrentRow.SetValue("SP_GL_IND", item.UMSKZ); tb1.CurrentRow.SetValue("GL_ACCOUNT", item.GL_ACCOUNT); tb1.CurrentRow.SetValue("PROFIT_CTR", item.PROFIT_CTR); } else if (!string.IsNullOrEmpty(item.PROFIT_CTR)) { tb1.CurrentRow.SetValue("GL_ACCOUNT", item.GL_ACCOUNT); tb1.CurrentRow.SetValue("PROFIT_CTR", item.PROFIT_CTR); } } } if (model.币种 != null && model.币种.Count > 0) { IRfcTable tb2 = Fun.GetTable("CURRENCYAMOUNT"); foreach (var item in model.币种) { tb2.Insert(); tb2.CurrentRow.SetValue("ITEMNO_ACC", item.ITEMNO_ACC); tb2.CurrentRow.SetValue("CURRENCY", item.CURRENCY); tb2.CurrentRow.SetValue("AMT_DOCCUR", item.AMT_DOCCUR); tb2.CurrentRow.SetValue("EXCH_RATE", item.EXCH_RATE); } } if (model.行项目 != null && model.行项目.Count > 0) { IRfcTable tb3 = Fun.GetTable("EXTENSION2"); foreach (var item in model.行项目) { tb3.Insert(); tb3.CurrentRow.SetValue("STRUCTURE", item.STRUCTURE); tb3.CurrentRow.SetValue("VALUEPART1", item.VALUEPART1); tb3.CurrentRow.SetValue("VALUEPART2", item.VALUEPART2); tb3.CurrentRow.SetValue("VALUEPART3", item.VALUEPART3); tb3.CurrentRow.SetValue("VALUEPART4", item.VALUEPART4); } } Fun.Invoke(Conn); SapRetrun result = new SapRetrun(); var voucher = Fun.GetValue("OBJ_KEY").ToString(); if (!string.IsNullOrEmpty(voucher) && voucher != "$") { result.TYPE = "S"; result.MESSAGE = "凭证上传成功"; result.VOUCHER = voucher; } else { var Return = Fun.GetTable("RETURN"); if (Return.RowCount >= 2) { result.TYPE = Return[1].GetValue("TYPE").ToString(); result.MESSAGE = Return[1].GetValue("MESSAGE").ToString(); result.VOUCHER = Return[1].GetValue("MESSAGE_V2").ToString(); } else { result.TYPE = Return[0].GetValue("TYPE").ToString(); result.MESSAGE = Return[0].GetValue("MESSAGE").ToString(); result.VOUCHER = Return[0].GetValue("MESSAGE_V2").ToString(); } } return(result); } catch (Exception ex) { throw; } }
/// <summary> /// 给函数的深层结构赋值(行赋值) /// </summary> /// <param name="IRFCS"></param> /// <param name="stype"></param> /// <param name="ceng"></param> /// <param name="tname"></param> /// <returns></returns> public DataTable setStructureByStru(IRfcStructure IRFCS, string stype, string ceng, string tname) { string linetabletypename = ""; //表结构名称 string linetablename = ""; //表名称 int rowindex = 0; int columnindex = 0; int r = 0; int c = 0; string sname = ""; String[] tnames = tname.Split('.'); DataTable dt = new DataTable(); if (stype == "TABLE") { dt = dsRFC.Tables[tname]; String[] snames = tnames[tnames.Count() - 1].Split('[', ']', ','); sname = snames[0].ToString(); r = int.Parse(snames[1].Substring(1, snames[1].Length - 1).ToString()); c = int.Parse(snames[2].Substring(1, snames[2].Length - 1).ToString()); IRfcStructure import = null; IRfcTable table = IRFCS.GetTable(sname); foreach (DataRow item1 in dt.Rows) { import = SapRfcRepository.GetStructureMetadata(table.Metadata.LineType.Name).CreateStructure(); columnindex = 0; foreach (DataColumn item2 in dt.Columns) { if (item2.Namespace == "TABLE") { linetabletypename = tname + "." + item2.ColumnName.ToString(); linetablename = linetabletypename + "[R" + (rowindex + 1).ToString() + ",C" + (columnindex + 1).ToString() + "]"; setStructureByStru(import, item2.Namespace, linetabletypename, linetablename); } else if (item2.Namespace == "STRUCTURE") { linetabletypename = tname + "." + item2.ColumnName.ToString(); linetablename = linetabletypename + "[R" + (rowindex + 1).ToString() + ",C" + (columnindex + 1).ToString() + "]"; setStructureByStru(import, item2.Namespace, linetabletypename, linetablename); } else { if (!string.IsNullOrEmpty(item1[item2.ColumnName].ToString())) { import.SetValue(item2.ColumnName, item1[item2.ColumnName]); } } columnindex++; } table.Insert(import); rowindex++; } } else if (stype == "STRUCTURE") { dt = dsRFC.Tables[tname]; String[] snames = tnames[tnames.Count() - 1].Split('[', ']', ','); sname = snames[0].ToString(); r = int.Parse(snames[1].Substring(1, snames[1].Length - 1).ToString()); c = int.Parse(snames[2].Substring(1, snames[2].Length - 1).ToString()); IRfcStructure structure = IRFCS.GetStructure(sname); foreach (DataRow item1 in dt.Rows) { columnindex = 0; foreach (DataColumn item2 in dt.Columns) { if (item2.Namespace == "TABLE") { linetabletypename = tname + "." + item2.ColumnName.ToString(); linetablename = linetabletypename + "[R" + (rowindex + 1).ToString() + ",C" + (columnindex + 1).ToString() + "]"; setStructureByStru(structure, item2.Namespace, linetabletypename, linetablename); } else if (item2.Namespace == "STRUCTURE") { linetabletypename = tname + "." + item2.ColumnName.ToString(); linetablename = linetabletypename + "[R" + (rowindex + 1).ToString() + ",C" + (columnindex + 1).ToString() + "]"; setStructureByStru(structure, item2.Namespace, linetabletypename, linetablename); } else { structure.SetValue(item2.ColumnName, item1[item2.ColumnName]); } columnindex++; } rowindex++; } } else { } return(dt); }
/// <summary>执行按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 函数执行ToolStripMenuItem_Click(object sender, EventArgs e) { try { ttbFunName.Focus(); //指定函数名称 dsRFC.DataSetName = ttbFunName.Text.Trim(); myfun = SapRfcRepository.CreateFunction(ttbFunName.Text.Trim());//根据输入的函数名获取函数对象 //传入值赋值 foreach (DataTable item in dsRFC.Tables) { //传入值赋值 if (item.Namespace == "IM") { int imrowindex = 0; foreach (DataRow item1 in item.Rows) { if (myfun.Metadata[item1["Code"].ToString()].DataType != RfcDataType.TABLE && myfun.Metadata[item1["Code"].ToString()].DataType != RfcDataType.STRUCTURE) { if (!string.IsNullOrEmpty(item1["Value"].ToString())) { myfun.SetValue(item1["Code"].ToString(), item1["Value"].ToString()); } } if (myfun.Metadata[item1["Code"].ToString()].DataType == RfcDataType.TABLE) { if (dsRFC.Tables.Contains("IMT." + item1["Code"].ToString() + "[R" + (imrowindex + 1).ToString() + ",C3]")) { //setStructureByFun(myfun, myfun.Metadata[item1["Code"].ToString()].DataType.ToString(), "IMT." + item1["Code"].ToString(), "IMT." + item1["Code"].ToString() + "[R" + (imrowindex + 1).ToString() + ",C3]"); setStructureByFun(myfun, myfun.Metadata[item1["Code"].ToString()].DataType.ToString(), "IMT." + item1["Code"].ToString() + "[R" + (imrowindex + 1).ToString() + ",C3]", "IMT." + item1["Code"].ToString()); } } imrowindex++; } } //传入结构赋值 if (item.Namespace == "IMS") { if (item.Rows.Count > 0) { setStructureByFun(myfun, "STRUCTURE", item.Namespace, item.TableName); } } //表赋值 if (item.Namespace == "Tables") { if (item.Rows.Count > 0) { IRfcStructure import = null; IRfcTable table = myfun.GetTable(item.TableName); foreach (DataRow item1 in item.Rows) { import = SapRfcRepository.GetStructureMetadata(myfun.Metadata[item.TableName].ValueMetadataAsTableMetadata.LineType.Name).CreateStructure(); foreach (DataColumn item2 in item.Columns) { item2.Namespace = "String"; if (!string.IsNullOrEmpty(item1[item2.ColumnName].ToString())) { import.SetValue(item2.ColumnName, item1[item2.ColumnName]); } } table.Insert(import); } } } } Stopwatch = new System.Diagnostics.Stopwatch(); CWaitForm b = new CWaitForm(); b._wtVoid = 执行; b.ShowDialog(); toolStripMenuItem1.Text = "SAP端执行时间:" + Stopwatch.Elapsed.ToString(); int exrowindex = -1; //获取返回值 foreach (DataRow item in dtEX.Rows) { exrowindex++; string flag = ""; if (item["Value"].ToString().Length >= 4) { flag = item["Value"].ToString().Substring(0, 4); } if (flag == "点击赋值") { if (dsRFC.Tables.Contains("EXT." + item["Code"].ToString())) { DataTable dt = new DataTable(); if (!dsRFC.Tables.Contains("EXT." + item["Code"].ToString() + "[R" + (exrowindex + 1).ToString() + ",C3]")) { dt = dsRFC.Tables["EXT." + item["Code"].ToString()].Clone(); dt.Namespace = "EXT." + item["Code"].ToString(); dt.TableName = "EXT." + item["Code"].ToString() + "[R" + (exrowindex + 1).ToString() + ",C3]"; dsRFC.Tables.Add(dt); } else { dt = dsRFC.Tables["EXT." + item["Code"].ToString() + "[R" + (exrowindex + 1).ToString() + ",C3]"]; dt.Clear(); } IRfcTable irtb; irtb = (IRfcTable)myfun.GetValue(item["Code"].ToString()); if (irtb.RowCount > 0) { for (int i = 0; i < irtb.RowCount; i++) { DataRow dr = dt.NewRow(); foreach (DataColumn item1 in dt.Columns) { item1.Namespace = "String"; irtb.CurrentIndex = i; dr[item1.ColumnName] = irtb.CurrentRow[item1.ColumnName].GetValue(); } dt.Rows.Add(dr); } } } //if (!dsRFC.Tables.Contains(linetablename)) //{ // //不存在则创建 // DataTable dt = new DataTable(); // dt = dsRFC.Tables[linetabletypename].Clone(); // dt.Namespace = linetabletypename; // dt.TableName = linetablename; // dsRFC.Tables.Add(dt); //} } else { item["Value"] = myfun.GetValue(item["Code"].ToString()); } } //获取表结果,结构结果 foreach (DataTable item in dsRFC.Tables) { if (item.Namespace == "Tables") { IRfcTable irtb; irtb = (IRfcTable)myfun.GetValue(item.TableName); if (irtb.RowCount > 0) { item.Clear(); for (int i = 0; i < irtb.RowCount; i++) { DataRow dr = item.NewRow(); foreach (DataColumn item1 in item.Columns) { item1.Namespace = "String"; irtb.CurrentIndex = i; dr[item1.ColumnName] = irtb.CurrentRow[item1.ColumnName].GetValue(); } item.Rows.Add(dr); } } } else if (item.Namespace == "EXS") { IRfcStructure irs; String[] ssname = item.TableName.Split('.'); irs = (IRfcStructure)myfun.GetValue(ssname[1]); if (irs.Count > 0) { item.Clear(); DataRow dr = item.NewRow(); foreach (DataColumn item1 in item.Columns) { if (item1.Namespace == "STRUCTURE") { dr[item1.ColumnName.ToString()] = "点击赋值"; } else if (item1.Namespace == "TABLE") { dr[item1.ColumnName.ToString()] = "点击赋值"; } else { dr[item1.ColumnName.ToString()] = irs.GetValue(item1.ColumnName.ToString()); } } item.Rows.Add(dr); } } } string filepath = ""; filepath = System.Environment.CurrentDirectory + "\\RFCFunConfig\\" + dsRFC.DataSetName.ToString() + "\\" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + "\\"; if (!File.Exists(filepath)) { FileInfo oInfo = new FileInfo(filepath); if (!Directory.Exists(oInfo.DirectoryName)) { Directory.CreateDirectory(oInfo.DirectoryName); } } dsRFC.WriteXmlSchema(filepath + "\\JieGou.XML"); dsRFC.WriteXml(filepath + "\\ShuZhi.XML"); MessageBox.Show("执行成功,结果保存在" + filepath); } catch (Exception ex) { MessageBox.Show(ex.Message); } }