Formal control if field urlHistory is empty was introduced. If it is empty warning pop up and execution go to label end1:. Probably, much simpler solution is possible to stop execution but I'm not aware of it. Any idea? Also, if download finished regularly then make BackColor of urlHistory field LightGreen.
private void getHistory_Click(object sender, EventArgs e)
{
if (urlHistory.Text=="") // is url entered?
{MessageBox.Show("URL field is empty.", "No infomation"); // url is not enetred
goto end1;} // no action. goto end WebRequest req = WebRequest.Create(urlHistory.Text); // to use WebRequest we need to add "using System.Net;" row
req.Proxy = null; // i do not use proxy
string selectedIndices = listIndices.SelectedItem.ToString(); // get selected indice
selectedIndices=selectedIndices.Replace(":", "-"); // file name can not contain ":"
selectedIndices = workingPath + selectedIndices + ".txt"; // make full path,file name and add .txt extension as it is text file
using (WebResponse res = req.GetResponse()) // get response from internet
using (Stream s = res.GetResponseStream()) // make a stream
using (StreamReader sr = new StreamReader(s)) File.WriteAllText(selectedIndices, sr.ReadToEnd()); // save stream to file
urlHistory.BackColor = Color.LightGreen; // if file was created make BackColor LightGreen
// System.Diagnostics.Process.Start(selectedIndices); // remove comment and result can be seen in text editor
end1: ;
}
Accordingly, we have to reset color to White when new indice is chosen.
private void listIndices_SelectedIndexChanged(object sender, EventArgs e)
{
string part1bloom = "http://www.internet.com/apps/data?pid=webpxta&Securities="; // first part of internet url histroy string
string part2bloom = "&TimePeriod=5Y&Outfields=HDATE,PR006-H,PR007-H,PR008-H,PR005-H,PR013-H,&rnd=421"; // second part of internet url histroy string
urlHistory.Text = part1bloom + listIndices.SelectedItem.ToString()+ part2bloom; // construct whole url string
historyTable.Clear();
Int16 j = Convert.ToInt16( fillHistoryTableDays.Text); // convert textbox text to int16
fillHistoryT(j); // getting data from local disk // invoke table filling
urlHistory.BackColor = Color.White;
}
No comments:
Post a Comment