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_WagesRecordDAL : IOA_WagesRecordDAL
|
{
|
private Database _dataBase = null;
|
|
public OA_WagesRecordDAL()
|
{
|
_dataBase = new Database();
|
}
|
|
public OA_WagesRecordDAL(Database dataBase)
|
{
|
_dataBase = dataBase;
|
}
|
|
/// <summary>
|
/// 新增
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_WagesRecord trueModel = model as Model.OA_WagesRecord;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{ new SqlParameter("@FirmId", trueModel.FirmId) ,
|
new SqlParameter("@MemberId", trueModel.MemberId) ,
|
new SqlParameter("@StartBelongsTime", trueModel.StartBelongsTime) ,
|
new SqlParameter("@EndBelongsTime", trueModel.EndBelongsTime) ,
|
new SqlParameter("@WorkDay", trueModel.WorkDay) ,
|
new SqlParameter("@BasicWage", trueModel.BasicWage) ,
|
new SqlParameter("@SeniorityWage", trueModel.SeniorityWage) ,
|
new SqlParameter("@Outputcommission", trueModel.Outputcommission) ,
|
new SqlParameter("@ProfitCommission", trueModel.ProfitCommission) ,
|
new SqlParameter("@OtherCommission", trueModel.OtherCommission) ,
|
new SqlParameter("@PerformanceTotal", trueModel.PerformanceTotal) ,
|
new SqlParameter("@OvertimePay", trueModel.OvertimePay) ,
|
new SqlParameter("@RewardMoney", trueModel.RewardMoney) ,
|
new SqlParameter("@PunishmentMoney", trueModel.PunishmentMoney) ,
|
new SqlParameter("@Allowance", trueModel.Allowance) ,
|
new SqlParameter("@AggregatePaychecks", trueModel.AggregatePaychecks) ,
|
new SqlParameter("@Attendance", trueModel.Attendance) ,
|
new SqlParameter("@AskForLeave", trueModel.AskForLeave) ,
|
new SqlParameter("@EducedTotal", trueModel.EducedTotal) ,
|
new SqlParameter("@Unit", trueModel.Unit) ,
|
new SqlParameter("@Personal", trueModel.Personal) ,
|
new SqlParameter("@WillPayTax", trueModel.WillPayTax) ,
|
new SqlParameter("@AmountWagCards", trueModel.AmountWagCards) ,
|
new SqlParameter("@AccountingSituation", trueModel.AccountingSituation) ,
|
new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) ,
|
new SqlParameter("@Operator", trueModel.Operator)
|
};
|
try
|
{
|
_dataBase.Query("sp_OA_WagesRecord_Insert", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 修改
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_WagesRecord trueModel = model as Model.OA_WagesRecord;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{ new SqlParameter("@Keyid", trueModel.Keyid) ,
|
new SqlParameter("@FirmId", trueModel.FirmId) ,
|
new SqlParameter("@MemberId", trueModel.MemberId) ,
|
new SqlParameter("@StartBelongsTime", trueModel.StartBelongsTime) ,
|
new SqlParameter("@EndBelongsTime", trueModel.EndBelongsTime) ,
|
new SqlParameter("@WorkDay", trueModel.WorkDay) ,
|
new SqlParameter("@BasicWage", trueModel.BasicWage) ,
|
new SqlParameter("@SeniorityWage", trueModel.SeniorityWage) ,
|
new SqlParameter("@Outputcommission", trueModel.Outputcommission) ,
|
new SqlParameter("@ProfitCommission", trueModel.ProfitCommission) ,
|
new SqlParameter("@OtherCommission", trueModel.OtherCommission) ,
|
new SqlParameter("@PerformanceTotal", trueModel.PerformanceTotal) ,
|
new SqlParameter("@OvertimePay", trueModel.OvertimePay) ,
|
new SqlParameter("@RewardMoney", trueModel.RewardMoney) ,
|
new SqlParameter("@PunishmentMoney", trueModel.PunishmentMoney) ,
|
new SqlParameter("@Allowance", trueModel.Allowance) ,
|
new SqlParameter("@AggregatePaychecks", trueModel.AggregatePaychecks) ,
|
new SqlParameter("@Attendance", trueModel.Attendance) ,
|
new SqlParameter("@AskForLeave", trueModel.AskForLeave) ,
|
new SqlParameter("@EducedTotal", trueModel.EducedTotal) ,
|
new SqlParameter("@Unit", trueModel.Unit) ,
|
new SqlParameter("@Personal", trueModel.Personal) ,
|
new SqlParameter("@WillPayTax", trueModel.WillPayTax) ,
|
new SqlParameter("@AmountWagCards", trueModel.AmountWagCards) ,
|
new SqlParameter("@AccountingSituation", trueModel.AccountingSituation) ,
|
new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) ,
|
new SqlParameter("@Operator", trueModel.Operator)
|
};
|
try
|
{
|
_dataBase.Query("sp_OA_WagesRecord_Update", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_WagesRecord trueModel = model as Model.OA_WagesRecord;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@Keyid",trueModel.Keyid)
|
};
|
try
|
{
|
_dataBase.Query("sp_OA_WagesRecord_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
|
return true;
|
}
|
|
/// <summary>
|
/// 分页查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <param name="pagination"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_WagesRecord> SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 单个查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_WagesRecord> SelectAllModel(Infrastructure.Query.Query query)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 根据编号获得信息
|
/// </summary>
|
/// <param name="Keyid">编号</param>
|
/// <returns></returns>
|
public OA_WagesRecord GetModelByKeyid(int? Keyid)
|
{
|
try
|
{
|
if (Keyid == null || Keyid < 0)
|
return null;//错误数据返会空
|
|
IList<OA_WagesRecord> result = _dataBase.SelectModel<OA_WagesRecord>(" * ", " OA_WagesRecord ", string.Format(" Keyid='{0}'", Keyid)) as IList<OA_WagesRecord>;//执行查询
|
|
return (null == result || result.Count == 0) ? null : result[0];//返回结果
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 分页查询
|
/// </summary>
|
/// <param name="pagination"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_WagesRecord> SelectModelPage(Infrastructure.Query.Pagination pagination, Guid _FirmId, Guid _MemberId, DateTime? _BeginStartBelongsTime, DateTime? _EndStartBelongsTime, DateTime? _BeginEndBelongsTime, DateTime? _EndEndBelongsTime, int? _WorkDay, decimal? _BasicWage, decimal? _SeniorityWage, decimal? _Outputcommission, decimal? _ProfitCommission, decimal? _OtherCommission, decimal? _PerformanceTotal, decimal? _OvertimePay, decimal? _RewardMoney, decimal? _PunishmentMoney, decimal? _Allowance, decimal? _AggregatePaychecks, decimal? _Attendance, decimal? _AskForLeave, decimal? _EducedTotal, decimal? _Unit, decimal? _Personal, decimal? _WillPayTax, decimal? _AmountWagCards, string _AccountingSituation, 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 (_BeginStartBelongsTime.HasValue)
|
condition += string.Format(" and CAST(StartBelongsTime AS DATE) >='{0}'", _BeginStartBelongsTime);
|
|
if (_EndStartBelongsTime.HasValue)
|
condition += string.Format(" and CAST(StartBelongsTime AS DATE) <='{0}'", _EndStartBelongsTime);
|
|
if (_BeginEndBelongsTime.HasValue)
|
condition += string.Format(" and CAST(EndBelongsTime AS DATE) >='{0}'", _BeginEndBelongsTime);
|
|
if (_EndEndBelongsTime.HasValue)
|
condition += string.Format(" and CAST(EndBelongsTime AS DATE) <='{0}'", _EndEndBelongsTime);
|
|
if (_WorkDay.HasValue)
|
condition += " and WorkDay = '" + _WorkDay + "'";
|
|
if (_BasicWage.HasValue)
|
condition += " and BasicWage = '" + _BasicWage + "'";
|
|
if (_SeniorityWage.HasValue)
|
condition += " and SeniorityWage = '" + _SeniorityWage + "'";
|
|
if (_Outputcommission.HasValue)
|
condition += " and Outputcommission = '" + _Outputcommission + "'";
|
|
if (_ProfitCommission.HasValue)
|
condition += " and ProfitCommission = '" + _ProfitCommission + "'";
|
|
if (_OtherCommission.HasValue)
|
condition += " and OtherCommission = '" + _OtherCommission + "'";
|
|
if (_PerformanceTotal.HasValue)
|
condition += " and PerformanceTotal = '" + _PerformanceTotal + "'";
|
|
if (_OvertimePay.HasValue)
|
condition += " and OvertimePay = '" + _OvertimePay + "'";
|
|
if (_RewardMoney.HasValue)
|
condition += " and RewardMoney = '" + _RewardMoney + "'";
|
|
if (_PunishmentMoney.HasValue)
|
condition += " and PunishmentMoney = '" + _PunishmentMoney + "'";
|
|
if (_Allowance.HasValue)
|
condition += " and Allowance = '" + _Allowance + "'";
|
|
if (_AggregatePaychecks.HasValue)
|
condition += " and AggregatePaychecks = '" + _AggregatePaychecks + "'";
|
|
if (_Attendance.HasValue)
|
condition += " and Attendance = '" + _Attendance + "'";
|
|
if (_AskForLeave.HasValue)
|
condition += " and AskForLeave = '" + _AskForLeave + "'";
|
|
if (_EducedTotal.HasValue)
|
condition += " and EducedTotal = '" + _EducedTotal + "'";
|
|
if (_Unit.HasValue)
|
condition += " and Unit = '" + _Unit + "'";
|
|
if (_Personal.HasValue)
|
condition += " and Personal = '" + _Personal + "'";
|
|
if (_WillPayTax.HasValue)
|
condition += " and WillPayTax = '" + _WillPayTax + "'";
|
|
if (_AmountWagCards.HasValue)
|
condition += " and AmountWagCards = '" + _AmountWagCards + "'";
|
|
if (!string.IsNullOrEmpty(_AccountingSituation))
|
condition += " and AccountingSituation = '" + _AccountingSituation + "'";
|
|
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<Model.OA_WagesRecord>(pagination, " * ", " OA_WagesRecord ", " Keyid desc", " Keyid desc ", condition);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 工资核算
|
/// </summary>
|
/// <param name="pagination"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_WagesRecord> SelectModelPage(Infrastructure.Query.Pagination pagination, Guid _FirmId, Guid _MemberId, int? DepartmentId, string StaffName, DateTime? _BeginStartBelongsTime, DateTime? _EndStartBelongsTime)
|
{
|
try
|
{
|
string condition = " 1=1 ";
|
|
if (_FirmId != Guid.Empty)
|
condition += " and a.FirmId = '" + _FirmId + "'";
|
|
if (_MemberId != Guid.Empty)
|
condition += " and a.MemberId = '" + _MemberId + "'";
|
|
if (DepartmentId.HasValue)
|
condition += " and a.DepartmentId = '" + DepartmentId + "'";
|
|
if (!string.IsNullOrEmpty(StaffName))
|
condition += " and a.Name = '" + StaffName + "'";
|
|
condition += string.Format(" and ( a.Status='在职' OR a.Status='审核中' OR ( a.Status ='离职' AND CAST(SM_EndWorkTime AS DATE) >'{0}' )) ", _BeginStartBelongsTime);
|
|
string condition0 = "";
|
|
if (_BeginStartBelongsTime.HasValue)
|
condition0 += string.Format(" and CAST(c.StartBelongsTime AS DATE) >='{0}'", _BeginStartBelongsTime);
|
|
if (_EndStartBelongsTime.HasValue)
|
condition0 += string.Format(" and CAST(c.StartBelongsTime AS DATE) <'{0}'", _EndStartBelongsTime);
|
|
return _dataBase.SelectModelPage<Model.OA_WagesRecord>(pagination, " c.*,a.Name AS StaffName,a.MemberId as StaffMemberId,a.Status as StaffStatus,a.SM_EndWorkTime as SM_EndWorkTime,a.DepartmentId,b.Name AS DepartmentName,d.SW_BasicSalary,d.SW_WorkAge,d.SW_WorkAgeMoney ", " dbo.OA_Staff AS a LEFT JOIN dbo.OA_Department AS b ON a.DepartmentId = b.Keyid LEFT JOIN dbo.OA_WagesRecord AS c ON a.MemberId = c.MemberId " + condition0 + " left join OA_WageManage as d on a.MemberId = d.MemberId", " a.DepartmentId ASC", " DepartmentId ASC ", condition);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 工资历史记录
|
/// </summary>
|
/// <param name="pagination"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_WagesRecord> SelectAllModelPage(Infrastructure.Query.Pagination pagination, Guid _FirmId, Guid _MemberId, int? DepartmentId, string StaffName, DateTime? _BeginStartBelongsTime, DateTime? _EndStartBelongsTime)
|
{
|
try
|
{
|
string condition = " 1=1 ";
|
|
if (_FirmId != Guid.Empty)
|
condition += " and a.FirmId = '" + _FirmId + "'";
|
|
if (_MemberId != Guid.Empty)
|
condition += " and a.MemberId = '" + _MemberId + "'";
|
|
if (DepartmentId.HasValue)
|
condition += " and a.DepartmentId = '" + DepartmentId + "'";
|
|
if (!string.IsNullOrEmpty(StaffName))
|
condition += " and a.Name = '" + StaffName + "'";
|
|
condition += string.Format(" and ( a.Status='在职' OR a.Status='审核中' OR ( a.Status ='离职' AND CAST(SM_EndWorkTime AS DATE) >'{0}' )) ", _BeginStartBelongsTime);
|
|
//string condition0 = "";
|
|
if (_BeginStartBelongsTime.HasValue)
|
condition += string.Format(" and CAST(c.StartBelongsTime AS DATE) >='{0}'", _BeginStartBelongsTime);
|
|
if (_EndStartBelongsTime.HasValue)
|
condition += string.Format(" and CAST(c.StartBelongsTime AS DATE) <'{0}'", _EndStartBelongsTime);
|
|
return _dataBase.SelectModelPage<Model.OA_WagesRecord>(pagination, " c.*,a.Name AS StaffName,a.MemberId as StaffMemberId,a.Status as StaffStatus,a.SM_EndWorkTime as SM_EndWorkTime,a.DepartmentId,b.Name AS DepartmentName ", " dbo.OA_WagesRecord AS c LEFT JOIN dbo.OA_Staff AS a ON a.MemberId = c.MemberId LEFT JOIN dbo.OA_Department AS b ON a.DepartmentId = b.Keyid ", " c.StartBelongsTime DESC", " StartBelongsTime DESC ", condition);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 核算工资
|
/// </summary>
|
/// <param name="m_OA_WagesRecordList"></param>
|
/// <returns></returns>
|
public bool AccountingWage(List<OA_WagesRecord> m_OA_WagesRecordList)
|
{
|
try
|
{
|
bool IsSuccess = true;
|
using (TransactionScope t_TransactionScope = new TransactionScope())
|
{
|
foreach (var m_OA_WagesRecord in m_OA_WagesRecordList)
|
{
|
if (IsSuccess)
|
{
|
if (m_OA_WagesRecord.Keyid > 0)
|
{
|
IsSuccess = this.UpdateModel(m_OA_WagesRecord);
|
}
|
else
|
{
|
IsSuccess = this.InserModel(m_OA_WagesRecord);
|
}
|
}
|
else
|
{
|
return false;
|
}
|
}
|
if (IsSuccess)
|
{
|
t_TransactionScope.Complete();
|
}
|
}
|
return IsSuccess;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
}
|
}
|