コード例 #1
0
ファイル: DataAccessLayer.cs プロジェクト: M1mez/PDB3
        public virtual IEnumerable <IPictureModel> GetPictures()
        {
            var output = "Get all pictures";

            Console.WriteLine(output);
            var pictures = new List <IPictureModel>();

            try
            {
                Conn.Open();
                using (var reader = PS.GetAllPictures.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        pictures.Add(DTOParser.ParsePictureModel(RecordToDictionary(reader)));
                    }
                }
                Conn.Close();
                Console.WriteLine($"Returned {pictures.Count} pictures!");
                return(pictures);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw new Exception(output, e);
            }
            finally
            {
                Conn.Close();
            }
        }
コード例 #2
0
ファイル: DataAccessLayer.cs プロジェクト: M1mez/PDB3
        public virtual IPictureModel GetPicture(int ID)
        {
            var output = $"Get picture with ID: {ID}";

            Console.WriteLine(output);
            try
            {
                Conn.Open();
                PS.GetOnePictureId.Parameters["@ID"].Value = ID;
                PictureModel picture;
                using (var reader = PS.GetOnePictureId.ExecuteReader())
                {
                    reader.Read();
                    picture = DTOParser.ParsePictureModel(RecordToDictionary(reader));
                }
                Conn.Close();
                return(picture);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw new Exception(output, e);
            }
            finally
            {
                Conn.Close();
            }
        }
コード例 #3
0
ファイル: DataAccessLayer.cs プロジェクト: M1mez/PDB3
        public virtual IEnumerable <IPictureModel> GetPictures(string namePart, IPhotographerModel photographerParts, IIPTCModel iptcParts, IEXIFModel exifParts)
        {
            var output = "Search Pictures";

            Console.WriteLine(output);

            var pictures = new List <IPictureModel>();

            try
            {
                PS.GetSearchPictures.Parameters["@namePart"].Value = (object)namePart ?? DBNull.Value;

                // Photographer
                if (photographerParts?.ID == 0 || photographerParts?.ID == null)
                {
                    PS.GetSearchPictures.Parameters["@PG_PG_ID"].Value = DBNull.Value;
                }
                else
                {
                    PS.GetSearchPictures.Parameters["@PG_PG_ID"].Value = (object)photographerParts.ID;
                }
                PS.GetSearchPictures.Parameters["@PG_Birthday"].Value  = (object)photographerParts?.BirthDay ?? DBNull.Value;
                PS.GetSearchPictures.Parameters["@PG_FirstName"].Value = (object)photographerParts?.FirstName ?? DBNull.Value;
                PS.GetSearchPictures.Parameters["@PG_LastName"].Value  = (object)photographerParts?.LastName ?? DBNull.Value;
                PS.GetSearchPictures.Parameters["@PG_Notes"].Value     = (object)photographerParts?.Notes ?? DBNull.Value;

                // IPTC
                if (iptcParts?.Keywords == "" || iptcParts?.Keywords == null)
                {
                    PS.GetSearchPictures.Parameters["@IPTC_Keywords"].Value = DBNull.Value;
                }
                else
                {
                    PS.GetSearchPictures.Parameters["@IPTC_Keywords"].Value = iptcParts.Keywords;
                }

                if (iptcParts?.ByLine == "" || iptcParts?.ByLine == null)
                {
                    PS.GetSearchPictures.Parameters["@IPTC_ByLine"].Value = DBNull.Value;
                }
                else
                {
                    PS.GetSearchPictures.Parameters["@IPTC_ByLine"].Value = iptcParts.ByLine;
                }

                if (iptcParts?.CopyrightNotice == "" || iptcParts?.CopyrightNotice == null)
                {
                    PS.GetSearchPictures.Parameters["@IPTC_CopyrightNotice"].Value = DBNull.Value;
                }
                else
                {
                    PS.GetSearchPictures.Parameters["@IPTC_CopyrightNotice"].Value = iptcParts.CopyrightNotice;
                }

                if (iptcParts?.Headline == "" || iptcParts?.Headline == null)
                {
                    PS.GetSearchPictures.Parameters["@IPTC_Headline"].Value = DBNull.Value;
                }
                else
                {
                    PS.GetSearchPictures.Parameters["@IPTC_Headline"].Value = iptcParts.Headline;
                }

                if (iptcParts?.Caption == "" || iptcParts?.Caption == null)
                {
                    PS.GetSearchPictures.Parameters["@IPTC_Caption"].Value = DBNull.Value;
                }
                else
                {
                    PS.GetSearchPictures.Parameters["@IPTC_Caption"].Value = iptcParts.Caption;
                }

                /*PS.GetSearchPictures.Parameters["@IPTC_Keywords"].Value = (object)iptcParts?.Keywords ?? DBNull.Value;
                 * PS.GetSearchPictures.Parameters["@IPTC_ByLine"].Value = (object)iptcParts?.ByLine ?? DBNull.Value;
                 * PS.GetSearchPictures.Parameters["@IPTC_CopyrightNotice"].Value = (object)iptcParts?.CopyrightNotice ?? DBNull.Value;
                 * PS.GetSearchPictures.Parameters["@IPTC_Headline"].Value = (object)iptcParts?.Headline ?? DBNull.Value;
                 * PS.GetSearchPictures.Parameters["@IPTC_Caption"].Value = (object)iptcParts?.Caption ?? DBNull.Value;*/

                // EXIF
                PS.GetSearchPictures.Parameters["@EXIF_Make"].Value = (object)exifParts?.Make ?? DBNull.Value;
                //TODO cant search for value 0 because of interface, what to do?
                PS.GetSearchPictures.Parameters["@EXIF_FNumber"].Value =
                    exifParts?.FNumber == 0 || exifParts?.FNumber == null
                        ? DBNull.Value
                        : (object)exifParts.FNumber; //(object)exifParts?.FNumber ?? DBNull.Value;
                PS.GetSearchPictures.Parameters["@EXIF_ExposureTime"].Value =
                    exifParts?.ExposureTime == 0 || exifParts?.ExposureTime == null
                        ? DBNull.Value
                        : (object)exifParts.ExposureTime; //(object)exifParts?.ExposureTime ?? DBNull.Value;
                PS.GetSearchPictures.Parameters["@EXIF_ISOValue"].Value =
                    exifParts?.ISOValue == 0 || exifParts?.ISOValue == null
                        ? DBNull.Value
                        : (object)exifParts.ISOValue; //(object)exifParts?.ISOValue ?? DBNull.Value;
                PS.GetSearchPictures.Parameters["@EXIF_Flash"].Value           = (object)exifParts?.Flash ?? DBNull.Value;
                PS.GetSearchPictures.Parameters["@EXIF_ExposureProgram"].Value = (object)exifParts?.ExposureProgram ?? DBNull.Value;

                Conn.Open();
                using (var reader = PS.GetSearchPictures.ExecuteReader())
                {
                    Console.WriteLine("FieldCount" + reader.FieldCount);
                    while (reader.Read())
                    {
                        pictures.Add(DTOParser.ParsePictureModel(RecordToDictionary(reader)));
                    }
                }
                Conn.Close();
                return(pictures);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw new Exception(output, e);
            }
            finally
            {
                Conn.Close();
            }
        }