using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using CY.IDAL.Inquiry;
|
using CY.Model;
|
using System.Data;
|
using System.Data.SqlClient;
|
using System.Transactions;
|
using CY.Infrastructure.Common;
|
using CY.Model.Inquiry;
|
|
namespace CY.SQLDAL
|
{
|
/// <summary>
|
/// 纸张相关操作--SQL数据库操作
|
/// </summary>
|
public class PaperInfoDAL : IPaperInfoDAL
|
{
|
private Database _dataBase = null;
|
public PaperInfoDAL()
|
{
|
_dataBase = new Database();
|
}
|
|
public PaperInfoDAL(Database dataBase)
|
{
|
_dataBase = dataBase;
|
}
|
|
/// <summary>
|
/// 新增一条纸张记录
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.SysInquiry_PaperInfo trueModel = model as Model.SysInquiry_PaperInfo;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
SqlParameter[] parameters = {
|
new SqlParameter("@PapeId", SqlDbType.Int,4),
|
new SqlParameter("@PaperName", SqlDbType.VarChar,50),
|
new SqlParameter("@GramWeight", SqlDbType.Int,4),
|
new SqlParameter("@DefaultBrandId",SqlDbType.Int,4),
|
new SqlParameter("@Status", SqlDbType.Bit,1),
|
new SqlParameter("@Operater", SqlDbType.VarChar,20),
|
new SqlParameter("@OperateTime", SqlDbType.DateTime),
|
new SqlParameter("@LastUpdateTime", SqlDbType.DateTime),
|
new SqlParameter("@OrderNum", SqlDbType.Int,4),
|
new SqlParameter("@PaperTypeId", SqlDbType.Int,4)
|
};
|
parameters[0].Value = trueModel.PapeId;
|
parameters[1].Value = trueModel.PaperName;
|
parameters[2].Value = trueModel.GramWeight;
|
parameters[3].Value = DBNull.Value;
|
parameters[4].Value = trueModel.Status;
|
parameters[5].Value = trueModel.Operater;
|
parameters[6].Value = trueModel.OperateTime;
|
parameters[7].Value = trueModel.LastUpdateTime;
|
parameters[8].Value = trueModel.OrderNum;
|
parameters[9].Value = trueModel.PaperTypeId;
|
try
|
{
|
_dataBase.Query("SysInquiry_PaperInfo_ADD", CommandType.StoredProcedure, parameters);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
///// <summary>
|
///// 保存纸张的品牌列表
|
///// </summary>
|
//public bool SaveBrandListByPaper(SysInquiry_BrandListByPaper brandPaperModel,SysInquiry_PaperInfo paperModel)
|
//{
|
// bool isSuccess = true;
|
// isSuccess = DeleteBrandListByPaper(brandPaperModel);
|
// isSuccess = InsertBrandByPaper(brandPaperModel);
|
// if (isSuccess)
|
// {
|
// if (paperModel != null)
|
// {
|
// isSuccess = UpdateDefaultBrand(paperModel);
|
// }
|
// }
|
// return isSuccess;
|
//}
|
/// <summary>
|
/// 新增纸张的品牌
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool InsertBrandByPaper(SysInquiry_BrandListByPaper model, SysInquiry_PaperInfo paperModel)
|
{
|
bool isSuccess = true;
|
if (model == null)
|
{
|
isSuccess = false;
|
}
|
else
|
{
|
SqlParameter[] parameters = {
|
new SqlParameter("@PaperId", SqlDbType.Int,4),
|
new SqlParameter("@BrandId", SqlDbType.Int,4)};
|
parameters[0].Value = model.PaperId;
|
parameters[1].Value = model.BrandId;
|
try
|
{
|
_dataBase.Query("SysInquiry_BrandListByPaper_ADD", CommandType.StoredProcedure, parameters);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
if (isSuccess)
|
{
|
if (paperModel != null)
|
{
|
isSuccess = UpdateDefaultBrand(paperModel);
|
}
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 修改纸张的品牌
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool UpdateBrandByPaper(SysInquiry_BrandListByPaper model, SysInquiry_PaperInfo paperModel,SysInquiry_PaperInfo orPaperModel)
|
{
|
bool isSuccess = true;
|
if (model == null)
|
{
|
isSuccess = false;
|
}
|
else
|
{
|
SqlParameter[] parameters = {
|
new SqlParameter("@PaperId", SqlDbType.Int,4),
|
new SqlParameter("@BrandId", SqlDbType.Int,4)};
|
parameters[0].Value = model.PaperId;
|
parameters[1].Value = model.BrandId;
|
try
|
{
|
_dataBase.Query("SysInquiry_BrandListByPaper_Update", CommandType.StoredProcedure, parameters);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
if (isSuccess)
|
{
|
if (paperModel != null)
|
{
|
isSuccess = UpdateDefaultBrand(paperModel);
|
}
|
if (orPaperModel != null)
|
{
|
isSuccess = UpdateDefaultBrand(orPaperModel);
|
}
|
}
|
return true;
|
}
|
|
|
/// <summary>
|
/// 判断是否存在
|
/// </summary>
|
/// <param name="model"></param>
|
public bool isExists(SysInquiry_BrandListByPaper model)
|
{
|
string condition = string.Empty;
|
condition = " PaperId=" + model.PaperId + " and BrandId=" + model.BrandId + " ";
|
IList<SysInquiry_BrandListByPaper> result = _dataBase.SelectModel<SysInquiry_BrandListByPaper>("*", "SysInquiry_BrandListByPaper", condition);
|
if (result != null && result.Count > 0)
|
return true;
|
else
|
return false;
|
}
|
|
/// <summary>
|
/// 删除纸张的品牌
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool DeleteBrandListByPaper(SysInquiry_BrandListByPaper model)
|
{
|
SqlParameter[] parameters = {
|
new SqlParameter("@PaperId", SqlDbType.Int,4),
|
new SqlParameter("@BrandId", SqlDbType.Int,4)};
|
parameters[0].Value = model.PaperId;
|
parameters[1].Value = model.BrandId;
|
try
|
{
|
_dataBase.Query("SysInquiry_BrandListByPaper_Delete", CommandType.StoredProcedure, parameters);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 修改一条纸张信息
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.SysInquiry_PaperInfo trueModel = model as Model.SysInquiry_PaperInfo;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
SqlParameter[] parameters = {
|
new SqlParameter("@PapeId", SqlDbType.Int,4),
|
new SqlParameter("@PaperName", SqlDbType.VarChar,50),
|
new SqlParameter("@GramWeight", SqlDbType.Int,4),
|
new SqlParameter("@DefaultBrandId",SqlDbType.Int,4),
|
new SqlParameter("@Status", SqlDbType.Bit,1),
|
new SqlParameter("@Operater", SqlDbType.VarChar,20),
|
new SqlParameter("@OperateTime", SqlDbType.DateTime),
|
new SqlParameter("@LastUpdateTime", SqlDbType.DateTime),
|
new SqlParameter("@OrderNum", SqlDbType.Int,4),
|
new SqlParameter("@PaperTypeId", SqlDbType.Int,4)
|
};
|
parameters[0].Value = trueModel.PapeId;
|
parameters[1].Value = trueModel.PaperName;
|
parameters[2].Value = trueModel.GramWeight;
|
parameters[3].Value = DBNull.Value;
|
parameters[4].Value = trueModel.Status;
|
parameters[5].Value = trueModel.Operater;
|
parameters[6].Value = trueModel.OperateTime;
|
parameters[7].Value = trueModel.LastUpdateTime;
|
parameters[8].Value = trueModel.OrderNum;
|
parameters[9].Value = trueModel.PaperTypeId;
|
try
|
{
|
_dataBase.Query("SysInquiry_PaperInfo_Update", CommandType.StoredProcedure, parameters);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 修改纸张状态
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool UpdatePaperStatus(SysInquiry_PaperInfo model)
|
{
|
|
if (model == null)
|
{
|
return true;
|
}
|
SqlParameter[] parameters = {
|
new SqlParameter("@Status", SqlDbType.Bit,1),
|
new SqlParameter("@PaperTypeId", SqlDbType.Int,4)
|
};
|
parameters[0].Value = model.Status;
|
parameters[1].Value = model.PaperTypeId;
|
try
|
{
|
_dataBase.Query("SysInquiry_PaperInfo_Update2", CommandType.StoredProcedure, parameters);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 修改纸张的默认品牌
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool UpdateDefaultBrand(SysInquiry_PaperInfo model)
|
{
|
if (model == null)
|
return true;
|
SqlParameter dfaultBrandIdPar = null;
|
if (model.DefaultBrandId == null)
|
{
|
dfaultBrandIdPar = new SqlParameter("@DefaultBrandId", DBNull.Value);
|
}
|
else
|
{
|
dfaultBrandIdPar = new SqlParameter("@DefaultBrandId", model.DefaultBrandId.Value);
|
}
|
SqlParameter[] parameters = {
|
new SqlParameter("@PapeId", SqlDbType.Int,4),
|
dfaultBrandIdPar
|
};
|
parameters[0].Value = model.PapeId;
|
try
|
{
|
_dataBase.Query("SysInquiry_PaperInfo_Update1", CommandType.StoredProcedure, parameters);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 删除一条纸张信息
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.SysInquiry_PaperInfo trueModel = model as Model.SysInquiry_PaperInfo;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
SqlParameter[] parameters = {
|
new SqlParameter("@KeyId", SqlDbType.Int,4)
|
};
|
parameters[0].Value = trueModel.KeyId;
|
try
|
{
|
_dataBase.Query("SysInquiry_PaperInfo_Delete", CommandType.StoredProcedure, parameters);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 分页获取纸张列表
|
/// </summary>
|
/// <param name="paperName">品牌名称</param>
|
/// <param name="pa">分页参数</param>
|
/// <returns></returns>
|
public IEnumerable<Model.SysInquiry_PaperInfo> GetPaperListByPaging(string paperName,int paperTypeId,string stauts,Infrastructure.Query.Pagination pa)
|
{
|
string selectTarget = " t.PapeId,t.PaperTypeOrderNum,t.OrderNum ";
|
string fromSouce = string.Empty;
|
fromSouce = "( SELECT DISTINCT a.PapeId,b.OrderNum AS PaperTypeOrderNum,a.OrderNum FROM SysInquiry_PaperInfo a INNER JOIN dbo.SysInquiry_PaperType b ON a.PaperTypeId=b.KeyId where a.PapeId!=0 ";
|
if (!string.IsNullOrEmpty(paperName))
|
{
|
fromSouce += " and a.PaperName LIKE '%" + paperName + "%' ";
|
}
|
if (paperTypeId != -1)
|
{
|
fromSouce += " and a.PaperTypeId=" + paperTypeId;
|
}
|
if (!string.IsNullOrEmpty(stauts))
|
{
|
fromSouce += " and a.Status='" + stauts + "'";
|
}
|
fromSouce += " ) AS t ";
|
return _dataBase.SelectModelPage<Model.SysInquiry_PaperInfo>(pa, selectTarget, fromSouce, "t.PaperTypeOrderNum,t.OrderNum", "PaperTypeOrderNum,OrderNum",string.Empty);
|
}
|
|
/// <summary>
|
/// 根据paperId获取纸张信息
|
/// </summary>
|
/// <param name="paperId"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.SysInquiry_PaperInfo> GetPaperList(int paperId)
|
{
|
string selectTarget = " a.KeyId,a.PapeId,a.DefaultBrandId,b.BrandName AS DefaultBrandName,a.GramWeight,a.PaperName,a.Status,a.PaperTypeId,a.OrderNum,c.PaperTypeName";
|
string fromSouce = " SysInquiry_PaperInfo a left JOIN dbo.SysInquiry_BrandInfo b ON a.DefaultBrandId=b.KeyId left join SysInquiry_PaperType c on a.PaperTypeId=c.KeyId ";
|
string condition = string.Empty;
|
condition = " PapeId=" + paperId;
|
IList<Model.SysInquiry_PaperInfo> result = _dataBase.SelectModel<Model.SysInquiry_PaperInfo>(selectTarget, fromSouce , condition);
|
return result;
|
}
|
|
/// <summary>
|
/// 根据paperId获取其对应的品牌列表
|
/// </summary>
|
/// <param name="paperId"></param>
|
/// <returns></returns>
|
public IEnumerable<SysInquiry_BrandInfo> GetBrandInfoListByPaper(int paperId)
|
{
|
string selectTarget = "b.*";
|
string fromSouce = "dbo.SysInquiry_BrandListByPaper a INNER JOIN dbo.SysInquiry_BrandInfo b ON a.BrandId=b.KeyId ";
|
string condition = string.Empty;
|
condition = " a.PaperId=" + paperId + " ORDER BY b.OrderNum";
|
IList<Model.SysInquiry_BrandInfo> result = _dataBase.SelectModel<Model.SysInquiry_BrandInfo>(selectTarget, fromSouce, condition);
|
return result;
|
}
|
|
/// <summary>
|
/// 判断是否有相同的纸扎名称
|
/// </summary>
|
/// <param name="peperName"></param>
|
/// <returns></returns>
|
public bool IsExistspeperName(string peperName)
|
{
|
string condition = string.Empty;
|
condition = " PaperName='" + peperName + "'";
|
IList<SysInquiry_PaperInfo> result = _dataBase.SelectModel<SysInquiry_PaperInfo>("*", "SysInquiry_PaperInfo", condition);
|
if (result != null && result.Count != 0)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 获取最新的纸张编号
|
/// </summary>
|
/// <returns></returns>
|
public int GetNewPaperId()
|
{
|
string selColumns = " MAX(PapeId) as papeNum ";
|
string tableSql = " SysInquiry_PaperInfo";
|
DataTable result = _dataBase.SelectModel(selColumns, tableSql, string.Empty);
|
int newPaperId = 0;
|
if (result != null && result.Rows.Count > 0)
|
{
|
string resultStr = result.Rows[0][0].ToString();
|
if (string.IsNullOrEmpty(resultStr))
|
{
|
newPaperId = 1;
|
}
|
else
|
{
|
newPaperId = Convert.ToInt32(resultStr) + 1;
|
}
|
}
|
else
|
{
|
newPaperId = 1;
|
}
|
return newPaperId;
|
}
|
|
/// <summary>
|
/// 新增纸张
|
/// </summary>
|
/// <param name="modelList"></param>
|
/// <returns></returns>
|
public bool InsertPaper(IList<SysInquiry_PaperInfo> modelList, IList<SysInquiry_BrandListByPaper> brandList)
|
{
|
bool isSuccess = true;
|
using (TransactionScope scope = new TransactionScope())
|
{
|
foreach (SysInquiry_PaperInfo model in modelList)
|
{
|
|
isSuccess = InserModel(model);
|
if (!isSuccess)
|
break;
|
}
|
//isSuccess = SaveBrandListByPaper(brandList);
|
if (isSuccess)
|
scope.Complete();
|
}
|
return isSuccess;
|
}
|
|
/// <summary>
|
/// 修改纸张
|
/// </summary>
|
/// <param name="modelList"></param>
|
/// <returns></returns>
|
public bool UpdatePaper(IList<SysInquiry_PaperInfo> modelList, IList<SysInquiry_BrandListByPaper> brandList)
|
{
|
if (modelList == null || modelList.Count == 0)
|
return false;
|
int paperId = modelList[0].PapeId;
|
List<SysInquiry_PaperInfo> allPaperList = GetPaperList(paperId).ToList<SysInquiry_PaperInfo>();
|
List<SysInquiry_PaperInfo> insertPaperList = new List<SysInquiry_PaperInfo>();
|
List<SysInquiry_PaperInfo> updatePaperList = new List<SysInquiry_PaperInfo>();
|
List<SysInquiry_PaperInfo> deletePaperList = new List<SysInquiry_PaperInfo>();
|
|
foreach (SysInquiry_PaperInfo obj in modelList)
|
{
|
if (!isExists(allPaperList, obj.GramWeight))
|
insertPaperList.Add(obj);
|
else
|
updatePaperList.Add(obj);
|
}
|
|
foreach (SysInquiry_PaperInfo obj in allPaperList)
|
{
|
if (!isExists(modelList.ToList<SysInquiry_PaperInfo>(), obj.GramWeight))
|
deletePaperList.Add(obj);
|
}
|
|
bool isSuccess = true;
|
using (TransactionScope scope = new TransactionScope())
|
{
|
foreach (SysInquiry_PaperInfo model in insertPaperList)
|
{
|
isSuccess = InserModel(model);
|
if (!isSuccess)
|
break;
|
}
|
if (isSuccess)
|
{
|
foreach (SysInquiry_PaperInfo model in updatePaperList)
|
{
|
isSuccess = UpdateModel(model);
|
if (!isSuccess)
|
break;
|
}
|
}
|
if (isSuccess)
|
{
|
foreach (SysInquiry_PaperInfo model in deletePaperList)
|
{
|
isSuccess = DeleteModel(model);
|
if (!isSuccess)
|
break;
|
}
|
}
|
//if (isSuccess)
|
//{
|
// isSuccess = SaveBrandListByPaper(brandList);
|
//}
|
if (isSuccess)
|
scope.Complete();
|
}
|
return isSuccess;
|
}
|
|
/// <summary>
|
/// 判断是否存在
|
/// </summary>
|
/// <returns></returns>
|
private bool isExists(List<SysInquiry_PaperInfo> paperList, int gramWeight)
|
{
|
foreach (SysInquiry_PaperInfo model in paperList)
|
{
|
if (model.GramWeight == gramWeight)
|
return true;
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 获取有效的纸张列表(不包括自带纸)
|
/// </summary>
|
/// <returns></returns>
|
public IEnumerable<SysInquiry_PaperInfo> GetPaperList()
|
{
|
string selectTarget = " a.*,b.PaperTypeName ";
|
string fromSouce = " SysInquiry_PaperInfo a INNER JOIN SysInquiry_PaperType b ON a.PaperTypeId=b.KeyId ";
|
string condition = " a.Status='true' and a.papeId<>0 ORDER BY b.OrderNum,a.OrderNum ";
|
IList<Model.SysInquiry_PaperInfo> result = _dataBase.SelectModel<Model.SysInquiry_PaperInfo>(selectTarget, fromSouce, condition);
|
return result;
|
}
|
|
/// <summary>
|
/// 获取纸张类型下的所有有效纸张
|
/// </summary>
|
/// <param name="paperTypeId"></param>
|
/// <returns></returns>
|
public IEnumerable<SysInquiry_PaperInfo> GetPaperListByPaperType(int paperTypeId)
|
{
|
string condition = string.Empty;
|
condition = " PaperTypeId=" + paperTypeId + " and Status='true' and papeId<>0 order by OrderNum";
|
IList<Model.SysInquiry_PaperInfo> result = _dataBase.SelectModel<Model.SysInquiry_PaperInfo>(" DISTINCT PapeId,PaperName,OrderNum ", "SysInquiry_PaperInfo", condition);
|
return result;
|
}
|
|
/// <summary>
|
/// 获取有效的纸张列表(包括自带纸)
|
/// </summary>
|
/// <returns></returns>
|
public IEnumerable<SysInquiry_PaperInfo> GetAllPaperList()
|
{
|
string condition = string.Empty;
|
condition = " Status='true' order by OrderNum ";
|
IList<Model.SysInquiry_PaperInfo> result = _dataBase.SelectModel<Model.SysInquiry_PaperInfo>("*", "SysInquiry_PaperInfo", condition);
|
return result;
|
}
|
|
/// <summary>
|
/// 根据纸张Id和品牌Id获取纸价列表
|
/// </summary>
|
/// <param name="paperId"></param>
|
/// <param name="firmId"></param>
|
/// <param name="customerId"></param>
|
/// <returns></returns>
|
public IEnumerable<Inquiry_PaperPriceInfo> GetAllPaperPriceList(int paperId, int brandId, Guid inquiryId)
|
{
|
string selectTarget = " a.GramWeight,ISNULL(PaperPrice,0) AS PaperPrice ";
|
string fromSouce = " dbo.SysInquiry_PaperInfo a LEFT JOIN dbo.Inquiry_PaperPriceInfo b ON a.PapeId=b.PaperId and a.gramweight=b.gramweight AND b.BrandId=" + brandId + " and FirmId='" + inquiryId.ToString() + "'";
|
string condition = " a.PapeId=" + paperId+" order by a.GramWeight";
|
IList<Model.Inquiry_PaperPriceInfo> result = _dataBase.SelectModel<Model.Inquiry_PaperPriceInfo>(selectTarget, fromSouce, condition);
|
return result;
|
}
|
|
/// <summary>
|
/// 根据纸张Id和品牌Id获取系统设置的纸价列表
|
/// </summary>
|
/// <param name="paperId"></param>
|
/// <param name="brandId"></param>
|
/// <returns></returns>
|
private IEnumerable<Inquiry_PaperPriceInfo> GetAllPaperPriceListByAdmin(int paperId, int brandId)
|
{
|
string selectTarget = " a.GramWeight,ISNULL(PaperPrice,0) AS PaperPrice ";
|
string fromSouce = " dbo.SysInquiry_PaperInfo a LEFT JOIN dbo.Inquiry_PaperPriceInfo b ON a.PapeId=b.PaperId and a.gramweight=b.gramweight AND b.BrandId=" + brandId + " and FirmId='" + UtilConst.AdminFirmId + "'";
|
string condition = " a.PapeId=" + paperId;
|
IList<Model.Inquiry_PaperPriceInfo> result = _dataBase.SelectModel<Model.Inquiry_PaperPriceInfo>(selectTarget, fromSouce, condition);
|
return result;
|
}
|
|
/// <summary>
|
/// 根据纸张Id和品牌Id获取厂商设置的纸价列表
|
/// </summary>
|
/// <param name="paperId"></param>
|
/// <param name="brandId"></param>
|
/// <returns></returns>
|
private IEnumerable<Inquiry_PaperPriceInfo> GetAllPaperPriceListByFirm(int paperId, int brandId, string firmId)
|
{
|
string selectTarget = " a.GramWeight,ISNULL(PaperPrice,0) AS PaperPrice ";
|
string fromSouce = " dbo.SysInquiry_PaperInfo a LEFT JOIN dbo.Inquiry_PaperPriceInfo b ON a.PapeId=b.PaperId and a.gramweight=b.gramweight AND b.BrandId=" + brandId;
|
string condition = " a.PapeId=" + paperId + " and b.FirmId='" + firmId + "' and b.CustomerId is null ";
|
IList<Model.Inquiry_PaperPriceInfo> result = _dataBase.SelectModel<Model.Inquiry_PaperPriceInfo>(selectTarget, fromSouce, condition);
|
return result;
|
}
|
|
/// <summary>
|
/// 根据纸张Id和品牌Id获取厂商的客户设置的纸价列表
|
/// </summary>
|
/// <param name="paperId"></param>
|
/// <param name="brandId"></param>
|
/// <returns></returns>
|
private IEnumerable<Inquiry_PaperPriceInfo> GetAllPaperPriceListByCustomer(int paperId, int brandId, string firmId, string customerId)
|
{
|
string selectTarget = " a.GramWeight,ISNULL(PaperPrice,0) AS PaperPrice ";
|
string fromSouce = " dbo.SysInquiry_PaperInfo a LEFT JOIN dbo.Inquiry_PaperPriceInfo b ON a.PapeId=b.PaperId and a.gramweight=b.gramweight AND b.BrandId=" + brandId;
|
string condition = " a.PapeId=" + paperId + " and b.FirmId='" + firmId + "' and b.CustomerId='" + customerId + "'";
|
IList<Model.Inquiry_PaperPriceInfo> result = _dataBase.SelectModel<Model.Inquiry_PaperPriceInfo>(selectTarget, fromSouce, condition);
|
return result;
|
}
|
|
|
/// <summary>
|
/// 根据纸张Id和品牌ID保存纸价
|
/// </summary>
|
/// <param name="modelList"></param>
|
/// <returns></returns>
|
public bool SavePaperPrice(List<Inquiry_PaperPriceInfo> modelList, InquiryCondition inquiryCondition)
|
{
|
bool isSuccess = true;
|
using (TransactionScope scope = new TransactionScope())
|
{
|
if (inquiryCondition.ActualFirmId != Guid.Parse(UtilConst.AdminFirmId))
|
{
|
//执行复制全部询价参数数据
|
if (inquiryCondition.IsFirstSave())
|
{
|
new CommonInquiryHelper(_dataBase).CopyALLInquiryParameter(inquiryCondition);
|
}
|
|
foreach (Inquiry_PaperPriceInfo model in modelList)
|
{
|
isSuccess = UpdatePaperPriceModel(model);
|
if (!isSuccess)
|
break;
|
}
|
}
|
else
|
{
|
foreach (Inquiry_PaperPriceInfo model in modelList)
|
{
|
isSuccess = SavePaperPriceByGramWeightValue(model);
|
if (!isSuccess)
|
break;
|
}
|
}
|
if (isSuccess)
|
scope.Complete();
|
}
|
return isSuccess;
|
}
|
|
/// <summary>
|
/// 根据纸张Id和品牌ID,克重值保存纸价
|
/// </summary>
|
/// <param name="paperId"></param>
|
/// <param name="brandId"></param>
|
/// <param name="gramWeightValue"></param>
|
/// <param name="paperPrice"></param>
|
/// <param name="firmId"></param>
|
/// <param name="customerId"></param>
|
/// <returns></returns>
|
private bool SavePaperPriceByGramWeightValue(Inquiry_PaperPriceInfo model)
|
{
|
bool isExits = IsExitsPaperPriceByGramWeightValue(model.PaperId, model.BrandId, model.GramWeight, model.PaperPrice, model.FirmId);
|
if (isExits)
|
{
|
|
return UpdatePaperPriceModel(model);
|
}
|
else
|
{
|
return InsertPaperPriceModel(model);
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 判断价格是否已存在
|
/// </summary>
|
/// <param name="paperId"></param>
|
/// <param name="brandId"></param>
|
/// <param name="gramWeightValue"></param>
|
/// <param name="paperPrice"></param>
|
/// <param name="firmId"></param>
|
/// <param name="customerId"></param>
|
/// <returns></returns>
|
private bool IsExitsPaperPriceByGramWeightValue(int paperId, int brandId, int gramWeightValue, decimal paperPrice, Guid firmId)
|
{
|
string selectTarget = " KeyId ";
|
string fromSouce = " Inquiry_PaperPriceInfo ";
|
string condition = string.Empty;
|
condition = " PaperId=" + paperId + " AND BrandId=" + brandId + " AND GramWeight=" + gramWeightValue + " AND FirmId='" + firmId + "'";
|
IList<Model.Inquiry_PaperPriceInfo> result = _dataBase.SelectModel<Model.Inquiry_PaperPriceInfo>(selectTarget, fromSouce, condition);
|
if (result == null || result.Count == 0)
|
return false;
|
else
|
return true;
|
}
|
|
/// <summary>
|
/// 新增纸价信息
|
/// </summary>
|
private bool InsertPaperPriceModel(Inquiry_PaperPriceInfo model)
|
{
|
Model.Inquiry_PaperPriceInfo trueModel = model as Model.Inquiry_PaperPriceInfo;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
SqlParameter[] parameters = {
|
new SqlParameter("@FirmId", SqlDbType.UniqueIdentifier,16),
|
new SqlParameter("@PaperId", SqlDbType.Int,4),
|
new SqlParameter("@GramWeight", SqlDbType.Int,4),
|
new SqlParameter("@BrandId", SqlDbType.Int,4),
|
new SqlParameter("@PaperPrice", SqlDbType.Money,8),
|
new SqlParameter("@Unit", SqlDbType.VarChar,10),
|
new SqlParameter("@Status", SqlDbType.Bit,1),
|
new SqlParameter("@Operater", SqlDbType.VarChar,20),
|
new SqlParameter("@OperateTime", SqlDbType.DateTime),
|
new SqlParameter("@LastUpdateTime", SqlDbType.DateTime)
|
};
|
parameters[0].Value = trueModel.FirmId;
|
parameters[1].Value = trueModel.PaperId;
|
parameters[2].Value = trueModel.GramWeight;
|
parameters[3].Value = trueModel.BrandId;
|
parameters[4].Value = trueModel.PaperPrice;
|
parameters[5].Value = trueModel.Unit;
|
parameters[6].Value = trueModel.Status;
|
parameters[7].Value = trueModel.Operater;
|
parameters[8].Value = trueModel.OperateTime;
|
parameters[9].Value = trueModel.LastUpdateTime;
|
try
|
{
|
_dataBase.Query("Inquiry_PaperPriceInfo_ADD", CommandType.StoredProcedure, parameters);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 修改纸张价格
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
private bool UpdatePaperPriceModel(Inquiry_PaperPriceInfo model)
|
{
|
Model.Inquiry_PaperPriceInfo trueModel = model as Model.Inquiry_PaperPriceInfo;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
SqlParameter[] parameters = {
|
new SqlParameter("@FirmId", SqlDbType.UniqueIdentifier,16),
|
new SqlParameter("@PaperId", SqlDbType.Int,4),
|
new SqlParameter("@GramWeight", SqlDbType.Int,4),
|
new SqlParameter("@BrandId", SqlDbType.Int,4),
|
new SqlParameter("@PaperPrice", SqlDbType.Money,8),
|
new SqlParameter("@Operater", SqlDbType.VarChar,20),
|
new SqlParameter("@LastUpdateTime", SqlDbType.DateTime)
|
};
|
parameters[0].Value = trueModel.FirmId;
|
parameters[1].Value = trueModel.PaperId;
|
parameters[2].Value = trueModel.GramWeight;
|
parameters[3].Value = trueModel.BrandId;
|
parameters[4].Value = trueModel.PaperPrice;
|
parameters[5].Value = trueModel.Operater;
|
parameters[6].Value = trueModel.LastUpdateTime;
|
try
|
{
|
_dataBase.Query("Inquiry_PaperPriceInfo_Update", CommandType.StoredProcedure, parameters);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
public decimal GetTonsOfPrice(int paperId, int gramWeight, int brandId, Guid inquiryId)
|
{
|
decimal tonsOfPrice = 0;
|
string selectTarget = " PaperPrice ";
|
string fromSouce = " Inquiry_PaperPriceInfo ";
|
string condition = string.Empty;
|
condition = " PaperId=" + paperId + " AND BrandId=" + brandId + " AND GramWeight=" + gramWeight + " AND FirmId='" + inquiryId.ToString() + "'";
|
IList<Model.Inquiry_PaperPriceInfo> result = _dataBase.SelectModel<Model.Inquiry_PaperPriceInfo>(selectTarget, fromSouce, condition);
|
if (result != null && result.Count > 0)
|
{
|
tonsOfPrice = result[0].PaperPrice;
|
}
|
return tonsOfPrice;
|
}
|
|
|
/// <summary>
|
/// 获取纸张的品牌列表,第一个是默认品牌
|
/// </summary>
|
/// <param name="paperId"></param>
|
/// <returns></returns>
|
public IList<SysInquiry_BrandInfo> GetBrandInfoByPaper(int paperId)
|
{
|
IList<SysInquiry_BrandInfo> resultList = new List<SysInquiry_BrandInfo>();
|
IList<Model.SysInquiry_PaperInfo> paperList = GetPaperList(paperId).ToList<SysInquiry_PaperInfo>();
|
int defaultBrandId = -1;
|
if (paperList != null && paperList.Count()>0)
|
{
|
if (paperList[0].DefaultBrandId.HasValue)
|
{
|
defaultBrandId = paperList[0].DefaultBrandId.Value;
|
BrandInfoDAL _brandInfoDAL = new BrandInfoDAL(_dataBase);
|
SysInquiry_BrandInfo defaultModel = _brandInfoDAL.SelectModelByKey(defaultBrandId);
|
if (defaultModel!=null)
|
resultList.Add(defaultModel);
|
}
|
}
|
string selectTarget = " b.* ";
|
string fromSouce = " dbo.SysInquiry_BrandListByPaper a INNER JOIN dbo.SysInquiry_BrandInfo b ON a.BrandId=b.KeyId ";
|
string condition = " a.PaperId=" + paperId + " and a.BrandId<>" + defaultBrandId + " and b.Status='1' ORDER BY b.OrderNum ";
|
IList<SysInquiry_BrandInfo> brandInfoList = _dataBase.SelectModel<Model.SysInquiry_BrandInfo>(selectTarget, fromSouce, condition);
|
if (brandInfoList != null && brandInfoList.Count > 0)
|
{
|
foreach (SysInquiry_BrandInfo brand in brandInfoList)
|
{
|
resultList.Add(brand);
|
}
|
}
|
return resultList;
|
}
|
|
/// <summary>
|
/// 获取最新排序顺序
|
/// </summary>
|
/// <returns></returns>
|
public int GetOrderNumByMax(int paperTypeId)
|
{
|
int orderNum = 1;
|
IList<SysInquiry_PaperInfo> result = _dataBase.SelectModel<SysInquiry_PaperInfo>(" MAX(OrderNum)+1 AS OrderNum ", "SysInquiry_PaperInfo", " PaperTypeId=" + paperTypeId);
|
if (result != null && result.Count > 0)
|
{
|
orderNum = result[0].OrderNum.Value;
|
}
|
return orderNum;
|
}
|
}
|
}
|