username@email.com
2024-12-20 ebd639c929bd5c05859b6b414787e3440cdcd4bc
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
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_GoodsInfoDAL : IOA_GoodsInfoDAL
    {
 
        private Database _dataBase = null;
 
        public OA_GoodsInfoDAL()
        {
            _dataBase = new Database();
        }
 
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.OA_GoodsInfo trueModel = model as Model.OA_GoodsInfo;
            if (trueModel == null)
            {
                return false;
            }
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {
                    new SqlParameter("@FirmId",trueModel.FirmId),
                    new SqlParameter("@BrandId",trueModel.BrandId),
                    new SqlParameter("@SpecificationId",trueModel.SpecificationId),
                    new SqlParameter("@GoodsName",trueModel.GoodsName),
                    new SqlParameter("@GoodsTypeId",trueModel.GoodsTypeId),
                    new SqlParameter("@Weight",trueModel.Weight),
                    new SqlParameter("@StatusId",trueModel.StatusId),
                    new SqlParameter("@Price",trueModel.Price),
                    new SqlParameter("@GoodsLength",trueModel.GoodsLength),
                    new SqlParameter("@GoodsWidth",trueModel.GoodsWidth),
                    new SqlParameter("@GoodsHeight",trueModel.GoodsHeight),
                    new SqlParameter("@Unit",trueModel.Unit),
                    new SqlParameter("@WarningInventory",trueModel.WarningInventory),
                    new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
                    new SqlParameter("@Operator",trueModel.Operator),
                    new SqlParameter("@Remark",trueModel.Remark)
                    ,new SqlParameter("@OrderNum",trueModel.OrderNum)
                  
            };
            try
            {
                _dataBase.Query("sp_OA_GoodsInfo_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_GoodsInfo trueModel = model as Model.OA_GoodsInfo;
            if (trueModel == null)
            {
                return false;
            }
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {
                    new SqlParameter("@Keyid",trueModel.Keyid),
                    new SqlParameter("@FirmId",trueModel.FirmId),
                    new SqlParameter("@BrandId",trueModel.BrandId),
                    new SqlParameter("@SpecificationId",trueModel.SpecificationId),
                    new SqlParameter("@GoodsName",trueModel.GoodsName),
                    new SqlParameter("@GoodsTypeId",trueModel.GoodsTypeId),
                    new SqlParameter("@Weight",trueModel.Weight),
                    new SqlParameter("@StatusId",trueModel.StatusId),
                    new SqlParameter("@Price",trueModel.Price),
                    new SqlParameter("@GoodsLength",trueModel.GoodsLength),
                    new SqlParameter("@GoodsWidth",trueModel.GoodsWidth),
                    new SqlParameter("@GoodsHeight",trueModel.GoodsHeight),
                    new SqlParameter("@Unit",trueModel.Unit),
                    new SqlParameter("@WarningInventory",trueModel.WarningInventory),
                    new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
                    new SqlParameter("@Operator",trueModel.Operator),
                    new SqlParameter("@Remark",trueModel.Remark) ,
                    new SqlParameter("@OrderNum",trueModel.OrderNum)
            };
            IList<SqlParameter> sqlParmsWhere = new List<SqlParameter>()
            {
                    new SqlParameter("@CommodityId",trueModel.GoodsTypeId),
                    new SqlParameter("@GoodsId",trueModel.Keyid)
            };
            try
            {
                _dataBase.ExecuteSql("UPDATE dbo.OA_Brand SET CommodityId = @CommodityId WHERE GoodsId=@GoodsId", sqlParmsWhere.ToArray<SqlParameter>());
                _dataBase.ExecuteSql("UPDATE dbo.OA_PaperWeight SET CommodityId = @CommodityId WHERE GoodsId=@GoodsId", sqlParmsWhere.ToArray<SqlParameter>());
                _dataBase.ExecuteSql("UPDATE dbo.OA_Specification SET CommodityId = @CommodityId WHERE GoodsId=@GoodsId", sqlParmsWhere.ToArray<SqlParameter>());
                _dataBase.Query("sp_OA_GoodsInfo_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_GoodsInfo trueModel = model as Model.OA_GoodsInfo;
            if (trueModel == null)
            {
                return false;
            }
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {
                new SqlParameter("@Keyid",trueModel.Keyid)
            };
            try
            {
                _dataBase.Query("sp_OA_GoodsInfo_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_GoodsInfo> SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
        {
            throw new NotImplementedException();
        }
 
        public IEnumerable<Model.OA_GoodsInfo> SelectModelPage(Pagination pa, Guid FirmId, string GoodsName, string CommodityName ,string selGoodsStatus)
        {
 
            string Condition = " where a.FirmId='" + FirmId + "' ";
            if (!string.IsNullOrEmpty(GoodsName))
            {
                Condition += "  and a.GoodsName like '%" + GoodsName + "%' ";
            }
            if (!string.IsNullOrEmpty(CommodityName))
            {
                Condition += "  and a.GoodsTypeId = " + CommodityName + " ";
            }
            if (!string.IsNullOrEmpty(selGoodsStatus))
            {
                Condition += "  and a.StatusId = " + selGoodsStatus + " ";
            }
            string selTarget = "a.* ,b.Name AS brandName,c.Name as SpecificationName,d.Name as  StatusName,e.CommodityName as CommodityName";
 
            string fromSource = @" oa_GoodsInfo AS a left join oa_brand AS b ON a.BrandId=b.Keyid left join OA_Specification AS c  on a.SpecificationId=c.Keyid left join Sys_Dictionary AS d on a.StatusId=d.Keyid left join OA_Commodity as e  on a.GoodsTypeId=e.Keyid " + Condition + "";
 
            return _dataBase.SelectModelPage<Model.OA_GoodsInfo>(pa, selTarget, fromSource, " a.GoodsTypeId,a.OrderNum ASC ", "GoodsTypeId ,OrderNum ASC", "");
 
        }
 
        /// <summary>
        /// 单个查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public IEnumerable<Model.OA_GoodsInfo> SelectAllModel(Infrastructure.Query.Query query)
        {
            throw new NotImplementedException();
        }
 
        public Model.OA_GoodsInfo SelectSingleModel(string Keyid)
        {
            try
            {
                string Condition = "where Keyid='" + Keyid + "' ";
                string selTarget = " a.* ,b.Name AS brandName,c.Name as SpecificationName,d.Name as  StatusName,e.CommodityName as CommodityName  ";
                string fromSource = "  (select * from oa_GoodsInfo   " + Condition + ") AS a left join oa_brand AS b ON a.BrandId=b.Keyid left join OA_Specification AS c  on a.SpecificationId=c.Keyid left join Sys_Dictionary AS d on a.StatusId=d.Keyid left join OA_Commodity as e  on a.GoodsTypeId=e.Keyid";
                return _dataBase.SelectModel<Model.OA_GoodsInfo>(selTarget, fromSource)[0];
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 
        /// <summary>
        /// 获取table类型的全部数据
        /// </summary>
        /// <returns></returns>
        public DataTable SelectTableList(Guid FirmId)
        {
            string selectTarget = " * ";
            string fromSource = " OA_GoodsInfo  where FirmId='" + FirmId + "' ";
            return _dataBase.SelectModel(selectTarget, fromSource);
        }
 
        public DataTable SlectModleByCommity(string GoodsTypeId, Guid FirmId)
        {
            string selectTarget = " * ";
            string fromSource = string.Empty;
            if (string.IsNullOrEmpty(GoodsTypeId))
            {
                fromSource = " OA_GoodsInfo where FirmId = '" + FirmId + "'";
            }
            else
            {
                fromSource = " OA_GoodsInfo  where FirmId = '" + FirmId + "' and GoodsTypeId='" + GoodsTypeId + "' ";
            }
            return _dataBase.SelectModel(selectTarget, fromSource);
        }
 
        /// <summary>
        /// 货品名字是否存在
        /// </summary>
        /// <param name="GoodsName"></param>
        /// <param name="FirmId"></param>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool isExistGoodsName(String GoodsName, Guid FirmId, int ID)
        {
            Model.OA_GoodsInfo model;
            String selectTarget = " * ";
            string fromSouce = "OA_GoodsInfo where GoodsName='" + GoodsName + "' and FirmId='" + FirmId + "'";
            if (_dataBase.SelectModel<Model.OA_GoodsInfo>(selectTarget, fromSouce).Count > 0)
            {
                model = _dataBase.SelectModel<Model.OA_GoodsInfo>(selectTarget, fromSouce)[0];
            }
            else
            {
                model = null;
            }
 
 
            if (model == null)
            {
                return true;
            }
            else
            {
                if (ID == model.Keyid)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
    }
}