// fill the list public int LoadData() { objSugar sugar = new objSugar();; DataSet ds; // clear the list sugarList.Clear(); // get the data try { ds = sugar.GetAll(); } catch { throw; } // fill the list foreach (DataRow row in ds.Tables[0].Rows) { sugar = new objSugar(row); sugarList.Add(sugar); } return(Count); }
//------------------------- // private methods private bool LoadData() { objMeter meter = new objMeter(cbCommPort.Text); objSugar sugar; int readCount, writeCount; try { readCount = meter.Load(); } catch (Exception ex) { MessageBox.Show("Cannot import data - " + ex.Message); return(false); } // if no readings, say so if (readCount == 0) { MessageBox.Show("Nothing read"); return(true); } // copy the data sugar = new objSugar(); writeCount = 0; try { foreach (objSugar newSugar in meter.sugarList) { if (sugar.LoadByTime(newSugar.Time) == false) { newSugar.Add(); writeCount++; } } } catch (Exception ex) { MessageBox.Show("Cannot copy data - " + ex.Message); return(false); } MessageBox.Show("Read " + readCount.ToString() + ", added " + writeCount.ToString()); return(true); }
//------------------ // private methods // parse the data from the line read from the comm port and add to the sugar list private void addSugar(string buff) { objSugar sugar = new objSugar(); string y, m, d, hh, mm, s; // split fields byy commas string[] itms = buff.Split(','); if (itms.Length < 7) { return; } // convert text to sugar structure y = itms[1]; m = itms[2]; d = itms[3]; hh = itms[4]; mm = itms[5]; s = itms[6]; // convert time try { sugar.Time = DateTime.Parse(m + "/" + d + "/" + y + " " + hh + ":" + mm); sugar.Sugar = int.Parse(s); } catch { return; } sugarList.Add(sugar); }