代码阐释:我这里是取奖金支给率的排序(正序/倒叙),通过指定的公式得到tempa,tempb,tempc插入到IDictionary中.此逻辑有些乱,但是最终实现了我想要的效果,下面是我的代码及效果图.
IDictionary<string, decimal> dic = new Dictionary<string, decimal>();
decimal tempa = 0;
if (E1 != 0 || A1 != 0)
{
tempa = Convert.ToDecimal(E1 / A1);
}
decimal tempb = 0;
if (E2 != 0 || A2 != 0)
{
tempb = Convert.ToDecimal(E2 / A2);
}
decimal tempc = 0;
if (E3 != 0 || A3 != 0)
{
tempc = Convert.ToDecimal(E3 / A3);
}
dic.Add("GLB", tempa);
dic.Add("SJB", tempb);
dic.Add("JXB", tempc);
List<Dictionary<string, decimal>> listDict = new List<Dictionary<string, decimal>>();
Dictionary<string, decimal> dict = new Dictionary<string, decimal>();
var dicSort = from objDic in dic orderby objDic.Value descending select objDic;//倒叙
//var dicNew = dic.OrderBy(s1 => s1.Value);//正序
foreach (KeyValuePair<string, decimal> kvp in dicSort)
{
dict.Add(kvp.Key, kvp.Value);
listDict.Add(dict);
}
var keys = listDict[0].Keys;
List<TestClass> list = new List<TestClass>();
foreach (var key in keys)
{
TestClass test = new TestClass();
test.BM = key;
list.Add(test);
}
var bm1 = list[0].BM;
var bm2 = list[1].BM;
var bm3 = list[2].BM;
#region bm1
if (bm1 == "GLB")
{
sheetAt.GetRow(4).GetCell(12).SetCellValue(1);
}
if (bm1 == "SJB")
{
sheetAt.GetRow(5).GetCell(12).SetCellValue(1);
}
if (bm1 == "JXB")
{
}
#endregion
#region bm2
if (bm2 == "GLB")
{
sheetAt.GetRow(4).GetCell(12).SetCellValue(2);
}
if (bm2 == "SJB")
{
sheetAt.GetRow(5).GetCell(12).SetCellValue(2);
}
if (bm2 == "JXB")
{
sheetAt.GetRow(6).GetCell(12).SetCellValue(2);
}
#endregion
#region bm3
if (bm3 == "GLB")
{
sheetAt.GetRow(4).GetCell(12).SetCellValue(3);
}
if (bm3 == "SJB")
{
sheetAt.GetRow(5).GetCell(12).SetCellValue(3);
}
if (bm3 == "JXB")
{
sheetAt.GetRow(6).GetCell(12).SetCellValue(3);//应发奖金支给率排名
}
#endregion