private void WebService() { var mnbService = new MNBArfolyamServiceSoapClient(); var request = new GetExchangeRatesRequestBody() { currencyNames = comboBox1.SelectedItem.ToString(), startDate = dateTimePicker1.Value.ToString(), endDate = dateTimePicker2.Value.ToString() }; var response = mnbService.GetExchangeRates(request); result = response.GetExchangeRatesResult; }
private void mnbDownload_Click(object sender, RibbonControlEventArgs e) { //Check MNB service if (_mnbService.State.ToString() != "Created") { _mnbService = new MNBArfolyamServiceSoapClient(); _mnbService.Open(); } //Log to the database LogDatabaseDataSet.LogRow newLogRow = _logDatabaseDataSet.Log.NewLogRow(); newLogRow.Név = Environment.UserName; newLogRow.TimeStamp = DateTime.Now; _logDatabaseDataSet.Log.Rows.Add(newLogRow); _logTableAdapter.Update(_logDatabaseDataSet.Log); //Get currencies xml and map it to its model GetCurrenciesResponseBody currenciesXML = _mnbService.GetCurrencies(new GetCurrenciesRequestBody()); MNBCurrencies currenciesModel = (MNBCurrencies)_operatorService.XmlToModel <MNBCurrencies>(currenciesXML.GetCurrenciesResult); //Exchange rates query config GetExchangeRatesRequestBody getExchangeRatesRequestBody = new GetExchangeRatesRequestBody { startDate = "2015.01.01.", endDate = "2020.04.01.", currencyNames = string.Join(",", currenciesModel.Currencies) }; //Get exchange rates xml and map it to its model GetExchangeRatesResponseBody exchangeRatesXML = _mnbService.GetExchangeRates(getExchangeRatesRequestBody); MNBExchangeRates exchangeRatesModel = (MNBExchangeRates)_operatorService.XmlToModel <MNBExchangeRates>(exchangeRatesXML.GetExchangeRatesResult); //Create datatable from model and import it to Excel then save it DataTable dataTable = _operatorService.ModelToDataTable(exchangeRatesModel, currenciesModel); DataSet dataSet = new DataSet(); dataSet.Tables.Add(dataTable); _operatorService.DataSetToExcel(dataSet); //Format worksheet and save the workbook to the user's documents Excel.Worksheet activeWorksheet = Globals.ThisAddIn.Application.ActiveSheet; activeWorksheet.Range["A2:CV2"].NumberFormatLocal = ""; activeWorksheet.Range["B3:CV10000"].NumberFormatLocal = "0"; activeWorksheet.Range["A3:A10000"].NumberFormatLocal = "éééé\\.hh\\.nn\\."; string savePath = Directory.GetCurrentDirectory() + "\\arfolyam-letoltes.xlsx"; Globals.ThisAddIn.Application.ActiveWorkbook.SaveCopyAs(savePath); _mnbService.Close(); }
public void feladat3() { var mnbService = new MNBArfolyamServiceSoapClient(); var request = new GetExchangeRatesRequestBody() { currencyNames = "EUR", startDate = "2020-01-01", endDate = "2020-06-30" }; var response = mnbService.GetExchangeRates(request); var result = response.GetExchangeRatesResult; }
private string WebService() { var MNBservice = new MNBArfolyamServiceSoapClient(); var request = new GetExchangeRatesRequestBody() { currencyNames = cbCurrency.SelectedItem.ToString(), startDate = dtpFrom.Value.ToString(), endDate = dtpTo.Value.ToString() }; var response = MNBservice.GetExchangeRates(request); var result = response.GetExchangeRatesResult; return(result); }
private void WebServiceCallOutput() { RatesOutput.Clear(); var mnbServiceOutput = new MNBArfolyamServiceSoapClient(); var requestOutput = new GetExchangeRatesRequestBody() { currencyNames = selectedCurrencyOutput, //startDate = DateTime.Today.AddYears(-1).ToString(), //endDate = DateTime.Today.ToString() startDate = dateTimePicker1.Value.AddYears(-1).ToString(), endDate = dateTimePicker1.Value.ToString() }; var responseOutput = mnbServiceOutput.GetExchangeRates(requestOutput); resultOutput = responseOutput.GetExchangeRatesResult; }
private void RefreshData() { Rates.Clear(); var mnbService = new MNBArfolyamServiceSoapClient(); var request = new GetExchangeRatesRequestBody() { currencyNames = comboBox1.SelectedItem.ToString(), startDate = dateTimeStart.Value.ToString(), endDate = dateTimeEnd.Value.ToString() }; var response = mnbService.GetExchangeRates(request); var result = response.GetExchangeRatesResult; newXml(result); dataGridView1.DataSource = Rates; newChart(); }
private void GER() { var mnbService = new MNBArfolyamServiceSoapClient(); foreach (var item in cv) { var request = new GetExchangeRatesRequestBody() { currencyNames = item, startDate = DateTime.Today.AddDays(-29).ToString("yyyy-MM-dd"), endDate = DateTime.Today.ToString("yyyy-MM-dd") }; var response = mnbService.GetExchangeRates(request); var result = response.GetExchangeRatesResult; var xml = new XmlDocument(); xml.LoadXml(result); foreach (XmlElement element in xml.DocumentElement) { var valuta = new Valuta(); Arfolyamok.Add(valuta); valuta.Date = DateTime.Parse(element.GetAttribute("date")); var childElement = (XmlElement)element.ChildNodes[0]; if (childElement == null) { continue; } valuta.Currency = childElement.GetAttribute("curr"); var unit = decimal.Parse(childElement.GetAttribute("unit")); var value = decimal.Parse(childElement.InnerText); if (unit != 0) { valuta.Value = value / unit; } } } }
private void fv() { BindingList <Money> moneydata = new BindingList <Money>(); moneydata.Clear(); dataGridView1.DataSource = moneydata; var valuta = new MNBArfolyamServiceSoapClient(); var inquiry = new GetExchangeRatesRequestBody() { currencyNames = comboBox1.SelectedItem.ToString(), startDate = dateTimePicker1.Value.ToString(), endDate = dateTimePicker2.Value.ToString() }; var feedback = valuta.GetExchangeRates(inquiry); var end = feedback.GetExchangeRatesResult; var xml = new XmlDocument(); xml.LoadXml(end); foreach (XmlElement item in xml.DocumentElement) { var money = new Money(); moneydata.Add(money); money.Date = DateTime.Parse(item.GetAttribute("date")); var childElement = (XmlElement)item.ChildNodes[0]; money.Currency = childElement.GetAttribute("curr"); var unit = decimal.Parse(childElement.GetAttribute("unit")); var value = decimal.Parse(childElement.InnerText); if (unit != 0) { money.Value = value / unit; } } }
private void RefreshData() { Rates.Clear(); var mnbService = new MNBArfolyamServiceSoapClient(); var request = new GetExchangeRatesRequestBody() { currencyNames = (comboBox1.SelectedItem).ToString(), startDate = (dateTimePicker1.Value).ToString(), endDate = (dateTimePicker2.Value).ToString() }; var response = mnbService.GetExchangeRates(request); var result = response.GetExchangeRatesResult; var xml = new XmlDocument(); xml.LoadXml(result); foreach (XmlElement element in xml.DocumentElement) { var rate = new RateData(); Rates.Add(rate); rate.Date = DateTime.Parse(element.GetAttribute("date")); var childElement = (XmlElement)element.ChildNodes[0]; rate.Currency = childElement.GetAttribute("curr"); var unit = decimal.Parse(childElement.GetAttribute("unit")); var value = decimal.Parse(childElement.InnerText); if (unit != 0) { rate.Value = value / unit; } } //comboBox1.DataSource = Currencies; dataGridView1.DataSource = Rates; }
private void CreateWebService() { var webService = new MNBArfolyamServiceSoapClient(); //MNBArfolyamServiceSoapClient osztály példányosítása var beertek = new GetExchangeRatesRequestBody() { currencyNames = "DKK", startDate = "2019-12-31", endDate = "2020-12-31" }; var visszaertek = webService.GetExchangeRates(beertek); var vegertek = visszaertek.GetExchangeRatesResult; //vegertek string!!! var xml = new XmlDocument(); xml.LoadXml(vegertek); foreach (XmlElement element in xml.DocumentElement) { var jelenarfolyam = new Arfolyam(); Arfolyamok.Add(jelenarfolyam); jelenarfolyam.dátum = DateTime.Parse(element.GetAttribute("date")); var childElement = (XmlElement)element.ChildNodes[0]; jelenarfolyam.valuta = childElement.GetAttribute("curr"); var unit = decimal.Parse(childElement.GetAttribute("unit")); var value = decimal.Parse(childElement.InnerText); if (unit != 0) { jelenarfolyam.érték = value / unit; } { } } }
/// <summary> /// Query the MNB Client to retrieve Exchange rates for given currencies /// </summary> /// <param name="start">DateTime: The start date to be used in the query</param> /// <param name="end">DateTime: The end date to be used in the query</param> /// <param name="currencyNames">IList<string>: The names of the currencies to be used in the query</param> private void GetAndProcessExchangeRates(DateTime start, DateTime end, IList <string> currencyNames) { try { string startDate = start.ToString(DATE_REQUEST_FORMAT); string endDate = end.ToString(DATE_REQUEST_FORMAT); var currencies = string.Join(",", currencyNames); GetExchangeRatesRequestBody requestBody = new GetExchangeRatesRequestBody() { startDate = startDate, endDate = endDate, currencyNames = currencies }; GetExchangeRatesResponseBody exchangeRatesResponseBody = client.GetExchangeRates(requestBody); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(exchangeRatesResponseBody.GetExchangeRatesResult); XmlNodeList rawNodes = xmlDoc.SelectNodes(MNB_EXCHANGE_RATES_PER_DAY); foreach (XmlNode rawNode in rawNodes) { // Retrieve the day of the FX rate and store it in variable: date XmlNode rawDate = rawNode.Attributes.GetNamedItem(MNB_DATE_ATTRIBUTE_NAME); DateTime.TryParse(rawDate.Value, out DateTime date); // check if date is not included var dateIsAlreadyAdded = CurrencySnapshotDate.Any(item => item.Date == date); if (!dateIsAlreadyAdded) { var newFxDate = new FxDateWrapper() { Date = date, }; CurrencySnapshotDate.Add(newFxDate); } // Iterate through child nodes and retrieve the unit and curr from attributes - and fx rate from innerText foreach (XmlNode currencyRate in rawNode.ChildNodes) { // Find currency by name XmlNode currAttrib = currencyRate.Attributes.GetNamedItem(MNB_CURRENCY_ATTRIBUTE_NAME); var currencyWrapper = CurrenciesRetrieved.FirstOrDefault(currName => currName.CurrencyName.Equals(currAttrib.Value, StringComparison.InvariantCultureIgnoreCase)); if (currencyWrapper is null) { continue; } // feed currency unit to currencyWrapper XmlNode unitAttrib = currencyRate.Attributes.GetNamedItem(MNB_UNIT_ATTRIBUTE_NAME); if (Int32.TryParse(unitAttrib.Value, out int result)) { currencyWrapper.RateUnit = result; } // Feed rate into currencyWrapper currencyWrapper.CurrencyRates.Add(new Currency() { Date = date, RawRate = currencyRate.InnerText }); } } } catch (Exception e) { string error = e.Message; ShowErrorMessage(error); } }
private void FillDataToExcel(Excel.Worksheet sheet, MNBArfolyamServiceSoapClient soapClient) //Fill excel worksheet { GetCurrenciesRequestBody getCurrenciesBody = new GetCurrenciesRequestBody(); GetExchangeRatesRequestBody getRatesBody = new GetExchangeRatesRequestBody(); var range = sheet.get_Range("A1", "A1"); var currencies = soapClient.GetCurrencies(getCurrenciesBody); int DayID = 0, countRates = 0; string xmlResult = currencies.GetCurrenciesResult; DataTable table = XmlToDataTable(xmlResult, 1); DataTable dataRates = new DataTable(); DataTable dataDays = new DataTable(); List <string> currenciesList = new List <string>(); ((Excel.Range)range.Cells[1, 1]).Value = "Dátum/ISO"; ((Excel.Range)range.Cells[2, 1]).Value = "Egység"; //Fill and get all currencies// int columnIndex = 2; foreach (DataRow items in table.Rows) { ((Excel.Range)range.Cells[1, columnIndex]).Value = items[0]; currenciesList.Add(items[0].ToString()); columnIndex++; } ////////////////////////////// //Fill days// var exchRates = soapClient.GetExchangeRates(getRatesBody); xmlResult = exchRates.GetExchangeRatesResult; table = XmlToDataTable(xmlResult, 0); columnIndex = 3; foreach (DataRow item in table.Rows) { ((Excel.Range)range.Cells[columnIndex, 1]).Value2 = item[0]; columnIndex++; } ///////////// //Fill Rates// getRatesBody = new GetExchangeRatesRequestBody(); dataRates = new DataTable(); dataDays = new DataTable(); for (int k = 0; k < currenciesList.Count; k++)//Loop all currencies and fill rates value { //if (k > 2) break; Set how many item will appaer range.Cells[1, k + 2].Select(); DayID = 0; countRates = 0; columnIndex = 3; getRatesBody.currencyNames = currenciesList[k]; exchRates = soapClient.GetExchangeRates(getRatesBody); xmlResult = exchRates.GetExchangeRatesResult; dataRates = XmlToDataTable(xmlResult, 1); dataDays = XmlToDataTable(xmlResult, 0); if (dataRates != null) { ((Excel.Range)range.Cells[2, k + 2]).Value = dataRates.Rows[countRates][0]; //Fill unit while (countRates < dataRates.Rows.Count) { if (dataRates.Rows[countRates][3].ToString() == dataDays.Rows[DayID][0].ToString()) //Date ID check { ((Excel.Range)range.Cells[columnIndex, k + 2]).Value = dataRates.Rows[countRates][2].ToString().Replace(",", "."); //Change string format columnIndex++; DayID++; countRates++; } else { columnIndex++; DayID++; } } } } }
private void GetExchangeRates() { var mnbService = new MNBArfolyamServiceSoapClient(); var request = new GetExchangeRatesRequestBody() { currencyNames = comboBox1.SelectedItem.ToString(), startDate = dateTimePicker1.Value.ToString(), endDate = dateTimePicker2.Value.ToString() }; var response = mnbService.GetExchangeRates(request); var result = response.GetExchangeRatesResult; var xml = new XmlDocument(); xml.LoadXml(result); foreach (XmlElement element in xml.DocumentElement) { // Létrehozzuk az adatsort és rögtön hozzáadjuk a listához // Mivel ez egy referencia típusú változó, megtehetjük, hogy előbb adjuk a listához és csak később töltjük fel a tulajdonságait var rate = new RateData(); Rates.Add(rate); // Dátum rate.Date = DateTime.Parse(element.GetAttribute("date")); // Valuta var childElement = (XmlElement)element.ChildNodes[0]; if (childElement == null) { continue; } rate.Currency = childElement.GetAttribute("curr"); // Érték var unit = decimal.Parse(childElement.GetAttribute("unit")); var value = decimal.Parse(childElement.InnerText); if (unit != 0) { rate.Value = value / unit; } } var series = chartRateData.Series[0]; series.ChartType = SeriesChartType.Line; series.XValueMember = "Date"; series.YValueMembers = "Value"; series.BorderWidth = 2; var legend = chartRateData.Legends[0]; legend.Enabled = false; var chartArea = chartRateData.ChartAreas[0]; chartArea.AxisX.MajorGrid.Enabled = false; chartArea.AxisY.MajorGrid.Enabled = false; chartArea.AxisY.IsStartedFromZero = false; }