Esempio n. 1
0
 private void chooseToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
     {
         try
         {
             if (openFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 MainClass.filePathAndName = openFileDialog1.FileName;
                 using (FileStream fs = new FileStream(MainClass.filePathAndName, FileMode.Open))
                 {
                     MainClass.DataBytes = new byte[fs.Length];
                     fs.Read(MainClass.DataBytes, 0, MainClass.DataBytes.Length);
                 }
                 this.Text = "View File: " + MainClass.filePathAndName;
                 statusStrip1.Items[0].Text = "Read " +
                                              MainClass.DataBytes.Length.ToString() +
                                              " bytes from: " +
                                              MainClass.filePathAndName;
                 resetTabPages();
             }
         }
         catch (Exception er)
         {
             MainClass.ShowError(er);
         }
     }//from using wait cursor
 }
Esempio n. 2
0
 private void buttonSaveSettings_Click(object sender, EventArgs e)
 {
     using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
     {
         try
         {
             if (saveFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 char          delimiter = '|';
                 StringBuilder sb        = new StringBuilder();
                 sb.Append(textBoxServer.Text.Trim());
                 sb.Append(delimiter);
                 sb.Append(textBoxDatabase.Text.Trim());
                 sb.Append(delimiter);
                 sb.Append(textBoxLogin.Text);
                 sb.Append(delimiter);
                 sb.Append(textBoxPassword.Text);
                 sb.Append(delimiter);
                 sb.Append(textBoxSqlQuery.Text);
                 using (StreamWriter sw = new StreamWriter(saveFileDialog1.FileName))
                 {
                     sw.Write(sb.ToString());
                     sw.Flush();
                 }
             }//from if ok to save
         }
         catch (Exception er)
         {
             MainClass.ShowError(er);
         }
     }
 }
        /// <summary>
        /// load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SettingsForm_Load(object sender, EventArgs e)
        {
            using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
            {
                try
                {
                    _ignoreChangeEvents = true;
                    //listBoxTypeOfData.Items.Add("Hopkins_World");
                    //listBoxTypeOfData.Items.Add("Hopkins_US");

                    //for(int i=0; i<listBoxTypeOfData.Items.Count; i++)
                    //{
                    //    if(listBoxTypeOfData.Items[i].ToString().Trim() ==
                    //        MainClass.TypeOfData.Trim())
                    //    {
                    //        listBoxTypeOfData.SelectedIndex = i;
                    //    }
                    //}
                }
                catch (Exception er)
                {
                    Wve.MyEr.Show(this, er, true);
                }
                finally
                {
                    _ignoreChangeEvents = false;
                }
            }
        }
 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
     {
         try
         {
             Process.Start("https://eastridges.com/covid19");
         }
         catch (Exception er)
         {
             Wve.MyEr.Show(this, er, true);
         }
     }
 }
Esempio n. 5
0
 private void buttonOK_Click(object sender, EventArgs e)
 {
     using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
     {
         try
         {
             SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder();
             scsb.DataSource     = textBoxServer.Text.Trim();
             scsb.InitialCatalog = textBoxDatabase.Text.Trim();
             scsb.UserID         = textBoxLogin.Text.Trim();
             scsb.Password       = textBoxPassword.Text.Trim();
             using (SqlConnection cn = new SqlConnection())
             {
                 cn.ConnectionString = scsb.ToString();
                 SqlCommand cmd = new SqlCommand(textBoxSqlQuery.Text.Trim(), cn);
                 cn.Open();
                 object o = cmd.ExecuteScalar();
                 if ((o != null) && (o != DBNull.Value))
                 {
                     if (o is byte[])
                     {
                         ResultBytes       = (Byte[])o;
                         this.DialogResult = DialogResult.OK;
                     }
                     else if (o is String)
                     {
                         ResultBytes       = UnicodeEncoding.Unicode.GetBytes((string)o);
                         this.DialogResult = DialogResult.OK;
                     }
                     else
                     {
                         throw new Exception("Don't know how to read this data.  Only know byte[] and string.");
                     }
                 }
                 else
                 {
                     MessageBox.Show("Sorry, got null result.");
                 }
             }
         }
         catch (Exception er)
         {
             MainClass.ShowError(er);
         }
     }
 }
Esempio n. 6
0
 private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
     {
         try
         {
             if (saveFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 File.WriteAllBytes(saveFileDialog1.FileName, MainClass.DataBytes);
             }
         }
         catch (Exception er)
         {
             MainClass.ShowError(er);
         }
     }
 }
 private void listBoxTypeOfData_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
     {
         try
         {
             //if ((!_ignoreChangeEvents) && (listBoxTypeOfData.SelectedItem != null))
             //{
             //    MainClass.TypeOfData = listBoxTypeOfData.SelectedItem.ToString();
             //    //reload main form
             //    //Form1.ReloadForm1(sender, e);
             //}
         }
         catch (Exception er)
         {
             Wve.MyEr.Show(this, er, true);
         }
     }
 }
Esempio n. 8
0
 private void SingleGraph_FormClosing(object sender, FormClosingEventArgs e)
 {
     using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
     {
         try
         {
             ////sorry, but we can't allow chart to be closed because for some unknown
             //// reason, whenever the form is closed, any subsequent drawing of the
             //// same chart causes an Internal List error within DataVisualization...
             //MessageBox.Show("Chart will close when the main program is closed, " +
             //    "but can hide the box now." );
             this.WindowState = FormWindowState.Minimized;
             e.Cancel         = true;
         }
         catch (Exception er)
         {
             Wve.MyEr.Show(this, er, true);
         }
     }
 }
Esempio n. 9
0
 private void toolStripMenuItemReadDatabase_Click(object sender, EventArgs e)
 {
     using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
     {
         try
         {
             ReadDatabaseForm dlg = new ReadDatabaseForm();
             if (dlg.ShowDialog() == DialogResult.OK)
             {
                 MainClass.filePathAndName = "DATABASE:" + dlg.textBoxServer.Text + "::" + dlg.textBoxDatabase.Text;
                 this.Text = "View Data from " + MainClass.filePathAndName;
                 this.statusStrip1.Items[0].Text = "Read Data from " + MainClass.filePathAndName;
                 MainClass.DataBytes             = dlg.ResultBytes;
                 resetTabPages();
             }
         }
         catch (Exception er)
         {
             MainClass.ShowError(er);
         }
     }
 }
Esempio n. 10
0
 private void SingleGraph_Load(object sender, EventArgs e)
 {
     using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
     {
         try
         {
             labelTitle.Text = _title;
             chart1.Series.Clear();
             for (int i = 0; i < _chartToView.Series.Count; i++)
             {
                 chart1.Series.Add(_chartToView.Series[i]);
             }
             //chart1.Update();
             chart1.Show();
             //chart1.ChartAreas[0].RecalculateAxesScale();
         }
         catch (Exception er)
         {
             Wve.MyEr.Show(this, er, true);
         }
     }
 }
Esempio n. 11
0
 private void buttonLoadSettings_Click(object sender, EventArgs e)
 {
     using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
     {
         try
         {
             if (openFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 if (File.Exists(openFileDialog1.FileName))
                 {
                     using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
                     {
                         char     delimiter = '|';
                         string   s         = sr.ReadToEnd();
                         string[] ss        = s.Split(delimiter);
                         if (ss.Length > 4)
                         {
                             textBoxServer.Text   = ss[0];
                             textBoxDatabase.Text = ss[1];
                             textBoxLogin.Text    = ss[2];
                             textBoxPassword.Text = ss[3];
                             textBoxSqlQuery.Text = ss[4];
                         }
                         else
                         {
                             MessageBox.Show("unrecognized format for file " +
                                             openFileDialog1.FileName);
                         }
                     } //from using streamreader
                 }     //from if file exists
             }         //from if ok to open file
         }
         catch (Exception er)
         {
             MainClass.ShowError(er);
         }
     }
 }
        internal void buttonDownload_Click(object sender, EventArgs e)
        {
            using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
            {
                try
                {
                    //get data
                    string url                  = string.Empty;
                    string outputFileName       = string.Empty;
                    string urlDeaths            = string.Empty;
                    string outputDeathsFileName = string.Empty;
                    //load countries, then counties
                    for (int i = 0; i < 2; i++)
                    {
                        if (i == 0)
                        {
                            url                  = MainClass.DataUrlForCountries;
                            outputFileName       = MainClass.DataFileNameforCountries;
                            urlDeaths            = MainClass.DataUrlForCountriesDeaths;
                            outputDeathsFileName = MainClass.DataFileNameForCountriesDeaths;
                        }
                        else if (i == 1)
                        {
                            url                  = MainClass.DataUrlForStates;
                            outputFileName       = MainClass.DataFileNameForStates;
                            urlDeaths            = MainClass.DataUrlForStatesDeaths;
                            outputDeathsFileName = MainClass.DataFileNameForStatesDeaths;
                        }

                        string dataRaw       = MainClass.SendRequest("GET", "", null, url);
                        string dataRawDeaths = MainClass.SendRequest("GET", "", null, urlDeaths);
                        //write to files
                        DirectoryInfo di = new DirectoryInfo(@"c:\covid19");
                        if (!di.Exists)
                        {
                            di.Create();
                        }
                        //rename old data if exists
                        FileInfo fi = new FileInfo(outputFileName);
                        if (fi.Exists)
                        {
                            if (File.Exists(outputFileName + ".old"))
                            {
                                File.Delete(outputFileName + ".old");
                            }
                            fi.MoveTo(outputFileName + ".old");
                        }
                        fi = new FileInfo(outputDeathsFileName);
                        if (fi.Exists)
                        {
                            if (File.Exists(outputDeathsFileName + ".old"))
                            {
                                File.Delete(outputDeathsFileName + ".old");
                            }
                            fi.MoveTo(outputDeathsFileName + ".old");
                        }
                        //write to files
                        using (StreamWriter sw = new StreamWriter(outputFileName,
                                                                  false)) //false to append
                        {
                            sw.Write(dataRaw);
                            sw.Flush();
                        }
                        using (StreamWriter sw = new StreamWriter(outputDeathsFileName,
                                                                  false)) //false to append
                        {
                            sw.Write(dataRawDeaths);
                            sw.Flush();
                        }
                        StringBuilder sbLog = new StringBuilder();
                        sbLog.Append("Downloaded ");
                        sbLog.Append(outputFileName);
                        sbLog.Append(" and ");
                        sbLog.Append(outputDeathsFileName);
                        sbLog.Append("\r\n\r\n");
                        this.Log = this.Log + sbLog.ToString();
                        //MessageBox.Show("Downloaded " + outputFileName + " and " + outputDeathsFileName);
                    }//for i
                     //close form
                    buttonClose_Click(sender, e);
                }
                catch (Exception er)
                {
                    Wve.MyEr.Show(this, er, true);
                }
            }//using
        }
Esempio n. 13
0
        private void AboutForm_Load(object sender, EventArgs e)
        {
            using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
            {
                try
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("To calculate and display the doubling rate of Covid-19 cases in the U.S. as a function of time \r\n" +

                              "Data comes from Johns Hopkins Coronavirus COVID - 19 Global Cases by the Center for Systems Science and Engineering(CSSE) at Johns Hopkins University(JHU) \r\n" +
                              "  https://www.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6 \r\n" +
                              "and in particular, from their daily updated dataset at github \r\n " +
                              " https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_time_series \r\n");
                    // was "  https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data \r\n");

                    //sb.Append(Environment.NewLine);
                    sb.Append(Environment.NewLine);
                    sb.Append(" The global data is saved in your computer with the name \r\n");
                    sb.Append(MainClass.DataFileNameforCountries);
                    sb.Append(". ");

                    sb.Append("\r\n\r\n");
                    sb.Append("This is a work in progress.  Please send errors or questions to [email protected]   \r\nI mainly wanted to see the doubling time, ");
                    sb.Append("that is, the number of days it took to reach the cases total from half the total.");
                    sb.Append("\r\nAlso interesting is the spread rate, i.e. the number of people each case spreads to.  ");
                    sb.Append("  I just took the median incubation ");
                    sb.Append("period of 5 days and divided each daily new cases by the new cases 5 days prior.  ");
                    sb.Append("\r\nThe similar graph below it shows the same entities (doubling rate, effective reproductive rate),  ");
                    sb.Append("but calculated from the slope of the log curve the prior 5 days, so is more accurate ");
                    sb.Append("during exponential growth, and also less prone to aberrencies from day to day variability.  ");
                    sb.Append("\r\nThe hope is, if we can keep that spread rate below 1, the infection dies out. ");
                    sb.Append("\r\n\r\nThe data calculated in comma separated value format is saved to disk in the same folder as the downloaded data.");

                    sb.Append(Environment.NewLine);
                    sb.Append(Environment.NewLine);
                    sb.Append("Source code is at GitHub at \r\n");
                    sb.Append("https://github.com/weastridge/Covid19DoublingTime.git");

                    sb.Append("\r\n\r\[email protected]");

                    textBoxDisplay.Text = sb.ToString();
                    //Wve.TextViewer.ShowText("About this program...", sb.ToString());

                    //show assembly version
                    Assembly      asm       = Assembly.GetAssembly(this.GetType());
                    StringBuilder sbVersion = new StringBuilder();
                    sbVersion.Append("Version: ");
                    sbVersion.Append(System.Reflection.Assembly.GetEntryAssembly()
                                     .GetName().Version.ToString());
                    //sbVersion.Append("  Release:1   (mm3 ");
                    //sbVersion.Append(asm.GetName().Version.ToString());
                    //sbVersion.Append(")");
                    labelVersion.Text = sbVersion.ToString();

                    //show build date if version format supports it
                    //  (i.e. build and revision numbers indicate date and time)
                    StringBuilder sbBuild   = new StringBuilder();
                    DateTime      buildDate = DateTime.Parse("2000/01/01").AddDays(
                        asm.GetName().Version.Build);
                    DateTime buildTime = DateTime.Today.AddSeconds(
                        asm.GetName().Version.Revision * 2);
                    if ((asm.GetName().Version.Build != 0) &&
                        (buildDate < DateTime.Parse("2100/01/01")))
                    {
                        sbBuild.Append("Built on ");
                        sbBuild.Append(buildDate.ToLongDateString());
                        sbBuild.Append(" at ");
                        sbBuild.Append(buildTime.ToShortTimeString());
                        sbBuild.Append(" Standard Time");
                    } // testin subversion -chris
                    else
                    {
                        //unreasonable build date, so don't show it
                    }
                    labelBuildDate.Text = sbBuild.ToString();
                    //take focus away from textbox
                    textBoxDisplay.SelectionStart  = 0;
                    textBoxDisplay.SelectionLength = 0;
                    buttonOK.Focus();
                }
                catch (Exception er)
                {
                    Wve.MyEr.Show(this, er, true);
                }
            }
        }
Esempio n. 14
0
 private void buttonFind_Click(object sender, EventArgs e)
 {
     using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
     {
         try
         {
             //if text
             if (tabControl1.SelectedTab == tabPageText)
             {
                 //start with beginning if no text is selected or
                 // with next character if some already selected
                 int startPoint = textBoxText.SelectionLength == 0 ?
                                  0 : textBoxText.SelectionStart + 1;
                 if (textBoxText.Text.IndexOf(textBoxFind.Text,
                                              startPoint) > -1)
                 {
                     textBoxText.Select(textBoxText.Text.IndexOf(textBoxFind.Text,
                                                                 startPoint), textBoxFind.Text.Length);
                     textBoxText.ScrollToCaret();
                 }
                 else
                 {
                     MessageBox.Show("Reached end of text.");
                     //reset to beginning in case want to search from top again
                     if (textBoxText.Text.Length > 0)
                     {
                         textBoxText.Select(0, 0);
                         textBoxText.ScrollToCaret();
                     }
                 }
             }//from if tabPageText
             //if hex
             else if (tabControl1.SelectedTab == tabPageHex)
             {
                 //start with beginning if no text is selected or
                 // with next character if some already selected
                 int startPoint = textBoxHex.SelectionLength == 0 ?
                                  0 : textBoxHex.SelectionStart + 1;
                 if (textBoxHex.Text.ToUpper().IndexOf(textBoxFind.Text.ToUpper(),
                                                       startPoint) > -1)
                 {
                     textBoxHex.Select(textBoxHex.Text.ToUpper().IndexOf(textBoxFind.Text.ToUpper(),
                                                                         startPoint), textBoxFind.Text.Length);
                     textBoxHex.ScrollToCaret();
                 }
                 else
                 {
                     MessageBox.Show("Reached end of text.");
                     //reset to beginning in case want to search from top again
                     if (textBoxText.Text.Length > 0)
                     {
                         textBoxText.Select(0, 0);
                         textBoxText.ScrollToCaret();
                     }
                 }
             }//from if hex
         }
         catch (Exception er)
         {
             MainClass.ShowError(er);
         }
     }
 }
Esempio n. 15
0
        /// <summary>
        /// load current file into currently active tab page
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonLoad_Click(object sender, EventArgs e)
        {
            using (Wve.HourglassCursor waitCursor = new Wve.HourglassCursor())
            {
                try
                {
                    if (checkBoxLoadToMemory.Checked) //if data is loaded in memory
                    {
                        if (MainClass.DataBytes == null)
                        {
                            MessageBox.Show("Please choose file to load.");
                        }
                        else
                        {
                            if (tabControl1.SelectedTab == tabPageHex)
                            {
                                textBoxHex.Clear();
                                string s = Wve.WveTools.BytesToHex(MainClass.DataBytes, " ");
                                textBoxHex.Text = s;
                            }//from if hex page
                            else if (tabControl1.SelectedTab == tabPageText)
                            {
                                //first, if there are any 0x0 end of file bytes in the data, we
                                // will replace them with the @ char so reading the file not truncated
                                byte[] dataBytesModified = (byte[])MainClass.DataBytes.Clone();
                                for (int i = 0; i < dataBytesModified.Length; i++)
                                {
                                    if (dataBytesModified[i] == 0)
                                    {
                                        dataBytesModified[i] = 7; //bell character
                                    }
                                }
                                using (MemoryStream ms = new MemoryStream(dataBytesModified))
                                {
                                    Encoding enc = ((_encodingType)(comboBoxEncoding.SelectedItem)).encodingType;
                                    if (enc == null)
                                    {
                                        using (StreamReader sr = new StreamReader(ms))
                                        {
                                            textBoxText.Text = sr.ReadToEnd();
                                        }
                                    }//from if enc null
                                    else
                                    {
                                        using (StreamReader sr = new StreamReader(ms, enc))
                                        {
                                            textBoxText.Text = sr.ReadToEnd();
                                        }
                                    }
                                } //from using memory stream
                            }     //from if text page

                            //show details
                            statusStrip1.Items[0].Text = MainClass.filePathAndName +
                                                         "   length: " + MainClass.DataBytes.Length;
                        } //from if data exists
                    }     //from if reading data from memory
                    else
                    {
                        //here we would read pages of data from large data file, such
                        // as when too large to load to memory
                    }
                }
                catch (Exception er)
                {
                    MainClass.ShowError(er);
                }
            }//from using wait cursor
        }