Exemple #1
0
        private bool NewWarehouseLocation(string itemID)
        {
            WarehouseLocation newItem = new WarehouseLocation();

            //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...
            _newWarehouseLocationAutoId = _newWarehouseLocationAutoId - 1;
            newItem.AutoID = _newWarehouseLocationAutoId;
            newItem.WarehouseLocationID = itemID;
            newItem.CompanyID           = ClientSessionSingleton.Instance.CompanyID;
            newItem.IsValid             = 1;
            newItem.NotValidMessage     = "New Record Key Field/s Are Required.";
            WarehouseLocationList.Add(newItem);
            _serviceAgent.AddToWarehouseLocationRepository(newItem);
            SelectedWarehouseLocation = WarehouseLocationList.LastOrDefault();

            AllowEdit     = true;
            Dirty         = false;
            AllowKeyEntry = true;
            return(true);
        }
Exemple #2
0
 private void ChangeKeyLogic()
 {
     if (!string.IsNullOrEmpty(SelectedWarehouseLocation.WarehouseLocationID))
     {//check to see if key is part of the current companylist...
         WarehouseLocation query = WarehouseLocationList.Where(company => company.WarehouseLocationID == SelectedWarehouseLocation.WarehouseLocationID &&
                                                               company.AutoID != SelectedWarehouseLocation.AutoID).FirstOrDefault();
         if (query != null)
         {//revert it back
             SelectedWarehouseLocation.WarehouseLocationID = SelectedWarehouseLocationMirror.WarehouseLocationID;
             //change to the newly selected company...
             SelectedWarehouseLocation = query;
             return;
         }
         //it is not part of the existing list try to fetch it from the db...
         WarehouseLocationList = GetWarehouseLocationByID(SelectedWarehouseLocation.WarehouseLocationID, XERP.Client.ClientSessionSingleton.Instance.CompanyID);
         if (WarehouseLocationList.Count == 0)//it was not found do new record required logic...
         {
             NotifyNewRecordNeeded("Record " + SelectedWarehouseLocation.WarehouseLocationID + " Does Not Exist.  Create A New Record?");
         }
         else
         {
             SelectedWarehouseLocation = WarehouseLocationList.FirstOrDefault();
         }
     }
     else
     {
         string errorMessage = "ID Is Required.";
         NotifyMessage(errorMessage);
         //revert back to the value it was before it was changed...
         if (SelectedWarehouseLocation.WarehouseLocationID != SelectedWarehouseLocationMirror.WarehouseLocationID)
         {
             SelectedWarehouseLocation.WarehouseLocationID = SelectedWarehouseLocationMirror.WarehouseLocationID;
         }
     }
 }
Exemple #3
0
        public void DeleteWarehouseLocationCommand()
        {
            try
            {
                int i  = 0;
                int ii = 0;
                for (int j = SelectedWarehouseLocationList.Count - 1; j >= 0; j--)
                {
                    WarehouseLocation item = (WarehouseLocation)SelectedWarehouseLocationList[j];
                    //get Max Index...
                    i = WarehouseLocationList.IndexOf(item);
                    if (i > ii)
                    {
                        ii = i;
                    }
                    Delete(item);
                    WarehouseLocationList.Remove(item);
                }

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

                    SelectedWarehouseLocation = WarehouseLocationList[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("WarehouseLocation/s Can Not Be Deleted.  Contact XERP Admin For More Details.");
                Refresh();
            }
        }
Exemple #4
0
 private void OnSearchResult(object sender, NotificationEventArgs <BindingList <WarehouseLocation> > e)
 {
     if (e.Data != null && e.Data.Count > 0)
     {
         WarehouseLocationList     = e.Data;
         SelectedWarehouseLocation = WarehouseLocationList.FirstOrDefault();
         Dirty       = false;
         AllowCommit = false;
     }
     UnregisterToReceiveMessages <BindingList <WarehouseLocation> >(MessageTokens.WarehouseLocationSearchToken.ToString(), OnSearchResult);
 }
Exemple #5
0
        //Object.Property Scope Validation...
        private bool WarehouseLocationIsValid(WarehouseLocation item, _warehouseLocationValidationProperties validationProperties, out string errorMessage)
        {
            errorMessage = "";
            switch (validationProperties)
            {
            case _warehouseLocationValidationProperties.WarehouseLocationID:
                //validate key
                if (string.IsNullOrEmpty(item.WarehouseLocationID))
                {
                    errorMessage = "ID Is Required.";
                    return(false);
                }
                EntityStates entityState = GetWarehouseLocationState(item);
                if (entityState == EntityStates.Added && WarehouseLocationExists(item.WarehouseLocationID, item.WarehouseLocationID, item.WarehouseID, item.PlantID))
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                //check cached list for duplicates...
                int count = WarehouseLocationList.Count(q => q.WarehouseLocationID == item.WarehouseLocationID);
                if (count > 1)
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                break;

            case _warehouseLocationValidationProperties.Name:
                //validate Description
                if (string.IsNullOrEmpty(item.Name))
                {
                    errorMessage = "Description Is Required.";
                    return(false);
                }
                break;

            case _warehouseLocationValidationProperties.WarehouseID:
                //validate 2nd key
                if (string.IsNullOrEmpty(item.WarehouseID))
                {
                    errorMessage = "Warehouse Is Required.";
                    return(false);
                }
                break;
            }
            return(true);
        }
Exemple #6
0
        //WarehouseLocation Object Scope Validation check the entire object for validity...
        private byte WarehouseLocationIsValid(WarehouseLocation item, out string errorMessage)
        {   //validate key
            errorMessage = "";
            if (string.IsNullOrEmpty(item.WarehouseLocationID))
            {
                errorMessage = "ID Is Required.";
                return(1);
            }
            EntityStates entityState = GetWarehouseLocationState(item);

            if (entityState == EntityStates.Added && WarehouseLocationExists(item.WarehouseLocationID, item.WarehouseLocationID, item.WarehouseID, item.PlantID))
            {
                errorMessage = "Item All Ready Exists.";
                return(1);
            }
            //check cached list for duplicates...
            int count = WarehouseLocationList.Count(q => q.WarehouseLocationID == item.WarehouseLocationID);

            if (count > 1)
            {
                errorMessage = "Item All Ready Exists...";
                return(1);
            }
            //validate Name
            if (string.IsNullOrEmpty(item.Name))
            {
                errorMessage = "Name Is Required.";
                return(1);
            }
            //validate WarehouseLocationID
            if (string.IsNullOrEmpty(item.WarehouseLocationID))
            {
                errorMessage = "Warehouse Location Is Required.";
                return(1);
            }
            //validate WarehouseID
            if (string.IsNullOrEmpty(item.WarehouseLocationID))
            {
                errorMessage = "Warehouse 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 SelectedWarehouseLocationBin_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {//these properties are not to be persisted we will igore them...
            if (e.PropertyName == "IsSelected" ||
                e.PropertyName == "IsExpanded" ||
                e.PropertyName == "IsValid" ||
                e.PropertyName == "NotValidMessage" ||
                e.PropertyName == "LastModifiedBy" ||
                e.PropertyName == "LastModifiedByDate" ||
                e.PropertyName == "PlantID" ||
                e.PropertyName == "WarehouseID")
            {//WarehouseID and PlantID or set from the WarehouseLocation selection...
                return;
            }
            //Key ID Logic...
            if (e.PropertyName == "WarehouseLocationBinID")
            {//make sure it is has changed...
                if (SelectedWarehouseLocationBinMirror.WarehouseLocationBinID != SelectedWarehouseLocationBin.WarehouseLocationBinID)
                {
                    //if their are no records it is a key change
                    if (WarehouseLocationBinList != null && WarehouseLocationBinList.Count == 0 &&
                        SelectedWarehouseLocationBin != null && !string.IsNullOrEmpty(SelectedWarehouseLocationBin.WarehouseLocationBinID))
                    {
                        ChangeKeyLogic();
                        return;
                    }

                    EntityStates entityState = GetWarehouseLocationBinState(SelectedWarehouseLocationBin);

                    if (entityState == EntityStates.Unchanged ||
                        entityState == EntityStates.Modified)
                    {                             //once a key is added it can not be modified...
                        if (Dirty && AllowCommit) //dirty record exists ask if save is required...
                        {
                            NotifySaveRequired("Do you want to save changes?", _saveRequiredResultActions.ChangeKeyLogic);
                        }
                        else
                        {
                            ChangeKeyLogic();
                        }

                        return;
                    }
                }
            }//end KeyID logic...
            //2ndary key logic... when this key is selected we will populate it upstream keys...
            if (e.PropertyName == "WarehouseLocationID" &&
                SelectedWarehouseLocationBinMirror.WarehouseLocationID != SelectedWarehouseLocationBin.WarehouseLocationID)
            {
                //look up WarehouseLocation to fetch its upstream properties...
                WarehouseLocation item = WarehouseLocationList.Where(q => q.WarehouseLocationID == SelectedWarehouseLocationBin.WarehouseLocationID).FirstOrDefault();
                SelectedWarehouseLocationBin.WarehouseID = item.WarehouseID;
                SelectedWarehouseLocationBin.PlantID     = item.PlantID;
            }

            object propertyChangedValue = SelectedWarehouseLocationBin.GetPropertyValue(e.PropertyName);
            object prevPropertyValue    = SelectedWarehouseLocationBinMirror.GetPropertyValue(e.PropertyName);
            string propertyType         = SelectedWarehouseLocationBin.GetPropertyType(e.PropertyName);
            //in some instances the value is not really changing but yet it still is tripping property change..
            //This will ensure that the field has physically been modified...
            //As well when we revert back it constitutes a property change but they will be = and it will bypass the logic...
            bool objectsAreEqual;

            if (propertyChangedValue == null)
            {
                if (prevPropertyValue == null)//both values are null
                {
                    objectsAreEqual = true;
                }
                else//only one value is null
                {
                    objectsAreEqual = false;
                }
            }
            else
            {
                if (prevPropertyValue == null)//only one value is null
                {
                    objectsAreEqual = false;
                }
                else //both values are not null use .Equals...
                {
                    objectsAreEqual = propertyChangedValue.Equals(prevPropertyValue);
                }
            }
            if (!objectsAreEqual)
            {
                //Here we do property change validation if false is returned we will reset the value
                //Back to its mirrored value and return out of the property change w/o updating the repository...
                if (WarehouseLocationBinPropertyChangeIsValid(e.PropertyName, propertyChangedValue, prevPropertyValue, propertyType))
                {
                    Update(SelectedWarehouseLocationBin);
                    //set the mirrored objects field...
                    SelectedWarehouseLocationBinMirror.SetPropertyValue(e.PropertyName, propertyChangedValue);
                    SelectedWarehouseLocationBinMirror.IsValid         = SelectedWarehouseLocationBin.IsValid;
                    SelectedWarehouseLocationBinMirror.IsExpanded      = SelectedWarehouseLocationBin.IsExpanded;
                    SelectedWarehouseLocationBinMirror.NotValidMessage = SelectedWarehouseLocationBin.NotValidMessage;
                }
                else
                {
                    SelectedWarehouseLocationBin.SetPropertyValue(e.PropertyName, prevPropertyValue);
                    SelectedWarehouseLocationBin.IsValid         = SelectedWarehouseLocationBinMirror.IsValid;
                    SelectedWarehouseLocationBin.IsExpanded      = SelectedWarehouseLocationBinMirror.IsExpanded;
                    SelectedWarehouseLocationBin.NotValidMessage = SelectedWarehouseLocationBinMirror.NotValidMessage;
                }
            }
        }
Exemple #8
0
 public void ClearLogic()
 {
     WarehouseLocationList.Clear();
     SetAsEmptySelection();
 }