add
zongzhibin
2024-11-30 752fd1d6f70afc3f58eca4ab2e6b9359ba2a5578
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
using iWareSql;
using iWareSql.Orm;
using iWareSql.DBModel;
 
namespace iWareSql.DataAccess
{
    /// <summary>
    /// 托盘和物料的绑定关系
    /// </summary>
    public class Salver_Material_Handler
    {
 
        /// <summary>
        /// 根据 ContainerId 寻找 Base_Salver_V_Material 对象
        /// </summary>
        /// <param name="edm"></param>
        /// <param name="placeId"></param>
        /// <returns></returns>
        public static Base_Salver_V_Material GetIVCByContainerId(DbModel edm, string ContainerId)
        {
            var items = edm.Base_Salver_V_Material.Where(x => x.SalverId == ContainerId);
            if (items != null)
            {
                var readItems = items.ToList();
                if (readItems == null)
                {
                    return null;
                }
                else
                {
                    if (readItems.Count > 1)
                    {
                        throw new Exception("同一个ContainerId:" + ContainerId + "关联了" + readItems.Count + "个 Base_Salver_V_Material 数据!");
                    }
                    else if (readItems.Count == 1)
                    {
                        return readItems[0];
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            else
            {
                return null;
            }
        }
 
        /// <summary>
        /// 通过ItemId获取IVC数据
        /// </summary>
        /// <param name="edm"></param>
        /// <param name="mat"></param>
        public static Base_Salver_V_Material GetIVCByItemId(DbModel edm, string itemId)
        {
            Base_Salver_V_Material ivc = null;
            var ivcs = edm.Base_Salver_V_Material.Where(x => x.MaterialId == itemId.ToString());
            if (ivcs == null)
            {
                throw new Exception(string.Format("根据itemId:{0}没有找到ivc数据", itemId));
            }
            else
            {
                if (ivcs.Count() == 1)
                {
                    ivc = ivcs.FirstOrDefault();
                }
                else
                {
                    throw new Exception(string.Format("根据itemId:{0}找到{1}条ivc数据", itemId, ivcs.Count()));
                }
            }
            return ivc;
        }
 
        /// <summary>
        /// 创建一个托盘和物料的绑定关系
        /// </summary>
        /// <param name="ctn"></param>
        /// <param name="item"></param>
        /// <param name="remark">备注</param>
        /// <returns></returns>
        public static bool CreateCvIRelation(string userName, Base_Salver ctn, Base_Material item, string remark)
        {
            using (DbModel edm = new DbModel())
            {
                CreateCvIRelation(edm, userName, ctn, item, remark);
                int i = edm.SaveChanges();
                return i > 0 ? true : false;
            };
        }
 
        /// <summary>
        /// 创建一个托盘和物料的绑定关系
        /// </summary>
        /// <param name="ctn"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public static void CreateCvIRelation(DbModel edm, string userName, Base_Salver salver, Base_Material item, string remark)
        {
            Base_Salver_V_Material cvI = new Base_Salver_V_Material()
            {
                Id = Guid.NewGuid().ToString(),
 
                MaterialId = item.Id,
                MaterialName = item.OrderNo,
 
 
                SalverId = salver.Id,
                SalverCode = salver.SalverCode,
                OperationRemark = remark,
                CreateTime = DateTime.Now,
                CreateBy = userName,
                ModifyBy = userName,
                ModifyTime = DateTime.Now
            };
            edm.Base_Salver_V_Material.Add(cvI);
        }
        /// <summary>
        /// 检验此上料单是否已经做过(有CVI关系的视为已经做过)
        /// </summary>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public static bool IsAlsoDone(string itemId)
        {
            using (DbModel edm = new DbModel())
            {
                var cvi = edm.Base_Salver_V_Material.FirstOrDefault(x => x.MaterialId == itemId);
 
                if (cvi != null)
                    return true;
                else
                    return false;
            }
        }
 
    }
}