Exemplo n.º 1
0
        private void DeletePlate(object obj)
        {
            PlateCount pc = obj as PlateCount;

            Plates.Remove(pc);
            UpdateAvailablePlates();
        }
Exemplo n.º 2
0
        public bool SetPlates(String tex, int plates)
        {
            bool changed = false;
            int  current = 0;
            var  plate   = _plates.FirstOrDefault(t => t.Tex == Texture.GetTexture(tex));

            if (plate == null)
            {
                plate = new PlateCount(Texture.GetTexture(tex), plates, PlateChanged);
                _plates.Add(plate);
                changed = true;
            }
            else
            {
                bool changePossible = true;

                current = plate.Count;

                // check usage if lowering
                int change = plates - current;

                if (change <= NumAvailablePlates)
                {
                    if (change > 0) // Adding plates, no need to check if this effects production
                    {
                        plate.Count         = plates;
                        NumAvailablePlates += change;
                        changed             = true;
                    }
                    else
                    {
                        foreach (var pressShift in Shifts)
                        {
                            var potentialOutputUnits = 30; // normally 30 units of output, but depends on the thickness in the press

                            var actualOutput =
                                pressShift.Produced.Where(m => m.MasterItem.Texture.Contains(tex))
                                .Sum(i => i.UnitsMade * i.MasterItem.PiecesPerUnit);
                            if (actualOutput > potentialOutputUnits)
                            {
                                changePossible = false;
                                break;
                            }
                        }

                        if (changePossible)
                        {
                            plate.Count         = plates;
                            NumAvailablePlates += change;
                            changed             = true;
                        }
                    }
                }
            }

            return(changed);
        }
Exemplo n.º 3
0
        private void PlateChanged(object sender, PropertyChangedEventArgs e)
        {
            PlateCount pc = sender as PlateCount;

            UpdateAvailablePlates();
            int availablePlates = NumAvailablePlates;

            //prevent too many plates
            if (availablePlates < 0)
            {
                if (pc != null)
                {
                    pc.Count += availablePlates;
                }
                NumAvailablePlates = 0;
            }
            else
            {
                NumAvailablePlates = availablePlates;
            }
        }