Framwork
Framwork
cs
ChuyenBayController.cs
StoreContext context =
HttpContext.RequestServices.GetService(typeof(StoreContext)) as StoreContext;
var count1 = context.LietKeChuyenBay(chuyenBay.MaCB);
var count2 = context.ThongTinChuyenBay(chuyenBay.MaCB);
var model = new ChuyenBayViewModel
{
ListCB = count1,
ChuyenBay = count2
};
return View(model);
}
return View(ct_cb);
}
public IActionResult Update(CT_CB ct_cb)
{
int count;
StoreContext context =
HttpContext.RequestServices.GetService(typeof(StoreContext)) as StoreContext;
count = context.Update(ct_cb);
if (count > 0)
ViewData["thongbao"] = "Update thành công";
else
ViewData["thongbao"] = "Update không thành công";
return View();
}
public IActionResult Delete(string makh, string macb) {
// ViewData["id"] = Id;
StoreContext context =
HttpContext.RequestServices.GetService(typeof(StoreContext)) as StoreContext;
int count = context.Delete(makh,macb);
if (count > 0)
ViewData["thongbao"] = "Xóa thành công";
else
ViewData["thongbao"] = "Xóa không thành công";
return View();
}
}
StoreContext.cs
result.MaCB = reader["MaCB"].ToString();
result.Chuyen = reader["Chuyen"].ToString();
result.Di = reader["Di"].ToString();
result.Den = reader["Den"].ToString();
result.GBay = reader["GBay"].ToString();
result.GDen = reader["GDen"].ToString();
result.Ngay = reader["Ngay"].ToString();
result.Thuong = reader["Thuong"].ToString();
result.Vip = reader["Vip"].ToString();
}
reader.Close();
}
}
return result;
}
var str =
"select HK.*, CT_CB.LoaiGhe, CT_CB.SoGHe from CT_CB, HANHKHACH
HK where MaCB=@macb and HK.MaHK = CT_CB.MaHK";
var cmd = new MySqlCommand(str, conn);
cmd.Parameters.AddWithValue("macb", maCB);
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
result.Add(new CT_CB
{
LoaiGhe = bool.Parse(reader["LoaiGhe"].ToString()),
SoGhe = reader["SoGhe"].ToString(),
HanhKhach = new HanhKhach
{
MaHK = reader["MaHK"].ToString(),
HoTen = reader["Hoten"].ToString(),
DiaChi = reader["DiaChi"].ToString(),
DienThoai = reader["DienThoai"].ToString(),
}
});
}
reader.Close();
}
return (result);
}
}
View/HanhKhach/Insert.cshtml
@model HanhKhach
@{
ViewData["Title"] = "Thêm Hành Khách";
<form method="post" asp-controller="HanhKhach" asp-action="Enter">
View/HanhKhach/Enter.cshtml
@model HanhKhach
@{
ViewData["Title"] = "Thông tin lấy được từ form";
}
@{
<p>Mã khoa:@Model.MaHK</p>
<p>Tên khoa:@Model.HoTen</p>
<p>@ViewData["ThongBao"]</p>
}
View/ChuyenBay/Index.cshtml
@model ChuyenBay
@{
ViewData["Title"] = "Xem thông tin máy bay";
<form method="get" asp-controller="ChuyenBay" asp-action="LietKe">
<h1>Xem thông tin chuyến bay</h1>
<label for="macb">Mã chuyến bay</label><input type="text" id="macb"
asp-for="MaCB" required/><br/>
<button type="submit" name="submit" value="Liệt kê">Liệt kê</button>
</form>
}
View/ChuyenBay/LietKe.cshtml
@model ChuyenBayViewModel
@{
ViewData["Title"] = "Liệt Kê Chuyến Bay";
<table>
<tr>
<td colspan="2">Thông tin chuyến bay</td>
</tr>
<tr>
<td>Chuyến <input type="text"
value="@Model.ChuyenBay.Chuyen" name="chuyen" disabled/></td>
<td>Ngày bay <input type="text"
value="@Model.ChuyenBay.Ngay" name="ngay" disabled/></td>
</tr>
<tr>
<td>Điểm Đi <input type="text"
value="@Model.ChuyenBay.Di" name="di" disabled/></td>
<td>Giờ Đi <input type="text"
value="@Model.ChuyenBay.GBay" name="giobay" disabled/></td>
</tr>
<tr>
<td>Điểm Đến <input type="text"
value="@Model.ChuyenBay.Den" name="den" disabled/></td>
<td>Giờ Đến <input type="text"
value="@Model.ChuyenBay.GDen" name="gioden" disabled/></td>
</tr>
<tr>
<td>Chỗ VIP <input type="text"
value="@Model.ChuyenBay.Vip" name="vip" disabled/></td>
<td>Chỗ Thường <input type="text"
value="@Model.ChuyenBay.Thuong" name="thuong" disabled/></td>
</tr>
<tr>
<td colspan="2">
<a href="/ChuyenBay/ThemHanhKhach" asp-
action="ThemHanhKhach" asp-route-id="@Model.ChuyenBay.MaCB">Thêm hành
khách</a>
</td>
</tr>
<tr>
<td colspan="2">
<table>
<thead>
<td>Họ tên hành khách</td>
<td>Điện thoại</td>
<td>Loại ghế</td>
<td>Số ghế</td>
<td>Chức năng</td>
</thead>
<tbody>
@foreach (var item in Model.ListCB)
{
<tr>
<td>@item.HanhKhach.HoTen</td>
<td>@item.HanhKhach.DienThoai</td>
<td>@item.LoaiGhe</td>
<td>@item.SoGhe</td>
<td>
<a href="Update?
makh=@item.MaHK&macb=@item.MaCB">Sửa</a>
<a href="Delete?
makh=@item.MaHK&macb=@item.MaCB">Xoá</a>
</td>
</tr>
}
</tbody>
</table>
</tr>
</table>
View/ChuyenBay/ThemHanhKhach.cshtml
@model ChuyenBay
@{
ViewData["Title"] = "Thêm hành khách";
<form method="get" asp-controller="ChuyenBay" asp-action="ThemHanhKhach">
<table>
<tr>
<td colspan="2">Thêm hành khách vào chuyến bay</td>
</tr>
<tr>
<td>Chuyến <input type="text" value="@Model.Chuyen"
name="chuyen" disabled/></td>
<td>Ngày bay <input type="text" value="@Model.Ngay"
name="ngay" disabled/></td>
</tr>
<tr>
<td>Điểm Đi <input type="text" value="@Model.Di" name="di"
disabled/></td>
<td>Giờ Đi <input type="text" value="@Model.GBay"
name="giobay" disabled/></td>
</tr>
<tr>
<td>Điểm Đến <input type="text" value="@Model.Den" name="den"
disabled/></td>
<td>Giờ Đến <input type="text" value="@Model.GDen"
name="gioden" disabled/></td>
</tr>
<tr>
<td>Chỗ VIP <input type="text" value="@Model.Vip" name="vip"
disabled/></td>
<td>Chỗ Thường <input type="text" value="@Model.Thuong"
name="thuong" disabled/></td>
</tr>
<tr>
<td>Mã hành khách <input type="text" name="mahk" /></td>
<td>Tên hành khách <input type="text" name="thuong" /></td>
</tr>
<tr>
<td>
Loại ghế
<select name="loaighe">
<option value="Thuong">Thường</option>
<option value="Vip">Vip</option>
</select>
</td>
<td>Số Ghế <input type="text" name="soghe" /></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" name="submit" value="Thêm">Thêm hành
khách</button>
</td>
</tr>
</table>
</form>
}
View/ChuyenBay/Update.cshtml
@model CT_CB
@{
ViewData["Title"] = "Update";
<form method="get" asp-controller="ChuyenBay" asp-action="Update">
<h1>Cập nhật thông tin hành khách</h1>
<label for="mahk">Mã Hành Khách</label><input type="text" id="mahk"
value="@Model.HanhKhach.MaHK"/><br/>
<label for="tenhk">Tên hành kháchh</label><input type="text"
id="tenhk" value="@Model.HanhKhach.HoTen"/><br/>
<label for="loaighe">Loại ghế</label>
<select id="loaighe" name="loaighe" asp-for="LoaiGhe">
<option value="Thuong">Thường</option>
<option value="Vip">Vip</option>
</select>
<label for="soghe">Số ghế</label><input type="text" id="soghe" asp-
for="SoGhe" value="@Model.SoGhe"/><br/>
<button type="submit" name="submit" value="Cập nhật">Cập nhật</button>
</form>
}