public async Task <IActionResult> Edit(int id, [Bind("deviceFlowHistoryId,deviceId,fromLocation,toLocation,fromDepartmentId,toDepartmentId,fromMemberId,toMemberId,flowDateTime,deviceStatus")] DeviceFlowHistory deviceFlowHistory) { if (id != deviceFlowHistory.deviceFlowHistoryId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(deviceFlowHistory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DeviceFlowHistoryExists(deviceFlowHistory.deviceFlowHistoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["deviceId"] = new SelectList(_context.Device, "deviceId", "contractNo", deviceFlowHistory.deviceId); ViewData["fromDepartmentId"] = new SelectList(_context.Department, "departmentId", "departmentName", deviceFlowHistory.fromDepartmentId); ViewData["fromMemberId"] = new SelectList(_context.Member, "memberId", "employeeId", deviceFlowHistory.fromMemberId); ViewData["toDepartmentId"] = new SelectList(_context.Department, "departmentId", "departmentName", deviceFlowHistory.toDepartmentId); ViewData["toMemberId"] = new SelectList(_context.Member, "memberId", "employeeId", deviceFlowHistory.toMemberId); return(View(deviceFlowHistory)); }
public async Task <IActionResult> Create([Bind("deviceFlowHistoryId,deviceId,fromLocation,toLocation,fromDepartmentId,toDepartmentId,fromMemberId,toMemberId,flowDateTime,deviceStatus")] DeviceFlowHistory deviceFlowHistory) { if (ModelState.IsValid) { _context.Add(deviceFlowHistory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["deviceId"] = new SelectList(_context.Device, "deviceId", "contractNo", deviceFlowHistory.deviceId); ViewData["fromDepartmentId"] = new SelectList(_context.Department, "departmentId", "departmentName", deviceFlowHistory.fromDepartmentId); ViewData["fromMemberId"] = new SelectList(_context.Member, "memberId", "employeeId", deviceFlowHistory.fromMemberId); ViewData["toDepartmentId"] = new SelectList(_context.Department, "departmentId", "departmentName", deviceFlowHistory.toDepartmentId); ViewData["toMemberId"] = new SelectList(_context.Member, "memberId", "employeeId", deviceFlowHistory.toMemberId); return(View(deviceFlowHistory)); }
public async Task <IActionResult> Create([Bind("deviceId,contractNo,devModelId,createTime,inWareHouse,devCount,toLocation")] MultiDev multidev) { //DeviceFlowHistory history = new DeviceFlowHistory { toLocation = multidev.toLocation, flowDateTime = multidev.createTime, deviceStatus = ToyForSI.Models.Enum.DeviceStatus.Warehouse }; //multidev.historys = new List<DeviceFlowHistory>() { history }.AsEnumerable(); if (ModelState.IsValid) { //List<Device> devices=new List<Device>(); for (int idx = 0; idx != multidev.devCount; idx++) { DevModel devModel = _context.DevModel.FirstOrDefault(d => d.devModelId == multidev.devModelId); DeviceFlowHistory history = new DeviceFlowHistory { toLocation = multidev.toLocation, flowDateTime = multidev.createTime, deviceStatus = ToyForSI.Models.Enum.DeviceStatus.Warehouse }; List <DeviceFlowHistory> h = new List <DeviceFlowHistory> { history }; Device device = new Device { contractNo = multidev.contractNo, devModelId = multidev.devModelId, createTime = multidev.createTime, inWareHouse = multidev.inWareHouse, historys = h.AsEnumerable() }; _context.Add(device); } await _context.SaveChangesAsync(); //foreach (Device d in devices) //{ // DeviceFlowHistory history = new DeviceFlowHistory { toLocation = multidev.toLocation, deviceId = d.deviceId, transferDateTime = DateTime.Now }; // _context.Add(history); //} //await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["devModelId"] = new SelectList(_context.DevModel, "devModelId", "devModelName", multidev.devModelId); return(View(multidev)); }
public async Task <IActionResult> Do(int?id) { if (id == null) { return(NotFound()); } var device = await _context.Device.Include(d => d.historys) .Include(d => d.devModel).ThenInclude(m => m.brand) .Include(d => d.devModel).ThenInclude(m => m.equipmentType) .SingleOrDefaultAsync(m => m.deviceId == id); if (device == null) { return(NotFound()); } DeviceFlowHistory history = new DeviceFlowHistory(); history.deviceStatus = ToyForSI.Models.Enum.DeviceStatus.Normal; history.deviceId = device.deviceId; history.flowDateTime = DateTime.Now; history.device = device; ViewData["fromDepartmentId"] = new List <SelectListItem>() { new SelectListItem() { Value = "", Text = "无" } }; ViewData["fromMemberId"] = new List <SelectListItem>() { new SelectListItem() { Value = "", Text = "无" } }; ViewData["fromLocation"] = new List <SelectListItem>() { new SelectListItem() { Value = "", Text = "无" } }; if (device.historys.ToList().Count != 0) { var lastHistory = device.historys.OrderBy(c => c.deviceFlowHistoryId).ToList().Last(); history.fromLocation = lastHistory.toLocation; history.fromDepartmentId = lastHistory.toDepartmentId; history.fromMemberId = lastHistory.toMemberId; var toDepart = lastHistory.toDepartmentId; if (toDepart.HasValue) { ViewData["fromDepartmentId"] = new SelectList(_context.Department.Where(d => d.departmentId == history.fromDepartmentId), "departmentId", "departmentName", history.fromDepartmentId); } if (lastHistory.toMemberId.HasValue) { ViewData["fromMemberId"] = new SelectList(_context.Member, "memberId", "name", history.fromMemberId); } if (history.fromLocation != string.Empty) { if (history.fromLocation != null) { ViewData["fromLocation"] = new List <SelectListItem>() { new SelectListItem() { Value = history.fromLocation, Text = history.fromLocation } }; } } } ViewData["deviceId"] = new List <SelectListItem>() { new SelectListItem() { Value = id.ToString(), Text = device.devModel.brand.brandName + device.devModel.devModelName + device.devModel.equipmentType.equipmentTypeName } }; ViewData["toDepartmentId"] = new SelectList(_context.Department, "departmentId", "departmentName", history.toDepartmentId); ViewData["toMemberId"] = new SelectList(_context.Member, "memberId", "name", history.toMemberId); //ViewData["deviceStatus"]=GetEnumSelectList<ToyForSI.Models.Enum.DeviceStatus>(); return(View(history)); }
public async Task <IActionResult> Do([Bind("deviceId,fromDepartmentId,fromMemberId,fromLocation,toDepartmentId,toMemberId,toLocation,deviceStatus,flowDateTime")] DeviceFlowHistory history, bool configNetwork) { if (ModelState.IsValid) { //List<Device> devices=new List<Device>(); var lastHistory = await _context.DeviceFlowHistory.Where(h => h.deviceId == history.deviceId).OrderBy(d => d.deviceId).LastOrDefaultAsync(); if (lastHistory != null) { if (lastHistory.toLocation != history.toLocation || lastHistory.toDepartmentId != history.toDepartmentId || lastHistory.toMemberId != history.toMemberId || lastHistory.deviceStatus != history.deviceStatus) { _context.Add(history); } } else { _context.Add(history); } await _context.SaveChangesAsync(); //foreach (Device d in devices) //{ // DeviceFlowHistory history = new DeviceFlowHistory { toLocation = multidev.toLocation, deviceId = d.deviceId, transferDateTime = DateTime.Now }; // _context.Add(history); //} //await _context.SaveChangesAsync(); if (!configNetwork) { return(RedirectToAction(nameof(Index))); } } var device = await _context.Device.Include(d => d.historys).Include(d => d.devModel).SingleOrDefaultAsync(m => m.deviceId == history.deviceId); if (device == null) { return(NotFound()); } history.flowDateTime = DateTime.Now; history.device = device; ViewData["fromDepartmentId"] = new List <SelectListItem>() { new SelectListItem() { Value = "", Text = "无" } }; ViewData["fromMemberId"] = new List <SelectListItem>() { new SelectListItem() { Value = "", Text = "无" } }; ViewData["fromLocation"] = new List <SelectListItem>() { new SelectListItem() { Value = "", Text = "无" } }; ViewData["deviceId"] = new List <SelectListItem>() { new SelectListItem() { Value = history.deviceId.ToString(), Text = device.devModel.devModelName } }; ViewData["toDepartmentId"] = new SelectList(_context.Department, "departmentId", "departmentName", history.toDepartmentId); ViewData["toMemberId"] = new SelectList(_context.Member, "memberId", "name", history.toMemberId); if (history.fromDepartmentId.HasValue) { ViewData["fromDepartmentId"] = new SelectList(_context.Department.Where(d => d.departmentId == history.fromDepartmentId), "departmentId", "departmentName", history.fromDepartmentId); } if (history.fromMemberId.HasValue) { ViewData["fromMemberId"] = new SelectList(_context.Member, "memberId", "name", history.fromMemberId); } if (history.fromLocation != string.Empty) { ViewData["fromLocation"] = new List <SelectListItem>() { new SelectListItem() { Value = history.fromLocation, Text = history.fromLocation } }; } return(View(history)); }