//UdList Object Scope Validation check the entire object for validity... private byte UdListIsValid(UdList udList, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(udList.UdListID)) { errorMessage = "ID Is Required."; return(1); } EntityStates entityState = GetUdListState(udList); if (entityState == EntityStates.Added && UdListExists(udList.UdListID)) { errorMessage = "Item All Ready Exists."; return(1); } //check cached list for duplicates... int count = UdListList.Count(q => q.UdListID == udList.UdListID); if (count > 1) { errorMessage = "Item All Ready Exists."; return(1); } //validate Description if (string.IsNullOrEmpty(udList.Name)) { errorMessage = "Name Is Required."; return(1); } return(2); }
//UdList Object Scope Validation validate entire object... private byte UdListItemIsValid(UdListItem udListItem, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(udListItem.UdListItemID)) { errorMessage = "ID Is Required."; return(1); } var count = UdListList. Where(q => q.UdListID == udListItem.UdListID).Single(). UdListItems. Where(x => x.UdListItemID == udListItem.UdListItemID).Count(); if (count > 1) { errorMessage = "UdListItem ID " + udListItem.UdListItemID + " Allready Exists..."; return(1); } if (UdListItemExists(udListItem.UdListID, udListItem.UdListItemID.ToString(), (int)udListItem.AutoID)) { errorMessage = "UdListItem ID " + udListItem.UdListItemID + " Allready Exists..."; return(1); } //validate Description if (string.IsNullOrEmpty(udListItem.Description)) { errorMessage = "Description Is Required."; return(1); } return(0); }
public void DeleteUdListCommand() { int i = 0; int ii = 0; for (int j = SelectedUdListList.Count - 1; j >= 0; j--) { UdList udList = (UdList)SelectedUdListList[j]; //get Max Index... i = UdListList.IndexOf(udList); if (i > ii) { ii = i; } Delete(udList); UdListList.Remove(udList); } if (UdListList != null && UdListList.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 >= UdListList.Count()) { ii = UdListList.Count - 1; } SelectedUdList = UdListList[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(); } }
public void DeleteUdListItemCommand() { int i = 0; //temp index int ii = 0; //calculated index for (int j = SelectedUdListItemList.Count - 1; j >= 0; j--) { UdListItem udListItem = (UdListItem)SelectedUdListItemList[j]; //get Max Index... i = SelectedUdList.UdListItems.IndexOf(udListItem); if (i > ii) { ii = i; } Delete(udListItem); UdListList.Where(q => q.AutoID == SelectedUdList.AutoID).FirstOrDefault().UdListItems.Remove(udListItem); } if (UdListList != null && SelectedUdList != null && SelectedUdList.UdListItems.Count > 0) { //back off one index from the max index... ii = ii - 1; //if they delete the first row... if (ii < 0) { ii = 0; } //need some work on this... //make sure it does not exceed the list count... if (ii >= SelectedUdList.UdListItems.Count) { ii = SelectedUdList.UdListItems.Count - 1; } //only allow commit for dirty validated records... SelectedUdListItem = SelectedUdList.UdListItems[ii]; if (Dirty) { AllowCommit = CommitIsAllowed(); } else { AllowCommit = false; } } else//only one record, deleting will result in no records... { SetAsEmptySelection(); } }
private void OnSearchResult(object sender, NotificationEventArgs <BindingList <UdList> > e) { if (e.Data != null && e.Data.Count > 0) { UdListList = e.Data; SelectedUdList = UdListList.FirstOrDefault(); if (SelectedUdList.UdListItems.Count > 0) { SelectedUdListItem = SelectedUdList.UdListItems[0]; } Dirty = false; AllowCommit = false; } UnregisterToReceiveMessages <BindingList <UdList> >(MessageTokens.UdListSearchToken.ToString(), OnSearchResult); }
private bool NewUdListItem(string udListItemID) { UdListItem udListItem = new UdListItem(); _newUdListItemAutoId = _newUdListItemAutoId - 1; udListItem.AutoID = _newUdListItemAutoId; udListItem.UdListID = SelectedUdList.UdListID; udListItem.UdListItemID = udListItemID; udListItem.IsValid = 1; udListItem.NotValidMessage = "New Record Key Field/s Required."; udListItem.CompanyID = ClientSessionSingleton.Instance.CompanyID; UdListList.Where(q => q.AutoID == SelectedUdList.AutoID).FirstOrDefault().UdListItems.Add(udListItem); _serviceAgent.AddToUdListRepository(udListItem); SelectedUdListItem = SelectedUdList.UdListItems.LastOrDefault(); AllowEditUdListItem = true; return(true); }
//UdListItem Object.Property Scope Validation... private bool UdListItemIsValid(UdListItem udListItem, _udListItemValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _udListItemValidationProperties.UdListItemID: //validate key if (string.IsNullOrEmpty(udListItem.UdListItemID)) { errorMessage = "ID Is Required."; return(false); } var count = UdListList. Where(q => q.UdListID == udListItem.UdListID).Single(). UdListItems. Where(x => x.UdListItemID == udListItem.UdListItemID).Count(); if (count > 1) { errorMessage = "UdListItem ID " + udListItem.UdListItemID + " Allready Exists..."; return(false); } if (UdListItemExists(udListItem.UdListID, udListItem.UdListItemID.ToString(), (int)udListItem.AutoID)) { errorMessage = "UdListItem ID " + udListItem.UdListItemID + " Allready Exists..."; return(false); } break; case _udListItemValidationProperties.Description: //validate Description if (string.IsNullOrEmpty(udListItem.Description)) { errorMessage = "Description Is Required."; return(false); } break; } return(true); }
//Object.Property Scope Validation... private bool UdListIsValid(UdList udList, _udListValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _udListValidationProperties.UdListID: //validate key if (string.IsNullOrEmpty(udList.UdListID)) { errorMessage = "ID Is Required."; return(false); } EntityStates entityState = GetUdListState(udList); if (entityState == EntityStates.Added && UdListExists(udList.UdListID)) { errorMessage = "Item All Ready Exists..."; return(false); } //check cached list for duplicates... int count = UdListList.Count(q => q.UdListID == udList.UdListID); if (count > 1) { errorMessage = "Item All Ready Exists..."; return(false); } break; case _udListValidationProperties.Name: //validate Description if (string.IsNullOrEmpty(udList.Name)) { errorMessage = "Description Is Required."; return(false); } break; } return(true); }
private bool NewUdList(string udListID) { UdList udList = new UdList(); //all new records will be give a negative int autoid... //when they are updated then sql will generate one for them overiding this set value... //it will allow us to give uniqueness to the tempory new records... //Before they are updated to the entity and given an autoid... //we use a negative number and keep subtracting by 1 for each new item added... //This will allow it to alwasy be unique and never interfere with SQL's positive autoid... _newUdListAutoId = _newUdListAutoId - 1; udList.AutoID = _newUdListAutoId; udList.UdListID = udListID; udList.CompanyID = ClientSessionSingleton.Instance.CompanyID; udList.IsValid = 1; udList.NotValidMessage = "New Record Key Field/s Are Required."; UdListList.Add(udList); _serviceAgent.AddToUdListRepository(udList); SelectedUdList = UdListList.LastOrDefault(); AllowEdit = true; Dirty = false; return(true); }
private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedUdList.UdListID)) { //check to see if key is part of the current udListlist... UdList query = UdListList.Where(udList => udList.UdListID == SelectedUdList.UdListID && udList.AutoID != SelectedUdList.AutoID).FirstOrDefault(); if (query != null) {//change to the newly selected udList... //before navigating to the newly selected client cached record revert the old one back to what it was... SelectedUdList.UdListID = SelectedUdListMirror.UdListID; SelectedUdList = query; return; } //it is not part of the existing list try to fetch it from the db... UdListList = GetUdListByID(SelectedUdList.UdListID, ClientSessionSingleton.Instance.CompanyID); if (UdListList.Count == 0) {//it was not found do new record required logic... NotifyNewRecordNeeded("Record " + SelectedUdList.UdListID + " Does Not Exist. Create A New Record?"); } else { SelectedUdList = UdListList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedUdList.UdListID != SelectedUdListMirror.UdListID) { SelectedUdList.UdListID = SelectedUdListMirror.UdListID; } } }
public void ClearLogic() { UdListList.Clear(); SetAsEmptySelection(); SetAsEmptyItemSelection(); }