schangxiang@126.com
2025-09-17 ff43ddf18764629ff875478e4e47a7281cbd230a
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using Admin.NET.Core;
using Admin.NET.Core.QualityControl.Enum;
using Admin.NET.Core.WareHouse.Enum;
using iWareSql.MyDbContext;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
 
namespace Admin.NET.Application
{
    public class MyCommonHelper
    {
 
        /// <summary>
        /// 生产配餐单备注计划生产月 转换日期格式,/将    格式ddmm 转换为日期类型
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DateTime ConvertToDateTimeForDDMMByKittingRemark(string str)
        {
            try
            {
                //将    格式dd/mm/yyyy 转换为日期类型
                str = str.Trim();
                if (str.Length != 6)//牧野约定备注日期填6位罗马数字 比如:202403 
                {
                    throw new System.Exception($"日期类型格式不正确,应该是长度6位的年月罗马数字,实际是{str}!");
                }
                var year = str.Substring(0, 4); //前4位是年纷
                var month = str.Substring(str.Length - 2);//后两位是月份
 
                int i_month, i_year = 0;
                bool isSu = int.TryParse(month, out i_month);
                if (isSu == false)
                {
                    throw new System.Exception($"月'{month}'格式不正确!");
                }
                isSu = int.TryParse(year, out i_year);
                if (isSu == false)
                {
                    throw new System.Exception($"年'{year}'格式不正确!");
                }
 
 
                if (i_month < 1 || i_month > 12)
                {
                    throw new System.Exception($"月'{i_month}'不在正确范围内!");
                }
 
 
                string dateString = string.Format("{0}-{1}",//得到日期字符串
                    year, month);
 
 
                DateTime result = DateTime.ParseExact(dateString, "yyyy-MM", CultureInfo.InvariantCulture);
                return result;
            }
            catch (Exception ex)
            {
 
                throw new System.Exception($"日期{str}转换异常:" + ex.Message);
            }
        }
 
        /// <summary>
        ///  获取展示用的生产配餐单备注计划生产月字符串 
        /// </summary>
        /// <param name="PlannedProductionYear"></param>
        /// <param name="PlannedProductionMonth"></param>
        /// <returns></returns>
        public static string GetPlannedProductionDate(int PlannedProductionYear, int PlannedProductionMonth)
        {
            if (PlannedProductionYear > 0 && PlannedProductionMonth > 0)
            {
                string year = PlannedProductionYear.ToString();
                string month = PlannedProductionMonth.ToString();
                if (month.Length == 1) // 单月前面补全0
                {
                    month = "0" + month;
                }
                return month + "-" + year;
            }
 
 
            return string.Empty;
        }
 
        /// <summary>
        /// 根据物料编号获取物料基础信息 【Editby shaocx,2023-07-25】
        /// </summary>
        /// <param name="_ware_materialRep"></param>
        /// <param name="materialCode"></param>
        /// <returns></returns>
        public static ware_material GetWareMaterialInfo(MyDbContext dbContext, string materialCode)
        {
            var material = dbContext.ware_material.Where(x => x.Code == materialCode).FirstOrDefault();
            if (material == null)
            {
                throw new System.Exception($"物料基础信息没有找到物料编号为{materialCode}的信息!");
            }
            return material;
        }
 
        /// <summary>
        /// 根据物料编号获取物料基础信息 【Editby shaocx,2023-07-25】
        /// </summary>
        /// <param name="_ware_materialRep"></param>
        /// <param name="materialCode"></param>
        /// <returns></returns>
        public static ware_material GetWareMaterialInfo( List<ware_material> _list, string materialCode)
        {
            var material = _list.Where(x => x.Code == materialCode).FirstOrDefault();
            if (material == null)
            {
                throw new System.Exception($"物料基础信息没有找到物料编号为{materialCode}的信息!");
            }
            return material;
        }
 
        /// <summary>
        /// 根据物料编号获取物料基础信息 【Editby shaocx,2023-07-25】
        /// </summary>
        /// <param name="_ware_materialRep"></param>
        /// <param name="materialCode"></param>
        /// <returns></returns>
        public static List<ware_material> GetWareMaterialInfoList(MyDbContext dbContext)
        {
            var material = dbContext.ware_material.ToList();
            return material;
        }
 
        /// <summary>
        /// 获取发货记录  不能用于撤销
        /// </summary>
        /// <param name="ware_material"></param>
        /// <param name="_deliveryOrderDetails"></param>
        /// <param name="records"></param>
        /// <param name="orderNo"></param>
        /// <param name="sortingNo"></param>
        /// <param name="equipment"></param>
        /// <param name="process"></param>
        /// <param name="img"></param>
        /// <param name="deliveryRecordInput"></param>
        /// <returns></returns>
        public static WareDeliveryInfo GetWareDeliveryRecord(
            MyDbContext dbContext,
            ref List<ware_common_sap_delivery_info> ware_common_sap_delivery_infos,
            ware_material ware_material,
            List<ware_container_vs_material> records,
            string orderNo,
            string sortingNo,
            string equipment,
            string process,
            string img, ware_orders_details ordersDetail)
        {
            List<ware_delivery_record> ware_delivery_records = new List<ware_delivery_record>();
 
            WareDeliveryInfo returnInfo = new WareDeliveryInfo();
 
            returnInfo.WareDeliveryRecords = new List<ware_delivery_record>();
 
            var orderType = SysAllOrderTypeEnum.生产出库单;
            foreach (var item in records)
            {
                long Id = Yitter.IdGenerator.YitIdHelper.NextId();
 
                var ware_delivery_record = new ware_delivery_record()
                {
                    Id = Id,
                    MaterialCode = ordersDetail.WareMaterialCode,
                    MaterialName = ware_material.Name,
                    Quantity = (decimal)item.Quantity,
                    OrderNo = orderNo,
                    BatchNo = item.BarNo,
                    Sap_Location = item.Sap_Location,
                    SortingNo = sortingNo,
                    Equipment = equipment,
                    Process = process,
                    OrderType = (int)orderType,
                    Unit = ware_material.Unit,//单位
                    LineNumber = ordersDetail.LineNumber,//行号
                    SAP_ConfirmStatus = (int)EnumSAPConfirmStatus.待发送,
                    SAP_CancelConfirmStatus = (int)EnumSAPCancelConfirmStatus.未撤销,
                    //这两个字段必须赋值!
                    OrderDetailId = ordersDetail.Id,//订单详情id
                    //SortOrderDetailId = deliveryRecordInput.SortOrderDetailId,
                    MaterialResvItem = ordersDetail.MaterialResvItem,//Kitting 单预约行号
                    MaterialResvNo = ordersDetail.MaterialResvNo,//Kitting 单预约号
                    SubOrderNo = ordersDetail.SubOrderNo,//Kitting 单号
                    ImgPath = img,
                    CancelStatus = (int)EnumCancelStatus.未撤销,//默认未撤销
                    //增加一些事项 【Editby shaocx,2023-08-02】
                    CheckStatus = item.CheckStatus,
                    SupplierNo = item.SupplierNo,
                    SupplierName = item.SupplierName,
                    PurchaseOrderDetailId = item.PurchaseOrderDetailId,
                    RecordInsertTime = item.RecordInsertTime,
 
 
 
                    Costcenter = ordersDetail.Costcenter//成本中心
 
                };
                ware_delivery_records.Add(ware_delivery_record);
 
                DO_GetWareDeliveryInfo(ref ware_common_sap_delivery_infos, orderType, ware_material, ordersDetail, ware_delivery_record);
            }
            returnInfo.WareDeliveryRecords.AddRange(ware_delivery_records);
 
            return returnInfo;
        }
 
 
        #region 根据发货记录创建sap推送发货记录
 
        /// <summary>
        ///  根据发货记录创建sap推送发货记录 可以用于撤销-DeliveryOrderDetails
        /// </summary>
        /// <param name="ware_common_sap_delivery_infos"></param>
        /// <param name="orderType"></param>
        /// <param name="ware_material"></param>
        /// <param name="ordersDetail"></param>
        /// <param name="ware_delivery_record"></param>
        public static void DO_GetWareDeliveryInfo(ref List<ware_common_sap_delivery_info> ware_common_sap_delivery_infos, SysAllOrderTypeEnum orderType, ware_material ware_material,
            ware_orders_details ordersDetail, ware_delivery_record ware_delivery_record)
        {
 
        }
 
 
 
 
        #endregion
 
 
 
 
    }
}