lixiaojun
2022-08-04 afa723170f1547f7fdb8528f5ae12cf941d3e375
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
80
81
82
83
84
85
86
87
88
89
90
91
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
 
namespace IStation.DAL
{
    /// <summary>
    /// Epanet文件
    /// </summary>
    public partial class EpanetFile : CorpTraceDAL<Entity.EpanetFile>
    {
        /// <summary>
        /// 
        /// </summary>
        public override ConnectionConfig ConnectionConfig
        {
            get { return ConfigHelper.DefaultConnectionConfig; }
        }
 
 
        /// <summary>
        /// 通过 BelongType 和 BelongID 获取
        /// </summary>
        public List<Entity.EpanetFile> GetByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID) 
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.EpanetFile>() 
                    .Where(x => x.CorpID == CorpID && x.BelongType == BelongType && x.BelongID == BelongID).ToList();
            }
        }
 
        /// <summary>
        /// 更新存储编码
        /// </summary>
        public bool UpdateStorageCode(long CorpID, long ID, string StorageCode, long UpdateUserID, DateTime UpdateTime) 
        {
            using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Updateable<Entity.EpanetFile>()
                    .SetColumns(x => x.StorageCode == StorageCode)
                    .SetColumns(x => x.UpdateUserID == UpdateUserID)
                    .SetColumns(x => x.UpdateTime == UpdateTime)
                    .Where(x => x.CorpID == CorpID && x.ID == ID)
                    .ExecuteCommand() > 0;
            }
        }
 
        /// <summary>
        /// 设置工作文件
        /// </summary>
        public bool SetWorking(long CorpID, string BelongType, long BelongID, long ID, long UpdateUserID, DateTime UpdateTime)
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                try
                {
                    db.BeginTran();
                    var bol = db.Updateable<Entity.EpanetFile>()
                        .SetColumns(x => x.IsWorking == true)
                        .SetColumns(x => x.UpdateUserID == UpdateUserID)
                        .SetColumns(x => x.UpdateTime == UpdateTime)
                        .Where(x => x.CorpID == CorpID && x.BelongType == BelongType && x.BelongID == BelongID && x.ID == ID).ExecuteCommand() > 0;
                    if (!bol)
                    {
                        db.RollbackTran();
                        return false;
                    }
                    db.Updateable<Entity.EpanetFile>()
                        .SetColumns(x => x.IsWorking == false)
                        .SetColumns(x => x.UpdateUserID == UpdateUserID)
                        .SetColumns(x => x.UpdateTime == UpdateTime)
                        .Where(x => x.CorpID == CorpID && x.BelongType==BelongType&&x.BelongID==BelongID && x.ID != ID).ExecuteCommand();
                    db.CommitTran();
                    return true;
                }
                catch
                {
                    db.RollbackTran();
                    throw;
                }
            }
        }
 
 
 
 
    }
}