Пример #1
0
        public static void ListViewOrgsOnSelectedChanged()
        {
            ListViewOrgsCource.Clear();
            OrgsItem LItem = (OrgsItem)Orgs.ElementAt(ListViewOrgs.SelectedItem);

            ListViewOrgsCource.SetSource(LItem.Cources);
        }
Пример #2
0
        public static void miCources(OrgsItem AItem)
        {
            Window LWndw = new Window("Курсы валют у " + AItem.Name.PadRight(36));

            LWndw.X                  = 0;
            LWndw.Y                  = 1;
            LWndw.Width              = Dim.Fill();
            LWndw.Height             = Dim.Fill();
            LWndw.ColorScheme.Normal = Application.Driver.MakeAttribute(Color.White, Color.Red);
            ListView LListViewCource = new ListView(
                new Rect()
            {
                X      = 0,
                Y      = 0,
                Height = 56,
                Width  = 156
            },
                AItem.Cources);

            LWndw.Add(LListViewCource);
            Application.Top.Add(LWndw);
            Application.Run();
        }
Пример #3
0
        static void Main(string[] args)
        {
            // I. установление путей в приложении
            // I.1 получаем путь к папке "Мои Документы"
            String LDefaultPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            // I.2 устанавливаем текущим путь "Мои Документы"
            Directory.SetCurrentDirectory(LDefaultPath);
            // I.3 проверяем наличие папки FolderMyApplication
            if (!Directory.Exists(FolderMyApplication))         // если нет
            {
                Directory.CreateDirectory(FolderMyApplication); // создаём эту папку
            }
            // I.4 получаем путь к папке "Мои Документы" \ FolderMyApplication
            LDefaultPath = Path.Combine(LDefaultPath, FolderMyApplication);
            // устанавливаем этот путь текущим для приложения
            Directory.SetCurrentDirectory(LDefaultPath);

            // 12 скачать файл из инетернета
            WebRequest RQ = WebRequest.Create(RemoteURL);

            RQ.Credentials = CredentialCache.DefaultCredentials;
            WebResponse  WR        = RQ.GetResponse();
            Stream       DS        = WR.GetResponseStream();
            StreamWriter fileSaver = new StreamWriter(Path.Combine(LDefaultPath, LocalFile));
            StreamReader reader    = new StreamReader(DS);
            string       Answer    = reader.ReadToEnd();

            fileSaver.Write(Answer);
            fileSaver.Close();            //
            reader.Close();
            WR.Close();
            Console.WriteLine("file was downloded....\n");
            // 13. ОБработка файла
            XmlDocument LXMLDoc = new XmlDocument();

            LXMLDoc.Load(Path.Combine(LDefaultPath, LocalFile));
            XmlElement LRoot = LXMLDoc.DocumentElement;

            List <ReferenceItem> LOrgTypes   = new List <ReferenceItem>();
            List <ReferenceItem> LCurrencies = new List <ReferenceItem>();
            List <ReferenceItem> LRegions    = new List <ReferenceItem>();
            List <ReferenceItem> LCities     = new List <ReferenceItem>();

            // 14. Парсинг справочников
            foreach (XmlNode LNode in LRoot)
            {
                if (LNode.Name.Equals("org_types"))
                {
                    ReferenceFill(LNode, LOrgTypes);
                }
                if (LNode.Name.Equals("currencies"))
                {
                    ReferenceFill(LNode, LCurrencies);
                }
                if (LNode.Name.Equals("regions"))
                {
                    ReferenceFill(LNode, LRegions);
                }
                if (LNode.Name.Equals("cities"))
                {
                    ReferenceFill(LNode, LCities);
                }
            }
            // 15. контрольный вывод
            ReferencePrint("Типы организаций", LOrgTypes, ConsoleColor.Red);
            ReferencePrint("Валюты", LCurrencies, ConsoleColor.Green);
            ReferencePrint("Регионы", LRegions, ConsoleColor.Cyan);
            ReferencePrint("Города", LCities, ConsoleColor.Magenta);

            // создаём списки организаций
            List <OrgsItem> LOrgs = new List <OrgsItem>();

            // 16. грузим курсы валют
            foreach (XmlNode LNodeOrganizations in LRoot)
            {
                if (LNodeOrganizations.Name.Equals("organizations"))
                {
                    // загружаем все дочерние узлы
                    foreach (XmlNode LNodeChild in LNodeOrganizations.ChildNodes)
                    {
                        OrgsItem LOrgItem = new OrgsItem();
                        // проверяем все аттрибуты текущего дочерниего узла
                        foreach (XmlAttribute LAttributesNodeChild in LNodeChild.Attributes)
                        {
                            if (LAttributesNodeChild.Name.Equals("id"))
                            {
                                LOrgItem.Id = LAttributesNodeChild.Value;
                            }
                            if (LAttributesNodeChild.Name.Equals("oldid"))
                            {
                                LOrgItem.OldId = LAttributesNodeChild.Value;
                            }
                            if (LAttributesNodeChild.Name.Equals("org_type"))
                            {
                                LOrgItem.OrgType = ReferenceGet(LOrgTypes, LAttributesNodeChild.Value);
                            }
                        }
                        foreach (XmlNode LNode2Level in LNodeChild.ChildNodes)
                        {
                            if (LNode2Level.Name.Equals("title"))
                            {
                                LOrgItem.Name = LNode2Level.Value;
                            }
                            if (LNode2Level.Name.Equals("address"))
                            {
                                LOrgItem.Address = LNode2Level.Value;
                            }
                            if (LNode2Level.Name.Equals("phone"))
                            {
                                LOrgItem.Phone = LNode2Level.Value;
                            }
                            if (LNode2Level.Name.Equals("city id"))
                            {
                                LOrgItem.City = ReferenceGet(LCities, LNode2Level.Value);
                            }
                            if (LNode2Level.Name.Equals("region id"))
                            {
                                LOrgItem.Region = ReferenceGet(LRegions, LNode2Level.Value);
                            }
                        }
                        LOrgs.Add(LOrgItem);
                    }
                }
            }
            // вывод списка организаций
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("---------------------------------------------");
            foreach (OrgsItem LO in LOrgs)
            {
                Console.WriteLine("  " + LO.Id + "  " + LO.OrgType.Name + " " + LO.Name + " " + LO.Address);
            }


            Console.ReadLine();
        }