Exemplo n.º 1
0
        /// <summary>
        /// Convierte una fecha inscrita en formato Fecha SAP
        /// </summary>
        /// <param name="dateValue">Fecha enviada</param>
        /// <returns>Fecha en formato dd.mm.rrrr</returns>
        public static string DateString(string dateString)
        {
            string sapDateString = null;

            if (!string.IsNullOrEmpty(dateString))
            {
                DateTime date = new DateTime();
                if (DateTime.TryParse(dateString, out date))
                {
                    sapDateString = SAPData.DateString(date);
                }
                else
                {
                    throw new Exception("Invalid dateString. It does not match with a valid date string.");
                }
            }
            return(sapDateString);
        }
Exemplo n.º 2
0
        public static Dictionary <string, object> GetDictionaryForMetadataExport(IRfcFunction rfc, string tableName)
        {
            Dictionary <string, object> dictionary = new 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":
                        for (int j = 0;
                             j < rfc.Metadata[i].ValueMetadataAsStructureMetadata.FieldCount;
                             j++)
                        {
                            dictionary[rfc.Metadata[i].ValueMetadataAsStructureMetadata[j].Name] = Activator.CreateInstance(SAPData.GetDataType(rfc.Metadata[i].ValueMetadataAsStructureMetadata[j].DataType));
                        }
                        break;

                    case "TABLE":
                        IRfcTable detail = rfc[tableName].GetTable();

                        /*for (int j = 0; j < detail.Count(); j++)
                         * {
                         *  var valueObj = detail[j].GetValue(rfc.Metadata[i].ValueMetadataAsTableMetadata[i].Name);
                         *  dictionary[rfc.Metadata[i].ValueMetadataAsTableMetadata[i].Name] = valueObj;
                         * }*/
                        for (int j = 0;
                             j < rfc.Metadata[i].ValueMetadataAsTableMetadata.LineType.FieldCount;
                             j++)
                        {
                            RfcFieldMetadata jd = rfc.Metadata[i].ValueMetadataAsTableMetadata[j];

                            Type   t           = SAPData.GetDataType(rfc.Metadata[i].ValueMetadataAsTableMetadata[j].DataType);
                            var    valueObject = detail.GetValue(rfc.Metadata[i].ValueMetadataAsTableMetadata[j].Name);
                            object value       = new object();
                            System.Reflection.PropertyInfo propInfo = t.GetType().GetProperty("UnderlyingSystemType");
                            if (t.Name != "String")
                            {
                                Type type;

                                switch (t.Name)
                                {
                                case "Decimal":
                                    type  = (Type)propInfo.GetValue(typeof(System.Decimal), null);
                                    value = Activator.CreateInstance(type, valueObject);
                                    break;

                                case "int":
                                    type  = (Type)propInfo.GetValue(typeof(System.Int64), null);
                                    value = Activator.CreateInstance(type, valueObject);
                                    break;

                                case "double":
                                    type  = (Type)propInfo.GetValue(typeof(System.Double), null);
                                    value = Activator.CreateInstance(type, valueObject);
                                    break;

                                default:
                                    type  = (Type)propInfo.GetValue(t, null);
                                    value = Activator.CreateInstance(typeof(System.String), valueObject);
                                    break;
                                }
                            }
                            else
                            {
                                //Type type = (Type)propInfo.GetValue(t, null);
                                value = valueObject.ToString();
                            }

                            dictionary[rfc.Metadata[i].ValueMetadataAsTableMetadata[j].Name] = value;
                        }
                        break;
                    }
                }
            }
            return(dictionary);
        }