public void DeleteFromRepository(ExecutableProgramType executableProgramType) { if (_repositoryContext.GetEntityDescriptor(executableProgramType) != null) {//if it exists in the db delete it from the db MenuSecurityEntities context = new MenuSecurityEntities(_rootUri); context.MergeOption = MergeOption.AppendOnly; context.IgnoreResourceNotFoundException = true; ExecutableProgramType deletedExecutableProgramType = (from q in context.ExecutableProgramTypes where q.ExecutableProgramTypeID == executableProgramType.ExecutableProgramTypeID select q).FirstOrDefault(); if (deletedExecutableProgramType != null) { context.DeleteObject(deletedExecutableProgramType); context.SaveChanges(); } context = null; _repositoryContext.MergeOption = MergeOption.AppendOnly; //if it is being tracked remove it... if (GetExecutableProgramTypeEntityState(executableProgramType) != EntityStates.Detached) { _repositoryContext.Detach(executableProgramType); } } }
private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedExecutableProgramType.ExecutableProgramTypeID)) {//check to see if key is part of the current companylist... ExecutableProgramType query = ExecutableProgramTypeList.Where(company => company.ExecutableProgramTypeID == SelectedExecutableProgramType.ExecutableProgramTypeID && company.AutoID != SelectedExecutableProgramType.AutoID).FirstOrDefault(); if (query != null) {//revert it back... SelectedExecutableProgramType.ExecutableProgramTypeID = SelectedExecutableProgramTypeMirror.ExecutableProgramTypeID; //change to the newly selected company... SelectedExecutableProgramType = query; return; } //it is not part of the existing list try to fetch it from the db... ExecutableProgramTypeList = GetExecutableProgramTypeByID(SelectedExecutableProgramType.ExecutableProgramTypeID, XERP.Client.ClientSessionSingleton.Instance.CompanyID); if (ExecutableProgramTypeList.Count == 0)//it was not found do new record required logic... { NotifyNewRecordNeeded("Record " + SelectedExecutableProgramType.ExecutableProgramTypeID + " Does Not Exist. Create A New Record?"); } else { SelectedExecutableProgramType = ExecutableProgramTypeList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedExecutableProgramType.ExecutableProgramTypeID != SelectedExecutableProgramTypeMirror.ExecutableProgramTypeID) { SelectedExecutableProgramType.ExecutableProgramTypeID = SelectedExecutableProgramTypeMirror.ExecutableProgramTypeID; } } }
//ExecutableProgramType Object Scope Validation check the entire object for validity... private byte ExecutableProgramTypeIsValid(ExecutableProgramType item, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(item.ExecutableProgramTypeID)) { errorMessage = "ID Is Required."; return(1); } EntityStates entityState = GetExecutableProgramTypeState(item); if (entityState == EntityStates.Added && ExecutableProgramTypeExists(item.ExecutableProgramTypeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists."; return(1); } //check cached list for duplicates... int count = ExecutableProgramTypeList.Count(q => q.ExecutableProgramTypeID == item.ExecutableProgramTypeID); 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); }
public IEnumerable <ExecutableProgramType> GetExecutableProgramTypes(ExecutableProgramType executableProgramTypeQuerryObject, string companyID) { _repositoryContext = new MenuSecurityEntities(_rootUri); _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.IgnoreResourceNotFoundException = true; var queryResult = from q in _repositoryContext.ExecutableProgramTypes where q.CompanyID == companyID select q; if (!string.IsNullOrEmpty(executableProgramTypeQuerryObject.Type)) { queryResult = queryResult.Where(q => q.Type.StartsWith(executableProgramTypeQuerryObject.Type.ToString())); } if (!string.IsNullOrEmpty(executableProgramTypeQuerryObject.Description)) { queryResult = queryResult.Where(q => q.Description.StartsWith(executableProgramTypeQuerryObject.Description.ToString())); } if (!string.IsNullOrEmpty(executableProgramTypeQuerryObject.ExecutableProgramTypeID)) { queryResult = queryResult.Where(q => q.Description.StartsWith(executableProgramTypeQuerryObject.ExecutableProgramTypeID.ToString())); } return(queryResult); }
public static List <Temp> GetMetaData(this ExecutableProgramType entityObject) { XERP.Server.DAL.MenuSecurityDAL.DALUtility dalUtility = new DALUtility(); List <Temp> tempList = new List <Temp>(); int id = 0; using (MenuSecurityEntities ctx = new MenuSecurityEntities(dalUtility.EntityConectionString)) { var c = ctx.ExecutableProgramTypes.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 DeleteExecutableProgramTypeCommand() { try {//company is fk to 100's of tables deleting it can be tricky... int i = 0; int ii = 0; for (int j = SelectedExecutableProgramTypeList.Count - 1; j >= 0; j--) { ExecutableProgramType item = (ExecutableProgramType)SelectedExecutableProgramTypeList[j]; //get Max Index... i = ExecutableProgramTypeList.IndexOf(item); if (i > ii) { ii = i; } Delete(item); ExecutableProgramTypeList.Remove(item); } if (ExecutableProgramTypeList != null && ExecutableProgramTypeList.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 >= ExecutableProgramTypeList.Count()) { ii = ExecutableProgramTypeList.Count - 1; } SelectedExecutableProgramType = ExecutableProgramTypeList[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("ExecutableProgramType/s Can Not Be Deleted. Contact XERP Admin For More Details."); Refresh(); } }
private BindingList <ExecutableProgramType> GetExecutableProgramTypes(ExecutableProgramType itemType, string companyID) { BindingList <ExecutableProgramType> itemTypeList = new BindingList <ExecutableProgramType>(_serviceAgent.GetExecutableProgramTypes(itemType, companyID).ToList()); Dirty = false; AllowCommit = false; return(itemTypeList); }
public static void SetPropertyValue(this ExecutableProgramType myObj, object propertyName, object propertyValue) { var propInfo = typeof(ExecutableProgramType).GetProperty((string)propertyName); if (propInfo != null) { propInfo.SetValue(myObj, propertyValue, null); } }
private void SetAsEmptySelection() { SelectedExecutableProgramType = new ExecutableProgramType(); AllowEdit = false; AllowDelete = false; Dirty = false; AllowCommit = false; AllowRowCopy = false; }
public void UpdateRepository(ExecutableProgramType itemType) { if (_repositoryContext.GetEntityDescriptor(itemType) != null) { itemType.LastModifiedBy = XERP.Client.ClientSessionSingleton.Instance.SystemUserID; itemType.LastModifiedByDate = DateTime.Now; _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.UpdateObject(itemType); } }
public EntityStates GetExecutableProgramTypeEntityState(ExecutableProgramType executableProgramType) { if (_repositoryContext.GetEntityDescriptor(executableProgramType) != null) { return(_repositoryContext.GetEntityDescriptor(executableProgramType).State); } else { return(EntityStates.Detached); } }
public static string GetPropertyType(this ExecutableProgramType myObj, string propertyName) { var propInfo = typeof(ExecutableProgramType).GetProperty(propertyName); if (propInfo != null) { return(propInfo.PropertyType.Name.ToString()); } else { return(null); } }
public static object GetPropertyValue(this ExecutableProgramType myObj, string propertyName) { var propInfo = typeof(ExecutableProgramType).GetProperty(propertyName); if (propInfo != null) { return(propInfo.GetValue(myObj, null)); } else { return(string.Empty); } }
public void OnChangeExecutableProgramTypes(ExecutableProgramType executableProgramType, UpdateOperations operations) { if (operations == UpdateOperations.Delete) {//update a null to any place the Type was used by its parent record... XERP.Server.DAL.MenuSecurityDAL.DALUtility dalUtility = new DALUtility(); var context = new MenuSecurityEntities(dalUtility.EntityConectionString); context.ExecutablePrograms.MergeOption = System.Data.Objects.MergeOption.NoTracking; string companyID = executableProgramType.CompanyID; string typeID = executableProgramType.ExecutableProgramTypeID; string sqlstring = "UPDATE ExecutablePrograms SET ExecutableProgramTypeID = null WHERE CompanyID = '" + companyID + "' and ExecutableProgramTypeID = '" + typeID + "'"; context.ExecuteStoreCommand(sqlstring); } }
//udpate merely updates the repository a commit is required //to commit it to the db... private bool Update(ExecutableProgramType item) { _serviceAgent.UpdateExecutableProgramTypeRepository(item); Dirty = true; if (CommitIsAllowed()) { AllowCommit = true; } else { AllowCommit = false; } return(AllowCommit); }
public IQueryable <Temp> GetMetaData(string tableName) { switch (tableName) { case "MenuItems": MenuItem menuItem = new MenuItem(); return(menuItem.GetMetaData().AsQueryable()); case "MenuItemTypes": MenuItemType menuItemType = new MenuItemType(); return(menuItemType.GetMetaData().AsQueryable()); case "MenuItemCodes": MenuItemCode menuItemCode = new MenuItemCode(); return(menuItemCode.GetMetaData().AsQueryable()); case "ExecutablePrograms": ExecutableProgram executablePrograms = new ExecutableProgram(); return(executablePrograms.GetMetaData().AsQueryable()); case "ExecutableProgramTypes": ExecutableProgramType executableProgramType = new ExecutableProgramType(); return(executableProgramType.GetMetaData().AsQueryable()); case "ExecutableProgramCodes": ExecutableProgramCode executableProgramCode = new ExecutableProgramCode(); return(executableProgramCode.GetMetaData().AsQueryable()); case "MenuSecurities": MenuSecurity menuSecurity = new MenuSecurity(); return(menuSecurity.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 TypeSearchViewModel(IExecutableProgramServiceAgent serviceAgent) { this._serviceAgent = serviceAgent; SearchObject = new ExecutableProgramType(); ResultList = new BindingList <ExecutableProgramType>(); SelectedList = new BindingList <ExecutableProgramType>(); //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; } }
//Object.Property Scope Validation... private bool ExecutableProgramTypeIsValid(ExecutableProgramType item, _companyValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _companyValidationProperties.ExecutableProgramTypeID: //validate key if (string.IsNullOrEmpty(item.ExecutableProgramTypeID)) { errorMessage = "ID Is Required."; return(false); } EntityStates entityState = GetExecutableProgramTypeState(item); if (entityState == EntityStates.Added && ExecutableProgramTypeExists(item.ExecutableProgramTypeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists..."; return(false); } //check cached list for duplicates... int count = ExecutableProgramTypeList.Count(q => q.ExecutableProgramTypeID == item.ExecutableProgramTypeID); 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 NewExecutableProgramType(string id) { ExecutableProgramType item = new ExecutableProgramType(); //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... _newExecutableProgramTypeAutoId = _newExecutableProgramTypeAutoId - 1; item.AutoID = _newExecutableProgramTypeAutoId; item.ExecutableProgramTypeID = id; item.CompanyID = ClientSessionSingleton.Instance.CompanyID; item.IsValid = 1; item.NotValidMessage = "New Record Key Field/s Are Required."; ExecutableProgramTypeList.Add(item); _serviceAgent.AddToExecutableProgramTypeRepository(item); SelectedExecutableProgramType = ExecutableProgramTypeList.LastOrDefault(); AllowEdit = true; Dirty = false; return(true); }
public IEnumerable <ExecutableProgramType> GetExecutableProgramTypes(ExecutableProgramType executableProgramTypeQuerryObject, string companyID) { return(ExecutableProgramTypeSingletonRepository.Instance.GetExecutableProgramTypes(executableProgramTypeQuerryObject, companyID)); }
public void UpdateExecutableProgramTypeRepository(ExecutableProgramType executableProgramType) { ExecutableProgramTypeSingletonRepository.Instance.UpdateRepository(executableProgramType); }
public void AddToExecutableProgramTypeRepository(ExecutableProgramType executableProgramType) { ExecutableProgramTypeSingletonRepository.Instance.AddToRepository(executableProgramType); }
public void AddToRepository(ExecutableProgramType executableProgramType) { _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.AddToExecutableProgramTypes(executableProgramType); }
public void DeleteFromExecutableProgramTypeRepository(ExecutableProgramType executableProgramType) { ExecutableProgramTypeSingletonRepository.Instance.DeleteFromRepository(executableProgramType); }
public EntityStates GetExecutableProgramTypeEntityState(ExecutableProgramType executableProgramType) { return(ExecutableProgramTypeSingletonRepository.Instance.GetExecutableProgramTypeEntityState(executableProgramType)); }
private bool Delete(ExecutableProgramType itemType) {//deletes are done indenpendently of the repository as a delete will not commit //dirty records it will simply just delete the record... _serviceAgent.DeleteFromExecutableProgramTypeRepository(itemType); return(true); }
private BindingList <ExecutableProgramType> GetExecutableProgramTypes(ExecutableProgramType itemQueryObject, string companyID) { return(new BindingList <ExecutableProgramType>(_serviceAgent.GetExecutableProgramTypes(itemQueryObject, companyID).ToList())); }
private EntityStates GetExecutableProgramTypeState(ExecutableProgramType itemType) { return(_serviceAgent.GetExecutableProgramTypeEntityState(itemType)); }