222
schangxiang@126.com
2025-09-29 f782248da68c035aae12f902f29d828e9867abb0
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
using iWareCc.DecomposeTask.Entity;
using iWareCc.Properties;
using iWareCc.Srm.Entity;
using iWareCommon.Common.Entity;
using iWareCommon.Common.EnumType;
using iWareCommon.Utils;
using iWareDataCore.ORM;
using iWareDataCore.TASK.EnumType;
using iWareLog.ORM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareCc.FinishStackerTask.Chain
{
    public class 保存出入库明细信息 : IHandler
    {
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        private StackerEntity Stacker;
 
        /// <summary>
        /// 任务容器
        /// </summary>
        private PartTaskContainer DecompositionTaskContainer;
 
 
        public 保存出入库明细信息(StackerEntity stacker, PartTaskContainer decompositionTaskContainer)
        {
            this.Stacker = stacker;
            this.DecompositionTaskContainer = decompositionTaskContainer;
        }
 
 
        public void Handle()
        {
            using (var dbModel = new DbModelLog())
            {
                try
                {
                    var task = DecompositionTaskContainer.PartTask;
                    int materid = 0;
                    using (var dbModelcore = new DbModelCore())
                    {
                        var mater = dbModelcore.BASEMaterials.FirstOrDefault(x => x.code == task.MaterialCode);
                        if (mater != null)
                        {
                            materid = mater.id;
                        }
                    }
                    ;
                    int tp = 0;
                    int? _isSendToMes = null;//是否发送给MES 【Editby shaocx,2025-09-25】
                    switch (task.MainTaskType)
                    {
                        case (int)EMainTaskType.入库任务:
                            tp = 0;
                            _isSendToMes = (int)EIsSendToMes.待推送;
                            break;
                        case (int)EMainTaskType.出库任务:
                            tp = 1;
                            _isSendToMes = (int)EIsSendToMes.待推送;
                            break;
                        case (int)EMainTaskType.移库任务:
                            tp = 2;
                            task.IsHandled = (int)EYesOrNo.是;
                            break;
                        default:
                            tp = 3;
                            task.IsHandled = (int)EYesOrNo.是;
                            break;
                    }
                    InOutStorageDetail iosd = new InOutStorageDetail()
                    {
                        fromplacecode = task.SourcePlace,
                        formplaceid = task.SourcePlaceId,
                        toplacecode = task.ToPlace,
                        toplaceid = task.ToPlaceId,
                        equipid = task.EquipId,
                        equipname = task.EquipName,
                        updatetime = DateTime.Now,
                        createtime = task.CreateTime,
                        materialcode = task.MaterialCode,
                        materialid = materid,
                        type = tp,
                        isSendToMes = _isSendToMes //是否发送给MES 【Editby shaocx,2025-09-25】
                    };
                    dbModel.InOutStorageDetails.Add(iosd);
                    dbModel.SaveChanges();
                    LogTextHelper.WriteLine(Resources.LogDir + @"/完成堆垛机任务/" + Stacker.Equipment.EquipName, "保存出入库明细信息:{0}", task.Id);
 
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
 
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLine(Resources.LogDir + @"/完成堆垛机任务/" + Stacker.Equipment.EquipName, "保存出入库明细信息:{0}", ex.Message);
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            }
        }
    }
}