private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedPlant.PlantID)) {//check to see if key is part of the current companylist... Plant query = PlantList.Where(company => company.PlantID == SelectedPlant.PlantID && company.AutoID != SelectedPlant.AutoID).FirstOrDefault(); if (query != null) {//revert it back SelectedPlant.PlantID = SelectedPlantMirror.PlantID; //change to the newly selected company... SelectedPlant = query; return; } //it is not part of the existing list try to fetch it from the db... PlantList = GetPlantByID(SelectedPlant.PlantID, XERP.Client.ClientSessionSingleton.Instance.CompanyID); if (PlantList.Count == 0)//it was not found do new record required logic... { NotifyNewRecordNeeded("Record " + SelectedPlant.PlantID + " Does Not Exist. Create A New Record?"); } else { SelectedPlant = PlantList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedPlant.PlantID != SelectedPlantMirror.PlantID) { SelectedPlant.PlantID = SelectedPlantMirror.PlantID; } } }
private void OnSearchResult(object sender, NotificationEventArgs <BindingList <Plant> > e) { if (e.Data != null && e.Data.Count > 0) { PlantList = e.Data; SelectedPlant = PlantList.FirstOrDefault(); Dirty = false; AllowCommit = false; } UnregisterToReceiveMessages <BindingList <Plant> >(MessageTokens.PlantSearchToken.ToString(), OnSearchResult); }