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