Exemple #1
0
        private static void SaveRecord(SeriesRecord r, string dbConnectionString, Series series, long templateId)
        {
            if (r == null)
            {
                return;
            }
            using (SqlConnection connection = new SqlConnection(dbConnectionString))
            {
                connection.Open();
                using (SqlCommand insert = new SqlCommand())
                {
                    insert.CommandType = CommandType.StoredProcedure;
                    insert.CommandText = "InsertSeriesRecord";
                    insert.Connection  = connection;
                    /*INSERT INTO SeriesRecords (time, x, y, template_id, series_id) VALUES (@time, @x,  @y, @template_id, @series_id);**/

                    SqlParameter param = insert.Parameters.Add("@time", SqlDbType.BigInt, 1);
                    param.Value = r.Time;
                    SqlParameter param1 = insert.Parameters.Add("@x", SqlDbType.BigInt, 1);
                    param1.Value = r.X;
                    SqlParameter param2 = insert.Parameters.Add("@y", SqlDbType.BigInt, 1);
                    param2.Value = r.Y;
                    SqlParameter param3 = insert.Parameters.Add("@template_id", SqlDbType.BigInt, 1);
                    param3.Value = templateId;
                    SqlParameter param4 = insert.Parameters.Add("@series_id", SqlDbType.BigInt, 1);
                    param4.Value = series.Id;

                    insert.ExecuteNonQuery();
                }
            }
        }
Exemple #2
0
        public static ArrayList GetRecords(long seria_id, long template_id, string dbConnectionString)
        {
            ArrayList result = new ArrayList();

            using (SqlConnection connection = new SqlConnection(dbConnectionString))
            {
                connection.Open();
                using (SqlCommand select = new SqlCommand())
                {
                    select.CommandType = CommandType.StoredProcedure;
                    select.CommandText = "SelectRecordsForSeriaAndTemplate";
                    select.Connection  = connection;


                    SqlParameter pId = select.Parameters.Add("@seria_id", SqlDbType.BigInt, 1);
                    pId.Value = seria_id;
                    SqlParameter pTemplateId = select.Parameters.Add("@template_id", SqlDbType.BigInt, 1);
                    pTemplateId.Value = template_id;

                    using (SqlDataReader reader = select.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            SeriesRecord sr = new SeriesRecord();
                            sr.X    = (int)reader.GetInt64(0);
                            sr.Y    = (int)reader.GetInt64(1);
                            sr.Time = (int)reader.GetInt64(2);
                            result.Add(sr);
                        }
                    }
                }
            }

            return(result);
        }
        public void SetTemplateCoord(int templateIndex, SeriesRecord coord, int timePosition)
        {
            ArrayList coords = (ArrayList)TemplateCoords[templateIndex];
            int       index  = timePosition / Constants.TIME_CHUNK_MS;

            if (index < coords.Count)
            {
                coords[index] = coord;
            }
        }
Exemple #4
0
        public static ArrayList SelectSeries(int trialId, string dbConnectionString)
        {
            ArrayList result = new ArrayList();

            using (SqlConnection connection = new SqlConnection(dbConnectionString))
            {
                connection.Open();
                using (SqlCommand select = new SqlCommand())
                {
                    select.CommandType = CommandType.StoredProcedure;
                    select.CommandText = "SelectSeriesForTrial";
                    select.Connection  = connection;

                    SqlParameter param = select.Parameters.Add("@id", SqlDbType.BigInt, 1);
                    param.Value = trialId;

                    using (SqlDataReader reader = select.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Series s = new Series();
                            s.Id = reader.GetInt64(0);
                            long seriesConfigId = reader.GetInt64(1);
                            s.Config = SelectSeriesConfig(seriesConfigId, dbConnectionString);
                            s.Name   = reader.GetString(2);
                            ArrayList templates = GetTemplates(s.Id, dbConnectionString);
                            for (int i = 0; i < templates.Count; i++)
                            {
                                Template t = (Template)templates[i];
                                s.AddTemplate(t);
                                s.AddTemplateCoordArray();
                            }

                            for (int i = 0; i < s.Templates.Count; i++)
                            {
                                Template  t      = (Template)s.Templates[i];
                                ArrayList coords = GetRecords(s.Id, t.Id, dbConnectionString);
                                for (int j = 0; j < coords.Count; j++)
                                {
                                    SeriesRecord sr = (SeriesRecord)coords[j];
                                    s.SetTemplateCoord(i, sr, (int)sr.Time);
                                }
                            }
                            result.Add(s);
                        }
                    }
                }
            }
            return(result);
        }
Exemple #5
0
 public static void SaveSeries(Series series, string dbConnectionString)
 {
     for (int i = 0; i < series.Templates.Count; i++)
     {
         Template t  = (Template)series.Templates[i];
         long     id = SaveTemplate(series, t, dbConnectionString);
         if (id != -1)
         {
             t.Id = id;
         }
     }
     for (int i = 0; i < series.TemplateCoords.Count; i++)
     {
         ArrayList coords = (ArrayList)series.TemplateCoords[i];
         Template  t      = (Template)series.Templates[i];
         for (int j = 0; j < coords.Count; j++)
         {
             SeriesRecord r = (SeriesRecord)coords[j];
             SaveRecord(r, dbConnectionString, series, t.Id);
         }
     }
 }