示例#1
0
 public static int SaveMeasure(Measure item)
 {
     return MeasureRepository.SaveMeasure(item);
 }
示例#2
0
 public static int SaveMeasure(Measure item)
 {
     var max = 0;
     measures.ForEach( t => max = Math.Max (max,t.Id));
     item.Id = ++max;
     measures.Add (item);
     WriteXml ();
     return max;
 }
示例#3
0
        public static long SaveMeasure(Measure measure)
        {
            using (var conn = GetConnection ()) {
                conn.Open ();
                using (var cmd = conn.CreateCommand ()) {

                    if (measure.Id == 0) {
                        // Do an insert
                        cmd.CommandText = "INSERT INTO Measures (MeasureName, DataType, MeasureType, Created) VALUES (@MeasureName, @DataType, @MeasureType, @Created); SELECT last_insert_rowid();";
                        cmd.Parameters.AddWithValue ("@MeasureName", measure.MeasureName);
                        cmd.Parameters.AddWithValue ("@DataType", measure.DataType);
                        cmd.Parameters.AddWithValue ("@MeasureType", measure.MeasureType.Id);
                        cmd.Parameters.AddWithValue ("@Created", DateTime.Now);

                        measure.Id = (long)cmd.ExecuteScalar();
                    } else {
                        // Do an update
                        cmd.CommandText = "UPDATE Measures SET MeasureName = @MeasureName, DataType = @DataType, MeasureType = @MeasureType WHERE Id = @Id";
                        cmd.Parameters.AddWithValue ("@Id", measure.Id);
                        cmd.Parameters.AddWithValue ("@MeasureName", measure.MeasureName);
                        cmd.Parameters.AddWithValue ("@DataType", measure.DataType);
                        cmd.Parameters.AddWithValue ("@MeasureType", measure.MeasureType.Id);

                        cmd.ExecuteNonQuery ();
                    }
                }
            }

            Console.WriteLine(string.Format("Saved measure - ID is {0}", measure.Id));
            return measure.Id;
        }