Exemplo n.º 1
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;
         }
     }
 }
Exemplo n.º 2
0
        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;
                }
            }
        }