schangxiang@126.com
2025-09-17 e8e8a06fc68a6a645ce32be2cc9c3aaa67a97d68
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
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 InOutListService : CommonService<InOutListEntity, BASEInOutList, DbModelCore>
    {
        private static object Lock = new object();
 
        private InOutListService() : base(InOutListDao.GetInstance()) { }
 
        private static InOutListService Instance = null;
 
        /// <summary>
        /// 获取单例的方法
        /// </summary>
        /// <returns>用户服务的单例实体</returns>
        public static InOutListService GetInstance()
        {
 
            if (Instance == null)
            {
                lock (Lock)
                {
                    if (Instance == null)
                    {
                        Instance = new InOutListService();
                    }
                }
            }
            return Instance;
        }
 
        /// <summary>
        /// 转换子表ORM
        /// </summary>
        /// <param name="iol"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public int CreateListAndDetial(InOutListEntity iol, out string msg)
        {
            try
            {
                using (var DbModel = new DbModelCore())
                {
                    List<BASEInOutListDetail> inldlst = new List<BASEInOutListDetail>();
                    msg = "";
                    iol.InOutListDetail.ForEach(x => { inldlst.Add(x.ToOrm()); });
                    BASEInOutList biol = new BASEInOutList();
                    biol = iol.ToOrm();
                    biol.BASEInOutListDetails = inldlst;
                    DbModel.BASEInOutLists.Add(biol);
                    return DbModel.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
 
                return -1;
 
            }
        }
        public bool AddOutInDetail(string inoutNo, string maritalNo, out string msg)
        {
            try
            {
                msg = "";
                using (var dbModel = new DbModelCore())
                {
                    var cutInOut = dbModel.BASEInOutLists.FirstOrDefault(x=>x.listno== inoutNo);
                    if (cutInOut == null)
                    {
                        msg = "出入库单号不存在";
                        return false;
                    }
                    var cutMarital = dbModel.BASEMaterials.FirstOrDefault(x => x.code == maritalNo);
                    if (cutMarital == null)
                    {
                        msg = "物料不存在";
                        return false;
                    }
                    var findInOutDetail = dbModel.BASEInOutListDetails.FirstOrDefault(x => x.inoutlistid == cutInOut.id && x.materialid== cutMarital.id);
                    if (findInOutDetail != null)
                    {
                        msg = "此单号和物料已存在";
                        return false;
                    }
                    BASEInOutListDetail newDetail = new BASEInOutListDetail();
                    newDetail.inoutlistid = cutInOut.id;
                    newDetail.placeid = 0;
                    newDetail.materialid = cutMarital.id;
                    newDetail.isfinish = 0;
                    dbModel.BASEInOutListDetails.Add(newDetail);
                    dbModel.SaveChanges();
                    msg = "新增成功";
                    return true;
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return false;
            }
        }
        
        public override int Delete(int id, out string msg)
        {
            msg = "";
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    var inoutlist = dbModel.BASEInOutLists.Where(x => id == x.id).ToList();
 
                    var inoutdetail = dbModel.BASEInOutListDetails.Where(x => id == x.inoutlistid).ToList();
                    inoutdetail.ForEach(x => dbModel.BASEInOutListDetails.Remove(x));
                    inoutlist.ForEach(x => dbModel.BASEInOutLists.Remove(x));
 
                    dbModel.SaveChanges();
                    return inoutdetail.Count;
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Delete", ex.Message);
                    return 0;
                }
            }
        }
 
        public int DeleteInOut(int id, out string msg)
        {
            msg = "";
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    var inoutlist = dbModel.BASEInOutLists.Where(x => id == x.id).ToList();
 
                    var inoutdetail = dbModel.BASEInOutListDetails.Where(x => x.inoutlistid == id).ToList();
                    inoutdetail.ForEach(x => dbModel.BASEInOutListDetails.Remove(x));
                    dbModel.BASEInOutLists.RemoveRange(inoutlist);
 
                    dbModel.SaveChanges();
                    return inoutlist.Count;
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "DeleteInOut", ex.Message);
                    return 0;
                }
            }
        }
 
        //public override int Delete(List<int> id, out string msg)
        //{
        //    msg = "";
        //    using (var dbModel = new DbModelCore())
        //    {
        //        try
        //        {
        //            var inoutlist = dbModel.BASEInOutLists.Where(x => id == x.id).ToList();
 
        //            var inoutdetail = dbModel.BASEInOutListDetails.Where(x => id == x.inoutlistid).ToList();
        //            inoutdetail.ForEach(x => dbModel.BASEInOutListDetails.Remove(x));
        //            inoutlist.ForEach(x => dbModel.BASEInOutLists.Remove(x));
 
        //            dbModel.SaveChanges();
        //            return inoutdetail.Count;
        //        }
        //        catch (Exception ex)
        //        {
        //            msg = ex.Message;
        //            LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Delete", ex.Message);
        //            return 0;
        //        }
        //    }
        //}
 
    }
}