Пример #1
0
        public static Image GetCurrentImage(string project, string guid)
        {
            try {
                string projectsPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                string currentPicture = "";

                using (SQLiteConnection Conn = new SQLiteConnection())
                {
                    Conn.ConnectionString = "Data Source=" + projectsPath + @"\\Projects\\" + project + ".db;Version=3;New=False;Compress=True;Synchronous=Off";
                    Conn.Open();

                    SQLiteParameter sqlGuid = new SQLiteParameter("@guid", DbType.String)
                    {
                        Value = guid
                    };
                    SQLiteCommand cmd = new SQLiteCommand();
                    cmd = Conn.CreateCommand();
                    cmd.Parameters.Add(sqlGuid);
                    cmd.CommandText = "SELECT image_base64 FROM images WHERE guid_images = @guid";


                    using (SQLiteDataReader sqReader = cmd.ExecuteReader())
                    {
                        if (sqReader.Read())
                        {
                            currentPicture = sqReader.GetString(0);
                        }
                    }

                    if (currentPicture == "")
                    {
                        ResourceManager resources = new ResourceManager("CameratrapManager_db.Resources.Images", System.Reflection.Assembly.GetExecutingAssembly());


                        return((System.Drawing.Bitmap)(resources.GetObject("no-photo-available")));
                    }
                    else
                    {
                        return(ConversionUtilities.Base64ToImage(currentPicture));
                    }
                }
            } catch (Exception ex) {
                throw ex;
            }
        }