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
using iWareCommon.Utils;
using iWareDataCore.BASE.EnumType;
using iWareDataCore.ORM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareDataCore.BASE.Service
{
    public class WareHouseService
    {
        private static object Lock = new Object();
 
        private static WareHouseService Instance = null;
 
        /// <summary>
        /// 获取单例的方法
        /// </summary>
        /// <returns>单例实体</returns>
        public static WareHouseService GetInstance()
        {
            if (Instance == null)
            {
                lock (Lock)
                {
                    if (Instance == null)
                    {
                        Instance = new WareHouseService();
                    }
                }
            }
            return Instance;
        }
        /// <summary>
        /// 获取辅助不实际使用的库位号
        /// </summary>
        /// <param name="layer"></param>
        /// <returns></returns>
        public List<string> GetALlNoUsePlace()
        {
            using (DbModelCore context = new DbModelCore())
            {
                try
                {
 
                    return context.BASEPlaces.Where(x =>x.typeid == 17).Select(x=>x.code).ToList();
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLine("WareHouseService", "GetALlPlace", ex.ToString());
                    return new List<string>();
                }
            }
        }
 
 
 
        /// <summary>
        /// 获取所有库位号
        /// </summary>
        /// <param name="layer"></param>
        /// <returns></returns>
        public List<string> GetALlPlace()
        {
            using (DbModelCore context = new DbModelCore())
            {
                try
                {
                    string sql = "select code from [dbo].[BASEPlace] where typeid={0} ";
                    return context.Database.SqlQuery<string>(sql, (int)EPlaceType.普通库位).ToList();
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLine("WareHouseService", "GetALlPlace", ex.ToString());
                    return new List<string>();
                }
            }
        }
 
        /// <summary>
        /// 获取有物料的库位名称
        /// </summary>
        /// <returns></returns>
        public List<string> GetItemInPlace()
        {
            using (DbModelCore context = new DbModelCore())
            {
                try
                {
                    string sql = "SELECT code from BASEPlace  where id in (select placeid from BASEPlaceMaterial )  and typeid={0} and islock =0  ";
                    return context.Database.SqlQuery<string>(sql, (int)EPlaceType.普通库位).ToList();
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLine("WareHouseService", "GetItemInPlace", ex.ToString());
                    return new List<string>();
                }
            }
        }
 
        /// <summary>
        /// 获取锁定库位
        /// </summary>
        /// <returns></returns>
        public List<string> GetLockedPlace()
        {
            using (DbModelCore context = new DbModelCore())
            {
                try
                {
                    string sql = "select code from [dbo].[BASEPlace] where islock = 1 and typeid={0}";
                    return context.Database.SqlQuery<string>(sql, (int)EPlaceType.普通库位).ToList();
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLine("WareHouseService", "GetLockedPlace", ex.ToString());
                    return new List<string>();
                }
            }
        }
 
        /// <summary>
        /// 获取空库位库位号
        /// </summary>
        /// <returns></returns>
        public List<string> GetEmptyInPlace()
        {
            using (DbModelCore context = new DbModelCore())
            {
                try
                {
                    string sql = " SELECT code from BASEPlace  where id not in (select placeid from BASEPlaceMaterial )  and typeid={0}";
                    return context.Database.SqlQuery<string>(sql, (int)EPlaceType.普通库位).ToList();
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLine("WareHouseService", "GetEmptyInPlace", ex.ToString());
                    return new List<string>();
                }
            }
        }
 
    }
}