private void InitData() { try { if (PersonTypeItems != null && PersonTypeItems.Count > 0) { return; } PersonTypeItems = EnumHelper <PersonType> .GetMapKeyValues(); PersonTypeItems.Insert(0, new ListItem { ID = "-1", Name = "所有" }); //查询条件 QueryBusinessPersonModel = new QueryBusinessPersonModel(); } catch (Exception ex) { ex = new Exception("初始化数据失败", ex); //MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); MessageBox.Show(this.Text + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop); Log.Error(ex); } }
public List <BusinessPersonModel> QueryBusinessPerson(QueryBusinessPersonModel queryBusinessPersonModel) { try { List <BusinessPersonModel> dataList = new List <BusinessPersonModel>(); var employees = QueryEmployees(queryBusinessPersonModel); if (queryBusinessPersonModel != null && (queryBusinessPersonModel.PersonTypeValue < 0 || queryBusinessPersonModel.PersonTypeValue == (int)PersonType.Employee) && employees != null) { dataList.AddRange(employees); } var purchaseUnitBuyers = QueryPurchaseUnitBuyers(queryBusinessPersonModel); if ( queryBusinessPersonModel != null && (queryBusinessPersonModel.PersonTypeValue < 0 || queryBusinessPersonModel.PersonTypeValue == (int)PersonType.PurchaseUnitBuyer) && purchaseUnitBuyers != null) { dataList.AddRange(purchaseUnitBuyers); } var supplyUnitSalesman = QuerySupplyUnitSalesmans(queryBusinessPersonModel); if ( queryBusinessPersonModel != null && (queryBusinessPersonModel.PersonTypeValue < 0 || queryBusinessPersonModel.PersonTypeValue == (int)PersonType.SupplyUnitSalesman) && supplyUnitSalesman != null) { dataList.AddRange(supplyUnitSalesman); } return(dataList); } catch (Exception ex) { ex = new BusinessException("查询人员失败", ex); Log.Error(ex); return(new List <BusinessPersonModel>()); } }
private List <BusinessPersonModel> QueryEmployees(QueryBusinessPersonModel queryModel) { try { var db = this._UnitOfWork as Db; var query = db.Employees.AsQueryable().Where(t => !t.Deleted); if (queryModel != null) { string Name = queryModel.Name; if (!string.IsNullOrEmpty(Name)) { query = query.Where(t => t.Name.Contains(Name)); } string IDNumber = queryModel.IDNumber; if (!string.IsNullOrEmpty(IDNumber)) { query = query.Where(t => t.IdentityNo.Contains(IDNumber)); } string Tel = queryModel.Tel; if (!string.IsNullOrEmpty(Tel)) { query = query.Where(t => t.Phone.Contains(Tel)); } string Address = queryModel.Address; if (!string.IsNullOrEmpty(Address)) { query = query.Where(t => t.Address.Contains(Address)); } string Gender = queryModel.Gender; if (!string.IsNullOrEmpty(Address)) { query = query.Where(t => t.Gender.Contains(Gender)); } var Birthday = queryModel.Birthday; if (Birthday != null && Birthday.Max >= Birthday.Min) { DateTime BirthdayMax = Birthday.Max; DateTime BirthdayMin = Birthday.Min; if (BirthdayMax == BirthdayMin) { query = query.Where(t => t.BirthDay == BirthdayMax); } else { query = query.Where(t => t.BirthDay >= BirthdayMin && t.BirthDay <= BirthdayMax); } } var OutDate = queryModel.OutDate; if (OutDate != null && OutDate.Max >= OutDate.Min) { DateTime OutDateMax = OutDate.Max; DateTime OutDateMin = OutDate.Min; if (OutDateMax == OutDateMin) { query = query.Where(t => t.OutDate == OutDateMax); } else { query = query.Where(t => t.OutDate >= OutDateMin && t.OutDate <= OutDateMax); } } } return(query.ToList() .Select(t => new BusinessPersonModel { Address = t.Address, Birthday = t.BirthDay ?? DateTime.MinValue, Gender = t.Gender, IDNumber = t.IdentityNo, Id = t.Id, Name = t.Name, OutDate = t.OutDate, PersonType = PersonType.Employee, Tel = t.Phone }) .ToList()); } catch (Exception ex) { return(null); } }