alielie
2025-05-12 7bf89fd93bc487e8445d6d85bb527251b7371a04
HMI.MenuManage/Model/MenuManageModel.cs
@@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.Data;
using System.IO;
using System.Linq;
using HMI.Core.Entity;
using HMI.Core.Util;
using HMI.MenuManage.Entity;
@@ -47,12 +48,14 @@
                    id INTEGER PRIMARY KEY AUTOINCREMENT,
                    code TEXT NOT NULL,
                    name TEXT NOT NULL,
                    icon TEXT,
                    iconPath TEXT,
                    level TEXT,
                    type TEXT,
                    parentCode TEXT,
                    dllPath TEXT,
                    className TEXT,
                    sort REAL,
                    UNIQUE(code)
                    );");
        }
@@ -61,7 +64,7 @@
        {
            ObservableCollection<MenuData> data = new ObservableCollection<MenuData>();
            ObservableCollection<MenuData> treeData = new ObservableCollection<MenuData>();
            DataTable dt = sqliteHelper.GetDataTable("SELECT m1.*,m2.name AS parentName FROM menu AS m1 LEFT JOIN menu AS m2 ON m1.parentCode = m2.code Order By m1.id;");
            DataTable dt = sqliteHelper.GetDataTable("SELECT m1.*,m2.name AS parentName FROM menu AS m1 LEFT JOIN menu AS m2 ON m1.parentCode = m2.code Order By m1.sort,m1.id;");
            Dictionary<string, MenuData> cache = new Dictionary<string, MenuData>();
            if (dt != null)
            {
@@ -72,13 +75,14 @@
                        Id = dr["id"].ToString(),
                        Code = dr["code"].ToString(),
                        Name = dr["name"].ToString(),
                        IconPath = dr["iconPath"].ToString(),
                        Icon = dr["icon"].ToString(),
                        Level = dr["level"].ToString(),
                        Type = dr["type"].ToString(),
                        ParentCode = dr["parentCode"].ToString(),
                        ParentName = dr["parentName"].ToString(),
                        DllPath = dr["dllPath"].ToString(),
                        ClassName = dr["className"].ToString()
                        ClassName = dr["className"].ToString(),
                        Sort = dr["sort"] == DBNull.Value ? 0 : double.Parse(dr["sort"].ToString()),
                    };
                    data.Add(menu);
                    if (menu.Level == "1")
@@ -103,8 +107,15 @@
        public void DeleteMenuById(string id)
        {
            string sql = $"DELETE FROM menu WHERE id = {id}";
            string sql = $"DELETE FROM menu WHERE id = {id};";
            sqliteHelper.ExecuteSql(sql);
        }
        public void DeleteMenuByIds(IEnumerable<string> ids)
        {
            List<string> sqls = ids.Select(id => $"DELETE FROM menu WHERE id = {id};")
                .ToList();
            sqliteHelper.ExecuteBatchSql(sqls);
        }
    }
}