schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
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
using DataRWDAL.Base;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using XImagingXhandler.XDAL;
 
namespace DataRWDAL
{
    /// <summary>
    /// 获取液体类型库表操作类
    /// </summary>
    public class LiquidTypeDB:BaseDB
    {
        #region 查询返回液体类型数据集 by 查询请求类型
        /// <summary>
        /// 查询返回液体类型数据集 by 查询请求类型
        /// </summary>
        /// <param name="lType">1:默认类型;0:非默认;2:全部类型</param>
        /// <returns>液体类型数据集</returns>
        public static ObservableCollection<LiquidType> GetLiquidTypeFromdb(int lType)
        {
            using (var db = GetInstance())
            {
                if (lType == 1 || lType == 0)
                {
                    return new ObservableCollection<LiquidType>(db.Queryable<LiquidType>().Where(it => it.is_default_type.Equals(lType)
                                                         && it.liquid_type_status.Equals(1)).OrderBy(it => it.timestamp, SqlSugar.OrderByType.Asc).ToList());
                }
                else if (lType == 2)
                {
                    return new ObservableCollection<LiquidType>(db.Queryable<LiquidType>().Where(it => it.liquid_type_status.Equals(1)).OrderBy(it => it.timestamp, SqlSugar.OrderByType.Asc).ToList());
                }
                else
                {
                    return null;
                }
            }
        }
        #endregion
 
        #region 添加一条新的液体类型数据 by 液体类型数据
        /// <summary>
        /// 添加一条新的液体类型数据 by 液体类型数据
        /// </summary>
        /// <param name="liquidType">液体类型对象</param>
        /// <returns>1:成功;0:失败</returns>
        public static int AddLiquidTypeIntodb(LiquidType liquidType)
        {
            using (var db = GetInstance())
            {
                var result = 0;
                db.BeginTran(); // 开启事务
                try
                {
                    result = db.Insertable<LiquidType>(liquidType).ExecuteCommand();
                    db.CommitTran(); // 提交事务
                }
                catch (Exception ex)
                {
                    db.RollbackTran(); // 事务回滚
                                       // 处理异常
                    result = 0;
                }
                return result;
            }
        }
        #endregion
    }
}