129 lines
4.7 KiB
C#
129 lines
4.7 KiB
C#
|
using Newtonsoft.Json.Linq;
|
|||
|
using ryCommon;
|
|||
|
using ryCommonDb;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
|
|||
|
namespace SuperDesign.Tools.UpLog
|
|||
|
{
|
|||
|
public partial class FrmGroupSelected : Form
|
|||
|
{
|
|||
|
public FrmGroupSelected()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
OlvGroup.AspectGetter = delegate (object x) { return ((GroupInfo)x).GroupName; };
|
|||
|
}
|
|||
|
public string ProjectName { get; set; }
|
|||
|
public string DbPath { get; set; }
|
|||
|
public string SelectedGroupName { get; private set; } = "";
|
|||
|
class GroupInfo
|
|||
|
{
|
|||
|
public string GroupName { get; set; }
|
|||
|
public long Time { get; set; }
|
|||
|
}
|
|||
|
|
|||
|
private void ObjectListView1_MouseDoubleClick(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
if (objectListView1.SelectedObject == null) { return; }
|
|||
|
var item = (GroupInfo)objectListView1.SelectedObject;
|
|||
|
SelectedGroupName = item.GroupName;
|
|||
|
DialogResult = DialogResult.OK;
|
|||
|
}
|
|||
|
|
|||
|
private void FrmGroupSelected_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
IDbInterface db = new SQLiteDataProvider();
|
|||
|
if (db.ConnDb(DbPath) == 1)
|
|||
|
{
|
|||
|
JObject jo_group;
|
|||
|
try
|
|||
|
{
|
|||
|
var ds_group = db.ReadData("select * from Settings where Name='GroupList'");
|
|||
|
if (ds_group.HaveData())
|
|||
|
{
|
|||
|
jo_group = JObject.Parse(ds_group.GetRow(0)["Value"].ToString());
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
jo_group = new JObject();
|
|||
|
}
|
|||
|
ds_group?.Dispose();
|
|||
|
}
|
|||
|
catch { jo_group = new JObject(); }
|
|||
|
var jarr_group = jo_group.GetJsonValue("group_" +ProjectName, new JArray());
|
|||
|
List<GroupInfo> list = new List<GroupInfo>();
|
|||
|
for (int i = 0; i < jarr_group.Count; i++)
|
|||
|
{
|
|||
|
list.Add(new GroupInfo()
|
|||
|
{
|
|||
|
GroupName = jarr_group[i].GetJsonValue("text",""),
|
|||
|
Time = jarr_group[i].GetJsonValue("time", 0L),
|
|||
|
});
|
|||
|
}
|
|||
|
objectListView1.AddObjects(list);
|
|||
|
}
|
|||
|
db.Free();
|
|||
|
}
|
|||
|
|
|||
|
private void BtnDel_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (objectListView1.SelectedObject == null) {
|
|||
|
MessageBox.Show("请选择分组。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|||
|
return;
|
|||
|
}
|
|||
|
if (MessageBox.Show("是否确认要删除该分组?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
var item = (GroupInfo)objectListView1.SelectedObject;
|
|||
|
IDbInterface db = new SQLiteDataProvider();
|
|||
|
if (db.ConnDb(DbPath) == 1)
|
|||
|
{
|
|||
|
JObject jo_group;
|
|||
|
try
|
|||
|
{
|
|||
|
var ds_group = db.ReadData("select * from Settings where Name='GroupList'");
|
|||
|
if (ds_group.HaveData())
|
|||
|
{
|
|||
|
jo_group = JObject.Parse(ds_group.GetRow(0)["Value"].ToString());
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
jo_group = new JObject();
|
|||
|
}
|
|||
|
ds_group?.Dispose();
|
|||
|
}
|
|||
|
catch { jo_group = new JObject(); }
|
|||
|
var jarr_group = jo_group.GetJsonValue("group_" + ProjectName, new JArray());
|
|||
|
for (int i = 0; i < jarr_group.Count; i++)
|
|||
|
{
|
|||
|
if(jarr_group[i].GetJsonValue("text", "")==item.GroupName)
|
|||
|
{
|
|||
|
jarr_group[i].Remove();
|
|||
|
objectListView1.RemoveObject(item);
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
jo_group["group_" + ProjectName] = jarr_group;
|
|||
|
RyQuickSQL MySQL_Setting = new RyQuickSQL("Settings");
|
|||
|
MySQL_Setting.AddField("Name", "GroupList");
|
|||
|
MySQL_Setting.AddField("Value", jo_group.ToString());
|
|||
|
MySQL_Setting.AddField("EditTime", DateTime.Now);
|
|||
|
if (db.Update(MySQL_Setting, "Name=@Name") == 0)
|
|||
|
{
|
|||
|
MySQL_Setting.AddField("AddTime", DateTime.Now);
|
|||
|
db.Insert(MySQL_Setting);
|
|||
|
}
|
|||
|
}
|
|||
|
db.Free();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|