using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using CY.IDAL;
|
using System.Data.SqlClient;
|
using System.Data;
|
using CY.Model;
|
|
namespace CY.SQLDAL
|
{
|
/*
|
* ×Öµä±íÊý¾Ý·ÃÎÊʵÏÖ
|
*
|
* ×÷Óãº×Öµä±íÊý¾Ý·ÃÎÊʵÏÖ
|
* ´´½¨Ê±¼ä:2013-4-12 9:23
|
* ÐÞ¸Äʱ¼ä:2013-4-12 17:45
|
* ´´½¨ÈË:ÎâÆé¾ù
|
* ÐÞ¸ÄÈË£ºÎâÆé¾ù
|
*/
|
/// <summary>
|
/// ×Öµä±íÊý¾Ý·ÃÎÊʵÏÖ
|
/// </summary>
|
public class Sys_DictionaryDAL : ISys_DictionaryDAL
|
{
|
|
private Database _dataBase = null;
|
|
public Sys_DictionaryDAL()
|
{
|
_dataBase = new Database();
|
}
|
public Sys_DictionaryDAL(Database dataBase)
|
{
|
_dataBase = dataBase;
|
}
|
|
/// <summary>
|
/// ÐÂÔö
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.Sys_Dictionary trueModel = model as Model.Sys_Dictionary;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
else
|
{
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@Name",trueModel.Name),
|
new SqlParameter("@DicType",trueModel.DicType),
|
new SqlParameter("@MeanValue",trueModel.MeanValue),
|
new SqlParameter("@Operator",trueModel.Operator),
|
new SqlParameter("@Remark",trueModel.Remark)
|
};
|
try
|
{
|
_dataBase.Query("sp_Sys_Dictionary_Insert", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// ÐÞ¸Ä
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.Sys_Dictionary trueModel = model as Model.Sys_Dictionary;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
else
|
{
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@Keyid",trueModel.Keyid),
|
new SqlParameter("@Name",trueModel.Name),
|
new SqlParameter("@DicType",trueModel.DicType),
|
new SqlParameter("@MeanValue",trueModel.MeanValue),
|
new SqlParameter("@Operator",trueModel.Operator),
|
new SqlParameter("@Remark",trueModel.Remark)
|
};
|
try
|
{
|
_dataBase.Query("sp_Sys_Dictionary_Update", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// ɾ³ý
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.Sys_Dictionary trueModel = model as Model.Sys_Dictionary;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
else
|
{
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@Keyid",trueModel.Keyid)
|
};
|
try
|
{
|
_dataBase.Query("sp_Sys_Dictionary_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// ·ÖÒ³²éѯ
|
/// </summary>
|
/// <param name="query"></param>
|
/// <param name="pagination"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.Sys_Dictionary> SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// µ¥¸ö²éѯ
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.Sys_Dictionary> SelectAllModel(Infrastructure.Query.Query query)
|
{
|
throw new NotImplementedException();
|
}
|
/// <summary>
|
/// ¸ù¾ÝÊý¾ÝÀàÐÍ»ñÈ¡Êý¾Ý¼¯ºÏ
|
/// </summary>
|
/// <param name="dicType">Êý¾ÝÀàÐÍ</param>
|
/// <returns></returns>
|
public IEnumerable<Model.Sys_Dictionary> SelectModlesByType(string dicType)
|
{
|
if (string.IsNullOrEmpty(dicType))
|
return null;
|
else
|
{
|
}
|
|
IDataReader reader = _dataBase.QueryDataReader("sp_Sys_Dictionary_SelectByType", CommandType.StoredProcedure,
|
new SqlParameter()
|
{
|
ParameterName = "@DataType",
|
Value = dicType
|
});
|
|
return _dataBase.ReadDataToModelAndDispose<Model.Sys_Dictionary>(reader);
|
|
}
|
|
/// <summary>
|
/// »ñȡȫ²¿Êý¾ÝÀàÐÍ
|
/// </summary>
|
/// <returns></returns>
|
public IEnumerable<string> SelectDicTypes()
|
{
|
List<string> data = new List<string>();
|
|
IDataReader reader = _dataBase.QueryDataReader("sp_Sys_Dictionary_SelectAllType", CommandType.StoredProcedure);
|
using (reader)
|
{
|
while (reader.Read())
|
{
|
data.Add(string.Format("{0}", reader[0]));
|
}
|
}
|
return data;
|
|
}
|
|
/// <summary>
|
/// ¸ù¾ÝKeyid»ñµÃ×Öµä
|
/// </summary>
|
/// <param name="Keyid">Êý¾Ýid</param>
|
/// <returns></returns>
|
public string SelectModelByKeyid(int? Keyid)
|
{
|
if (Keyid == null || Keyid <= 0)
|
return null;//´íÎóÊý¾Ý·µ»á¿Õ
|
|
IList<Sys_Dictionary> result = _dataBase.SelectModel<Sys_Dictionary>("*", "Sys_Dictionary", string.Format(" Keyid='{0}' ", Keyid)) as IList<Sys_Dictionary>;//Ö´Ðвéѯ
|
|
return (null == result || result.Count == 0) ? null : result[0].Name;//·µ»Ø½á¹û
|
}
|
|
/// <summary>
|
/// ¸ù¾Ý´ú±íÖµºÍÀàÐÍ»ñµÃÃû³Æ
|
/// </summary>
|
/// <param name="MeanValue">´ú±íÖµ</param>
|
/// <param name="DicType">ÀàÐÍ</param>
|
/// <returns></returns>
|
public int? GetNameByKeyid(int? MeanValue, string DicType)
|
{
|
try
|
{
|
if (MeanValue == null || string.IsNullOrEmpty(DicType))
|
return null;//´íÎóÊý¾Ý·µ»á¿Õ
|
|
IList<Sys_Dictionary> result = _dataBase.SelectModel<Sys_Dictionary>("*", "Sys_Dictionary", string.Format(" MeanValue='{0}' and DicType ='{1}'", MeanValue, DicType)) as IList<Sys_Dictionary>;//Ö´Ðвéѯ
|
|
return (null == result || result.Count == 0) ? null : result[0].Keyid;//·µ»Ø½á¹û
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// ¸ù¾Ý´ú±íÖµºÍÀàÐÍ»ñµÃName
|
/// </summary>
|
/// <param name="MeanValue">Êý¾Ýid</param>
|
/// <param name="DicType">Êý¾Ýid</param>
|
/// <returns></returns>
|
public string GetNameByMeanValue(int? MeanValue, string DicType)
|
{
|
if (MeanValue == null || string.IsNullOrEmpty(DicType))
|
return "";//´íÎóÊý¾Ý·µ»á¿Õ
|
try
|
{
|
IList<Sys_Dictionary> result = _dataBase.SelectModel<Sys_Dictionary>("*", "Sys_Dictionary", string.Format(" MeanValue='{0}' and DicType ='{1}'", MeanValue, DicType)) as IList<Sys_Dictionary>;//Ö´Ðвéѯ
|
|
return (null == result || result.Count == 0) ? "" : result[0].Name;//·µ»Ø½á¹û
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
}
|
}
|