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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL.Inquiry;
using System.Transactions;
using CY.Infrastructure.Common;
using System.Data.SqlClient;
using System.Data;
using CY.Model.Inquiry;
using CY.Model;
 
namespace CY.SQLDAL
{
    /// <summary>
    /// 厂商快速设置表操作接口--SQL实现
    /// </summary>
    public class FastSetByFirmDAL : IFastSetByFirmDAL
    {
        Database _dataBase = null;
 
        public FastSetByFirmDAL()
        {
            _dataBase = new Database();
        }
 
        /// <summary>
        /// 获取设置的快速价格
        /// </summary>
        /// <param name="firmId"></param>
        /// <param name="customerId"></param>
        /// <returns></returns>
        public  IList<Inquiry_FastSetByFirm> GetModelList(Guid firmId,Guid customerId)
        {
            IList<Inquiry_FastSetByFirm> list = new List<Inquiry_FastSetByFirm>();
            //获取厂商设置的价格
            if (customerId == Guid.Empty)
            {
                list = GetModelListByFirm(firmId);
                if (list == null || list.Count == 0)
                {
                    list = GetModelListByAdmin();
                }
            }
            else //获取客户设置的价格
            {
                list = GetModelListByCustomer(firmId,customerId);
                if (list == null || list.Count == 0)
                {
                    list = GetModelListByFirm(firmId);
                    if (list == null || list.Count == 0)
                    {
                        list = GetModelListByAdmin();
                    }
                }
            }
            return list;
        }
 
        /// <summary>
        /// 获取系统设置的快速价格
        /// </summary>
        /// <returns></returns>
        public IList<Inquiry_FastSetByFirm> GetModelListByAdmin()
        {
            //string selectTarget = " a.FastValue,a.PrintTypeId,b.PrintName AS PrintTypeName ";
            //string fromSouce = " Inquiry_FastSetByFirm a INNER JOIN SysInquiry_PrintingType b ON a.PrintTypeId=b.KeyId ";
            //string condition = " a.FirmId='" + UtilConst.AdminFirmId + "' ";
            //IList<Model.Inquiry_FastSetByFirm> result = _dataBase.SelectModel<Model.Inquiry_FastSetByFirm>(selectTarget, fromSouce, condition);
            //return result;
            string selectTarget = " 100 AS FastValue,KeyId AS PrintTypeId,PrintName AS PrintTypeName ";
            string fromSouce = " SysInquiry_PrintingType ";
            string condition = " ParentId<>0 AND Status=1 ORDER BY orderNum ";
            IList<Model.Inquiry_FastSetByFirm> result = _dataBase.SelectModel<Model.Inquiry_FastSetByFirm>(selectTarget, fromSouce, condition);
            return result;
        }
 
        /// <summary>
        /// 获取厂商设置的快速价格
        /// </summary>
        /// <returns></returns>
        public IList<Inquiry_FastSetByFirm> GetModelListByFirm(Guid firmId)
        {
            string selectTarget = " a.FastValue,a.PrintTypeId,b.PrintName AS PrintTypeName ";
            string fromSouce = " Inquiry_FastSetByFirm a INNER JOIN SysInquiry_PrintingType b ON a.PrintTypeId=b.KeyId ";
            string condition = " a.FirmId='" + firmId.ToString() + "' and a.CustomerId is null ";
            IList<Model.Inquiry_FastSetByFirm> result = _dataBase.SelectModel<Model.Inquiry_FastSetByFirm>(selectTarget, fromSouce, condition);
            return result;
        }
 
        /// <summary>
        /// 获取厂商的客户设置的快速价格
        /// </summary>
        /// <returns></returns>
        public IList<Inquiry_FastSetByFirm> GetModelListByCustomer(Guid firmId,Guid customerId)
        {
            string selectTarget = " a.FastValue,a.PrintTypeId,b.PrintName AS PrintTypeName ";
            string fromSouce = " Inquiry_FastSetByFirm a INNER JOIN SysInquiry_PrintingType b ON a.PrintTypeId=b.KeyId ";
            string condition = " a.FirmId='" + firmId.ToString() + "' and a.CustomerId='" + customerId.ToString() + "'";
            IList<Model.Inquiry_FastSetByFirm> result = _dataBase.SelectModel<Model.Inquiry_FastSetByFirm>(selectTarget, fromSouce, condition);
            return result;
 
            
        }
 
 
        public bool SaveModelList(IList<Inquiry_FastSetByFirm> modelList)
        {
            bool isSuccess = true;
            using (TransactionScope scope = new TransactionScope())
            {
                foreach (Inquiry_FastSetByFirm model in modelList)
                {
                    if(IsExits(model.FirmId,model.CustomerId,model.PrintTypeId))
                    {
                        isSuccess=UpdateModel(model);
                        if(!isSuccess)
                            break;
                    }
                    else
                    {
                        isSuccess=InserModel(model);
                        if(!isSuccess)
                            break;
                    }
                }
                if (isSuccess)
                   scope.Complete();
            }
            return isSuccess;
        }
 
        /// <summary>
        /// 判断是否存在
        /// </summary>
        /// <param name="model"></param>
        /// <param name="firmId"></param>
        /// <param name="customerId"></param>
        /// <returns></returns>
        public bool IsExits(Guid firmId, Guid customerId, int printTypeId)
        {
            string selectTarget = " FirmId ";
            string fromSouce = " Inquiry_FastSetByFirm ";
            string condition = string.Empty;
            if (customerId == Guid.Empty)
            {
                condition = " FirmId='" + firmId.ToString() + "' and printTypeId=" + printTypeId;
            }
            else
            {
                condition = " FirmId='" + firmId.ToString() + "' and CustomerId='" + customerId.ToString() + "' and printTypeId=" + printTypeId;
            }
            IList<Model.Inquiry_FastSetByFirm> result = _dataBase.SelectModel<Model.Inquiry_FastSetByFirm>(selectTarget, fromSouce, condition);
            if (result == null || result.Count == 0)
                return false;
            else
                return true;
        }
 
        public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.Inquiry_FastSetByFirm trueModel = model as Model.Inquiry_FastSetByFirm;
            if (trueModel == null)
            {
                return false;
            }
            SqlParameter cusPar = null;
            if (trueModel.CustomerId == Guid.Empty)
            {
                cusPar = new SqlParameter("@CustomerId", DBNull.Value);
            }
            else
            {
                cusPar = new SqlParameter("@CustomerId", trueModel.CustomerId);
            }
            SqlParameter[] parameters = {
                    new SqlParameter("@FirmId", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@FastValue", SqlDbType.Float,8),
                    new SqlParameter("@PrintTypeId",SqlDbType.Int),
                    cusPar
            };
            parameters[0].Value = trueModel.FirmId;
            parameters[1].Value = trueModel.FastValue;
            parameters[2].Value = trueModel.PrintTypeId;
            try
            {
                _dataBase.Query("Inquiry_FastSetByFirm_ADD", CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
 
        public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.Inquiry_FastSetByFirm trueModel = model as Model.Inquiry_FastSetByFirm;
            if (trueModel == null)
            {
                return false;
            }
            SqlParameter cusPar = null;
            if (trueModel.CustomerId == Guid.Empty)
            {
                cusPar = new SqlParameter("@CustomerId", DBNull.Value);
            }
            else
            {
                cusPar = new SqlParameter("@CustomerId", trueModel.CustomerId);
            }
            SqlParameter[] parameters = {
                    new SqlParameter("@FirmId", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@FastValue", SqlDbType.Float,8),
                    new SqlParameter("@PrintTypeId",SqlDbType.Int),
                    cusPar
            };
            parameters[0].Value = trueModel.FirmId;
            parameters[1].Value = trueModel.FastValue;
            parameters[2].Value = trueModel.PrintTypeId;
            try
            {
                _dataBase.Query("Inquiry_FastSetByFirm_Update", CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
 
        public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
        {
            throw new NotImplementedException();
        }
    }
}