Пример #1
0
        //UdList Object Scope Validation check the entire object for validity...
        private byte UdListIsValid(UdList udList, out string errorMessage)
        {
            //validate key
            errorMessage = "";
            if (string.IsNullOrEmpty(udList.UdListID))
            {
                errorMessage = "ID Is Required.";
                return(1);
            }
            EntityStates entityState = GetUdListState(udList);

            if (entityState == EntityStates.Added && UdListExists(udList.UdListID))
            {
                errorMessage = "Item All Ready Exists.";
                return(1);
            }
            //check cached list for duplicates...
            int count = UdListList.Count(q => q.UdListID == udList.UdListID);

            if (count > 1)
            {
                errorMessage = "Item All Ready Exists.";
                return(1);
            }
            //validate Description
            if (string.IsNullOrEmpty(udList.Name))
            {
                errorMessage = "Name Is Required.";
                return(1);
            }
            return(2);
        }
Пример #2
0
        public void ConvertNestedObject(object obj, out UdList udListout, out UdListItem udListItemout)
        {
            string type = obj.GetType().Name;

            udListout            = new UdList();
            udListItemout        = new UdListItem();
            UdListItemIsSelected = false;
            switch (type)
            {
            case "UdList":
                udListout     = (UdList)obj;
                udListItemout = udListout.UdListItems.FirstOrDefault();
                break;

            case "UdListItem":
                UdListItemIsSelected = true;
                udListItemout        = (UdListItem)obj;
                UdListItem item = (UdListItem)obj;
                udListout = (from q in UdListList
                             where q.UdListID == item.UdListID &&
                             q.CompanyID == item.CompanyID
                             select q).FirstOrDefault();
                break;

            default:
                break;
            }
        }
Пример #3
0
        public void DeleteFromRepository(UdList udList)
        {
            if (_repositoryContext.GetEntityDescriptor(udList) != null)
            {
                //if it exists in the db delete it from the db
                UdListEntities context = new UdListEntities(_rootUri);
                context.MergeOption = MergeOption.AppendOnly;
                context.IgnoreResourceNotFoundException = true;
                UdList deletedUdList = (from q in context.UdLists
                                        where q.UdListID == udList.UdListID &&
                                        q.CompanyID == udList.CompanyID
                                        select q).FirstOrDefault();
                if (deletedUdList != null)
                {
                    context.DeleteObject(deletedUdList);
                    context.SaveChanges();
                }
                context = null;

                _repositoryContext.MergeOption = MergeOption.AppendOnly;
                //if it is being tracked remove it...
                if (GetUdListEntityState(udList) != EntityStates.Detached)
                {
                    _repositoryContext.Detach(udList);
                }
            }
        }
Пример #4
0
        public static List <Temp> GetMetaData(this UdList entityObject)
        {
            XERP.Server.DAL.UdListDAL.DALUtility dalUtility = new DALUtility();
            List <Temp> tempList = new List <Temp>();
            int         id       = 0;

            using (UdListEntities ctx = new UdListEntities(dalUtility.EntityConectionString))
            {
                var c            = ctx.Companies.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);
        }
Пример #5
0
        private BindingList <UdList> GetUdLists(UdList udList, string companyID)
        {
            BindingList <UdList> udListList = new BindingList <UdList>(_serviceAgent.GetUdLists(udList, companyID).ToList());

            Dirty       = false;
            AllowCommit = false;
            return(udListList);
        }
Пример #6
0
        public static void SetPropertyValue(this UdList myObj, object propertyName, object propertyValue)
        {
            var propInfo = typeof(UdList).GetProperty((string)propertyName);

            if (propInfo != null)
            {
                propInfo.SetValue(myObj, propertyValue, null);
            }
        }
Пример #7
0
 public void UpdateRepository(UdList item)
 {
     if (_repositoryContext.GetEntityDescriptor(item) != null)
     {
         item.LastModifiedBy            = XERP.Client.ClientSessionSingleton.Instance.SystemUserID;
         item.LastModifiedByDate        = DateTime.Now;
         _repositoryContext.MergeOption = MergeOption.AppendOnly;
         _repositoryContext.UpdateObject(item);
     }
 }
Пример #8
0
 private void SetAsEmptySelection()
 {
     SelectedUdList     = new UdList();
     AllowEdit          = false;
     AllowDelete        = false;
     Dirty              = false;
     AllowCommit        = false;
     AllowRowCopy       = false;
     AllowNewUdListItem = false;
 }
Пример #9
0
 public EntityStates GetUdListEntityState(UdList udList)
 {
     if (_repositoryContext.GetEntityDescriptor(udList) != null)
     {
         return(_repositoryContext.GetEntityDescriptor(udList).State);
     }
     else
     {
         return(EntityStates.Detached);
     }
 }
Пример #10
0
        public void DeleteUdListCommand()
        {
            int i  = 0;
            int ii = 0;

            for (int j = SelectedUdListList.Count - 1; j >= 0; j--)
            {
                UdList udList = (UdList)SelectedUdListList[j];
                //get Max Index...
                i = UdListList.IndexOf(udList);
                if (i > ii)
                {
                    ii = i;
                }

                Delete(udList);
                UdListList.Remove(udList);
            }

            if (UdListList != null && UdListList.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 >= UdListList.Count())
                {
                    ii = UdListList.Count - 1;
                }

                SelectedUdList = UdListList[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();
            }
        }
Пример #11
0
        public static object GetPropertyValue(this UdList myObj, string propertyName)
        {
            var propInfo = typeof(UdList).GetProperty(propertyName);

            if (propInfo != null)
            {
                return(propInfo.GetValue(myObj, null));
            }
            else
            {
                return(string.Empty);
            }
        }
Пример #12
0
        public static string GetPropertyType(this UdList myObj, string propertyName)
        {
            var propInfo = typeof(UdList).GetProperty(propertyName);

            if (propInfo != null)
            {
                return(propInfo.PropertyType.Name.ToString());
            }
            else
            {
                return(null);
            }
        }
Пример #13
0
        //udpate merely updates the repository a commit is required
        //to commit it to the db...
        private bool Update(UdList udList)
        {
            _serviceAgent.UpdateUdListRepository(udList);
            Dirty = true;
            if (CommitIsAllowed())
            {
                AllowCommit = true;
            }
            else
            {
                AllowCommit = false;
            }

            return(AllowCommit);
        }
Пример #14
0
        public MainSearchViewModel(IUdListServiceAgent serviceAgent)
        {
            this._serviceAgent = serviceAgent;

            SearchObject = new UdList();
            ResultList   = new BindingList <UdList>();
            SelectedList = new BindingList <UdList>();
            //make sure of session authentication...
            if (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...
            }
        }
Пример #15
0
        public IEnumerable <UdList> GetUdLists(UdList udListQuerryObject, string companyID)
        {
            _repositoryContext             = new UdListEntities(_rootUri);
            _repositoryContext.MergeOption = MergeOption.AppendOnly;
            _repositoryContext.IgnoreResourceNotFoundException = true;
            var queryResult = from q in _repositoryContext.UdLists.Expand("UdListItems")
                              where q.CompanyID == companyID
                              select q;

            if (!string.IsNullOrEmpty(udListQuerryObject.Name))
            {
                queryResult = queryResult.Where(q => q.Name.StartsWith(udListQuerryObject.Name.ToString()));
            }

            if (!string.IsNullOrEmpty(udListQuerryObject.Description))
            {
                queryResult = queryResult.Where(q => q.Description.StartsWith(udListQuerryObject.Description.ToString()));
            }

            return(queryResult);
        }
Пример #16
0
        //Object.Property Scope Validation...
        private bool UdListIsValid(UdList udList, _udListValidationProperties validationProperties, out string errorMessage)
        {
            errorMessage = "";
            switch (validationProperties)
            {
            case _udListValidationProperties.UdListID:
                //validate key
                if (string.IsNullOrEmpty(udList.UdListID))
                {
                    errorMessage = "ID Is Required.";
                    return(false);
                }
                EntityStates entityState = GetUdListState(udList);
                if (entityState == EntityStates.Added && UdListExists(udList.UdListID))
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                //check cached list for duplicates...
                int count = UdListList.Count(q => q.UdListID == udList.UdListID);
                if (count > 1)
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                break;

            case _udListValidationProperties.Name:
                //validate Description
                if (string.IsNullOrEmpty(udList.Name))
                {
                    errorMessage = "Description Is Required.";
                    return(false);
                }
                break;
            }
            return(true);
        }
Пример #17
0
 private void ChangeKeyLogic()
 {
     if (!string.IsNullOrEmpty(SelectedUdList.UdListID))
     {
         //check to see if key is part of the current udListlist...
         UdList query = UdListList.Where(udList => udList.UdListID == SelectedUdList.UdListID &&
                                         udList.AutoID != SelectedUdList.AutoID).FirstOrDefault();
         if (query != null)
         {//change to the newly selected udList...
             //before navigating to the newly selected client cached record revert the old one back to what it was...
             SelectedUdList.UdListID = SelectedUdListMirror.UdListID;
             SelectedUdList          = query;
             return;
         }
         //it is not part of the existing list try to fetch it from the db...
         UdListList = GetUdListByID(SelectedUdList.UdListID, ClientSessionSingleton.Instance.CompanyID);
         if (UdListList.Count == 0)
         {//it was not found do new record required logic...
             NotifyNewRecordNeeded("Record " + SelectedUdList.UdListID + " Does Not Exist.  Create A New Record?");
         }
         else
         {
             SelectedUdList = UdListList.FirstOrDefault();
         }
     }
     else
     {
         string errorMessage = "ID Is Required.";
         NotifyMessage(errorMessage);
         //revert back to the value it was before it was changed...
         if (SelectedUdList.UdListID != SelectedUdListMirror.UdListID)
         {
             SelectedUdList.UdListID = SelectedUdListMirror.UdListID;
         }
     }
 }
Пример #18
0
        private bool NewUdList(string udListID)
        {
            UdList udList = new UdList();

            //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...
            _newUdListAutoId       = _newUdListAutoId - 1;
            udList.AutoID          = _newUdListAutoId;
            udList.UdListID        = udListID;
            udList.CompanyID       = ClientSessionSingleton.Instance.CompanyID;
            udList.IsValid         = 1;
            udList.NotValidMessage = "New Record Key Field/s Are Required.";
            UdListList.Add(udList);
            _serviceAgent.AddToUdListRepository(udList);
            SelectedUdList = UdListList.LastOrDefault();

            AllowEdit = true;
            Dirty     = false;
            return(true);
        }
Пример #19
0
        public IQueryable <Temp> GetMetaData(string tableName)
        {
            switch (tableName)
            {
            case "UdLists":
                UdList udList = new UdList();
                return(udList.GetMetaData().AsQueryable());

            case "UdListItems":
                UdListItem udListItem = new UdListItem();
                return(udListItem.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());
            }
        }
Пример #20
0
 private BindingList <UdList> GetUdLists(UdList udListQueryObject, string companyID)
 {//note this get is to the singleton repository...
     return(new BindingList <UdList>(_serviceAgent.GetUdLists(udListQueryObject, companyID).ToList()));
 }
Пример #21
0
 public void AddToRepository(UdList udList)
 {
     udList.CompanyID = XERP.Client.ClientSessionSingleton.Instance.CompanyID;
     _repositoryContext.MergeOption = MergeOption.AppendOnly;
     _repositoryContext.AddToUdLists(udList);
 }
Пример #22
0
 private EntityStates GetUdListState(UdList udList)
 {
     return(_serviceAgent.GetUdListEntityState(udList));
 }
Пример #23
0
 public EntityStates GetUdListEntityState(UdList udList)
 {
     return(UdListSingletonRepository.Instance.GetUdListEntityState(udList));
 }
Пример #24
0
 public void DeleteFromUdListRepository(UdList udList)
 {
     UdListSingletonRepository.Instance.DeleteFromRepository(udList);
 }
Пример #25
0
 public void AddToUdListRepository(UdList udList)
 {
     UdListSingletonRepository.Instance.AddToRepository(udList);
 }
Пример #26
0
 public void UpdateUdListRepository(UdList udList)
 {//make sure client only fields are never updated to the db...
     UdListSingletonRepository.Instance.UpdateRepository(udList);
 }
Пример #27
0
 public IEnumerable <UdList> GetUdLists(UdList udListQuerryObject, string companyID)
 {
     return(UdListSingletonRepository.Instance.GetUdLists(udListQuerryObject, companyID));
 }
Пример #28
0
 private bool Delete(UdList udList)
 {//deletes are done indenpendently of the repository as a delete will not commit
     //dirty records it will simply just delete the record...
     _serviceAgent.DeleteFromUdListRepository(udList);
     return(true);
 }