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