private Collection<GraphDataSet> ExecuteReaderGDSSWeek(string connection, string query, string column) { DataTable dt = new DataTable(); GraphDataSet temp; Collection<GraphDataSet> result = new Collection<GraphDataSet>(); try { SQLiteConnection cnn = new SQLiteConnection(connection); cnn.Open(); SQLiteCommand mycommand = new SQLiteCommand(query, cnn); SQLiteDataAdapter da = new SQLiteDataAdapter(mycommand); da.Fill(dt); cnn.Close(); string lastval; lastval = "0"; temp = new GraphDataSet(column); if (dt.Rows.Count > 0) { lastval = (string)dt.Rows[0][column].ToString(); string lastserial = dt.Rows[0]["Serial"].ToString(); temp.AddWeek(lastval, dt.Rows[0]["Week"].ToString()); foreach (DataRow row in dt.Rows) { if ((row[column] != System.DBNull.Value)) { if (row["Serial"].ToString() == lastserial) temp.Y[temp.Y.Count - 1] = double.Parse(row[column].ToString()); else { lastval = (string)row[column].ToString(); temp.AddWeek(lastval, row["Week"].ToString()); } } else { temp.AddWeek(lastval, row["Week"].ToString()); } lastserial = row["Serial"].ToString(); } } else { temp.Name = "empty"; temp.AddWeek("0", "0"); temp.AddWeek("0", "0"); temp.AddWeek("0", "0"); temp.AddWeek("0", "0"); } result.Add(temp); } catch (SQLiteException e) { MessageBox.Show(e.Message); } return result; }
//Execute Query private Collection<GraphDataSet> ExecuteReaderGDS(string connection, string query) { DataTable dt = new DataTable(); GraphDataSet temp; Collection<GraphDataSet> result = new Collection<GraphDataSet>(); try { SQLiteConnection cnn = new SQLiteConnection(connection); cnn.Open(); SQLiteCommand mycommand = new SQLiteCommand(query, cnn); SQLiteDataAdapter da = new SQLiteDataAdapter(mycommand); da.Fill(dt); cnn.Close(); string lastval; foreach (DataColumn x in dt.Columns) { lastval = "0"; temp = new GraphDataSet(x.ColumnName); foreach (DataRow row in dt.Rows) { if ((row[x.ColumnName] != System.DBNull.Value)) { lastval = (string)row[x.ColumnName].ToString(); temp.Add(lastval); } else { temp.Add(lastval); } } result.Add(temp); } } catch (SQLiteException e) { MessageBox.Show(e.Message); } return result; }