Archived
Added: icon database support
This commit is contained in:
1 parent
4dd399f537
commit
253365d25e
3 files changed
+80
-80
No files matched your search
+43
-39
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace BookmarkManager
|
||||
{
|
||||
@@ -30,14 +31,6 @@ namespace BookmarkManager
|
||||
|
||||
if (isNew) Initialise();
|
||||
|
||||
|
||||
|
||||
|
||||
//if (File.Exists(filename))
|
||||
//{
|
||||
// File.Delete("test.db3");
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
public bool AddIcon(string id, Image image)
|
||||
@@ -52,14 +45,17 @@ namespace BookmarkManager
|
||||
command.Connection = dbConnection;
|
||||
command.CommandText = "INSERT INTO icons (id, content) VALUES (@id, @content)";
|
||||
command.Parameters.Add("@id", SqliteType.Text).Value = id;
|
||||
command.Parameters.Add("@content", SqliteType.Blob, 20).Value = ImageToBytes(image);
|
||||
command.Parameters.Add("@content", SqliteType.Blob).Value = ImageToBytes(image);
|
||||
|
||||
try
|
||||
{
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception exc)
|
||||
{
|
||||
//#if DEBUG
|
||||
// MessageBox.Show(exc.Message);
|
||||
//#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -89,8 +85,11 @@ namespace BookmarkManager
|
||||
{
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception exc)
|
||||
{
|
||||
//#if DEBUG
|
||||
// MessageBox.Show(exc.Message);
|
||||
//#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -103,30 +102,30 @@ namespace BookmarkManager
|
||||
if (dbConnection == null) return null;
|
||||
if (string.IsNullOrWhiteSpace(id)) return null;
|
||||
|
||||
if (!HasIcon(id)) return null;
|
||||
|
||||
byte[] iconBytes = null;
|
||||
|
||||
SqliteCommand command = new SqliteCommand();
|
||||
command.Connection = dbConnection;
|
||||
command.CommandText = "SELECT content FROM icons WHERE @id";
|
||||
command.CommandText = "SELECT content FROM icons WHERE id = @id";
|
||||
command.Parameters.Add("@id", SqliteType.Text).Value = id;
|
||||
|
||||
try
|
||||
{
|
||||
using (var reader = command.ExecuteReader())
|
||||
var rs = command.ExecuteScalar();
|
||||
if (rs != null)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader["content"] != null && !Convert.IsDBNull(reader["content"]))
|
||||
{
|
||||
iconBytes = (byte[])reader["content"];
|
||||
}
|
||||
}
|
||||
iconBytes = (byte[])rs;
|
||||
}
|
||||
|
||||
command.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception exc)
|
||||
{
|
||||
//#if DEBUG
|
||||
// MessageBox.Show(exc.Message);
|
||||
//#endif
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -141,8 +140,11 @@ namespace BookmarkManager
|
||||
{
|
||||
img = Image.FromStream(new MemoryStream(iconBytes));
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception exc)
|
||||
{
|
||||
//#if DEBUG
|
||||
// MessageBox.Show(exc.Message);
|
||||
//#endif
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -154,33 +156,30 @@ namespace BookmarkManager
|
||||
if (dbConnection == null) return false;
|
||||
if (string.IsNullOrWhiteSpace(id)) return false;
|
||||
|
||||
int rv = 0;
|
||||
string rs = string.Empty;
|
||||
|
||||
SqliteCommand command = new SqliteCommand();
|
||||
command.Connection = dbConnection;
|
||||
command.CommandText = "SELECT COUNT(1) AS count FROM icons WHERE @id";
|
||||
command.CommandText = "SELECT COUNT(1) AS count FROM icons WHERE id = @id";
|
||||
command.Parameters.Add("@id", SqliteType.Text).Value = id;
|
||||
|
||||
try
|
||||
{
|
||||
using (var reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader["count"] != null && !Convert.IsDBNull(reader["count"]))
|
||||
{
|
||||
rv = (int)reader["count"];
|
||||
}
|
||||
}
|
||||
}
|
||||
rs = command.ExecuteScalar()?.ToString() ?? string.Empty;
|
||||
|
||||
command.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception exc)
|
||||
{
|
||||
//#if DEBUG
|
||||
// MessageBox.Show(exc.Message);
|
||||
//#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
int rv;
|
||||
if (!int.TryParse(rs, out rv)) rv = 0;
|
||||
|
||||
return (rv > 0);
|
||||
}
|
||||
|
||||
@@ -196,14 +195,17 @@ namespace BookmarkManager
|
||||
command.Connection = dbConnection;
|
||||
command.CommandText = "UPDATE icons SET content = @content WHERE id = @id";
|
||||
command.Parameters.Add("@id", SqliteType.Text).Value = id;
|
||||
command.Parameters.Add("@content", SqliteType.Blob, 20).Value = ImageToBytes(image);
|
||||
command.Parameters.Add("@content", SqliteType.Blob).Value = ImageToBytes(image);
|
||||
|
||||
try
|
||||
{
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception exc)
|
||||
{
|
||||
//#if DEBUG
|
||||
// MessageBox.Show(exc.Message);
|
||||
//#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -221,8 +223,11 @@ namespace BookmarkManager
|
||||
command.ExecuteNonQuery();
|
||||
command.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception exc)
|
||||
{
|
||||
//#if DEBUG
|
||||
// MessageBox.Show(exc.Message);
|
||||
//#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -239,6 +244,5 @@ namespace BookmarkManager
|
||||
return stream.ToArray();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user