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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL.Inquiry;
using CY.Model;
using System.Data.SqlClient;
using System.Data;
using System.Transactions;
using CY.Infrastructure.Common;
namespace CY.SQLDAL
{
    /// <summary>
    /// 纸张类别相关操作--SQL数据库操作
    /// </summary>
    public class PaperTypeDAL : IPaperTypeDAL
    {
 
        private Database _dataBase = null;
 
        public PaperTypeDAL()
        {
            _dataBase = new Database();
        }
 
        /// <summary>
        /// 新增纸张类别
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.SysInquiry_PaperType trueModel = model as Model.SysInquiry_PaperType;
            if (trueModel == null)
            {
                return false;
            }
            SqlParameter[] parameters = {
                    new SqlParameter("@PaperTypeName", SqlDbType.VarChar,50),
                    new SqlParameter("@Status", SqlDbType.Int,4),
                    new SqlParameter("@OrderNum", SqlDbType.Int,4)};
            parameters[0].Value = trueModel.PaperTypeName;
            parameters[1].Value = trueModel.Status;
            parameters[2].Value = trueModel.OrderNum;
            try
            {
                _dataBase.Query("SysInquiry_PaperType_ADD", CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
        /// <summary>
        /// 修改纸张类别
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
        {
            bool isSuccess = true;
            PaperInfoDAL _paperInfoDAL = new PaperInfoDAL(_dataBase);
            using (TransactionScope scope = new TransactionScope())
            {
                Model.SysInquiry_PaperType trueModel = model as Model.SysInquiry_PaperType;
                if (trueModel == null)
                {
                    isSuccess = false;
                }
                else
                {
                    SqlParameter[] parameters = {
                    new SqlParameter("@PaperTypeName", SqlDbType.VarChar,50),
                    new SqlParameter("@Status", SqlDbType.Int,4),
                    new SqlParameter("@OrderNum", SqlDbType.Int,4),
                    new SqlParameter("@KeyId", SqlDbType.Int,4)};
                    parameters[0].Value = trueModel.PaperTypeName;
                    parameters[1].Value = trueModel.Status;
                    parameters[2].Value = trueModel.OrderNum;
                    parameters[3].Value = trueModel.KeyId;
                    try
                    {
                        _dataBase.Query("SysInquiry_PaperType_Update", CommandType.StoredProcedure, parameters);
                        isSuccess = true;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    if (isSuccess)
                    {
                            SysInquiry_PaperInfo paperModel = new SysInquiry_PaperInfo();
                            paperModel.PaperTypeId = trueModel.KeyId;
                            if (trueModel.Status == 1)
                            {
                                paperModel.Status = true;
                            }
                            else
                            {
                                paperModel.Status = false;
                            }
                            isSuccess = _paperInfoDAL.UpdatePaperStatus(paperModel);
                    }
                    if (isSuccess)
                        scope.Complete();
                }
            }
            return isSuccess;
        }
        /// <summary>
        /// 删除纸张类别
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
        {
            return false;
        }
 
        /// <summary>
        /// 分页返回纸张类别列表
        /// </summary>
        /// <param name="brandName">类别名称</param>
        /// <param name="pagination">分页参数</param>
        /// <returns></returns>
        public IEnumerable<Model.SysInquiry_PaperType> SelectModelPage(string typeName,int status,Infrastructure.Query.Pagination pagination)
        {
            string condition=string.Empty;
            condition = " 1=1 ";
            if (!string.IsNullOrEmpty(typeName))
            {
                condition = " and PaperTypeName like '%" + typeName + "%'";
            }
            if (status != -1)
            {
                condition += " and Status=" + status;
            }
            return _dataBase.SelectModelPage<SysInquiry_PaperType>(pagination, "*", "SysInquiry_PaperType", "OrderNum", "OrderNum", condition);
        }
 
        /// <summary>
        /// 根据主键返回品牌实体
        /// </summary>
        /// <param name="keyid">主键ID</param>
        /// <returns>品牌实体</returns>
        public SysInquiry_PaperType SelectModelByKey(int keyid)
        {
            string condition=string.Empty;
            condition=" KeyId="+keyid;
            IList<SysInquiry_PaperType> result = _dataBase.SelectModel<SysInquiry_PaperType>("*", "SysInquiry_PaperType", condition);
            return null == result || result.Count == 0 ? null : result[0];
        }
 
        /// <summary>
        /// 判断是否有相同的纸张类别名称
        /// </summary>
        /// <param name="brandName"></param>
        /// <returns></returns>
        public bool IsExistsPaperTypeName(string typeName)
        {
            string condition=string.Empty;
            condition = " PaperTypeName='" + typeName + "'";
            IList<SysInquiry_PaperType> result = _dataBase.SelectModel<SysInquiry_PaperType>("*", "SysInquiry_PaperType", condition);
            if(result!=null&&result.Count!=0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
 
        /// <summary>
        /// 返回所有有效的纸张类别列表
        /// </summary>
        /// <returns></returns>
        public IEnumerable<SysInquiry_PaperType> GetPaperTypeList()
        {
            string condition = string.Empty;
            condition = " Status=1 order by OrderNum ";
            IList<SysInquiry_PaperType> result = _dataBase.SelectModel<SysInquiry_PaperType>("*", "SysInquiry_PaperType", condition);
            return result;
        }
 
        /// <summary>
        /// 获取最新排序顺序
        /// </summary>
        /// <returns></returns>
        public int GetOrderNumByMax()
        {
            int orderNum = 1;
            IList<SysInquiry_PaperType> result = _dataBase.SelectModel<SysInquiry_PaperType>(" MAX(OrderNum)+1 AS OrderNum ", "SysInquiry_PaperType", string.Empty);
            if (result != null && result.Count > 0)
            {
                orderNum = result[0].OrderNum.Value;
            }
            return orderNum;
        }
    }
}