public MeterAlarmSetViewModel GetViewModel(string userName) { MeterAlarmSetViewModel viewModel = new MeterAlarmSetViewModel(); string buildID = ""; string energyCode = ""; viewModel.Builds = tvContext.GetBuildsByUserName(userName); if (viewModel.Builds.Count > 0) { buildID = viewModel.Builds.First().BuildID; } List <EnergyItemDict> energys = tvContext.GetEnergyItemDictByBuild(buildID); if (energys.Count > 0) { energyCode = energys.First().EnergyItemCode; } List <TreeViewModel> treeView = tvContext.GetCircuitTreeListViewModel(buildID, energyCode); List <MeterAlarmSet> data = context.GetMeterParamList(buildID, treeView.First().Id); viewModel.Energys = energys; viewModel.TreeView = treeView; viewModel.Data = data; return(viewModel); }
public NoWorkDayViewModel GetViewModel(string userName) { DateTime today = DateTime.Now; string beginDate = today.ToString("yyyy-MM-01 00:00:00"); string endDate = today.ToString("yyyy-MM-dd HH:mm:00"); string energyCode = ""; IHomeDbContext homeContext = new HomeDbContext(); List <BuildViewModel> builds = homeContext.GetBuildsByUserName(userName); string buildID = ""; if (builds.Count > 0) { buildID = builds.First().BuildID; } List <EnergyItemDict> energys = tvcontext.GetEnergyItemDictByBuild(buildID); if (energys.Count > 0) { energyCode = energys.First().EnergyItemCode; } List <TreeViewModel> treeView = tvcontext.GetCircuitTreeListViewModel(buildID, energyCode); List <NoWorkDay> data = context.GetCircuitData(buildID, energyCode, beginDate, endDate); NoWorkDayViewModel viewModel = new NoWorkDayViewModel(); viewModel.Builds = builds; viewModel.Energys = energys; viewModel.TreeView = treeView; viewModel.Data = data; return(viewModel); }