Example #1
0
        async Task <Worksheet> GenerateWorkSheetAsync(string charCode, CBRXMLParser data)
        {
            Worksheet ws = new Worksheet(charCode);

            ws.Cells[0, 0] = new Cell("КОД");
            ws.Cells[0, 1] = new Cell("Наименование");
            ws.Cells[0, 2] = new Cell("Номинал");
            ws.Cells[0, 3] = new Cell("Стоимость");
            return(await Task <Worksheet> .Run(() =>
            {
                int i = 1;
                CBRRate rur = data.Rates.Where(c => c.CharCode == charCode).FirstOrDefault();
                if (rur != null)
                {
                    ws.Cells[i, 0] = new Cell("RUR");
                    ws.Cells[i, 1] = new Cell("Российский Рубль");
                    ws.Cells[i, 2] = new Cell(rur.Nominal);
                    ws.Cells[i, 3] = new Cell(1 / rur.Value);
                    i++;
                }
                foreach (CBRRate rate in data.Rates)
                {
                    if (rate.CharCode == charCode)
                    {
                        continue;
                    }
                    ws.Cells[i, 0] = new Cell(rate.CharCode);
                    ws.Cells[i, 1] = new Cell(rate.Name);
                    ws.Cells[i, 2] = new Cell(rate.Nominal);
                    ws.Cells[i, 3] = new Cell((charCode == "RUR") ?  rate.Value : rur.Value / rate.Value);
                    i++;
                }
                return ws;
            }));
        }
Example #2
0
 public void GetQuotes()
 {
     if (_request == null)
     {
         _request = new CBRWebData(_date);
     }
     if (_parser == null)
     {
         _parser = new CBRXMLParser();
     }
     _request.onError += onBankQoutes;
     _parser.onError  += onBankQoutes;
     _request.GetData();
     _parser.ParseXML(CBRXMLTypes.Currency, _request.CurrencyData);
     _parser.ParseXML(CBRXMLTypes.Rate, _request.RateData);
     UpdateDB();
     GenerateExcelFile();
 }
Example #3
0
        public void GenerateExcelFile(CBRXMLParser data)
        {
            Task <Worksheet>[] task = new Task <Worksheet> [data.Rates.Count + 1];
            List <Worksheet>   list = new List <Worksheet>();
            int i = 0;

            task[i] = GenerateWorkSheetAsync("RUR", data);
            if (data.Rates == null | data.Rates.Count() == 0)
            {
                return;
            }
            foreach (CBRRate rate in data.Rates)
            {
                i++;
                task[i] = GenerateWorkSheetAsync(rate.CharCode, data);
            }
            Task.WaitAll(task);
            foreach (var item in task)
            {
                list.Add(item.Result);
            }

            SaveFile(list);
        }