private void SearchButton_Click(object sender, EventArgs e) { if (!DateTime.TryParse(startDateTextBox.Text, out DateTime startDate)) { startDate = DateTime.MinValue; } if (!DateTime.TryParse(endDateTextBox.Text, out DateTime endDate)) { endDate = DateTime.MaxValue; } // флаг доступности bool?isOpen; // если нажат if (isOpenCheckBox.CheckState == CheckState.Checked) { isOpen = true; } // если не нажат else if (isOpenCheckBox.CheckState == CheckState.Unchecked) { isOpen = false; } // если не определен else { isOpen = null; } search = new SearchRentParam( int.TryParse(numberTextBox.Text, out int number) ? new int?(number) : null, startDate, endDate, int.TryParse(periodTextBox.Text, out int period) ? new int?(period) : null, brandTextBox.Text, clientTextBox.Text, employeeTextBox.Text, isOpen ); UpdateView(); }
// метод для поиска аренд, аналогичен методу поиска клиентов public IEnumerable <Models.Library.Rent> GetRents(SearchRentParam search) { var rents = Rents.ToArray(); var queryable = Rents.AsQueryable(); if (!string.IsNullOrWhiteSpace(search.CarBrand)) { queryable = queryable.Where(r => r.Car.CarBrand.Brand.Contains(search.CarBrand)); } if (!string.IsNullOrWhiteSpace(search.ClientFIO)) { queryable = queryable.Where(r => r.Client.FIO.Contains(search.ClientFIO)); } queryable = queryable.Where(r => r.StartDate >= search.Start && r.StartDate <= search.End); if (!string.IsNullOrWhiteSpace(search.EmployeeFIO)) { queryable = queryable.Where(r => r.User.FIO.Contains(search.EmployeeFIO)); } if (search.Number.HasValue) { queryable = queryable.Where(r => r.RentID == search.Number.Value); } if (search.Period.HasValue) { queryable = queryable.Where(r => r.RentalPeriod == search.Period); } if (search.IsOpen.HasValue) { queryable = queryable.Where(r => r.IsOpen == search.IsOpen); } return(queryable.ToArray().Select(r => GetRentFromDB(r))); }
public Rents() { InitializeComponent(); search = SearchRentParam.Empty; UpdateView(); }