Someone could help me because I get this error in c #

0

The error is given to me in parameters in this part

He tells me

  

You can not convert sapestructura to system collections.Generic.List.   enSAPConnector.RunSAP Function ("ZMM_B2B_ENC_RESPUESTA", parameters);

 public class RespuestaEncuestaRepository
    {
        public ResprovSolicitudModel EnviarEncuesta(ResprovSolicitudModel value)
        {
            ResprovSolicitudModel respuesta = new ResprovSolicitudModel();


            SAPEstructura parametros = new SAPEstructura();
            //Dictionary<string, object> parametros = new Dictionary<string, object>();
           // Dictionary<string, object> tablasSalida = new Dictionary<string, object>();
            List<DataTable> datos = new List<DataTable>();

            SAPTabla MB1B = new SAPTabla { NombreTabla = "RESPROV" };

            foreach (var variable in value.ListaEncuesta)
            {
                Dictionary<string, object> elemento = new Dictionary<string, object>();
                elemento.Add("SECCION", variable.SECCION);
                elemento.Add("PREG", variable.PREG);
                elemento.Add("CONS", variable.CONS);
                elemento.Add("TIPO", variable.TIPO);
                elemento.Add("RESP", variable.RESP);
                MB1B.Parametros.Add(elemento);
            }

            parametros.Parametros.Add("RESPROV", MB1B);
            parametros.Parametros.Add("E_LIFNR", "0000254142"/*Common.RellenarIzquierda(value.CuentaSAP)*/);
            //parametros.Add("E_SPRAS", value.IdiomaSAPId);
            //tablasSalida.Add("RESPROV", new DataTable());

           SAPConector.EjecutarFuncionSAP("ZMM_B2B_ENC_RESPUESTA", parametros);



            return respuesta;

        }
    }
}

This is the function RunSAP Function.

public static MessageModel EjecutarFuncionSAP(string NameFunction, List<SAPEstructura> value)
        {
            MessageModel message = new MessageModel();
            RfcDestination rfcDestination = null;

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["SYSID_SAP"]))
            {
                rfcDestination = RfcDestinationManager.GetDestination(ConfigurationManager.AppSettings["SYSID_SAP"].ToString());
                if (rfcDestination != null)
                {
                    //Crea la instancia de la funcion
                    IRfcFunction funcion = rfcDestination.Repository.CreateFunction(NameFunction);

                    //Genera un listado para agregar las estructura que vaya a contener
                    List<IRfcStructure> Estructuras = new List<IRfcStructure>();

                    //Itera cada una de las estructuras
                    foreach (SAPEstructura estructuraSAP in value)
                    {
                        if (estructuraSAP.NombreEstructura == string.Empty)
                        {
                            foreach (var parametro in estructuraSAP.Parametros)
                            {
                                funcion.SetValue(parametro.Key, parametro.Value);
                            }
                        }
                        else
                        {
                            //Obtiene el tipo de estructura actual
                            IRfcStructure tempStruct = funcion.GetStructure(estructuraSAP.NombreEstructura);

                            //Agrega los N parametros que contiene
                            foreach (KeyValuePair<string, object> param in estructuraSAP.Parametros)
                            {
                                tempStruct.SetValue(param.Key, param.Value);
                            }

                            //Agrega al listado
                            Estructuras.Add(tempStruct);
                        }
                    }

                    //Ejecuta la funcion
                    funcion.Invoke(rfcDestination);

                    message.Status = 1;
                    message.Message = "GrlMsgExitoConsulta";
                }
                else
                {
                    throw new Exception("Error al crear RFCDestination.");
                }
            }
            else
            {
                throw new Exception("La cadena de conexion [SYSID_SAP] para SAP no esta configurada en el archivo .config.");
            }

            return message;
        }
    
asked by Noé Torres 26.12.2018 в 17:22
source

2 answers

0

You must modify this line:

SAPEstructura parametros = new SAPEstructura();

It must be a list - that's what the other function List<SAPEstructura> expects.

What happens is that now the parameter is a list, you must have 2 variables SAPEstructura parametros = new SAPEstructura(); and List ListaParametros = new List(); after you add the data in parameters you add it in the variable ListaParametros and that is the variable that you pass to the function.

    
answered by 26.12.2018 в 17:42
-2

What happens is that now parameters is a list, you must have 2 variables SAPEstructura parametros = new SAPEstructura(); and List<SAPEstructura> Listaparametros = new List<SAPEstructura>(); after you add the data in parameters you add it in the variable ListToParameters and that is the variable that you pass to the function

    
answered by 02.01.2019 в 19:41