AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 24.04.2008, 20:19   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
dax-lessons: Weather forecasting using X++
Источник: http://DAX-Lessons.spaces.live.com/B...FCD1!146.entry
==============


In todays competitive business world, there are many factors which determine the profit or loss.

Climatic conditions has its own impact and is becoming increasingly important for the corporates.

Like Demand forecast, weather forecast can be very helpful in business planning.

This Job is an attempt to predict the weather conditions in advance and organize things in such a way which will help the companies not
only to optimize their resources but also maximize their profits.

In the example, I used Yahoo released rss weather feeds: http://weather.yahoo.com/rss and XML programming to get the climatic conditions

The format of the URL for the feed is:
http://xml.weather.yahoo.com/forecastrss?p=USNY0996&u=f
p is a US zip or a Yahoo! Weather location ID
u is the temp. units. ‘F’ for Fahrenheit (default) and ‘C’ for celcius

static void weatherForecast(Args _args)
{
   XmlDocument         doc = newXmlDocument();
   XmlNamespaceManager ns;
   XmlNodeList         nodes;
   XmlNode                node;
  //AddressZipCode     addresszipCode;
   container day(str _day)
    {
        ;
       switch(_day)
        {
           case 'Mon' : return [1,'Monday'];
           case 'Tue' : return [2,'Tuesday'];
           case 'Wed' : return [3,'Wednesday'];
           case 'Thu' : return [4,'Thursday'];
           case 'Fri' : return [5,'Friday'];
           case 'Sat' : return [6,'Saturday'];
           case 'Sun' : return [7,'Sunday'];
            Default : return connull();
        }
    }
     ;
    //addresszipCode = _args.record();
   doc.Load("http://xml.weather.yahoo.com/forecastrss?p=UKXX0085&u=c" );// +addresszipCode.ZipCode +’&u=c’);
    // Setup namespace manager for XPath
    ns =new XmlNamespaceManager(doc.nameTable());
   ns.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");
    // Getforecast with XPath
    nodes= doc.SelectNodes("//rss/channel/item/yweather:forecast", ns);
    node =nodes.nextNode();
   setprefix("Weather forecast");
     while(node)
    {
       info("-----------------------------------------------------");
       info(conpeek(day(node.attributes().getNamedItem("day").InnerText()),2));
       info("-----------------------------------------------------");
       info( node.attributes().getNamedItem("text").InnerText());
       info('Min :'    +node.attributes().getNamedItem("low").InnerText());
       info('Max :'    +node.attributes().getNamedItem("high").InnerText());
       if(dayofwk(today()) ==conpeek(day(node.attributes().getNamedItem("day").InnerText()),1))
        {
           info('Current :' +node.attributes().getNamedItem("code").InnerText());
        }
       else
        {
            info('Current : NA');
        }
       node = nodes.nextNode();
    }
}
Note:

1) An essential pre-requisite for the code to work is the URL should not be blocked by the firewall.

2)We can directly use this job as an menuitemaction button by adding the job in menuitems under actions, Then add the button in the AddressZipcode form , for that make use of the commented code of AddressZipcode in the above Job.

Here are some example location IDs (do not include the city name) or use the existing Zipcodes of AX
  • Beijing: CHXX0008
  • Helsinki: FIXX0002
  • London: UKXX0085
  • Moscow: RSXX0063
  • Munich: GMXX0087
  • Paris: FRXX0076
  • Riyadh: SAXX0017Tokyo: JAXX0085
For more details on the Yahoo! Weather RSS feed and other location IDs, please visit http://developer.yahoo.com/weather/index.html.
" Don't bother about weather"








Источник: http://DAX-Lessons.spaces.live.com/B...FCD1!146.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Старый 24.04.2008, 23:13   #2  
mazzy is offline
mazzy
Участник
Аватар для mazzy
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
29,472 / 4494 (208) ++++++++++
Регистрация: 29.11.2001
Адрес: Москва
Записей в блоге: 10
Цитата:
Сообщение от Blog bot Посмотреть сообщение
X++:
   container day(str _day)
    {
        ;
       switch(_day)
        {
           case 'Mon' : return [1,'Monday'];
           case 'Tue' : return [2,'Tuesday'];
           case 'Wed' : return [3,'Wednesday'];
           case 'Thu' : return [4,'Thursday'];
           case 'Fri' : return [5,'Friday'];
           case 'Sat' : return [6,'Saturday'];
           case 'Sun' : return [7,'Sunday'];
            Default : return connull();
        }
интересно, с какого языка пришел этот человек на Аксапту, что не пользуется enum'ами? Неужели с Basic?

И вдобавок наверняка американец или англичанин - для него других языков просто не сущесвует Скорее англичанин, раз неделя у него жестко начинается с понедельника

И кто бы объяснил, зачем он в контейнер упаковывает, если потом все равно только номером пользуется?...

И зачем он постоянно лишний вызов через точку делает? node.attributes()
Он надеется на оптимизатор, которого нет?
__________________
полезное на axForum, github, vk, coub.
Старый 25.04.2008, 12:00   #3  
belugin is offline
belugin
Участник
Аватар для belugin
Сотрудники Microsoft Dynamics
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии 2011
Лучший по профессии 2009
 
4,622 / 2925 (107) +++++++++
Регистрация: 16.01.2004
Записей в блоге: 5
Цитата:
Сообщение от mazzy Посмотреть сообщение
интересно, с какого языка пришел этот человек на Аксапту, что не пользуется enum'ами? Неужели с Basic?
Тут вомбще можно было обойтись одним контейнером
X++:
days = ['Mon', 'Tue', ....]
...
conFind(days, _day)
Цитата:

И вдобавок наверняка американец или англичанин - для него других языков просто не сущесвует Скорее англичанин, раз неделя у него жестко начинается с понедельника
это жестко требуется dayofwk
Цитата:
И зачем он постоянно лишний вызов через точку делает? node.attributes()
Он надеется на оптимизатор, которого нет?
Если он точно знает, что есть атрибуты, то может пользоваться XMLElement.getAttribute
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
dax-lessons: Generate XML Documentation Files for a project - DAX 2009 Blog bot DAX Blogs 0 08.08.2008 19:06
dax-lessons: Create Outlook Appointment or Meeting Request using X++ Blog bot DAX Blogs 0 30.04.2008 23:07
dax-lessons: How to write a message to the Event Log Blog bot DAX Blogs 2 04.04.2008 10:18
dax-lessons: Stopping and starting services using x++ Blog bot DAX Blogs 0 31.03.2008 16:05
dax-lessons: Active directory in Axapta Blog bot DAX Blogs 0 27.08.2007 23:00

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 10:46.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.