private void ChangeKeyLogic()
 {
     if (!string.IsNullOrEmpty(SelectedWarehouseLocationBinType.WarehouseLocationBinTypeID))
     {//check to see if key is part of the current companylist...
         WarehouseLocationBinType query = WarehouseLocationBinTypeList.Where(company => company.WarehouseLocationBinTypeID == SelectedWarehouseLocationBinType.WarehouseLocationBinTypeID &&
                                                                             company.AutoID != SelectedWarehouseLocationBinType.AutoID).FirstOrDefault();
         if (query != null)
         {//revert it back...
             SelectedWarehouseLocationBinType.WarehouseLocationBinTypeID = SelectedWarehouseLocationBinTypeMirror.WarehouseLocationBinTypeID;
             //change to the newly selected company...
             SelectedWarehouseLocationBinType = query;
             return;
         }
         //it is not part of the existing list try to fetch it from the db...
         WarehouseLocationBinTypeList = GetWarehouseLocationBinTypeByID(SelectedWarehouseLocationBinType.WarehouseLocationBinTypeID, XERP.Client.ClientSessionSingleton.Instance.CompanyID);
         if (WarehouseLocationBinTypeList.Count == 0)//it was not found do new record required logic...
         {
             NotifyNewRecordNeeded("Record " + SelectedWarehouseLocationBinType.WarehouseLocationBinTypeID + " Does Not Exist.  Create A New Record?");
         }
         else
         {
             SelectedWarehouseLocationBinType = WarehouseLocationBinTypeList.FirstOrDefault();
         }
     }
     else
     {
         string errorMessage = "ID Is Required.";
         NotifyMessage(errorMessage);
         //revert back to the value it was before it was changed...
         if (SelectedWarehouseLocationBinType.WarehouseLocationBinTypeID != SelectedWarehouseLocationBinTypeMirror.WarehouseLocationBinTypeID)
         {
             SelectedWarehouseLocationBinType.WarehouseLocationBinTypeID = SelectedWarehouseLocationBinTypeMirror.WarehouseLocationBinTypeID;
         }
     }
 }
        //WarehouseLocationBinType Object Scope Validation check the entire object for validity...
        private byte WarehouseLocationBinTypeIsValid(WarehouseLocationBinType item, out string errorMessage)
        {   //validate key
            errorMessage = "";
            if (string.IsNullOrEmpty(item.WarehouseLocationBinTypeID))
            {
                errorMessage = "ID Is Required.";
                return(1);
            }
            EntityStates entityState = GetWarehouseLocationBinTypeState(item);

            if (entityState == EntityStates.Added && WarehouseLocationBinTypeExists(item.WarehouseLocationBinTypeID, ClientSessionSingleton.Instance.CompanyID))
            {
                errorMessage = "Item All Ready Exists.";
                return(1);
            }
            //check cached list for duplicates...
            int count = WarehouseLocationBinTypeList.Count(q => q.WarehouseLocationBinTypeID == item.WarehouseLocationBinTypeID);

            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 <WarehouseLocationBinType> GetWarehouseLocationBinTypes(WarehouseLocationBinType itemTypeQuerryObject, string companyID)
        {
            _repositoryContext             = new WarehouseEntities(_rootUri);
            _repositoryContext.MergeOption = MergeOption.AppendOnly;
            _repositoryContext.IgnoreResourceNotFoundException = true;
            var queryResult = from q in _repositoryContext.WarehouseLocationBinTypes
                              where q.CompanyID == companyID
                              select q;

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

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

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

            return(queryResult);
        }
        private void Refresh()
        {//refetch current records...
            long   selectedAutoID = SelectedWarehouseLocationBinType.AutoID;
            string autoIDs        = "";

            //bool isFirstItem = true;
            foreach (WarehouseLocationBinType itemType in WarehouseLocationBinTypeList)
            {//auto seeded starts at 1 any records at 0 or less or not valid records...
                if (itemType.AutoID > 0)
                {
                    autoIDs = autoIDs + itemType.AutoID.ToString() + ",";
                }
            }
            if (autoIDs.Length > 0)
            {
                //ditch the extra comma...
                autoIDs = autoIDs.Remove(autoIDs.Length - 1, 1);
                WarehouseLocationBinTypeList     = new BindingList <WarehouseLocationBinType>(_serviceAgent.RefreshWarehouseLocationBinType(autoIDs).ToList());
                SelectedWarehouseLocationBinType = (from q in WarehouseLocationBinTypeList
                                                    where q.AutoID == selectedAutoID
                                                    select q).FirstOrDefault();
                Dirty       = false;
                AllowCommit = false;
            }
        }
        public void DeleteFromRepository(WarehouseLocationBinType itemType)
        {
            if (_repositoryContext.GetEntityDescriptor(itemType) != null)
            {//if it exists in the db delete it from the db
                WarehouseEntities context = new WarehouseEntities(_rootUri);
                context.MergeOption = MergeOption.AppendOnly;
                context.IgnoreResourceNotFoundException = true;
                WarehouseLocationBinType deletedWarehouseLocationBinType = (from q in context.WarehouseLocationBinTypes
                                                                            where q.WarehouseLocationBinTypeID == itemType.WarehouseLocationBinTypeID
                                                                            select q).FirstOrDefault();
                if (deletedWarehouseLocationBinType != null)
                {
                    context.DeleteObject(deletedWarehouseLocationBinType);
                    context.SaveChanges();
                }
                context = null;

                _repositoryContext.MergeOption = MergeOption.AppendOnly;
                //if it is being tracked remove it...
                if (GetWarehouseLocationBinTypeEntityState(itemType) != EntityStates.Detached)
                {
                    _repositoryContext.Detach(itemType);
                }
            }
        }
        public static List <Temp> GetMetaData(this WarehouseLocationBinType entityObject)
        {
            XERP.Server.DAL.WarehouseDAL.DALUtility dalUtility = new DALUtility();
            List <Temp> tempList = new List <Temp>();
            int         id       = 0;

            using (WarehouseEntities ctx = new WarehouseEntities(dalUtility.EntityConectionString))
            {
                var c            = ctx.WarehouseLocationBinTypes.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 DeleteWarehouseLocationBinTypeCommand()
        {
            try
            {//company is fk to 100's of tables deleting it can be tricky...
                int i  = 0;
                int ii = 0;
                for (int j = SelectedWarehouseLocationBinTypeList.Count - 1; j >= 0; j--)
                {
                    WarehouseLocationBinType item = (WarehouseLocationBinType)SelectedWarehouseLocationBinTypeList[j];
                    //get Max Index...
                    i = WarehouseLocationBinTypeList.IndexOf(item);
                    if (i > ii)
                    {
                        ii = i;
                    }
                    Delete(item);
                    WarehouseLocationBinTypeList.Remove(item);
                }

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

                    SelectedWarehouseLocationBinType = WarehouseLocationBinTypeList[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("WarehouseLocationBinType/s Can Not Be Deleted.  Contact XERP Admin For More Details.");
                Refresh();
            }
        }
        private BindingList <WarehouseLocationBinType> GetWarehouseLocationBinTypes(WarehouseLocationBinType itemType, string companyID)
        {
            BindingList <WarehouseLocationBinType> itemTypeList = new BindingList <WarehouseLocationBinType>(_serviceAgent.GetWarehouseLocationBinTypes(itemType, companyID).ToList());

            Dirty       = false;
            AllowCommit = false;
            return(itemTypeList);
        }
 private void SetAsEmptySelection()
 {
     SelectedWarehouseLocationBinType = new WarehouseLocationBinType();
     AllowEdit    = false;
     AllowDelete  = false;
     Dirty        = false;
     AllowCommit  = false;
     AllowRowCopy = false;
 }
Esempio n. 10
0
        public static void SetPropertyValue(this WarehouseLocationBinType myObj, object propertyName, object propertyValue)
        {
            var propInfo = typeof(WarehouseLocationBinType).GetProperty((string)propertyName);

            if (propInfo != null)
            {
                propInfo.SetValue(myObj, propertyValue, null);
            }
        }
 public void UpdateRepository(WarehouseLocationBinType 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 GetWarehouseLocationBinTypeEntityState(WarehouseLocationBinType itemType)
 {
     if (_repositoryContext.GetEntityDescriptor(itemType) != null)
     {
         return(_repositoryContext.GetEntityDescriptor(itemType).State);
     }
     else
     {
         return(EntityStates.Detached);
     }
 }
Esempio n. 13
0
 private void OnSearchResult(object sender, NotificationEventArgs <BindingList <WarehouseLocationBinType> > e)
 {
     if (e.Data != null && e.Data.Count > 0)
     {
         WarehouseLocationBinTypeList     = e.Data;
         SelectedWarehouseLocationBinType = WarehouseLocationBinTypeList.FirstOrDefault();
         Dirty       = false;
         AllowCommit = false;
     }
     UnregisterToReceiveMessages <BindingList <WarehouseLocationBinType> >(MessageTokens.WarehouseLocationBinTypeSearchToken.ToString(), OnSearchResult);
 }
Esempio n. 14
0
        public static object GetPropertyValue(this WarehouseLocationBinType myObj, string propertyName)
        {
            var propInfo = typeof(WarehouseLocationBinType).GetProperty(propertyName);

            if (propInfo != null)
            {
                return(propInfo.GetValue(myObj, null));
            }
            else
            {
                return(string.Empty);
            }
        }
Esempio n. 15
0
 public void OnChangeWarehouseLocationBinTypes(WarehouseLocationBinType warehouseType, UpdateOperations operations)
 {
     if (operations == UpdateOperations.Delete)
     {//update a null to any place the Type was used by its parent record...
         XERP.Server.DAL.WarehouseDAL.DALUtility dalUtility = new DALUtility();
         var context = new WarehouseEntities(dalUtility.EntityConectionString);
         context.WarehouseLocationBins.MergeOption = System.Data.Objects.MergeOption.NoTracking;
         string companyID = warehouseType.CompanyID;
         string typeID    = warehouseType.WarehouseLocationBinTypeID;
         string sqlstring = "UPDATE WarehouseLocationBins SET WarehouseLocationBinTypeID = null WHERE CompanyID = '" + companyID + "' and WarehouseLocationBinTypeID = '" + typeID + "'";
         context.ExecuteStoreCommand(sqlstring);
     }
 }
Esempio n. 16
0
        public static string GetPropertyType(this WarehouseLocationBinType myObj, string propertyName)
        {
            var propInfo = typeof(WarehouseLocationBinType).GetProperty(propertyName);

            if (propInfo != null)
            {
                return(propInfo.PropertyType.Name.ToString());
            }
            else
            {
                return(null);
            }
        }
Esempio n. 17
0
 //udpate merely updates the repository a commit is required
 //to commit it to the db...
 private bool Update(WarehouseLocationBinType item)
 {
     _serviceAgent.UpdateWarehouseLocationBinTypeRepository(item);
     Dirty = true;
     if (CommitIsAllowed())
     {
         AllowCommit = true;
     }
     else
     {
         AllowCommit = false;
     }
     return(AllowCommit);
 }
Esempio n. 18
0
        public TypeSearchViewModel(IWarehouseServiceAgent serviceAgent)
        {
            this._serviceAgent = serviceAgent;

            SearchObject = new WarehouseLocationBinType();
            ResultList   = new BindingList <WarehouseLocationBinType>();
            SelectedList = new BindingList <WarehouseLocationBinType>();
            //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;
            }
        }
Esempio n. 19
0
        public IQueryable <Temp> GetMetaData(string tableName)
        {
            switch (tableName)
            {
            case "Warehouses":
                Warehouse Warehouse = new Warehouse();
                return(Warehouse.GetMetaData().AsQueryable());

            case "WarehouseTypes":
                WarehouseType WarehouseType = new WarehouseType();
                return(WarehouseType.GetMetaData().AsQueryable());

            case "WarehouseCodes":
                WarehouseCode WarehouseCode = new WarehouseCode();
                return(WarehouseCode.GetMetaData().AsQueryable());

            case "WarehouseLocationBins":
                WarehouseLocationBin WarehouseLocationBin = new WarehouseLocationBin();
                return(WarehouseLocationBin.GetMetaData().AsQueryable());

            case "WarehouseLocationBinTypes":
                WarehouseLocationBinType WarehouseLocationBinType = new WarehouseLocationBinType();
                return(WarehouseLocationBinType.GetMetaData().AsQueryable());

            case "WarehouseLocationBinCodes":
                WarehouseLocationBinCode WarehouseLocationBinCode = new WarehouseLocationBinCode();
                return(WarehouseLocationBinCode.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());
            }
        }
Esempio n. 20
0
        //Object.Property Scope Validation...
        private bool WarehouseLocationBinTypeIsValid(WarehouseLocationBinType item, _companyValidationProperties validationProperties, out string errorMessage)
        {
            errorMessage = "";
            switch (validationProperties)
            {
            case _companyValidationProperties.WarehouseLocationBinTypeID:
                //validate key
                if (string.IsNullOrEmpty(item.WarehouseLocationBinTypeID))
                {
                    errorMessage = "ID Is Required.";
                    return(false);
                }
                EntityStates entityState = GetWarehouseLocationBinTypeState(item);
                if (entityState == EntityStates.Added && WarehouseLocationBinTypeExists(item.WarehouseLocationBinTypeID, ClientSessionSingleton.Instance.CompanyID))
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                //check cached list for duplicates...
                int count = WarehouseLocationBinTypeList.Count(q => q.WarehouseLocationBinTypeID == item.WarehouseLocationBinTypeID);
                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);
        }
Esempio n. 21
0
        private bool NewWarehouseLocationBinType(string id)
        {
            WarehouseLocationBinType item = new WarehouseLocationBinType();

            //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...
            _newWarehouseLocationBinTypeAutoId = _newWarehouseLocationBinTypeAutoId - 1;
            item.AutoID = _newWarehouseLocationBinTypeAutoId;
            item.WarehouseLocationBinTypeID = id;
            item.CompanyID       = ClientSessionSingleton.Instance.CompanyID;
            item.IsValid         = 1;
            item.NotValidMessage = "New Record Key Field/s Are Required.";
            WarehouseLocationBinTypeList.Add(item);
            _serviceAgent.AddToWarehouseLocationBinTypeRepository(item);
            SelectedWarehouseLocationBinType = WarehouseLocationBinTypeList.LastOrDefault();

            AllowEdit = true;
            Dirty     = false;
            return(true);
        }
Esempio n. 22
0
 public EntityStates GetWarehouseLocationBinTypeEntityState(WarehouseLocationBinType itemType)
 {
     return(WarehouseLocationBinTypeSingletonRepository.Instance.GetWarehouseLocationBinTypeEntityState(itemType));
 }
Esempio n. 23
0
 private BindingList <WarehouseLocationBinType> GetWarehouseLocationBinTypes(WarehouseLocationBinType itemQueryObject, string companyID)
 {
     return(new BindingList <WarehouseLocationBinType>(_serviceAgent.GetWarehouseLocationBinTypes(itemQueryObject, companyID).ToList()));
 }
Esempio n. 24
0
 public void DeleteFromWarehouseLocationBinTypeRepository(WarehouseLocationBinType itemType)
 {
     WarehouseLocationBinTypeSingletonRepository.Instance.DeleteFromRepository(itemType);
 }
 public void AddToRepository(WarehouseLocationBinType itemType)
 {
     _repositoryContext.MergeOption = MergeOption.AppendOnly;
     _repositoryContext.AddToWarehouseLocationBinTypes(itemType);
 }
Esempio n. 26
0
 private bool Delete(WarehouseLocationBinType itemType)
 {//deletes are done indenpendently of the repository as a delete will not commit
     //dirty records it will simply just delete the record...
     _serviceAgent.DeleteFromWarehouseLocationBinTypeRepository(itemType);
     return(true);
 }
Esempio n. 27
0
 public void AddToWarehouseLocationBinTypeRepository(WarehouseLocationBinType itemType)
 {
     WarehouseLocationBinTypeSingletonRepository.Instance.AddToRepository(itemType);
 }
Esempio n. 28
0
 public IEnumerable <WarehouseLocationBinType> GetWarehouseLocationBinTypes(WarehouseLocationBinType itemTypeQuerryObject, string companyID)
 {
     return(WarehouseLocationBinTypeSingletonRepository.Instance.GetWarehouseLocationBinTypes(itemTypeQuerryObject, companyID));
 }
Esempio n. 29
0
 public void UpdateWarehouseLocationBinTypeRepository(WarehouseLocationBinType itemType)
 {
     WarehouseLocationBinTypeSingletonRepository.Instance.UpdateRepository(itemType);
 }
Esempio n. 30
0
 private EntityStates GetWarehouseLocationBinTypeState(WarehouseLocationBinType itemType)
 {
     return(_serviceAgent.GetWarehouseLocationBinTypeEntityState(itemType));
 }