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_WageAwardPunishDAL : IOA_WageAwardPunishDAL { private Database _dataBase = null; public OA_WageAwardPunishDAL() { _dataBase = new Database(); } public OA_WageAwardPunishDAL(Database dataBase) { _dataBase = dataBase; } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_WageAwardPunish trueModel = model as Model.OA_WageAwardPunish; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@FirmId", trueModel.FirmId) , new SqlParameter("@MemberId", trueModel.MemberId) , new SqlParameter("@RecTitle", trueModel.RecTitle) , new SqlParameter("@RecTime", trueModel.RecTime) , new SqlParameter("@RecType", trueModel.RecType) , new SqlParameter("@RecContent", trueModel.RecContent) , new SqlParameter("@RecMoney", trueModel.RecMoney) , new SqlParameter("@PlanId", trueModel.PlanId) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Operator", trueModel.Operator) }; try { _dataBase.Query("sp_OA_WageAwardPunish_Insert", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_WageAwardPunish trueModel = model as Model.OA_WageAwardPunish; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid", trueModel.Keyid) , new SqlParameter("@FirmId", trueModel.FirmId) , new SqlParameter("@MemberId", trueModel.MemberId) , new SqlParameter("@RecTitle", trueModel.RecTitle) , new SqlParameter("@RecTime", trueModel.RecTime) , new SqlParameter("@RecType", trueModel.RecType) , new SqlParameter("@RecContent", trueModel.RecContent) , new SqlParameter("@RecMoney", trueModel.RecMoney) , new SqlParameter("@PlanId", trueModel.PlanId) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Operator", trueModel.Operator) }; try { _dataBase.Query("sp_OA_WageAwardPunish_Update", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_WageAwardPunish trueModel = model as Model.OA_WageAwardPunish; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; try { _dataBase.Query("sp_OA_WageAwardPunish_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_WageAwardPunish GetModelByKeyid(int? Keyid) { try { if (Keyid == null || Keyid < 0) return null;//错误数据返会空 IList result = _dataBase.SelectModel(" * ", " OA_WageAwardPunish ", 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, Guid _MemberId, string _RecTitle, DateTime? _BeginRecTime, DateTime? _EndRecTime, int? _RecType, string _RecContent, decimal? _RecMoney, int? _PlanId, DateTime? _BeginLastUpdateTime, DateTime? _EndLastUpdateTime, string _Operator) { try { string condition = " 1=1 "; if (_FirmId != Guid.Empty) condition += " and FirmId = '" + _FirmId + "' "; if (_MemberId != Guid.Empty) condition += " and MemberId = '" + _MemberId + "' "; if (!string.IsNullOrEmpty(_RecTitle)) condition += " and RecTitle = '" + _RecTitle + "' "; if (_BeginRecTime.HasValue) condition += string.Format(" and CAST(RecTime AS DATE) >='{0}' ", _BeginRecTime); if (_EndRecTime.HasValue) condition += string.Format(" and CAST(RecTime AS DATE) <='{0}' ", _EndRecTime); if (_RecType.HasValue) condition += " and RecType = '" + _RecType + "' "; if (!string.IsNullOrEmpty(_RecContent)) condition += " and RecContent = '" + _RecContent + "' "; if (_RecMoney.HasValue) condition += " and RecMoney = '" + _RecMoney + "' "; if (_PlanId.HasValue) condition += " and PlanId = '" + _PlanId + "' "; 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_WageAwardPunish ", " Keyid desc", " Keyid desc ", condition); } catch (Exception ex) { throw ex; } } /// /// 分页查询-奖惩统计 /// /// /// /// /// /// public IEnumerable SelectModelPageByWage(Infrastructure.Query.Pagination pagination, Guid MemberId, int? DepartmentId, string PlanPeople, string StatisticsTime) { try { string condition = " where 1=1 "; if (MemberId != Guid.Empty) condition += " and a.FirmId = '" + MemberId + "' "; if (!string.IsNullOrEmpty(PlanPeople)) condition += " and a.Name = '" + PlanPeople + "' "; if (DepartmentId.HasValue) condition += " and a.DepartmentId = '" + DepartmentId + "' "; string condition1 = ""; string condition2 = ""; if (!string.IsNullOrEmpty(StatisticsTime)) { StatisticsTime = StatisticsTime.Replace("年", "-").Replace("月", "-") + "1"; DateTime Time1 = DateTime.Parse(StatisticsTime); DateTime Time2 = DateTime.Parse(StatisticsTime).AddMonths(1); condition1 += " and ((b.RecTime >= '" + Time1 + "' and b.RecTime < '" + Time2 + "') or b.RecTime is null)"; condition2 += " and ((c.RecTime >= '" + Time1 + "' and c.RecTime < '" + Time2 + "') or c.RecTime is null)"; } //condition += string.Format(" and ( a.Status='在职' OR ( a.Status ='离职' AND CAST(a.SM_EndWorkTime AS DATE) >'{0}' )) ", DateTime.Now); condition += " GROUP BY a.MemberId,a.DepartmentId,a.Name,a.Sex,a.Status,a.SM_EndWorkTime,d.Name "; return _dataBase.SelectModelPage(pagination, " p.* ", " ( select a.MemberId,a.DepartmentId,a.Name as StaffName,a.Sex,a.Status,a.SM_EndWorkTime,d.Name AS DepartmentName,SUM(b.RecMoney) AS RewardMoney,SUM(c.RecMoney) AS PushMoney from dbo.OA_Staff AS a LEFT JOIN dbo.OA_WageAwardPunish AS b ON a.MemberId = b.MemberId AND b.RecType =1 " + condition1 + " LEFT JOIN dbo.OA_WageAwardPunish AS c ON a.MemberId = c.MemberId AND c.RecType=2 " + condition2 + " LEFT JOIN dbo.OA_Department AS d ON a.DepartmentId = d.Keyid " + condition +" ) as p", " p.Status DESC,p.DepartmentId ASC ", " Status DESC,DepartmentId ASC "); } catch (Exception ex) { throw ex; } } } }