//WarehouseLocationCode Object Scope Validation check the entire object for validity... private byte WarehouseLocationCodeIsValid(WarehouseLocationCode item, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(item.WarehouseLocationCodeID)) { errorMessage = "ID Is Required."; return(1); } EntityStates entityState = GetWarehouseLocationCodeState(item); if (entityState == EntityStates.Added && WarehouseLocationCodeExists(item.WarehouseLocationCodeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item AllReady Exists."; return(1); } //check cached list for duplicates... int count = WarehouseLocationCodeList.Count(q => q.WarehouseLocationCodeID == item.WarehouseLocationCodeID); if (count > 1) { errorMessage = "Item AllReady 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); }
public IEnumerable <WarehouseLocationCode> GetWarehouseLocationCodes(WarehouseLocationCode itemCodeQuerryObject, string companyID) { _repositoryContext = new WarehouseEntities(_rootUri); _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.IgnoreResourceNotFoundException = true; var queryResult = from q in _repositoryContext.WarehouseLocationCodes where q.CompanyID == companyID select q; if (!string.IsNullOrEmpty(itemCodeQuerryObject.Code)) { queryResult = queryResult.Where(q => q.Code.StartsWith(itemCodeQuerryObject.Code.ToString())); } if (!string.IsNullOrEmpty(itemCodeQuerryObject.Description)) { queryResult = queryResult.Where(q => q.Description.StartsWith(itemCodeQuerryObject.Description.ToString())); } if (!string.IsNullOrEmpty(itemCodeQuerryObject.WarehouseLocationCodeID)) { queryResult = queryResult.Where(q => q.Description.StartsWith(itemCodeQuerryObject.WarehouseLocationCodeID.ToString())); } return(queryResult); }
private void Refresh() {//refetch current records... long selectedAutoID = SelectedWarehouseLocationCode.AutoID; string autoIDs = ""; //bool isFirstItem = true; foreach (WarehouseLocationCode itemCode in WarehouseLocationCodeList) {//auto seeded starts at 1 any records at 0 or less or not valid records... if (itemCode.AutoID > 0) { autoIDs = autoIDs + itemCode.AutoID.ToString() + ","; } } if (autoIDs.Length > 0) { //ditch the extra comma... autoIDs = autoIDs.Remove(autoIDs.Length - 1, 1); WarehouseLocationCodeList = new BindingList <WarehouseLocationCode>(_serviceAgent.RefreshWarehouseLocationCode(autoIDs).ToList()); SelectedWarehouseLocationCode = (from q in WarehouseLocationCodeList where q.AutoID == selectedAutoID select q).FirstOrDefault(); Dirty = false; AllowCommit = false; } }
private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedWarehouseLocationCode.WarehouseLocationCodeID)) {//check to see if key is part of the current companylist... WarehouseLocationCode query = WarehouseLocationCodeList.Where(company => company.WarehouseLocationCodeID == SelectedWarehouseLocationCode.WarehouseLocationCodeID && company.AutoID != SelectedWarehouseLocationCode.AutoID).FirstOrDefault(); if (query != null) {//revert it back... SelectedWarehouseLocationCode.WarehouseLocationCodeID = SelectedWarehouseLocationCodeMirror.WarehouseLocationCodeID; //change to the newly selected item... SelectedWarehouseLocationCode = query; return; } //it is not part of the existing list try to fetch it from the db... WarehouseLocationCodeList = GetWarehouseLocationCodeByID(SelectedWarehouseLocationCode.WarehouseLocationCodeID, XERP.Client.ClientSessionSingleton.Instance.CompanyID); if (WarehouseLocationCodeList.Count == 0)//it was not found do new record required logic... { NotifyNewRecordNeeded("Record " + SelectedWarehouseLocationCode.WarehouseLocationCodeID + " Does Not Exist. Create A New Record?"); } else { SelectedWarehouseLocationCode = WarehouseLocationCodeList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedWarehouseLocationCode.WarehouseLocationCodeID != SelectedWarehouseLocationCodeMirror.WarehouseLocationCodeID) { SelectedWarehouseLocationCode.WarehouseLocationCodeID = SelectedWarehouseLocationCodeMirror.WarehouseLocationCodeID; } } }
public void DeleteFromRepository(WarehouseLocationCode itemCode) { if (_repositoryContext.GetEntityDescriptor(itemCode) != null) {//if it exists in the db delete it from the db WarehouseEntities context = new WarehouseEntities(_rootUri); context.MergeOption = MergeOption.AppendOnly; context.IgnoreResourceNotFoundException = true; WarehouseLocationCode deletedWarehouseLocationCode = (from q in context.WarehouseLocationCodes where q.WarehouseLocationCodeID == itemCode.WarehouseLocationCodeID select q).FirstOrDefault(); if (deletedWarehouseLocationCode != null) { context.DeleteObject(deletedWarehouseLocationCode); context.SaveChanges(); } context = null; _repositoryContext.MergeOption = MergeOption.AppendOnly; //if it is being tracked remove it... if (GetWarehouseLocationCodeEntityState(itemCode) != EntityStates.Detached) { _repositoryContext.Detach(itemCode); } } }
public void DeleteWarehouseLocationCodeCommand() { try {//company is fk to 100's of tables deleting it can be tricky... int i = 0; int ii = 0; for (int j = SelectedWarehouseLocationCodeList.Count - 1; j >= 0; j--) { WarehouseLocationCode item = (WarehouseLocationCode)SelectedWarehouseLocationCodeList[j]; //get Max Index... i = WarehouseLocationCodeList.IndexOf(item); if (i > ii) { ii = i; } Delete(item); WarehouseLocationCodeList.Remove(item); } if (WarehouseLocationCodeList != null && WarehouseLocationCodeList.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 >= WarehouseLocationCodeList.Count()) { ii = WarehouseLocationCodeList.Count - 1; } SelectedWarehouseLocationCode = WarehouseLocationCodeList[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 company 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("WarehouseLocationCode/s Can Not Be Deleted. Contact XERP Admin For More Details."); Refresh(); } }
private BindingList <WarehouseLocationCode> GetWarehouseLocationCodes(WarehouseLocationCode itemCode, string companyID) { BindingList <WarehouseLocationCode> itemCodeList = new BindingList <WarehouseLocationCode>(_serviceAgent.GetWarehouseLocationCodes(itemCode, companyID).ToList()); Dirty = false; AllowCommit = false; return(itemCodeList); }
private void SetAsEmptySelection() { SelectedWarehouseLocationCode = new WarehouseLocationCode(); AllowEdit = false; AllowDelete = false; Dirty = false; AllowCommit = false; AllowRowCopy = false; }
public static void SetPropertyValue(this WarehouseLocationCode myObj, object propertyName, object propertyValue) { var propInfo = typeof(WarehouseLocationCode).GetProperty((string)propertyName); if (propInfo != null) { propInfo.SetValue(myObj, propertyValue, null); } }
public void UpdateRepository(WarehouseLocationCode itemCode) { if (_repositoryContext.GetEntityDescriptor(itemCode) != null) { itemCode.LastModifiedBy = XERP.Client.ClientSessionSingleton.Instance.SystemUserID; itemCode.LastModifiedByDate = DateTime.Now; _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.UpdateObject(itemCode); } }
public EntityStates GetWarehouseLocationCodeEntityState(WarehouseLocationCode itemCode) { if (_repositoryContext.GetEntityDescriptor(itemCode) != null) { return(_repositoryContext.GetEntityDescriptor(itemCode).State); } else { return(EntityStates.Detached); } }
private void OnSearchResult(object sender, NotificationEventArgs <BindingList <WarehouseLocationCode> > e) { if (e.Data != null && e.Data.Count > 0) { WarehouseLocationCodeList = e.Data; SelectedWarehouseLocationCode = WarehouseLocationCodeList.FirstOrDefault(); Dirty = false; AllowCommit = false; } UnregisterToReceiveMessages <BindingList <WarehouseLocationCode> >(MessageTokens.WarehouseLocationCodeSearchToken.ToString(), OnSearchResult); }
public void OnChangeWarehouseLocationTypes(WarehouseLocationCode warehouseCode, UpdateOperations operations) { if (operations == UpdateOperations.Delete) {//update a null to any place the Code was used by its parent record... XERP.Server.DAL.WarehouseDAL.DALUtility dalUtility = new DALUtility(); var context = new WarehouseEntities(dalUtility.EntityConectionString); context.WarehouseLocations.MergeOption = System.Data.Objects.MergeOption.NoTracking; string companyID = warehouseCode.CompanyID; string codeID = warehouseCode.WarehouseLocationCodeID; string sqlstring = "UPDATE WarehouseLocations SET WarehouseLocationCodeID = null WHERE CompanyID = '" + companyID + "' and WarehouseLocationCodeID = '" + codeID + "'"; context.ExecuteStoreCommand(sqlstring); } }
public static object GetPropertyValue(this WarehouseLocationCode myObj, string propertyName) { var propInfo = typeof(WarehouseLocationCode).GetProperty(propertyName); if (propInfo != null) { return(propInfo.GetValue(myObj, null)); } else { return(string.Empty); } }
public static string GetPropertyCode(this WarehouseLocationCode myObj, string propertyName) { var propInfo = typeof(WarehouseLocationCode).GetProperty(propertyName); if (propInfo != null) { return(propInfo.PropertyType.Name.ToString()); } else { return(null); } }
//udpate merely updates the repository a commit is required //to commit it to the db... private bool Update(WarehouseLocationCode item) { _serviceAgent.UpdateWarehouseLocationCodeRepository(item); Dirty = true; if (CommitIsAllowed()) { AllowCommit = true; } else { AllowCommit = false; } return(AllowCommit); }
public CodeSearchViewModel(IWarehouseServiceAgent serviceAgent) { this._serviceAgent = serviceAgent; SearchObject = new WarehouseLocationCode(); ResultList = new BindingList <WarehouseLocationCode>(); SelectedList = new BindingList <WarehouseLocationCode>(); //make sure of session authentication... if (XERP.Client.ClientSessionSingleton.Instance.SessionIsAuthentic)//make sure user has rights to UI... { DoFormsAuthentication(); } else {//User is not authenticated... RegisterToReceiveMessages <bool>(MessageTokens.StartUpLogInToken.ToString(), OnStartUpLogIn); FormIsEnabled = false; //we will do forms authentication once the log in returns a valid System User... } }
//Object.Property Scope Validation... private bool WarehouseLocationCodeIsValid(WarehouseLocationCode item, _companyValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _companyValidationProperties.WarehouseLocationCodeID: //validate key if (string.IsNullOrEmpty(item.WarehouseLocationCodeID)) { errorMessage = "ID Is Required."; return(false); } EntityStates entityState = GetWarehouseLocationCodeState(item); if (entityState == EntityStates.Added && WarehouseLocationCodeExists(item.WarehouseLocationCodeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists..."; return(false); } //check cached list for duplicates... int count = WarehouseLocationCodeList.Count(q => q.WarehouseLocationCodeID == item.WarehouseLocationCodeID); if (count > 1) { errorMessage = "Item All Ready Exists..."; return(false); } break; case _companyValidationProperties.Name: //validate Description if (string.IsNullOrEmpty(item.Description)) { errorMessage = "Description Is Required."; return(false); } break; } return(true); }
private bool NewWarehouseLocationCode(string id) { WarehouseLocationCode item = new WarehouseLocationCode(); //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... _newWarehouseLocationCodeAutoId = _newWarehouseLocationCodeAutoId - 1; item.AutoID = _newWarehouseLocationCodeAutoId; item.WarehouseLocationCodeID = id; item.CompanyID = ClientSessionSingleton.Instance.CompanyID; item.IsValid = 1; item.NotValidMessage = "New Record Key Field/s Are Required."; WarehouseLocationCodeList.Add(item); _serviceAgent.AddToWarehouseLocationCodeRepository(item); SelectedWarehouseLocationCode = WarehouseLocationCodeList.LastOrDefault(); AllowEdit = true; Dirty = false; return(true); }
public EntityStates GetWarehouseLocationCodeEntityState(WarehouseLocationCode itemCode) { return(WarehouseLocationCodeSingletonRepository.Instance.GetWarehouseLocationCodeEntityState(itemCode)); }
private bool Delete(WarehouseLocationCode itemCode) { _serviceAgent.DeleteFromWarehouseLocationCodeRepository(itemCode); return(true); }
private BindingList <WarehouseLocationCode> GetWarehouseLocationCodes(WarehouseLocationCode itemQueryObject, string companyID) { return(new BindingList <WarehouseLocationCode>(_serviceAgent.GetWarehouseLocationCodes(itemQueryObject, companyID).ToList())); }
public void DeleteFromWarehouseLocationCodeRepository(WarehouseLocationCode itemCode) { WarehouseLocationCodeSingletonRepository.Instance.DeleteFromRepository(itemCode); }
public void AddToRepository(WarehouseLocationCode itemCode) { _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.AddToWarehouseLocationCodes(itemCode); }
public void UpdateWarehouseLocationCodeRepository(WarehouseLocationCode itemCode) { WarehouseLocationCodeSingletonRepository.Instance.UpdateRepository(itemCode); }
private EntityStates GetWarehouseLocationCodeState(WarehouseLocationCode itemCode) { return(_serviceAgent.GetWarehouseLocationCodeEntityState(itemCode)); }
public IEnumerable <WarehouseLocationCode> GetWarehouseLocationCodes(WarehouseLocationCode itemCodeQuerryObject, string companyID) { return(WarehouseLocationCodeSingletonRepository.Instance.GetWarehouseLocationCodes(itemCodeQuerryObject, companyID)); }
public void AddToWarehouseLocationCodeRepository(WarehouseLocationCode itemCode) { WarehouseLocationCodeSingletonRepository.Instance.AddToRepository(itemCode); }