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 OA_GongzuoneirongDAL : IOA_GongzuoneirongDAL { private Database _dataBase = null; public OA_GongzuoneirongDAL() { _dataBase = new Database(); } public OA_GongzuoneirongDAL(Database dataBase) { _dataBase = dataBase; } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_Gongzuoneirong trueModel = model as Model.OA_Gongzuoneirong; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@MemberId", trueModel.MemberId) , new SqlParameter("@Gongzuozhize", trueModel.Gongzuozhize) , new SqlParameter("@Zerenren",trueModel.Zerenren.HasValue?trueModel.Zerenren.Value:0 ) , new SqlParameter("@ZerenrenName", string.IsNullOrEmpty(trueModel.ZerenrenName)?"":trueModel.ZerenrenName) , new SqlParameter("@CreateTime", trueModel.CreateTime) , new SqlParameter("@Creator", trueModel.Creator) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Updator", trueModel.Updator) , }; string sql = "Insert Into OA_Gongzuoneirong ([MemberId],[Gongzuozhize],[Zerenren],[ZerenrenName],[CreateTime],[Creator],[LastUpdateTime],[Updator])" + " Values (@MemberId,@Gongzuozhize,@Zerenren,@ZerenrenName,@CreateTime,@Creator,@LastUpdateTime,@Updator )"; try { _dataBase.ExecuteSql(sql, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_Gongzuoneirong trueModel = model as Model.OA_Gongzuoneirong; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid", trueModel.Keyid) , new SqlParameter("@MemberId", trueModel.MemberId) , new SqlParameter("@Gongzuozhize", trueModel.Gongzuozhize) , new SqlParameter("@Zerenren",trueModel.Zerenren.HasValue?trueModel.Zerenren.Value:0 ) , new SqlParameter("@ZerenrenName", string.IsNullOrEmpty(trueModel.ZerenrenName)?"":trueModel.ZerenrenName) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Updator", trueModel.Updator) , }; string sql = "Update OA_Gongzuoneirong Set [MemberId]=@MemberId,[Gongzuozhize]=@Gongzuozhize,[Zerenren]=@Zerenren,[ZerenrenName]=@ZerenrenName, [LastUpdateTime]=@LastUpdateTime, [Updator]=@Updator where [Keyid] =@Keyid "; try { _dataBase.ExecuteSql(sql, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_Gongzuoneirong trueModel = model as Model.OA_Gongzuoneirong; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; string sql = "Delete OA_Gongzuoneirong Where [Keyid] = @Keyid "; try { _dataBase.ExecuteSql(sql, 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) { return _dataBase.SelectModel(" * ", " OA_Gongzuoneirong ") as IList;//执行查询 } /// /// 根据编号获得信息 /// /// 编号 /// public OA_Gongzuoneirong GetModelByKeyid(int? Keyid) { try { if (Keyid == null || Keyid < 0) return null;//错误数据返会空 IList result = _dataBase.SelectModel(" * ", " OA_Gongzuoneirong ", string.Format(" Keyid='{0}'", Keyid)) as IList;//执行查询 return (null == result || result.Count == 0) ? null : result[0];//返回结果 } catch (Exception ex) { throw ex; } } /// /// 获取物品分类 /// /// /// public IEnumerable GetDataByType(Guid _MemberId) { try { string condition = " 1=1 "; if (_MemberId != Guid.Empty) condition += " and MemberId = '" + _MemberId + "'"; return _dataBase.SelectModel(" * ", " OA_GongzuoneirongCate ", condition); } catch (Exception ex) { throw ex; } } /// /// 分页查询 /// /// /// public IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, Guid _MemberId, string Gongzuozhize, int? Zerenren) { try { string condition = " 1=1 "; if (_MemberId != Guid.Empty) condition += " and a.MemberId = '" + _MemberId + "'"; if (!string.IsNullOrEmpty(Gongzuozhize)) condition += " and a.Gongzuozhize like '%" + Gongzuozhize + "%'"; if (Zerenren.HasValue) condition += " and a.Zerenren = '" + Zerenren + "'"; return _dataBase.SelectModelPage(pagination, " a.* ", " OA_Gongzuoneirong a ", " a.Zerenren", " Zerenren ", condition); } catch (Exception ex) { throw ex; } } /// /// 检测物品是否重复 /// /// /// /// /// public int IsExitsName(int? Zerenren, int? Keyid, string neirong) { try { string where = " Zerenren = " + Zerenren /*+ " and Gongzuozhize='"+ neirong + "'"*/; if (Keyid.HasValue) { where += " and Keyid <> " + Keyid + " "; } IList result = _dataBase.SelectModel("*", "OA_Gongzuoneirong", where) as IList;//执行查询 if (null == result || result.Count == 0) return 0; else return 1; } catch (Exception ex) { throw ex; } } } }