杨前锦
2025-07-07 c8f338feee0b6003d8f069b1d37fd9b90dd1b7f4
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using HH.WCS.Mobox3.YNJT_BZP.models.other;
using HH.WCS.Mobox3.YNJT_BZP.util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static HH.WCS.Mobox3.YNJT_BZP.dispatch.NDC;
 
namespace HH.WCS.Mobox3.YNJT_BZP.wms {
    /// <summary>
    /// 容器帮助类
    /// </summary>
    internal class ContainerHelper {
        internal static string GenerateCntrNo() {
            var id = SYSHelper.GetSerialNumber("托盘号", "TP");
            var date = DateTime.Now.ToString("yyMMdd");
            return $"TP{date}{id.ToString().PadLeft(4, '0')}";
        }
        
        
        /// <summary>
        /// 判断容器是否有物料信息
        /// </summary>
        /// <param name="cntr"></param>
        /// <returns></returns>
        internal static bool CheckEmpty(string cntr) {
            //1.0 查货位容器表
            var db = new SqlHelper<object>().GetInstance();
            return db.Queryable<LocCntrRel>().Count(a => a.S_LOC_CODE.Trim() == cntr) == 0;
 
        }
 
        internal static bool AddCntr(string cntrCode ,int type)
        {
            var res = true;
            var db = new SqlHelper<object>().GetInstance();
            try
            {
               var TN_Container = new Container { S_CODE = cntrCode, N_TYPE = type };
               TN_Container.S_TYPE = Container.GetStateStr(type);
               res = db.Insertable<Container>(TN_Container).ExecuteCommand() > 0;
            }
            catch (Exception ex)
            {
                res = false;
            }
            return res;
        }
 
        /// <summary>
        /// 根据容器号获取容器信息
        /// </summary>
        /// <param name="cntr"></param>
        /// <returns></returns>
        internal static Container GetCntr(string cntr) {
            var db = new SqlHelper<object>().GetInstance();
            return db.Queryable<Container>().Where(a => a.S_CODE == cntr).First();
        }
 
        /// <summary>
        /// 根据容器获取物料信息
        /// </summary>
        /// <param name="cntr"></param>
        /// <returns></returns>
        internal static List<CntrItemRel> GetCntrItemRel(string cntr) {
            var db = new SqlHelper<object>().GetInstance();
            var list = db.Queryable<CntrItemRel>().Where(a => a.S_CNTR_CODE == cntr).ToList();
            return list;
        }
 
        internal static bool addCntrItem(string cntrCode, CntrItemRel cntrItemRel)
        {
            var res = false;
            var db = new SqlHelper<object>().GetInstance();
            try
            {
                db.BeginTran();
                var container = db.Queryable<Container>().Where(a => a.S_CODE == cntrCode).First();
                if (container == null)
                {
                    container = new Container { S_CODE = cntrCode, N_DETAIL_COUNT = 1 };
                    db.Insertable(container).ExecuteCommand();
                }
                else 
                {
                    container.N_DETAIL_COUNT = 1;
                    db.Updateable(container).ExecuteCommand();
                }
                res = db.Insertable<CntrItemRel>(cntrItemRel).ExecuteCommand() > 0;
                db.CommitTran();
                res = true;
            }
            catch (Exception ex)
            {
                db.RollbackTran();
                Console.WriteLine(ex.Message);
            }
 
            return res;
        }
 
        internal static bool deleteCntrItem(string cntrCode)
        {
            var res = false;
            var db = new SqlHelper<object>().GetInstance();
            try
            {
                db.BeginTran();
                res = db.Deleteable<CntrItemRel>().Where(a => a.S_CNTR_CODE == cntrCode).ExecuteCommand() > 0;
                db.CommitTran();
                res = true;
            }
            catch (Exception ex)
            {
                db.RollbackTran();
                Console.WriteLine(ex.Message);
            }
            return res;
        }
 
    }
}