partial         void Opportunities_Inserted(Opportunity entity)
        {
            // Calculate a new opportunity number
            if(entity.OpportunityNumber == null)
            {
                int year = DateTime.Today.Year;
                string an = entity.Account.AccountNumber;

                int count = this.DataWorkspace.CRMData.Opportunities.Count(x => x.Created.Value.Year == year);
                if (count <= 0)
                    count = 1;
                entity.OpportunityNumber = string.Format("{0}{1}{2:00}", an, year, count);
            }

            // Update account type
            if (entity.Account.AccountType == "O")
                entity.Account.AccountType = "A";
        }
partial         void Opportunities_Validate(Opportunity entity, EntitySetValidationResultsBuilder results)
        {
        }
partial         void Opportunities_Updated(Opportunity entity)
        {
            if (entity.Account.AccountType == "O")
                entity.Account.AccountType = "A";
        }