using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL.Inquiry;
using System.Data.SqlClient;
using System.Data;
using CY.Model;
namespace CY.SQLDAL
{
///
/// 绳子类型管理接口--SQL实现
///
public class SysInquiry_RopeTypeDAL : ISysInquiry_RopeTypeDAL
{
private Database _dataBase = null;
public SysInquiry_RopeTypeDAL()
{
_dataBase = new Database();
}
public IEnumerable SelectModelPage(string typeName, string status, Infrastructure.Query.Pagination pagination)
{
string condition = string.Empty;
condition = " 1=1 ";
if (!string.IsNullOrEmpty(typeName))
{
condition += " and RopeTypeName like '%" + typeName + "%' ";
}
if (!string.IsNullOrEmpty(status))
{
condition += " and Status='" + status+"'" ;
}
return _dataBase.SelectModelPage(pagination, "*", "SysInquiry_RopeType", "OrderNum", "OrderNum", condition);
}
public Model.SysInquiry_RopeType SelectModelByKey(int keyid)
{
string condition = string.Empty;
condition = " KeyId=" + keyid;
IList result = _dataBase.SelectModel("*", "SysInquiry_RopeType", condition);
return null == result || result.Count == 0 ? null : result[0];
}
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.SysInquiry_RopeType trueModel = model as Model.SysInquiry_RopeType;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@RopeTypeName",trueModel.RopeTypeName),
new SqlParameter("@Status",trueModel.Status),
new SqlParameter("@OrderNum",trueModel.OrderNum)
};
try
{
_dataBase.Query("SysInquiry_RopeType_ADD", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.SysInquiry_RopeType trueModel = model as Model.SysInquiry_RopeType;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@KeyId",trueModel.KeyId),
new SqlParameter("@RopeTypeName",trueModel.RopeTypeName),
new SqlParameter("@Status",trueModel.Status),
new SqlParameter("@OrderNum",trueModel.OrderNum)
};
try
{
_dataBase.Query("SysInquiry_RopeType_Update", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
{
throw new NotImplementedException();
}
///
/// 获取最新排序顺序
///
///
public int GetOrderNumByMax()
{
int orderNum = 1;
try
{
IList result = _dataBase.SelectModel(" MAX(OrderNum)+1 AS OrderNum ", "SysInquiry_RopeType", "");
if (result != null && result.Count > 0)
{
orderNum = result[0].OrderNum;
}
}
catch
{
orderNum = 1;
}
return orderNum;
}
public IList GetModelList()
{
string condition = string.Empty;
condition = " Status='true' order by orderNum ";
IList result = _dataBase.SelectModel("*", "SysInquiry_RopeType", condition);
return result;
}
///
/// 判断是否存在相同的数据
///
///
///
public bool IsExist(string ropeTypeName)
{
bool isExist = false;
string condition = string.Empty;
condition = " RopeTypeName='" + ropeTypeName + "' ";
IList result = _dataBase.SelectModel("*", "SysInquiry_RopeType", condition);
if (result != null && result.Count > 0)
{
isExist = true;
}
return isExist;
}
}
}