public MaterialRDEControl(User user) { InitializeComponent(); this.User = user; txtIdentification.BindUser(user, LookupType.Taxon); txtClassifiedBy.BindUser(User, "tblMaterial", "vchrIDBy"); txtAccessionNo.BindUser(User, "MaterialAccessionNo", "tblMaterial", "vchrAccessionNo"); txtRegistrationNo.BindUser(User, "MaterialRegNo", "tblMaterial", "vchrRegNo"); txtCollectorNo.BindUser(User, "MaterialCollectorNo", "tblMaterial", "vchrCollectorNo"); txtSource.BindUser(user, PickListType.Phrase, "Material Source", TraitCategoryType.Material); txtInstitution.BindUser(user, PickListType.Phrase, "Institution", TraitCategoryType.Material); txtCollectionMethod.BindUser(user, PickListType.Phrase, "Collection Method", TraitCategoryType.Material); txtMacroHabitat.BindUser(user, PickListType.Phrase, "Macro Habitat", TraitCategoryType.Material); txtMicroHabitat.BindUser(user, PickListType.Phrase, "Micro Habitat", TraitCategoryType.Material); txtTrap.BindUser(User, LookupType.Trap); _traits = new TraitControl(user, TraitCategoryType.Material, null, true); tabTraits.Content = _traits; _subpartsFull = new MaterialPartsControl(user, null, true); tabSubparts.Content = _subpartsFull; _associates = new OneToManyControl(new AssociatesOneToManyController(user, TraitCategoryType.Material, null), true); tabAssociates.Content = _associates; _multimedia = new MultimediaControl(User, TraitCategoryType.Material, null); tabMultimedia.Content = _multimedia; this.IsEnabled = false; this.DataContextChanged += new DependencyPropertyChangedEventHandler(MaterialRDEControl_DataContextChanged); }
void LoanDetails_ChangeContainerSet() { txtLoanNumber.BindUser(User, "LoanNumber", "tblLoan", "vchrLoanNumber"); txtTransferMethod.BindUser(User, PickListType.Phrase, "Transfer Method", TraitCategoryType.Contact); txtReturnType.BindUser(User, PickListType.Phrase, "Return Type", TraitCategoryType.Contact); txtBorrower.BindUser(User, LookupType.Contact); txtReceiver.BindUser(User, LookupType.Contact); txtAuthorizedBy.BindUser(User, LookupType.Contact); chkBorrowerIsReceiver.Checked += new RoutedEventHandler(chkBorrowerIsReceiver_Checked); chkBorrowerIsReceiver.Unchecked += new RoutedEventHandler(chkBorrowerIsReceiver_Unchecked); Loan model = null; if (LoanID >= 0) { var service = new LoanService(User); model = service.GetLoan(LoanID); } else { model = new Loan { LoanClosed = false }; RegisterUniquePendingChange(new InsertLoanCommand(model)); } if (model != null) { _viewModel = new LoanViewModel(model); if (model.ReceiverID != 0 && model.ReceiverID == model.RequestorID) { _viewModel.BorrowerIsReceiver = true; } this.DataContext = _viewModel; _viewModel.DataChanged += new DataChangedHandler(viewModel_DataChanged); } var materialControl = new OneToManyControl(new LoanMaterialControl(User, model)); var lbl = new Label { Content = "" }; materialControl.AddButtonRHS(lbl); // Count the total number of specimens currently attached to this loan. Sometimes specimen counts are represented as "1 x adult" etc, // so we be a bit liberal in our interpretation. var specimenCountRegex = new Regex(@"[^\d]*(\d+)[^\d]*"); materialControl.ModelChanged += list => { var dblTotal = list.Sum(vm => { var loanMaterial = vm as LoanMaterialViewModel; decimal subtotal = 0; var matcher = specimenCountRegex.Match(loanMaterial.NumSpecimens); while (matcher.Success) { decimal d; if (Decimal.TryParse(matcher.Groups[1].Value, out d)) { subtotal += d; } matcher = matcher.NextMatch(); } return(subtotal); }); lbl.Content = String.Format("Total specimen count: {0}", (long)dblTotal); }; tabLoan.AddTabItem("_Material", materialControl); tabLoan.AddTabItem("_Correspondence", new OneToManyControl(new LoanCorrespondenceControl(User, model))); _reminders = new OneToManyControl(new LoanRemindersControl(User, model)); tabLoan.AddTabItem("_Reminders", _reminders); tabLoan.AddTabItem("_Traits", new TraitControl(User, TraitCategoryType.Loan, _viewModel)); tabLoan.AddTabItem("_Notes", new NotesControl(User, TraitCategoryType.Loan, _viewModel)); var window = this.FindParentWindow() as ControlHostWindow; if (window != null) { var button = new Button { Width = 130, Height = 23, Content = "_Generate Loan Form..." }; window.AddCustomButton(button); button.Click += new RoutedEventHandler((source, e) => { ShowLoanForms(); }); } }