Exemplo n.º 1
0
        /// <summary>
        /// Returns requested picture.
        /// </summary>
        /// <param name="pGroup">Picture group</param>
        /// <param name="pId">Picture Id</param>
        /// <param name="pSubID">Picture sub Id</param>
        /// <param name="pThumbnail">Do you want the thumbnail or the actual picture?</param>
        /// <returns>Found picture informations</returns>
        public PictureInfo GetPicture(string pGroup, int pId, int pSubID, bool pThumbnail)
        {
            string sql = pThumbnail
                ? "SELECT thumbnail,name FROM Pictures WHERE [group]=@group AND id=@id AND subid=@subid"
                : "SELECT picture,name FROM Pictures WHERE [group]=@group AND id=@id AND subid=@subid";

            using (OpenCbsCommand c = new OpenCbsCommand(sql, AttachmentsConnection))
            {
                c.AddParam("@group", pGroup);
                c.AddParam("@id", pId);
                c.AddParam("@subid", pSubID);

                using (OpenCbsReader r = c.ExecuteReader())
                {
                    if (r == null || r.Empty)
                    {
                        return(null);
                    }

                    r.Read();
                    PictureInfo pi = new PictureInfo
                    {
                        Binary = r.GetBytes(0),
                        Name   = r.GetString(1),
                        Id     = pId,
                        SubId  = pSubID,
                        Group  = pGroup
                    };
                    return(pi);
                }
            }
        }
Exemplo n.º 2
0
        public byte[] GetPicture(string clientType, int clientId, bool thumbnail, int photoSubId)
        {
            string q;

            if (thumbnail)
            {
                q = string.Format(
                    @"SELECT TOP(1) [Pictures].[thumbnail]
                        FROM [Pictures]
                        WHERE [Pictures].[group]=@client_type 
                              AND [Pictures].[id]=@client_id 
                              AND [Pictures].[subid]=@photo_sub_id
                              ");
            }
            else
            {
                q =
                    string.Format(
                        @"SELECT TOP(1) Pictures.picture
                        FROM Pictures
                        WHERE [Pictures].[group]=@client_type 
                              AND [Pictures].[id]=@client_id
                              AND [Pictures].[subid]=@photo_sub_id 
                        ");
            }

            using (OpenCbsCommand c = new OpenCbsCommand(q, AttachmentsConnection))
            {
                c.AddParam("client_type", clientType);
                c.AddParam("client_id", clientId);
                c.AddParam("photo_sub_id", photoSubId);
                using (OpenCbsReader r = c.ExecuteReader())
                {
                    if (r.Read())
                    {
                        return(r.GetBytes(0));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public byte[] GetPicture(int personId, int photoSubId, bool thumbnail)
        {
            string q;

            if (thumbnail)
            {
                q = string.Format(@"SELECT TOP(1) [Pictures].[thumbnail]
                        FROM [Pictures]
                        WHERE [Pictures].[group]='PERSON' 
                        AND [Pictures].[id]=@person_id 
                        AND [Pictures].[subid]=@sub_id");
            }
            else
            {
                q =
                    string.Format(
                        @"SELECT TOP(1) Pictures.picture
                        FROM Pictures
                        WHERE [Pictures].[group]='PERSON' 
                        AND [Pictures].[id]=@person_id 
                        AND [Pictures].[subid]=@sub_id");
            }

            using (OpenCbsCommand c = new OpenCbsCommand(q, AttachmentsConnection))
            {
                c.AddParam("person_id", personId);
                c.AddParam("@sub_id", photoSubId);
                using (OpenCbsReader r = c.ExecuteReader())
                {
                    while (r.Read())
                    {
                        return(r.GetBytes(0));
                    }
                }
                return(null);
            }
        }