username@email.com
2025-05-21 a980cd04341d71216e0f59bd4b7327fe9fc50032
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
/**  
* EC_DemandDescribeDAL.cs
*
* 功 能: 用户需求信息数据访问实现
* 类 名: EC_DemandDescribeDAL
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013-4-12 9:23       吴崎均    更改InsertModel以及UpdateModel以与存储相匹配
* V0.02                       吴崎均    新增分页实现、获取单个实体实现 
* V0.03  2013-4-18 16:00      吴崎均    新增批量删除 
* V0.04  2013-5-3 10:15       吴崎均    变更字典表关联数据为DicType + MeanValue
* V0.05  2013-5-28 13:43      吴崎均    修改批量删除方法定义及实现
* V0.06  2013-6-2 10:42       吴崎均    增加修改状态方法
*
*
*
*
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL;
using System.Data.SqlClient;
using System.Data;
using CY.Model;
using CY.Infrastructure.Query;
 
namespace CY.SQLDAL
{
 
 
    /// <summary>
    /// 用户信息数据访问实现
    /// </summary>
    public class EC_DemandDescribeDAL : IEC_DemandDescribeDAL
    {
 
        private Database _dataBase = null;
 
 
        #region 常量
 
        /// <summary>
        /// 查询目标 
        /// </summary>
        const string SELECTTARGET = @" d.*,
                                    p.PrintName as PrintTypeName,
                                    d_state.Name as StateName,
                                    d_calltype.Name as CallTypeName,
                                    m.Name as MemberName";
        /// <summary>
        /// 查询来源
        /// </summary>
        const string FROMSOUCEBEFORE = " EC_DemandDescribe  as d Inner Join EC_MemberBasic as m On(d.MemberId=m.MemberId  ";
        const string FROMSOUCEEND = " ) " +
                                    "left join SysInquiry_PrintingType as p On(d.PrintTypeId=p.Keyid) " +
                                    "Left Join Sys_Dictionary as d_state On(d_state.DicType='需求信息状态' And d.[State]=d_state.MeanValue) " +
                                    "Left Join Sys_Dictionary as d_calltype On(d_calltype.DicType ='通知类型' And d.[CallTypeId]=d_calltype.MeanValue) " +
                                    "";
        /// <summary>
        /// 分页默认排序字段
        /// </summary>
        const string ORDERBY = "d.Keyid desc";
        #endregion
 
        public EC_DemandDescribeDAL()
        {
            _dataBase = new Database();
        }
 
 
 
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
        {
            EC_DemandDescribe trueModel = model as EC_DemandDescribe;
            if (trueModel == null)
            {
                return false;
            }
            else { }
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {
                new SqlParameter("@MemberId",trueModel.MemberId),
                    new SqlParameter("@PrintTypeId",trueModel.PrintTypeId),
                    new SqlParameter("@DemandName",trueModel.DemandName),
                    new SqlParameter("@DemandDemand",trueModel.DemandDemand),
                    new SqlParameter("@EndTime",trueModel.EndTime),
                    new SqlParameter("@CallTypeId",trueModel.CallTypeId),
                    new SqlParameter("@State",trueModel.State),
                    new SqlParameter("@Operator",trueModel.Operator),
                    new SqlParameter("@Remark",trueModel.Remark) 
            };
            try
            {
                _dataBase.Query("sp_EC_DemandDescribe_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)
        {
            EC_DemandDescribe trueModel = model as EC_DemandDescribe;
            if (trueModel == null)
            {
                return false;
            }
            else { }
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {
                new SqlParameter("@Keyid",trueModel.Keyid),
                new SqlParameter("@MemberId",trueModel.MemberId),
                    new SqlParameter("@PrintTypeId",trueModel.PrintTypeId),
                    new SqlParameter("@DemandName",trueModel.DemandName),
                    new SqlParameter("@DemandDemand",trueModel.DemandDemand),
                    new SqlParameter("@EndTime",trueModel.EndTime),
                    new SqlParameter("@CallTypeId",trueModel.CallTypeId),
                    new SqlParameter("@State",trueModel.State),
                    new SqlParameter("@Operator",trueModel.Operator),
                    new SqlParameter("@Remark",trueModel.Remark) 
            };
            try
            {
                _dataBase.Query("sp_EC_DemandDescribe_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)
        {
            EC_DemandDescribe trueModel = model as EC_DemandDescribe;
            if (trueModel == null)
            {
                return false;
            }
            else { }
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {
                new SqlParameter("@Keyid",trueModel.Keyid)
            };
            try
            {
                _dataBase.Query("sp_EC_DemandDescribe_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<EC_DemandDescribe> SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
        {
            if (null == pagination || null == query || null == query.Criteria || 1 > query.Criteria.Count) return null; else { }
            //query.Criteria 首个元素必须是排序字段,其值为结果排序字段
 
            int maxParamIndex = query.Criteria.Count - 1;//最大索引
 
            string[] orderbys = new string[] { ORDERBY };
            string resultOrderBy = "";//结果集排序方式
 
            if ("@orderBy".Equals(query.Criteria[maxParamIndex].PropertyName))
            {
                orderbys = string.Format("{0}", query.Criteria[maxParamIndex].Value).Split(',');
                resultOrderBy = 1 == orderbys.Length ? resultOrderBy : orderbys[1];
            }
 
            string fromSouce = string.Format("{0}{1}{2}", FROMSOUCEBEFORE, query.Criteria[0].Value, FROMSOUCEEND);//拼装条件
            return _dataBase.SelectModelPage<EC_DemandDescribe>(pagination, SELECTTARGET, fromSouce, orderbys[0], resultOrderBy);
 
 
        }
 
 
        /// <summary>
        /// 分页查询(前台用)
        /// </summary>
        /// <param name="pagination">分页对象</param>
        /// <param name="province">省</param>
        /// <param name="city">市</param>
        /// <param name="printTypeId">印刷类型</param>
        /// <returns></returns>
        public IEnumerable<EC_DemandDescribe> SelectModelPage(Infrastructure.Query.Pagination pagination, string province = "", string city = "", int printTypeId = -1)
        {
 
            string stateId = "0";//获取有效类型编号
            //using (IDataReader reader = _dataBase.QueryDataReader("Select Keyid Form Sys_Dictionary Where DicType='需求信息状态' And MeanValue=0", CommandType.Text))
            //{
            //    if (reader.Read())
            //    {
            //        stateId = reader[0].ToString();
            //    }
            //}
            string condition = string.Format(" And d.State = {0}", stateId);
            if (!string.IsNullOrEmpty(province))
            {
                condition += string.Format(" And m.Province='{0}'", province);
            }
            else { }
            if (!string.IsNullOrEmpty(city))
            {
                condition += string.Format(" And m.City='{0}'", city);
            }
            else { }
            if (-1 != printTypeId)
            {
                condition += string.Format(" And d.PrintTypeId={0}", printTypeId);
            }
            else { }
 
            Query query = new Query(true);
            query.Criteria.Add(new Criterion("condition", condition));
            //query.Criteria.Add(new Criterion("orderBy", "CreateTime,CreateTime"));
 
            return SelectModelPage(query, pagination);
        }
 
 
        /// <summary>
        /// 分页查询(后台用)
        /// </summary>
        /// <param name="pagination">分页对象</param>
        /// <param name="memberId">会员编号</param>
        /// <param name="name">名称</param>
        /// <param name="beginDate">开始时间</param>
        /// <param name="endDate">结束时间</param>
        /// <param name="printTypeId">印刷类型</param>
        /// <param name="state">状态</param>
        /// <returns></returns>
        public IEnumerable<EC_DemandDescribe> SelectModelPage(Infrastructure.Query.Pagination pagination, Guid memberId, string name, DateTime? beginDate, DateTime? endDate, int printTypeId = -1, int? state = null)
        {
 
 
            string condition = "";
         
 
            if (state.HasValue && -1 != state)
            {
                condition += state == 0 ? " And d.EndTime  > Getdate() And d.State=0 " : " And ( d.EndTime  < Getdate() Or d.State <> 0  )"; // 0为未结束 1为已结束 -1为不限
            }
            else { }
            if (Guid.Empty != memberId)
            {
                condition += string.Format(" And d.MemberId='{0}'", memberId);
            }
            else { }
            if (string.IsNullOrEmpty(name))
            {
                condition += string.Format(" And d.DemandName like '%{0}%'", name);
            }
            if (beginDate.HasValue)
            {
                condition += string.Format(" And d.CreateTime >= '{0}'", beginDate.Value.ToString("yyyy-MM-dd"));
            }
            else { }
            if (endDate.HasValue)
            {
                condition += string.Format(" And d.CreateTime <= '{0}'", endDate.Value.ToString("yyyy-MM-dd"));
            }
            else { }
            if (-1 != printTypeId)
            {
                condition += string.Format(" And d.PrintTypeId={0}", printTypeId);
            }
            else { }
 
            Query query = new Query(true);
            query.Criteria.Add(new Criterion("condition", condition));
            //query.Criteria.Add(new Criterion("orderBy", "CreateTime,CreateTime"));
 
            return SelectModelPage(query, pagination);
        }
        /// <summary>
        /// 单个查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public IEnumerable<EC_DemandDescribe> SelectAllModel(Infrastructure.Query.Query query)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// 根据编号获取实体信息
        /// </summary>
        /// <param name="id">主键编号</param>
        /// <returns></returns>
        public EC_DemandDescribe SelectModleById(int id)
        {
            if (id < 1) return null;//错误数据返会空 
            else { }
            IList<EC_DemandDescribe> result = _dataBase.SelectModel<EC_DemandDescribe>(SELECTTARGET, string.Format("{0}{1}{2}{3}", FROMSOUCEBEFORE, " And Keyid=", id, FROMSOUCEEND));
            return null == result || result.Count == 0 ? null : result[0];//返回结果
        }
 
 
        /// <summary>
        /// 根据编号批量删除数据
        /// </summary>
        /// <param name="currentOperator">当前操作人</param>
        /// <param name="ids">编号集合</param>
        /// <returns></returns>
        public bool DeleteDataByIds(string currentOperator, params int[] ids)
        {
            return Database.DeleteDataByIds<EC_DemandDescribe>(this, currentOperator, ids);
        }
        /// <summary>
        /// 改变需求业务状态
        /// </summary>
        /// <param name="id">数据编号</param>
        /// <param name="state">状态</param>
        /// <returns></returns>
        public bool ChangeState(int id, int state)
        {
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {
                new SqlParameter("@Keyid",id),
                new SqlParameter("@State",state)
            };
            try
            {
                _dataBase.Query("EC_DemandDescribe_ChangeState", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
 
    }
}