/// <summary> /// Initialises a new instance of the <see cref="LabelGenerationViewModel"/> class. /// </summary> /// <param name="model">junior handicap model</param> /// <param name="normalisationConfigManager">normalisation configuration manager</param> /// <param name="seriesConfigManager">series configuration manager</param> /// <param name="logger">application logger</param> /// <param name="saveFolder">folder to save the output to</param> public LabelGenerationViewModel( IModel model, INormalisationConfigMngr normalisationConfigManager, ISeriesConfigMngr seriesConfigManager, IJHcLogger logger, string saveFolder) { this.model = model; this.seriesConfigManager = seriesConfigManager; this.logger = logger; SaveFolder = saveFolder; NormalisationConfigType hcConfiguration = normalisationConfigManager.ReadNormalisationConfiguration(); // TODO, this is repeated code, see HandicapWriter.cs foreach (AthleteDetails athlete in model.Athletes.AthleteDetails) { TimeType newHandicap = model.CurrentSeason.GetAthleteHandicap(athlete.Key, hcConfiguration); // Only look at active athletes. if (athlete.Active) { List <string> runningNumbers = model.Athletes.GetAthleteRunningNumbers(athlete.Key); // Use default handicap, if the athlete is not registered for the current season. // TODO, I suspect this should never happen??? if (newHandicap == null) { newHandicap = athlete.RoundedHandicap; } // Ensure that the athlete is registered for the season. if (runningNumbers.Count > 0) { AthleteLabel modelAthlete = new AthleteLabel( athlete.Name, athlete.Club, runningNumbers[0], newHandicap, athlete.Appearances == 0); modelAthlete.AthleteLabelWidth = A4Details.GetLabelWidth96DPI(NoColumns); modelAthlete.AthleteLabelHeight = A4Details.GetLabelHeight96DPI(NoRows); this.AthleteDetails.Add(modelAthlete); } } } // Order the athletes alphabetically. this.AthleteDetails = this.AthleteDetails.OrderBy(athlete => athlete.Forename).ToList(); this.AthleteDetails = this.AthleteDetails.OrderBy(athlete => athlete.Surname).ToList(); this.saveDirectory = saveFolder; this.CreateRaceLabelsCommand = new CreateAndSaveRaceLabelsCmd(this); this.CreateSpareLabelsCommand = new CreateAndSaveSpareLabelsCmd(this); this.CreateAllLabelsCommand = new CreateAndSaveAllLabelsCmd(this); }
/// <summary> /// Creates a set of image files, each containing a spare barcodes. /// </summary> /// <param name="model">junior handicap model</param> /// <param name="seriesConfigManager">series configuration manager</param> /// <param name="savePath">path to save the images to</param> /// <param name="numberOfSpareSheets">number of spare sheets to create</param> /// <param name="numberOfColumns">number of columns of labels</param> /// <param name="numberOfRow">number of rows of labels</param> /// <param name="eventDetails">details of the event, name and date</param> public static void CreateSpareLabels( IModel model, ISeriesConfigMngr seriesConfigManager, string savePath, int numberOfSpareSheets, int numberOfColumns, int numberOfRow, string eventDetails) { int raceNumber = model.Athletes.NextAvailableRaceNumber; SeriesConfigType config = seriesConfigManager.ReadSeriesConfiguration(); for (int sheetNumber = 0; sheetNumber < numberOfSpareSheets; ++sheetNumber) { ObservableCollection <AthleteLabel> sheet = new ObservableCollection <AthleteLabel>(); for (int labelIndex = 0; labelIndex < numberOfColumns * numberOfRow; ++labelIndex) { AthleteLabel newLabel = new AthleteLabel( string.Empty, string.Empty, GetRaceNumber(config?.NumberPrefix, raceNumber), null, false); newLabel.EventDetails = eventDetails; newLabel.AthleteLabelWidth = A4Details.GetLabelWidth96DPI(numberOfColumns); newLabel.AthleteLabelHeight = A4Details.GetLabelHeight96DPI(numberOfRow); sheet.Add(newLabel); // TODO UpdateString ++raceNumber; } CreateSingleSheet(new LabelsSheetViewModel(sheet), savePath + Path.DirectorySeparatorChar + spareLabelsName + sheetNumber.ToString() + ".png"); } }