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