using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using CY.IDAL.Inquiry;
|
using CY.Model;
|
using System.Data.SqlClient;
|
using System.Data;
|
using System.Transactions;
|
using CY.Infrastructure.Common;
|
namespace CY.SQLDAL
|
{
|
/// <summary>
|
/// 纸张类别相关操作--SQL数据库操作
|
/// </summary>
|
public class PaperTypeDAL : IPaperTypeDAL
|
{
|
|
private Database _dataBase = null;
|
|
public PaperTypeDAL()
|
{
|
_dataBase = new Database();
|
}
|
|
/// <summary>
|
/// 新增纸张类别
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.SysInquiry_PaperType trueModel = model as Model.SysInquiry_PaperType;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
SqlParameter[] parameters = {
|
new SqlParameter("@PaperTypeName", SqlDbType.VarChar,50),
|
new SqlParameter("@Status", SqlDbType.Int,4),
|
new SqlParameter("@OrderNum", SqlDbType.Int,4)};
|
parameters[0].Value = trueModel.PaperTypeName;
|
parameters[1].Value = trueModel.Status;
|
parameters[2].Value = trueModel.OrderNum;
|
try
|
{
|
_dataBase.Query("SysInquiry_PaperType_ADD", 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)
|
{
|
bool isSuccess = true;
|
PaperInfoDAL _paperInfoDAL = new PaperInfoDAL(_dataBase);
|
using (TransactionScope scope = new TransactionScope())
|
{
|
Model.SysInquiry_PaperType trueModel = model as Model.SysInquiry_PaperType;
|
if (trueModel == null)
|
{
|
isSuccess = false;
|
}
|
else
|
{
|
SqlParameter[] parameters = {
|
new SqlParameter("@PaperTypeName", SqlDbType.VarChar,50),
|
new SqlParameter("@Status", SqlDbType.Int,4),
|
new SqlParameter("@OrderNum", SqlDbType.Int,4),
|
new SqlParameter("@KeyId", SqlDbType.Int,4)};
|
parameters[0].Value = trueModel.PaperTypeName;
|
parameters[1].Value = trueModel.Status;
|
parameters[2].Value = trueModel.OrderNum;
|
parameters[3].Value = trueModel.KeyId;
|
try
|
{
|
_dataBase.Query("SysInquiry_PaperType_Update", CommandType.StoredProcedure, parameters);
|
isSuccess = true;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
if (isSuccess)
|
{
|
SysInquiry_PaperInfo paperModel = new SysInquiry_PaperInfo();
|
paperModel.PaperTypeId = trueModel.KeyId;
|
if (trueModel.Status == 1)
|
{
|
paperModel.Status = true;
|
}
|
else
|
{
|
paperModel.Status = false;
|
}
|
isSuccess = _paperInfoDAL.UpdatePaperStatus(paperModel);
|
}
|
if (isSuccess)
|
scope.Complete();
|
}
|
}
|
return isSuccess;
|
}
|
/// <summary>
|
/// 删除纸张类别
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
return false;
|
}
|
|
/// <summary>
|
/// 分页返回纸张类别列表
|
/// </summary>
|
/// <param name="brandName">类别名称</param>
|
/// <param name="pagination">分页参数</param>
|
/// <returns></returns>
|
public IEnumerable<Model.SysInquiry_PaperType> SelectModelPage(string typeName,int status,Infrastructure.Query.Pagination pagination)
|
{
|
string condition=string.Empty;
|
condition = " 1=1 ";
|
if (!string.IsNullOrEmpty(typeName))
|
{
|
condition = " and PaperTypeName like '%" + typeName + "%'";
|
}
|
if (status != -1)
|
{
|
condition += " and Status=" + status;
|
}
|
return _dataBase.SelectModelPage<SysInquiry_PaperType>(pagination, "*", "SysInquiry_PaperType", "OrderNum", "OrderNum", condition);
|
}
|
|
/// <summary>
|
/// 根据主键返回品牌实体
|
/// </summary>
|
/// <param name="keyid">主键ID</param>
|
/// <returns>品牌实体</returns>
|
public SysInquiry_PaperType SelectModelByKey(int keyid)
|
{
|
string condition=string.Empty;
|
condition=" KeyId="+keyid;
|
IList<SysInquiry_PaperType> result = _dataBase.SelectModel<SysInquiry_PaperType>("*", "SysInquiry_PaperType", condition);
|
return null == result || result.Count == 0 ? null : result[0];
|
}
|
|
/// <summary>
|
/// 判断是否有相同的纸张类别名称
|
/// </summary>
|
/// <param name="brandName"></param>
|
/// <returns></returns>
|
public bool IsExistsPaperTypeName(string typeName)
|
{
|
string condition=string.Empty;
|
condition = " PaperTypeName='" + typeName + "'";
|
IList<SysInquiry_PaperType> result = _dataBase.SelectModel<SysInquiry_PaperType>("*", "SysInquiry_PaperType", condition);
|
if(result!=null&&result.Count!=0)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
|
|
/// <summary>
|
/// 返回所有有效的纸张类别列表
|
/// </summary>
|
/// <returns></returns>
|
public IEnumerable<SysInquiry_PaperType> GetPaperTypeList()
|
{
|
string condition = string.Empty;
|
condition = " Status=1 order by OrderNum ";
|
IList<SysInquiry_PaperType> result = _dataBase.SelectModel<SysInquiry_PaperType>("*", "SysInquiry_PaperType", condition);
|
return result;
|
}
|
|
/// <summary>
|
/// 获取最新排序顺序
|
/// </summary>
|
/// <returns></returns>
|
public int GetOrderNumByMax()
|
{
|
int orderNum = 1;
|
IList<SysInquiry_PaperType> result = _dataBase.SelectModel<SysInquiry_PaperType>(" MAX(OrderNum)+1 AS OrderNum ", "SysInquiry_PaperType", string.Empty);
|
if (result != null && result.Count > 0)
|
{
|
orderNum = result[0].OrderNum.Value;
|
}
|
return orderNum;
|
}
|
}
|
}
|