//MenuItemCode Object Scope Validation check the entire object for validity... private byte MenuItemCodeIsValid(MenuItemCode item, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(item.MenuItemCodeID)) { errorMessage = "ID Is Required."; return(1); } EntityStates entityState = GetMenuItemCodeState(item); if (entityState == EntityStates.Added && MenuItemCodeExists(item.MenuItemCodeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists."; return(1); } //check cached list for duplicates... int count = MenuItemCodeList.Count(q => q.MenuItemCodeID == item.MenuItemCodeID); 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 static List <Temp> GetMetaData(this MenuItemCode 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.MenuItemCodes.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 IEnumerable <MenuItemCode> GetMenuItemCodes(MenuItemCode securityGroupCodeQuerryObject, string companyID) { _repositoryContext = new MenuSecurityEntities(_rootUri); _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.IgnoreResourceNotFoundException = true; var queryResult = from q in _repositoryContext.MenuItemCodes where q.CompanyID == companyID select q; if (!string.IsNullOrEmpty(securityGroupCodeQuerryObject.Code)) { queryResult = queryResult.Where(q => q.Code.StartsWith(securityGroupCodeQuerryObject.Code.ToString())); } if (!string.IsNullOrEmpty(securityGroupCodeQuerryObject.Description)) { queryResult = queryResult.Where(q => q.Description.StartsWith(securityGroupCodeQuerryObject.Description.ToString())); } if (!string.IsNullOrEmpty(securityGroupCodeQuerryObject.MenuItemCodeID)) { queryResult = queryResult.Where(q => q.Description.StartsWith(securityGroupCodeQuerryObject.MenuItemCodeID.ToString())); } return(queryResult); }
public void DeleteFromRepository(MenuItemCode securityGroupCode) { if (_repositoryContext.GetEntityDescriptor(securityGroupCode) != null) { //if it exists in the db delete it from the db MenuSecurityEntities context = new MenuSecurityEntities(_rootUri); context.MergeOption = MergeOption.AppendOnly; context.IgnoreResourceNotFoundException = true; MenuItemCode deletedMenuItemCode = (from q in context.MenuItemCodes where q.MenuItemCodeID == securityGroupCode.MenuItemCodeID select q).FirstOrDefault(); if (deletedMenuItemCode != null) { context.DeleteObject(deletedMenuItemCode); context.SaveChanges(); } context = null; _repositoryContext.MergeOption = MergeOption.AppendOnly; //if it is being tracked remove it... if (GetMenuItemCodeEntityState(securityGroupCode) != EntityStates.Detached) { _repositoryContext.Detach(securityGroupCode); } } }
private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedMenuItemCode.MenuItemCodeID)) {//check to see if key is part of the current companylist... MenuItemCode query = MenuItemCodeList.Where(company => company.MenuItemCodeID == SelectedMenuItemCode.MenuItemCodeID && company.AutoID != SelectedMenuItemCode.AutoID).FirstOrDefault(); if (query != null) {//revert it back... SelectedMenuItemCode.MenuItemCodeID = SelectedMenuItemCodeMirror.MenuItemCodeID; //change to the newly selected item... SelectedMenuItemCode = query; return; } //it is not part of the existing list try to fetch it from the db... MenuItemCodeList = GetMenuItemCodeByID(SelectedMenuItemCode.MenuItemCodeID, XERP.Client.ClientSessionSingleton.Instance.CompanyID); if (MenuItemCodeList.Count == 0)//it was not found do new record required logic... { NotifyNewRecordNeeded("Record " + SelectedMenuItemCode.MenuItemCodeID + " Does Not Exist. Create A New Record?"); } else { SelectedMenuItemCode = MenuItemCodeList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedMenuItemCode.MenuItemCodeID != SelectedMenuItemCodeMirror.MenuItemCodeID) { SelectedMenuItemCode.MenuItemCodeID = SelectedMenuItemCodeMirror.MenuItemCodeID; } } }
public void DeleteMenuItemCodeCommand() { try {//company is fk to 100's of tables deleting it can be tricky... int i = 0; int ii = 0; for (int j = SelectedMenuItemCodeList.Count - 1; j >= 0; j--) { MenuItemCode item = (MenuItemCode)SelectedMenuItemCodeList[j]; //get Max Index... i = MenuItemCodeList.IndexOf(item); if (i > ii) { ii = i; } Delete(item); MenuItemCodeList.Remove(item); } if (MenuItemCodeList != null && MenuItemCodeList.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 >= MenuItemCodeList.Count()) { ii = MenuItemCodeList.Count - 1; } SelectedMenuItemCode = MenuItemCodeList[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("MenuItemCode/s Can Not Be Deleted. Contact XERP Admin For More Details."); Refresh(); } }
private BindingList <MenuItemCode> GetMenuItemCodes(MenuItemCode itemCode, string companyID) { BindingList <MenuItemCode> itemCodeList = new BindingList <MenuItemCode>(_serviceAgent.GetMenuItemCodes(itemCode, companyID).ToList()); Dirty = false; AllowCommit = false; return(itemCodeList); }
private void SetAsEmptySelection() { SelectedMenuItemCode = new MenuItemCode(); AllowEdit = false; AllowDelete = false; Dirty = false; AllowCommit = false; AllowRowCopy = false; }
public static void SetPropertyValue(this MenuItemCode myObj, object propertyName, object propertyValue) { var propInfo = typeof(MenuItemCode).GetProperty((string)propertyName); if (propInfo != null) { propInfo.SetValue(myObj, propertyValue, null); } }
public void UpdateRepository(MenuItemCode 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 GetMenuItemCodeEntityState(MenuItemCode securityGroupCode) { if (_repositoryContext.GetEntityDescriptor(securityGroupCode) != null) { return(_repositoryContext.GetEntityDescriptor(securityGroupCode).State); } else { return(EntityStates.Detached); } }
public void OnChangeMenuItemTypes(MenuItemCode menuItemCode, UpdateOperations operations) { if (operations == UpdateOperations.Delete) {//update a null to any place the Code was used by its parent record... XERP.Server.DAL.MenuSecurityDAL.DALUtility dalUtility = new DALUtility(); var context = new MenuSecurityEntities(dalUtility.EntityConectionString); context.MenuItems.MergeOption = System.Data.Objects.MergeOption.NoTracking; string companyID = menuItemCode.CompanyID; string codeID = menuItemCode.MenuItemCodeID; string sqlstring = "UPDATE MenuItems SET MenuItemCodeID = null WHERE CompanyID = '" + companyID + "' and MenuItemCodeID = '" + codeID + "'"; context.ExecuteStoreCommand(sqlstring); } }
public static string GetPropertyCode(this MenuItemCode myObj, string propertyName) { var propInfo = typeof(MenuItemCode).GetProperty(propertyName); if (propInfo != null) { return(propInfo.PropertyType.Name.ToString()); } else { return(null); } }
public static object GetPropertyValue(this MenuItemCode myObj, string propertyName) { var propInfo = typeof(MenuItemCode).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(MenuItemCode item) { _serviceAgent.UpdateMenuItemCodeRepository(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 CodeSearchViewModel(IMenuItemServiceAgent serviceAgent) { this._serviceAgent = serviceAgent; SearchObject = new MenuItemCode(); ResultList = new BindingList <MenuItemCode>(); SelectedList = new BindingList <MenuItemCode>(); //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 MenuItemCodeIsValid(MenuItemCode item, _companyValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _companyValidationProperties.MenuItemCodeID: //validate key if (string.IsNullOrEmpty(item.MenuItemCodeID)) { errorMessage = "ID Is Required."; return(false); } EntityStates entityState = GetMenuItemCodeState(item); if (entityState == EntityStates.Added && MenuItemCodeExists(item.MenuItemCodeID, ClientSessionSingleton.Instance.CompanyID)) { errorMessage = "Item All Ready Exists..."; return(false); } //check cached list for duplicates... int count = MenuItemCodeList.Count(q => q.MenuItemCodeID == item.MenuItemCodeID); 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 NewMenuItemCode(string id) { MenuItemCode item = new MenuItemCode(); //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... _newMenuItemCodeAutoId = _newMenuItemCodeAutoId - 1; item.AutoID = _newMenuItemCodeAutoId; item.MenuItemCodeID = id; item.CompanyID = ClientSessionSingleton.Instance.CompanyID; item.IsValid = 1; item.NotValidMessage = "New Record Key Field/s Are Required."; MenuItemCodeList.Add(item); _serviceAgent.AddToMenuItemCodeRepository(item); SelectedMenuItemCode = MenuItemCodeList.LastOrDefault(); AllowEdit = true; Dirty = false; return(true); }
public IEnumerable <MenuItemCode> GetMenuItemCodes(MenuItemCode menuItemCodeQuerryObject, string companyID) { return(MenuItemCodeSingletonRepository.Instance.GetMenuItemCodes(menuItemCodeQuerryObject, companyID)); }
public void AddToMenuItemCodeRepository(MenuItemCode menuItemCode) { MenuItemCodeSingletonRepository.Instance.AddToRepository(menuItemCode); }
public void AddToRepository(MenuItemCode securityGroupCode) { _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.AddToMenuItemCodes(securityGroupCode); }
public void DeleteFromMenuItemCodeRepository(MenuItemCode menuItemCode) { MenuItemCodeSingletonRepository.Instance.DeleteFromRepository(menuItemCode); }
public EntityStates GetMenuItemCodeEntityState(MenuItemCode menuItemCode) { return(MenuItemCodeSingletonRepository.Instance.GetMenuItemCodeEntityState(menuItemCode)); }
public void UpdateMenuItemCodeRepository(MenuItemCode menuItemCode) { MenuItemCodeSingletonRepository.Instance.UpdateRepository(menuItemCode); }
private bool Delete(MenuItemCode itemCode) { _serviceAgent.DeleteFromMenuItemCodeRepository(itemCode); return(true); }
private EntityStates GetMenuItemCodeState(MenuItemCode itemCode) { return(_serviceAgent.GetMenuItemCodeEntityState(itemCode)); }
private BindingList <MenuItemCode> GetMenuItemCodes(MenuItemCode itemQueryObject, string companyID) { return(new BindingList <MenuItemCode>(_serviceAgent.GetMenuItemCodes(itemQueryObject, companyID).ToList())); }