username@email.com
2025-05-12 ae6e40362a745caef9ead36f81f38313fb8c2c66
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
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;
 
namespace CY.SQLDAL
{
    public class ReduceWorkCountSetDAL : IReduceWorkCountSetDAL
    {
        Database _dataBase = null;
 
        public ReduceWorkCountSetDAL()
        {
            _dataBase = new Database();
        }
 
        public Model.Inquiry_ReduceWorkCountSet GetModel(Guid firmId, Guid customerId)
        {
            Inquiry_ReduceWorkCountSet model = null;
             //获取厂商设置的价格
            if (customerId == Guid.Empty)
            {
                model = GetModelByFirm(firmId);
            }
            else
            {
                model = GetModelByCustomer(firmId, customerId);
                if (model == null)
                {
                    model = GetModelByFirm(firmId);
                }
            }
            return model;
        }
 
        public Inquiry_ReduceWorkCountSet GetModelByFirm(Guid firmId)
        {
            Inquiry_ReduceWorkCountSet model = null;
            string selectTarget = " KeyId,Count ";
            string fromSouce = " Inquiry_ReduceWorkCountSet ";
            string condition = " FirmId='" + firmId.ToString() + "' and CustomerId is null ";
            IList<Model.Inquiry_ReduceWorkCountSet> result = _dataBase.SelectModel<Model.Inquiry_ReduceWorkCountSet>(selectTarget, fromSouce, condition);
            if (result != null && result.Count > 0)
            {
                model = result[0];
            }
            return model;
        }
 
        public Inquiry_ReduceWorkCountSet GetModelByCustomer(Guid firmId, Guid customerId)
        {
            Inquiry_ReduceWorkCountSet model = null;
            string selectTarget = " KeyId,Count ";
            string fromSouce = " Inquiry_ReduceWorkCountSet ";
            string condition = " FirmId='" + firmId.ToString() + "' and CustomerId='" + customerId.ToString() + "'";
            IList<Model.Inquiry_ReduceWorkCountSet> result = _dataBase.SelectModel<Model.Inquiry_ReduceWorkCountSet>(selectTarget, fromSouce, condition);
            if (result != null && result.Count > 0)
            {
                model = result[0];
            }
            return model;
        }
 
        public bool IsExits(Guid firmId, Guid customerId)
        {
            string selectTarget = " KeyId ";
            string fromSouce = " Inquiry_ReduceWorkCountSet ";
            string condition = string.Empty;
            if (customerId == Guid.Empty)
            {
                condition = " FirmId='" + firmId.ToString() + "'";
            }
            else
            {
                condition = " FirmId='" + firmId.ToString() + "' and CustomerId='" + customerId.ToString() + "'";
            }
            IList<Model.Inquiry_ReduceWorkCountSet> result = _dataBase.SelectModel<Model.Inquiry_ReduceWorkCountSet>(selectTarget, fromSouce, condition);
            if (result == null || result.Count == 0)
                return false;
            else
                return true;
        }
 
        public bool SaveModel(Model.Inquiry_ReduceWorkCountSet model)
        {
            bool isSuccess = true;
            if (IsExits(model.FirmId, model.CustomerId))
            {
                isSuccess = UpdateModel(model);
            }
            else
            {
                isSuccess = InserModel(model);
            }
            return isSuccess;
        }
 
        public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.Inquiry_ReduceWorkCountSet trueModel = model as Model.Inquiry_ReduceWorkCountSet;
            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("@Count",SqlDbType.Int),
                    cusPar
            };
            parameters[0].Value = trueModel.FirmId;
            parameters[1].Value = trueModel.Count;
            try
            {
                _dataBase.Query("Inquiry_ReduceWorkCountSet_ADD", CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
 
        public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.Inquiry_ReduceWorkCountSet trueModel = model as Model.Inquiry_ReduceWorkCountSet;
            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("@Count", SqlDbType.Int),
                    cusPar
            };
            parameters[0].Value = trueModel.FirmId;
            parameters[1].Value = trueModel.Count;
            try
            {
                _dataBase.Query("Inquiry_ReduceWorkCountSet_Update", CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
    }
}