public static ElementVM CreateElementVMByElement(Element element) { ElementVM toReturn; switch (element.Type) { case ElementType.Element: toReturn = new ElementVM(element); break; case ElementType.Port: toReturn = new PortVM(element); break; case ElementType.ResistorInSeries: toReturn = new ResistorInSeriesVM(element); break; case ElementType.ResistorInParallel: toReturn = new ResistorInParallelVM(element); break; case ElementType.InductorInSeries: toReturn = new InductorInSeriesVM(element); break; case ElementType.InductorInParallel: toReturn = new InductorInParallelVM(element); break; case ElementType.CapacitorInSeries: toReturn = new CapacitorInSeriesVM(element); break; case ElementType.CapacitorInParallel: toReturn = new CapacitorInParallelVM(element); break; case ElementType.OpenCircuit: toReturn = new OpenCircuitVM(element); break; case ElementType.ShortCircuit: toReturn = new ShortCircuitVM(element); break; case ElementType.TransmissionLine: toReturn = new TransmissionLineVM(element); break; case ElementType.ImportedComponent: toReturn = new ImportedComponentVM(element); break; default: toReturn = new ElementVM(element); break; } return(toReturn); }
//获取所有端口信息 public void GetPorts() { XmPortBLL bll = new XmPortBLL(); List <PortVM> models = new List <PortVM>(); foreach (var item in bll.GetPorts()) { PortVM model = new PortVM() { port = item.port.ToString(), xmno = item.xmno.ToString() }; models.Add(model); } dataGridView1.DataSource = models; dataGridView1.Columns[0].HeaderText = "端口状态"; dataGridView1.Columns[1].HeaderText = "端口号"; dataGridView1.Columns[2].HeaderText = "项目编号"; dataGridView1.Columns[1].ReadOnly = true; }
public async Task <IActionResult> Portfolio(int?id) { var user = await _userManager.GetUserAsync(User); Profile currentProfile = null; int currentId = 0; int profileId = 0; if (_signInManager.IsSignedIn(User)) { currentProfile = db.Profile.FirstOrDefault(p => p.UsersId == user.Id); currentId = currentProfile.id; } if (id == null) { if (_signInManager.IsSignedIn(User)) { profileId = currentId; } else { return(RedirectToAction("Index", "Home")); } } else { profileId = (int)id; } var profile = db.Profile.FirstOrDefault(p => p.id == profileId); var thisUser = db.Users.FirstOrDefault(u => u.Id == profile.UsersId); if (_signInManager.IsSignedIn(User)) { var block = db.Blocklist.FirstOrDefault(b => b.blockedId == user.Id && b.blockerId == thisUser.Id || b.blockerId == user.Id && b.blockedId == thisUser.Id); if (block != null) { return(RedirectToAction("Index", "Home")); } } if (profile.Disabled && profile.UsersId != user.Id) { return(RedirectToAction("Index", "Home")); } if (currentProfile != null && currentProfile.Disabled) { return(RedirectToAction("Ban", "Home", new { profile.id })); } // Get profile Cover information bool isfolowing = false; if (user != null) { var folow = db.Follow.FirstOrDefault(f => f.folowerId == currentProfile.id && f.folowingId == profile.id); if (folow != null) { isfolowing = true; } } var coverClass = new CoverClass() { Profile = profile, User = db.Users.FirstOrDefault(u => u.Id == profile.UsersId), folowings = db.Follow.Where(f => f.folowerId == profile.id).Count(), folowers = db.Follow.Where(f => f.folowingId == profile.id).Count(), views = profile.View, isFolowing = isfolowing }; var model = new PortVM() { CoverClass = coverClass, Portfolio = db.Portfolio.Where(p => p.ProfileId == profile.id).ToList(), PortfolioImages = db.PortfolioImages.ToList() }; bool isAjaxCall = Request.Headers["x-requested-with"] == "XMLHttpRequest"; if (isAjaxCall) { return(PartialView("_Portfolio", model)); } else { return(View(model)); } }