private ManagerL6 AddToQl6Tree(long calcAccountId) { // Get level and level_index var lastestChild = (ManagerL6)m_PersistenceManager.GetQlLatestChild <ManagerL6>(); // Find Parent account if (lastestChild == null) { var root = new ManagerL6 { AccountId = calcAccountId, ChildIndex = 0, Level = 0, LevelIndex = 0, IsActive = "Y", ParentId = -1, CreatedBy = "JOB", CreatedDate = DateTime.Now }; m_PersistenceManager.Save(root); return(root); } else { var newLevel = lastestChild.Level; var newLevelIndex = lastestChild.LevelIndex + 1; if (Math.Pow(3, lastestChild.Level) == lastestChild.LevelIndex) { newLevel = lastestChild.Level + 1; newLevelIndex = 1; } var parentLevel = newLevel - 1; var parentLevelIndex = (newLevelIndex % 3 > 0) ? ((newLevelIndex / 3) + 1) : (newLevelIndex / 3); var managerParent = (ManagerL6)m_PersistenceManager.FindQlByLocation <ManagerL6>(parentLevel, parentLevelIndex); // Insert into QL6 tree var newNode = new ManagerL6 { AccountId = calcAccountId, ChildIndex = (newLevelIndex % 3) == 0 ? 3 : newLevelIndex % 3, Level = newLevel, LevelIndex = newLevelIndex, IsActive = "Y", ParentId = managerParent.AccountId, CreatedBy = "JOB", CreatedDate = DateTime.Now }; m_PersistenceManager.Save(newNode); return(newNode); } }
private void CalculateBonusOfQl6(ManagerL6 newManager) { // Hoa hong quan ly m_PersistenceManager.SaveAccountBonus(newManager.ParentId, ConstUtil.BONUS_TYPE_QL6.Amount, ConstUtil.BONUS_TYPE_QL6.Type); var firstUpLevel = (ManagerL6)m_PersistenceManager.GetManagerLevel <ManagerL6>(newManager.ParentId); ManagerL6 secondUpLevel = null; if (firstUpLevel != null && firstUpLevel.Level != 0) { m_PersistenceManager.SaveAccountBonus(firstUpLevel.ParentId, ConstUtil.BONUS_TYPE_QL6.Amount, ConstUtil.BONUS_TYPE_QL6.Type); secondUpLevel = (ManagerL6)m_PersistenceManager.GetManagerLevel <ManagerL4>(firstUpLevel.ParentId); if (secondUpLevel != null && secondUpLevel.Level != 0) { m_PersistenceManager.SaveAccountBonus(secondUpLevel.ParentId, ConstUtil.BONUS_TYPE_QL6.Amount, ConstUtil.BONUS_TYPE_QL6.Type); } } // Can cap if ((newManager.LevelIndex % 3) != 1) { m_PersistenceManager.SaveAccountBonus(newManager.ParentId, ConstUtil.BONUS_TYPE_CCL6.Amount, ConstUtil.BONUS_TYPE_CCL6.Type); if (firstUpLevel != null && firstUpLevel.ParentId != -1) { m_PersistenceManager.SaveAccountBonus(firstUpLevel.ParentId, ConstUtil.BONUS_TYPE_CCL6.Amount, ConstUtil.BONUS_TYPE_CCL6.Type); if (secondUpLevel != null && secondUpLevel.Level != 0) { m_PersistenceManager.SaveAccountBonus(secondUpLevel.ParentId, ConstUtil.BONUS_TYPE_CCL6.Amount, ConstUtil.BONUS_TYPE_CCL6.Type); } } } }