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_DocumentDAL : IOA_DocumentDAL { private Database _dataBase = null; public OA_DocumentDAL() { _dataBase = new Database(); } public OA_DocumentDAL(Database dataBase) { _dataBase = dataBase; } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_Document trueModel = model as Model.OA_Document; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@FirmId", trueModel.FirmId) , new SqlParameter("@DM_PromulgatedDate", trueModel.DM_PromulgatedDate) , new SqlParameter("@DM_Status", trueModel.DM_Status) , new SqlParameter("@DM_PostingId", trueModel.DM_PostingId) , new SqlParameter("@DM_PostingName", trueModel.DM_PostingName) , new SqlParameter("@DM_PostingFirmName", trueModel.DM_PostingFirmName) , new SqlParameter("@DM_DocumentType", trueModel.DM_DocumentType) , new SqlParameter("@DM_DocumentNumber", trueModel.DM_DocumentNumber) , new SqlParameter("@DM_Title", trueModel.DM_Title) , new SqlParameter("@DM_Content", trueModel.DM_Content) , new SqlParameter("@DM_ThemeWords", trueModel.DM_ThemeWords) , new SqlParameter("@DM_CCUnit", trueModel.DM_CCUnit) , new SqlParameter("@DM_PrintNumber", trueModel.DM_PrintNumber) , new SqlParameter("@DM_Number", trueModel.DM_Number) , new SqlParameter("@DM_DelTime", trueModel.DM_DelTime) , new SqlParameter("@DM_PrintTime", trueModel.DM_PrintTime) , new SqlParameter("@DM_PrintStatus", trueModel.DM_PrintStatus) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Operator", trueModel.Operator) }; try { _dataBase.Query("sp_OA_Document_Insert", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_Document trueModel = model as Model.OA_Document; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid", trueModel.Keyid) , new SqlParameter("@FirmId", trueModel.FirmId) , new SqlParameter("@DM_PromulgatedDate", trueModel.DM_PromulgatedDate) , new SqlParameter("@DM_Status", trueModel.DM_Status) , new SqlParameter("@DM_PostingId", trueModel.DM_PostingId) , new SqlParameter("@DM_PostingName", trueModel.DM_PostingName) , new SqlParameter("@DM_PostingFirmName", trueModel.DM_PostingFirmName) , new SqlParameter("@DM_DocumentType", trueModel.DM_DocumentType) , new SqlParameter("@DM_DocumentNumber", trueModel.DM_DocumentNumber) , new SqlParameter("@DM_Title", trueModel.DM_Title) , new SqlParameter("@DM_Content", trueModel.DM_Content) , new SqlParameter("@DM_ThemeWords", trueModel.DM_ThemeWords) , new SqlParameter("@DM_CCUnit", trueModel.DM_CCUnit) , new SqlParameter("@DM_PrintNumber", trueModel.DM_PrintNumber) , new SqlParameter("@DM_Number", trueModel.DM_Number) , new SqlParameter("@DM_DelTime", trueModel.DM_DelTime) , new SqlParameter("@DM_PrintTime", trueModel.DM_PrintTime) , new SqlParameter("@DM_PrintStatus", trueModel.DM_PrintStatus) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Operator", trueModel.Operator), new SqlParameter("@Jusequanxian", trueModel.Jusequanxian), }; try { _dataBase.Query("sp_OA_Document_Update", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_Document trueModel = model as Model.OA_Document; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; try { _dataBase.Query("sp_OA_Document_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_Document GetModelByKeyid(int? Keyid) { try { if (Keyid == null || Keyid < 0) return null;//错误数据返会空 IList result = _dataBase.SelectModel(" * ", " OA_Document ", string.Format(" 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 _FirmId, DateTime? _BeginDM_PromulgatedDate, DateTime? _EndDM_PromulgatedDate, int? _DM_Status, int? _DM_PostingId, string _DM_PostingName, string _DM_PostingFirmName, string _DM_DocumentType, string _DM_DocumentNumber, string _DM_Title, string _DM_Content, string _DM_ThemeWords, string _DM_CCUnit, int? _DM_PrintNumber, int? _DM_Number, DateTime? _BeginDM_DelTime, DateTime? _EndDM_DelTime, DateTime? _BeginDM_PrintTime, DateTime? _EndDM_PrintTime, int? _DM_PrintStatus, DateTime? _BeginLastUpdateTime, DateTime? _EndLastUpdateTime, string _Operator) { try { string condition = " 1=1 "; if (_FirmId != Guid.Empty) condition += " and FirmId = '" + _FirmId + "'"; if (_BeginDM_PromulgatedDate.HasValue) condition += string.Format(" and CAST(DM_PromulgatedDate AS DATE) >='{0}'", _BeginDM_PromulgatedDate); if (_EndDM_PromulgatedDate.HasValue) condition += string.Format(" and CAST(DM_PromulgatedDate AS DATE) <='{0}'", _EndDM_PromulgatedDate); if (_DM_Status.HasValue) condition += " and DM_Status = '" + _DM_Status + "'"; if (_DM_PostingId.HasValue) condition += " and DM_PostingId = '" + _DM_PostingId + "'"; if (!string.IsNullOrEmpty(_DM_PostingName)) condition += " and DM_PostingName = '" + _DM_PostingName + "'"; if (!string.IsNullOrEmpty(_DM_PostingFirmName)) condition += " and DM_PostingFirmName = '" + _DM_PostingFirmName + "'"; if (!string.IsNullOrEmpty(_DM_DocumentType)) condition += " and DM_DocumentType = '" + _DM_DocumentType + "'"; if (!string.IsNullOrEmpty(_DM_DocumentNumber)) condition += " and DM_DocumentNumber = '" + _DM_DocumentNumber + "'"; if (!string.IsNullOrEmpty(_DM_Title)) condition += " and DM_Title = '" + _DM_Title + "'"; if (!string.IsNullOrEmpty(_DM_Content)) condition += " and DM_Content = '" + _DM_Content + "'"; if (!string.IsNullOrEmpty(_DM_ThemeWords)) condition += " and DM_ThemeWords = '" + _DM_ThemeWords + "'"; if (!string.IsNullOrEmpty(_DM_CCUnit)) condition += " and DM_CCUnit = '" + _DM_CCUnit + "'"; if (_DM_PrintNumber.HasValue) condition += " and DM_PrintNumber = '" + _DM_PrintNumber + "'"; if (_DM_Number.HasValue) condition += " and DM_Number = '" + _DM_Number + "'"; if (_BeginDM_DelTime.HasValue) condition += string.Format(" and CAST(DM_DelTime AS DATE) >='{0}'", _BeginDM_DelTime); if (_EndDM_DelTime.HasValue) condition += string.Format(" and CAST(DM_DelTime AS DATE) <='{0}'", _EndDM_DelTime); if (_BeginDM_PrintTime.HasValue) condition += string.Format(" and CAST(DM_PrintTime AS DATE) >='{0}'", _BeginDM_PrintTime); if (_EndDM_PrintTime.HasValue) condition += string.Format(" and CAST(DM_PrintTime AS DATE) <='{0}'", _EndDM_PrintTime); if (_DM_PrintStatus.HasValue) condition += " and DM_PrintStatus = '" + _DM_PrintStatus + "'"; if (_BeginLastUpdateTime.HasValue) condition += string.Format(" and CAST(LastUpdateTime AS DATE) >='{0}'", _BeginLastUpdateTime); if (_EndLastUpdateTime.HasValue) condition += string.Format(" and CAST(LastUpdateTime AS DATE) <='{0}'", _EndLastUpdateTime); if (!string.IsNullOrEmpty(_Operator)) condition += " and Operator = '" + _Operator + "'"; return _dataBase.SelectModelPage(pagination, " * ", " OA_Document ", " Keyid desc", " Keyid desc ", condition); } catch (Exception ex) { throw ex; } } /// /// 根据发文部门获取列表 /// /// /// /// /// /// public IEnumerable SelectModelListByPostId(Guid _FirmId, DateTime? _BeginDM_PromulgatedDate, DateTime? _EndDM_PromulgatedDate, int? _DM_PostingId) { try { string condition = " 1=1 "; if (_FirmId != Guid.Empty) condition += " and FirmId = '" + _FirmId + "'"; if (_BeginDM_PromulgatedDate.HasValue) condition += string.Format(" and CAST(DM_PromulgatedDate AS DATE) >='{0}'", _BeginDM_PromulgatedDate); if (_EndDM_PromulgatedDate.HasValue) condition += string.Format(" and CAST(DM_PromulgatedDate AS DATE) <='{0}'", _EndDM_PromulgatedDate); if (_DM_PostingId.HasValue) condition += " and DM_PostingId = '" + _DM_PostingId + "'"; condition += " order by DM_Number DESC"; return _dataBase.SelectModel(" * ", " OA_Document ", condition); } catch (Exception ex) { throw ex; } } } }