schangxiang@126.com
2025-09-29 682eba0aaf922e69dfafe05fb6c1bbdbf3a0e04a
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
using iWareCommon.Common.Entity;
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 InputMaterialService : CommonService<InputMaterialEntity, BASEInputMaterial, DbModelCore>
    {
 
        private static object Lock = new object();
 
        private InputMaterialService() : base(InputMaterialDao.GetInstance()) { }
 
        private static InputMaterialService Instance = null;
 
        /// <summary>
        /// 获取单例的方法
        /// </summary>
        /// <returns>角色服务的单例实体</returns>
        public static InputMaterialService GetInstance()
        {
 
            if (Instance == null)
            {
                lock (Lock)
                {
                    if (Instance == null)
                    {
                        Instance = new InputMaterialService();
                    }
                }
            }
            return Instance;
        }
        
        /// <summary>
        /// 取得导入物料的id的集合
        /// </summary>
        /// <param name="codes"></param>
        /// <returns></returns>
        public List<BASEMaterial> GetIds(List<string> codes)
        {
            using (var DbModel = new DbModelCore())
            {
                string msg = "";
                try
                {
                    var mid = DbModel.BASEMaterials.Where(x => codes.Contains(x.code)).ToList();
 
                    return mid;
 
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetIds", ex.Message);
                    return null;
                }
            }
        }
 
        /// <summary>
        /// 每次加载时,如果有上次导入未生成的数据,全部删除
        /// </summary>
        /// <returns></returns>
        public int DeleteAll()
        {
            using (var DbModel = new DbModelCore())
            {
                string msg = "";
                try
                {
                    var input = DbModel.BASEInputMaterials.Where(x => x.id != 0).ToList();
                    if (input.Count > 0)
                    {
                        DbModel.BASEInputMaterials.RemoveRange(input);
                        DbModel.SaveChanges();
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "DeleteAll", ex.Message);
                    return -1;
                }
            }
        }
 
        
 
    }
}