LocationTools.cs
4.82 KB
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
using HHECS.Application.Enums;
using HHECS.Application.Service;
using HHECS.Dal;
using HHECS.Dal.Repository;
using HHECS.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HHECS.Test
{
public class LocationTools
{
/// <summary>
/// 创建库位
/// </summary>
public static void CreateLocations(List<LocationAddModel> locationAddModels, bool isdel)
{
using (var um = DALHelper.GetFreeSql().CreateUnitOfWork())
{
try
{
LocationRepository locationRepository = new LocationRepository();
locationRepository.UnitOfWork = um;
List<Location> locations = new List<Location>();
LocationService locationService = new LocationService();
if (isdel)
{
var data = locationService.GetAllLocations(t => true).Data.Select(t => t.Code).ToList();
locationService.DeleteLocations(data);
}
foreach (var locationAddModel in locationAddModels)
{
for (int i = locationAddModel.RowBeginIndex; i <= locationAddModel.RowEndIndex; i++)//行
{
for (int j = locationAddModel.ColumnBeginIndex; j <= locationAddModel.ColumnEndIndex; j++)//列
{
for (int k = locationAddModel.LayerBeginIndex; k <= locationAddModel.LayerEndIndex; k++)//层
{
Location location = new Location();
location.Code = $"{locationAddModel.Prefix}{i.ToString().PadLeft(2, '0')}{locationAddModel.Connector}{j.ToString().PadLeft(2, '0')}{locationAddModel.Connector}{k.ToString().PadLeft(2, '0')}";
location.Roadway = locationAddModel.Roadway;
location.Row = i;
location.Column = j;
location.Layer = k;
location.RowIndex1 = locationAddModel.RowIndex1;
location.RowIndex2 = locationAddModel.RowIndex2;
location.SRMCode = locationAddModel.SRMCode;
location.Type = locationAddModel.Type;
//location.Type = k <= 3 ? "Small" : "Middle";
location.Status = (int)LocationStatus.Free;
location.ContainerCode = "";
location.WarehouseCode = locationAddModel.WarehouseCode;
location.DestinationArea = locationAddModel.DestinationArea;
locations.Add(location);
}
}
}
}
locationRepository.Insert(locations);
um.Commit();
}
catch (Exception ex)
{
um.Rollback();
Console.WriteLine(ex.Message);
}
}
}
/// <summary>
/// 用于删除缺失库位
/// </summary>
/// <param name="prefix"></param>
/// <param name="connector"></param>
/// <param name="RowBeging"></param>
/// <param name="RowEnd"></param>
/// <param name="ColumnBeging"></param>
/// <param name="ColumnEnd"></param>
/// <param name="LayerBeging"></param>
/// <param name="LayerEnd"></param>
/// <param name="warehouseCode"></param>
public static void DeleteLocations(int rowBeging, int rowEnd, int columnBeging, int columnEnd, int layerBeging, int layerEnd, string warehouseCode)
{
using (var um = DALHelper.GetFreeSql().CreateUnitOfWork())
{
try
{
LocationRepository locationRepository = new LocationRepository();
locationRepository.UnitOfWork = um;
locationRepository.Delete(t => t.Row >= rowBeging && t.Row <= rowEnd
&& t.Column >= columnBeging && t.Column <= columnEnd
&& t.Layer >= layerBeging && t.Layer <= layerEnd
&& t.WarehouseCode == warehouseCode);
um.Commit();
}
catch (Exception ex)
{
um.Rollback();
Console.WriteLine(ex.Message);
}
}
}
}
}