public override void WebData() { // If required by the server, set the credentials. WebRequest DataRequest = WebRequest.Create("https://www.eobot.com/api.aspx?supportedcoins=true¤cy=USD"); DataRequest.Credentials = CredentialCache.DefaultCredentials; // Get the response. WebResponse DataResponse = DataRequest.GetResponse(); // Display the status. //Console.WriteLine(((HttpWebResponse)DataResponse).StatusDescription); // Get the stream containing content returned by the server. Stream dataStream = DataResponse.GetResponseStream(); // Open the stream using a StreamReader for easy access. try { StreamReader WebAnswerReader = new StreamReader(dataStream); // Read the content. ResponseFromServer = WebAnswerReader.ReadToEnd(); WebAnswerReader.Close(); DataResponse.Close(); } catch (Exception except) { MessageBox.Show(except.ToString()); return; } string data1 = ResponseFromServer; if (string.IsNullOrEmpty(data1)) { return; } var strValues = ResponseFromServer.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); //розделение строки на блоки с инфой валюты if (strValues.Count == 0) { return; } IdxOfPrice = strValues[0].IndexOf("Price:"); // начало сплита string strPrice = strValues[0].Substring(IdxOfPrice + "Price:".Length); //выделение цены сплитом из стороки //--------------------------------------заполнение списка данными--------------------------------- var obs = new Observation(); obs.price = StrToDouble(strPrice); obs.TimeDiff = DateTime.Now.TimeOfDay; //CurrentData = GetDouble(ResponseFromServer, double.MinValue); observs.Add(obs); //--------------------------------------запись в бд скюл --------------------------------- SqlConnection Connect = new SqlConnection(Properties.Settings.Default.SQLConnectionString); try { Connect.Open(); SqlCommand command = new SqlCommand(Connect.ConnectionString, Connect); //command.Parameters["@ObsDate"].Value = DateTime.Now.TimeOfDay; //command.Parameters["@Price"].Value = obs.price; command.Parameters.AddWithValue("@ObsDate", DateTime.Now); command.Parameters.AddWithValue("@Price", obs.price); command.CommandText = @"INSERT INTO Observations (ObsDate, Price) VALUES (@ObsDate, @Price)"; command.ExecuteNonQuery(); } catch (Exception except) { MessageBox.Show(except.ToString()); } finally { Connect.Close(); } //--------------------------------------запись в бд скюл --------------------------------- }
public virtual void AddObservation(Observation obs) { observs.Add(obs); }