|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Web.WebView2.Core;
|
|
|
|
|
using Microsoft.Web.WebView2.WinForms;
|
|
|
|
|
using PhotoCollector.Data;
|
|
|
|
@ -258,6 +259,107 @@ namespace PhotoCollector
|
|
|
|
|
message
|
|
|
|
|
}, jsonSerializerOptions);
|
|
|
|
|
});
|
|
|
|
|
WebView2Interop.FuncList.Add("executeQuery", o =>
|
|
|
|
|
{
|
|
|
|
|
var code = 0;
|
|
|
|
|
var message = "操作成功";
|
|
|
|
|
var value = new List<Dictionary<string, object>>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = new List<object>();
|
|
|
|
|
using var db = new AppDbContext();
|
|
|
|
|
using var cmd = db.Database.GetDbConnection().CreateCommand();
|
|
|
|
|
cmd.CommandText = o["sql"];
|
|
|
|
|
db.Database.OpenConnection();
|
|
|
|
|
using (var reader = cmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
var item = new Dictionary<string, object>();
|
|
|
|
|
for (int i = 0; i < reader.FieldCount; i++)
|
|
|
|
|
{
|
|
|
|
|
item.Add(reader.GetName(i), reader.IsDBNull(i) ? null : reader.GetValue(i));
|
|
|
|
|
}
|
|
|
|
|
value.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(ex.ToString());
|
|
|
|
|
#if DEBUG
|
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
#endif
|
|
|
|
|
code = 1;
|
|
|
|
|
message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonSerializer.Serialize(new
|
|
|
|
|
{
|
|
|
|
|
code,
|
|
|
|
|
message,
|
|
|
|
|
value = value,
|
|
|
|
|
}, jsonSerializerOptions);
|
|
|
|
|
});
|
|
|
|
|
WebView2Interop.FuncList.Add("executeCommand", o =>
|
|
|
|
|
{
|
|
|
|
|
var code = 0;
|
|
|
|
|
var message = "操作成功";
|
|
|
|
|
var value = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = new List<object>();
|
|
|
|
|
using var db = new AppDbContext();
|
|
|
|
|
using var cmd = db.Database.GetDbConnection().CreateCommand();
|
|
|
|
|
cmd.CommandText = o["sql"];
|
|
|
|
|
db.Database.OpenConnection();
|
|
|
|
|
value = cmd.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(ex.ToString());
|
|
|
|
|
#if DEBUG
|
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
#endif
|
|
|
|
|
code = 1;
|
|
|
|
|
message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonSerializer.Serialize(new
|
|
|
|
|
{
|
|
|
|
|
code,
|
|
|
|
|
message,
|
|
|
|
|
value = value,
|
|
|
|
|
}, jsonSerializerOptions);
|
|
|
|
|
});
|
|
|
|
|
WebView2Interop.FuncList.Add("executeScalar", o =>
|
|
|
|
|
{
|
|
|
|
|
var code = 0;
|
|
|
|
|
var message = "操作成功";
|
|
|
|
|
object value = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = new List<object>();
|
|
|
|
|
using var db = new AppDbContext();
|
|
|
|
|
using var cmd = db.Database.GetDbConnection().CreateCommand();
|
|
|
|
|
cmd.CommandText = o["sql"];
|
|
|
|
|
db.Database.OpenConnection();
|
|
|
|
|
value = cmd.ExecuteScalar();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(ex.ToString());
|
|
|
|
|
#if DEBUG
|
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
#endif
|
|
|
|
|
code = 1;
|
|
|
|
|
message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonSerializer.Serialize(new
|
|
|
|
|
{
|
|
|
|
|
code,
|
|
|
|
|
message,
|
|
|
|
|
value = value,
|
|
|
|
|
}, jsonSerializerOptions);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CoreWebView2_WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e)
|
|
|
|
|