/// <summary>
/// 获取一批产品的单位列表字典。
/// </summary>
/// <param name="productId"></param>
/// <returns></returns>
public Dictionary<int, List<ProductUnit>> GetProductUnitListDicByProductIdList(IList<int> ids)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select Id,Product_Id,UnitName,Conversion,IsDefaultUnit,IsBasicUnit,SortNo ");
strSql.Append(" FROM T_Product_Unit ");
if (ids != null && ids.Count > 0)
{
strSql.Append(" Where Product_Id in (");
for (int i = 0; i < ids.Count; i++)
{
strSql.Append(ids[i]);
strSql.Append(",");
}
strSql.Remove(strSql.Length - 1, 1);
strSql.Append(")");
}
Dictionary<int, List<ProductUnit>> unitdic = new Dictionary<int, List<ProductUnit>>();
_dbCommand = _database.GetSqlStringCommand(strSql.ToString());
using (IDataReader reader = _database.ExecuteReader(_dbCommand))
{
while (reader.Read())
{
ProductUnit pu = ReaderBind(reader);
List<ProductUnit> pus = null;
if (unitdic.TryGetValue(pu.ProductId, out pus) == false)
{
pus = new List<ProductUnit>();
unitdic[pu.ProductId] = pus;
}
pus.Add(pu);
}
}
return unitdic;
}