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 * ´´½¨ÈË:ÎâÆé¾ù * ÐÞ¸ÄÈË£ºÎâÆé¾ù */ /// /// ×Öµä±íÊý¾Ý·ÃÎÊʵÏÖ /// public class Sys_DictionaryDAL : ISys_DictionaryDAL { private Database _dataBase = null; public Sys_DictionaryDAL() { _dataBase = new Database(); } public Sys_DictionaryDAL(Database dataBase) { _dataBase = dataBase; } /// /// ÐÂÔö /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.Sys_Dictionary trueModel = model as Model.Sys_Dictionary; if (trueModel == null) { return false; } else { } IList sqlParms = new List() { 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()); } catch (Exception ex) { throw ex; } return true; } /// /// ÐÞ¸Ä /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.Sys_Dictionary trueModel = model as Model.Sys_Dictionary; if (trueModel == null) { return false; } else { } IList sqlParms = new List() { 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()); } catch (Exception ex) { throw ex; } return true; } /// /// ɾ³ý /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.Sys_Dictionary trueModel = model as Model.Sys_Dictionary; if (trueModel == null) { return false; } else { } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; try { _dataBase.Query("sp_Sys_Dictionary_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// ·ÖÒ³²éѯ /// /// /// /// public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination) { throw new NotImplementedException(); } /// /// µ¥¸ö²éѯ /// /// /// public IEnumerable SelectAllModel(Infrastructure.Query.Query query) { throw new NotImplementedException(); } /// /// ¸ù¾ÝÊý¾ÝÀàÐÍ»ñÈ¡Êý¾Ý¼¯ºÏ /// /// Êý¾ÝÀàÐÍ /// public IEnumerable 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(reader); } /// /// »ñȡȫ²¿Êý¾ÝÀàÐÍ /// /// public IEnumerable SelectDicTypes() { List data = new List(); IDataReader reader = _dataBase.QueryDataReader("sp_Sys_Dictionary_SelectAllType", CommandType.StoredProcedure); using (reader) { while (reader.Read()) { data.Add(string.Format("{0}", reader[0])); } } return data; } /// /// ¸ù¾ÝKeyid»ñµÃ×Öµä /// /// Êý¾Ýid /// public string SelectModelByKeyid(int? Keyid) { if (Keyid == null || Keyid <= 0) return null;//´íÎóÊý¾Ý·µ»á¿Õ IList result = _dataBase.SelectModel("*", "Sys_Dictionary", string.Format(" Keyid='{0}' ", Keyid)) as IList;//Ö´Ðвéѯ return (null == result || result.Count == 0) ? null : result[0].Name;//·µ»Ø½á¹û } /// /// ¸ù¾Ý´ú±íÖµºÍÀàÐÍ»ñµÃÃû³Æ /// /// ´ú±íÖµ /// ÀàÐÍ /// public int? GetNameByKeyid(int? MeanValue, string DicType) { try { if (MeanValue == null || string.IsNullOrEmpty(DicType)) return null;//´íÎóÊý¾Ý·µ»á¿Õ IList result = _dataBase.SelectModel("*", "Sys_Dictionary", string.Format(" MeanValue='{0}' and DicType ='{1}'", MeanValue, DicType)) as IList;//Ö´Ðвéѯ return (null == result || result.Count == 0) ? null : result[0].Keyid;//·µ»Ø½á¹û } catch (Exception ex) { throw ex; } } /// /// ¸ù¾Ý´ú±íÖµºÍÀàÐÍ»ñµÃName /// /// Êý¾Ýid /// Êý¾Ýid /// public string GetNameByMeanValue(int? MeanValue, string DicType) { if (MeanValue == null || string.IsNullOrEmpty(DicType)) return "";//´íÎóÊý¾Ý·µ»á¿Õ try { IList result = _dataBase.SelectModel("*", "Sys_Dictionary", string.Format(" MeanValue='{0}' and DicType ='{1}'", MeanValue, DicType)) as IList;//Ö´Ðвéѯ return (null == result || result.Count == 0) ? "" : result[0].Name;//·µ»Ø½á¹û } catch (Exception ex) { throw ex; } } } }