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_StaffDAL : IOA_StaffDAL { private Database _dataBase = null; public OA_StaffDAL() { _dataBase = new Database(); } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_Staff trueModel = model as Model.OA_Staff; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter(){Direction=ParameterDirection.ReturnValue,SqlDbType = SqlDbType.Int}, new SqlParameter("@FirmId", trueModel.FirmId) , new SqlParameter("@Name", trueModel.Name) , new SqlParameter("@Sex", trueModel.Sex) , new SqlParameter("@StaffUserName", trueModel.StaffUserName) , new SqlParameter("@StaffUserPwd", trueModel.StaffUserPwd) , new SqlParameter("@MobieNum", trueModel.MobieNum) , new SqlParameter("@QQ", trueModel.QQ) , new SqlParameter("@PhoneNum", trueModel.PhoneNum) , new SqlParameter("@Email", trueModel.Email) , new SqlParameter("@Status", trueModel.Status) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Operator", trueModel.Operator) , new SqlParameter("@Remark", trueModel.Remark) , new SqlParameter("@MemberId", trueModel.MemberId) , new SqlParameter("@IsBusinessManager", trueModel.IsBusinessManager) , new SqlParameter("@IsAccountManager", trueModel.IsAccountManager) , new SqlParameter("@DepartmentId", trueModel.DepartmentId) , new SqlParameter("@SM_Number", trueModel.SM_Number) , new SqlParameter("@SM_SpouseName", trueModel.SM_SpouseName) , new SqlParameter("@SM_SpousePhone", trueModel.SM_SpousePhone) , new SqlParameter("@SM_OtherLog", trueModel.SM_OtherLog) , new SqlParameter("@SM_Post", trueModel.SM_Post) , new SqlParameter("@SM_Degree", trueModel.SM_Degree) , new SqlParameter("@SM_StartWorkTime", trueModel.SM_StartWorkTime) , new SqlParameter("@SM_Money", trueModel.SM_Money) , new SqlParameter("@SM_IsSocialSecurity", trueModel.SM_IsSocialSecurity) , new SqlParameter("@SM_SocialSecurityType", trueModel.SM_SocialSecurityType) , new SqlParameter("@SM_SocialSecurityNumber", trueModel.SM_SocialSecurityNumber) , new SqlParameter("@SM_SocialSecurityTime", trueModel.SM_SocialSecurityTime) , new SqlParameter("@SM_SocialSecurityAllMoney", trueModel.SM_SocialSecurityAllMoney) , new SqlParameter("@SM_SocialSecurityFirmMoney", trueModel.SM_SocialSecurityFirmMoney) , new SqlParameter("@SM_SocialSecuritySelfMoney", trueModel.SM_SocialSecuritySelfMoney) , new SqlParameter("@SM_IsContract", trueModel.SM_IsContract) , new SqlParameter("@SM_ContractStartTime", trueModel.SM_ContractStartTime) , new SqlParameter("@SM_ContractEndTime", trueModel.SM_ContractEndTime) , new SqlParameter("@SM_EndWorkStatus", trueModel.SM_EndWorkStatus) , new SqlParameter("@SM_EndWorkStartTime", trueModel.SM_EndWorkStartTime) , new SqlParameter("@SM_EndWorkTime", trueModel.SM_EndWorkTime) , new SqlParameter("@SM_EndWorkContent", trueModel.SM_EndWorkContent) , new SqlParameter("@SM_DepartmentHeads", trueModel.SM_DepartmentHeads) , new SqlParameter("@SM_AdministrationDepartment", trueModel.SM_AdministrationDepartment) , new SqlParameter("@SM_MinistryFinance", trueModel.SM_MinistryFinance) , new SqlParameter("@SM_GeneralManager", trueModel.SM_GeneralManager) , new SqlParameter("@SM_IsImporting", trueModel.SM_IsImporting) , new SqlParameter("@SM_IsDelete", trueModel.SM_IsDelete) , new SqlParameter("@SM_Birthday", trueModel.SM_Birthday) , new SqlParameter("@SM_IDCardNum", trueModel.SM_IDCardNum) , new SqlParameter("@SM_IDCardPic", trueModel.SM_IDCardPic) , new SqlParameter("@SM_CertificateType", trueModel.SM_CertificateType) , new SqlParameter("@SM_CertificatePic", trueModel.SM_CertificatePic) , new SqlParameter("@SM_NowProvince", trueModel.SM_NowProvince) , new SqlParameter("@SM_NowCity", trueModel.SM_NowCity) , new SqlParameter("@SM_NowArea", trueModel.SM_NowArea) , new SqlParameter("@SM_NowAddress", trueModel.SM_NowAddress) , new SqlParameter("@SM_OldProvence", trueModel.SM_OldProvence) , new SqlParameter("@SM_OldCity", trueModel.SM_OldCity) , new SqlParameter("@SM_OldArea", trueModel.SM_OldArea) , new SqlParameter("@SM_OldAdress", trueModel.SM_OldAdress), new SqlParameter("@ManageProvince", trueModel.ManageProvince) , new SqlParameter("@ManageCity", trueModel.ManageCity) , new SqlParameter("@ManageCountry", trueModel.ManageCountry) , new SqlParameter("@ManageCountry1", trueModel.ManageCountry1) , new SqlParameter("@BF_IsDeliverManage", trueModel.BF_IsDeliverManage) , new SqlParameter("@BF_IsDriver", trueModel.BF_IsDriver) , new SqlParameter("@BF_Isbaoxiaojingli", trueModel.BF_Isbaoxiaojingli) , new SqlParameter("@BF_IsBaoxiaozhuguan", trueModel.BF_IsBaoxiaozhuguan) , new SqlParameter("@BF_IsGongwen", trueModel.BF_IsGongwen.HasValue?trueModel.BF_IsGongwen.Value:false) , }; try { _dataBase.Query("sp_OA_Staff_Insert", CommandType.StoredProcedure, sqlParms.ToArray()); trueModel.Keyid = (int)sqlParms[0].Value; } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_Staff trueModel = model as Model.OA_Staff; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid", trueModel.Keyid) , new SqlParameter("@FirmId", trueModel.FirmId) , new SqlParameter("@Name", trueModel.Name) , new SqlParameter("@Sex", trueModel.Sex) , new SqlParameter("@StaffUserName", trueModel.StaffUserName) , new SqlParameter("@StaffUserPwd", trueModel.StaffUserPwd) , new SqlParameter("@MobieNum", trueModel.MobieNum) , new SqlParameter("@QQ", trueModel.QQ) , new SqlParameter("@PhoneNum", trueModel.PhoneNum) , new SqlParameter("@Email", trueModel.Email) , new SqlParameter("@Status", trueModel.Status) , new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) , new SqlParameter("@Operator", trueModel.Operator) , new SqlParameter("@Remark", trueModel.Remark) , new SqlParameter("@MemberId", trueModel.MemberId) , new SqlParameter("@IsBusinessManager", trueModel.IsBusinessManager) , new SqlParameter("@IsAccountManager", trueModel.IsAccountManager) , new SqlParameter("@DepartmentId", trueModel.DepartmentId) , new SqlParameter("@SM_Number", trueModel.SM_Number) , new SqlParameter("@SM_SpouseName", trueModel.SM_SpouseName) , new SqlParameter("@SM_SpousePhone", trueModel.SM_SpousePhone) , new SqlParameter("@SM_OtherLog", trueModel.SM_OtherLog) , new SqlParameter("@SM_Post", trueModel.SM_Post) , new SqlParameter("@SM_Degree", trueModel.SM_Degree) , new SqlParameter("@SM_StartWorkTime", trueModel.SM_StartWorkTime) , new SqlParameter("@SM_Money", trueModel.SM_Money) , new SqlParameter("@SM_IsSocialSecurity", trueModel.SM_IsSocialSecurity) , new SqlParameter("@SM_SocialSecurityType", trueModel.SM_SocialSecurityType) , new SqlParameter("@SM_SocialSecurityNumber", trueModel.SM_SocialSecurityNumber) , new SqlParameter("@SM_SocialSecurityTime", trueModel.SM_SocialSecurityTime) , new SqlParameter("@SM_SocialSecurityAllMoney", trueModel.SM_SocialSecurityAllMoney) , new SqlParameter("@SM_SocialSecurityFirmMoney", trueModel.SM_SocialSecurityFirmMoney) , new SqlParameter("@SM_SocialSecuritySelfMoney", trueModel.SM_SocialSecuritySelfMoney) , new SqlParameter("@SM_IsContract", trueModel.SM_IsContract) , new SqlParameter("@SM_ContractStartTime", trueModel.SM_ContractStartTime) , new SqlParameter("@SM_ContractEndTime", trueModel.SM_ContractEndTime) , new SqlParameter("@SM_EndWorkStatus", trueModel.SM_EndWorkStatus) , new SqlParameter("@SM_EndWorkStartTime", trueModel.SM_EndWorkStartTime) , new SqlParameter("@SM_EndWorkTime", trueModel.SM_EndWorkTime) , new SqlParameter("@SM_EndWorkContent", trueModel.SM_EndWorkContent) , new SqlParameter("@SM_DepartmentHeads", trueModel.SM_DepartmentHeads) , new SqlParameter("@SM_AdministrationDepartment", trueModel.SM_AdministrationDepartment) , new SqlParameter("@SM_MinistryFinance", trueModel.SM_MinistryFinance) , new SqlParameter("@SM_GeneralManager", trueModel.SM_GeneralManager) , new SqlParameter("@SM_IsImporting", trueModel.SM_IsImporting) , new SqlParameter("@SM_IsDelete", trueModel.SM_IsDelete) , new SqlParameter("@SM_Birthday", trueModel.SM_Birthday) , new SqlParameter("@SM_IDCardNum", trueModel.SM_IDCardNum) , new SqlParameter("@SM_IDCardPic", trueModel.SM_IDCardPic) , new SqlParameter("@SM_CertificateType", trueModel.SM_CertificateType) , new SqlParameter("@SM_CertificatePic", trueModel.SM_CertificatePic) , new SqlParameter("@SM_NowProvince", trueModel.SM_NowProvince) , new SqlParameter("@SM_NowCity", trueModel.SM_NowCity) , new SqlParameter("@SM_NowArea", trueModel.SM_NowArea) , new SqlParameter("@SM_NowAddress", trueModel.SM_NowAddress) , new SqlParameter("@SM_OldProvence", trueModel.SM_OldProvence) , new SqlParameter("@SM_OldCity", trueModel.SM_OldCity) , new SqlParameter("@SM_OldArea", trueModel.SM_OldArea) , new SqlParameter("@SM_OldAdress", trueModel.SM_OldAdress), new SqlParameter("@ManageProvince", trueModel.ManageProvince) , new SqlParameter("@ManageCity", trueModel.ManageCity) , new SqlParameter("@ManageCountry", trueModel.ManageCountry) , new SqlParameter("@ManageCountry1", trueModel.ManageCountry1) , new SqlParameter("@BF_IsDeliverManage", trueModel.BF_IsDeliverManage) , new SqlParameter("@BF_IsDriver", trueModel.BF_IsDriver) , new SqlParameter("@BF_Isbaoxiaojingli", trueModel.BF_Isbaoxiaojingli) , new SqlParameter("@BF_IsBaoxiaozhuguan", trueModel.BF_IsBaoxiaozhuguan) , new SqlParameter("@BF_IsGongwen", trueModel.BF_IsGongwen.HasValue?trueModel.BF_IsGongwen.Value:false) , }; try { _dataBase.Query("sp_OA_Staff_Update", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.OA_Staff trueModel = model as Model.OA_Staff; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; try { _dataBase.Query("sp_OA_Staff_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_Staff GetModelByKeyid(int? Keyid) { try { if (Keyid == null || Keyid < 0) return null;//错误数据返会空 IList result = _dataBase.SelectModel(" a.*,b.Name as DepartmentName ", " dbo.OA_Staff AS a LEFT JOIN dbo.OA_Department AS b ON a.DepartmentId = b.Keyid ", string.Format(" a.Keyid='{0}'", Keyid)) as IList;//执行查询 return (null == result || result.Count == 0) ? null : result[0];//返回结果 } catch (Exception ex) { throw ex; } } /// /// 根据员工会员编号获得信息 /// /// 编号 /// public OA_Staff GetModelByMemberId(Guid MemberId) { try { if (MemberId == null || MemberId == Guid.Empty) return null;//错误数据返会空 IList result = _dataBase.SelectModel(" a.*,b.Name as DepartmentName ", " dbo.OA_Staff AS a LEFT JOIN dbo.OA_Department AS b ON a.DepartmentId = b.Keyid ", string.Format(" a.MemberId='{0}'", MemberId)) as IList;//执行查询 return (null == result || result.Count == 0) ? null : result[0];//返回结果 } catch (Exception ex) { throw ex; } } /// /// 分页查询 /// /// /// /// /// /// /// public IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, int? DepartmentId, Guid MemberId, string MemberName, string Status) { try { string condition = " 1=1 "; if (!string.IsNullOrEmpty(MemberName)) { condition += "and a.Name like '%" + MemberName + "%'"; } if (!string.IsNullOrEmpty(Status)) { condition += " and a.Status = '" + Status + "'"; } if (MemberId != Guid.Empty) { condition += " and a.FirmId = '" + MemberId + "'"; } if (DepartmentId > 0) { condition += " and a.DepartmentId = '" + DepartmentId + "'"; } return _dataBase.SelectModelPage(pagination, " a.*,b.Name as DepartmentName ", " dbo.OA_Staff AS a LEFT JOIN dbo.OA_Department AS b ON a.DepartmentId = b.Keyid ", "a.Status DESC,a.DepartmentId ASC ", " Status DESC,DepartmentId ASC ", condition); } catch (Exception ex) { throw ex; } } /// /// 生日提醒 /// /// /// /// /// /// /// public IEnumerable BirthdayRemind(Infrastructure.Query.Pagination pagination, int? DepartmentId, Guid MemberId, string MemberName, string Status) { try { string condition = " 1=1 "; if (!string.IsNullOrEmpty(MemberName)) { condition += "and a.Name like '%" + MemberName + "%'"; } if (!string.IsNullOrEmpty(Status)) { condition += " and a.Status = '" + Status + "'"; } if (MemberId != Guid.Empty) { condition += " and a.FirmId = '" + MemberId + "'"; } if (DepartmentId > 0) { condition += " and a.DepartmentId = '" + DepartmentId + "'"; } return _dataBase.SelectModelPage(pagination, " a.*,b.Name as DepartmentName ", " (select *,'1' as PeriodSection,substring(convert(varchar(10),SM_Birthday,21),6,5) as date1 FROM dbo.OA_Staff where substring(convert(varchar(10),SM_Birthday,21),6,5)>= substring(convert(varchar(10),GETDATE(),21),6,5) union all select *,'2' as PeriodSection,substring(convert(varchar(10),SM_Birthday,21),6,5) as date1 from dbo.OA_Staff where substring(convert(varchar(10),SM_Birthday,21),6,5)< substring(convert(varchar(10),GETDATE(),21),6,5)) AS a LEFT JOIN dbo.OA_Department AS b ON a.DepartmentId = b.Keyid ", " a.PeriodSection,a.date1 ", " PeriodSection,date1 ", condition); } catch (Exception ex) { throw ex; } } /// /// 添加员工 /// /// /// /// public bool AddStaff(OA_Staff m_OA_Staff, EC_MemberBasic m_EC_MemberBasic, OA_StaffRoleRel m_OA_StaffRoleRel) { try { EC_MemberBasicDAL dal_EC_MemberBasicDAL = new EC_MemberBasicDAL(_dataBase); OA_StaffRoleRelDAL dal_OA_StaffRoleRelDAL = new OA_StaffRoleRelDAL(_dataBase); bool result = true; using (TransactionScope t_TransactionScope = new TransactionScope()) { if (result) { result = InserModel(m_OA_Staff); if (result) { m_OA_StaffRoleRel.StaffId = m_OA_Staff.Keyid; result = dal_OA_StaffRoleRelDAL.InserModel(m_OA_StaffRoleRel); if (result) { result = dal_EC_MemberBasicDAL.InserModel(m_EC_MemberBasic); if (result) { t_TransactionScope.Complete(); } } } } } return result; } catch (Exception ex) { throw ex; } } /// /// 更新员工信息 /// /// /// /// public bool UpdateStaff(OA_Staff m_OA_Staff, EC_MemberBasic m_EC_MemberBasic, OA_StaffRoleRel m_OA_StaffRoleRel) { try { EC_MemberBasicDAL dal_EC_MemberBasicDAL = new EC_MemberBasicDAL(_dataBase); OA_StaffRoleRelDAL dal_OA_StaffRoleRelDAL = new OA_StaffRoleRelDAL(_dataBase); bool result = true; using (TransactionScope t_TransactionScope = new TransactionScope()) { if (result) { result = UpdateModel(m_OA_Staff); if (result) { result = dal_OA_StaffRoleRelDAL.UpdateModel(m_OA_StaffRoleRel); if (result) { result = dal_EC_MemberBasicDAL.UpdateModel(m_EC_MemberBasic); if (result) { t_TransactionScope.Complete(); } } } } } return result; } catch (Exception ex) { throw ex; } } /// /// 根据厂商编号获取员工列表 /// /// /// /// /// public IEnumerable SelectListByFirmId(Guid FirmId, bool? IsBusinessManager, bool? IsAccountManager) { try { if (FirmId == null || FirmId == Guid.Empty) return null;//错误数据返会空 string condition = " FirmId='" + FirmId + "' "; if (IsBusinessManager == true && IsAccountManager == true) condition += " And ( IsBusinessManager='" + IsBusinessManager + "' or IsAccountManager='" + IsAccountManager + "' )"; if (IsBusinessManager == true && IsAccountManager == false) condition += " And IsBusinessManager='" + IsBusinessManager + "' "; if (IsBusinessManager == false && IsAccountManager == true) condition += " And IsAccountManager='" + IsAccountManager + "' "; condition += " and Status='在职' order by DepartmentId ASC"; IList result = _dataBase.SelectModel("*", "OA_Staff", condition) as IList;//执行查询 return result;//返回结果 } catch (Exception ex) { throw ex; } } /// /// 检测员工姓名是否重复 /// /// /// /// public int IsExitsName(string Name, Guid MemberId) { try { IList result = _dataBase.SelectModel("*", "OA_Staff", " Name = '" + Name + "' and FirmId ='" + MemberId + "'") as IList;//执行查询 if (null == result || result.Count == 0) return 0; else return 1; } catch (Exception ex) { throw ex; } } public DataTable GetStaffByDep(Guid FirmId, string DepartmentId) { string selectTarget = " * "; string condition = ""; if (!string.IsNullOrEmpty(DepartmentId)) { condition += " and DepartmentId='" + DepartmentId + "' "; } string fromSource = " OA_Staff where Status ='在职' and FirmId = '" + FirmId + "'" + condition + " order by DepartmentId ASC "; return _dataBase.SelectModel(selectTarget, fromSource); } } }