Exemplo n.º 1
0
        public void AddProducer(Producer pd)
        {
            if (_producers.ContainsKey(pd.ID))
                throw new ArgumentException(string.Format("ProducerID ({0}) already belongs to another producer: {1}({2})", pd.ID, _producers[pd.ID].ID, _producers[pd.ID].Name));

            if (pd.DisplayColour != Color.Empty) {
                throw new AccessViolationException("Producer likely belongs to another set of producers and forgot to return it's display colour, call Producers.RemoveProducer() first.");
            }
            if (_availableColours.Count == 0)
                throw new InvalidOperationException("There are no more colours to give out, either remove some producers, or ask the dev to add more colours.");

            pd.SetColour(_availableColours.Pop());
            _producers.Add(pd.ID, pd);
        }
Exemplo n.º 2
0
        public Producers ReadProducers()
        {
            Producers pd = new Producers();
            Producer dummy = null;

            #if DEBUG
            Console.WriteLine("Reading producers");
            #endif

            _rObj = _worksheet[0].Range[SearchCellProducers, Missing.Value];
            _rObj = _rObj.End[XlDirection.xlDown];
            string downAddress = _rObj.Address[false, false, XlReferenceStyle.xlA1, Missing.Value, Missing.Value];
            _rObj = _worksheet[0].Range[StartingCellProducers, "A" + downAddress.Substring(1)];
            object[,] values = (object[,])_rObj.Value2;
            for (int i = 1; i <= values.GetLength(0); i++) {
                if ((string)values[i,1] != null) {
                    dummy = new Producer();
                    dummy.ParseFromString((string)values[i,1]);
                    pd.AddProducer(dummy);
                }
                Debug.Assert(dummy != null, "dummy != null");
                pd.AddProduct(dummy.ID, _worksheet[0].Cells[i + StartingRowOffsetProducers, 2].Value2);
            }

            #if DEBUG
            Console.WriteLine("Successfully added {0} producer{1} with {2} product{3}",pd.Count, pd.Count != 0 ? "s" : "", pd.ProductCount, pd.ProductCount != 0 ? "s" : "");
            #endif
            Marshal.ReleaseComObject(_rObj);
            _rObj = null;
            return pd;
        }