username@email.com
2025-05-14 99ddfbcecf0fa2881eb3a91028257eef87dab6de
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.Model.Inquiry;
using System.Transactions;
using CY.Infrastructure.Common;
using System.Data.SqlClient;
using System.Data;
using CY.Model;
using CY.IDAL.Inquiry;
 
namespace CY.SQLDAL
{
    public class RecoverySysInquiryDataDAL : IRecoverySysInquiryDataDAL
    {
        private Database _dataBase = null;
 
        public RecoverySysInquiryDataDAL()
        {
            _dataBase = new Database();
        }
 
        public bool RecoverySysInquiryData(InquiryCondition condition,bool isAllRecovery)
        {
            bool isSuccess = true;
            CommonInquiryHelper commHelper = new CommonInquiryHelper(_dataBase);
            OA_CorporateClientsDAL corporateClientsDAL = new OA_CorporateClientsDAL(_dataBase);
            using (TransactionScope scope = new TransactionScope())
            {
                if (condition.CustomerId == Guid.Empty) //厂商恢复系统数据
                {
                    if (condition.InquiryId != Guid.Parse(UtilConst.AdminFirmId))
                    {
                        isSuccess = commHelper.DelInquiryParameterData(condition.InquiryId);
                        if (isSuccess)
                            isSuccess = UpdateInquiryIdByFirm(condition.FirmId);
                    }
                    if (isSuccess)
                    {
                        IEnumerable<OA_CorporateClients> clients = corporateClientsDAL.SelectListByFirmId(condition.FirmId);
                        foreach (OA_CorporateClients client in clients)
                        {
                            if (!isAllRecovery)
                            {
                                if (client.InquiryId == client.Keyid)
                                {
                                    continue;
                                }
                            }
                            if (client.InquiryId != Guid.Parse(UtilConst.AdminFirmId))
                            {
                                isSuccess = commHelper.DelInquiryParameterData(client.InquiryId);
                                if (!isSuccess)
                                    break;
                                else
                                {
                                    isSuccess = UpdateInquiryIdByCustomerToSys(client.Keyid);
                                    if (!isSuccess)
                                        break;
                                }
                            }
                        }
                    }
                }
                else //客户恢复到厂商数据
                {
                    if (condition.InquiryId == condition.CustomerId) 
                    {
                        isSuccess = commHelper.DelInquiryParameterData(condition.InquiryId);
                        if (isSuccess)
                        {
                            isSuccess = UpdateInquiryIdByCustomerToFirm(condition.CustomerId, condition.FirmId);
                        }
                    }
                }
                if (isSuccess)
                    scope.Complete();
            }
            return isSuccess;
        }
 
        /// <summary>
        /// 修改厂商的询价参数Id为厂商的询价参数
        /// </summary>
        /// <param name="customerd"></param>
        /// <param name="firmId"></param>
        /// <returns></returns>
        public bool UpdateInquiryIdByCustomerToFirm(Guid customerd, Guid firmId)
        {
            bool isSuccess = true;
            try
            {
                string sqlStr = string.Empty;
                Guid firmInquiryId = Guid.Empty;
                EC_MemberBasicDAL memberBasicDAL = new EC_MemberBasicDAL(_dataBase);
                EC_MemberBasic memberBasic = memberBasicDAL.SelectModleByMemberId(firmId);
                firmInquiryId = memberBasic.InquiryId;
                sqlStr = @"UPDATE dbo.OA_CorporateClients SET InquiryId=@firmInquiryId WHERE keyid=@customerd";
                SqlParameter[] pars = new SqlParameter[]{
                    new SqlParameter("@firmInquiryId",SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@customerd",SqlDbType.UniqueIdentifier,16),
                };
                pars[0].Value = firmInquiryId;
                pars[1].Value = customerd;
                isSuccess = (_dataBase.ExecuteSql(sqlStr, pars) > 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return isSuccess;
        }
 
        //修改厂商的询价参数Id为系统ID
        public bool UpdateInquiryIdByCustomerToSys(Guid customerd)
        {
            bool isSuccess = true;
            try
            {
                string sqlStr = @"UPDATE dbo.OA_CorporateClients SET InquiryId=@adminId WHERE keyid=@customerd";
                SqlParameter[] pars = new SqlParameter[]{
                    new SqlParameter("@adminId",SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@customerd",SqlDbType.UniqueIdentifier,16),
                };
                pars[0].Value = Guid.Parse(UtilConst.AdminFirmId);
                pars[1].Value = customerd;
                isSuccess = (_dataBase.ExecuteSql(sqlStr, pars) > 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return isSuccess;
        }
 
        /// <summary>
        /// 修改厂商的询价参数Id为系统ID
        /// </summary>
        /// <param name="firmId"></param>
        /// <returns></returns>
        public bool UpdateInquiryIdByFirm(Guid firmId)
        {
            bool isSuccess = true;
            try
            {
                string sqlStr = @"UPDATE dbo.EC_MemberBasic SET InquiryId=@adminId WHERE MemberId=@firmId";
                SqlParameter[] pars = new SqlParameter[]{
                    new SqlParameter("@adminId",SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@firmId",SqlDbType.UniqueIdentifier,16),
                };
                pars[0].Value = Guid.Parse(UtilConst.AdminFirmId);
                pars[1].Value = firmId;
                isSuccess = (_dataBase.ExecuteSql(sqlStr,pars)>0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return isSuccess;
        }
    }
}