private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedSecurityGroupCode.SecurityGroupCodeID)) {//check to see if key is part of the current companylist... SecurityGroupCode query = SecurityGroupCodeList.Where(company => company.SecurityGroupCodeID == SelectedSecurityGroupCode.SecurityGroupCodeID && company.AutoID != SelectedSecurityGroupCode.AutoID).FirstOrDefault(); if (query != null) {//revert it back... SelectedSecurityGroupCode.SecurityGroupCodeID = SelectedSecurityGroupCodeMirror.SecurityGroupCodeID; //change to the newly selected item... SelectedSecurityGroupCode = query; return; } //it is not part of the existing list try to fetch it from the db... SecurityGroupCodeList = GetSecurityGroupCodeByID(SelectedSecurityGroupCode.SecurityGroupCodeID, XERP.Client.ClientSessionSingleton.Instance.CompanyID); if (SecurityGroupCodeList.Count == 0)//it was not found do new record required logic... { NotifyNewRecordNeeded("Record " + SelectedSecurityGroupCode.SecurityGroupCodeID + " Does Not Exist. Create A New Record?"); } else { SelectedSecurityGroupCode = SecurityGroupCodeList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedSecurityGroupCode.SecurityGroupCodeID != SelectedSecurityGroupCodeMirror.SecurityGroupCodeID) { SelectedSecurityGroupCode.SecurityGroupCodeID = SelectedSecurityGroupCodeMirror.SecurityGroupCodeID; } } }
public IQueryable <Temp> GetMetaData(string tableName) { switch (tableName) { case "SecurityGroups": SecurityGroup SecurityGroup = new SecurityGroup(); return(SecurityGroup.GetMetaData().AsQueryable()); case "SecurityGroupTypes": SecurityGroupType SecurityGroupType = new SecurityGroupType(); return(SecurityGroupType.GetMetaData().AsQueryable()); case "SecurityGroupCodes": SecurityGroupCode SecurityGroupCode = new SecurityGroupCode(); return(SecurityGroupCode.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 IEnumerable <SecurityGroupCode> GetSecurityGroupCodes(SecurityGroupCode itemCodeQuerryObject, string companyID) { _repositoryContext = new SecurityGroupEntities(_rootUri); _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.IgnoreResourceNotFoundException = true; var queryResult = from q in _repositoryContext.SecurityGroupCodes 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.SecurityGroupCodeID)) { queryResult = queryResult.Where(q => q.Description.StartsWith(itemCodeQuerryObject.SecurityGroupCodeID.ToString())); } return(queryResult); }
public void DeleteFromRepository(SecurityGroupCode itemCode) { if (_repositoryContext.GetEntityDescriptor(itemCode) != null) {//if it exists in the db delete it from the db SecurityGroupEntities context = new SecurityGroupEntities(_rootUri); context.MergeOption = MergeOption.AppendOnly; context.IgnoreResourceNotFoundException = true; SecurityGroupCode deletedSecurityGroupCode = (from q in context.SecurityGroupCodes where q.SecurityGroupCodeID == itemCode.SecurityGroupCodeID select q).FirstOrDefault(); if (deletedSecurityGroupCode != null) { context.DeleteObject(deletedSecurityGroupCode); context.SaveChanges(); } context = null; _repositoryContext.MergeOption = MergeOption.AppendOnly; //if it is being tracked remove it... if (GetSecurityGroupCodeEntityState(itemCode) != EntityStates.Detached) { _repositoryContext.Detach(itemCode); } } }
public static List <Temp> GetMetaData(this SecurityGroupCode entityObject) { XERP.Server.DAL.SecurityGroupDAL.DALUtility dalUtility = new DALUtility(); List <Temp> tempList = new List <Temp>(); int id = 0; using (SecurityGroupEntities ctx = new SecurityGroupEntities(dalUtility.EntityConectionString)) { var c = ctx.SecurityGroupCodes.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); }
//SecurityGroupCode Object Scope Validation check the entire object for validity... private byte SecurityGroupCodeIsValid(SecurityGroupCode item, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(item.SecurityGroupCodeID)) { errorMessage = "ID Is Required."; return(1); } EntityStates entityState = GetSecurityGroupCodeState(item); if (entityState == EntityStates.Added && SecurityGroupCodeExists(item.SecurityGroupCodeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item AllReady Exists."; return(1); } //check cached list for duplicates... int count = SecurityGroupCodeList.Count(q => q.SecurityGroupCodeID == item.SecurityGroupCodeID); 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); }
private void Refresh() {//refetch current records... long selectedAutoID = SelectedSecurityGroupCode.AutoID; string autoIDs = ""; //bool isFirstItem = true; foreach (SecurityGroupCode itemCode in SecurityGroupCodeList) {//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); SecurityGroupCodeList = new BindingList <SecurityGroupCode>(_serviceAgent.RefreshSecurityGroupCode(autoIDs).ToList()); SelectedSecurityGroupCode = (from q in SecurityGroupCodeList where q.AutoID == selectedAutoID select q).FirstOrDefault(); Dirty = false; AllowCommit = false; } }
public void DeleteSecurityGroupCodeCommand() { try {//company is fk to 100's of tables deleting it can be tricky... int i = 0; int ii = 0; for (int j = SelectedSecurityGroupCodeList.Count - 1; j >= 0; j--) { SecurityGroupCode item = (SecurityGroupCode)SelectedSecurityGroupCodeList[j]; //get Max Index... i = SecurityGroupCodeList.IndexOf(item); if (i > ii) { ii = i; } Delete(item); SecurityGroupCodeList.Remove(item); } if (SecurityGroupCodeList != null && SecurityGroupCodeList.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 >= SecurityGroupCodeList.Count()) { ii = SecurityGroupCodeList.Count - 1; } SelectedSecurityGroupCode = SecurityGroupCodeList[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("SecurityGroupCode/s Can Not Be Deleted. Contact XERP Admin For More Details."); Refresh(); } }
private BindingList <SecurityGroupCode> GetSecurityGroupCodes(SecurityGroupCode itemCode, string companyID) { BindingList <SecurityGroupCode> itemCodeList = new BindingList <SecurityGroupCode>(_serviceAgent.GetSecurityGroupCodes(itemCode, companyID).ToList()); Dirty = false; AllowCommit = false; return(itemCodeList); }
public static void SetPropertyValue(this SecurityGroupCode myObj, object propertyName, object propertyValue) { var propInfo = typeof(SecurityGroupCode).GetProperty((string)propertyName); if (propInfo != null) { propInfo.SetValue(myObj, propertyValue, null); } }
private void SetAsEmptySelection() { SelectedSecurityGroupCode = new SecurityGroupCode(); AllowEdit = false; AllowDelete = false; Dirty = false; AllowCommit = false; AllowRowCopy = false; }
public void UpdateRepository(SecurityGroupCode 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 GetSecurityGroupCodeEntityState(SecurityGroupCode itemCode) { if (_repositoryContext.GetEntityDescriptor(itemCode) != null) { return(_repositoryContext.GetEntityDescriptor(itemCode).State); } else { return(EntityStates.Detached); } }
private void OnSearchResult(object sender, NotificationEventArgs <BindingList <SecurityGroupCode> > e) { if (e.Data != null && e.Data.Count > 0) { SecurityGroupCodeList = e.Data; SelectedSecurityGroupCode = SecurityGroupCodeList.FirstOrDefault(); Dirty = false; AllowCommit = false; } UnregisterToReceiveMessages <BindingList <SecurityGroupCode> >(MessageTokens.SecurityGroupCodeSearchToken.ToString(), OnSearchResult); }
public void OnChangeSecurityGroupTypes(SecurityGroupCode securityGroupCode, UpdateOperations operations) { if (operations == UpdateOperations.Delete) {//update a null to any place the Code was used by its parent record... XERP.Server.DAL.SecurityGroupDAL.DALUtility dalUtility = new DALUtility(); var context = new SecurityGroupEntities(dalUtility.EntityConectionString); context.SecurityGroups.MergeOption = System.Data.Objects.MergeOption.NoTracking; string companyID = securityGroupCode.CompanyID; string codeID = securityGroupCode.SecurityGroupCodeID; string sqlstring = "UPDATE SecurityGroups SET SecurityGroupCodeID = null WHERE CompanyID = '" + companyID + "' and SecurityGroupCodeID = '" + codeID + "'"; context.ExecuteStoreCommand(sqlstring); } }
public static string GetPropertyCode(this SecurityGroupCode myObj, string propertyName) { var propInfo = typeof(SecurityGroupCode).GetProperty(propertyName); if (propInfo != null) { return(propInfo.PropertyType.Name.ToString()); } else { return(null); } }
public static object GetPropertyValue(this SecurityGroupCode myObj, string propertyName) { var propInfo = typeof(SecurityGroupCode).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(SecurityGroupCode item) { _serviceAgent.UpdateSecurityGroupCodeRepository(item); Dirty = true; if (CommitIsAllowed()) { AllowCommit = true; } else { AllowCommit = false; } return(AllowCommit); }
public CodeSearchViewModel(ISecurityGroupServiceAgent serviceAgent) { this._serviceAgent = serviceAgent; SearchObject = new SecurityGroupCode(); ResultList = new BindingList <SecurityGroupCode>(); SelectedList = new BindingList <SecurityGroupCode>(); //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 SecurityGroupCodeIsValid(SecurityGroupCode item, _companyValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _companyValidationProperties.SecurityGroupCodeID: //validate key if (string.IsNullOrEmpty(item.SecurityGroupCodeID)) { errorMessage = "ID Is Required."; return(false); } EntityStates entityState = GetSecurityGroupCodeState(item); if (entityState == EntityStates.Added && SecurityGroupCodeExists(item.SecurityGroupCodeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists..."; return(false); } //check cached list for duplicates... int count = SecurityGroupCodeList.Count(q => q.SecurityGroupCodeID == item.SecurityGroupCodeID); 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 NewSecurityGroupCode(string id) { SecurityGroupCode item = new SecurityGroupCode(); //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... _newSecurityGroupCodeAutoId = _newSecurityGroupCodeAutoId - 1; item.AutoID = _newSecurityGroupCodeAutoId; item.SecurityGroupCodeID = id; item.CompanyID = ClientSessionSingleton.Instance.CompanyID; item.IsValid = 1; item.NotValidMessage = "New Record Key Field/s Are Required."; SecurityGroupCodeList.Add(item); _serviceAgent.AddToSecurityGroupCodeRepository(item); SelectedSecurityGroupCode = SecurityGroupCodeList.LastOrDefault(); AllowEdit = true; Dirty = false; return(true); }
public IEnumerable <SecurityGroupCode> GetSecurityGroupCodes(SecurityGroupCode itemCodeQuerryObject, string companyID) { return(SecurityGroupCodeSingletonRepository.Instance.GetSecurityGroupCodes(itemCodeQuerryObject, companyID)); }
public void AddToSecurityGroupCodeRepository(SecurityGroupCode itemCode) { SecurityGroupCodeSingletonRepository.Instance.AddToRepository(itemCode); }
private bool Delete(SecurityGroupCode itemCode) { _serviceAgent.DeleteFromSecurityGroupCodeRepository(itemCode); return(true); }
public void DeleteFromSecurityGroupCodeRepository(SecurityGroupCode itemCode) { SecurityGroupCodeSingletonRepository.Instance.DeleteFromRepository(itemCode); }
public EntityStates GetSecurityGroupCodeEntityState(SecurityGroupCode itemCode) { return(SecurityGroupCodeSingletonRepository.Instance.GetSecurityGroupCodeEntityState(itemCode)); }
private EntityStates GetSecurityGroupCodeState(SecurityGroupCode itemCode) { return(_serviceAgent.GetSecurityGroupCodeEntityState(itemCode)); }
private BindingList <SecurityGroupCode> GetSecurityGroupCodes(SecurityGroupCode itemQueryObject, string companyID) { return(new BindingList <SecurityGroupCode>(_serviceAgent.GetSecurityGroupCodes(itemQueryObject, companyID).ToList())); }
public void AddToRepository(SecurityGroupCode itemCode) { _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.AddToSecurityGroupCodes(itemCode); }
public void UpdateSecurityGroupCodeRepository(SecurityGroupCode itemCode) { SecurityGroupCodeSingletonRepository.Instance.UpdateRepository(itemCode); }