schangxiang@126.com
2025-09-18 49a51c068d62084bc4c3e77c4be94a20de556c4a
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using iWareSAP.Cache.Entity;
using iWareSAP.IDOC.Entity;
using iWareSAP.PARAM.Entity;
using iWareSAP.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using UtilDll.UTIL;
 
namespace iWareSAP.WCF
{
    // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“SapWcfService”。
    public class SapWcfService : ISapWcfService
    {
        /// <summary>
        /// 根据采购单号获取采购单
        /// </summary>
        /// <param name="poNumber"></param>
        /// <param name="msg"></param>    
        /// <returns></returns>
        public PurchaseOrderEntity GetPurchaseOrder(string poNumber, out string msg)
        {
            try
            {
                msg = "";
                LogTextHelper.WriteLine(Resources.LogDir, "调用接口{0},poNumber={1}", "GetPurchaseOrder", poNumber);
                var po = CacheEntity.SapncoClient.InvokeRFCFunctionGetPoDetail(poNumber, out msg);
                if (!string.IsNullOrEmpty(msg))
                {
                    LogTextHelper.WriteLine(Resources.LogDir, "msg={0}", msg);
                    return null;
                }
                var purchaseOrder = new PurchaseOrderEntity(po);
                if (purchaseOrder != null)
                {
                    LogTextHelper.WriteLine(Resources.LogDir, "purchaseOrder={0}", purchaseOrder);
                }
                return purchaseOrder;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetPurchaseOrder", msg);
                return null;
            }
        }
 
        /// <summary>
        /// 获取采购单的展示字符传
        /// </summary>
        /// <param name="poNumber"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public string GetPurchaseOrderTxt(PurchaseOrderEntity po) 
        {
            return po == null ? "" : po.ToString();        
        }
 
 
 
        /// <summary>
        /// 对收到的物料进行收货确认
        /// </summary>
        /// <param name="grMaterials"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public string ConfirmGR(List<GRMaterialEntity> grMaterials, out string msg)
        {
            try
            {
                msg = "";
                var grStr = "";
                grMaterials.ForEach(x => grStr += x.ToString() + "\r\n");
                LogTextHelper.WriteLine(Resources.LogDir, "调用接口{0},grMaterials={1}", "ConfirmGR", grStr);
                var grs = new List<GRMaterial>();
                grMaterials.ForEach(x => grs.Add(new GRMaterial(x)));
                var materialDoc = CacheEntity.SapncoClient.InvokeRFCFunctionPoGR(grs, out msg);
                if (!string.IsNullOrEmpty(msg))
                {
                    LogTextHelper.WriteLine(Resources.LogDir, "msg={0}", msg);
                }
                else
                {
                    LogTextHelper.WriteLine(Resources.LogDir, "materialDoc={0}", materialDoc);
                }
                return materialDoc;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "ConfirmGR", msg);
                return "";
            }
        }
 
 
        /// <summary>
        /// 对物料进行出库确认
        /// </summary>
        /// <param name="grMaterials"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public string ConfirmGI(List<GIMaterialEntity> giMaterials, out string msg)
        {
            try
            {
                msg = "";
 
                var giStr = "";
                giMaterials.ForEach(x => giStr += x.ToString() + "\r\n");
                LogTextHelper.WriteLine(Resources.LogDir, "调用接口{0},giMaterials={1}", "ConfirmGI", giStr);
                var gies = new List<GIMaterial>();
                giMaterials.ForEach(x => gies.Add(new GIMaterial(x)));
                var materialDoc = CacheEntity.SapncoClient.InvokeRFCFunctionWmsGI(gies, out msg);
                if (!string.IsNullOrEmpty(msg))
                {
                    LogTextHelper.WriteLine(Resources.LogDir, "msg={0}", msg);
                }
                else
                {
                    LogTextHelper.WriteLine(Resources.LogDir, "materialDoc={0}", materialDoc);
                }
                return materialDoc;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "ConfirmGI", msg);
                return "";
            }
        }
 
 
 
        /// <summary>
        /// 对物料进行移库确认
        /// </summary>
        /// <param name="grMaterials"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public string ConfirmMOV(List<MovMaterialEntity> movMaterials, out string msg)
        {
            try
            {
                msg = "";
                var movStr = "";
                movMaterials.ForEach(x => movStr += x.ToString() + "\r\n");
                LogTextHelper.WriteLine(Resources.LogDir, "调用接口{0},movMaterials={1}", "ConfirmMOV", movStr);
                var movs = new List<MovMaterial>();
                movMaterials.ForEach(x => movs.Add(new MovMaterial(x)));
                var materialDoc = CacheEntity.SapncoClient.InvokeRFCFunctionWmsStkMov(movs, out msg);
                if (!string.IsNullOrEmpty(msg))
                {
                    LogTextHelper.WriteLine(Resources.LogDir, "msg={0}", msg);
                }
                else
                {
                    LogTextHelper.WriteLine(Resources.LogDir, "materialDoc={0}", materialDoc);
                }
 
                return materialDoc;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "ConfirmMOV", msg);
                return "";
            }
        }
 
 
        /// <summary>
        /// 根据物料凭证退物料
        /// </summary>
        /// <param name="poNumber"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public string WmsReverser(string doc, out string msg) 
        {
            try
            {
                msg = "";
                LogTextHelper.WriteLine(Resources.LogDir, "调用接口{0},doc={1}", "WmsReverser", doc);
                var res = CacheEntity.SapncoClient.InvokeRFCFunctionWmsReverser(doc, out msg);
                
                LogTextHelper.WriteLine(Resources.LogDir, "res={0},msg={1}", res, msg);
                
              
                
                return res;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "WmsReverser", msg);
                return null;
            }
        }
    }
}