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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL.Inquiry;
using CY.Infrastructure.Common;
using System.Transactions;
using CY.Model;
using System.Data.SqlClient;
using System.Data;
using CY.Model.Inquiry;
 
namespace CY.SQLDAL
{
    /// <summary>
    /// 模切费操作接口--SQL实现
    /// </summary>
    public class CuttingCostDAL : ICuttingCostDAL
    {
        Database _dataBase = null;
 
        public CuttingCostDAL()
        {
            _dataBase = new Database();
        }
 
        public IList<Model.Inquiry_CuttingCost> GetModelList(Guid inquiryId, int printingTyId, bool isByPapersize)
        {
            string selectTarget = string.Empty;
            string fromSouce = string.Empty;
            string condition = string.Empty;
            if (isByPapersize)
            {
                selectTarget = " a.Price,a.StartPrice,a.PlatemakPrice,a.PaperSizeValue as ShowId ,b.SizeName AS ShowName ";
                fromSouce = " Inquiry_CuttingCost a INNER JOIN dbo.SysInquiry_PaperSize b ON a.PaperSizeValue=b.KeyId ";
                condition = "  a.FirmId='" + inquiryId.ToString() + "' and a.PrintingTypeId='" + printingTyId + "' ORDER BY b.SizeValue DESC ";
            }
            else
            {
                selectTarget = " a.Price,a.StartPrice,a.PlatemakPrice,a.EnvelopeModeTypeId as ShowId,b.Name AS ShowName ";
                fromSouce = " Inquiry_CuttingCost a INNER JOIN dbo.SysInquiry_PaperSizeDetail b  ON a.EnvelopeModeTypeId=b.KeyId ";
                condition = "  a.FirmId='" + inquiryId.ToString() + "' and a.PrintingTypeId='" + printingTyId + "' ";
            }
            IList<Model.Inquiry_CuttingCost> result = _dataBase.SelectModel<Model.Inquiry_CuttingCost>(selectTarget, fromSouce, condition);
            return result;
        }
 
        
        public bool SaveModelList(IList<Model.Inquiry_CuttingCost> list, InquiryCondition inquiryCondition, int printingTyId, bool isByPapersize)
        {
            bool isSuccess = true;
            using (TransactionScope scope = new TransactionScope())
            {
                //执行复制全部询价参数数据
                if (inquiryCondition.IsFirstSave())
                {
                    new CommonInquiryHelper(_dataBase).CopyALLInquiryParameter(inquiryCondition);
                }
 
                foreach (Inquiry_CuttingCost model in list)
                {
                    isSuccess = UpdateModel(model,isByPapersize);
                    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 IsExitsModel(Guid firmId, Guid customerId, int printingTypeId, bool isByPapersize)
        {
            string selectTarget = " KeyId ";
            string fromSouce = " Inquiry_CuttingCost ";
            string condition = string.Empty;
            if (customerId == Guid.Empty)
            {
                condition = " FirmId='" + firmId.ToString() + "' AND CostomerId  is null and PrintingTypeId='" + printingTypeId + "' ";
            }
            else
            {
                condition = " FirmId='" + firmId.ToString() + "' AND CostomerId ='" + customerId.ToString() + "' and PrintingTypeId='" + printingTypeId + "' ";
            }
 
            if (isByPapersize)
            {
                condition += " and EnvelopeModeTypeId is null ";
            }
            else
            {
                condition += " and PaperSizeValue is null ";
            }
            IList<Model.Inquiry_CuttingCost> result = _dataBase.SelectModel<Model.Inquiry_CuttingCost>(selectTarget, fromSouce, condition);
            if (result == null || result.Count == 0)
                return false;
            else
                return true;
        }
 
        public bool InserModel(Infrastructure.Domain.IAggregateRoot model, bool isByPapersize)
        {
            //Model.Inquiry_CuttingCost trueModel = model as Model.Inquiry_CuttingCost;
            //if (trueModel == null)
            //{
            //    return false;
            //}
 
            //string tableName = @" Inquiry_CuttingCost ";
            //string columns = string.Empty;
            //string condition = "";
            //if (trueModel.CostomerId == Guid.Empty)
            //{
            //    columns = " '" + trueModel.FirmId + "',null, PrintingTypeId ,EnvelopeModeTypeId ,PaperSizeValue ,Price ,StartPrice ,Unit ,PlatemakPrice ,Operater , OperateTime ,LastUpdateTime ";
            //    condition = " [FirmId]='" + UtilConst.AdminFirmId + "' and PrintingTypeId='" + trueModel.PrintingTypeId + "'";
            //}
            //else
            //{
            //    if (IsExitsModel(trueModel.FirmId, Guid.Empty, trueModel.PrintingTypeId,isByPapersize))
            //    {
            //        columns = " '" + trueModel.FirmId + "','" + trueModel.CostomerId + "',PrintingTypeId ,PaperSizeValue ,Price ,StartPrice ,Unit ,PlatemakPrice ,Operater ,OperaterTime ,LastUpdateTime ";
            //        condition = " [FirmId]='" + trueModel.FirmId + "' AND CostomerId  is null and PrintingTypeId='" + trueModel.PrintingTypeId + "'";
            //    }
            //    else
            //    {
            //        columns = " '" + trueModel.FirmId + "','" + trueModel.CostomerId + "',PrintingTypeId ,PaperSizeValue ,Price ,StartPrice ,Unit ,PlatemakPrice ,Operater ,OperaterTime ,LastUpdateTime ";
            //        condition = " [FirmId]='" + UtilConst.AdminFirmId + "' and PrintingTypeId='" + trueModel.PrintingTypeId + "'";
            //    }
            //}
 
            //if (isByPapersize)
            //{
            //    condition += " and EnvelopeModeTypeId is null ";
            //}
            //else
            //{
            //    condition += " and PaperSizeValue is null ";
            //}
 
            //SqlParameter[] parameters = {
            //        new SqlParameter("@TableName", tableName),
            //        new SqlParameter("@Columns", columns),
            //        new SqlParameter("@Condition", condition)
            //};
            //try
            //{
            //    _dataBase.Query("sp_CopyModel", CommandType.StoredProcedure, parameters);
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            return true;
        }
 
        public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model,bool isByPapersize)
        {
            Model.Inquiry_CuttingCost trueModel = model as Model.Inquiry_CuttingCost;
            if (trueModel == null)
            {
                return false;
            }
            SqlParameter envelopeModeTypeIdPar = null;
            SqlParameter paperSizeValuePar = null;
            if (isByPapersize)
            {
                envelopeModeTypeIdPar = new SqlParameter("@EnvelopeModeTypeId", DBNull.Value);
                paperSizeValuePar = new SqlParameter("@PaperSizeValue", trueModel.PaperSizeValue);
            }
            else
            {
                envelopeModeTypeIdPar = new SqlParameter("@EnvelopeModeTypeId", trueModel.EnvelopeModeTypeId);
                paperSizeValuePar = new SqlParameter("@PaperSizeValue", DBNull.Value);
            }
            SqlParameter[] parameters = {
                    new SqlParameter("@FirmId", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@PrintingTypeId", SqlDbType.Int,4),
                    new SqlParameter("@Price", SqlDbType.Money,8),
                    new SqlParameter("@StartPrice", SqlDbType.Money,8),
                    new SqlParameter("@PlatemakPrice", SqlDbType.Money,8),
                    new SqlParameter("@Operater", SqlDbType.VarChar,20),
                    new SqlParameter("@LastUpdateTime", SqlDbType.DateTime),
                    envelopeModeTypeIdPar,
                    paperSizeValuePar
            };
            parameters[0].Value = trueModel.FirmId;
            parameters[1].Value = trueModel.PrintingTypeId;
            parameters[2].Value = trueModel.Price;
            parameters[3].Value = trueModel.StartPrice;
            parameters[4].Value = trueModel.PlatemakPrice;
            parameters[5].Value = trueModel.Operater;
            parameters[6].Value = trueModel.LastUpdateTime;
            try
            {
                _dataBase.Query("Inquiry_CuttingCost_Update", CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
 
        public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
        {
            throw new NotImplementedException();
        }
    }
}