コード例 #1
0
        private Media getMediaByValue(string where, string value)
        {
            Media ret = null;

            using (SQLiteConnection connection = new SQLiteConnection(connectionString))
            {
                try
                {
                    connection.Open();

                    using (SQLiteCommand command = new SQLiteCommand("SELECT * FROM Media WHERE " + where, connection))
                    {
                        command.Parameters.AddWithValue("@var", value);
                        using (SQLiteDataReader reader = command.ExecuteReader())
                        {
                            reader.Read();

                            if (reader.HasRows)
                            {
                                ret = createMediaFromReader(reader);

                                using (SQLiteCommand command2 = new SQLiteCommand("SELECT * FROM Details WHERE mediaID=@ID", connection))
                                {
                                    command2.Parameters.AddWithValue("@ID", ret.ID);
                                    using (SQLiteDataReader reader2 = command2.ExecuteReader())
                                    {
                                        while (reader2.Read())
                                        {
                                            ret.addDetail(createDetailFromReader(reader2));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Database.getMediaByValue: " + ex);
                }
            }

            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// Provides a filtered list of the content.
        /// </summary>
        public List <PictureListItem> getData(string category, List <int> type)
        {
            if (type.Count < 1)
            {
                return(null);
            }

            List <PictureListItem> ret = new List <PictureListItem>();

            using (SQLiteConnection connection = new SQLiteConnection(connectionString))
            {
                try
                {
                    connection.Open();

                    string typeString = "";
                    foreach (int item in type)
                    {
                        typeString += item + ",";
                    }
                    typeString = typeString.Substring(0, typeString.Length - 1);

                    using (SQLiteCommand command = new SQLiteCommand("SELECT * FROM Media WHERE Type = @type AND ID IN (SELECT DISTINCT MediaID FROM Details WHERE AktivStatus IN (" + typeString + "))", connection))
                    {
                        command.Parameters.AddWithValue("@type", category);
                        using (SQLiteDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                try
                                {
                                    Media item = createMediaFromReader(reader);

                                    using (SQLiteCommand detCommand = new SQLiteCommand("SELECT * FROM Details WHERE MediaID=@id", connection))
                                    {
                                        detCommand.Parameters.AddWithValue("@id", item.ID);
                                        using (SQLiteDataReader detailReader = detCommand.ExecuteReader())
                                        {
                                            while (detailReader.Read())
                                            {
                                                item.addDetail(createDetailFromReader(detailReader));
                                            }
                                        }

                                        ret.Add(new PictureListItem(item));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.ToString());
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Database.getData: " + ex);
                }
            }

            return(ret);
        }