示例#1
0
        // Returns a list of random contracts
        public static List <Contracts> ListRandomContracts()
        {
            Random           rand         = new Random();
            var              customerList = CustomerDataAccess.GetCustomerList();
            var              hireList     = DataAccessLayer.GetHireList();
            List <Contracts> contractList = new List <Contracts>();

            // Generates 25 random contracts but this could easily be 5 or 50
            for (int i = 0; i < 25; i++)
            {
                int     rContractID    = rand.Next(1, 500);
                decimal rContractValue = rand.Next(1, 500);
                // Create an index of the amount of customers/nireassets to create a random
                int index  = rand.Next(customerList.Count);
                int index2 = rand.Next(hireList.Count);
                // Create two temp customers and hireasssets
                Customer  rCustomer  = customerList[index];
                HireAsset rHireAsset = hireList[index2];

                // Create the contracts object
                Contracts contract = new Contracts()
                {
                    contractID    = rContractID,
                    contractValue = rContractValue,
                    customer      = rCustomer,
                    item          = rHireAsset
                };

                // Add it to the list
                contractList.Add(contract);
            }
            // Return it for use in the listbox
            return(contractList);
        }
示例#2
0
        // Method to create a new contract based on a specific customer and hireAsset.
        public static Contracts addContract(Customer _customer, HireAsset hireAsset)
        {
            // Create an instance of random
            Random rand = new Random();

            Contracts newContract = new Contracts()
            {
                // Just create a random contract ID and value for show
                contractID    = rand.Next(1, 500),
                contractValue = rand.Next(1, 500),
                customer      = _customer,
                item          = hireAsset
            };

            // The method returns a type of Contracts so that can be added to the list we have alreadym
            return(newContract);
        }