/// <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); }
private Boolean ImportInvoice(String databaseName, DocumentCached invoice, out String documentNumber, out String errorMessage) { errorMessage = String.Empty; documentNumber = String.Empty; try { IRfcFunction fReadTable = repo.CreateFunction("ZZBAPI_DEBIT_MEMO_REQUEST"); fReadTable.SetValue("CUSTOMER", ("0000000" + invoice.CustomerCode).Right(10)); fReadTable.SetValue("SALES_ORG", invoice.VLCompany); fReadTable.SetValue("PURCH_DATE", invoice.DocDate); fReadTable.SetValue("PURCH_NO_C", invoice.Comment); foreach (DocumentLineCached line in invoice.Lines) { RfcStructureMetadata metaData = dest.Repository.GetStructureMetadata("ZORDERLINE"); IRfcStructure structConditions = metaData.CreateStructure(); structConditions.SetValue("ITM_NUMBER", ("0000" + line.LineNum.ToString() + "0").Right(6)); structConditions.SetValue("MATERIAL", line.ItemCode); // C => Certificate structConditions.SetValue("TARGET_QTY", line.Quantity); structConditions.SetValue("SALES_UNIT", line.UnitOfMeasure); structConditions.SetValue("COND_VALUE", line.Price); structConditions.SetValue("CURRENCY", line.Currency); structConditions.SetValue("SHORT_TEXT", line.ShortText); IRfcTable tblItems = fReadTable.GetTable("ORDERLINE"); tblItems.Append(structConditions); fReadTable.SetValue("ORDERLINE", tblItems); } fReadTable.Invoke(dest); String result = (String)fReadTable.GetValue("SALESDOCUMENT"); IRfcStructure result2 = (IRfcStructure)fReadTable.GetValue("RETURN"); documentNumber = result.ToString(); errorMessage = result2[3].ToString().Replace("FIELD MESSAGE=", ""); if (String.IsNullOrEmpty(documentNumber) || !String.IsNullOrEmpty(errorMessage)) { return(false); } } catch (Exception ex) { errorMessage = ex.Message; } return(true); }
private void btnPO_Click(object sender, EventArgs e) { sapConnClass sc = new sapConnClass(); var rfcPara = sc.setParaToConn(connClient); var rfcDest = RfcDestinationManager.GetDestination(rfcPara); var rfcRepo = rfcDest.Repository; IRfcFunction getPORFC = null; // rfc 函數名稱 getPORFC = rfcRepo.CreateFunction(getPODetail); //輸入參數:工單號碼 getPORFC.SetValue("P_AUFNR", txtAufnr.Text.ToString().Trim()); // Call function. getPORFC.Invoke(rfcDest); //回傳內表 IRfcTable ITAB = getPORFC.GetTable("ITAB"); DataTable dt = new DataTable(); dt.Columns.Add("作業號碼"); dt.Columns.Add("作業短文"); dt.Columns.Add("報工數量"); for (int i = 0; i <= ITAB.RowCount - 1; i++) { DataRow dr = dt.NewRow(); ITAB.CurrentIndex = i; dr["作業號碼"] = ITAB.GetString("VORNR").ToString(); dr["作業短文"] = ITAB.GetString("LTXA1").ToString(); dr["報工數量"] = ITAB.GetString("GMNGA").ToString(); dt.Rows.Add(dr); } dataGridView1.DataSource = dt.DefaultView; dataGridView1.ReadOnly = true; // rfc 回傳參數 string KDAUF = getPORFC.GetValue("KDAUF").ToString().TrimStart('0'); string KDPOS = getPORFC.GetValue("KDPOS").ToString().TrimStart('0'); string PSMNG = getPORFC.GetValue("PSMNG").ToString().TrimEnd('0').TrimEnd('.'); string DGLTS = getPORFC.GetValue("DGLTS").ToString(); string USER_LINE = getPORFC.GetValue("USER_LINE").ToString(); lblQty.Text = "工單數量:" + PSMNG; lblStatus.Text = "使用者自定狀態:" + USER_LINE; lblSoitme.Text = "銷售訂單/項次:" + KDAUF + " / " + KDPOS; lblEnddate.Text = "工單排程結束日期:" + DGLTS; }
public void tableBLPlan(string name) { connect(); RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "PLANNING_ID DESCRICAO DATA_INICIAL DATA_FINAL VALIDADE_DE VALIDADE_ATE"); IReader.SetValue("IV_FROM", "/SSCN/BL_PLAN"); IReader.SetValue("IV_WHERE", "DESCRICAO = '" + name + "'"); IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); string path = Path.GetFullPath("Relatorio/pathBLPlan.txt"); System.IO.File.WriteAllText(path, optionData); List <Schedule_SapTable> jsonList = JsonConvert.DeserializeObject <List <Schedule_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel3 = new Schedule_BLPlanExcel(); CreateExcel3.CreateWorkbook("Relatorio/DadosBLPlan.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel3.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel3.Save(); } }
public void tableLperWkc() { connect(); RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "PERNR ENDDA"); IReader.SetValue("IV_FROM", "/SSCN/LPER_WKC"); IReader.SetValue("IV_WHERE", "ARBPL = 'PSQA-AUT' AND WERKS = '1000'"); IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); string path = Path.GetFullPath("Relatorio/pathLperWkc.txt"); System.IO.File.WriteAllText(path, optionData); List <Schedule_SapTable> jsonList = JsonConvert.DeserializeObject <List <Schedule_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel8 = new Schedule_LperWkcExcel(); CreateExcel8.CreateWorkbook("Relatorio/DadosLperWkc.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel8.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel8.Save(); } }
public void tableLList(string lista) { RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "*"); // pegar todas as tabelas IReader.SetValue("IV_FROM", "/SSCN/LLIST"); IReader.SetValue("IV_WHERE", "NOME_LISTA = 'CENTRO_TRAB' AND CENTRO IN (" + lista + ") AND EXTRA_FLD3 = 'X' AND IDIOMA = 'EN'"); IReader.SetValue("IV_ORDER", "COD_ITEM DESCRICAO"); IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); string path = Path.GetFullPath("Relatorio/pathLList.txt"); System.IO.File.WriteAllText(path, optionData); List <Schedule_SapTable> jsonList = JsonConvert.DeserializeObject <List <Schedule_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel2 = new Schedule_LListExcel(); CreateExcel2.CreateWorkbook("Relatorio/DadosLList.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel2.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel2.Save(); } }
public void tableAssetGroupAmPerson(string pernr) { connect(); RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "A~PERNR A~AM_KEY_TYPE A~AM_KEY B~EQKTX C~PLTXT A~AM_KN A~EXP_EQUI"); IReader.SetValue("IV_FROM", "/SSCN/AM_PERSON AS A LEFT JOIN /SSCN/LEQP_T AS B ON ( A~AM_KEY = B~EQUNR AND B~SPRAS = 'EN' ) LEFT JOIN /SSCN/LFUN_LOC_T AS C ON(A~AM_KEY = C~TPLNR AND C~SPRAS = 'EN')"); IReader.SetValue("IV_WHERE", "A~AM_TYPE = '3' AND A~PERNR = '100029'"); IReader.SetValue("IV_ORDER", "A~AM_KEY_TYPE A~AM_KEY"); IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); filePathTxt = filePathTxt + @"\pathAGLPerson.txt"; System.IO.File.WriteAllText(filePathTxt, optionData); List <AbilityMatrix_SapTable> jsonList = JsonConvert.DeserializeObject <List <AbilityMatrix_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel2 = new AbilityMatrix_AssetGroup_AmPersonExcel(); CreateExcel2.CreateWorkbook(filePathXlsx = filePathXlsx + @"\DadosAgAmPerson.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel1.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel2.Save(); } }
public void tableLPer_Wkc(string plant, string workcenter) { connect(); RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "A~PERNR A~ENAME"); IReader.SetValue("IV_FROM", "/SSCN/LPERSON AS A INNER JOIN /SSCN/LPER_WKC AS B ON ( A~PERNR = B~PERNR )"); IReader.SetValue("IV_WHERE", "B~WERKS = '" + plant + "' AND B~ARBPL = '" + workcenter + "'"); IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); filePathTxt = filePathTxt + @"\pathLPerWkc.txt"; System.IO.File.WriteAllText(filePathTxt, optionData); List <IndividualCapacity_SapTable> jsonList = JsonConvert.DeserializeObject <List <IndividualCapacity_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel3 = new IndividualCapacity_LperWkcExcel(); CreateExcel3.CreateWorkbook(filePathXlsx = filePathXlsx + @"\DadosLPerWkc.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel3.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel3.Save(); } }
public void tablePlants() { connect(); RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "USERID PLANT"); IReader.SetValue("IV_FROM", "/SSCN/PLANT"); IReader.SetValue("IV_WHERE", "USERID = 'SIGGA127'"); IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); filePathTxt = filePathTxt + @"\pathPlant.txt"; System.IO.File.WriteAllText(filePathTxt, optionData); List <IndividualCapacity_SapTable> jsonList = JsonConvert.DeserializeObject <List <IndividualCapacity_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel = new IndividualCapacity_PlantExcel(); CreateExcel.CreateWorkbook(filePathXlsx = filePathXlsx + @"\DadosPlant.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel.Save(); } }
public void tableLList(string plant) { connect(); RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "COD_ITEM DESCRICAO"); IReader.SetValue("IV_FROM", "/SSCN/LLIST"); IReader.SetValue("IV_WHERE", "NOME_LISTA = 'CENTRO_TRAB' AND CENTRO = '" + plant + "' AND EXTRA_FLD3 = 'X' AND IDIOMA = 'EN'"); IReader.SetValue("IV_ORDER", "COD_ITEM DESCRICAO"); IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); filePathTxt = filePathTxt + @"\pathLList.txt"; System.IO.File.WriteAllText(filePathTxt, optionData); List <IndividualCapacity_SapTable> jsonList = JsonConvert.DeserializeObject <List <IndividualCapacity_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel1 = new IndividualCapacity_LListExcel(); CreateExcel1.CreateWorkbook(filePathXlsx = filePathXlsx + @"\DadosLList.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel1.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel1.Save(); } }
public void tableLoper(string nome) { connect(); RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "ORDERID ACTIVITY SUB_ACTIVITY CONTROL_KEY WORK_CNTR PLANT DESCRIPTION SYSTCOND FUNCLOC EQUIPMENT EARL_SCH_START_D EARL_SCH_START_T"); IReader.SetValue("IV_FROM", "/SSCN/LOPER"); IReader.SetValue("IV_WHERE", "WORK_CNTR = '" + nome + "'"); IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); string path = Path.GetFullPath("Relatorio/pathLoper.txt"); System.IO.File.WriteAllText(path, optionData); List <Schedule_SapTable> jsonList = JsonConvert.DeserializeObject <List <Schedule_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel6 = new Schedule_LoperExcel(); CreateExcel6.CreateWorkbook("Relatorio/DadosLoper.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel6.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel6.Save(); } }
public void tableParam() { connect(); RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "FIRST_DAY_WEEK SCHED_VALID_TIME"); IReader.SetValue("IV_FROM", "/SSCN/PARAM"); IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); string path = Path.GetFullPath("Relatorio/pathParam.txt"); System.IO.File.WriteAllText(path, optionData); List <Schedule_SapTable> jsonList = JsonConvert.DeserializeObject <List <Schedule_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel7 = new Schedule_ParamExcel(); CreateExcel7.CreateWorkbook("Relatorio/DadosParam.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel7.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel7.Save(); } }
/// <summary> /// Metoda zwracajaca ID uzytkownika z bazy SAP. /// </summary> /// <param name="mode">Tryb pracy (PROD/DEV)</param> /// <param name="user">Nazwa uzytkownika</param> /// <param name="FVI_PERNR">Zmienna do której zostanie zapisany numer ID uzytkownika</param> /// <returns>Zwraca kod, 100 - poprawnie odczytany ID uzytkownikam, 101 - nie znaleziono uzytkownika</returns> public int GetPernr(string mode, string user, out string FVI_PERNR) { FVI_PERNR = string.Empty; int ret = -1; AppMode = mode; try { RfcDestination dest = RfcDestinationManager.GetDestination(mode); RfcRepository repo = dest.Repository; // FUNCTION z_get_pernr_4_user. IRfcFunction z_get_pernr_4_user = repo.CreateFunction("Z_GET_PERNR_4_USER"); // IMPORTING //VALUE(FVI_ENV_USER) TYPE ZHR_ENVUSER // FVI_VLPLA - nr kontenera (CHAR10) z_get_pernr_4_user.SetValue("FVI_ENV_USER", user); // call z_get_pernr_4_user.Invoke(dest); var FVO_RETURN = z_get_pernr_4_user.GetValue("FVO_RETURN").ToString(); ret = Convert.ToInt32(FVO_RETURN); FVI_PERNR = z_get_pernr_4_user.GetValue("FVO_PERNR").ToString(); // if 100 -> 00000000 var FVO_UNAME = z_get_pernr_4_user.GetValue("FVO_UNAME").ToString(); // if 100 -> "" PerNBR = FVI_PERNR; return(ret); // EXPORTING // VALUE(FVO_RETURN) TYPE NUM03 //* return codes //* 100 - OK //* 101 - nie znalazlem uzytkownika } catch (Exception ex) { Messenger.Default.Send(new LogMessage(ex.Message, LogType.ERROR_SAP), "Log"); return(-1); } }
public object GetValue(string funname, string valuename, Dictionary <string, string> sps, out string msg) { IRfcFunction myfun = null; msg = string.Empty; List <IRfcTable> list = new List <IRfcTable>(); myfun = rfcrep.CreateFunction(funname); foreach (var item in sps) { myfun.SetValue(item.Key, item.Value); } myfun.Invoke(dest); msg = myfun.GetValue("STATUS").ToString(); return(myfun.GetValue(valuename)); }
/// <summary> /// 物料凭证查询 /// </summary> /// <param name="I_BKTXT">凭证抬头文本(凭证号与抬头文本至少填一个)</param> /// <param name="I_MBLNR">物料凭证(凭证号与抬头文本至少填一个)</param> /// <param name="I_MJAHR">物料凭证年度(选填)</param> /// <returns></returns> public static Result ZWMS_MKPF(string I_BKTXT, string I_MBLNR = "", string I_MJAHR = "") { Result result = new Result { Success = false }; try { //RfcDestination rfcDest = RfcDestinationManager.GetDestination(GetSapServerString()); RfcDestination rfcDest = RfcDestinationManager.GetDestination(ConfigurationManager.AppSettings["sapServer"].ToString()); //选择要调用的BAPI的名称 RfcFunctionMetadata rfMD = rfcDest.Repository.GetFunctionMetadata("ZWMS_MKPF"); //新建调用该BAPI的一个“实例” IRfcFunction irF = rfMD.CreateFunction(); //****************************** //输入参数设置 //****************************** irF.SetValue("I_MBLNR", I_MBLNR); //物料凭证 irF.SetValue("I_MJAHR", I_MJAHR); //物料凭证年度 irF.SetValue("I_BKTXT", I_BKTXT); //凭证抬头文本 IRfcTable irt = irF.GetTable("O_MKPF"); RfcSessionManager.BeginContext(rfcDest); irF.Invoke(rfcDest); //irfCommit.Invoke(rfcDest); RfcSessionManager.EndContext(rfcDest); result.Success = irF.GetString("RTYPE").ToUpper() == "S"; result.Message = irF.GetValue("RTMSG").ToString(); if (result.Success && irt.RowCount > 0) { var MBLNR = ""; for (int i = 0; i < irt.RowCount; i++) { irt.CurrentIndex = i; if (MBLNR.IsNotEmpty()) { MBLNR += "/"; } MBLNR += irt.GetString("MBLNR"); } result.Message = MBLNR; } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public byte[] Get_Z_RFC_ZPP007(string partNumber, string facCode, string strDate) { this._strError = string.Empty; System.Data.DataTable outDataTable = new System.Data.DataTable("Z_RFC_ZPP007"); try { string err = string.Empty; outDataTable.Columns.Add("IDNRK", typeof(string)); outDataTable.Columns.Add("MFRPN", typeof(string)); outDataTable.Columns.Add("MAKTX", typeof(string)); outDataTable.Columns.Add("MENGE", typeof(int)); outDataTable.Columns.Add("ALPGR", typeof(string)); outDataTable.Columns.Add("SORTF", typeof(string)); outDataTable.Columns.Add("REVLV", typeof(string)); outDataTable.Columns.Add("TEXT1", typeof(string)); RfcDestination destination = RfcDestinationManager.GetDestination(this.GetCfgParameters()); IRfcFunction rfcFunction = destination.Repository.CreateFunction("Z_RFC_ZPP007"); rfcFunction.SetValue("MATNR", partNumber); rfcFunction.SetValue("WERKS", facCode); rfcFunction.SetValue("DATE", strDate); rfcFunction.Invoke(destination); this._strError = rfcFunction.GetValue("RETURN").ToString(); IRfcTable table = rfcFunction.GetTable("T_BOM"); for (int i = 0; i < table.RowCount; i++) { string text1 = table[i].GetString("TEXT1").Trim(); string text2 = table[i].GetString("TEXT2").Trim(); string text3 = table[i].GetString("TEXT3").Trim(); outDataTable.Rows.Add( table[i].GetString("IDNRK").TrimStart('0'), table[i].GetString("MFRPN").TrimStart('0'), table[i].GetString("MAKTX").TrimStart('0'), Convert.ToInt16(table[i].GetDouble("MENGE")), table[i].GetString("ALPGR").TrimStart('0'), table[i].GetString("SORTF").TrimStart('0'), table[i].GetString("REVLV").TrimStart('0'), string.Format("{0}{1}{2}", string.IsNullOrEmpty(text1) ? "" : text1.Substring(text1.Length - 1, 1) == "," ? text1 : text1 + ",", string.IsNullOrEmpty(text2) ? "" : text1.Substring(text2.Length - 1, 1) == "," ? text2 : text2 + ",", string.IsNullOrEmpty(text2) ? "" : text1.Substring(text3.Length - 1, 1) == "," ? text3 : text3 + ",")); } DataSet ds = new DataSet(); ds.Tables.Add(outDataTable); return(mlc.GetDataSetSurrogateZipBytes(ds)); } catch { this._strError = "SAP Connect Error"; return(null); } }
/// <summary> /// 产品料号BOM信息 /// </summary> /// <param name="partNumber">成品料号</param> /// <param name="facCode">工厂代码</param> /// <param name="strDate">有效日期(130101)</param> /// <returns></returns> public static string Get_Z_RFC_ZPP007(string partNumber, string facCode, string strDate, out System.Data.DataTable outDataTable) { //RETURN(c,30) outDataTable = new System.Data.DataTable("Z_RFC_ZPP007"); try { string err = string.Empty; outDataTable.Columns.Add("IDNRK", typeof(string)); outDataTable.Columns.Add("MFRPN", typeof(string)); outDataTable.Columns.Add("MAKTX", typeof(string)); outDataTable.Columns.Add("MENGE", typeof(int)); outDataTable.Columns.Add("ALPGR", typeof(string)); outDataTable.Columns.Add("SORTF", typeof(string)); outDataTable.Columns.Add("REVLV", typeof(string)); outDataTable.Columns.Add("TEXT1", typeof(string)); IRfcFunction rfcFunction = destination.Repository.CreateFunction("Z_RFC_ZPP007"); rfcFunction.SetValue("MATNR", partNumber); rfcFunction.SetValue("WERKS", facCode); rfcFunction.SetValue("DATE", strDate); //rfcFunction.SetValue("REVLV", "A"); rfcFunction.Invoke(destination); err = rfcFunction.GetValue("RETURN").ToString(); IRfcTable table = rfcFunction.GetTable("T_BOM"); for (int i = 0; i < table.RowCount; i++) { string text1 = table[i].GetString("TEXT1").Trim(); string text2 = table[i].GetString("TEXT2").Trim(); string text3 = table[i].GetString("TEXT3").Trim(); outDataTable.Rows.Add( table[i].GetString("IDNRK").TrimStart('0'), table[i].GetString("MFRPN").TrimStart('0'), table[i].GetString("MAKTX").TrimStart('0'), Convert.ToInt16(table[i].GetDouble("MENGE")), table[i].GetString("ALPGR").TrimStart('0'), table[i].GetString("SORTF").TrimStart('0'), table[i].GetString("REVLV").TrimStart('0'), string.Format("{0}{1}{2}", string.IsNullOrEmpty(text1) ? "" : text1.Substring(text1.Length - 1, 1) == "," ? text1 : text1 + ",", string.IsNullOrEmpty(text2) ? "" : text1.Substring(text2.Length - 1, 1) == "," ? text2 : text2 + ",", string.IsNullOrEmpty(text2) ? "" : text1.Substring(text3.Length - 1, 1) == "," ? text3 : text3 + ",")); } return(string.IsNullOrEmpty(err) ? string.Empty : err); } catch (Exception ex) { return(ex.Message); } }
public void tableMachCal(string plant, string workCenter, string functionalLoc, string equipment, string startDate, string finishDate) { connect(); RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "A~FUNC_LOC B~PLTXT A~EQUNR C~EQKTX A~START_DATE A~FINISH_DATE A~START_TIME A~FINISH_TIME A~STOP_TYPE A~TIME_CONF A~NOTE"); IReader.SetValue("IV_FROM", "/SSCN/MACH_CAL AS A LEFT JOIN /SSCN/LFUN_LOC_T AS B ON ( A~FUNC_LOC = B~TPLNR AND B~SPRAS = 'EN') LEFT JOIN /SSCN/LEQP_T AS C ON ( A~EQUNR = C~EQUNR AND C~SPRAS = 'EN' )"); string scenario = ScenarioContext.Current.ScenarioInfo.Title; switch (scenario) { case "Filtering only by plant": IReader.SetValue("IV_WHERE", "PLANT = '" + plant + "'"); break; case "Filtering by plant and work center": IReader.SetValue("IV_WHERE", "PLANT = '" + plant + "' AND WORK_CENTER = '" + workCenter + "'"); break; case "Filtering by plant and Functional location": IReader.SetValue("IV_WHERE", "PLANT = '" + plant + "' AND A~FUNC_LOC LIKE '%" + functionalLoc + "%'"); break; case "Filtering by plant and Equipment": IReader.SetValue("IV_WHERE", "PLANT = '" + plant + "' AND A~EQUNR LIKE '%" + equipment + "%'"); break; case "Filtering by plant and date": IReader.SetValue("IV_WHERE", "PLANT = '" + plant + "' AND A~START_DATE GE '" + startDate + "' AND A~START_DATE LE '" + finishDate + "'"); break; } IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); filePathTxt = filePathTxt + @"\pathMachCal.txt"; System.IO.File.WriteAllText(filePathTxt, optionData); List <MachineDowntimeCalendar_SapTable> jsonList = JsonConvert.DeserializeObject <List <MachineDowntimeCalendar_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel5 = new MachineDowntimeCalendar_Mach_CalExcel(); CreateExcel5.CreateWorkbook(filePathXlsx = filePathXlsx + @"\DadosMachCal.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel5.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel5.Save(); } }
public override T GetOutput <T>(string name) { object returnValue = function.GetValue(name); if (returnValue is IRfcStructure) { return(this.structureMapper.FromStructure <T>(returnValue as IRfcStructure)); } return((T)this.structureMapper.FromRemoteValue(typeof(T), returnValue)); }
public string TestFunction(string MATNR) { IRfcFunction rfcSurvey = this.RfcDestination.Repository.CreateFunction("Z_FEEDBACK_TEST"); rfcSurvey.SetValue("I_MATNR", MATNR); rfcSurvey.Invoke(this.RfcDestination); string E_MAKTX = rfcSurvey.GetValue("E_MAKTX").ToString(); return(E_MAKTX); }
private static Dictionary <string, object> GetTables(IRfcFunction function) { var regex = new Regex(@"TABLES (\w+):"); var exportParams = new Dictionary <string, object>(); foreach (Match match in regex.Matches(function.Metadata.ToString())) { var name = match.Groups[1].Value; var value = function.GetValue(name).ToString(); exportParams.Add(name, value); } return(exportParams); }
public byte[] Get_Z_RFC_MSEG(string IMBLNR, string MJAHR) { this._strError = string.Empty; System.Data.DataTable outDataTable = new System.Data.DataTable("Z_RFC_MSEG"); try { outDataTable.Columns.Add("MBLNR", typeof(string)); outDataTable.Columns.Add("MJAHR", typeof(string)); outDataTable.Columns.Add("ZEILE", typeof(string)); outDataTable.Columns.Add("MATNR", typeof(string)); outDataTable.Columns.Add("LIFNR", typeof(string)); outDataTable.Columns.Add("NAME1", typeof(string)); outDataTable.Columns.Add("ERFMG", typeof(string)); RfcDestination destination = RfcDestinationManager.GetDestination(this.GetCfgParameters()); IRfcFunction rfcFunction = destination.Repository.CreateFunction("Z_RFC_MSEG"); rfcFunction.SetValue("I_MBLNR", IMBLNR); if (!string.IsNullOrEmpty(MJAHR)) { rfcFunction.SetValue("I_MJAHR", MJAHR); } rfcFunction.Invoke(destination); this._strError = rfcFunction.GetValue("E_MESSAGE").ToString(); IRfcTable table = rfcFunction.GetTable("T_ZRFC_MSEG"); for (int i = 0; i < table.RowCount; i++) { outDataTable.Rows.Add( table[i].GetString("MBLNR").TrimStart('0'), table[i].GetString("MJAHR").TrimStart('0'), table[i].GetString("ZEILE").TrimStart('0'), table[i].GetString("MATNR").TrimStart('0'), table[i].GetString("LIFNR").TrimStart('0'), table[i].GetString("NAME1").TrimStart('0'), table[i].GetString("ERFMG").TrimStart('0')); } DataSet ds = new DataSet(); ds.Tables.Add(outDataTable); return(mlc.GetDataSetSurrogateZipBytes(ds)); } catch { this._strError = "SAP Connect Error"; return(null); } }
public void tableLEQP(string plant, string data, string workCenter, string equipment) { connect(); int datalimit = Convert.ToInt32(data); RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "A~EQUNR B~EQKTX"); IReader.SetValue("IV_FROM", "/SSCN/LEQP AS A LEFT JOIN /SSCN/LEQP_T AS B ON ( A~EQUNR = B~EQUNR AND B~SPRAS = 'EN' )"); string scenario = ScenarioContext.Current.ScenarioInfo.Title; switch (scenario) { case "Filtering only by plant": IReader.SetValue("IV_WHERE", "A~MAINTPLANT = '" + plant + "'"); break; case "Filtering by plant and work center": IReader.SetValue("IV_WHERE", "A~MAINTPLANT = '" + plant + "' AND A~WORK_CTR = '" + workCenter + "'"); break; case "Filtering by plant and Equipment": IReader.SetValue("IV_WHERE", "A~MAINTPLANT = '" + plant + "' AND A~EQUNR LIKE '%" + equipment + "%'"); break; } IReader.SetValue("IV_ORDER", "A~EQUNR"); IReader.SetValue("IV_ROWS", datalimit); IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); filePathTxt = filePathTxt + @"\pathLeqp.txt"; System.IO.File.WriteAllText(filePathTxt, optionData); List <MachineDowntimeCalendar_SapTable> jsonList = JsonConvert.DeserializeObject <List <MachineDowntimeCalendar_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel4 = new MachineDowntimeCalendar_LeqpExcel(); CreateExcel4.CreateWorkbook(filePathXlsx = filePathXlsx + @"\DadosLeqp.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel4.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel4.Save(); } }
private Boolean ImportInvoice2(String databaseName, DocumentCached invoice) { IRfcFunction fReadTable = repo.CreateFunction("ZZBAPI_DEBIT_MEMO_REQUEST"); fReadTable.SetValue("CUSTOMER", "0000008289"); fReadTable.SetValue("SALES_ORG", "ZW01"); fReadTable.SetValue("PURCH_DATE", DateTime.Now); fReadTable.SetValue("PURCH_NO_C", "TEST ZZBAPI_DEBIT_MEMO_REQUEST"); RfcStructureMetadata metaData = dest.Repository.GetStructureMetadata("ZORDERLINE"); IRfcStructure structConditions = metaData.CreateStructure(); structConditions.SetValue("ITM_NUMBER", "000010"); structConditions.SetValue("MATERIAL", "C"); // C => Certificate structConditions.SetValue("TARGET_QTY", 10); structConditions.SetValue("SALES_UNIT", "ST"); structConditions.SetValue("COND_VALUE", 16); structConditions.SetValue("CURRENCY", "EUR"); structConditions.SetValue("SHORT_TEXT", "test"); IRfcTable tblItems = fReadTable.GetTable("ORDERLINE"); tblItems.Append(structConditions); fReadTable.SetValue("ORDERLINE", tblItems); fReadTable.Invoke(dest); var result = fReadTable.GetValue("SALESDOCUMENT"); var result2 = fReadTable.GetValue("RETURN"); Console.WriteLine(result.ToString()); Console.ReadLine(); return(true); }
/// <summary> /// 产品料号BOM信息 /// </summary> /// <param name="partNumber">成品料号</param> /// <param name="facCode">工厂代码</param> /// <param name="strDate">有效日期(130101)</param> /// <returns>返回错误信息,否则返回空</returns> public byte[] Get_Z_RFC_ZPP007(string partNumber, string facCode, string strDate) { this._strError = string.Empty; System.Data.DataTable outDataTable = new System.Data.DataTable("Z_RFC_ZPP007"); try { string err = string.Empty; outDataTable.Columns.Add("IDNRK", typeof(string)); outDataTable.Columns.Add("MFRPN", typeof(string)); outDataTable.Columns.Add("MAKTX", typeof(string)); outDataTable.Columns.Add("MENGE", typeof(string)); outDataTable.Columns.Add("ALPGR", typeof(string)); outDataTable.Columns.Add("REVLV", typeof(string)); outDataTable.Columns.Add("TEXT1", typeof(string)); IRfcFunction rfcFunction = destination.Repository.CreateFunction("Z_RFC_ZPP007"); rfcFunction.SetValue("MATNR", partNumber); rfcFunction.SetValue("WERKS", facCode); rfcFunction.SetValue("DATE", strDate); rfcFunction.Invoke(destination); this._strError = rfcFunction.GetValue("RETURN").ToString(); IRfcTable table = rfcFunction.GetTable("OUTPUT1"); for (int i = 0; i < table.RowCount; i++) { outDataTable.Rows.Add( table[i].GetString("IDNRK"), table[i].GetString("MFRPN"), table[i].GetString("MAKTX"), table[i].GetString("MENGE"), table[i].GetString("ALPGR"), table[i].GetString("REVLV"), table[i].GetString("TEXT1")); } System.Data.DataSet ds = new System.Data.DataSet(); ds.Tables.Add(outDataTable); return(null);// GetDataSetSurrogateZipBytes(ds); } catch { this._strError = "SAP Connect Error"; return(null); } }
static void Main(string[] args) { SapConnection con = new SapConnection(); RfcDestinationManager.RegisterDestinationConfiguration(con); RfcDestination dest = RfcDestinationManager.GetDestination("NSP"); RfcRepository repo = dest.Repository; IRfcFunction fReadTable = repo.CreateFunction("ZSOMA"); fReadTable.SetValue("I_NRO1", 1); fReadTable.SetValue("I_NRO2", 2); fReadTable.Invoke(dest); var result = fReadTable.GetValue("E_RESULT"); Console.WriteLine(result.ToString()); Console.ReadLine(); }
/*Exemplo de Envio para o SAP, usando estrutura*/ public String RegistraAbastecimento(string Equipamento, string Posto, string Data, string Hora, string Trajeto_consumo, string Consumo, string Posicao_contador) { IRfcFunction objRfc = repo.CreateFunction("ZRFC_FROTAWEB_ABASTECE"); IRfcStructure objEstrutura = objRfc.GetStructure("I_DADOS"); objEstrutura.SetValue("equip", Equipamento); objEstrutura.SetValue("POSTO_ABAST", Posto); objEstrutura.SetValue("DATA", Data); objEstrutura.SetValue("HORA", Hora); objEstrutura.SetValue("TRAJETO", Trajeto_consumo); objEstrutura.SetValue("CONSUMO", Consumo); objEstrutura.SetValue("CONTADOR", Posicao_contador); objRfc.Invoke(dest); return(objRfc.GetValue(0).ToString()); }
public void Conversion2(string P_UNAME, string P_PASSWORD, string P_IDSISTEMA, string P_INSTANCIA, string P_MANDANTE, string P_SAPROUTER, string P_SERVER, string P_IDIOMA, string LAND, string VPAGO, string FCURR, string TCURR, string FAMOUNT, string TAMOUNT) { try { connectorSap.idioma = P_IDIOMA; connectorSap.idSistema = P_IDSISTEMA; connectorSap.instancia = P_INSTANCIA; connectorSap.mandante = P_MANDANTE; connectorSap.paswr = P_PASSWORD; connectorSap.sapRouter = P_SAPROUTER; connectorSap.user = P_UNAME; connectorSap.server = P_SERVER; string retval = connectorSap.connectionsSAP(); if (string.IsNullOrEmpty(retval)) { RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(connectorSap.connectorConfig); RfcRepository SapRfcRepository = SapRfcDestination.Repository; IRfcFunction BapiGetUser = SapRfcRepository.CreateFunction("ZSCP_RFC_GET_TCURR"); BapiGetUser.SetValue("LAND", LAND); BapiGetUser.SetValue("VPAGO", VPAGO); BapiGetUser.SetValue("FCURR", FCURR); BapiGetUser.SetValue("TCURR", TCURR); BapiGetUser.SetValue("FAMOUNT", FAMOUNT); BapiGetUser.SetValue("TAMOUNT", TAMOUNT); BapiGetUser.Invoke(SapRfcDestination); string Val = BapiGetUser.GetValue("LAMOUNT").ToString().Replace(".", ","); double val4 = Math.Ceiling(Convert.ToDouble(Val)); ValorConvertido = val4; } } catch (Exception e) { System.Diagnostics.Debug.Write(e.StackTrace); throw new Exception(); } finally { } }
public void tableAmPerson(string pernr) { connect(); RfcDestination rfcDest = RfcDestinationManager.GetDestination(parms); RfcRepository rfcRep = rfcDest.Repository; IRfcFunction IReader = rfcRep.CreateFunction("ZSSCN_DYNAMIC_SELECT"); IReader.SetValue("IV_SELECT", "A~COD_ITEM A~DESCRICAO B~AM_KN"); if (FeatureContext.Current.FeatureInfo.Title.Equals("AbilityMatrix_AssetClass")) { IReader.SetValue("IV_FROM", "/SSCN/LLIST AS A LEFT JOIN /SSCN/AM_PERSON AS B ON ( A~COD_ITEM = B~AM_KEY AND B~AM_TYPE = '1' AND B~PERNR = '" + pernr + "')"); IReader.SetValue("IV_WHERE", "A~NOME_LISTA = 'CLASSES' AND A~IDIOMA = 'EN'"); IReader.SetValue("IV_ORDER", "A~COD_ITEM"); } else { IReader.SetValue("IV_FROM", "/SSCN/LLIST AS A LEFT JOIN /SSCN/AM_PERSON AS B ON ( A~COD_ITEM = B~AM_KEY AND B~AM_TYPE = '2' AND B~PERNR = '" + pernr + "')"); IReader.SetValue("IV_WHERE", "A~NOME_LISTA = 'TIPO_OBJ' AND A~IDIOMA = 'EN'"); IReader.SetValue("IV_ORDER", "A~COD_ITEM"); } IReader.Invoke(rfcDest); string optionData = (string)IReader.GetValue("EV_RESULT_SET"); Directory.CreateDirectory("Relatorio"); filePathTxt = filePathTxt + @"\pathLPerson.txt"; System.IO.File.WriteAllText(filePathTxt, optionData); List <AbilityMatrix_SapTable> jsonList = JsonConvert.DeserializeObject <List <AbilityMatrix_SapTable> >(optionData); if (jsonList.Count() > 0) { //file CreateExcel1 = new AbilityMatrix_AmPersonExcel(); CreateExcel1.CreateWorkbook(filePathXlsx = filePathXlsx + @"\DadosAmPerson.xlsx"); //Adicionar Celulas jsonList .Select((mandante, x) => new { mandante, position = x }) .ToList() .ForEach(item => CreateExcel1.AddCell(item.position, item.mandante)); //Salvando dados no excel CreateExcel1.Save(); } }
public void fillDetailInformation(RfcDestination destination) { RfcRepository repo = destination.Repository; IRfcFunction costCenterList = repo.CreateFunction("BAPI_COSTCENTER_GETDETAIL"); costCenterList.SetValue("CONTROLLINGAREA", ControllingArea.ControllingAreaCode); costCenterList.SetValue("COSTCENTER", this.CostCenterCode); costCenterList.SetValue("DATE", DateTime.Now); costCenterList.Invoke(destination); this.PersonInCharge = costCenterList.GetValue("PERSON_IN_CHARGE").ToString(); IRfcStructure costCenters = costCenterList.GetStructure("ADDRESS"); this.CostCenterAddressCity = costCenters.GetString("CITY"); this.CostCenterAddressDistrict = costCenters.GetString("DISTRICT"); this.CostCenterAddressPOBOX = costCenters.GetString("PO_BOX"); this.CostCenterAddressStreet = costCenters.GetString("STREET"); }