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;
|
}
|
}
|
}
|