/// <summary> /// Skapar en CreateHistorical data och sparar ner och strukturerar data i en excelfil /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLaddaNer_Click(object sender, RoutedEventArgs e) { MessageBoxResult result; if (!string.IsNullOrEmpty(txtSymbol.Text) && fromDate.SelectedDate.HasValue && toDate.SelectedDate.HasValue && !string.IsNullOrEmpty(format)) { CreateHistoricalData hd = new CreateHistoricalData(txtSymbol.Text, fromDateStr, toDateStr, format); Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog(); saveFileDialog.DefaultExt = ".xlsx"; saveFileDialog.Filter = "Jespers Excelfil(.xlsx)|*.xlsx"; if (saveFileDialog.ShowDialog() == true) { try { hd.CreateExcel(saveFileDialog.FileName); } catch (WebException) { result = MessageBox.Show("Det finns ingen aktie med denna symbol, använd sökfältet. ", "FEL!", MessageBoxButton.OK, MessageBoxImage.Error); return; } catch (Exception ex) { result = MessageBox.Show("Något gick fel "+ex.ToString(), "FEL!", MessageBoxButton.OK, MessageBoxImage.Error); return; } result = MessageBox.Show("Din fil är sparad "+saveFileDialog.FileName, "Grattis!", MessageBoxButton.OK, MessageBoxImage.Information); } } }
private Uri getApiUri(CreateHistoricalData hdr) { Uri url = new Uri(@"http://ichart.finance.yahoo.com/table.csv?s=" + aktieSymbol + "&a=" + fromMonth + "&b=" + fromDay + "&c=" + fromYear + "&d=" + toMonth + "&e=" + toDay + "&f=" + toYear + "&g=" + dataFormat + "&ignore=.csv"); return url; }