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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
using Admin.NET.Core.EnterWareHouseModule;
using iWareCommon.Utils;
using iWareModel;
using iWareSql.MyDbContext;
using iWareTestForm;
using iWareTestForm.Model;
using Newtonsoft.Json;
using NPOI.SS.Formula.PTG;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace XiGang_iWareTestForm.iWareTest.DialogForm
{
    public partial class TestBatchForm : Form
    {
        delegate void Delegate_SetPostResult2(string content);
        public TestBatchForm()
        {
            InitializeComponent();
        }
 
        private void LoadItemType()
        {
            List<ListItem> itemList = new List<ListItem>();
            itemList.Add(new ListItem()
            {
                Text = "发送机",
                Value = "1"
            });
            itemList.Add(new ListItem()
            {
                Text = "托盘",
                Value = "2"
            });
            foreach (var item in itemList)
            {
                this.cmbItemType.Items.Add(item);
            }
 
            cmbItemType.SelectedIndex = 1;
        }
 
        /// <summary>
        /// 显示请求结果
        /// </summary>
        /// <param name="content"></param>
        private void ShowResult(string content)
        {
 
            if (this.tb_Log.InvokeRequired)
            {
                Delegate_SetPostResult2 delegate_SetPostResult = new Delegate_SetPostResult2(ShowResult);
                this.Invoke(delegate_SetPostResult, new object[] { content });
            }
            else
            {
                //content += "\r\n";
                this.tb_Log.Text = StringHelper.GetLog(content) + this.tb_Log.Text;
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            //ClearPlace();
        }
 
 
 
        private void TestBatchForm_Load(object sender, EventArgs e)
        {
            LoadItemType();
            this.tb_SalverCount.Text = "1";
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            //测试打印
            ShowResult($"开始打印");
            Dictionary<string, object> data = new Dictionary<string, object>();
            data.Add("bar", "heihei");
            data.Add("material", "heihei");
            data.Add("supplier", "heihei");
            data.Add("unit", "heihei");
            data.Add("date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
 
            //调用打印接口
            bool isSuccess = false;
            string errMsg = "";
            using (iWareTestForm.PrintBaseService.PrintWcfServiceClient client = new iWareTestForm.PrintBaseService.PrintWcfServiceClient())
            {
                isSuccess = client.Print3(data, 1, @"D:\打印程序\跟踪码打印模板\跟踪码打印模板_一维码.btw", "ZDesigner ZD888-203dpi ZPL", out errMsg);
            }
            if (isSuccess)
            {
                ShowResult($"打印成功");
            }
            else
            {
                ShowResult($"打印失败:" + errMsg);
            }
 
 
        }
 
        /// <summary>
        /// 生成批次号
        /// </summary>
        /// <param name="prefix"></param>
        /// <returns></returns>
        public string CreateBatchNo(string prefix)
        {
            string BarNo = "WH" + Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).Ticks.ToString();
            return BarNo;
        }
 
 
        private List<string> GetString()
        {
            List<String> list = new List<string>();
            list.Add("2-01-10-02".Trim());
            list.Add("1-01-04-01".Trim());
 
            list.Add("1-01-06-04".Trim());
 
            return list;
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            ////零件归还管理增加
            //List<ware_sorting_details> ware_Sorting_Details = new List<ware_sorting_details>();
 
            ////借用单库存增加
            //using (MyDbContext dbContext = new MyDbContext())
            //{
 
            //    //获取所有 借用单的明细
            //    var orders = dbContext.ware_orders.Where(x => x.OrderType == "11" && x.OrderNo == "借用" && (x.IsDeleted == null || x.IsDeleted == false)).ToList();
            //    var ids = orders.Select(y => y.Id).ToList();
            //    var details = dbContext.ware_orders_details.Where(x => ids.Contains(x.OrdersId) && (x.IsDeleted == null || x.IsDeleted == false)).ToList();
 
 
 
 
            //    // 创建分拣订单
 
            //    var sortingOrder = new ware_sorting
            //    {
            //        Id = Yitter.IdGenerator.YitIdHelper.NextId(),
            //        OrderNo = Yitter.IdGenerator.YitIdHelper.NextId().ToString(),
            //        OrderType = "1",//借用取货单
            //        Remarks = "分拣单创建",
            //        OrderStatus = (int)EnumWarehousStatus.Completed,
            //        IsDeleted = false,
            //        Status = 0
            //    };
 
            //    List<string> str = new List<string>();
            //    List<long> str1 = new List<long>();
            //    foreach (var item in details)
            //    {
            //        ware_Sorting_Details.Add(new ware_sorting_details
            //        {
            //            Status = 0,
            //            Id = Yitter.IdGenerator.YitIdHelper.NextId(),
            //            OrdersId = sortingOrder.Id,
            //            WareContainerCode = "",
            //            WareContainerName = "",
            //            WareMaterialCode = item.WareMaterialCode,
            //            WareMaterialName = "",
            //            Unit = "",
            //            CompleteQuantity = item.Quantity,
            //            Quantity = item.Quantity,
            //            OrderStatus = (int)EnumWarehousStatus.Completed,
            //            DeliveryNo = "借用",
            //            IsDeleted = false
            //        });
            //    }
 
            //    dbContext.ware_sorting.Add(sortingOrder);
            //    dbContext.ware_sorting_details.AddRange(ware_Sorting_Details);
 
            //    dbContext.SaveChanges();
 
            //}
 
            //ShowResult($"新增{ware_Sorting_Details.Count}条");
        }
 
        private void btn_SelectFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = true;
            fileDialog.Title = "请选择文件";
            fileDialog.Filter = "所有文件(*xls*)|*.xls*"; //设置要选择的文件的类型
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string file = fileDialog.FileName;//返回文件的完整路径    
                this.tb_FilePath.Text = file;
            }
        }
 
        private void button2_Click_1(object sender, EventArgs e)
        {
            // 批量导入 客户寄售区库存
            // var name = this.tb_KeHuJiShouKuWei.Text;
            // if (string.IsNullOrEmpty(name))
            // {
            //     MessageBox.Show("请输入客户寄售区名称!");
            //     return;
            // }
            // string filePath = this.tb_FilePath.Text;
            // if (filePath == string.Empty)
            // {
            //     MessageBox.Show("请选择Excel!");
            //     return;
            // }
 
            // Dictionary<string, string> cellheader = new Dictionary<string, string> {
            //         { "MaterialNo", "零件号" },
            //         { "MaterialName", "名称" },
            //         { "Quntity", "数量" }
            //     };
 
            // 1.2解析文件,存放到一个List集合里
            //StringBuilder errorMsg = new StringBuilder(); // 错误信息
            // string tableDesc = "", tableName = "";
            // List<MyMaterial> enlist = ExcelHelper.ExcelToEntityListForCreateTable<MyMaterial>(cellheader, filePath, out tableDesc, out tableName, out errorMsg);
            // if (!string.IsNullOrEmpty(errorMsg.ToString()))
            // {
            //     MessageBox.Show("错误:" + errorMsg.ToString());
            //     return;
            // }
 
            // 汇总数据
            // List<MyMaterial> inertList = new List<MyMaterial>();
            // foreach (var item in enlist)
            // {
            //     if (!string.IsNullOrEmpty(item.MaterialNo))
            //     {
            //         var zz = inertList.Where(x => x.MaterialNo == item.MaterialNo).FirstOrDefault();
            //         if (zz == null)
            //         {
            //             inertList.Add(new MyMaterial()
            //             {
            //                 MaterialNo = item.MaterialNo,
            //                 MaterialName = item.MaterialName,
            //                 Quntity = item.Quntity
            //             });
            //         }
            //         else
            //         {
            //             zz.Quntity += item.Quntity;
            //         }
            //     }
            // }
 
 
            // List<ware_container_vs_material> addList = new List<ware_container_vs_material>();
            // ware_container_vs_material aa = null;
            // using (MyDbContext dbContext = new MyDbContext())
            // {
            //     var ddd = dbContext.ware_location_vs_container.Where(x => x.WareContainerCode == name).FirstOrDefault();
 
            //     if (ddd == null)
            //     {
            //         默认自己写入
            //         ddd = new ware_location_vs_container()
            //         {
            //             Id = Yitter.IdGenerator.YitIdHelper.NextId(),
            //             WareContainerCode = name,
            //             WareContainerName = name,
            //             WareLocationCode = name,
            //             IsEmptyContainer = false,
            //             IsDeleted = false
            //         };
            //         dbContext.ware_location_vs_container.Add(ddd);
            //     }
 
            //     var barno = CreateBatchNo("");
            //     foreach (var item in inertList)
            //     {
            //         aa = new ware_container_vs_material
            //         {
            //             Id = Yitter.IdGenerator.YitIdHelper.NextId(),
            //             locationVsContainerid = ddd.Id,
            //             WareContainerCode = name,
            //             WareMaterialCode = item.MaterialNo,
            //             Quantity = item.Quntity,
            //             PurchaseNo = "",
            //             DeliveryNo = "",
            //             CollectNo = "",
            //             OCCQuantity = 0,
            //             ITEMBATCHNO = "",
            //             OrdersNo = "",//入库单号
            //             Status = 0,
            //             TenantId = null,
            //             CreatedTime = DateTime.Now,
            //             CreatedUserId = CurrentUserInfo.UserId,
            //             CreatedUserName = CurrentUserInfo.Name,
            //             IsLocked = false,
            //             LockRemark = "平库入库,新增物料,初始为false",
            //             DoLockTime = DateTime.Now,
 
            //             IsDeleted = false,
            //             Remarks = "自动插入",
            //             StockStatus = 2,
            //             BarNo = barno,
            //             MaterialType = item.ma,
            //             LocationType = 2,
 
            //             MaterialRegionId = wareRegion.Id,
            //             MaterialRegionCode = wareRegion.Code,
            //             MaterialRegionName = wareRegion.Name
            //             ,
            //             CustomerCode = CustomerCode
            //             ,
            //             MachineToolName = MachineToolName
            //             ,
            //             MachineToolId = MachineToolId,
 
            //             RealWareContainerCode = realWareContainerCode //记录真实的托盘号,用于展示组盘区域中的真实托盘号 [Editby shaocx,2023-01-31]
            //         };
            //         addList.Add(aa);
            //     }
 
            //     dbContext.ware_container_vs_material.AddRange(addList);
 
 
            //     dbContext.SaveChanges();
 
            // }
            // ShowResult($"新增{addList.Count}条");
        }
 
        private void button4_Click(object sender, EventArgs e)
        {
            ////采购单明细中没有行号的赋值为有值
 
            ////零件归还管理增加
            //List<ware_purchase_order_details> orders = new List<ware_purchase_order_details>();
 
            ////借用单库存增加
            //using (MyDbContext dbContext = new MyDbContext())
            //{
 
            //    //获取所有 借用单的明细
            //    orders = dbContext.ware_purchase_order_details.Where(x => (x.EBELP == null || x.EBELP == "")).ToList();
 
            //    foreach (var item in orders)
            //    {
            //        item.EBELP = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
            //    }
 
            //    dbContext.SaveChanges();
            //}
 
            //ShowResult($"新增{orders.Count}条");
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
 
            //List<FunRetEntity> errList = new List<FunRetEntity>();
            //int addCount = 0, updateCount = 0;
 
            ////批量更新容器的栅格数(生产库用)
            //string filePath = this.tb_FilePath.Text;
            //if (filePath == string.Empty)
            //{
            //    MessageBox.Show("请选择Excel!");
            //    return;
            //}
 
            //Dictionary<string, string> cellheader = new Dictionary<string, string> {
            //        { "LocationCode", "库位号" },
            //        { "GridNumber", "栅格数" }
            //    };
 
            //// 1.2解析文件,存放到一个List集合里
            //StringBuilder errorMsg = new StringBuilder(); // 错误信息
            //string tableDesc = "", tableName = "";
            //List<MyLocation> myLocationList = ExcelHelper.ExcelToEntityListForCreateTable<MyLocation>(cellheader, filePath, out tableDesc, out tableName, out errorMsg);
            //if (!string.IsNullOrEmpty(errorMsg.ToString()))
            //{
            //    MessageBox.Show("错误:" + errorMsg.ToString());
            //    return;
            //}
 
 
            //List<ware_container_vs_material> addList = new List<ware_container_vs_material>();
            //ware_container_vs_material aa = null;
            //using (MyDbContext dbContext = new MyDbContext())
            //{
            //    foreach (var item in myLocationList)
            //    {
 
            //        SimulatorCommonHelper.GetGridNumber(item);
 
            //        var los = dbContext.ware_location.Where(x => x.Code == item.LocationCode && (x.IsDeleted == null || x.IsDeleted == false)).ToList();
            //        if (los == null || los.Count == 0)
            //        {
            //            errList.Add(new FunRetEntity()
            //            {
            //                resData = item.LocationCode,
            //                resMsg = $"{item.LocationCode}库位没有找到"
            //            }); ; ;
            //        }
            //        else if (los.Count > 1)
            //        {
            //            //数据不正确
            //            errList.Add(new FunRetEntity()
            //            {
            //                resData = item.LocationCode,
            //                resMsg = $"{item.LocationCode}库位数超过了1条"
            //            }); ; ;
            //        }
 
            //        var ddds = dbContext.ware_container.Where(x => x.Code == item.LocationCode && (x.IsDeleted == null || x.IsDeleted == false)).ToList();
            //        if (ddds == null || ddds.Count == 0)
            //        {
            //            //新增
            //            var add_container = new ware_container()
            //            {
            //                IsDeleted = false,
            //                IsVirtual = 1,
            //                Id = Yitter.IdGenerator.YitIdHelper.NextId(),
            //                Code = item.LocationCode,
            //                Name = item.LocationCode,
            //                CreatedTime = DateTime.Now,
            //                UpdatedTime = DateTime.Now,
            //                CreatedUserName = "系统初始",
            //                UpdatedUserName = "系统初始",
            //                Status = 0,
            //                GridNumber = Convert.ToInt32(item.GridNumber)
            //            };
            //            //计算已占用栅格数
            //            add_container.UseNumber = ContainerHandler.ReCalcUseNumber(dbContext, item.LocationCode);
 
            //            dbContext.ware_container.Add(add_container);
            //            addCount++;
 
            //        }
            //        else if (ddds.Count > 1)
            //        {
            //            //数据不正确
            //            errList.Add(new FunRetEntity()
            //            {
            //                resData = item.LocationCode,
            //                resMsg = $"{item.LocationCode}容器数超过了1条"
            //            }); ; ;
            //        }
            //        else
            //        {//已存在
            //            var db_container = ddds.FirstOrDefault();
            //            db_container.GridNumber = Convert.ToInt32(item.GridNumber);
            //            //计算已占用栅格数
            //            db_container.UseNumber = ContainerHandler.ReCalcUseNumber(dbContext, item.LocationCode);
            //            updateCount++;
            //        }
            //    }
 
 
            //    dbContext.SaveChanges();
 
            //}
            //ShowResult($"新增{addCount}条");
            //ShowResult($"更新{updateCount}条");
            //ShowResult($"错误{errList.Count}条," + JsonConvert.SerializeObject(errList));
        }
 
        private void button6_Click(object sender, EventArgs e)
        {
            this.tb_Yitter.Text = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
            ShowResult(this.tb_Yitter.Text);
        }
    }
}