haohaocrazy 2014年01月15日
linq to entity 的复杂计算,计算时间差并求和等问题,在线等!!!
我现在有两张表,一张是测试任务表,一张是测试用例表,每一个测试任务下面都会有N个测试用例,并且测试用例会有重复的,因为一条用例可能执行了好多遍,关联关系为PlanId,每一个测试用例都会有开始时间和结束时间,现在我想做的是:先根据planId过滤出来不同名称的用例,然后根据用例名称和planid去计算每一条用例的测试时间,也就是结束时间和开始时间的差,然后把相同名称的用例的测试时间加和。我要的就是这个和。求大神给写个demo。

下面是我的代码:
public List<ExcelInfo> GetExcelDetailsByInformation(List<testplan> testplanlist)
{
string planName="";
string caseName = "";
int times=0;
string time = "";
string username = "";
string editionName = "";


testplan tp = new testplan();
List<testplan> testplanList = new List<testplan>();
List<ExcelInfo> excelList = new List<ExcelInfo>();
ExcelInfo excelInfo = new ExcelInfo();
List<testcase> TestCaseList = new List<testcase>();
testplanList = testplanlist;
for (int i = 0; i < testplanList.Count;i++ )
{
tp = testplanList[i];
int failed = 0;
int pass = 0;
int noRun = 0;
string Planname = testplanList.ElementAt(i).planname.ToString();
string Username = testplanList.ElementAt(i).pusername.ToString();
string editionNames = testplanList.ElementAt(i).edition.ToString();
int planId = Convert.ToInt32(testplanList.ElementAt(i).testplanid);
string[] mTestCaseName = (from c in men.testcase where (c.planid == planId) select c.casename).Distinct().ToArray();


for (int k = 0; k < mTestCaseName.Length; k++)
{
float hour = (float)0.0;
string sname = mTestCaseName[k];

var testcasefail = (from c in men.testcase where (c.planid == planId && c.casename == sname && c.result == "fail") select c);
failed = testcasefail.Count();
var testcasepass = (from c in men.testcase where (c.planid == planId && c.casename == sname && c.result == "pass") select c);
pass = testcasepass.Count();
var testcasenorun = (from c in men.testcase where (c.planid == planId && c.casename == sname && c.result == "norun") select c);
noRun = testcasenorun.Count();
List<testcase> TestCase = (from c in men.testcase where (c.planid == planId && c.username == Username && c.casename == sname) select c).ToList();
var tcs = from c in men.testcase where (c.planid == planId && c.username == Username && c.casename == sname) select new {}
for (int m = 0; m < TestCase.Count; m++)
{
TimeSpan ts = new TimeSpan(0);
DateTime start = Convert.ToDateTime(TestCase[m].time);
DateTime end = Convert.ToDateTime(TestCase[m].endtime);
ts = end.Subtract(start);
float dh = ((float)ts.Days * 24);
float hh = ((float)ts.Hours);
float mh = ((float)ts.Minutes / 60);
float sh = ((float)ts.Seconds / 3600);
hour = (dh + hh + mh + sh) + hour;
time = hour.ToString("F3");
}
times = failed + pass + noRun;
int success = pass;
float rate = (float)pass / (float)times * 100;
string rates = rate.ToString("F2") + "%";
caseName = sname;
planName = Planname;
username = Username;
editionName = editionNames;
excelInfo = new ExcelInfo(editionName, planName, username, caseName, times, time, success, failed, noRun, rates);
excelList.Add(excelInfo);
}
}
return excelList;
}
...全文
87 点赞 收藏 4
写回复
4 条回复

还没有回复,快来抢沙发~

发动态
发帖子
疑难问题
创建于2007-09-28

9300

社区成员

12.1w+

社区内容

MS-SQL Server 疑难问题
社区公告
暂无公告