username@email.com
2025-01-26 a0b3492010949e0d044892b9bb6456b51ae0d458
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL;
using System.Data.SqlClient;
using System.Data;
using CY.Infrastructure.Query;
 
namespace CY.SQLDAL
{
    public class OA_ProcurementDAL : IOA_ProcurementDAL
    {
 
        private Database _dataBase = null;
 
        public OA_ProcurementDAL()
        {
            _dataBase = new Database();
        }
 
        public OA_ProcurementDAL(Database dDatabase)
        {
            _dataBase = dDatabase;
        }
 
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.OA_Procurement trueModel = model as Model.OA_Procurement;
            if (trueModel == null)
            {
                return false;
            }
            SqlParameter SuppliersId = null;
            if (trueModel.SuppliersId.HasValue)
            {
                SuppliersId = new SqlParameter("@SuppliersId", trueModel.SuppliersId);
            }
            else
            {
                SuppliersId = new SqlParameter("@SuppliersId", DBNull.Value);
            }
 
 
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {
                    new SqlParameter("@FirmId",trueModel.FirmId),
                    SuppliersId,
                    new SqlParameter("@GoodsId",trueModel.GoodsId),
                    new SqlParameter("@ClearingStatusId",trueModel.ClearingStatusId),
                    new SqlParameter("@Price",trueModel.Price),
                    new SqlParameter("@Quantity",trueModel.Quantity),
                    new SqlParameter("@AllMoney",trueModel.AllMoney),
                    new SqlParameter("@PurchaseTime",trueModel.PurchaseTime),
                    new SqlParameter("@PurchaseStatusId",trueModel.PurchaseStatusId),
                    new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
                    new SqlParameter("@Operator",trueModel.Operator),
                    new SqlParameter("@Remark",trueModel.Remark) ,
                    new SqlParameter("@SpecificationId",trueModel.SpecificationId),
                    new SqlParameter("@BrandId",trueModel.BrandId),
                    new SqlParameter("@PaperWeightId",trueModel.PaperWeightId),
                    new SqlParameter("@tanPrice",trueModel.TanPrice??0),
                    new SqlParameter("@ReceiveMoney",decimal.Parse("0")),
                    new SqlParameter("@Commodityid",trueModel.Commodityid),
                     new SqlParameter("@orderId",trueModel.orderId.HasValue?trueModel.orderId.Value:0),
                      new SqlParameter("@DocumentName",string.IsNullOrEmpty(trueModel.DocumentName)?"":trueModel.DocumentName)
            };
            try
            {
                _dataBase.Query("sp_OA_Procurement_Insert", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
 
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.OA_Procurement trueModel = model as Model.OA_Procurement;
            if (trueModel == null)
            {
                return false;
            }
 
            SqlParameter SuppliersId = null;
            if (trueModel.SuppliersId.HasValue)
            {
                SuppliersId = new SqlParameter("@SuppliersId", trueModel.SuppliersId);
            }
            else
            {
                SuppliersId = new SqlParameter("@SuppliersId", DBNull.Value);
            }
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            { 
                    new SqlParameter("@Keyid",trueModel.Keyid),
                    new SqlParameter("@FirmId",trueModel.FirmId),
                    SuppliersId,
                    new SqlParameter("@GoodsId",trueModel.GoodsId),
                    new SqlParameter("@ClearingStatusId",trueModel.ClearingStatusId),
                    new SqlParameter("@Price",trueModel.Price),
                    new SqlParameter("@Quantity",trueModel.Quantity),
                    new SqlParameter("@AllMoney",trueModel.AllMoney),
                    new SqlParameter("@PurchaseTime",trueModel.PurchaseTime),
                    new SqlParameter("@PurchaseStatusId",trueModel.PurchaseStatusId),
                    new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
                    new SqlParameter("@Operator",trueModel.Operator),
                    new SqlParameter("@Remark",trueModel.Remark) ,
                    new SqlParameter("@SpecificationId",trueModel.SpecificationId),
                    new SqlParameter("@BrandId",trueModel.BrandId),
                    new SqlParameter("@PaperWeightId",trueModel.PaperWeightId),
                    new SqlParameter("@tanPrice",trueModel.TanPrice??0),
                    new SqlParameter("@ReceiveMoney",trueModel.ReceiveMoney),
                    new SqlParameter("@Commodityid",trueModel.Commodityid)
            };
            try
            {
                _dataBase.Query("sp_OA_Procurement_Update", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
 
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.OA_Procurement trueModel = model as Model.OA_Procurement;
            if (trueModel == null)
            {
                return false;
            }
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {
                new SqlParameter("@Keyid",trueModel.Keyid)
            };
            try
            {
                _dataBase.Query("sp_OA_Procurement_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
 
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public IEnumerable<Model.OA_Procurement> SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
        {
            throw new NotImplementedException();
        }
 
        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="pa"></param>
        /// <param name="FirmId"></param>
        /// <param name="Operator"></param>
        /// <param name="PurchaseStatusId"></param>
        /// <param name="ClearingStatusId"></param>
        /// <param name="SuppliersId"></param>
        /// <param name="GoodsId"></param>
        /// <param name="GoodTypeID"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <param name="BrandName"></param>
        /// <param name="PaperWeight"></param>
        /// <returns></returns>
        public IEnumerable<Model.OA_Procurement> getModelList(Pagination pa, Guid FirmId, string Operator, string PurchaseStatusId, string ClearingStatusId, string SuppliersId, string GoodsId, string GoodTypeID, DateTime? beginTime, DateTime? endTime, string BrandName, string PaperWeight)
        {
            string Condition = " where  FirmId='" + FirmId + "'";
            if (beginTime.HasValue)
            {
                Condition += string.Format(" and CAST(PurchaseTime AS DATE) >='{0}'", beginTime);
            }
 
            if (endTime.HasValue)
            {
                Condition += string.Format(" and CAST(PurchaseTime AS DATE) <='{0}'", endTime);
            }
 
            if (!string.IsNullOrEmpty(PurchaseStatusId))
            {
                Condition += string.Format(" and  PurchaseStatusId='{0}'", PurchaseStatusId);
            }
            if (!string.IsNullOrEmpty(Operator))
            {
                Condition += string.Format(" and  Operator='{0}'", Operator);
            }
            if (!string.IsNullOrEmpty(ClearingStatusId))
            {
                Condition += string.Format(" and  ClearingStatusId='{0}'", ClearingStatusId);
            }
            if (!string.IsNullOrEmpty(SuppliersId))
            {
                Condition += string.Format(" and  SuppliersId='{0}'", SuppliersId);
            }
            if (!string.IsNullOrEmpty(GoodsId))
            {
                Condition += string.Format(" and  GoodsId='{0}'", GoodsId);
            }
            string Condition2 = " where 1=1  ";
            if (!string.IsNullOrEmpty(GoodTypeID))
            {
                Condition2 += string.Format(" and b.GoodsTypeId='{0}'", GoodTypeID);
            }
            string BandCondition = string.Empty;
            if (!string.IsNullOrEmpty(BrandName))
            {
                BandCondition += string.Format(" and  h.Name like '%{0}%' ", BrandName);
            }
            string PaperWeightCondition = string.Empty;
            if (!string.IsNullOrEmpty(PaperWeight))
            {
                PaperWeightCondition += string.Format(" and  l.Name like '%{0}%' ", PaperWeight);
            }
 
            string selTarget = " a.*,b.GoodsName as GoodsName ,c.Name as ClearingStatus  ,d.Name as PurchaseStatus,e.Name as SuppliersName,   g.GoodsTypeId as GoodsTypeId    ,h.Name AS BrandName ,j.Name AS SpeceicationName ,l.Name AS PaperWeightName";
 
            string fromSource = "  (select * from OA_Procurement  " + Condition + " ) AS a left join OA_GoodsInfo  AS b on  a.GoodsId=b.Keyid left join sys_Dictionary AS c on a.ClearingStatusId=c.keyid left join sys_Dictionary AS d on a.PurchaseStatusId=d.keyid  LEFT JOIN dbo.OA_Brand  AS h ON a.BrandId=h.Keyid LEFT JOIN dbo.OA_Specification  AS j ON a.SpecificationId=j.Keyid LEFT JOIN dbo.OA_PaperWeight AS l ON a.PaperWeightId = l.Keyid  left join dbo.OA_Suppliers AS e on a.SuppliersId=e.Keyid  left join OA_GoodsInfo as g on a.GoodsId=g.Keyid  " + Condition2 + " " + BandCondition + " " + PaperWeightCondition + " ";
            return _dataBase.SelectModelPage<Model.OA_Procurement>(pa, selTarget, fromSource, " a.LastUpdateTime DESC ");
 
        }
 
        /// <summary>
        /// 单个查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public IEnumerable<Model.OA_Procurement> SelectAllModel(Infrastructure.Query.Query query)
        {
            throw new NotImplementedException();
        }
 
        /// <summary>
        /// 获取单条数据
        /// </summary>
        /// <param name="Keyid"></param>
        /// <returns></returns>
        public Model.OA_Procurement SelectAllModel(string Keyid)
        {
            try
            {
                string selTarget = " a.*,b.GoodsName as GoodsName ,c.Name as ClearingStatus  ,d.Name as PurchaseStatus,e.Name as SuppliersName,   g.GoodsTypeId as GoodsTypeId ,h.Name AS BrandName,j.Name AS SpeceicationName,L.Name AS PaperWeightName ";
 
                string fromSource = "  (select * from OA_Procurement  where Keyid='" + Keyid + "') AS a left join OA_GoodsInfo  AS b on  a.GoodsId=b.Keyid left join sys_Dictionary AS c on a.ClearingStatusId=c.keyid left join sys_Dictionary AS d on a.PurchaseStatusId=d.keyid  left join dbo.OA_Suppliers AS e on a.SuppliersId=e.Keyid  left join OA_GoodsInfo as g on a.GoodsId=g.Keyid  LEFT JOIN dbo.OA_Brand AS h ON a.BrandId= h.Keyid LEFT JOIN  dbo.OA_Specification AS j ON a.SpecificationId= j.Keyid LEFT JOIN  dbo.OA_PaperWeight AS L ON a.PaperWeightId =L.Keyid";
 
                return _dataBase.SelectModel<Model.OA_Procurement>(selTarget, fromSource)[0];
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 
        /// <summary>
        /// 金额统计
        /// </summary>
        /// <param name="pa"></param>
        /// <param name="FirmId"></param>
        /// <param name="Operator"></param>
        /// <param name="PurchaseStatusId"></param>
        /// <param name="ClearingStatusId"></param>
        /// <param name="SuppliersId"></param>
        /// <param name="GoodsId"></param>
        /// <param name="GoodTypeID"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <param name="BrandName"></param>
        /// <param name="PaperWeight"></param>
        /// <returns></returns>
        public Model.OA_Procurement SumMoney(Pagination pa, Guid FirmId, string Operator, string PurchaseStatusId, string ClearingStatusId, string SuppliersId, string GoodsId, string GoodTypeID, DateTime? beginTime, DateTime? endTime, string BrandName, string PaperWeight)
        {
            try
            {
 
                string Condition = " where  FirmId='" + FirmId + "'";
                if (beginTime.HasValue)
                {
                    Condition += string.Format(" and CAST(PurchaseTime AS DATE) >='{0}'", beginTime);
                }
 
                if (endTime.HasValue)
                {
                    Condition += string.Format(" and CAST(PurchaseTime AS DATE) <='{0}'", endTime);
                }
 
                if (!string.IsNullOrEmpty(PurchaseStatusId))
                {
                    Condition += string.Format(" and  PurchaseStatusId='{0}'", PurchaseStatusId);
                }
                if (!string.IsNullOrEmpty(Operator))
                {
                    Condition += string.Format(" and  Operator='{0}'", Operator);
                }
                if (!string.IsNullOrEmpty(ClearingStatusId))
                {
                    Condition += string.Format(" and  ClearingStatusId='{0}'", ClearingStatusId);
                }
                if (!string.IsNullOrEmpty(SuppliersId))
                {
                    Condition += string.Format(" and  SuppliersId='{0}'", SuppliersId);
                }
                if (!string.IsNullOrEmpty(GoodsId))
                {
                    Condition += string.Format(" and  GoodsId='{0}'", GoodsId);
                }
                string Condition2 = " where 1=1  ";
                if (!string.IsNullOrEmpty(GoodTypeID))
                {
                    Condition2 += string.Format(" and b.GoodsTypeId='{0}'", GoodTypeID);
                }
                string BandCondition = string.Empty;
                if (!string.IsNullOrEmpty(BrandName))
                {
                    BandCondition += string.Format(" and  h.Name like '%{0}%' ", BrandName);
                }
                string PaperWeightCondition = string.Empty;
                if (!string.IsNullOrEmpty(PaperWeight))
                {
                    PaperWeightCondition += string.Format(" and  l.Name like '%{0}%' ", PaperWeight);
                }
 
                string selTarget = " sum(AllMoney) as AllMoney,sum(ReceiveMoney) as ReceiveMoney";
 
                string fromSource = "  (select * from OA_Procurement  " + Condition + " ) AS a left join OA_GoodsInfo  AS b on  a.GoodsId=b.Keyid left join sys_Dictionary AS c on a.ClearingStatusId=c.keyid left join sys_Dictionary AS d on a.PurchaseStatusId=d.keyid  LEFT JOIN dbo.OA_Brand  AS h ON a.BrandId=h.Keyid LEFT JOIN dbo.OA_Specification  AS j ON a.SpecificationId=j.Keyid LEFT JOIN dbo.OA_PaperWeight AS l ON a.PaperWeightId = l.Keyid  left join dbo.OA_Suppliers AS e on a.SuppliersId=e.Keyid  left join OA_GoodsInfo as g on a.GoodsId=g.Keyid  " + Condition2 + " " + BandCondition + " " + PaperWeightCondition + " ";
                IList<Model.OA_Procurement> m_OA_ProcurementList = _dataBase.SelectModel<Model.OA_Procurement>(selTarget, fromSource, "");
                if (m_OA_ProcurementList != null && m_OA_ProcurementList.Count > 0)
                {
                    return m_OA_ProcurementList[0];
                }
                else
                {
                    return new Model.OA_Procurement();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 
        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="pa"></param>
        /// <param name="FirmId"></param>
        /// <param name="Keyids"></param>
        /// <returns></returns>
        public IEnumerable<Model.OA_Procurement> getModelList(Pagination pa, Guid FirmId, string Keyids)
        {
            string Condition = " where  FirmId='" + FirmId + "'";
 
 
            if (!string.IsNullOrEmpty(Keyids))
            {
                Condition += string.Format(" and  Keyid  in ({0}) ", Keyids);
            }
 
 
            string selTarget = " a.*,b.GoodsName as GoodsName ,c.Name as ClearingStatus  ,d.Name as PurchaseStatus,e.Name as SuppliersName,   g.GoodsTypeId as GoodsTypeId    ,h.Name AS BrandName ,j.Name AS SpeceicationName ,l.Name AS PaperWeightName";
 
            string fromSource = "  (select * from OA_Procurement  " + Condition + " ) AS a left join OA_GoodsInfo  AS b on  a.GoodsId=b.Keyid left join sys_Dictionary AS c on a.ClearingStatusId=c.keyid left join sys_Dictionary AS d on a.PurchaseStatusId=d.keyid  LEFT JOIN dbo.OA_Brand  AS h ON a.BrandId=h.Keyid LEFT JOIN dbo.OA_Specification  AS j ON a.SpecificationId=j.Keyid LEFT JOIN dbo.OA_PaperWeight AS l ON a.PaperWeightId = l.Keyid  left join dbo.OA_Suppliers AS e on a.SuppliersId=e.Keyid  left join OA_GoodsInfo as g on a.GoodsId=g.Keyid  ";
            return _dataBase.SelectModelPage<Model.OA_Procurement>(pa, selTarget, fromSource, " a.LastUpdateTime DESC ");
 
        }
    }
}