예제 #1
0
 private void _saveButton_Click(object sender, EventArgs e)
 {
     if (_channelList.SelectedIndices.Count == 0)
     {
         MessageBox.Show("Must select a channel");
         return;
     }
     if (_txtName.Text.Length == 0)
     {
         MessageBox.Show("Must enter a name");
         return;
     }
     _reading = _db.CreateReading(_txtName.Text, _txtDescription.Text);
     foreach(object obj in _channelList.CheckedItems)
     {
         ChannelConfig cc = (ChannelConfig)obj;
         _db.CreateChannelForReading(_reading, cc, "", cc.DefaultChannel);
     }
     this.DialogResult = System.Windows.Forms.DialogResult.OK;
     Close();
 }
예제 #2
0
 private void GetChannelsForReading(Reading r)
 {
     Dictionary<int, ChannelConfig> configDictionary = new Dictionary<int, ChannelConfig>();
     foreach (ChannelConfig cc in GetChannelConfigs())
     {
         configDictionary.Add(cc.ID, cc);
     }
     Dictionary<string,object> parameters = new Dictionary<string,object>();
     parameters.Add("@rid",r.ID);
     IDataReader reader = ExecuteQuery("SELECT c_id,c_details,c_channelnumber,c_ccid from channel where c_rid = @rid ORDER by c_channelnumber asc", parameters);
     while (reader.Read())
     {
         DAQChannel ch = new DAQChannel();
         int ccid = reader.GetInt32(3);
         ch.Config = configDictionary[ccid];
         ch.ID = reader.GetInt32(0);
         ch.Details = reader.GetString(1);
         ch.Channel = reader.GetInt32(2);
         ch.ParentReading = r;
         r.ChannelList.Add(ch);
     }
     reader.Close();
     foreach (DAQChannel ch in r.ChannelList)
     {
         GetReadingDetailsForChannel(ch);
     }
 }
예제 #3
0
 public Reading[] GetReadings()
 {
     BeginTransaction();
     List<Reading> readings = new List<Reading>();
     IDataReader reader = ExecuteQuery("SELECT r_id,r_date,r_name,r_description FROM READING order by r_date asc");
     while (reader.Read())
     {
         Reading r = new Reading();
         r.ID = reader.GetInt32(0);
         r.Date = Convert.ToDateTime(reader.GetString(1));
         r.Name = reader.GetString(2);
         r.Description = reader.GetString(3);
         readings.Add(r);
     }
     reader.Close();
     foreach (Reading r in readings)
     {
         GetChannelsForReading(r);
     }
     CommitTransaction();
     return readings.ToArray();
 }
예제 #4
0
 public Reading CreateReading(string name, string description)
 {
     Reading r = new Reading();
     r.Name = name;
     r.Description = description;
     SQLiteCommand cmd = _connection.CreateCommand();
     cmd.CommandText = Properties.Settings.Default.INSERT_READING;
     DateTime dt = DateTime.Now;
     r.Date = dt;
     cmd.Parameters.Add(new SQLiteParameter("@date", dt.ToUniversalTime().ToString("u")));
     cmd.Parameters.Add(new SQLiteParameter("@name",name));
     cmd.Parameters.Add(new SQLiteParameter("@description",description));
     int rid = Convert.ToInt32(cmd.ExecuteScalar());
     r.ID = rid;
     return r;
 }
예제 #5
0
        public DAQChannel CreateChannelForReading(Reading r,ChannelConfig cc, string details,int number)
        {
            SQLiteCommand cmd = _connection.CreateCommand();
            cmd.CommandText = Properties.Settings.Default.INSERT_CHANNEL;
            cmd.Parameters.Add(new SQLiteParameter("@rid",r.ID));
            cmd.Parameters.Add(new SQLiteParameter("@details",details));
            cmd.Parameters.Add(new SQLiteParameter("@number",number));
            cmd.Parameters.Add(new SQLiteParameter("@channelconfig", cc.ID));
            int cid = Convert.ToInt32(cmd.ExecuteScalar());

            DAQChannel ch = new DAQChannel();
            ch.ID = cid;
            ch.Details = details;
            ch.ParentReading = r;
            ch.Channel = number;
            ch.Config = cc;
            r.ChannelList.Add(ch);
            return ch;
        }
예제 #6
0
 private void _listReadings_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (_listReadings.SelectedItem == null)
     {
         return;
     }
     _currentReading = (Reading)_listReadings.SelectedItem;
     graphTrans.GraphPane.CurveList.Clear();
     graphTrans.GraphPane.Legend.IsVisible = true;
     int curveListIndex = 0;
     foreach (DAQChannel ch in _currentReading.ChannelList)
     {
         lock (ch)
         {
             graphTrans.GraphPane.AddCurve(ch.Config.Name, null, Color.Red, ZedGraph.SymbolType.None);
             foreach (ReadingDetail rd in ch.ReadingDetails)
             {
                 graphTrans.GraphPane.CurveList[curveListIndex].AddPoint(rd.Time, rd.PSI);
             }
             curveListIndex++;
         }
     }
     graphTrans.AxisChange();
     graphTrans.Refresh();
 }
예제 #7
0
 private void startToolStripMenuItem_Click(object sender, EventArgs e)
 {
     ReadingSetup rs = new ReadingSetup(_db);
     if (rs.ShowDialog() != System.Windows.Forms.DialogResult.OK)
     {
         return;
     }
     peekPress.Stop();
     graphTrans.GraphPane.CurveList.Clear();
     graphTrans.AxisChange();
     graphTrans.Refresh();
     _listReadings.Items.Add(rs.Reading);
     _listReadings.SelectedItem = _reading;
     _listReadings.Enabled = false;
     _currentReading = rs.Reading;
     if(_currentReading == null)
     {
         MessageBox.Show("Start a new reading");
         return;
     }
     _reading = true;
     _daqInterface = new DAQReader();
     List<DAQ> daqChannel = new List<DAQ>();
     foreach (DAQChannel ch in _currentReading.ChannelList)
     {
         graphTrans.GraphPane.AddCurve(ch.Config.Name, null, Color.Red, ZedGraph.SymbolType.None);
     }
     _daqInterface.Setup(new DataRetrieved(RetrievedData), _currentReading.ChannelList.ToArray());
     _readingThread = new Thread(new ThreadStart(_daqInterface.StartReading));
     _readingThread.Start();
 }