schangxiang@126.com
2025-09-17 c9c91ad3e3ac218d81c86809c93a35622b51a686
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
using iWareCommon.Common.Service;
using iWareCommon.Utils;
using iWareDataCore.BASE.Dao;
using iWareDataCore.BASE.Entity;
using iWareDataCore.ORM;
using iWareDataCore.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareDataCore.BASE.Service
{
    public class MaterialService : CommonService<MaterialEntity, BASEMaterial, DbModelCore>
    {
 
        private static object Lock = new object();
 
        private MaterialService() : base(MaterialDao.GetInstance()) { }
 
        private static MaterialService Instance = null;
 
        /// <summary>
        /// 获取单例的方法
        /// </summary>
        /// <returns>角色服务的单例实体</returns>
        public static MaterialService GetInstance()
        {
 
            if (Instance == null)
            {
                lock (Lock)
                {
                    if (Instance == null)
                    {
                        Instance = new MaterialService();
                    }
                }
            }
            return Instance;
        }
 
 
 
        /// <summary>
        /// 批量修改物料状态
        /// </summary>
        /// <param name="ids">需要修改的物料id列表</param>
        /// <param name="status">状态:1为启用,0为锁定</param>
        /// <param name="msg">异常错误消息</param>
        /// <returns>修改的物料数量</returns>
        public int ChangeStatus(List<int> ids, int status, out string msg)
        {
            msg = "";
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    var ones = dbModel.BASEMaterials.Where(x => ids.Contains(x.id)).ToList();
 
                    foreach (var one in ones)
                    {
                        one.status = status;
                    }
 
                    dbModel.SaveChanges();
                    return ones.Count;
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "ChangeStatus", ex.Message);
                    return -1;
                }
            }
        }
 
        /// <summary>
        /// 获取指定字符串开头的物料信息表
        /// added by Dongwenwu
        /// </summary>
        /// <param name="term">指定字符串</param>
        /// <param name="size">返回的最大条数</param>
        /// <param name="msg">异常错误消息</param>
        /// <returns>订单号列表</returns>
        public List<string> GetCodes(string term, int size, out string msg)
        {
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    msg = "";
                    if (string.IsNullOrEmpty(term))
                    {
                        return new List<string>();
                    }
                    var materials = dbModel.BASEMaterials.Select(x => new { x.id, x.code }).OrderByDescending(x => x.id).Where(x => x.code.StartsWith(term)).Skip(0).Take(size).ToList();
                    return materials.Select(x => x.code).Distinct().ToList();
 
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetCodes", ex.Message);
                    return new List<string>();
                }
            }
        }
 
    }
}