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_PropertyRecordDAL : IOA_PropertyRecordDAL { private Database _dataBase = null; public OA_PropertyRecordDAL() { _dataBase = new Database(); } public OA_PropertyRecordDAL(Database dataBase) { _dataBase = dataBase; } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_PropertyRecord trueModel = model as Model.OA_PropertyRecord; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@MemberId", trueModel.MemberId) , new SqlParameter("@CateId", trueModel.CateId) , new SqlParameter("@PropertyId", trueModel.PropertyId) , new SqlParameter("@DepartmentId", trueModel.DepartmentId) , new SqlParameter("@Status", trueModel.Status) , new SqlParameter("@AddId", trueModel.AddId) , new SqlParameter("@AddName", trueModel.AddName) , new SqlParameter("@AddTime", trueModel.AddTime) , new SqlParameter("@AddQuality", trueModel.AddQuality) , new SqlParameter("@AddRemark", trueModel.AddRemark) , new SqlParameter("@ApproveId", trueModel.ApproveId) , new SqlParameter("@ApproveQuality", trueModel.ApproveQuality) , new SqlParameter("@ApproveTime", trueModel.ApproveTime) , new SqlParameter("@ApproveRemark", trueModel.ApproveRemark) , new SqlParameter("@BackId", trueModel.BackId) , new SqlParameter("@BackQuality", trueModel.BackQuality) , new SqlParameter("@BackTime", trueModel.BackTime) , new SqlParameter("@BackRemark", trueModel.BackRemark) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Operator", trueModel.Operator) , new SqlParameter("@Remark", trueModel.Remark) }; try { _dataBase.Query("sp_OA_PropertyRecord_Insert", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_PropertyRecord trueModel = model as Model.OA_PropertyRecord; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid", trueModel.Keyid) , new SqlParameter("@MemberId", trueModel.MemberId) , new SqlParameter("@CateId", trueModel.CateId) , new SqlParameter("@PropertyId", trueModel.PropertyId) , new SqlParameter("@DepartmentId", trueModel.DepartmentId) , new SqlParameter("@Status", trueModel.Status) , new SqlParameter("@AddId", trueModel.AddId) , new SqlParameter("@AddName", trueModel.AddName) , new SqlParameter("@AddTime", trueModel.AddTime) , new SqlParameter("@AddQuality", trueModel.AddQuality) , new SqlParameter("@AddRemark", trueModel.AddRemark) , new SqlParameter("@ApproveId", trueModel.ApproveId) , new SqlParameter("@ApproveQuality", trueModel.ApproveQuality) , new SqlParameter("@ApproveTime", trueModel.ApproveTime) , new SqlParameter("@ApproveRemark", trueModel.ApproveRemark) , new SqlParameter("@BackId", trueModel.BackId) , new SqlParameter("@BackQuality", trueModel.BackQuality) , new SqlParameter("@BackTime", trueModel.BackTime) , new SqlParameter("@BackRemark", trueModel.BackRemark) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Operator", trueModel.Operator) , new SqlParameter("@Remark", trueModel.Remark) }; try { _dataBase.Query("sp_OA_PropertyRecord_Update", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_PropertyRecord trueModel = model as Model.OA_PropertyRecord; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; try { _dataBase.Query("sp_OA_PropertyRecord_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 OA_PropertyRecord GetModelByKeyid(int? Keyid) { try { if (Keyid == null || Keyid < 0) return null;//错误数据返会空 IList result = _dataBase.SelectModel(" a.*,b.Name as PropertyName,c.Name as CateName,d.Name as DepartmentName,e.Name as ApproveName,f.Name as BackName ", " dbo.OA_PropertyRecord AS a LEFT JOIN dbo.OA_PropertyManage AS b ON a.PropertyId = b.Keyid LEFT JOIN dbo.OA_PropertyCate AS c ON a.CateId = c.Keyid LEFT JOIN dbo.OA_Department AS d ON a.DepartmentId = d.Keyid LEFT JOIN dbo.EC_MemberBasic AS e ON a.ApproveId = e.MemberId LEFT JOIN dbo.EC_MemberBasic AS f ON a.BackId=f.MemberId ", string.Format(" a.Keyid='{0}'", Keyid)) as IList;//执行查询 return (null == result || result.Count == 0) ? null : result[0];//返回结果 } catch (Exception ex) { throw ex; } } /// /// 分页查询 /// /// /// public IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, Guid _MemberId, Guid _AddId, int? _CateId, int? _PropertyId, int? _Status, string _AddName, DateTime? _BeginAddTime, DateTime? _EndAddTime) { try { string condition = " 1=1 "; if (_MemberId != Guid.Empty) condition += " and a.MemberId = '" + _MemberId + "'"; if (_AddId != Guid.Empty) condition += " and a.AddId = '" + _AddId + "'"; if (_CateId.HasValue) condition += " and a.CateId = '" + _CateId + "'"; if (_PropertyId.HasValue) condition += " and a.PropertyId = '" + _PropertyId + "'"; if (_Status.HasValue) { if (_Status == 2) condition += " and (a.Status = '2' or a.Status = '3')"; else condition += " and a.Status = '"+_Status+"'"; } if (!string.IsNullOrEmpty(_AddName)) condition += " and a.AddName = '" + _AddName + "'"; if (_BeginAddTime.HasValue) condition += string.Format(" and CAST(a.AddTime AS DATE) >='{0}'", _BeginAddTime); if (_EndAddTime.HasValue) condition += string.Format(" and CAST(a.AddTime AS DATE) <='{0}'", _EndAddTime); return _dataBase.SelectModelPage(pagination, " a.*,b.Name as PropertyName,c.Name as CateName,d.Name as DepartmentName,e.Name as ApproveName,f.Name as BackName ", " dbo.OA_PropertyRecord AS a LEFT JOIN dbo.OA_PropertyManage AS b ON a.PropertyId = b.Keyid LEFT JOIN dbo.OA_PropertyCate AS c ON a.CateId = c.Keyid LEFT JOIN dbo.OA_Department AS d ON a.DepartmentId = d.Keyid LEFT JOIN dbo.EC_MemberBasic AS e ON a.ApproveId = e.MemberId LEFT JOIN dbo.EC_MemberBasic AS f ON a.BackId=f.MemberId ", " a.Keyid desc", " Keyid desc ", condition); } catch (Exception ex) { throw ex; } } } }