duheng
2024-11-17 a2a57963e160a319276c5c8499f16c9809056e4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using Yw.DAL.SQLite;
 
namespace HStation.DAL.SQLite
{
    /// <summary>
    ///
    /// </summary>
    public partial class AssetsPumpGroup : BaseDAL_Paras_Flags_TagName_Sorter<Entity.AssetsPumpGroup>, IAssetsPumpGroup
    {
        /// <summary>
        ///
        /// </summary>
        public override ConnectionConfig ConnectionConfig
        {
            get { return Assets.ConfigHelper.SQLiteConnectionConfig; }
        }
 
        //删除拓展
        public bool DeleteEx(long ID)
        {
            if (ID < 0)
            {
                return default;
            }
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                try
                {
                    db.BeginTran();
                    var group = db.Queryable<Entity.AssetsPumpGroup>().ToList().Find(x => x.ID == ID);
                    var groupresult = db.Deleteable(group).ExecuteCommand() > 0;
                    if (!groupresult)
                    {
                        db.RollbackTran();
                        return default;
                    }
                    else
                    {
                        var idlist = db.Queryable<Entity.AssetsPumpGroupAndMainMapping>()
                        .Where(x => x.GroupID == group.ID)
                        .Select(x => x.MainID) // 假设 GroupID 是与 AssetsPumpMain 关联的外键
                        .ToList();
                        var main = db.Queryable<Entity.AssetsPumpGroupAndMainMapping>()
                       .Where(x => x.GroupID == group.ID)
                        .ToList();
                        if (main.Count > 0)
                        {
                            var Modelresult = db.Deleteable(main).ExecuteCommand() > 0;
                            if (!Modelresult)
                            {
                                db.RollbackTran();
                                return default;
                            }
                            else
                            {
                                var Map = db.Queryable<Entity.AssetsPumpMain>().ToList();
                                var Mapresult = db.Deleteable<Entity.AssetsPumpMain>()
                                .In(x => x.ID, idlist)
                                .ExecuteCommand() > 0;
                                if (!Mapresult)
                                {
                                    db.RollbackTran();
                                    return default;
                                }
                            }
                        }
                    }
                    db.CommitTran();
                    return groupresult;
                }
                catch (Exception ex)
                {
                    db.RollbackTran();
                    throw;
                }
            }
        }
    }
}