示例#1
0
        public Customer(CustomerName name, Address address)
        {
            if (address == null)
            {
                throw new ArgumentException("A customer's address cannot be set to nothing");
            }
            if (name == null)
            {
                throw new ArgumentException("A customer's name cannot be set to nothing");
            }
            if (name.Id < 0)
            {
                throw new ArgumentException("A customer canoot have a negative id");
            }
            if (name.Id == 0)
            {
                _id = GenerateNewId();
            }
            else
            {
                _id = name.Id;
            }

            _address = address;
            _name    = name;
        }
示例#2
0
        void GetCustomers()
        {
            string[] customerNames     = File.ReadAllLines("CustomerNames.txt");
            string[] customerAddresses = File.ReadAllLines("CustomerAddresses.txt");

            foreach (string nextName in customerNames)
            {
                CustomerName cn = CustomerName.GetName(nextName);

                Customer c = new Customer(cn, Address.GetAddressById(customerAddresses, cn.Id));

                _customers.Add(c.Id, c);
            }
        }
示例#3
0
        public static CustomerName GetName(string dataLine)
        {
            string[]     name = dataLine.Split(',');
            CustomerName c    = new CustomerName(name[1]);

            c._customerId = Convert.ToInt32(name[0]);

            if (name.Length > 2)
            {
                c.FirstName = name[2];
            }

            if (name.Length > 3)
            {
                for (int i = 3; i < name.Length; i++)
                {
                    c.MiddleNames.Add(name[i]);
                }
            }
            return(c);
        }