If A, B get same wallet.dat file, and after that, if B encrypt his computer's wallet program(or daemon) (B2), then what happen?
Given that you specifically mention "wallet.dat"... I will assume that you are referring to Bitcoin Core. The answers below are only valid for Bitcoin Core. Other wallets like Electrum deal with encryption in a different manner.
NOTE: it is important to understand that there will be quite a large number of pre-generated addresses already in the wallet (default keypool size for HD wallets in Bitcoin Core is 1000, older non-HD wallets had a keypool of 100). Using "generated before encryption" or "generated after encryption" could be a little misleading in this instance. As addresses may have already been created and stored in the wallet file, but they are only displayed to the user when the user clicks the "new receiving address" button. New addresses are only actually generated and added into the wallet file when the keypool is refilled.
All coins received via address generated before encryption, B can use them also?
Yes. A+B will have access to the same history and current keypool.
And all coins received via address generated after encryption, only B can use them?
Depends if the wallet.dat is an HD wallet (default from Bitcoin Core v0.13+) or an older non-HD wallet.
In a Bitcoin Core "HD" wallet... whenever you enable encryption (or change the password)... the "old" seed and addresses are marked as "inactive"... and a new seed is generated and a new "active" keypool is created with addresses based off the new seed (which A will not have). I'm not sure if the old seed is still stored in the wallet, but I
suspect it is.
However, the old addresses are still stored in the wallet.dat, so B will still have access to addresses that A had at the time the wallet was encrypted. I am not sure if encrypted B still contains a copy of the original seed. A "dumpwallet" on a newly encrypted file (or one with a recently changed password) only shows the current extended master key (and does not output any seed). So I'm not sure if B is still able to generate addresses on the "old" seed after A exhausts the keypool that B had a copy of and begins to generate addresses that B had not generated from the old seed yet.
In short:
B will have old A addresses and new B addresses
A will only have old A addresses.
In an older Bitcoin Core "non-HD" wallet... both A and B will still have the same keypool... so until that is exhausted, A and B will be using the same addresses. Over time, as the individual keypools in A and B are replenished with new randomly generated addresses, they'll be generating addresses that the other wallet does not contain.
In short:
B will have old A addresses + new B Addresses
A will have old A addresses + new A Addresses
And all coins received via address generated after encryption at A's computer (A2), A and B can use them?
I'm not sure if you mean that A then encrypts their wallet? Or do you mean original A wallet with no Encryption?
If A encrypts their wallet as well:
For HD, both A and B will now have new seed + new keypool... they'll both have access to original pre-encryption addresses... but will be both have new keypool with different addresses from this point.
For non-HD, both A and B will have access to original pre-encryption addresses + keypool... A will start generating addresses that B does not have as keypool is replenished.
If A doesn't encrypt their wallet:
For HD, A and B have access to original pre-encryption addresses... B will not be generating the new addresses that A generates as B is using new seed. I'm not sure if B can still access the original seed and continue to generate addresses that A will.
For non-HD, A and B have access to original addresses+keypool at the time the wallet.dat was copied... As the keypool is replenished A and B will then be generating different random addresses to replenish their respective keypools.