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