username@email.com
2025-04-22 277cffdd657197fbd72444ef24a99dde7a469011
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
219
220
221
222
223
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using CY.IDAL;
using CY.Model;
using CY.Infrastructure.Configuration;
using CY.Infrastructure.Common;
using CY.BLL;
using System.Transactions;
using CY.Infrastructure.Query;
namespace CY.BLL.OA
{
    public class OA_OutOfStorageBLL
    {
        OA_InventoryBLL _OA_InventoryBLL = null;
        IOA_OutOfStorageDAL outOfStorageDAL = null;
        OA_ProcurementBLL bll_OA_ProcurementBLL = null;
        OA_ProcurementBLL _OA_ProcurementBLL = null;
 
        public OA_OutOfStorageBLL()
        {
            _OA_ProcurementBLL = new OA_ProcurementBLL();
            _OA_InventoryBLL = new OA_InventoryBLL();
            outOfStorageDAL = AbstractFactory.Factory.GetDALByInterfaceName(AbstractFactory.DALInterface.IOA_OutOfStorageDAL) as IOA_OutOfStorageDAL;
            bll_OA_ProcurementBLL = new OA_ProcurementBLL();
 
        }
 
        public bool InertModel(OA_OutOfStorage outOfStorage)
        {
            return outOfStorageDAL.InserModel(outOfStorage);
 
        }
 
        public bool UpdateModel(OA_OutOfStorage model)
        {
            return outOfStorageDAL.UpdateModel(model);
        }
 
        /// <summary>
        /// 增加一条入库信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool InsertModel(OA_Inventory inventory, OA_OutOfStorage outOfStorage)
        {
            bool isSuccess = true;
            OA_Inventory m_OA_Inventory = _OA_InventoryBLL.IfHasModel(inventory);
            if (m_OA_Inventory != null)//如果所选货位存在此产品
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    isSuccess = outOfStorageDAL.InserModel(outOfStorage);
                    if (isSuccess)
                    {
                        if (outOfStorage.InfoType == "出库")
                        {
                            m_OA_Inventory.InventoryCount -= outOfStorage.Quantity;//出库数据量减
                        }
                        else
                        {
                            m_OA_Inventory.InventoryCount += outOfStorage.Quantity;//出库数据量减
                        }
                        m_OA_Inventory.TotalPrice = (m_OA_Inventory.UnitPrice ?? 0) * (m_OA_Inventory.InventoryCount ?? 0);
                        isSuccess = _OA_InventoryBLL.UpdateModel(m_OA_Inventory);
                    }
                    if (isSuccess)
                        scope.Complete();
                }
                return isSuccess;
            }
            else//如果所选货位不存在此产品
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    isSuccess = outOfStorageDAL.InserModel(outOfStorage);
                    if (isSuccess)
                    {
                        inventory.TotalPrice = (inventory.UnitPrice ?? 0) * (inventory.InventoryCount ?? 0);
                        isSuccess = _OA_InventoryBLL.InsertModel(inventory);
                    }
                    if (isSuccess)
                        scope.Complete();
                }
                return isSuccess;
            }
        }
 
        public IEnumerable<Model.OA_OutOfStorage> getModelList(Pagination pa, Guid FirmId, string Operator, string InfoType, string SuppliersId, string GoodsNameId, string WarehouseId, DateTime? beginTime, DateTime? endTime, string BrandName, string SpeceicationName, string PaperWeightName, string GoodsTypeId)
        {
            return outOfStorageDAL.getModelList(pa, FirmId, Operator, InfoType, SuppliersId, GoodsNameId, WarehouseId, beginTime, endTime, BrandName, SpeceicationName, PaperWeightName, GoodsTypeId);
        }
 
        public bool InsertModelList(string[] Keys, int? WarehouseId, string WarehouseName )
        {
            try
            {
                bool isSuccess = true;
                using (TransactionScope scope = new TransactionScope())
                {
                    foreach (var Keyid in Keys)
                    {
 
                        OA_Procurement m_OA_Procurement = new OA_Procurement();
                        OA_Inventory m_OA_Inventory = new OA_Inventory();
                        OA_OutOfStorage m_OA_OutOfStorage = new OA_OutOfStorage();
                        OA_WarehouseInfo m_OA_WarehouseInfo = new OA_WarehouseInfo();
                        OA_WarehouseInfoBLL bll_OA_WarehouseInfoBLL = new OA_WarehouseInfoBLL();
 
                        m_OA_WarehouseInfo = bll_OA_WarehouseInfoBLL.getSingleModel(WarehouseId.ToString());
 
                        m_OA_Procurement = _OA_ProcurementBLL.SelectSingleModel(Keyid);
                        m_OA_Procurement.PurchaseStatusId = 201;
                        m_OA_Procurement.WarehouseName = m_OA_WarehouseInfo.WarehouseName;
                        if (!WarehouseName.Equals("上机使用"))
                        {
                            //库存表对象
                            m_OA_Inventory.CargoSpaceId = 0;
                            m_OA_Inventory.FirmId = m_OA_Procurement.FirmId;
                            m_OA_Inventory.GoodsId = m_OA_Procurement.GoodsId;
                            m_OA_Inventory.InventoryCount = m_OA_Procurement.Quantity;
                            m_OA_Inventory.LastUpdateTime = DateTime.Now;
                            m_OA_Inventory.Operator = m_OA_Procurement.Operator;
                            m_OA_Inventory.Remark = "";
                            m_OA_Inventory.WarehouseId = WarehouseId;
                            m_OA_Inventory.BrandId = m_OA_Procurement.BrandId;
                            m_OA_Inventory.SpecificationId = m_OA_Procurement.SpecificationId;
                            m_OA_Inventory.PaperWeightId = m_OA_Procurement.PaperWeightId;
                            m_OA_Inventory.UnitPrice = m_OA_Procurement.Price ?? 0;
                            m_OA_Inventory.TotalPrice = m_OA_Procurement.AllMoney ?? 0;
 
                            //出入库信息表对象
                            m_OA_OutOfStorage.FirmId = m_OA_Procurement.FirmId;
                            m_OA_OutOfStorage.GoodsId = m_OA_Procurement.GoodsId;
                            m_OA_OutOfStorage.CargoSpaceId = 0;
                            m_OA_OutOfStorage.LastUpdateTime = DateTime.Now;
                            m_OA_OutOfStorage.Operator = m_OA_Procurement.Operator;
                            m_OA_OutOfStorage.Remark = "";
                            m_OA_OutOfStorage.WarehouseId = WarehouseId;
                            m_OA_OutOfStorage.SuppliersId = m_OA_Procurement.SuppliersId;
                            m_OA_OutOfStorage.AllMoney = m_OA_Procurement.AllMoney;
                            m_OA_OutOfStorage.InfoType = "入库";
                            m_OA_OutOfStorage.Price = m_OA_Procurement.Price;
                            m_OA_OutOfStorage.Quantity = m_OA_Procurement.Quantity;
                            m_OA_OutOfStorage.BrandId = m_OA_Procurement.BrandId;
                            m_OA_OutOfStorage.SpecificationId = m_OA_Procurement.SpecificationId;
                            m_OA_OutOfStorage.PaperWeightId = m_OA_Procurement.PaperWeightId;
                            m_OA_OutOfStorage.TanPrice = m_OA_Procurement.TanPrice ?? 0;
                            isSuccess = InsertModel(m_OA_Inventory, m_OA_OutOfStorage);
                        }
                        
 
                        if (isSuccess)
                        {
                            isSuccess = bll_OA_ProcurementBLL.UpdateModel(m_OA_Procurement);
 
                        }
                    }
                    if (isSuccess)
                        scope.Complete();
                }
 
                return isSuccess;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 
        /// <summary>
        /// 获取单个信息
        /// </summary>
        /// <param name="Keyid"></param>
        /// <returns></returns>
        public OA_OutOfStorage GetModelByKeyid(int? Keyid)
        {
            return outOfStorageDAL.GetModelByKeyid(Keyid);
        }
 
        public OA_OutOfStorage GetModelInfo(int? keyid)
        {
            return outOfStorageDAL.GetModelInfo(keyid);
        }
 
        public bool GoodsOutofStorage(Model.OA_Inventory model, Model.OA_OutOfStorage OutOfStorage)
        {
            OA_Inventory m_OA_Inventory = _OA_InventoryBLL.IfHasModel(model);
            if (m_OA_Inventory != null)//如果所选货位存在此产品
            {
                if (m_OA_Inventory.InventoryCount < OutOfStorage.Quantity)
                {
                    return false;
                }
                else
                {
                    m_OA_Inventory.InventoryCount = m_OA_Inventory.InventoryCount - OutOfStorage.Quantity;
                    bool isSuccess = _OA_InventoryBLL.UpdateModel(m_OA_Inventory);
                    if (isSuccess)
                    {
                        OutOfStorage.InfoType = "出库";
                        isSuccess = UpdateModel(OutOfStorage);
                    }
                    return isSuccess;
                }
            }
            else
            {
                return false;
            }
 
 
 
        }
 
        public IEnumerable<Model.OA_OutOfStorage> getModelList(Pagination pa, Guid FirmId, string Keyids)
        {
            return outOfStorageDAL.getModelList(pa, FirmId, Keyids);
        }
    }
}