private void button1_Click(object sender, EventArgs e) { rfc_Connector cfg = null; cfg = new rfc_Connector(); IRfcFunction getDataSAP = GlobalData.rfcRepository.CreateFunction("ZPM_ORDER_01_CONFIRM"); IRfcTable IT_DATA = getDataSAP.GetTable("LT_ORDER_CONF"); IT_DATA.Clear(); IT_DATA.Append(); IT_DATA.SetValue("AUFNR", aufnr.Text); IT_DATA.SetValue("VORNR", vornr.Text); if (ck1.Checked == true) { IT_DATA.SetValue("AUERU", "X"); } try { getDataSAP.Invoke(GlobalData.rfcDestination); RfcSessionManager.EndContext(GlobalData.rfcDestination); //var exObject = getDataSAP.GetObject("MESSAGE"); MessageBox.Show("Order Confirmed"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void ToRfcTable(ref IRfcTable resultTable) { resultTable.Clear(); for (int i = 0; i < dataTable.Rows.Count; i++) { resultTable.Append(); string dSIGN = dataTable.Rows[i][sSIGN].ToString(); if (dSIGN == string.Empty) { dSIGN = SIGN.I.ToString(); } resultTable[i].SetValue(sSIGN, dSIGN); string dOPTION = dataTable.Rows[i][sOPTION].ToString(); if (dOPTION == string.Empty) { dOPTION = OPTION.EQ.ToString(); } resultTable[i].SetValue(sOPTION, dOPTION); string low = RFC_FunctionBase.ValueProcess(dataTable.Rows[i][sLOW].ToString(), LengthLimit); resultTable[i].SetValue(sLOW, low); string high = RFC_FunctionBase.ValueProcess(dataTable.Rows[i][sHIGH].ToString(), LengthLimit); resultTable[i].SetValue(sHIGH, high); } }
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 void button2_Click(object sender, EventArgs e) { rfc_Connector cfg = null; cfg = new rfc_Connector(); IRfcFunction getDataSAP = GlobalData.rfcRepository.CreateFunction("ZFRFC001"); //getDataSAP.SetValue("P_KUNNR", "ALL"); IRfcTable IT_DATA = getDataSAP.GetTable("LTLTZTB001"); IT_DATA.Clear(); IT_DATA.Append(); IT_DATA.SetValue("MANDT", "400"); IT_DATA.SetValue("MATNR", matnr.Text); IT_DATA.SetValue("MAKTX", maktx.Text); //IT_DATA.Append(); //IT_DATA.SetValue("MANDT", "400"); //IT_DATA.SetValue("MATNR", "MATERIAL02"); //IT_DATA.SetValue("MAKTX", "COBA MATERIAL TEST"); try { getDataSAP.Invoke(GlobalData.rfcDestination); RfcSessionManager.EndContext(GlobalData.rfcDestination); var exObject = getDataSAP.GetObject("OUTPUT"); IRfcStructure exStructure = getDataSAP.GetStructure("LS_ZTB001"); } catch (Exception ex) { message = "SAP ZFDLKNA1 "; message += ex.Message; //RfcSessionManager.EndContext(GlobalData.rfcDestination); //Thread.Sleep(1000); } readdata(); }
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 static dynamic ExecuteQuery(InputQuery query, Options options) { List <string> rows = new List <string>(); DataTable results = new DataTable("DATA"); string[] field_names = query.Fields.Split(",".ToCharArray()); RfcConfigParameters connectionParams = new RfcConfigParameters(); String[] connectionStringArray = query.ConnectionString.Split(';'); foreach (String configEntry in connectionStringArray) { connectionParams.Add(configEntry.TrimEnd().TrimStart().Split('=')[0], configEntry.TrimEnd().TrimStart().Split('=')[1]); } RfcDestination destination = RfcDestinationManager.GetDestination(connectionParams); IRfcFunction readTable; try { switch (options.ReadTableTargetRFC) { case ReadTableRFC.BBP_RFC_READ_TABLE: readTable = destination.Repository.CreateFunction("BBP_RFC_READ_TABLE"); break; case ReadTableRFC.RFC_READ_TABLE: readTable = destination.Repository.CreateFunction("RFC_READ_TABLE"); break; default: readTable = destination.Repository.CreateFunction("BBP_RFC_READ_TABLE"); break; } } catch (RfcBaseException ex) { throw (ex); } readTable.SetValue("query_table", query.TableName); readTable.SetValue("delimiter", "~"); IRfcTable t = readTable.GetTable("DATA"); t.Clear(); t = readTable.GetTable("FIELDS"); t.Clear(); if (field_names.Length > 0) { t.Append(field_names.Length); int i = 0; foreach (string n in field_names) { t.CurrentIndex = i++; t.SetValue(0, n); } } t = readTable.GetTable("OPTIONS"); t.Clear(); t.Append(1); t.CurrentIndex = 0; t.SetValue(0, query.Filter); readTable.Invoke(destination); t = readTable.GetTable("DATA"); JArray dataRows = new JArray(); int a = t.Count; rows = new List <string>(); for (int x = 0; x < t.RowCount; x++) { JObject dataObject = new JObject(); t.CurrentIndex = x; String[] columnValues = t.GetString(0).Split('~'); for (int i = 0; i < columnValues.Length; i++) { dataObject.Add(field_names[i], columnValues[i]); } dataRows.Add(dataObject); } return(JToken.FromObject(dataRows)); }
public void Excute() { if (String.IsNullOrEmpty(this.TableName)) { throw new SAPException("表名为空!!"); } if (this._dataInput == null && DATA == null) { throw new SAPException("数量为0!!"); } if (this._fieldsIn == null && FIELDS == null) { throw new SAPException("字段列表不能为空!!"); } try { IRfcTable DATA2 = this._function.GetTable("DATA"); IRfcTable FIELDS2 = this._function.GetTable("FIELDS"); DATA2.Clear(); FIELDS2.Clear(); IRfcStructure line2; if (this.Operation == OperationType.direct) { for (int i = 0; i < DATA.RowCount; i++) { DATA.CurrentIndex = i; line2 = DATA2.Metadata.LineType.CreateStructure(); line2.SetValue("FELD", DATA.GetValue("FELD")); DATA2.Append(line2); } for (int i = 0; i < FIELDS.RowCount; i++) { FIELDS.CurrentIndex = i; line2 = FIELDS2.Metadata.LineType.CreateStructure(); line2.SetValue("FIELDNAME", FIELDS.GetValue("FIELDNAME")); line2.SetValue("OFFSET", FIELDS.GetValue("OFFSET")); line2.SetValue("LENGTH", FIELDS.GetValue("LENGTH")); line2.SetValue("TYPE", FIELDS.GetValue("TYPE")); line2.SetValue("FIELDTEXT", FIELDS.GetValue("FIELDTEXT")); FIELDS2.Append(line2); } } else if (this.Operation == OperationType.write) { foreach (var item in this._dataInput) { line2 = DATA2.Metadata.LineType.CreateStructure(); line2.SetValue(0, item); DATA2.Append(line2); } foreach (var item in this._fieldsIn) { line2 = FIELDS2.Metadata.LineType.CreateStructure(); line2.SetValue("FIELDNAME", item.FieldName); line2.SetValue("OFFSET", item.Offset); line2.SetValue("LENGTH", item.Length); line2.SetValue("TYPE", item.Type); line2.SetValue("FIELDTEXT", item.FieldText); FIELDS2.Append(line2); } } this._function.SetValue("QUERY_TABLE", this.TableName); this._function.SetValue("DATA", DATA2); this._function.SetValue("FIELDS", FIELDS2); this._function.SetValue("DELIMITER", this.Delimiter); this._function.SetValue("INSERTX", this.isInsert == true ? "X" : ""); this._function.SetValue("UPDATEX", this.isUpdate == true ? "X" : ""); this._function.SetValue("MODIFYX", this.isModify == true ? "X" : ""); this._function.SetValue("DELETEX", this.isDelete == true ? "X" : ""); NotifyListener(String.Format("SAP表:{0},总行数{1}写入开始!", this.TableName, DATA2.RowCount.ToString())); this._function.Invoke(_destination); NotifyListener(String.Format("SAP表:{0},写入结束!", this.TableName)); } catch (RfcAbapException abapEx) { throw new SAPException(abapEx.Key + abapEx.Message); } catch (RfcBaseException rfcbase) { throw new SAPException(rfcbase.Message); } catch (Exception ex) { throw new SAPException(ex.Message); } }
private void InitWhereClause(ref IRfcTable toptions) { toptions.Clear(); if (this._WhereClause.Equals("")) { for (int i = 0; i < this.options.Count; i++) { toptions.Append(); toptions.CurrentRow.SetValue("TEXT", this.options[i].ToString()); //toptions.AddRow()["TEXT"] = this.options[i].ToString(); } } else { for (int j = 0; j < this._WhereClause.Length; j += 0x48) { if ((this._WhereClause.Length - j) > 0x48) { IRfcStructure structure2 = toptions.Metadata.LineType.CreateStructure(); bool flag = false; for (int k = 0; k < 0x47; k++) { if (this._WhereClause.Substring((j + 0x47) - k, 1).Equals(" ")) { structure2["TEXT"].SetValue(this._WhereClause.Substring(j, 0x48 - k)); toptions.Append(structure2); j -= k; flag = true; k = 0x48; } } if (!flag) { structure2["TEXT"].SetValue(this._WhereClause.Substring(j, 0x48)); toptions.Append(structure2); } } else { // toptions.AddRow()["TEXT"] = this._WhereClause.Substring(j); toptions.Append(); toptions.CurrentRow["TEXT"].SetValue(this._WhereClause.Substring(j)); } } string str = ""; foreach (IRfcStructure structure4 in toptions.ToList()) { str = str + structure4["TEXT"].ToString() + "\r\n"; } } if (this._UsePrimaryKeyPackaging) { if (toptions.ToList().Count == 0) { this.AddWhereLine(toptions, "("); } else { this.AddWhereLine(toptions, "AND ("); } for (int m = 0; m < this._PrimaryKeys.Count; m++) { string whereline = this._PrimaryKeys[m].FieldName + " >= '" + this._PrimaryKeys[m].LastKeyValue + "'"; if (m == 0) { whereline = "( " + whereline; } else { whereline = "AND " + whereline; } if (m == (this._PrimaryKeys.Count - 1)) { whereline = whereline + " )"; } this.AddWhereLine(toptions, whereline); } for (int n = 0; n < this._PrimaryKeys.Count; n++) { for (int num6 = n; num6 >= 0; num6--) { string str3; if (num6 == n) { str3 = "OR ( " + this._PrimaryKeys[num6].FieldName + " > '" + this._PrimaryKeys[num6].LastKeyValue + "'"; } else { str3 = "AND " + this._PrimaryKeys[num6].FieldName + " >= '" + this._PrimaryKeys[num6].LastKeyValue + "'"; } if (num6 == 0) { str3 = str3 + " )"; } this.AddWhereLine(toptions, str3); } } //toptions.AddRow()["TEXT"] = ")"; toptions.Append(); toptions.CurrentRow.SetValue("TEXT", ")"); } //if (!this.con.LogDir.Equals("")) //{ // this.con.Log("Building where: "); // foreach (RFCStructure structure6 in toptions.Rows) // { // this.con.Log(structure6["TEXT"].ToString()); // } //} }
private void InitOnlyData() { //출하지점 Hashtable ht = new Hashtable(); ht.Add("I_MODE", "1"); IRfcTable sapTable = Common.Frm10.SapConntor.SAPConnection.SAPExecuteTableData(ht, "ZCA_OUTBOUND_INPUT", "E_TAB"); DataTable netTable = Common.Util.sapTableConvert.DataTableSet(sapTable); sle_vstel.Properties.DataSource = netTable; sle_vstel.Properties.DisplayMember = "CODE"; sle_vstel.Properties.ValueMember = "CODE"; sle_vstel.Properties.View.Columns.ColumnByFieldName("CODE").Caption = "코드"; sle_vstel.Properties.View.Columns.ColumnByFieldName("TEXT").Caption = "내역"; sapTable.Clear(); ht.Clear(); //납품유형 ht.Add("I_MODE", "2"); sapTable = Common.Frm10.SapConntor.SAPConnection.SAPExecuteTableData(ht, "ZCA_OUTBOUND_INPUT", "E_TAB"); DataTable netTable1 = Common.Util.sapTableConvert.DataTableSet(sapTable); sle_lfart.Properties.DataSource = netTable1; sle_lfart.Properties.DisplayMember = "CODE"; sle_lfart.Properties.ValueMember = "CODE"; sle_lfart.Properties.View.Columns.ColumnByFieldName("CODE").Caption = "코드"; sle_lfart.Properties.View.Columns.ColumnByFieldName("TEXT").Caption = "내역"; sapTable.Clear(); ht.Clear(); //영업조직 ht.Add("I_MODE", "3"); sapTable = Common.Frm10.SapConntor.SAPConnection.SAPExecuteTableData(ht, "ZCA_OUTBOUND_INPUT", "E_TAB"); DataTable netTable2 = Common.Util.sapTableConvert.DataTableSet(sapTable); sle_vkorg.Properties.DataSource = netTable2; sle_vkorg.Properties.DisplayMember = "CODE"; sle_vkorg.Properties.ValueMember = "CODE"; sle_vkorg.Properties.View.Columns.ColumnByFieldName("CODE").Caption = "코드"; sle_vkorg.Properties.View.Columns.ColumnByFieldName("TEXT").Caption = "내역"; sapTable.Clear(); ht.Clear(); date_delivery.Text = DateTime.Now.ToShortDateString(); //차량톤수 ht.Add("I_MODE", "8"); sapTable = Common.Frm10.SapConntor.SAPConnection.SAPExecuteTableData(ht, "ZCA_OUTBOUND_INPUT", "E_TAB"); DataTable netTable3 = Common.Util.sapTableConvert.DataTableSet(sapTable); sle_ton.Properties.DataSource = netTable3; sle_ton.Properties.DisplayMember = "CODE"; sle_ton.Properties.ValueMember = "CODE"; sle_ton.Properties.View.Columns.ColumnByFieldName("CODE").Caption = "코드"; sle_ton.Properties.View.Columns.ColumnByFieldName("TEXT").Caption = "내역"; sapTable.Clear(); ht.Clear(); //운송업체 ht.Add("I_MODE", "9"); sapTable = Common.Frm10.SapConntor.SAPConnection.SAPExecuteTableData(ht, "ZCA_OUTBOUND_INPUT", "E_TAB"); DataTable netTable4 = Common.Util.sapTableConvert.DataTableSet(sapTable); sle_lifnr.Properties.DataSource = netTable4; sle_lifnr.Properties.DisplayMember = "CODE"; sle_lifnr.Properties.ValueMember = "CODE"; sle_lifnr.Properties.View.Columns.ColumnByFieldName("CODE").Caption = "코드"; sle_lifnr.Properties.View.Columns.ColumnByFieldName("TEXT").Caption = "내역"; sapTable.Clear(); ht.Clear(); }