Exemplo n.º 1
0
        public dlgRecord(clsWeatherData oRecord, ListViewItem lviRecord)
        {
            InitializeComponent();

            // save these
            //
            g_oRecord   = oRecord;
            g_lviRecord = lviRecord;

            // use date/time as form label
            //
            this.Text = lviRecord.SubItems[0].Text;

            // Init text boxes
            //
            tb_TempOut.Text   = lviRecord.SubItems[1].Text;
            tb_TempIn.Text    = lviRecord.SubItems[2].Text;
            tb_HumOut.Text    = lviRecord.SubItems[3].Text;
            tb_HumIn.Text     = lviRecord.SubItems[4].Text;
            tb_Barometer.Text = lviRecord.SubItems[5].Text;
            tb_Rain.Text      = lviRecord.SubItems[6].Text;
            tb_RainRate.Text  = lviRecord.SubItems[7].Text;
            tb_Wind.Text      = lviRecord.SubItems[8].Text;
            tb_WindDir.Text   = lviRecord.SubItems[9].Text;
            tb_Gust.Text      = lviRecord.SubItems[10].Text;
            tb_GustDir.Text   = lviRecord.SubItems[11].Text;
        }  // end of constructor
Exemplo n.º 2
0
        }  // end of main

        //----------------------------------------------------
        // Open a WLK File
        //----------------------------------------------------
        private void openWLKFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FileStream   fsWLK;
            BinaryReader brWLK;
            byte         dataType;

            byte[]         buff;
            clsWeatherData oRecord;
            int            headerSize;
            string         strTmp;

            //**********************
            // Ask user for file
            //
            openFileDialog1.Title  = "Select WLK file";
            openFileDialog1.Filter = "WLK | *.wlk";
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            fpWLK = openFileDialog1.FileName;

            //*******************
            //  parse filename into Year and Month
            //
            strTmp = Path.GetFileName(fpWLK);
            if ((strTmp.Substring(4, 1) != "_") && (strTmp.Substring(4, 1) != "-"))
            {
                MessageBox.Show("error: Filename is not in YYYY_MM format");
                return;
            }
            if (!int.TryParse(strTmp.Substring(0, 4), out dataYear))
            {
                MessageBox.Show("error parsing Year from filename.");
                return;
            }
            if (!int.TryParse(strTmp.Substring(5, 2), out dataMonth))
            {
                MessageBox.Show("error parsing Mont from filename.");
                return;
            }

            //*******************
            // Open file
            //
            try
            {
                fsWLK = File.Open(fpWLK, FileMode.Open, FileAccess.Read, FileShare.Read);
                brWLK = new BinaryReader(fsWLK);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error opening WLK file <" + ex.Message + ">.");
                return;
            }
            toolStripStatusLabel1.Text = "Reading data from WLK file...";
            Application.DoEvents();

            //*****************
            // now read data from file
            //
            lstRecords.Clear();
            lvRecords.Items.Clear();
            try
            {
                // Read file header block
                //
                idCode       = brWLK.ReadChars(16);
                totalRecords = brWLK.ReadInt32();
                for (int i = 0; i < 32; i++)
                {
                    dayIndex[i].recordsInDay = brWLK.ReadInt16();
                    dayIndex[i].startPos     = brWLK.ReadInt32();
                }
                headerSize = 16 + 4 + 32 * (2 + 4);     // size of header record

                // Read records one day at a time...
                //
                for (int iDay = 1; iDay < 32; iDay++)
                {
                    // seek to the star of this day
                    //
                    fsWLK.Seek(headerSize + dayIndex[iDay].startPos * 88, SeekOrigin.Begin);

                    // Read all data records for this day
                    //   but just save the standard archive records
                    //
                    for (int i = 0; i < dayIndex[iDay].recordsInDay; i++)
                    {
                        // read first byte to ID the record type
                        //
                        dataType = brWLK.ReadByte();

                        // now handle it...
                        //
                        if (dataType != 1)
                        {
                            // not a standard archive record, read the 87 remaining bytes and move on
                            //
                            buff = brWLK.ReadBytes(87);
                        }
                        else
                        {
                            // we have a standard archive record, read it and keep the data
                            //
                            oRecord = new clsWeatherData();
                            oRecord.ReadRecord(brWLK);                                                                // errors will propagate out...
                            oRecord.dteTime = new DateTime(dataYear, dataMonth, iDay).AddMinutes(oRecord.packedTime); // set date/time

                            lstRecords.Add(oRecord);
                        }
                    } // end of loop for reading records for a day

                    toolStripStatusLabel1.Text = string.Format("{0}", iDay);
                    Application.DoEvents();
                }  // end of loop through days of month
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error opening WLK file <" + ex.Message + ">.");
                return;
            }
            finally
            {
                fsWLK.Close();
                brWLK.Close();
            }

            // update the list
            //
            UpdateList();

            // all done
            //
            toolStripStatusLabel1.Text = "WLK file has been read. " + lstRecords.Count.ToString() + " records imported.";
        } // end of open WLK file
Exemplo n.º 3
0
        } // end of open WLK file

        //----------------------------------------------------
        // DisplayLine - return ListView item for listview control
        //----------------------------------------------------
        private ListViewItem DisplayLine(clsWeatherData oRecord)
        {
            ListViewItem lviTmp;
            int          rainCollecterType;
            int          rainClicks;
            double       rainFactor;
            double       rainVal;
            int          iTmp;

            //init
            //
            lviTmp = new ListViewItem();        // note: this creates the first subitem

            // date/time in python format %Y-%m-%d %H:%M:%S : 2020 Apr 02 07:47
            //
            lviTmp.SubItems[0].Text = (string.Format("{0:yyyy-MM-dd HH:mm:ss}", oRecord.dteTime));

            // outside temp
            //
            if (oRecord.outsideTemp < -1000)
            {
                lviTmp.SubItems.Add("");
            }
            else
            {
                lviTmp.SubItems.Add(string.Format("{0:0.0}", (double)oRecord.outsideTemp * 0.1));
            }

            // inside temp
            //
            if (oRecord.insideTemp < -1000)
            {
                lviTmp.SubItems.Add("");
            }
            else
            {
                lviTmp.SubItems.Add(string.Format("{0:0.0}", (double)oRecord.insideTemp * 0.1));
            }

            // outside humidity
            //
            if (oRecord.outsideHum < -1)
            {
                lviTmp.SubItems.Add("");
            }
            else
            {
                lviTmp.SubItems.Add(string.Format("{0:0.0}", (double)oRecord.outsideHum * 0.1));
            }

            // inside humidty
            //
            if (oRecord.insideHum < -1)
            {
                lviTmp.SubItems.Add("");
            }
            else
            {
                lviTmp.SubItems.Add(string.Format("{0:0.0}", (double)oRecord.insideHum * 0.1));
            }

            // barometer
            //
            if (oRecord.barometer == 0)
            {
                lviTmp.SubItems.Add("");
            }
            else
            {
                lviTmp.SubItems.Add(string.Format("{0:0.000}", (double)oRecord.barometer * 0.001));
            }

            // rain
            //
            rainCollecterType = oRecord.rain & 0xF000;
            rainClicks        = oRecord.rain & 0x0FFF;
            if (rainCollecterType == 0x0000)
            {
                rainFactor = 0.1;
            }
            else if (rainCollecterType == 0x1000)
            {
                rainFactor = 0.01;
            }
            else if (rainCollecterType == 0x2000)
            {
                rainFactor = 0.2 / 25.4;        // mm => inches
            }
            else if (rainCollecterType == 0x3000)
            {
                rainFactor = 1.0 / 25.4;        // mm => inches
            }
            else if (rainCollecterType == 0x6000)
            {
                rainFactor = 0.1 / 25.4;        // mm => inches
            }
            else
            {
                throw new Exception("invalid value for rain 0x" + oRecord.rain.ToString("X4"));
            }
            rainVal = (double)rainClicks * rainFactor;
            lviTmp.SubItems.Add(string.Format("{0:0.00}", rainVal));

            // rain rate
            //
            rainVal = (double)oRecord.hiRainRate * rainFactor;
            lviTmp.SubItems.Add(string.Format("{0:0.00}", rainVal));

            // wind speed
            //
            lviTmp.SubItems.Add(string.Format("{0:0.0}", (double)oRecord.windSpeed * 0.1));

            // wind direction
            //
            iTmp = oRecord.windDirection;
            if (iTmp == 255)
            {
                lviTmp.SubItems.Add("");
            }
            else
            {
                lviTmp.SubItems.Add(string.Format("{0:0.0}", iTmp * 22.5));
            }

            // gust
            //
            lviTmp.SubItems.Add(string.Format("{0:0.0}", (double)oRecord.hiWindSpeed * 0.1));

            // Gust direction
            //
            iTmp = oRecord.hiWindDirection;
            if (iTmp == 255)
            {
                lviTmp.SubItems.Add("");
            }
            else
            {
                lviTmp.SubItems.Add(string.Format("{0:0.0}", iTmp * 22.5));
            }

            return(lviTmp);
        } // end of DisplayLine