//CompanyCode Object Scope Validation check the entire object for validity... private byte CompanyCodeIsValid(CompanyCode item, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(item.CompanyCodeID)) { errorMessage = "ID Is Required."; return(1); } EntityStates entityState = GetCompanyCodeState(item); if (entityState == EntityStates.Added && CompanyCodeExists(item.CompanyCodeID)) { errorMessage = "Item All Ready Exists."; return(1); } //check cached list for duplicates... int count = CompanyCodeList.Count(q => q.CompanyCodeID == item.CompanyCodeID); if (count > 1) { errorMessage = "Item All Ready Exists."; return(1); } //validate Description if (string.IsNullOrEmpty(item.Description)) { errorMessage = "Description Is Required."; return(1); } //a value of 2 is pending changes... //On Commit we will give it a value of 0... return(2); }
private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedCompanyCode.CompanyCodeID)) {//check to see if key is part of the current list... CompanyCode query = CompanyCodeList.Where(item => item.CompanyCodeID == SelectedCompanyCode.CompanyCodeID && item.AutoID != SelectedCompanyCode.AutoID).FirstOrDefault(); if (query != null) {//revert it back SelectedCompanyCode.CompanyCodeID = SelectedCompanyCodeMirror.CompanyCodeID; //change to the newly selected item... SelectedCompanyCode = query; return; } //it is not part of the existing list try to fetch it from the db... CompanyCodeList = GetCompanyCodeByID(SelectedCompanyCode.CompanyCodeID); if (CompanyCodeList.Count == 0)//it was not found do new record required logic... { NotifyNewRecordNeeded("Record " + SelectedCompanyCode.CompanyCodeID + " Does Not Exist. Create A New Record?"); } else { SelectedCompanyCode = CompanyCodeList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedCompanyCode.CompanyCodeID != SelectedCompanyCodeMirror.CompanyCodeID) { SelectedCompanyCode.CompanyCodeID = SelectedCompanyCodeMirror.CompanyCodeID; } } }
public void DeleteCompanyCodeCommand() { try { int i = 0; int ii = 0; for (int j = SelectedCompanyCodeList.Count - 1; j >= 0; j--) { CompanyCode item = (CompanyCode)SelectedCompanyCodeList[j]; //get Max Index... i = CompanyCodeList.IndexOf(item); if (i > ii) { ii = i; } Delete(item); CompanyCodeList.Remove(item); } if (CompanyCodeList != null && CompanyCodeList.Count > 0) { //back off one index from the max index... ii = ii - 1; //if they delete the first row... if (ii < 0) { ii = 0; } //make sure it does not exceed the list count... if (ii >= CompanyCodeList.Count()) { ii = CompanyCodeList.Count - 1; } SelectedCompanyCode = CompanyCodeList[ii]; //we will only enable committ for dirty validated records... if (Dirty == true) { AllowCommit = CommitIsAllowed(); } else { AllowCommit = false; } } else//only one record, deleting will result in no records... { SetAsEmptySelection(); } }//we try catch the item to delete as it may be used in another table as a key... //As well we will force a refresh to sqare up the UI after the botched delete... catch { NotifyMessage("CompanyCode/s Can Not Be Deleted. Contact XERP Admin For More Details."); Refresh(); } }
private void OnSearchResult(object sender, NotificationEventArgs <BindingList <CompanyCode> > e) { if (e.Data != null && e.Data.Count > 0) { CompanyCodeList = e.Data; SelectedCompanyCode = CompanyCodeList.FirstOrDefault(); Dirty = false; AllowCommit = false; } UnregisterToReceiveMessages <BindingList <CompanyCode> >(MessageTokens.CompanyCodeSearchToken.ToString(), OnSearchResult); }
private bool NewCompanyCode(string itemID) { CompanyCode newItem = new CompanyCode(); _newCompanyCodeAutoId = _newCompanyCodeAutoId - 1; newItem.AutoID = _newCompanyCodeAutoId; newItem.CompanyCodeID = itemID; newItem.IsValid = 1; newItem.NotValidMessage = "New Record Key Field/s Are Required."; CompanyCodeList.Add(newItem); _serviceAgent.AddToCompanyCodeRepository(newItem); SelectedCompanyCode = CompanyCodeList.LastOrDefault(); AllowEdit = true; Dirty = false; return(true); }
//Object.Property Scope Validation... private bool CompanyCodeIsValid(CompanyCode item, _itemValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _itemValidationProperties.CompanyCodeID: //validate key if (string.IsNullOrEmpty(item.CompanyCodeID)) { errorMessage = "ID Is Required."; return(false); } EntityStates entityState = GetCompanyCodeState(item); if (entityState == EntityStates.Added && CompanyCodeExists(item.CompanyCodeID)) { errorMessage = "Item All Ready Exists..."; return(false); } //check cached list for duplicates... int count = CompanyCodeList.Count(q => q.CompanyCodeID == item.CompanyCodeID); if (count > 1) { errorMessage = "Item All Ready Exists..."; return(false); } break; case _itemValidationProperties.Name: //validate Description if (string.IsNullOrEmpty(item.Description)) { errorMessage = "Description Is Required."; return(false); } break; } return(true); }
public void ClearLogic() { CompanyCodeList.Clear(); SetAsEmptySelection(); }