コード例 #1
0
        public static int Delete(SQLiteConnection conn, InspectionStation im)
        {
            if (im == null)
            {
                return(-2);
            }
            if (im.Id < 0)
            {
                return(-3);
            }

            using (SQLiteCommand cmd = new SQLiteCommand(delete, conn))
            {
                cmd.Parameters.AddWithValue("@Id", im.Id);

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    Trace.WriteLine($"EXCEPTION: InspectionStationDbMapper.Delete: {e.Message}");
                    return(-1);
                }
            }
            return(0);
        }
コード例 #2
0
        public static List <InspectionStation> SelectAll(SQLiteConnection conn)
        {
            List <InspectionStation> result = new List <InspectionStation>();

            using (SQLiteCommand cmd = new SQLiteCommand(selectAll, conn))
            {
                SQLiteDataReader reader = null;
                try
                {
                    reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        InspectionStation ism = new InspectionStation()
                        {
                            Id            = Convert.ToInt32(reader["rowid"].ToString()),
                            Active        = Convert.ToBoolean(reader["Active"]),
                            StationNumber = reader["StationNumber"].ToString(),
                            ZipCode       = reader["ZipCode"].ToString(),
                            City          = reader["City"].ToString(),
                            Street        = reader["Street"].ToString(),
                            Company       = reader["Company"].ToString(),
                            Phone         = reader["Phone"].ToString(),
                            Email         = reader["Email"].ToString(),
                            Orp           = reader["Orp"].ToString(),
                            District      = reader["District"].ToString(),
                            Region        = reader["Region"].ToString(),
                            Url           = reader["Url"].ToString()
                        };
                        result.Add(ism);
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine($"EXCEPTION: InspectionStationDbMapper.SelectAll: {e.Message}");
                }
                finally
                {
                    reader?.Close();
                }
            }

            return(result);
        }
コード例 #3
0
 public static InspectionStation 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())
             {
                 InspectionStation ism = new InspectionStation()
                 {
                     Id            = Convert.ToInt32(reader["rowid"].ToString()),
                     Active        = Convert.ToBoolean(reader["Active"]),
                     StationNumber = reader["StationNumber"].ToString(),
                     ZipCode       = reader["ZipCode"].ToString(),
                     City          = reader["City"].ToString(),
                     Street        = reader["Street"].ToString(),
                     Company       = reader["Company"].ToString(),
                     Phone         = reader["Phone"].ToString(),
                     Email         = reader["Email"].ToString(),
                     Orp           = reader["Orp"].ToString(),
                     District      = reader["District"].ToString(),
                     Region        = reader["Region"].ToString(),
                     Url           = reader["Url"].ToString()
                 };
                 reader.Close();
                 return(ism);
             }
         }
         catch (Exception e)
         {
             reader?.Close();
             Trace.WriteLine($"EXCEPTION: InspectionStationDbMapper.SelectById: {e.Message}");
         }
     }
     return(null);
 }
コード例 #4
0
        public static int Update(SQLiteConnection conn, InspectionStation im)
        {
            if (im == null)
            {
                return(-2);
            }
            if (im.Id < 0)
            {
                return(-3);
            }

            using (SQLiteCommand cmd = new SQLiteCommand(update, conn))
            {
                cmd.Parameters.AddWithValue("@Id", im.Id);
                cmd.Parameters.AddWithValue("@Active", im.Active);
                cmd.Parameters.AddWithValue("@StationNumber", im.StationNumber);
                cmd.Parameters.AddWithValue("@ZipCode", im.ZipCode);
                cmd.Parameters.AddWithValue("@City", im.City);
                cmd.Parameters.AddWithValue("@Street", im.Street);
                cmd.Parameters.AddWithValue("@Company", im.Company);
                cmd.Parameters.AddWithValue("@Phone", im.Phone);
                cmd.Parameters.AddWithValue("@Email", im.Email);
                cmd.Parameters.AddWithValue("@Orp", im.Orp);
                cmd.Parameters.AddWithValue("@District", im.District);
                cmd.Parameters.AddWithValue("@Region", im.Region);
                cmd.Parameters.AddWithValue("@Url", im.Url);

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    Trace.WriteLine($"EXCEPTION: InspectionStationDbMapper.Update: {e.Message}");
                    return(-1);
                }
            }
            return(0);
        }