private void GenerateReport() { System.Windows.Forms.Cursor cursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; try { using (RepositoryFactory factory = new RepositoryFactory()) { using (IProductionQueryRepository repository = factory.CreateProductionQueryRepository()) { ProductionQuery query = new ProductionQuery().AddDateRange(dtPeriodStart.Value, dtPeriodEnd.Value); if (!string.IsNullOrEmpty(txtProduct.Text)) query = query.AddProduct(new ProductNumber(txtProduct.Text)); if (!string.IsNullOrEmpty(txtOrder.Text)) query = query.AddOrder(new OrderNumber(txtOrder.Text)); if (cbMachine.SelectedItem != null) query = query.AddMachine(cbMachine.SelectedItem.ToString()); if (cbTeam.SelectedItem != null) query = query.AddTeam((ProductionTeam) cbTeam.SelectedItem); ShowResults(query, repository.LoadProductions(query)); } } } finally { Cursor.Current = cursor; } }
public IEnumerable<Production> LoadProductions(ProductionQuery query) { //log.InfoFormat("Loading all productions matching: {0}", query); IList<Production> result = new List<Production>(); try { ICriteria criteria = session.CreateCriteria(typeof(Production)); List<string> machines = new List<string>(query.Machines); List<ProductionTeam> teams = new List<ProductionTeam>(query.Teams); if (machines.Count > 0) { criteria.Add(Expression.In("Machine", machines)); } if (query.Order != null) criteria.Add(Expression.Eq("Order", query.Order)); if (query.Product != null) criteria.Add(Expression.Eq("Product", query.Product)); foreach (Production p in criteria.List<Production>()) { Production production = p; if (query.DateRange != null) { if (production.ProductionEnd.Date < query.DateRange.First.Date || query.DateRange.Second.Date < production.ProductionStart.Date) continue; List<ProductionShift> shifts = new List<ProductionShift>(); foreach (var shift in production.Shifts) { if (query.DateRange.First <= shift.ProductionStart.Date && shift.ProductionStart.Date <= query.DateRange.Second) shifts.Add(shift); } if (shifts.Count == 0) continue; production = Duplicate(production, shifts); } if (teams.Count > 0) { List<ProductionShift> shifts = new List<ProductionShift>(production.Shifts).FindAll(delegate(ProductionShift shift) { foreach (var team in teams) { if (shift.Team.Equals(team)) return true; } return false; }); if (shifts.Count == 0) continue; production = Duplicate(production, shifts); } result.Add(production); } } catch (HibernateException e) { //log.Error(string.Format("An exception occurred while loading all productions matching: {0}. No entities were loaded.", query), e); throw new RepositoryException("Could not load all productions due to an internal exception", e); } //log.InfoFormat("Loaded all productions matching: {0}. {1} entities were found", query, result.Count); return result; }
private void ShowResults(ProductionQuery query, IEnumerable<Production> productions) { IEnumerable<ProductionStop> stops = GetProductionStops(); ucReport.UpdateDisplay(query, productions, stops); btnPrint.Enabled = true; }