private DataMatrix MergeItemMatrices(DataMatrix siteData, DataMatrix siteVisitData, DataMatrix materialData) { var result = new DataMatrix(); // Create the final column set (based on the specified criteria) foreach (QueryCriteria c in Criteria) { result.Columns.Add(new MatrixColumn { Name = c.Field.DisplayName }); } // Now add the identity columns (as hidden columns, unless they already exist) string[] cols = { "Site Identifier", "Visit Identifier", "Material Identifier" }; foreach (string col in cols) { if (result.IndexOf(col) < 0) { result.Columns.Add(new MatrixColumn { Name = col, IsHidden = true }); } } int currentOrderNum = 1; LabelSetItem item = null; while ((item = Items.FirstOrDefault((candidate) => { return(candidate.PrintOrder == currentOrderNum); })) != null) { if (item.NumCopies > 0) { var row = result.AddRow(); if (item.SiteID > 0) { AddFieldData(row, item.SiteID, "Site Identifier", siteData); } if (item.VisitID > 0) { AddFieldData(row, item.VisitID, "Visit Identifier", siteVisitData); } if (item.MaterialID > 0) { AddFieldData(row, item.MaterialID, "Material Identifier", materialData); } if (item.NumCopies > 1) { CopyRow(result, row, item.NumCopies - 1); } } currentOrderNum++; } return(result); }
public void AddItemFromPinnable(PinnableObject pinnable) { int maxOrder = 0; if (_itemModel.Count > 0) { maxOrder = _itemModel.Max((item) => { return(item.PrintOrder); }); } var newItem = new LabelSetItem { ItemID = pinnable.ObjectID, ItemType = pinnable.LookupType.ToString(), SetID = CurrentItemSetID, PrintOrder = maxOrder + 1, NumCopies = 1 }; var service = new MaterialService(User); Site site = null; SiteVisit visit = null; Material material = null; switch (pinnable.LookupType) { case LookupType.Material: material = service.GetMaterial(pinnable.ObjectID); visit = service.GetSiteVisit(material.SiteVisitID); site = service.GetSite(material.SiteID); break; case LookupType.SiteVisit: visit = service.GetSiteVisit(pinnable.ObjectID); site = service.GetSite(visit.SiteID); break; case LookupType.Site: site = service.GetSite(pinnable.ObjectID); break; } if (material != null) { newItem.MaterialID = material.MaterialID; newItem.TaxaFullName = material.TaxaDesc; newItem.AccessionNo = material.AccessionNumber; } if (visit != null) { newItem.VisitID = visit.SiteVisitID; newItem.Collectors = visit.Collector; newItem.DateType = visit.DateType; newItem.CasualDate = visit.CasualTime; newItem.StartDate = visit.DateStart; newItem.EndDate = visit.DateEnd; } if (site != null) { if (site.PoliticalRegionID <= 0) { ErrorMessage.Show("You cannot add this item as it does not belong to a political region (unplaced)"); return; } newItem.SiteID = site.SiteID; newItem.Region = site.PoliticalRegion; newItem.Local = site.Locality; newItem.LocalType = site.LocalityType; newItem.Lat = site.PosY1; newItem.Long = site.PosX1; newItem.Lat2 = site.PosY2; newItem.Long2 = site.PosX2; } var vm = new LabelSetItemViewModel(newItem); vm.DataChanged += new DataChangedHandler((viewModel) => { Host.RegisterUniquePendingChange(new UpdateLabelSetItemCommand(newItem)); }); Host.RegisterUniquePendingChange(new InsertLabelSetItemCommand(newItem, CurrentLabelSet.Model)); _itemModel.Add(vm); }