private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedSystemUserCode.SystemUserCodeID)) {//check to see if key is part of the current companylist... SystemUserCode query = SystemUserCodeList.Where(company => company.SystemUserCodeID == SelectedSystemUserCode.SystemUserCodeID && company.AutoID != SelectedSystemUserCode.AutoID).FirstOrDefault(); if (query != null) {//revert it back... SelectedSystemUserCode.SystemUserCodeID = SelectedSystemUserCodeMirror.SystemUserCodeID; //change to the newly selected item... SelectedSystemUserCode = query; return; } //it is not part of the existing list try to fetch it from the db... SystemUserCodeList = GetSystemUserCodeByID(SelectedSystemUserCode.SystemUserCodeID, XERP.Client.ClientSessionSingleton.Instance.CompanyID); if (SystemUserCodeList.Count == 0)//it was not found do new record required logic... { NotifyNewRecordNeeded("Record " + SelectedSystemUserCode.SystemUserCodeID + " Does Not Exist. Create A New Record?"); } else { SelectedSystemUserCode = SystemUserCodeList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedSystemUserCode.SystemUserCodeID != SelectedSystemUserCodeMirror.SystemUserCodeID) { SelectedSystemUserCode.SystemUserCodeID = SelectedSystemUserCodeMirror.SystemUserCodeID; } } }
public IQueryable <Temp> GetMetaData(string tableName) { switch (tableName) { case "SystemUsers": SystemUser item = new SystemUser(); return(item.GetMetaData().AsQueryable()); case "SystemUserTypes": SystemUserType itemType = new SystemUserType(); return(itemType.GetMetaData().AsQueryable()); case "SystemUserCodes": SystemUserCode itemCode = new SystemUserCode(); return(itemCode.GetMetaData().AsQueryable()); default: //no table exists for the given tablename given... List <Temp> tempList = new List <Temp>(); Temp temp = new Temp(); temp.ID = 0; temp.Int_1 = 0; temp.Bool_1 = true; //bool_1 will flag it as an error... temp.Name = "Error"; temp.ShortChar_1 = "Table " + tableName + " Is Not A Valid Table Within The Given Entity Collection, Or Meta Data Was Not Defined For The Given Table Name"; tempList.Add(temp); return(tempList.AsQueryable()); } }
public void DeleteFromRepository(SystemUserCode itemCode) { if (_repositoryContext.GetEntityDescriptor(itemCode) != null) {//if it exists in the db delete it from the db SystemUserEntities context = new SystemUserEntities(_rootUri); context.MergeOption = MergeOption.AppendOnly; context.IgnoreResourceNotFoundException = true; SystemUserCode deletedSystemUserCode = (from q in context.SystemUserCodes where q.SystemUserCodeID == itemCode.SystemUserCodeID select q).FirstOrDefault(); if (deletedSystemUserCode != null) { context.DeleteObject(deletedSystemUserCode); context.SaveChanges(); } context = null; _repositoryContext.MergeOption = MergeOption.AppendOnly; //if it is being tracked remove it... if (GetSystemUserCodeEntityState(itemCode) != EntityStates.Detached) { _repositoryContext.Detach(itemCode); } } }
public IEnumerable <SystemUserCode> GetSystemUserCodes(SystemUserCode itemCodeQuerryObject) { _repositoryContext = new SystemUserEntities(_rootUri); _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.IgnoreResourceNotFoundException = true; var queryResult = from q in _repositoryContext.SystemUserCodes 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.SystemUserCodeID)) { queryResult = queryResult.Where(q => q.Description.StartsWith(itemCodeQuerryObject.SystemUserCodeID.ToString())); } return(queryResult); }
//SystemUserCode Object Scope Validation check the entire object for validity... private byte SystemUserCodeIsValid(SystemUserCode item, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(item.SystemUserCodeID)) { errorMessage = "ID Is Required."; return(1); } EntityStates entityState = GetSystemUserCodeState(item); if (entityState == EntityStates.Added && SystemUserCodeExists(item.SystemUserCodeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists."; return(1); } //check cached list for duplicates... int count = SystemUserCodeList.Count(q => q.SystemUserCodeID == item.SystemUserCodeID); 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); }
//All senior tables(Companies, Parts, Orders, ect...) tend to have a generic table called TableNameCodes //i.e. SystemUserCodes PartCodes, OrderCodes... //So this will constitute the meta data for that Code table... //Xerp attempts to use generic naming where possible to allow for cloning... public static List <Temp> GetMetaData(this SystemUserCode entityObject) { XERP.Server.DAL.SystemUserDAL.DALUtility dalUtility = new DALUtility(); List <Temp> tempList = new List <Temp>(); int id = 0; using (SystemUserEntities ctx = new SystemUserEntities(dalUtility.EntityConectionString)) { var c = ctx.SystemUserCodes.FirstOrDefault(); var queryResults = from meta in ctx.MetadataWorkspace.GetItems(DataSpace.CSpace) .Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType) from query in (meta as EntityType).Properties .Where(p => p.DeclaringType.Name == entityObject.GetType().Name) select query; if (queryResults.Count() > 0) { foreach (var queryResult in queryResults.ToList()) { Temp temp = new Temp(); temp.ID = id; temp.Name = queryResult.Name.ToString(); temp.ShortChar_1 = queryResult.TypeUsage.EdmType.Name; if (queryResult.TypeUsage.EdmType.Name == "String") { temp.Int_1 = Convert.ToInt32(queryResult.TypeUsage.Facets["MaxLength"].Value); } temp.Bool_1 = false; //we use this as a error trigger false = not an error... tempList.Add(temp); id++; } } } return(tempList); }
public void DeleteSystemUserCodeCommand() { try {//company is fk to 100's of tables deleting it can be tricky... int i = 0; int ii = 0; for (int j = SelectedSystemUserCodeList.Count - 1; j >= 0; j--) { SystemUserCode item = (SystemUserCode)SelectedSystemUserCodeList[j]; //get Max Index... i = SystemUserCodeList.IndexOf(item); if (i > ii) { ii = i; } Delete(item); SystemUserCodeList.Remove(item); } if (SystemUserCodeList != null && SystemUserCodeList.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 >= SystemUserCodeList.Count()) { ii = SystemUserCodeList.Count - 1; } SelectedSystemUserCode = SystemUserCodeList[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("SystemUserCode/s Can Not Be Deleted. Contact XERP Admin For More Details."); Refresh(); } }
private BindingList <SystemUserCode> GetSystemUserCodes(SystemUserCode itemCode, string companyID) { BindingList <SystemUserCode> itemCodeList = new BindingList <SystemUserCode>(_serviceAgent.GetSystemUserCodes(itemCode).ToList()); Dirty = false; AllowCommit = false; return(itemCodeList); }
public static void SetPropertyValue(this SystemUserCode myObj, object propertyName, object propertyValue) { var propInfo = typeof(SystemUserCode).GetProperty((string)propertyName); if (propInfo != null) { propInfo.SetValue(myObj, propertyValue, null); } }
private void SetAsEmptySelection() { SelectedSystemUserCode = new SystemUserCode(); AllowEdit = false; AllowDelete = false; Dirty = false; AllowCommit = false; AllowRowCopy = false; }
public void UpdateRepository(SystemUserCode 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 GetSystemUserCodeEntityState(SystemUserCode itemCode) { if (_repositoryContext.GetEntityDescriptor(itemCode) != null) { return(_repositoryContext.GetEntityDescriptor(itemCode).State); } else { return(EntityStates.Detached); } }
public void OnChangeSystemUserCodes(SystemUserCode itemCode, UpdateOperations operations) { if (operations == UpdateOperations.Delete) {//update a null to any place the Code was used by its parent record... XERP.Server.DAL.SystemUserDAL.DALUtility dalUtility = new DALUtility(); var context = new SystemUserEntities(dalUtility.EntityConectionString); context.SystemUsers.MergeOption = System.Data.Objects.MergeOption.NoTracking; string codeID = itemCode.SystemUserCodeID; string sqlstring = "UPDATE SystemUsers SET SystemUserCodeID = null Where SystemUserCodeID = '" + codeID + "'"; context.ExecuteStoreCommand(sqlstring); } }
public static string GetPropertyCode(this SystemUserCode myObj, string propertyName) { var propInfo = typeof(SystemUserCode).GetProperty(propertyName); if (propInfo != null) { return(propInfo.PropertyType.Name.ToString()); } else { return(null); } }
public static object GetPropertyValue(this SystemUserCode myObj, string propertyName) { var propInfo = typeof(SystemUserCode).GetProperty(propertyName); if (propInfo != null) { return(propInfo.GetValue(myObj, null)); } else { return(string.Empty); } }
//udpate merely updates the repository a commit is required //to commit it to the db... private bool Update(SystemUserCode item) { _serviceAgent.UpdateSystemUserCodeRepository(item); Dirty = true; if (CommitIsAllowed()) { AllowCommit = true; } else { AllowCommit = false; } return(AllowCommit); }
public CodeSearchViewModel(ISystemUserServiceAgent serviceAgent) { this._serviceAgent = serviceAgent; SearchObject = new SystemUserCode(); ResultList = new BindingList <SystemUserCode>(); SelectedList = new BindingList <SystemUserCode>(); //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 SystemUserCodeIsValid(SystemUserCode item, _companyValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _companyValidationProperties.SystemUserCodeID: //validate key if (string.IsNullOrEmpty(item.SystemUserCodeID)) { errorMessage = "ID Is Required."; return(false); } EntityStates entityState = GetSystemUserCodeState(item); if (entityState == EntityStates.Added && SystemUserCodeExists(item.SystemUserCodeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists..."; return(false); } //check cached list for duplicates... int count = SystemUserCodeList.Count(q => q.SystemUserCodeID == item.SystemUserCodeID); 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 NewSystemUserCode(string id) { SystemUserCode item = new SystemUserCode(); //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... _newSystemUserCodeAutoId = _newSystemUserCodeAutoId - 1; item.AutoID = _newSystemUserCodeAutoId; item.SystemUserCodeID = id; item.IsValid = 1; item.NotValidMessage = "New Record Key Field/s Are Required."; SystemUserCodeList.Add(item); _serviceAgent.AddToSystemUserCodeRepository(item); SelectedSystemUserCode = SystemUserCodeList.LastOrDefault(); AllowEdit = true; Dirty = false; return(true); }
public IQueryable <Temp> GetMetaData(string tableName) { switch (tableName) { case "SystemUsers": SystemUser systemUser = new SystemUser(); return(systemUser.GetMetaData().AsQueryable()); case "SystemUsersTypes": SystemUserType systemUserTypes = new SystemUserType(); return(systemUserTypes.GetMetaData().AsQueryable()); case "SystemUserCodes": SystemUserCode systemUserCode = new SystemUserCode(); return(systemUserCode.GetMetaData().AsQueryable()); case "SystemUserSecurities": SystemUserSecurity systemUserSecurity = new SystemUserSecurity(); return(systemUserSecurity.GetMetaData().AsQueryable()); case "SecurityGroups": SecurityGroup securityGroup = new SecurityGroup(); return(securityGroup.GetMetaData().AsQueryable()); default: //no table exists for the given tablename given... List <Temp> tempList = new List <Temp>(); Temp temp = new Temp(); temp.ID = 0; temp.Int_1 = 0; temp.Bool_1 = true; //bool_1 will flag it as an error... temp.Name = "Error"; temp.ShortChar_1 = "Table " + tableName + " Is Not A Valid Table Within The Given Entity Collection, Or Meta Data Is Not Publc For The Given Table Name"; tempList.Add(temp); return(tempList.AsQueryable()); } }
public EntityStates GetSystemUserCodeEntityState(SystemUserCode itemCode) { return(SystemUserCodeSingletonRepository.Instance.GetSystemUserCodeEntityState(itemCode)); }
public void DeleteFromSystemUserCodeRepository(SystemUserCode itemCode) { SystemUserCodeSingletonRepository.Instance.DeleteFromRepository(itemCode); }
public void AddToSystemUserCodeRepository(SystemUserCode itemCode) { SystemUserCodeSingletonRepository.Instance.AddToRepository(itemCode); }
public void UpdateSystemUserCodeRepository(SystemUserCode itemCode) { SystemUserCodeSingletonRepository.Instance.UpdateRepository(itemCode); }
public IEnumerable <SystemUserCode> GetSystemUserCodes(SystemUserCode itemCodeQuerryObject) { return(SystemUserCodeSingletonRepository.Instance.GetSystemUserCodes(itemCodeQuerryObject)); }
private BindingList <SystemUserCode> GetSystemUserCodes(SystemUserCode itemQueryObject, string companyID) { return(new BindingList <SystemUserCode>(_serviceAgent.GetSystemUserCodes(itemQueryObject).ToList())); }
private EntityStates GetSystemUserCodeState(SystemUserCode itemCode) { return(_serviceAgent.GetSystemUserCodeEntityState(itemCode)); }
public void AddToRepository(SystemUserCode itemCode) { _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.AddToSystemUserCodes(itemCode); }
private bool Delete(SystemUserCode itemCode) { _serviceAgent.DeleteFromSystemUserCodeRepository(itemCode); return(true); }