Model:
[Link]:
using System;
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public class NhanVien
{
public NhanVien()
{
}
public string MaNV { get; set; }
public string HoTen { get; set; }
public string DonVi { get;set; }
public double LuongNgay { get; set; }
public int SoNgay { get;set; }
public double ThuNhap { get
{
if (SoNgay < 25)
return LuongNgay * SoNgay;
else
return LuongNgay * SoNgay + 500000;
}
}
public NhanVien(string maNV, string hoTen, string donVi, double
luongNgay, int soNgay)
{
MaNV = maNV;
HoTen = hoTen;
DonVi = donVi;
LuongNgay = luongNgay;
SoNgay = soNgay;
}
}
}
-DSNhanVien
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public static class DsNhanVien
{
public static List<NhanVien> listnv = new List<NhanVien>();
}
}
-Controller:
QuanLyController:
using System;
using [Link];
using [Link];
using [Link].X509Certificates;
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public class QuanlyController : Controller
{
// GET: Quanly
static public List<NhanVien> KhoiTao()
{
NhanVien nv1=new NhanVien("NV01","Nguyen Van A","Hanh
chinh",200000,26); [Link](nv1);
NhanVien nv2= new NhanVien("NV02", "Nguyen Van B", "Nhan su",
100000, 26); [Link](nv2);
NhanVien nv3= new NhanVien("NV03", "Nguyen Van C", "Ke toan",
220000, 25); [Link](nv3);
NhanVien nv4 = new NhanVien("NV04", "Nguyen Van D", "Marketing",
203000, 21); [Link](nv4);
NhanVien nv5 = new NhanVien("NV05", "Nguyen Van E", "Ky thuat",
150000, 20); [Link](nv5);
return [Link];
}
public ActionResult Cau3()
{
return View([Link]);
}
public ActionResult Cau4()
{
return View();
}
[HttpPost]
public ActionResult HienThi1(string MaNV,string HoTen, string DonVi,
double LuongNgay, int SoNgay)
{
NhanVien a=new NhanVien(MaNV,HoTen, DonVi, LuongNgay, SoNgay);
[Link](a);
return View("HienThi",[Link]);
}
public ActionResult HienThi()
{
KhoiTao();
return View("HienThi",[Link]);
}
}
}
View:
View
Cau3:
@model List<[Link]>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Danh sách sốngày lớn hơn 20</title>
</head>
<body>
<div>
<table border="1">
<tr>
<th>Ma NV</th>
<th>Ho Ten</th>
<th>Don vi</th>
<th>Luong ngay</th>
<th>So ngay</th>
<th>Thu nhap</th>
</tr>
@foreach (var item in Model)
{
if ([Link] > 20)
{
<tr>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
</tr>
}
}
</table>
</div>
</body>
</html>
Cau4:
@model List<[Link]>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Cau4</title>
</head>
<body>
<div>
<form action="~/Quanly/HienThi1" method="post">
{
<table>
<tr>
<td>@[Link]("Ma NV:")</td>
<td>@[Link]("MaNV")</td>
</tr>
<tr>
<td>@[Link]("Ho ten:")</td>
<td>@[Link]("HoTen")</td>
</tr>
<tr>
<td>@[Link]("Don vi:")</td>
<td>
<select id="DonVi">
<option value="tochuc">To chuc</option>
<option value="kinhdoanh">kinh doanh</option>
<option value="kythuat">Ky thuat</option>
</select>
</td>
</tr>
<tr>
<td>@[Link]("Luong ngay:")</td>
<td>@[Link]("LuongNgay")</td>
</tr>
<tr>
<td>@[Link]("So Ngay:")</td>
<td>@[Link]("SoNgay")</td>
</tr>
<tr>
<td colspan="2">
<input value="Submit" type="submit" />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
Hien Thi
@model List<[Link]>
@{
[Link] = "HienThi";
}
<h2>HienThi</h2>
<table border="1">
<tr>
<th>Ma NV</th>
<th>Ho Ten</th>
<th>Don vi</th>
<th>Luong ngay</th>
<th>So ngay</th>
<th>Thu nhap</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
</tr>
}
</table>
---Layout
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@[Link] - My [Link] Application</title>
@[Link]("~/Content/css")
@[Link]("~/bundles/modernizr")
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-
dark">
<div class="container">
@[Link]("Application name", "Index", "Home", new { area =
"" }, new { @class = "navbar-brand" })
<button type="button" class="navbar-toggler" data-bs-
toggle="collapse" data-bs-target=".navbar-collapse" title="Toggle navigation"
aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse d-sm-inline-flex justify-
content-between">
<ul class="navbar-nav flex-grow-1">
<li>@[Link]("HienThi", "HienThi", "Quanly", new
{ area = "" }, new { @class = "nav-link" })</li>
<li>@[Link]("Cau3", "Cau3", "Quanly", new { area =
"" }, new { @class = "nav-link" })</li>
<li>@[Link]("Cau4", "Cau4", "Quanly", new { area =
"" }, new { @class = "nav-link" })</li>
</ul>
</div>
</div>
</nav>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @[Link] - My [Link] Application</p>
</footer>
</div>
@[Link]("~/bundles/jquery")
@[Link]("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>