Пример #1
0
 public static Inspection SelectById(SQLiteConnection conn, int id)
 {
     using (SQLiteCommand cmd = new SQLiteCommand(selectById, conn))
     {
         cmd.Parameters.AddWithValue("@Id", id);
         SQLiteDataReader reader = null;
         try
         {
             reader = cmd.ExecuteReader();
             while (reader.Read())
             {
                 Inspection im = new Inspection()
                 {
                     Id                = Convert.ToInt32(reader["rowid"].ToString()),
                     Vehicle           = VehicleDbMapper.SelectById(conn, Convert.ToInt32(reader["VehicleId"])),
                     InspectionDate    = Convert.ToDateTime(reader["InspectionDate"]),
                     ValidTo           = Convert.ToDateTime(reader["ValidTo"]),
                     InspectionStation = InspectionStationDbMapper.SelectById(conn, Convert.ToInt32(reader["InspectionStationId"])),
                     ProtocolNumber    = reader["ProtocolNumber"].ToString(),
                     Tachometer        = Convert.ToInt32(reader["Tachometer"].ToString()),
                     Price             = Convert.ToDecimal(reader["Price"].ToString()),
                     Defects           = reader["Defects"].ToString()
                 };
                 reader.Close();
                 return(im);
             }
         }
         catch (Exception e)
         {
             reader?.Close();
             Trace.WriteLine($"EXCEPTION: InspectionDbMapper.SelectById: {e.Message}");
         }
     }
     return(null);
 }
Пример #2
0
        public static List <Inspection> SelectAll(SQLiteConnection conn)
        {
            List <Inspection> result = new List <Inspection>();

            using (SQLiteCommand cmd = new SQLiteCommand(selectAll, conn))
            {
                SQLiteDataReader reader = null;
                try
                {
                    reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Inspection im = new Inspection()
                        {
                            Id                = Convert.ToInt32(reader["rowid"].ToString()),
                            Vehicle           = VehicleDbMapper.SelectById(conn, Convert.ToInt32(reader["VehicleId"])),
                            InspectionDate    = Convert.ToDateTime(reader["InspectionDate"]),
                            ValidTo           = Convert.ToDateTime(reader["ValidTo"]),
                            InspectionStation = InspectionStationDbMapper.SelectById(conn, Convert.ToInt32(reader["InspectionStationId"])),
                            ProtocolNumber    = reader["ProtocolNumber"].ToString(),
                            Tachometer        = Convert.ToInt32(reader["Tachometer"].ToString()),
                            Price             = Convert.ToDecimal(reader["Price"].ToString()),
                            Defects           = reader["Defects"].ToString()
                        };
                        result.Add(im);
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine($"EXCEPTION: InspectionDbMapper.SelectAll: {e.Message}");
                }
                finally
                {
                    reader?.Close();
                }
            }

            return(result);
        }