linq to entity 的复杂计算,计算时间差并求和等问题,在线等!!!

haohaocrazy 2014-01-15 04:31:01
我现在有两张表,一张是测试任务表,一张是测试用例表,每一个测试任务下面都会有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;
}
...全文
156 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
發糞塗牆 2014-01-15
  • 打赏
  • 举报
回复
那建议你发到这里问问吧
haohaocrazy 2014-01-15
  • 打赏
  • 举报
回复
我现在做的项目是asp.net的,操作数据库引用的是EDM模型,所以用的是linq,直接用SQL不知道怎么用了。。这是我第一个ASP.NET的项目,还是自己一个人做。纠结了一天了~
LongRui888 2014-01-15
  • 打赏
  • 举报
回复
linq的看不太懂。。。 能不能直接用sql来计算呢
haohaocrazy 2014-01-15
  • 打赏
  • 举报
回复
自己顶起来,菜鸟学习中,求大神指点迷津,谢谢

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧