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; using System.Transactions; namespace CY.SQLDAL { public class Adm_tongxunluDAL : IAdm_tongxunluDAL { private Database _dataBase = null; #region 常量 /// /// 查询目标 /// const string SELECTTARGET = " t.* "; /// /// 查询来源 /// const string FROMSOUCEBEFORE = " ( select ok.*,types.Name as typeName " + " from [Adm_tongxunlu] ok " + " Left Join Sys_Dictionary as types On(types.DicType= 'Sys_通讯录' and ok.[type_id]= types.MeanValue) where 0=0 "; const string FROMSOUCEEND = ") as t "; /// /// 分页默认排序字段 /// const string ORDERBY = " createtime desc "; #endregion public Adm_tongxunluDAL() { _dataBase = new Database(); } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.Adm_tongxunlu trueModel = model as Model.Adm_tongxunlu; if (trueModel == null) { return false; } IList sqlParms = new List() { // new SqlParameter("@Keyid",trueModel.Keyid), new SqlParameter("@FirmId",trueModel.FirmId), new SqlParameter("@type_id",trueModel.type_id), new SqlParameter("@danwei_name",trueModel.danwei_name), new SqlParameter("@lianxiren",trueModel.lianxiren), new SqlParameter("@lianxidianhua",trueModel.lianxidianhua), new SqlParameter("@beuzhu",trueModel.beuzhu), new SqlParameter("@rec_status",trueModel.rec_status), new SqlParameter("@creater",trueModel.creater), new SqlParameter("@createtime",trueModel.createtime), new SqlParameter("@modifier",trueModel.modifier), new SqlParameter("@modifytime",trueModel.modifytime), new SqlParameter("@Jusequanxian",string.IsNullOrEmpty(trueModel.Jusequanxian)?"":trueModel.Jusequanxian), }; string sql = "Insert Into Adm_tongxunlu ([FirmId],[type_id],[danwei_name],[lianxiren], [lianxidianhua], [beuzhu],[rec_status], [creater],[createtime], [modifier],[modifytime],[Jusequanxian])" + " Values (@FirmId,@type_id,@danwei_name, @lianxiren, @lianxidianhua, @beuzhu, @rec_status, @creater, @createtime, @modifier,@modifytime,@Jusequanxian)"; try { _dataBase.ExecuteSql(sql, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.Adm_tongxunlu trueModel = model as Model.Adm_tongxunlu; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid), new SqlParameter("@FirmId",trueModel.FirmId), new SqlParameter("@type_id",trueModel.type_id), new SqlParameter("@danwei_name",trueModel.danwei_name), new SqlParameter("@lianxiren",trueModel.lianxiren), new SqlParameter("@lianxidianhua",trueModel.lianxidianhua), new SqlParameter("@beuzhu",trueModel.beuzhu), new SqlParameter("@rec_status",trueModel.rec_status), new SqlParameter("@creater",trueModel.creater), new SqlParameter("@createtime",trueModel.createtime), new SqlParameter("@modifier",trueModel.modifier), new SqlParameter("@modifytime",trueModel.modifytime), new SqlParameter("@Jusequanxian",string.IsNullOrEmpty(trueModel.Jusequanxian)?"":trueModel.Jusequanxian), }; string sql = "Update Adm_tongxunlu Set [FirmId]=@FirmId,[type_id]=@type_id,[danwei_name]=@danwei_name,[lianxiren]=@lianxiren, [lianxidianhua]=@lianxidianhua, [beuzhu]=@beuzhu,[rec_status]=@rec_status, [creater]=@creater,[createtime]=@createtime,[modifier]=@modifier,[modifytime]=@modifytime,[Jusequanxian]=@Jusequanxian where [Keyid] =@Keyid "; try { _dataBase.ExecuteSql(sql, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 根据编号获得信息 /// /// 编号 /// public Adm_tongxunlu GetModelByKeyid(int keyid) { try { string condition = " "; if (keyid > 0) { condition = " Keyid=" + keyid + ""; } else { return null; } // return null;//错误数据返会空 IList result = _dataBase.SelectModel("*", "Adm_tongxunlu", condition) as IList;//执行查询 return (null == result || result.Count == 0) ? null : result[0];//返回结果 } catch (Exception ex) { throw ex; } } /// /// 根据编号获得信息 /// /// 编号 /// public IEnumerable GetModelByKeyids(string keyids) { try { string condition = " "; if (!string.IsNullOrEmpty(keyids)) { condition = " Keyid in (" + keyids + ")"; } else { return null; } // return null;//错误数据返会空 return _dataBase.SelectModel("*", "Adm_tongxunlu", condition) as IList;//执行查询 } catch (Exception ex) { throw ex; } } /// /// 全部查询 /// /// /// public IEnumerable SelectAllModel(Infrastructure.Query.Query query) { return _dataBase.SelectModel(" * ", " Adm_tongxunlu ") as IList;//执行查询 } /// /// 全部查询 /// /// /// public IEnumerable GetModelByformid(Guid FirmId) { return _dataBase.SelectModel(" * ", " Adm_tongxunlu ", " FirmId = '" + FirmId + "'") as IList;//执行查询 } /// /// 分页查询 /// /// /// /// public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination) { if (null == pagination || null == query || null == query.Criteria || 1 > query.Criteria.Count) return null; //query.Criteria 首个元素必须是排序字段,其值为结果排序字段 int maxParamIndex = query.Criteria.Count - 1;//最大索引 string[] orderbys = new string[] { ORDERBY }; string resultOrderBy = "";//结果集排序方式 if ("@orderBy".Equals(query.Criteria[maxParamIndex].PropertyName)) { orderbys = string.Format("{0}", query.Criteria[maxParamIndex].Value).Split(','); resultOrderBy = query.Criteria[maxParamIndex].Value.ToString();//= 1 == orderbys.Length ? resultOrderBy : orderbys[1]; } string fromSouce = string.Format("{0}{1}{2}", FROMSOUCEBEFORE, query.Criteria[0].Value, FROMSOUCEEND);//拼装条件 return _dataBase.SelectModelPage(pagination, SELECTTARGET, fromSouce, orderbys[0], resultOrderBy); } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.Adm_tongxunlu trueModel = model as Model.Adm_tongxunlu; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; string sql = "Delete Adm_tongxunlu Where [Keyid] = @Keyid "; try { _dataBase.ExecuteSql(sql, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } } }