Beispiel #1
0
        public List <string> Get_Z_RFC_GD_DELIVERY(string I_VBELN)
        {
            List <string> LsMsg = new List <string>();

            try
            {
                RfcDestination destination = RfcDestinationManager.GetDestination(this.GetCfgParameters());
                IRfcFunction   rfcFunction = destination.Repository.CreateFunction("Z_RFC_GD_DELIVERY");
                rfcFunction.SetValue("I_VBELN", I_VBELN);
                rfcFunction.Invoke(destination);

                IRfcStructure E_RETURN  = rfcFunction.GetStructure("E_RETURN");
                string        SAP_TYPE  = E_RETURN.GetValue("TYPE").ToString(); //是否成功 S 表示成功
                string        SAP_E_ID  = E_RETURN.GetValue("ID").ToString();
                string        SAP_E_NUM = E_RETURN.GetValue("NUMBER").ToString();
                string        SAP_MSG   = E_RETURN.GetValue("MESSAGE").ToString();
                LsMsg.Add(SAP_TYPE);
                LsMsg.Add(SAP_E_ID);
                LsMsg.Add(SAP_E_NUM);
                LsMsg.Add(SAP_MSG);
            }
            catch (Exception ex)
            {
                LsMsg.Add("ERR:" + ex.Message);
            }

            return(LsMsg);
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string dateStr = "";
            string timeStr = "";

            dateStr = dtDate.Text.Substring(6, 4) + "" + dtDate.Text.Substring(3, 2) + "" + dtDate.Text.Substring(0, 2);
            timeStr = dtTime.Text.Substring(0, 2) + "" + dtTime.Text.Substring(3, 2) + "" + dtTime.Text.Substring(6, 2);

            rfc_Connector cfg = null;

            cfg = new rfc_Connector();

            IRfcFunction getDataSAP = GlobalData.rfcRepository.CreateFunction("ZPM_NOTIF_01");

            IRfcStructure ls_ticketdata = getDataSAP.GetStructure("TICKED_DATA");
            IRfcStructure ls_result     = getDataSAP.GetStructure("RESULT");

            ls_ticketdata.SetValue("EQFNR", txt01.Text);
            ls_ticketdata.SetValue("QMART", cb01.Text);
            ls_ticketdata.SetValue("QMTXT", txt02.Text);
            ls_ticketdata.SetValue("TPLNR", txt03.Text);
            ls_ticketdata.SetValue("EQUNR", txt04.Text);
            ls_ticketdata.SetValue("QMNAM", txt05.Text);
            ls_ticketdata.SetValue("QMDAT", dateStr);
            ls_ticketdata.SetValue("MZEIT", timeStr);

            ls_ticketdata.SetValue("PRIOK", cbPriok.Text);
            ls_ticketdata.SetValue("STRMN", dateStr);
            ls_ticketdata.SetValue("LTRMN", dateStr);
            ls_ticketdata.SetValue("STRUR", timeStr);
            ls_ticketdata.SetValue("LTRUR", timeStr);

            ls_ticketdata.SetValue("ZBEBER", txt06.Text);
            ls_ticketdata.SetValue("ZBEBER2", txt07.Text);
            ls_ticketdata.SetValue("ZTPLNR2", txt08.Text);
            ls_ticketdata.SetValue("ZKOSTL", txt09.Text);

            try
            {
                getDataSAP.Invoke(GlobalData.rfcDestination);
                RfcSessionManager.EndContext(GlobalData.rfcDestination);

                IRfcStructure exStructure = getDataSAP.GetStructure("RESULT");
                MessageBox.Show(exStructure.GetValue("MESSAGE") + " - " + exStructure.GetValue("DOCNUM"));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Getting vendor details from SAP
        /// Date: 20 June 2019
        /// Developer: Shreyans Khandelwal (0538)
        /// </summary>
        /// <param name="rfcDest"></param>
        /// <returns></returns>
        public VendorDetail GetVendorDetail(RfcDestination rfcDest)
        {
            try
            {
                VendorDetail vendorDetModel = new VendorDetail();

                RfcDestination SAPRfcDestination = RfcDestinationManager.GetDestination("accelyides");

                RfcRepository rfcrep = SAPRfcDestination.Repository;
                IRfcFunction  BapiGetCompanyDetail = null;


                BapiGetCompanyDetail = rfcrep.CreateFunction("BAPI_VENDOR_GETDETAIL");
                BapiGetCompanyDetail.SetValue("VENDORNO", "VBX");
                BapiGetCompanyDetail.SetValue("COMPANYCODE", "0001");
                BapiGetCompanyDetail.Invoke(rfcDest);

                IRfcStructure IRS_OS_GeneralDet = BapiGetCompanyDetail.GetStructure("GENERALDETAIL");
                vendorDetModel.CompanyName   = IRS_OS_GeneralDet.GetValue("VENDOR").ToString();
                vendorDetModel.ContactName   = IRS_OS_GeneralDet.GetValue("NAME").ToString();
                vendorDetModel.ContactMobile = IRS_OS_GeneralDet.GetValue("TELEPHONE").ToString();
                vendorDetModel.Address       = IRS_OS_GeneralDet.GetValue("FORMOFADDR").ToString();
                //vendorDetModel.NAME_2 = IRS_OS_GeneralDet.GetValue("NAME_2").ToString();
                //vendorDetModel.NAME_3 = IRS_OS_GeneralDet.GetValue("NAME_3").ToString();
                //vendorDetModel.NAME_4 = IRS_OS_GeneralDet.GetValue("NAME_4").ToString();
                //vendorDetModel.CITY = IRS_OS_GeneralDet.GetValue("CITY").ToString();
                //vendorDetModel.DISTRICT = IRS_OS_GeneralDet.GetValue("DISTRICT").ToString();
                //vendorDetModel.PO_BOX = IRS_OS_GeneralDet.GetValue("PO_BOX").ToString();
                //vendorDetModel.POBX_PCD = IRS_OS_GeneralDet.GetValue("POBX_PCD").ToString();
                //vendorDetModel.POSTL_CODE = IRS_OS_GeneralDet.GetValue("POSTL_CODE").ToString();
                //vendorDetModel.REGION = IRS_OS_GeneralDet.GetValue("REGION").ToString();
                ////vendorDetModel.Address = IRS_OS_GeneralDet.GetValue("STREET").ToString();
                //vendorDetModel.COUNTRY = IRS_OS_GeneralDet.GetValue("STREET").ToString();
                //vendorDetModel.COUNTRYISO = IRS_OS_GeneralDet.GetValue("COUNTRYISO").ToString();
                //vendorDetModel.POBX_CTY = IRS_OS_GeneralDet.GetValue("POBX_CTY").ToString();
                //vendorDetModel.LANGU = IRS_OS_GeneralDet.GetValue("LANGU").ToString();
                //vendorDetModel.LANGU_ISO = IRS_OS_GeneralDet.GetValue("LANGU_ISO").ToString();
                //vendorDetModel.TELEPHONE2 = IRS_OS_GeneralDet.GetValue("TELEPHONE2").ToString();

                RfcSessionManager.EndContext(rfcDest);

                return(vendorDetModel);
            }
            catch (Exception ex)
            {
                logger.WriteLog(ex);
                throw ex;
            }
        }
Beispiel #4
0
        public int VALIDATE_MAIL(string UIDL, SharedSettings.Settings settings)
        {
            string value = string.Empty;

            try
            {
                //Establecemos conexion con SAP
                RfcConfigParameters rfc = SAP_Connection.GetParameters(settings);

                RfcDestination rfcDest = null;
                rfcDest = RfcDestinationManager.GetDestination(rfc);

                //Creamos repositorio para la función
                RfcRepository repo          = rfcDest.Repository;
                IRfcFunction  validate_mail = repo.CreateFunction("Z_MAIL_VALIDATE");


                validate_mail.SetValue("UIDL", UIDL);

                //Ejecutamos la consulta
                validate_mail.Invoke(rfcDest);

                IRfcStructure ret = validate_mail.GetStructure("RETURN");
                value = ret.GetValue("NUMBER").ToString();
                if (value == "004")
                {
                    //Encontró correo previamente guardado
                    return(0);
                }
                else
                {
                    //No encontró correo return
                    return(4);
                }
            }
            catch (RfcCommunicationException e)
            {
                throw e;
            }
            catch (RfcLogonException e)
            {
                // user could not logon...
                throw e;
            }
            catch (RfcAbapRuntimeException e)
            {
                // serious problem on ABAP system side...
                throw e;
            }
            catch (RfcAbapBaseException e)
            {
                // The function module returned an ABAP exception, an ABAP message
                // or an ABAP class-based exception...
                throw e;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #5
0
        public T FromStructure <T>(IRfcStructure structure)
        {
            Type type = typeof(T);

            EnsureTypeIsCached(type);

            T returnObject = default(T);

            if (!type.Equals(typeof(string)))
            {
                returnObject = Activator.CreateInstance <T>();
            }

            for (int i = 0; i < structure.Metadata.FieldCount; i++)
            {
                string fieldName = structure.Metadata[i].Name;
                object value     = structure.GetValue(fieldName);
                if (string.IsNullOrEmpty(fieldName))
                {
                    return((T)this.FromRemoteValue(type, value));
                }

                PropertyInfo property = null;
                if (typeProperties[type].TryGetValue(fieldName.ToLower(), out property))
                {
                    this.SetProperty(returnObject, property, value);
                }
            }
            return(returnObject);
        }
        public InvoiceValueModel GetInvoiceValue(RfcDestination rfcDest)
        {
            InvoiceValueModel invoiceValueModel = new InvoiceValueModel();
            RfcDestination    SAPRfcDestination = RfcDestinationManager.GetDestination("accelyides");

            RfcRepository rfcrep = SAPRfcDestination.Repository;
            IRfcFunction  BapiGetCompanyDetail = null;


            BapiGetCompanyDetail = rfcrep.CreateFunction("BAPI_INCOMINGINVOICE_GETDETAIL");
            BapiGetCompanyDetail.SetValue("INVOICEDOCNUMBER", "1000000020");
            BapiGetCompanyDetail.SetValue("FISCALYEAR", "2013");
            BapiGetCompanyDetail.Invoke(rfcDest);
            IRfcTable tblReturn = BapiGetCompanyDetail.GetTable("ITEMDATA");
            DataTable TBL       = tblReturn.ToDataTable("TBL");

            for (int i = 0; i < TBL.Rows.Count; i++)
            {
                InvoiceValueModel invoiceValueModel1 = new InvoiceValueModel();

                invoiceValueModel1.REF_DOC = TBL.Rows[i]["REF_DOC"].ToString();
                // invoiceValueModel.lstInvoiceValue.Add(invoiceValueModel1);
            }

            IRfcStructure IRS_OS_HEADER = BapiGetCompanyDetail.GetStructure("HEADERDATA");

            invoiceValueModel.Value = IRS_OS_HEADER.GetValue("USERNAME").ToString();
            //Console.WriteLine(invoiceValueModel.Value);
            //Console.ReadKey();
            RfcSessionManager.EndContext(rfcDest);

            return(invoiceValueModel);
        }
Beispiel #7
0
        //const string INCOMING_RFC = "SAP_INCOMING";

        private string[] getMaterialName(RfcDestination destination, string MaterialId)
        {
            string[]     material = new string[2];
            IRfcFunction function = null;

            try
            {
                function = destination.Repository.CreateFunction("BAPI_MATERIAL_GET_DETAIL");
                function.SetValue("material", MaterialId);
                function.Invoke(destination);
            }
            catch (RfcBaseException e)
            {
                Console.WriteLine(e.ToString());
            }
            IRfcStructure retData = (IRfcStructure)function.GetValue("material_general_data");

            material[0] = (string)retData.GetValue("MATL_DESC");
            material[1] = (string)retData.GetValue("MATL_GROUP");
            return(material);
        }
Beispiel #8
0
        //Class สำหรับ Convert structure เป็น Datatable
        public DataTable ConvertStructure(IRfcStructure myrefcTable)
        {
            DataTable rowTable = new DataTable();

            for (int i = 0; i <= myrefcTable.ElementCount - 1; i++)
            {
                rowTable.Columns.Add(myrefcTable.GetElementMetadata(i).Name);
            }
            DataRow row = rowTable.NewRow();

            for (int j = 0; j <= myrefcTable.ElementCount - 1; j++)
            {
                row[j] = myrefcTable.GetValue(j);
            }
            rowTable.Rows.Add(row);
            return(rowTable);
        }
Beispiel #9
0
        public static List <Dictionary <string, object> > GetListDictionaryForMetadataExport(IRfcFunction rfc, string tableName)
        {
            Dictionary <string, object>         dictionary     = new Dictionary <string, object>();
            List <Dictionary <string, object> > listDictionary = new List <Dictionary <string, object> >();

            for (int i = 0; i < rfc.Metadata.ParameterCount; i++)
            {
                if (rfc.Metadata[i].Name.ToString().ToUpper() == tableName)
                {
                    switch (rfc.Metadata[i].DataType.ToString())
                    {
                    case "STRUCTURE":
                        IRfcStructure detailStructure = rfc[tableName].GetStructure();
                        dictionary = new Dictionary <string, object>();
                        for (int j = 0; j < detailStructure.Count(); j++)
                        {
                            //dictionary[rfc.Metadata[i].ValueMetadataAsStructureMetadata[j].Name] = Activator.CreateInstance(SAPData.GetDataType(rfc.Metadata[i].ValueMetadataAsStructureMetadata[j].DataType));

                            var valueObj = detailStructure.GetValue(rfc.Metadata[i].ValueMetadataAsStructureMetadata[j].Name);
                            dictionary[rfc.Metadata[i].ValueMetadataAsStructureMetadata[j].Name] = valueObj;
                        }
                        listDictionary.Add(dictionary);
                        break;

                    case "TABLE":
                        IRfcTable detail = rfc[tableName].GetTable();
                        for (int j = 0; j < detail.Count(); j++)
                        {
                            //foreach (IRfcStructure column in detail[j])
                            dictionary = new Dictionary <string, object>();
                            for (int x = 0; x < detail[j].Count(); x++)
                            {
                                var valueObj = detail[j].GetValue(rfc.Metadata[i].ValueMetadataAsTableMetadata[x].Name);
                                dictionary[rfc.Metadata[i].ValueMetadataAsTableMetadata[x].Name] = valueObj;
                            }
                            listDictionary.Add(dictionary);
                        }

                        break;
                    }
                }
            }
            return(listDictionary);
        }
Beispiel #10
0
        public DataTable GetDataTableFromRFCStructure(IRfcStructure rfcStructure)
        {
            DataTable dt = new DataTable();

            for (int i = 0; i <= rfcStructure.ElementCount - 1; i++)
            {
                dt.Columns.Add(rfcStructure.GetElementMetadata(i).Name);
            }

            DataRow row = dt.NewRow();

            for (int j = 0; j <= rfcStructure.ElementCount - 1; j++)
            {
                row[j] = rfcStructure.GetValue(j);
            }

            dt.Rows.Add(row);

            return(dt);
        }
Beispiel #11
0
        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);
            }
        }
Beispiel #12
0
        public InvoiceValueModel GetInvoiceValue(RfcDestination rfcDest, string InvoiceDocNumber, string FISCALYEAR)
        {
            List <InvoiceValueModel> lstInvoiceValueDet = new List <InvoiceValueModel>();
            InvoiceValueModel        invoiceValueModel  = new InvoiceValueModel();
            RfcDestination           SAPRfcDestination  = RfcDestinationManager.GetDestination("accelyides");

            RfcRepository rfcrep = SAPRfcDestination.Repository;
            IRfcFunction  BapiGetCompanyDetail = null;


            BapiGetCompanyDetail = rfcrep.CreateFunction("BAPI_INCOMINGINVOICE_GETDETAIL");
            BapiGetCompanyDetail.SetValue("INVOICEDOCNUMBER", InvoiceDocNumber);
            BapiGetCompanyDetail.SetValue("FISCALYEAR", FISCALYEAR);
            BapiGetCompanyDetail.Invoke(rfcDest);
            IRfcTable tblReturn = BapiGetCompanyDetail.GetTable("ITEMDATA");
            DataTable TBL       = tblReturn.ToDataTable("TBL");

            IRfcTable tblTAXReturn = BapiGetCompanyDetail.GetTable("TAXDATA");
            DataTable TBLTaxReturn = tblTAXReturn.ToDataTable("TBL");

            IRfcTable tblWithTAXReturn = BapiGetCompanyDetail.GetTable("WITHTAXDATA");
            DataTable DtWithTAXReturn  = tblWithTAXReturn.ToDataTable("TBL");

            IRfcTable tblVendorSplitData = BapiGetCompanyDetail.GetTable("VENDORITEMSPLITDATA");
            DataTable DtVendorSplitData  = tblVendorSplitData.ToDataTable("TBL");

            //for (int i = 0; i < TBL.Rows.Count; i++)
            //{
            //    InvoiceValueModel InvoiceValueModel = new InvoiceValueModel();

            //    InvoiceValueModel.REF_DOC = TBL.Rows[i]["REF_DOC"].ToString();
            //   // invoiceValueModel.lstInvoiceValue.Add(InvoiceValueModel);
            //}
            invoiceValueModel.lstItemInvoiceDet = (from DataRow row in TBL.Rows
                                                   select new InvoiceValueModel
            {
                INVOICE_DOC_ITEM = row["INVOICE_DOC_ITEM"].ToString(),
                PO_NUMBER = row["INVOICE_DOC_ITEM"].ToString(),
                PO_ITEM = row["PO_ITEM"].ToString(),
                SERIAL_NO = row["SERIAL_NO"].ToString(),
                REF_DOC = row["REF_DOC"].ToString(),
                REF_DOC_YEAR = row["REF_DOC_YEAR"].ToString(),
                REF_DOC_IT = row["REF_DOC_IT"].ToString(),
                TAX_CODE = row["TAX_CODE"].ToString(),
                ITEM_AMOUNT = row["ITEM_AMOUNT"].ToString(),
                QUANTITY = row["QUANTITY"].ToString(),
                PO_UNIT = row["PO_UNIT"].ToString(),
                PO_UNIT_ISO = row["PO_UNIT_ISO"].ToString()
            }).ToList();

            invoiceValueModel.lstInvoiceTAXDet = (from DataRow row in TBLTaxReturn.Rows
                                                  select new InvoiceValueModel
            {
                TAX_CODE = row["TAX_CODE"].ToString(),
                TAX_AMOUNT = row["TAX_AMOUNT"].ToString(),
                VEND_ERROR = row["VEND_ERROR"].ToString(),
                TAX_ERROR = row["TAX_ERROR"].ToString(),
            }).ToList();

            invoiceValueModel.lstWithTAXInvoiceDet = (from DataRow row in DtWithTAXReturn.Rows
                                                      select new InvoiceValueModel
            {
                SPLIT_KEY = row["SPLIT_KEY"].ToString(),
                WI_TAX_TYPE = row["WI_TAX_TYPE"].ToString()
            }).ToList();

            invoiceValueModel.lstVEndorItemSolitData = (from DataRow row in DtVendorSplitData.Rows
                                                        select new InvoiceValueModel
            {
                SPLIT_KEY = row["SPLIT_KEY"].ToString(),
                SPLIT_AMOUNT = row["SPLIT_AMOUNT"].ToString()
            }).ToList();

            IRfcStructure IRS_OS_HEADER = BapiGetCompanyDetail.GetStructure("HEADERDATA");

            invoiceValueModel.INV_DOC_NO     = IRS_OS_HEADER.GetValue("INV_DOC_NO").ToString();
            invoiceValueModel.USERNAME       = IRS_OS_HEADER.GetValue("FISC_YEAR").ToString();
            invoiceValueModel.FISC_YEAR      = IRS_OS_HEADER.GetValue("USERNAME").ToString();
            invoiceValueModel.INVOICEE_IND   = IRS_OS_HEADER.GetValue("INVOICE_IND").ToString();
            invoiceValueModel.DOC_TYPE       = IRS_OS_HEADER.GetValue("DOC_TYPE").ToString();
            invoiceValueModel.DOC_DATE       = DateTime.Parse(IRS_OS_HEADER.GetValue("DOC_DATE").ToString());
            invoiceValueModel.PSTNG_DATE     = DateTime.Parse(IRS_OS_HEADER.GetValue("PSTNG_DATE").ToString());
            invoiceValueModel.USERNAME       = IRS_OS_HEADER.GetValue("USERNAME").ToString();
            invoiceValueModel.REF_DOC_NO     = IRS_OS_HEADER.GetValue("REF_DOC_NO").ToString();
            invoiceValueModel.COMP_CODE      = IRS_OS_HEADER.GetValue("COMP_CODE").ToString();
            invoiceValueModel.DIFF_INV       = IRS_OS_HEADER.GetValue("DIFF_INV").ToString();
            invoiceValueModel.CURRENCY       = IRS_OS_HEADER.GetValue("CURRENCY").ToString();
            invoiceValueModel.CURRENCY_ISO   = IRS_OS_HEADER.GetValue("CURRENCY_ISO").ToString();
            invoiceValueModel.EXCH_RATE      = IRS_OS_HEADER.GetValue("EXCH_RATE").ToString();
            invoiceValueModel.EXCH_RATE_V    = IRS_OS_HEADER.GetValue("EXCH_RATE_V").ToString();
            invoiceValueModel.GROSS_AMT      = IRS_OS_HEADER.GetValue("GROSS_AMNT").ToString();
            invoiceValueModel.BLINE_DATE     = DateTime.Parse(IRS_OS_HEADER.GetValue("BLINE_DATE").ToString());
            invoiceValueModel.ENTRY_DATE     = DateTime.Parse(IRS_OS_HEADER.GetValue("ENTRY_DATE").ToString());
            invoiceValueModel.ENTRY_TIME     = DateTime.Parse(IRS_OS_HEADER.GetValue("ENTRY_TIME").ToString());
            invoiceValueModel.DISCNT         = IRS_OS_HEADER.GetValue("DISCNT").ToString();
            invoiceValueModel.INVOICE_STATUS = IRS_OS_HEADER.GetValue("INVOICE_STATUS").ToString();

            //Console.WriteLine(invoiceValueModel.Value);
            //Console.ReadKey();
            RfcSessionManager.EndContext(rfcDest);

            return(invoiceValueModel);
        }
Beispiel #13
0
        public List <string> WHS_MOVE_Z_RFC_AUFNR_MIGO(string DicRFCAufnrMigo, string TestFlag)
        {
            IDictionary <string, object> mst = MapListConverter.JsonToDictionary(DicRFCAufnrMigo);
            List <string> LsMsg = new List <string>();

            try
            {
                #region GM_CODE是和SAP的T-code相关

                /*01 MB01
                *  02 MB31
                *  03 MB1A
                *  04 MB1B
                *  05 MB1C
                *  06 MB11*/
                #endregion


                RfcDestination destination = RfcDestinationManager.GetDestination(this.GetCfgParameters());
                IRfcFunction   rfcFunction = destination.Repository.CreateFunction("Z_RFC_AUFNR_MIGO");

                IRfcStructure IS_HEAD = rfcFunction.GetStructure("IS_HEAD");
                IS_HEAD.SetValue("GM_CODE", "04");
                //IS_HEAD.SetValue("PSTNG_DATE", string.IsNullOrEmpty(RFCAufnrMigo.PSTNG_DATE) ? DateTime.Now.ToString("yyyyMMdd") : RFCAufnrMigo.PSTNG_DATE);
                //IS_HEAD.SetValue("DOC_DATE", string.IsNullOrEmpty(RFCAufnrMigo.DOC_DATE) ? DateTime.Now.ToString("yyyyMMdd") : RFCAufnrMigo.DOC_DATE);
                //IS_HEAD.SetValue("HEADER_TXT", RFCAufnrMigo.EMP_NO + RFCAufnrMigo.EMP_NAME);//人员权限
                IS_HEAD.SetValue("PSTNG_DATE", mst.ContainsKey("PSTNG_DATE") ? DateTime.Now.ToString("yyyyMMdd") : mst["PSTNG_DATE"].ToString());
                IS_HEAD.SetValue("DOC_DATE", mst.ContainsKey("DOC_DATE") ? DateTime.Now.ToString("yyyyMMdd") : mst["DOC_DATE"].ToString());
                IS_HEAD.SetValue("HEADER_TXT", mst["EMP_NO"].ToString() + mst["EMP_NAME"].ToString()); //人员权限
                rfcFunction.SetValue("IS_HEAD", IS_HEAD);                                              //设置参数

                IRfcStructure IS_ITEM = rfcFunction.GetStructure("IS_ITEM");
                IS_ITEM.SetValue("MATERIAL", mst["PARTNUMBER"].ToString());
                IS_ITEM.SetValue("PLANT", mst["PLANT"].ToString());
                IS_ITEM.SetValue("STGE_LOC", mst["STGE_LOC"].ToString());        // RFCAufnrMigo.STGE_LOC); //转出仓
                IS_ITEM.SetValue("MOVE_TYPE", "311");                            //仓库之间转移
                IS_ITEM.SetValue("ENTRY_QNT", Convert.ToInt32(mst["STGE_LOC"])); // RFCAufnrMigo.QTY);
                IS_ITEM.SetValue("MOVE_PLANT", mst["MOVE_PLANT"].ToString());
                IS_ITEM.SetValue("MOVE_STLOC", mst["MOVE_STLOC"].ToString());    // RFCAufnrMigo.MOVE_STLOC);
                rfcFunction.SetValue("IS_ITEM", IS_ITEM);                        //设置参数

                rfcFunction.SetValue("I_TYPE", "3");                             //1成品入库 2出库  03 移库
                if (!string.IsNullOrEmpty(TestFlag))
                {
                    rfcFunction.SetValue("TESTRUN", "X"); //检查入库,不过账
                }
                rfcFunction.Invoke(destination);

                string        SAP_STOCKNO = rfcFunction.GetValue("E_MBLNR").ToString().TrimStart('0'); //物料凭证号码
                IRfcStructure ES_RETURN   = rfcFunction.GetStructure("ES_RETURN");
                string        SAP_TYPE    = ES_RETURN.GetValue("TYPE").ToString();                     //是否成功 S 表示成功
                string        SAP_E_ID    = ES_RETURN.GetValue("ID").ToString();
                string        SAP_E_NUM   = ES_RETURN.GetValue("NUMBER").ToString();
                string        SAP_MSG     = ES_RETURN.GetValue("MESSAGE").ToString();


                LsMsg.Add(SAP_STOCKNO);
                LsMsg.Add(SAP_TYPE);
                LsMsg.Add(SAP_E_ID);
                LsMsg.Add(SAP_E_NUM);
                LsMsg.Add(SAP_MSG);
                return(LsMsg);
            }
            catch (Exception ex)
            {
                LsMsg.Add(ex.Message);
                return(LsMsg);
            }
        }
 //public DataTable GetDataTableFromRFCTable(IRfcTable lrfcTable)
 //{
 //    //sapnco_util
 //    DataTable loTable = new DataTable();
 //    //... Create ADO.Net table.
 //    for (int liElement = 0; liElement < lrfcTable.ElementCount; liElement++)
 //    {
 //        RfcElementMetadata metadata = lrfcTable.GetElementMetadata(liElement);
 //        loTable.Columns.Add(metadata.Name);
 //    }
 //    //... Transfer rows from lrfcTable to ADO.Net table.
 //    foreach (IRfcStructure row in lrfcTable)
 //    {
 //        DataRow ldr = loTable.NewRow();
 //        for (int liElement = 0; liElement < lrfcTable.ElementCount; liElement++)
 //        {
 //            RfcElementMetadata metadata = lrfcTable.GetElementMetadata(liElement);
 //            ldr[metadata.Name] = row.GetString(metadata.Name);
 //        }
 //        loTable.Rows.Add(ldr);
 //    }
 //    return loTable;
 //}
 public DataTable RfcStructureToDataTable(IRfcStructure myrefcTable)
 {
     DataTable rowTable = new DataTable();
     for (int i = 0; i <= myrefcTable.ElementCount - 1; i++)
     {
         rowTable.Columns.Add(myrefcTable.GetElementMetadata(i).Name);
     }
     DataRow row = rowTable.NewRow();
     for (int j = 0; j <= myrefcTable.ElementCount - 1; j++)
     {
         row[j] = myrefcTable.GetValue(j);
     }
     rowTable.Rows.Add(row);
     return rowTable;
 }
Beispiel #15
0
        /// <summary>
        /// Transforma a 1 o 2 Meters (ver caso OLMFW01) una fila de la tabla de resultados
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        private static IEnumerable<Meter> getRowMeterList(IRfcStructure row)
        {
            IList<Meter> result = new List<Meter>();

            int numberOfCounters = getNumberOfCountersInThisRow(row);

            if (numberOfCounters == 0)
                return result;

            double  num = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER)));
            double den=double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER));
            DateTime startDate = DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_START_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true));
            DateTime endDate = DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_END_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true));

            Meter firstMeter = new Meter()
            {
                //IdMeter = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_ID),
                //IdPlant = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_UF),
                //LosingRate = double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_PERD)),
                //Power = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER)) / numberOfCounters),
                //PowerPercentage = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER))
                //    / double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER)))

                IdMeter = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_ID),
                IdPlant = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_UF),
                startDate=DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_START_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true)),
                endDate=DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_END_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true)),
                LosingRate = double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_PERD)),
                Power = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER))),
                PowerPercentage = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER))
                    / double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER)))
            };

            result.Add(firstMeter);

            if (numberOfCounters == 1)
                return result;

            Meter secondMeter = new Meter()
            {
                //IdMeter = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT2_ID),
                //IdPlant = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_UF),
                //LosingRate = double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT2_PERD)),
                //Power = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER)) / numberOfCounters),
                //PowerPercentage = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER))
                //    / double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER)))

                IdMeter = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT2_ID),
                IdPlant = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_UF),
                startDate = DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_START_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true)),
                endDate = DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_END_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true)),
                LosingRate = double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT2_PERD)),
                Power = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER)) / numberOfCounters),
                PowerPercentage = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER))
                    / double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER)))
            };

            result.Add(secondMeter);

            return result;
        }
Beispiel #16
0
 /// <summary>
 /// Devuelve el numero de Meters distintos en una unica fila
 /// </summary>
 /// <param name="row"></param>
 /// <returns></returns>
 private static int getNumberOfCountersInThisRow(IRfcStructure row)
 {
     int result = 0;
     if (((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_ID)).Trim() != string.Empty)
         result++;
     if (((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT2_ID)).Trim() != string.Empty)
         result++;
     return result;
 }
Beispiel #17
0
        public List <string> Get_Z_RFC_AUFNR_MIGO(string DicRFCAufnrMigo)
        {
            IDictionary <string, object> mst = MapListConverter.JsonToDictionary(DicRFCAufnrMigo);

            List <string> LsMsg = new List <string>();

            try
            {
                #region GM_CODE是和SAP的T-code相关

                /*01 MB01
                *  02 MB31
                *  03 MB1A
                *  04 MB1B
                *  05 MB1C
                *  06 MB11*/
                #endregion


                RfcDestination destination = RfcDestinationManager.GetDestination(this.GetCfgParameters());
                IRfcFunction   rfcFunction = destination.Repository.CreateFunction("Z_RFC_AUFNR_MIGO");

                IRfcStructure IS_HEAD = rfcFunction.GetStructure("IS_HEAD");
                IS_HEAD.SetValue("GM_CODE", "02");
                IS_HEAD.SetValue("PSTNG_DATE", mst.ContainsKey("PSTNG_DATE") ? DateTime.Now.ToString("yyyyMMdd") : mst["PSTNG_DATE"].ToString());
                IS_HEAD.SetValue("DOC_DATE", mst.ContainsKey("DOC_DATE") ? DateTime.Now.ToString("yyyyMMdd") : mst["DOC_DATE"].ToString());
                IS_HEAD.SetValue("HEADER_TXT", mst["EMP_NO"].ToString() + mst["EMP_NAME"].ToString()); //人员权限
                rfcFunction.SetValue("IS_HEAD", IS_HEAD);                                              //设置参数

                IRfcStructure IS_ITEM = rfcFunction.GetStructure("IS_ITEM");
                IS_ITEM.SetValue("MATERIAL", mst["PARTNUMBER"].ToString());
                if (mst.ContainsKey("PLANT"))
                {
                    IS_ITEM.SetValue("PLANT", mst["PLANT"].ToString());
                }
                else
                {
                    IS_ITEM.SetValue("PLANT", "2100");
                }
                IS_ITEM.SetValue("MOVE_TYPE", "101");
                IS_ITEM.SetValue("ENTRY_QNT", Convert.ToInt32(mst["QTY"]));
                IS_ITEM.SetValue("ORDERID", mst["WOID"]);
                IS_ITEM.SetValue("MVT_IND", "F");

                rfcFunction.SetValue("IS_ITEM", IS_ITEM); //设置参数
                rfcFunction.SetValue("I_TYPE", "1");      //1成品入库 2出库

                rfcFunction.Invoke(destination);

                string        SAP_STOCKNO = rfcFunction.GetValue("E_MBLNR").ToString().TrimStart('0'); //物料凭证号码
                IRfcStructure ES_RETURN   = rfcFunction.GetStructure("ES_RETURN");
                string        SAP_TYPE    = ES_RETURN.GetValue("TYPE").ToString();                     //是否成功 S 表示成功
                string        SAP_E_ID    = ES_RETURN.GetValue("ID").ToString();
                string        SAP_E_NUM   = ES_RETURN.GetValue("NUMBER").ToString();
                string        SAP_MSG     = ES_RETURN.GetValue("MESSAGE").ToString();


                LsMsg.Add(SAP_STOCKNO);
                LsMsg.Add(SAP_TYPE);
                LsMsg.Add(SAP_E_ID);
                LsMsg.Add(SAP_E_NUM);
                LsMsg.Add(SAP_MSG);
                return(LsMsg);
            }
            catch (Exception ex)
            {
                LsMsg.Add(ex.Message);
                return(LsMsg);
            }
        }
Beispiel #18
0
        /// <summary>
        /// 动态调用RFC函数
        /// </summary>
        /// <param name="sysName"></param>
        /// <param name="funame"></param>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <returns></returns>
        public static bool InvokeFunction(string sysName, string funame, MetaValueList input, out MetaValueList output)
        {
            try
            {
                RfcFunctionMetadata MetaData = SAPFunctionMeta.GetRfcFunctionMetadata(sysName, funame);
                IRfcFunction        function = MetaData.CreateFunction();
                //初步序列化后的参数还需要进一步进行格式化,把结构体与表格都转化成SAP格式。
                if (input != null)
                {
                    //填充所有的参数
                    List <String> KeyIndex = new List <string>();
                    KeyIndex.AddRange(input.FieldValueList.Keys);
                    KeyIndex.AddRange(input.StructureValueList.Keys);
                    KeyIndex.AddRange(input.TableValueList.Keys);
                    KeyIndex.ForEach(x => x.ToUpper().Trim());
                    for (int i = 0; i < MetaData.ParameterCount; i++)
                    {
                        RfcParameterMetadata pMetadata = MetaData[i];
                        if (pMetadata.Direction == RfcDirection.EXPORT)
                        {
                            continue;
                        }
                        if (!KeyIndex.Contains(pMetadata.Name))
                        {
                            continue;
                        }

                        // Dictionary<String, Object> ParameterList = new Dictionary<string, object>();
                        if (pMetadata.DataType == RfcDataType.STRUCTURE)
                        {
                            if (input.StructureValueList.ContainsKey(pMetadata.Name))
                            {
                                Dictionary <String, String> structure;
                                input.StructureValueList.TryGetValue(pMetadata.Name, out structure);
                                IRfcStructure str = function.GetStructure(pMetadata.Name, true);
                                if (structure != null)
                                {
                                    for (int s = 0; s < str.Metadata.FieldCount; s++)
                                    {
                                        RfcFieldMetadata field = str.Metadata[s];
                                        if (structure.Keys.Contains(field.Name))
                                        {
                                            Object o = Converts.ObjectToRfcValue(structure[field.Name], field.DataType);
                                            str.SetValue(field.Name, o);
                                        }
                                    }
                                }
                            }
                        }
                        else if (pMetadata.DataType == RfcDataType.TABLE)
                        {
                            List <Dictionary <String, String> > tablelist;
                            input.TableValueList.TryGetValue(pMetadata.Name, out tablelist);
                            if (tablelist != null)
                            {
                                IRfcTable table = function.GetTable(pMetadata.Name);
                                for (int j = 0; j < tablelist.Count; j++)
                                {
                                    table.Append();
                                    for (int k = 0; k < table.Metadata.LineType.FieldCount; k++)
                                    {
                                        RfcFieldMetadata field = table.Metadata.LineType[k];
                                        if (tablelist[j].Keys.Contains(field.Name))
                                        {
                                            Object o = Converts.ObjectToRfcValue(tablelist[j][field.Name], field.DataType);
                                            table.SetValue(field.Name, o);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            String value = "";
                            input.FieldValueList.TryGetValue(pMetadata.Name, out value);
                            Object o = Converts.ObjectToRfcValue(value, pMetadata.DataType);
                            function.SetValue(pMetadata.Name, o);
                        }
                    }
                }
                MetaValueList outputlist = new MetaValueList();

                try
                {
                    RfcDestination destination = SAPDestination.GetDesByName(sysName);

                    function.Invoke(destination);
                }
                catch (RfcAbapException ee)
                {
                    throw new SAPException(ee.Key + ee.Message + ee.PlainText);
                }
                catch (RfcAbapRuntimeException runtimeEx)
                {
                    throw new SAPException(runtimeEx.Key + runtimeEx.Message + runtimeEx.PlainText);
                }


                for (int i = 0; i < MetaData.ParameterCount; i++)
                {
                    RfcParameterMetadata pMetadata = MetaData[i];
                    if (pMetadata.Direction == RfcDirection.IMPORT)
                    {
                        continue;
                    }
                    // outputlist.FieldTypeList.Add(pMetadata.Name, pMetadata.DataType.ToString());
                    if (pMetadata.DataType == RfcDataType.STRUCTURE)
                    {
                        Dictionary <String, String> stru = null;
                        IRfcStructure structure          = function.GetStructure(pMetadata.Name, false);
                        if (structure != null)
                        {
                            stru = new Dictionary <string, string>();
                            for (int s = 0; s < structure.Metadata.FieldCount; s++)
                            {
                                RfcFieldMetadata field  = structure.Metadata[s];
                                Object           result = null;

                                if (field.DataType == RfcDataType.BYTE)
                                {
                                    result = structure.GetString(field.Name);
                                }
                                else
                                {
                                    result = structure.GetValue(field.Name);
                                }

                                result = Converts.RfcToDoNetValue(result, field.DataType).ToString();
                                stru.Add(field.Name, result.ToString());
                            }
                            if (stru != null)
                            {
                                outputlist.StructureValueList.Add(pMetadata.Name, stru);
                            }
                        }
                    }
                    else if (pMetadata.DataType == RfcDataType.TABLE)
                    {
                        List <Dictionary <String, String> > outTableList = null;
                        IRfcTable outTable = function.GetTable(pMetadata.Name, false);
                        if (outTable != null)
                        {
                            outTableList = new List <Dictionary <string, string> >();
                            for (int s = 0; s < outTable.RowCount; s++)
                            {
                                IRfcStructure rfcTableLine      = outTable[s];
                                Dictionary <String, String> row = new Dictionary <string, string>();
                                for (int z = 0; z < rfcTableLine.Metadata.FieldCount; z++)
                                {
                                    RfcFieldMetadata field  = rfcTableLine[z].Metadata;
                                    Object           result = null;

                                    if (field.DataType == RfcDataType.BYTE)
                                    {
                                        result = rfcTableLine.GetString(field.Name);
                                    }
                                    else
                                    {
                                        result = rfcTableLine.GetValue(field.Name);
                                    }
                                    result = Converts.RfcToDoNetValue(result, field.DataType).ToString();
                                    row.Add(field.Name, result.ToString());
                                }
                                outTableList.Add(row);
                            }
                        }
                        outputlist.TableValueList.Add(pMetadata.Name, outTableList);
                    }
                    else
                    {
                        Object result = function.GetValue(pMetadata.Name);
                        result = Converts.RfcToDoNetValue(result, pMetadata.DataType);
                        outputlist.FieldValueList.Add(pMetadata.Name, result.ToString());
                    }
                }
                output = outputlist;
                return(true);
            }
            catch (Exception e)
            {
                output = null;
                throw new SAPException(e.Message);
            }
        }