示例#1
0
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            var context = (PartsDataContext)this.DataContext;

            if (CheckForError() == false)
            {
                //if null then its a new item, otherwise update existing
                if (CurrentLocation != null)
                {
                    CurrentLocation.Quantity  = int.Parse(quantityTextBox.Text);
                    CurrentLocation.BinNumber = binTextBox.Text;
                    context.UpdateObject(CurrentLocation);
                }
                else
                {
                    InventoryLocationsItem locationsItem = new InventoryLocationsItem();
                    locationsItem.Quantity  = int.Parse(quantityTextBox.Text);
                    locationsItem.BinNumber = binTextBox.Text;
                    locationsItem.PartId    = this.currentPartId;
                    context.AddToInventoryLocations(locationsItem);
                    inventoryLocations.Add(locationsItem);
                    this.CurrentLocation = locationsItem;
                }
                context.BeginSaveChanges(SaveChangesOptions.Batch, OnSaveChanges, null);
            }
        }
        public string InventoryLocationSaved()
        {
            string error = ValidateSaveInputs(currentLocation.BinNumber, currentLocation.Quantity);

            if (error == null)
            {
                //if null then its a new item, otherwise update existing
                if (CurrentLocation != newLocation)
                {
                    //CurrentLocation represents an object that is already in the data context and observable
                    //collection.  We just need to update the values.
                    context.UpdateObject(CurrentLocation);
                }
                else
                {
                    //This is a new item, so we need to add a new item to the context.
                    newLocation.PartId = CurrentPart.Id;

                    //Add to the data context
                    context.AddToInventoryLocations(newLocation);

                    //Add to the observable collection
                    this.currentInventoryLocations.Add(newLocation);

                    this.CurrentLocation = newLocation;
                    newLocation          = null;
                }

                context.BeginSaveChanges(SaveChangesOptions.Batch, OnSaveChanges, null);
            }

            return(error);
        }
        public void SetNewLocation()
        {
            if (newLocation == null)
            {
                newLocation = new InventoryLocationsItem();
            }
            else
            {
                newLocation.BinNumber = string.Empty;
                newLocation.Quantity  = null;
            }

            CurrentLocation = newLocation;
        }