/// <summary> /// Handles the ReceiveCompleted event of the msmq control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e"> /// The <see cref="ReceiveCompletedEventArgs" /> /// instance containing the event data. /// </param> private void msmq_ReceiveCompleted( object sender, ReceiveCompletedEventArgs e) { var str = e.Message.Body.ToString(); var split = str.Split(",".ToCharArray()); // parse out message pieces Guid id = Guid.Parse(split[1]); var timestamp = DateTime.Parse(split[5]); var line = split[2].Substring(4); var lineNumber = int.Parse(line); // find an existing production entry if it exists var entry = this.ProductionEntryService.List().FirstOrDefault( p => p.Id == id); // create a new entry if it doesnt exist yet... if (entry == null) { var schedule = this.ScheduleService.GetByTimestamp(timestamp); entry = new ProductionEntry() { Id = id, Product = schedule == null ? null : schedule.Product, Stages = new Collection <ProductionStage>() }; this.ProductionEntryService.Add(entry); } // create a new stage var stage = new ProductionStage() { WorkArea = split[0], TimeStamp = timestamp, LineNumber = lineNumber, ProductionEntry = entry }; // find the station the product is at var stationId = split[3]; var station = this.StationService.List().FirstOrDefault( s => s.Identifier == stationId); stage.Station = station; // find the flaw if (split[4].Length > 0) { var flawId = split[4]; stage.ProductFlaw = this.FlawService.List().FirstOrDefault( f => f.Identifier == flawId); } // save the data! entry.Stages.Add(stage); this.ProductionEntryService.Update(entry); this.StageService.Add(stage); // start listening for messages again, if we aren't paused... if (this.IsRunning) { this.Queue.BeginReceive(); } }
/// <summary> /// Updates the specified product. /// </summary> /// <param name="product">The product.</param> public void Update(ProductionEntry product) { this.Repository.SaveChanges(); }
/// <summary> /// Deletes the specified product. /// </summary> /// <param name="product">The product.</param> public void Delete(ProductionEntry product) { this.Repository.Delete(product); this.Repository.SaveChanges(); }
/// <summary> /// Adds the specified product. /// </summary> /// <param name="product">The product.</param> public void Add(ProductionEntry product) { this.Repository.Add(product); this.Repository.SaveChanges(); }