1
yuyou_x
2024-01-31 426134e8a0dbb5fc63a0bc64eeff2de6aac4b81a
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
using Model.ModelDto;
using Model.ModelDto.SysDto;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using WMS.DAL;
using WMS.Entity.BllSoEntity;
using WMS.Entity.Context;
using WMS.Entity.SysEntity;
using WMS.IBLL.ISysServer;
 
namespace WMS.BLL.SysServer
{
    /// <summary>
    ///  物料类别管理方法
    /// </summary>
    public class MaterialCategory : DbHelper<SysMaterialCategory>, IMaterialCategory
    {
 
        private static readonly SqlSugarScope Db = DataContext.Db;
        public MaterialCategory() : base(Db)
        {
        }
 
        /// <summary>
        /// 获取物料类别信息
        /// </summary>
        /// <param name="categoryName">类别名称</param>
        /// <param name="areaNo">区域编码</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public List<MaterialCategoryDto> GetMaterialCategories(string categoryName, string areaNo)
        {
            try
            {
                var list = Db.Queryable<MaterialCategoryDto>()
                    .WhereIF(!string.IsNullOrWhiteSpace(categoryName), a => a.CategoryName == categoryName)
                    .WhereIF(!string.IsNullOrWhiteSpace(areaNo), a => a.AreaNo == areaNo)
                    .Where(a => a.IsDel == "0").ToList();
 
                return list;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 
        /// <summary>
        /// 新增类别信息
        /// </summary>
        /// <param name="category">物料类别实体</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public string InsertMaterialCategories(SysMaterialCategory category)
        {
            try
            {
                string msg = "";
                //获取类别信息
                var categoryInfo = Db.Queryable<SysMaterialCategory>().First(a => a.IsDel == "0" && a.CategoryNo == category.CategoryNo);
                //获取区域信息
                var area = Db.Queryable<SysStorageArea>().First(a => a.AreaNo == category.AreaNo && a.IsDel == "0");
 
                if (categoryInfo != null)
                {
                    msg = "当前类别信息已被创建,请重新填写信息!";
                    return msg;
                }
                if (area == null)
                {
                    msg = "当前选择区域信息异常,请重新选择或联系管理员!";
                    return msg;
                }
 
                Db.BeginTran();
                SysMaterialCategory list = new SysMaterialCategory()
                {                    
                    CategoryNo = category.CategoryNo, //类别号
                    CategoryName = category.CategoryName, //类别名称
 
                    AreaNo = category.AreaNo, //区域编码
                    WareHouseNo = area.WareHouseNo, //所属仓库
                    Demo = category.Demo, //备注
 
                    IsDel = "0", //是否删除
                    CreateUser = category.CreateUser, //创建人
                    CreateTime = Db.GetDate(), //创建时间
                };
 
                Db.Insertable(list).ExecuteCommand();
 
 
                Db.CommitTran();
 
                msg = "新增类别信息成功!";
                return msg;
 
                
            }
            catch (Exception ex)
            {
                Db.RollbackTran();
                throw new Exception(ex.Message);
            }
        }
 
        /// <summary>
        /// 编辑类别信息
        /// </summary>
        /// <param name="category">物料类别实体</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public string ExitMaterialCategories(SysMaterialCategory category)
        {
            try
            {
                string msg = "";
                //获取类别信息
                var categoryInfo = Db.Queryable<SysMaterialCategory>().First(a => a.IsDel == "0" && a.CategoryNo == category.CategoryNo);
                //获取区域信息
                var area = Db.Queryable<SysStorageArea>().First(a => a.AreaNo == category.AreaNo && a.IsDel == "0");
 
                if (categoryInfo != null)
                {
                    msg = "当前类别信息已被创建,请重新填写信息!";
                    return msg;
                }
 
                if (area == null)
                {
                    msg = "当前选择区域信息异常,请重新选择或联系管理员!";
                    return msg;
                }
 
                Db.BeginTran();
                categoryInfo = new SysMaterialCategory()
                {
                    CategoryNo = category.CategoryNo, //类别号
                    CategoryName = category.CategoryName, //类别名称
 
                    AreaNo = category.AreaNo, //区域编码
                    WareHouseNo = area.WareHouseNo, //所属仓库
                    Demo = category.Demo, //备注
 
                    IsDel = "0", //是否删除
                    UpdateUser = category.CreateUser, //更改人
                    UpdateTime = Db.GetDate(), //更改时间
                };
 
                Db.Updateable(categoryInfo).ExecuteCommand();
 
                Db.CommitTran();
 
                msg = "编辑类别信息成功!";
                return msg;
 
                
            }
            catch (Exception ex)
            {
                Db.RollbackTran();
                throw new Exception(ex.Message);
            }
        }
 
        /// <summary>
        /// 删除类别信息
        /// </summary>
        /// <param name="category">物料类别实体</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public string DeleteMaterialCategories(SysMaterialCategory category)
        {
            try
            {
                string msg = "";
                //获取类别信息
                var categoryInfo = Db.Queryable<SysMaterialCategory>().First(a => a.IsDel == "0" && a.CategoryNo == category.CategoryNo);
                //获取区域信息
                var area = Db.Queryable<SysStorageArea>().First(a => a.AreaNo == category.AreaNo && a.IsDel == "0");
 
 
                if (categoryInfo != null)
                {
                    msg = "当前类别信息已被删除,请重新选择!";
                    return msg;
                }
                if (area == null)
                {
                    msg = "当前选择区域信息异常,请重新选择或联系管理员!";
                    return msg;
                }
 
                Db.BeginTran();
 
                categoryInfo.IsDel = "1";
 
                Db.Updateable(categoryInfo).ExecuteCommand();
 
                Db.CommitTran();
 
                msg = "删除类别信息成功!";
                return msg;
 
 
            }
            catch (Exception ex)
            {
                Db.RollbackTran();
                throw new Exception(ex.Message);
            }
        }
    }
}