// get from and to counts between emailId and other emails public Dictionary<int, FromToInfo> SQLGetFromToTotals(int accountId) { Dictionary<int, FromToInfo> info = new Dictionary<int, FromToInfo>(); DataTable table = sqlData.GetDataTable(String.Format("SELECT * FROM FromToCounts WHERE AccountId1={0} OR AccountId2={0}", accountId)); foreach (DataRow row in table.Rows) { if (accountId == (int)(long)row[0]) info[(int)(long)row[1]] = new FromToInfo() { ToCount = (int)(long)row[2], FromCount = (int)(long)row[3] }; else info[(int)(long)row[1]] = new FromToInfo() { FromCount = (int)(long)row[2], ToCount = (int)(long)row[3] }; } return info; }
// get from and to counts between emailId and other emails protected Dictionary<int, FromToInfo> SQLGetAccountIdTotals() { Dictionary<int, FromToInfo> info = new Dictionary<int, FromToInfo>(); DataTable table = sqlData.GetDataTable("SELECT AccountId, FromTotal, ToTotal FROM Accounts"); foreach (DataRow row in table.Rows) info[(int)(long)row[0]] = new FromToInfo() { FromCount = (int)(long)row[1], ToCount = (int)(long)row[2] }; return info; }
// increase the counts in the dictionary private void SQLAddToDict(Dictionary<int, FromToInfo> dict, int key, int fromCount, int toCount) { if (!dict.ContainsKey(key)) dict[key] = new FromToInfo(); dict[key].FromCount += fromCount; dict[key].ToCount += toCount; }
public Dictionary<int, FromToInfo> GetPersonIdTotals() { Dictionary<int, FromToInfo> accountIdTotals = GetAccountIdTotals(); Dictionary<int, FromToInfo> personIdTotals = new Dictionary<int, FromToInfo>(); foreach (var person in GetPeople()) { FromToInfo info = new FromToInfo(); foreach (int id in person.GetAccountIds()) { if (accountIdTotals.ContainsKey(id)) { info.FromCount += accountIdTotals[id].FromCount; info.ToCount += accountIdTotals[id].ToCount; } } personIdTotals[person.PersonId] = info; } return personIdTotals; }