Esempio n. 1
0
        public List <T> IRcTabeltoList <T>(IRfcTable table) where T : new()
        {
            List <T> listt = new List <T>();

            System.Reflection.PropertyInfo[] propertiesT = typeof(T).GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);


            for (int i = 0; i < table.Count; i++)
            {
                T t = new T();
                table.CurrentIndex = i;
                for (int j = 0; j < table.ElementCount; j++)
                {
                    foreach (System.Reflection.PropertyInfo itemT in propertiesT)
                    {
                        if (itemT.Name.ToLower() == table.GetElementMetadata(j).Name.ToLower())
                        {
                            switch (itemT.PropertyType.Name.ToLower())
                            {
                            case "string":
                                itemT.SetValue(t, table.GetString(j), null);
                                break;

                            case "int":
                                itemT.SetValue(t, Convert.ToInt32(table.GetInt(j)), null);
                                break;

                            case "int32":
                                itemT.SetValue(t, Convert.ToInt32(table.GetInt(j)), null);
                                break;

                            case "datetime":
                                itemT.SetValue(t, Convert.ToDateTime(table.GetString(j)), null);

                                break;
                            }
                        }
                    }
                }

                listt.Add(t);
            }

            return(listt);
        }
Esempio n. 2
0
        private List <AM_SAP> getDivizionOrganization(Dictionary <string, string> openWith, string parentExternalCode, string organizationId)
        {
            try
            {
                RfcDestinationManager.RegisterDestinationConfiguration(new ZSMK_SAP_Config());
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
            RfcDestination destination = RfcDestinationManager.GetDestination("RFC_EAH");
            IRfcFunction   function    = null;
            string         strDate     = DateTime.Today.ToString("yyyyMMdd");

            IFormatProvider culture = new System.Globalization.CultureInfo("ru-RU", true);
            string          format  = "yyyy-MM-dd";
            List <AM_SAP>   list    = new List <AM_SAP>();
            string          prefix  = "";

            try
            {
                function = destination.Repository.CreateFunction("ZP_GET_OSP");
                foreach (KeyValuePair <string, string> kvp in openWith)
                {
                    function.SetValue(kvp.Key, kvp.Value);
                    if (kvp.Key == "IM_WERKS")
                    {
                        prefix = kvp.Value;
                    }
                }

                function.Invoke(destination);
            }
            catch (RfcBaseException e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }

            if (function != null)
            {
                //Get the function table parameter COMPANYCODE_LIST
                IRfcTable codes = function.GetTable("PIT_OBJECTS");
                if (codes.RowCount == 0)
                {
                    System.Diagnostics.Debug.WriteLine("Данные не выбраны");
                }
                else
                {
                    //Iterate over all rows in the table COMPANYCODE_LIST
                    DateTime dt = DateTime.MinValue;

                    for (int i = 0; i < codes.RowCount; i++)
                    {
                        codes.CurrentIndex = i;
                        AM_SAP amSap = new AM_SAP();

                        if (codes.GetString("OTYPE") == "P")
                        {
                            amSap.OBJID = "1111" + codes.GetString("OBJID").TrimStart('0');
                        }
                        else
                        {
                            amSap.OBJID = prefix + codes.GetString("OBJID");
                        }
                        amSap.SOBID = prefix + codes.GetString("SOBID");
                        amSap.OTYPE = codes.GetString("OTYPE");
                        amSap.PRIOX = codes.GetString("PRIOX");
                        amSap.PROZT = codes.GetDouble("PROZT");
                        dt          = DateTime.MinValue;
                        DateTime.TryParseExact(codes.GetString("SBEGDA"), format, culture, DateTimeStyles.AssumeLocal, out dt);
                        amSap.SBEGDA = dt;
                        amSap.SCLAS  = codes.GetString("SCLAS");
                        dt           = DateTime.MinValue;
                        DateTime.TryParseExact(codes.GetString("SENDDA"), format, culture, DateTimeStyles.AssumeLocal, out dt);
                        amSap.SENDDA  = dt;
                        amSap.SHORT   = codes.GetString("SHORT");
                        amSap.STEXT   = codes.GetString("STEXT");
                        amSap.LEV_HIE = codes.GetInt("LEV_HIE");

                        dt = DateTime.MinValue;
                        DateTime.TryParseExact(codes.GetString("BEGDA"), format, culture, DateTimeStyles.AssumeLocal, out dt);
                        amSap.BEGDA = dt;

                        dt = DateTime.MinValue;
                        DateTime.TryParseExact(codes.GetString("ENDDA"), format, culture, DateTimeStyles.AssumeLocal, out dt);
                        amSap.ENDDA     = dt;
                        amSap.BUKRS     = "";
                        amSap.PERNR     = codes.GetString("PERNR");
                        amSap.R_01      = codes.GetString("R_01");
                        amSap.R_02      = codes.GetString("R_02");
                        amSap.R_03      = codes.GetString("R_03");
                        amSap.R_04      = codes.GetString("R_04");
                        amSap.R_05      = codes.GetString("R_05");
                        amSap.R_06      = codes.GetString("R_06");
                        amSap.R_07      = codes.GetString("R_07");
                        amSap.GESCH     = codes.GetString("GESCH");
                        amSap.PERSK     = codes.GetString("PERSK");
                        amSap.PERSG     = codes.GetString("PERSG");
                        amSap.STRINF_ID = codes.GetString("STRINF_ID");
                        dt = DateTime.MinValue;
                        DateTime.TryParseExact(codes.GetString("DATP"), format, culture, DateTimeStyles.AssumeLocal, out dt);
                        amSap.DATP       = dt;
                        amSap.VERB       = codes.GetString("VERB");
                        amSap.SHOPNUMBER = prefix;
                        amSap.ISSHOP     = false;
                        if (amSap.SHORT == "EAH")
                        {
                            amSap.ISSHOP = true;
                            amSap.SOBID  = parentExternalCode;
                        }

                        dt = DateTime.MinValue;
                        DateTime.TryParseExact(codes.GetString("BEGDA_D"), format, culture, DateTimeStyles.AssumeLocal, out dt);
                        amSap.BEGDA_D = dt;
                        dt            = DateTime.MinValue;
                        DateTime.TryParseExact(codes.GetString("ENDDA_D"), format, culture, DateTimeStyles.AssumeLocal, out dt);
                        amSap.ENDDA_D  = dt;
                        amSap.MVZ      = DataGlobals.MVZ_EVRAZRUDA_DIVIZION;
                        amSap.MVZ_NAME = getMVZName(organizationId);
                        list.Add(amSap);
                    }
                }
            }
            return(list);
        }