예제 #1
0
        /// <summary>
        /// Averigua el ID de una administración a partir de su nombre.
        /// </summary>
        /// <param name="name">Nombre de la administración.</param>
        /// <returns>Identificador del registro.</returns>
        public Administration GetByName(string name)
        {
            string         sql  = string.Empty;
            Administration item = null;

            try
            {
                Connect();

                sql = @"SELECT 
                        " + AdministrationDAO.SQL_FIELDS_INSERT + @" 
                    FROM 
                        " + AdministrationDAO.SQL_TABLE + @" 
                    WHERE 
                        LCase(adminname) = @adminname";

                SetParameter("adminname", name);

                using (SQLiteDataReader reader = ExecuteReader(sql))
                {
                    if (reader.Read())
                    {
                        item = AdministrationDAO.ReadEntityRecord(reader);
                    }
                }

                // Obtiene la imagen
                if (item != null && !item.LogoFilename.Equals(string.Empty))
                {
                    FileInfo file = new FileInfo(Path.Combine(AdministrationDAO.LogosPath, item.LogoFilename));
                    if (file.Exists)
                    {
                        item.LogoImage = Image.FromFile(file.FullName);
                    }
                    else
                    {
                        item.LogoFilename = string.Empty;
                        item.LogoImage    = null;
                    }
                }

                return(item);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
            finally
            {
                Disconnect();
            }
        }
예제 #2
0
        /// <summary>
        /// Get all railway companies.
        /// </summary>
        /// <returns>The requested list filled with information.</returns>
        public List <Administration> GetAll()
        {
            string                sql = string.Empty;
            Administration        admin;
            List <Administration> admins = new List <Administration>();

            try
            {
                Connect();

                sql = @"SELECT 
                        " + AdministrationDAO.SQL_FIELDS_SELECT + @"
                    FROM 
                        " + AdministrationDAO.SQL_TABLE + @" 
                    ORDER BY 
                        adminname";

                using (SQLiteDataReader reader = ExecuteReader(sql))
                {
                    while (reader.Read())
                    {
                        admin = AdministrationDAO.ReadEntityRecord(reader);
                        if (admin != null)
                        {
                            admins.Add(admin);
                        }
                    }
                }

                return(admins);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
            finally
            {
                Disconnect();
            }
        }