You are on page 1of 92

TRƯỜNG ĐẠI HỌC TÀI NGUYÊN VÀ MÔI TRƯỜNG

THÀNH PHỐ HỒ CHÍ MINH


KHOA HỆ THỐNG THÔNG TIN VÀ VIỄN THÁM

TIỂU LUẬN
HỌC PHẦN: LẬP TRÌNH WED

ĐỀ TÀI: XÂY DỰNG PHẦN MỀM QUẢN LÍ THỊ


TRƯỜNG CHỨNG KHOÁN

Sinh viên thực hiện: Nguyễn Văn Tú


Lớp : ĐHCNTT1
Khoá : 09
Giảng viên hướng dẫn : Ngô Tân Khai

TP. Hồ Chí Minh, 13 tháng 06 năm 2022


MỤC LỤC
1.Bảng Khách hàng:....................................................................................................8
1.1.Thiết kế Form:.....................................................................................................................................8
1.2. Mã lệnh theo HTML Server Control (Cách 1):.........................................................................8
1.3. Mã lệnh Web server control:..........................................................................................................9
1.4. Mã lệnh Controller:........................................................................................................................10
1.5. Chức năng hiển thị:........................................................................................................................12
1.5.1.Giao diện chức năng hiển thị:...........................................................................................12
1.5.2. Mã lệnh Contreller hiển thị:............................................................................................12
1.6. Chức năng chỉnh sửa:........................................................................................................................14
1.6.1. Giao diện chức chỉnh sửa:..............................................................................................14
1.6.2. Mã lệnh Controller chức năng chỉnh sửa:......................................................................14
1.7.Chức năng thêm:.................................................................................................................................17
1.7.1.Giao diện chức năng thêm:...............................................................................................17
1.7.2.Mã lệnh Controller chức năng thêm:................................................................................17
1.7.3. Mã lệnh Create chức năng thêm......................................................................................17
1.8. Chức năng Xóa:..................................................................................................................................19
1.8.1. Giao diện chức năng xóa:................................................................................................19
1.8.2.Mã lệnh Controller chức năng xóa...................................................................................19
1.9. Chức năng hiển thị chi tiết:..............................................................................................................20
1.9.1. Giao diện chức năng chi tiết:...........................................................................................20
1.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:................................................................20
1.9.3.Mã lệnh Details chức năng hiển thị:.................................................................................20
2.Bảng Nhà mô giới:..................................................................................................21
2.1.Thiết kế form:....................................................................................................................................22
2.2.Mã lệnh theo HTML Server Control (Cách 1):........................................................................22
2.3. Mã lệnh Web server control:........................................................................................................23
2.4.Mã lệnh Controller:.........................................................................................................................24
2.5.Chức năng hiển thị:.........................................................................................................................26
2.5.1.Giao diện chức năng hiển thị:...........................................................................................26
2.5.2.Mã lệnh Controller:..........................................................................................................26
2.5.3.Mã lệnh Index chức năng hiển thị:....................................................................................26
2.6.Chức năng chỉnh sửa:.....................................................................................................................28

1
2.6.1.Giao diện chức năng chỉnh sửa:.......................................................................................28
2.6.2. Mã lệnh Controller chức năng chỉnh sửa:.......................................................................28
2.6.3 Mã lệnh Edit chức năng chỉnh sửa:..................................................................................28
2.7.Chức năng thêm:..............................................................................................................................30
2.7.1.Giao diện chức năng thêm:...............................................................................................30
2.7.2.Mã lệnh Controller chức năng thêm:...............................................................................30
2.7.3.Mã lệnh Create chức năng chỉnh sửa:..............................................................................31
2.8.Chức năng xóa:.................................................................................................................................32
2.8.1. Giao diện chức năng xóa:................................................................................................32
2.8.2.Mã lệnh Controller chức năng xóa:..................................................................................33
2.9.Chức năng hiển thị chi tiết:...........................................................................................................33
2.9.1.Giao diện chức năng hiển thị chi tiết:...............................................................................33
2.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:................................................................33
2.9.3.Mã lệnh Details Chức năng hiển thị chị tiết:....................................................................33
3.Bảng Công ty:...................................................................................................34
3.1.Thiết kế Form:...................................................................................................................................35
3.2. Mã lệnh theo HTML Server Control (Cách 1):.......................................................................35
3.3. Mã lệnh Web server control:........................................................................................................36
3.4.Mã lệnh Controller:.........................................................................................................................37
3.5.Chức năng hiển thị:.........................................................................................................................39
3.5.1.Giao diện chức năng hiển thị:...........................................................................................39
3.5.2.Mã lệnh Controller chức năng hiển thị:............................................................................39
3.5.3.Mã lệnh Index chức năng hiển thị:....................................................................................39
3.6.Chức năng chỉnh sửa:.....................................................................................................................41
3.6.1.Giao diện chức năng chỉnh sửa:.......................................................................................41
3.6.2. Mã lệnh Controller chức năng chỉnh sửa:.......................................................................41
3.6.3 Mã lệnh Edit chức năng chỉnh sửa:..................................................................................41
3.7.Chức năng thêm:..............................................................................................................................44
3.7.1.Giao diện chức năng thêm:...............................................................................................44
3.7.2.Mã lệnh Controller chức năng thêm:...............................................................................44
3.7.3.Mã lệnh Create chức năng thêm :.....................................................................................44
3.8.Chức năng xóa:.................................................................................................................................46
3.8.1. Giao diện chức năng xóa:................................................................................................46
3.8.2.Mã lệnh Controller chức năng xóa:..................................................................................46

2
3.9.Chức năng hiển thị chi tiết:...........................................................................................................47
3.9.1.Giao diện chức năng hiển thị chi tiết:...............................................................................47
3.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:................................................................47
3.9.3.Mã lệnh Details Chức năng hiển thị chị tiết:....................................................................47
4.Bảng Diễn biến giá:..........................................................................................48
4.1.Thiết kế Form:...................................................................................................................................49
4.2. Mã lệnh theo HTML Server Control (Cách 1):.......................................................................49
4.3. Mã lệnh Web server control:........................................................................................................50
4.4.Mã lệnh Controller:.........................................................................................................................51
4.5.Chức năng hiển thị:.........................................................................................................................52
4.5.1.Giao diện chức năng hiển thị:...........................................................................................52
4.5.2.Mã lệnh Controller:..........................................................................................................52
4.5.3.Mã lệnh Index chức năng hiển thị:....................................................................................53
4.6.Chức năng chỉnh sửa:.....................................................................................................................54
4.6.1.Giao diện chức năng chỉnh sửa:.......................................................................................54
4.6.2. Mã lệnh Controller chức năng chỉnh sửa:.......................................................................54
4.6.3 Mã lệnh Edit chức năng chỉnh sửa:..................................................................................54
4.7.Chức năng thêm:..............................................................................................................................56
4.7.1.Giao diện chức năng thêm:...............................................................................................56
4.7.2.Mã lệnh Controller chức năng thêm:...............................................................................56
4.7.3.Mã lệnh Create chức năng thêm:......................................................................................56
4.8.Chức năng xóa:.................................................................................................................................58
4.8.1. Giao diện chức năng xóa:................................................................................................58
4.8.2.Mã lệnh Controller chức năng xóa:..................................................................................58
4.9.Chức năng hiển thị chi tiết:...........................................................................................................58
4.9.1.Giao diện chức năng hiển thị chi tiết:...............................................................................58
4.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:................................................................58
4.9.3.Mã lệnh Details Chức năng hiển thị chị tiết:....................................................................59
5.Bảng Giao dịch:...............................................................................................59
5.1.Thiết Kế form:...................................................................................................................................60
5.2. Mã lệnh theo HTML Server Control (Cách 1):.......................................................................60
5.3. Mã lệnh Web server control:........................................................................................................62
5.4.Mã lệnh Controller:.........................................................................................................................63
5.5.Chức năng hiển thị:.........................................................................................................................65
3
5.5.1.Giao diện chức năng hiển thị:...........................................................................................65
5.5.2.Mã lệnh Controller:..........................................................................................................65
5.5.3.Mã lệnh Index chức năng hiển thị:....................................................................................65
5.6.Chức năng chỉnh sửa:.....................................................................................................................67
5.6.1.Giao diện chức năng chỉnh sửa:...............................................................................................67
5.6.2. Mã lệnh Controller chức năng chỉnh sửa:.......................................................................67
5.6.3 Mã lệnh Edit chức năng chỉnh sửa:..................................................................................68
5.7.Chức năng thêm:..............................................................................................................................70
5.7.1.Giao diện chức năng thêm:...............................................................................................70
5.7.2.Mã lệnh Controller chức năng thêm:...............................................................................70
5.7.3.Mã lệnh Create chức năng thêm:......................................................................................71
5.8.Chức năng xóa:.................................................................................................................................73
5.8.1. Giao diện chức năng xóa:................................................................................................73
5.8.2.Mã lệnh Controller chức năng xóa:..................................................................................73
5.9.Chức năng hiển thị chi tiết:...........................................................................................................73
5.9.1.Giao diện chức năng hiển thị chi tiết:...............................................................................73
5.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:................................................................74
5.9.3.Mã lệnh Details Chức năng hiển thị chị tiết:....................................................................74
6. Bảng Khách hàng mua...................................................................................75
6.1. Thiết kế form:...................................................................................................................................75
6.2. Mã lệnh theo HTML Server Control (Cách 1):.......................................................................75
6.3. Mã lệnh Web server control:........................................................................................................77
6.4.Mã lệnh Controller:.........................................................................................................................78
6.5.Chức năng hiển thị:.........................................................................................................................79
6.5.1.Giao diện chức năng hiển thị:...........................................................................................79
6.5.2.Mã lệnh Controller:..........................................................................................................79
6.5.3.Mã lệnh Index chức năng hiển thị:....................................................................................80
2.6.Chức năng chỉnh sửa:.....................................................................................................................81
2.6.1.Giao diện chức năng chỉnh sửa:.......................................................................................81
2.6.2. Mã lệnh Controller chức năng chỉnh sửa:.......................................................................81
2.6.3 Mã lệnh Edit chức năng chỉnh sửa:..................................................................................82
2.7.Chức năng thêm:..............................................................................................................................84
2.7.1.Giao diện chức năng thêm:...............................................................................................84
2.7.2.Mã lệnh Controller chức năng thêm:...............................................................................84

4
2.7.3.Mã lệnh Create chức năng thêm:......................................................................................84
2.8.Chức năng xóa:.................................................................................................................................86
2.8.1. Giao diện chức năng xóa:................................................................................................86
2.8.2.Mã lệnh Controller chức năng xóa:..................................................................................86
2.9.Chức năng hiển thị chi tiết:...........................................................................................................87
2.9.1.Giao diện chức năng hiển thị chi tiết:.................................................................................................87
2.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:................................................................87
2.9.3.Mã lệnh Details Chức năng hiển thị chị tiết:....................................................................87

5
LỜI MỞ ĐẦU
Thị trường chứng khoán Việt Nam mới chào đời đầu năm 2000. Thuật ngữ “Thị trường chứng
khoán” còn tương đối mới lạ so với công chúng Việt Nam. Trong lúc đó ở nhiều nước trên toàn cầu,
thị trường chứng khoán đã tiến triển rất nhộn nhịp. Đầu tư vào thị trường chứng khoán đã trở nên
trọng yếu so với mọi người.

Để gia nhập vào thị trường chứng khoán, mọi người đều cần phải có các tri thức khẳng định về thị
trường chứng khoán. Thị trường chứng khoán chỉ có thể tiến triển được nếu có sự gia nhập ngày
càng đông của những người có đầy đủ tri thức về thị trường chứng khoán. Cho nên, tri thức của mọi
người dân về thị trường chứng khoán ở Việt Nam cần được chuyên sâu. Thị trường chứng khoán có
sự cuốn hút vốn có của nó. Nó chẳng những trọng yếu so với nền kinh tế của một nước mà nó còn
trọng yếu so với mỗi người bởi vì khả năng đầu tư sinh lợi của nó. Chính vì như vậy, mỗi người tuỳ
theo điều kiện, khả năng của mình mà cần phải tiếp cận thật nhanh để gia nhập đầu tư có hiệu quả
vào thị trường chứng khoán. Chính các hoạt động đó sẽ góp thêm phần mang thị trường chứng
khoán Việt Nam tiến triển.Do đó em muốn chọn đề tài “Quản lý thị trường chứng khoán ” nhằm tạo
ra trang wed để cho mọi người tin dùng cũng như là để dễ hơn trong việc quản lý về chứng khoán

6
MÔ HÌNH DỮ LIỆU

Models

7
MÔ TẢ CHI TIẾT CHO CÁC BẢNG DỮ LIỆU
1.Bảng Khách hàng:
STT TÊN CỘT KIỂU DỮ ĐỘ DÀI
LIỆU
1 Makh int 10
2 Tenkh nchar 50
3 Diachi nchar 50
4 Dienthoai int 20
5 Thunhap int 10

1.1.Thiết kế Form:

1.2. Mã lệnh theo HTML Server Control (Cách 1):


<!DOCTYPE html>

<html lang="en-US">
<head>
    <title>
        TIỂU LUẬN KẾT THÚC MÔN
    </title>
</head>
<body>
    <br>
<CENTER>
   
        <form >
         <table>
            <tr><th colspan="3">THÔNG TIN KHÁCH HÀNG</th></tr>

        <tr>
            <td>Mã khách hàng</td>
            <td>:</td>
            <td> <input type="text"/></td>
        </tr>

8
        <tr>
            <td>Tên khách hàng</td>
            <td>:</td>
            <td> <input type="text"/></td>
        </tr>
        <tr>
            <td>Địa chỉ </td>
            <td>:</td>
            <td> <input type="text"/></td>
        </tr>
        <tr>
            <td>Điện thoại </td>
            <td>:</td>
            <td> <input type="text"/></td>
        </tr>
        <tr>
            <td>Thu nhập </td>
            <td>:</td>
            <td> <input type="text"/></td>
        </tr>
       
            <tr>
                <td></td>
                <td></td>
                <td><input type="submit" value="Lưu lại" />
                    <input type="submit" value="Đóng" />
            </td>
            </tr>
         
        </table>
       
        </form>
       
</CENTER>
</br>

</body>

</html>

1.3. Mã lệnh Web server control:


<div style="display: inline-block;
border: 1px solid blue;
padding: 15px">
<h2 style="text-align: center;">THÔNG TIN KHÁCH HÀNG</h2>
<form id=”formKhachhang” runat=”server”>
9
<table cellpadding=10 cellspacing=20>
<tr>
<th>Mã khách hàng</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtMakh"></td>
</tr>
<tr>
<th>Tên khách hàng</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtTenkh"></td>
</tr>
<tr>
<th>Địa chỉ</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtDiaChi"></td>
</tr>
<tr>
<th>Điện thoại</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtDienThoai"></td>
</tr>

</table>
<br>
<div style="text-align: center;">
<button type="">Đóng</button>&nbsp; &nbsp;
<button type="submit" runat=”server”>Lưu lại</button>
</div>
</form>
</div>

1.4. Mã lệnh Controller:


using System;
using System.Collections.Generic;

10
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TIEULUAN36.Models;

namespace TIEULUAN36.Controllers
{
public class KHACHHANGController : Controller
{
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities();
// GET: Default
public ActionResult Index()
{
var lstkh = from kh in db.KHACHHANGs select kh;
return View(lstkh);
}
[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(KHACHHANG kh)
{
db.KHACHHANGs.Add(kh);
db.SaveChanges();
return RedirectToAction("Index");
}
public ActionResult Delete(String id)
{
KHACHHANG kh = db.KHACHHANGs.Find(id);
db.KHACHHANGs.Remove(kh);
db.SaveChanges();
return RedirectToAction("Index");
}
[HttpGet]
public ActionResult Edit(String id)
{
var kh = db.KHACHHANGs.Find(id);
return View(kh);
}
[HttpPost]
public ActionResult Edit(KHACHHANG kh)
{
var updatekh= db.KHACHHANGs.Find(kh.MAKH);
updatekh.MAKH = kh.MAKH;
updatekh.TENKH = kh.TENKH;
updatekh.DIACHI = kh.DIACHI;
updatekh.DIENTHOAI = kh.DIENTHOAI;
updatekh.THUNHAP = kh.THUNHAP;

11
db.SaveChanges();
return RedirectToAction("Index");
}
public ActionResult Details(String id)
{
var lstkh= db.KHACHHANGs.Select(p => p).Where(p => p.MAKH ==
id).FirstOrDefault();
return View(lstkh);
}
}
}

1.5. Chức năng hiển thị:


1.5.1.Giao diện chức năng hiển thị:

1.5.2. Mã lệnh Contreller hiển thị:

public class KHACHHANGController : Controller


{
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities();
// GET: Default
public ActionResult Index()
{
var lstkh = from kh in db.KHACHHANGs select kh;
return View(lstkh);
}
1.5.3.Mã lên Index hiển thị

@model IEnumerable<TIEULUAN36.Models.KHACHHANG>

@{
12
ViewBag.Title = "Index";
}

<h2>Danh sách khách hàng</h2>

<p>
@Html.ActionLink("Tạo mới ", "Create")
</p>
<table class="table">
<tr>
<th>
Mã khách hàng
</th>
<th>
Tên khách hàng
</th>
<th>
Địa chỉ
</th>
<th>
Điện thoại
</th>
<th>
Thu nhập
</th>
<th></th>
</tr>

@foreach (var item in Model) {


<tr>
<td>
@Html.DisplayFor(modelItem => item.MAKH)
</td>
<td>
@Html.DisplayFor(modelItem => item.TENKH)
</td>
<td>
@Html.DisplayFor(modelItem => item.DIACHI)
</td>
<td>
@Html.DisplayFor(modelItem => item.DIENTHOAI)
</td>
<td>
@Html.DisplayFor(modelItem => item.THUNHAP)
</td>
<td>
@Html.ActionLink("Chỉnh sửa", "Edit", new { id=item.MAKH }) |
@Html.ActionLink("Chi tiết", "Details", new { id=item.MAKH }) |
@Html.ActionLink("Xóa", "Delete", new { id=item.MAKH })
</td>
</tr>
}
13
</table>
1.6. Chức năng chỉnh sửa:
1.6.1. Giao diện chức chỉnh sửa:

1.6.2. Mã lệnh Controller chức năng chỉnh sửa:


[HttpGet]
public ActionResult Edit(String id)
{
var kh = db.KHACHHANGs.Find(id);
return View(kh);
}
[HttpPost]
public ActionResult Edit(KHACHHANG kh)
{
var updatekh= db.KHACHHANGs.Find(kh.MAKH);
updatekh.MAKH = kh.MAKH;
updatekh.TENKH = kh.TENKH;
updatekh.DIACHI = kh.DIACHI;
updatekh.DIENTHOAI = kh.DIENTHOAI;
updatekh.THUNHAP = kh.THUNHAP;

db.SaveChanges();
return RedirectToAction("Index");
}

1.6.3.Mã lệnh Edit chức năng chỉnh sửa:


model TIEULUAN36.Models.KHACHHANG

@{
ViewBag.Title = "Edit";
14
}

<h2>Chỉnh sửa</h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Khách hàng</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.MAKH)

<div class="form-group">

<div class="col-md-10">
Mã khách hàng
@Html.EditorFor(model => model.MAKH, new { htmlAttributes = new
{ @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MAKH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Tên khách hàng
@Html.EditorFor(model => model.TENKH, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TENKH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Địa chỉ
@Html.EditorFor(model => model.DIACHI, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIACHI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Điện thoại
15
@Html.EditorFor(model => model.DIENTHOAI, new { htmlAttributes
= new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIENTHOAI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Thu nhập
@Html.EditorFor(model => model.THUNHAP, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.THUNHAP, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Lưu" class="btn btn-default" />
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

16
1.7.Chức năng thêm:
1.7.1.Giao diện chức năng thêm:

1.7.2.Mã lệnh Controller chức năng thêm:


[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(KHACHHANG kh)
{
db.KHACHHANGs.Add(kh);
db.SaveChanges();
return RedirectToAction("Index");
}

1.7.3. Mã lệnh Create chức năng thêm


@model TIEULUAN36.Models.KHACHHANG

@{
ViewBag.Title = "Create";
}

<h2>Tạo Mới</h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Khách hàng</h4>
<hr />
17
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">

<div class="col-md-10">
Mã khách hàng
@Html.EditorFor(model => model.MAKH, new { htmlAttributes = new
{ @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MAKH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Tên khách hàng
@Html.EditorFor(model => model.TENKH, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TENKH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Địa chỉ
@Html.EditorFor(model => model.DIACHI, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIACHI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Điện thoại
@Html.EditorFor(model => model.DIENTHOAI, new { htmlAttributes
= new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIENTHOAI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Thu nhập
@Html.EditorFor(model => model.THUNHAP, new { htmlAttributes =
new { @class = "form-control" } })

18
@Html.ValidationMessageFor(model => model.THUNHAP, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Tạo mới" class="btn btn-default" />
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

1.8. Chức năng Xóa:


1.8.1. Giao diện chức năng xóa:

1.8.2.Mã lệnh Controller chức năng xóa


public ActionResult Delete(String id)
{
KHACHHANG kh = db.KHACHHANGs.Find(id);
db.KHACHHANGs.Remove(kh);
db.SaveChanges();
return RedirectToAction("Index");
}

19
1.9. Chức năng hiển thị chi tiết:
1.9.1. Giao diện chức năng chi tiết:

1.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:


public ActionResult Details(String id)
{
var lstkh= db.KHACHHANGs.Select(p => p).Where(p => p.MAKH ==
id).FirstOrDefault();
return View(lstkh);
}

1.9.3.Mã lệnh Details chức năng hiển thị:


@model TIEULUAN36.Models.KHACHHANG

@{
ViewBag.Title = "Details";
}

<h2>chi tiết </h2>

<div>
<h4>Khách hàng</h4>
<hr />
<dl class="dl-horizontal">
<dt>
Mã khách hàng
</dt>

<dd>
@Html.DisplayFor(model => model.MAKH)
</dd>
<dt>
Tên khách hàng
</dt>

<dd>
@Html.DisplayFor(model => model.TENKH)
20
</dd>

<dt>
Địa chỉ
</dt>

<dd>
@Html.DisplayFor(model => model.DIACHI)
</dd>

<dt>
Điện thoại
</dt>

<dd>
@Html.DisplayFor(model => model.DIENTHOAI)
</dd>

<dt>
Thu nhập
</dt>

<dd>
@Html.DisplayFor(model => model.THUNHAP)
</dd>

</dl>
</div>
<p>
@Html.ActionLink("Chỉnh sửa", "Edit", new { id = Model.MAKH }) |
@Html.ActionLink("Back to List", "Index")
</p>

2.Bảng Nhà mô giới:


STT TÊN CỘT KIỂU DỮ ĐỘ DÀI
LIỆU
1 Manhamoigioi int 10
2 Tennhamogioi Nchar 50
3 Diachi Nchar 50
4 dienthoai int 20

21
2.1.Thiết kế form:

2.2.Mã lệnh theo HTML Server Control (Cách 1):


<!DOCTYPE html>

<html lang="en-US">
<head>
    <title>
        TIỂU LUẬN KẾT THÚC MÔN
    </title>
</head>
<body>
    <br>
<CENTER>
   
    <table>
        <form>
        <tr><th colspan="3">THÔNG TIN NHÀ MÔ GIỚI</th></tr>
        <tr>
            <td>Mã nhà mô giới</td>
            <td>:</td>
            <td>
                <input type="text"/>
            </td>
        </tr>
        <tr>
            <td>Tên nhà mô giới</td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>
        <tr>
            <td>Địa chỉ </td>
            <td>:</td>
            <td>
                 <input type="text"/>
22
           </td>
        </tr>
        <tr>
            <td>Điện thoại </td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>

        </tr>
       
            <tr>
                <td></td>
                <td></td>
                <td><input type="submit" value="Lưu lại" />
                    <input type="submit" value="Đóng"  />
            </td>
            </tr>
       
        </form>
        </table>
</CENTER>
</br>

</body>

</html>

2.3. Mã lệnh Web server control:


<div style="display: inline-block;
border: 1px solid blue;
padding: 15px">
<h2 style="text-align: center;">THÔNG TIN NHÀ MÔI GIỚI</h2>
<form id=”formNhamoigioi” runat=”server”>
<table cellpadding=10 cellspacing=20>
<tr>
<th>Mã nhà môi giới</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtManhamoigioi"></td>
</tr>
<tr>
<th>Tên nhà môi giới</th>
23
<td>:</td>
<td><asp:TextBox type="text" name="txtTennhamoigioi"></td>
</tr>
<tr>
<th>Địa chỉ</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtDiaChi"></td>
</tr>
<tr>
<th>Điện thoại</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtDienThoai"></td>
</tr>

</table>
<br>
<div style="text-align: center;">
<button type="">Đóng</button>&nbsp; &nbsp;
<button type="submit" runat=”server”>Lưu lại</button>
</div>
</form>
</div>

2.4.Mã lệnh Controller:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TIEULUAN36.Models;

namespace TIEULUAN36.Controllers
{
public class NAHMOIGIOIController : Controller
{
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities();
// GET: Default
public ActionResult Index()
24
{
var lstdt = from dt in db.NHAMOIGIOIs select dt;
return View(lstdt);
}
[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(NHAMOIGIOI dt)
{
db.NHAMOIGIOIs.Add(dt);
db.SaveChanges();
return RedirectToAction("Index");
}
public ActionResult Delete(String id)
{
NHAMOIGIOI dt = db.NHAMOIGIOIs.Find(id);
db.NHAMOIGIOIs.Remove(dt);
db.SaveChanges();
return RedirectToAction("Index");
}
[HttpGet]
public ActionResult Edit(String id)
{
var dt = db.NHAMOIGIOIs.Find(id);
return View(dt);
}
[HttpPost]
public ActionResult Edit(NHAMOIGIOI dt)
{
var updatedt = db.NHAMOIGIOIs.Find(dt.MANHAMOIGIOI);
updatedt.MANHAMOIGIOI = dt.MANHAMOIGIOI;
updatedt.TENNHAMOIGIOI = dt.TENNHAMOIGIOI;
updatedt.DIACHI = dt.DIACHI;
updatedt.DIENTHOAI = dt.DIENTHOAI;

db.SaveChanges();
return RedirectToAction("Index");
}

public ActionResult Details(String id)


{
var lstdt = db.NHAMOIGIOIs.Select(p => p).Where(p => p.MANHAMOIGIOI
== id).FirstOrDefault();
return View(lstdt);
}
}
}

25
2.5.Chức năng hiển thị:
2.5.1.Giao diện chức năng hiển thị:

2.5.2.Mã lệnh Controller:


public class NAHMOIGIOIController : Controller
{
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities();
// GET: Default
public ActionResult Index()
{
var lstdt = from dt in db.NHAMOIGIOIs select dt;
return View(lstdt);
}

2.5.3.Mã lệnh Index chức năng hiển thị:


@model IEnumerable<TIEULUAN36.Models.NHAMOIGIOI>

@{
ViewBag.Title = "Index";
}

<h2>Danh sách nhà môi giới </h2>

<p>
@Html.ActionLink("Tạo mới ", "Create")
</p>
<table class="table">
<tr>
<th>
Mã nhà môi giới
</th>
26
<th>
Tên nhà môi giới
</th>
<th>
Địa chỉ
</th>
<th>
Điện thoại
</th>
<th></th>
</tr>

@foreach (var item in Model) {


<tr>
<td>
@Html.DisplayFor(modelItem => item.MANHAMOIGIOI)
</td>
<td>
@Html.DisplayFor(modelItem => item.TENNHAMOIGIOI)
</td>
<td>
@Html.DisplayFor(modelItem => item.DIACHI)
</td>
<td>
@Html.DisplayFor(modelItem => item.DIENTHOAI)
</td>
<td>
@Html.ActionLink("Chỉnh sửa", "Edit", new { id=item.MANHAMOIGIOI })
|
@Html.ActionLink("Chi tiết", "Details", new
{ id=item.MANHAMOIGIOI }) |
@Html.ActionLink("Xóa", "Delete", new { id=item.MANHAMOIGIOI })
</td>
</tr>
}

</table>

27
2.6.Chức năng chỉnh sửa:
2.6.1.Giao diện chức năng chỉnh sửa:

2.6.2. Mã lệnh Controller chức năng chỉnh sửa:


[HttpGet]
public ActionResult Edit(String id)
{
var dt = db.NHAMOIGIOIs.Find(id);
return View(dt);
}
[HttpPost]
public ActionResult Edit(NHAMOIGIOI dt)
{
var updatedt = db.NHAMOIGIOIs.Find(dt.MANHAMOIGIOI);
updatedt.MANHAMOIGIOI = dt.MANHAMOIGIOI;
updatedt.TENNHAMOIGIOI = dt.TENNHAMOIGIOI;
updatedt.DIACHI = dt.DIACHI;
updatedt.DIENTHOAI = dt.DIENTHOAI;

db.SaveChanges();
return RedirectToAction("Index");
}
2.6.3 Mã lệnh Edit chức năng chỉnh sửa:
@model TIEULUAN36.Models.NHAMOIGIOI

@{
ViewBag.Title = "Edit";
}

28
<h2>Chỉnh sửa</h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Nhà môi giới</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.MANHAMOIGIOI)

<div class="form-group">

<div class="col-md-10">
Mã nhà môi giới
@Html.EditorFor(model => model.MANHAMOIGIOI, new
{ htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MANHAMOIGIOI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Tên nhà môi giới
@Html.EditorFor(model => model.TENNHAMOIGIOI, new
{ htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TENNHAMOIGIOI, "",
new { @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Địa chỉ
@Html.EditorFor(model => model.DIACHI, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIACHI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Điện thoại
@Html.EditorFor(model => model.DIENTHOAI, new { htmlAttributes
= new { @class = "form-control" } })
29
@Html.ValidationMessageFor(model => model.DIENTHOAI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Lưu" class="btn btn-default" />
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

2.7.Chức năng thêm:


2.7.1.Giao diện chức năng thêm:

2.7.2.Mã lệnh Controller chức năng thêm:


[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(NHAMOIGIOI dt)
{
db.NHAMOIGIOIs.Add(dt);

30
db.SaveChanges();
return RedirectToAction("Index");
}
2.7.3.Mã lệnh Create chức năng chỉnh sửa:
@model TIEULUAN36.Models.NHAMOIGIOI

@{
ViewBag.Title = "Create";
}

<h2>Tạo mới</h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Nhà môi giới </h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">

<div class="col-md-10">
Mã nhà môi giới
@Html.EditorFor(model => model.MANHAMOIGIOI, new
{ htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MANHAMOIGIOI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Tên nhà môi giới
@Html.EditorFor(model => model.TENNHAMOIGIOI, new
{ htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TENNHAMOIGIOI, "",
new { @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Địa chỉ
@Html.EditorFor(model => model.DIACHI, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIACHI, "", new
{ @class = "text-danger" })

31
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Điện thoại
@Html.EditorFor(model => model.DIENTHOAI, new { htmlAttributes
= new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIENTHOAI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Tạo mới " class="btn btn-default"
/>
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
2.8.Chức năng xóa:
2.8.1. Giao diện chức năng xóa:

32
2.8.2.Mã lệnh Controller chức năng xóa:
public ActionResult Delete(String id)
{
NHAMOIGIOI dt = db.NHAMOIGIOIs.Find(id);
db.NHAMOIGIOIs.Remove(dt);
db.SaveChanges();
return RedirectToAction("Index");
}

2.9.Chức năng hiển thị chi tiết:


2.9.1.Giao diện chức năng hiển thị chi tiết:

2.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:


public ActionResult Details(String id)
{
var lstdt = db.NHAMOIGIOIs.Select(p => p).Where(p => p.MANHAMOIGIOI
== id).FirstOrDefault();
return View(lstdt);
}

2.9.3.Mã lệnh Details Chức năng hiển thị chị tiết:


@model TIEULUAN36.Models.NHAMOIGIOI

@{
ViewBag.Title = "Details";
}

<h2>Chi tiết</h2>

<div>
<h4>Nhà môi giới </h4>
<hr />
<dl class="dl-horizontal">
<dt>
33
Mã nhà môi giới
</dt>

<dd>
@Html.DisplayFor(model => model.MANHAMOIGIOI)
</dd>
<dt>
Tên nhà môi giới
</dt>

<dd>
@Html.DisplayFor(model => model.TENNHAMOIGIOI)
</dd>

<dt>
Địa chỉ
</dt>

<dd>
@Html.DisplayFor(model => model.DIACHI)
</dd>

<dt>
Điện thoại
</dt>

<dd>
@Html.DisplayFor(model => model.DIENTHOAI)
</dd>

</dl>
</div>
<p>
@Html.ActionLink("Chỉnh sửa", "Edit", new { id = Model.MANHAMOIGIOI }) |
@Html.ActionLink("Trở lại danh sách", "Index")
</p>

3.Bảng Công ty:


STT TÊN CỘT KIỂU DỮ ĐỘ DÀI
LIỆU
1 Macongty int 20
2 Tencongty Nchar 50
3 Diachi Nchar 50
4 soluongcophieu int 10
5 Soluongnhanvien int 10

34
3.1.Thiết kế Form:

3.2. Mã lệnh theo HTML Server Control (Cách 1):


<!DOCTYPE html>

<html lang="en-US">
<head>
    <title>
        TIỂU LUẬN KẾT THÚC MÔN
    </title>
</head>
<body>
    <br>
<CENTER>
   
    <table>
        <form>
        <tr><th colspan="3">THÔNG TIN NHÀ CÔNG TY</th></tr>
        <tr>
            <td>Mã công ty</td>
            <td>:</td>
            <td>
                <input type="text"/>
            </td>
        </tr>
        <tr>
            <td>Tên công ty</td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>
        <tr>
            <td>Địa chỉ </td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>

35
        <tr>
            <td>Số lượng cổ phiếu </td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>

        <tr>
            <td>Số lượng  nhân viên </td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>
       
            <tr>
                <td></td>
                <td></td>
                <td><input type="submit" value="Lưu lại" />
                    <input type="submit" value="Đóng"  />
            </td>
            </tr>
       
        </form>
        </table>
</CENTER>
</br>

</body>

3.3. Mã lệnh Web server control:


<div style="display: inline-block;
border: 1px solid blue;
padding: 15px">
<h2 style="text-align: center;">THÔNG TIN CÔNG TY</h2>
<form id=”formCongty” runat=”server”>
<table cellpadding=10 cellspacing=20>
<tr>
<th>Mã công ty</th>
<td>:</td>

36
<td><asp:TextBox type="text" name="txtMacongty"></td>
</tr>
<tr>
<th>Tên công ty</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtTencongty"></td>
</tr>
<tr>
<th>Địa chỉ</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtDiaChi"></td>
</tr>
<tr>
<th>Số lượng cổ phiếu</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtslcophieu"></td>
</tr>
<tr>
<th>Số lượng nhân viên</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtslnhanvien"></td>
</tr>
</table>
<br>
<div style="text-align: center;">
<button type="">Đóng</button>&nbsp; &nbsp;
<button type="submit" runat=”server”>Lưu lại</button>
</div>
</form>
</div>

3.4.Mã lệnh Controller:


using System;
using System.Collections.Generic;

37
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TIEULUAN36.Models;

namespace TIEULUAN36.Controllers
{
public class CONGTYController : Controller
{
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities();
// GET: Default
public ActionResult Index()
{
var lstct = from ct in db.CONGTies select ct;
return View(lstct);
}
[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(CONGTY ct)
{
db.CONGTies.Add(ct);
db.SaveChanges();
return RedirectToAction("Index");
}
public ActionResult Delete(String id)
{
CONGTY ct = db.CONGTies.Find(id);
db.CONGTies.Remove(ct);
db.SaveChanges();
return RedirectToAction("Index");
}
[HttpGet]
public ActionResult Edit(String id)
{
var ct = db.CONGTies.Find(id);
return View(ct);
}
[HttpPost]
public ActionResult Edit(CONGTY ct)
{
var updatect = db.CONGTies.Find(ct.MACONGTY);
updatect.MACONGTY = ct.MACONGTY;
updatect.TENCONGTY = ct.TENCONGTY;
updatect.DIACHI = ct.DIACHI;
updatect.SLCOPHIEU = ct.SLCOPHIEU;
updatect.SLNHANVIEN = ct.SLNHANVIEN;

38
db.SaveChanges();
return RedirectToAction("Index");
}

public ActionResult Details(String id)


{
var lstct = db.CONGTies.Select(p => p).Where(p => p.MACONGTY ==
id).FirstOrDefault();
return View(lstct);
}
}
}

3.5.Chức năng hiển thị:


3.5.1.Giao diện chức năng hiển thị:

3.5.2.Mã lệnh Controller chức năng hiển thị:


public class CONGTYController : Controller
{
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities();
// GET: Default
public ActionResult Index()
{
var lstct = from ct in db.CONGTies select ct;
return View(lstct);
}
3.5.3.Mã lệnh Index chức năng hiển thị:
@model IEnumerable<TIEULUAN36.Models.CONGTY>

@{
ViewBag.Title = "Index";
}

<h2>Danh sách công ty</h2>

<p>
@Html.ActionLink("Tạo mới", "Create")
</p>
<table class="table">
39
<tr>
<th>
Mã công ty
</th>
<th>
Tên công ty
</th>
<th>
Địa chỉ
</th>
<th>
Số lượng cổ phiếu
</th>
<th>
Số lượng nhân viên
</th>
<th></th>
</tr>

@foreach (var item in Model) {


<tr>
<td>
@Html.DisplayFor(modelItem => item.MACONGTY)
</td>
<td>
@Html.DisplayFor(modelItem => item.TENCONGTY)
</td>
<td>
@Html.DisplayFor(modelItem => item.DIACHI)
</td>
<td>
@Html.DisplayFor(modelItem => item.SLCOPHIEU)
</td>
<td>
@Html.DisplayFor(modelItem => item.SLNHANVIEN)
</td>
<td>
@Html.ActionLink("Chỉnh sửa", "Edit", new { id=item.MACONGTY }) |
@Html.ActionLink("Chi tiết", "Details", new { id=item.MACONGTY }) |
@Html.ActionLink("Xóa", "Delete", new { id=item.MACONGTY })
</td>
</tr>
}

</table>

40
3.6.Chức năng chỉnh sửa:
3.6.1.Giao diện chức năng chỉnh sửa:

3.6.2. Mã lệnh Controller chức năng chỉnh sửa:


[HttpGet]
public ActionResult Edit(String id)
{
var ct = db.CONGTies.Find(id);
return View(ct);
}
[HttpPost]
public ActionResult Edit(CONGTY ct)
{
var updatect = db.CONGTies.Find(ct.MACONGTY);
updatect.MACONGTY = ct.MACONGTY;
updatect.TENCONGTY = ct.TENCONGTY;
updatect.DIACHI = ct.DIACHI;
updatect.SLCOPHIEU = ct.SLCOPHIEU;
updatect.SLNHANVIEN = ct.SLNHANVIEN;

db.SaveChanges();
return RedirectToAction("Index");
}
3.6.3 Mã lệnh Edit chức năng chỉnh sửa:
@model TIEULUAN36.Models.CONGTY

@{
ViewBag.Title = "Edit";
41
}

<h2>Chỉnh sửa</h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Công ty</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.MACONGTY)

<div class="form-group">

<div class="col-md-10">
Mã công ty
@Html.EditorFor(model => model.MACONGTY, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MACONGTY, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Tên công ty
@Html.EditorFor(model => model.TENCONGTY, new { htmlAttributes
= new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TENCONGTY, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Địa chỉ
@Html.EditorFor(model => model.DIACHI, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIACHI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
42
Số lượng cổ phiếu
@Html.EditorFor(model => model.SLCOPHIEU, new { htmlAttributes
= new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SLCOPHIEU, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Số lượng nhân viên
@Html.EditorFor(model => model.SLNHANVIEN, new { htmlAttributes
= new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SLNHANVIEN, "", new {
@class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Lưu" class="btn btn-default" />
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

43
3.7.Chức năng thêm:
3.7.1.Giao diện chức năng thêm:

3.7.2.Mã lệnh Controller chức năng thêm:


[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(CONGTY ct)
{
db.CONGTies.Add(ct);
db.SaveChanges();
return RedirectToAction("Index");
}
3.7.3.Mã lệnh Create chức năng thêm :
@model TIEULUAN36.Models.CONGTY

@{
ViewBag.Title = "Create";
}

<h2>Tạo danh sách</h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

44
<div class="form-horizontal">
<h4>Công ty</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">

<div class="col-md-10">
Mã công ty
@Html.EditorFor(model => model.MACONGTY, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MACONGTY, "", new
{ @class = "text-danger" })
</div>

</div>

<div class="form-group">

<div class="col-md-10">
Tên công ty
@Html.EditorFor(model => model.TENCONGTY, new { htmlAttributes
= new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TENCONGTY, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Địa chỉ
@Html.EditorFor(model => model.DIACHI, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIACHI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Số lượng cổ phiếu
@Html.EditorFor(model => model.SLCOPHIEU, new { htmlAttributes
= new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SLCOPHIEU, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
45
Số lượng nhân viên
@Html.EditorFor(model => model.SLNHANVIEN, new { htmlAttributes
= new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SLNHANVIEN, "", new {
@class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Tạo mới " class="btn btn-default"
/>
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

3.8.Chức năng xóa:


3.8.1. Giao diện chức năng xóa:

3.8.2.Mã lệnh Controller chức năng xóa:


public ActionResult Delete(String id)
{
CONGTY ct = db.CONGTies.Find(id);
db.CONGTies.Remove(ct);
db.SaveChanges();
return RedirectToAction("Index");

46
}

3.9.Chức năng hiển thị chi tiết:


3.9.1.Giao diện chức năng hiển thị chi tiết:

3.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:


public ActionResult Details(String id)
{
var lstct = db.CONGTies.Select(p => p).Where(p => p.MACONGTY ==
id).FirstOrDefault();
return View(lstct);
}

3.9.3.Mã lệnh Details Chức năng hiển thị chị tiết:


@model TIEULUAN36.Models.CONGTY

@{
ViewBag.Title = "Details";
}

<h2>Chi tiết </h2>

<div>
<h4>Công ty</h4>
<hr />
<dl class="dl-horizontal">
<dt>
Mã công ty
</dt>

<dd>
@Html.DisplayFor(model => model.MACONGTY)
</dd>
<dt>
Tên công ty
</dt>
47
<dd>
@Html.DisplayFor(model => model.TENCONGTY)
</dd>

<dt>
Địa chỉ
</dt>

<dd>
@Html.DisplayFor(model => model.DIACHI)
</dd>

<dt>
Số lượng cổ phiếu
</dt>

<dd>
@Html.DisplayFor(model => model.SLCOPHIEU)
</dd>

<dt>
Số lượng nhân viên
</dt>

<dd>
@Html.DisplayFor(model => model.SLNHANVIEN)
</dd>

</dl>
</div>
<p>
@Html.ActionLink("Chỉnh sửa", "Edit", new { id = Model.MACONGTY }) |
@Html.ActionLink("Trở về danh sách", "Index")
</p>

4.Bảng Diễn biến giá:


STT TÊN CỘT KIỂU DỮ ĐỘ DÀI
LIỆU
1 macongty int 20
2 Ngay int 10
3 Giacophieu int 20

48
4.1.Thiết kế Form:

4.2. Mã lệnh theo HTML Server Control (Cách 1):


<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>
        TIỂU LUẬN KẾT THÚC MÔN
    </title>
</head>
<body>
    <br>
<CENTER>
   
    <table>
        <form>
        <tr><th colspan="3">THÔNG TIN DIỄN BIẾN GIÁ</th></tr>
        <tr>
            <td>Mã công ty</td>
            <td>:</td>
            <td>
                <input type="text"/>
            </td>
        </tr>
        <tr>
            <td>Ngày</td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>
        <tr>
            <td>Giá của 1 cổ phiếu </td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>
       

49
            <tr>
                <td></td>
                <td></td>
                <td><input type="submit" value="Lưu lại" />
                    <input type="submit" value="Đóng"  />
            </td>
            </tr>
       
        </form>
        </table>
</CENTER>
</br>

</body>

4.3. Mã lệnh Web server control:


<div style="display: inline-block;
border: 1px solid blue;
padding: 15px">
<h2 style="text-align: center;">THÔNG TIN DIỄN BIẾN GIÁ</h2>
<form id=”formDienbiengia” runat=”server”>
<table cellpadding=10 cellspacing=20>
<tr>
<th>Mã công ty</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtMacongty"></td>
</tr>
<tr>
<th>Ngày</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtNgay"></td>
</tr>
<tr>
<th>Giá của 1 cổ phiếu</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtslcophieu"></td>
</tr>

50
</table>
<br>
<div style="text-align: center;">
<button type="">Đóng</button>&nbsp; &nbsp;
<button type="submit" runat=”server”>Lưu lại</button>
</div>
</form>
</div>

4.4.Mã lệnh Controller:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TIEULUAN36.Models;

namespace TIEULUAN36.Controllers
{
public class DIENBIENGIAController : Controller
{
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities();
// GET: Default
public ActionResult Index()
{
var lstdt = from dt in db.DIENBIENGIAs select dt;
return View(lstdt);
}
[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(DIENBIENGIA dt)
{
db.DIENBIENGIAs.Add(dt);
db.SaveChanges();
return RedirectToAction("Index");
}
public ActionResult Delete(String id)
{
DIENBIENGIA dt = db.DIENBIENGIAs.Find(id);
db.DIENBIENGIAs.Remove(dt);
db.SaveChanges();
return RedirectToAction("Index");
}
51
[HttpGet]
public ActionResult Edit(String id)
{
var dt = db.DIENBIENGIAs.Find(id);
return View(dt);
}
[HttpPost]
public ActionResult Edit(DIENBIENGIA dt)
{
var updatedt = db.DIENBIENGIAs.Find(dt.MACONGTY);
updatedt.MACONGTY = dt.MACONGTY;
updatedt.NGAY = dt.NGAY;
updatedt.GIA1COPHIEU = dt.GIA1COPHIEU;

db.SaveChanges();
return RedirectToAction("Index");
}

public ActionResult Details(String id)


{
var lstdt = db.DIENBIENGIAs.Select(p => p).Where(p => p.MACONGTY ==
id).FirstOrDefault();
return View(lstdt);
}
}
}

4.5.Chức năng hiển thị:


4.5.1.Giao diện chức năng hiển thị:

4.5.2.Mã lệnh Controller:


public class DIENBIENGIAController : Controller
{
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities();
// GET: Default
public ActionResult Index()

52
{
var lstdt = from dt in db.DIENBIENGIAs select dt;
return View(lstdt);
}
4.5.3.Mã lệnh Index chức năng hiển thị:
@model IEnumerable<TIEULUAN36.Models.DIENBIENGIA>

@{
ViewBag.Title = "Index";
}

<h2>Diễn biến giá</h2>

<p>
@Html.ActionLink("Tạo mới ", "Create")
</p>
<table class="table">
<tr>
<th>
Mã công ty
</th>
<th>
Ngày
</th>
<th>
Giá của 1 cổ phiếu
</th>
<th></th>
</tr>

@foreach (var item in Model) {


<tr>
<td>
@Html.DisplayFor(modelItem => item.MACONGTY)
</td>
<td>
@Html.DisplayFor(modelItem => item.NGAY)
</td>
<td>
@Html.DisplayFor(modelItem => item.GIA1COPHIEU)
</td>
<td>
@Html.ActionLink("Chỉnh sửa", "Edit", new { id=item.MACONGTY }) |
@Html.ActionLink("Chi tiết", "Details", new { id=item.MACONGTY }) |
@Html.ActionLink("Xóa", "Delete", new { id=item.MACONGTY })
</td>
</tr>
}

</table>

53
4.6.Chức năng chỉnh sửa:
4.6.1.Giao diện chức năng chỉnh sửa:

4.6.2. Mã lệnh Controller chức năng chỉnh sửa:


[HttpGet]
public ActionResult Edit(String id)
{
var dt = db.DIENBIENGIAs.Find(id);
return View(dt);
}
[HttpPost]
public ActionResult Edit(DIENBIENGIA dt)
{
var updatedt = db.DIENBIENGIAs.Find(dt.MACONGTY);
updatedt.MACONGTY = dt.MACONGTY;
updatedt.NGAY = dt.NGAY;
updatedt.GIA1COPHIEU = dt.GIA1COPHIEU;

db.SaveChanges();
return RedirectToAction("Index");
}
4.6.3 Mã lệnh Edit chức năng chỉnh sửa:
@model TIEULUAN36.Models.DIENBIENGIA

@{
ViewBag.Title = "Edit";
}

<h2>chỉnh sửa</h2>

54
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Diễn biến giá</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.MACONGTY)

<div class="form-group">

<div class="col-md-10">
Mã công ty
@Html.EditorFor(model => model.MACONGTY, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MACONGTY, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Ngày
@Html.EditorFor(model => model.NGAY, new { htmlAttributes = new
{ @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NGAY, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Giá của 1 cổ phiếu
@Html.EditorFor(model => model.GIA1COPHIEU, new
{ htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.GIA1COPHIEU, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Lưu" class="btn btn-default" />
</div>
</div>
</div>
}

<div>
55
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
4.7.Chức năng thêm:
4.7.1.Giao diện chức năng thêm:

4.7.2.Mã lệnh Controller chức năng thêm:


[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(DIENBIENGIA dt)
{
db.DIENBIENGIAs.Add(dt);
db.SaveChanges();
return RedirectToAction("Index");
}
4.7.3.Mã lệnh Create chức năng thêm:
model TIEULUAN36.Models.DIENBIENGIA

@{
ViewBag.Title = "Create";
}

<h2>Tạo mới </h2>


56
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Diễn biến giá</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">

<div class="col-md-10">
Mã công ty
@Html.EditorFor(model => model.MACONGTY, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MACONGTY, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Ngày
@Html.EditorFor(model => model.NGAY, new { htmlAttributes = new
{ @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NGAY, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Giá của 1 cổ phiếu
@Html.EditorFor(model => model.GIA1COPHIEU, new
{ htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.GIA1COPHIEU, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Tạo mới " class="btn btn-default"
/>
</div>
</div>
</div>
}

57
<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

4.8.Chức năng xóa:


4.8.1. Giao diện chức năng xóa:

4.8.2.Mã lệnh Controller chức năng xóa:


public ActionResult Delete(String id)
{
DIENBIENGIA dt = db.DIENBIENGIAs.Find(id);
db.DIENBIENGIAs.Remove(dt);
db.SaveChanges();
return RedirectToAction("Index");
}
4.9.Chức năng hiển thị chi tiết:
4.9.1.Giao diện chức năng hiển thị chi tiết:

4.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:


public ActionResult Details(String id)
{

58
var lstdt = db.DIENBIENGIAs.Select(p => p).Where(p => p.MACONGTY ==
id).FirstOrDefault();
return View(lstdt);
}
4.9.3.Mã lệnh Details Chức năng hiển thị chị tiết:
@model TIEULUAN36.Models.DIENBIENGIA

@{
ViewBag.Title = "Details";
}

<h2>chi tiết</h2>

<div>
<h4>Diễn biến giá</h4>
<hr />
<dl class="dl-horizontal">

<dt>
Mã công ty
</dt>

<dd>
@Html.DisplayFor(model => model.MACONGTY)
</dd>
<dt>
Ngày
</dt>

<dd>
@Html.DisplayFor(model => model.NGAY)
</dd>

<dt>
Giá của 1 cổ phiếu
</dt>

<dd>
@Html.DisplayFor(model => model.GIA1COPHIEU)
</dd>

</dl>
</div>
<p>
@Html.ActionLink("Chỉnh sửa", "Edit", new { id = Model.MACONGTY }) |
@Html.ActionLink("Back to List", "Index")
</p>

5.Bảng Giao dịch:


STT TÊN CỘT KIỂU DỮ LIỆU ĐỘ DÀI

59
1 Sothutugiaodich Int 20
2 Ngaygiaodich Int 10
3 Macongty Int 20
4 Manhamoigioi Int 20
5 Makhban Int 20
6 Makhmua int 20
7 Soluong int 20

5.1.Thiết Kế form:

5.2. Mã lệnh theo HTML Server Control (Cách 1):


<!DOCTYPE html>

<html lang="en-US">
<head>
    <title>
        TIỂU LUẬN KẾT THÚC MÔN
    </title>
</head>
<body>
    <br>
<CENTER>
   
    <table>
        <form>
        <tr><th colspan="3">THÔNG TIN GIAO DỊCH</th></tr>
        <tr>
            <td>Số thứ tự giao dịch</td>
            <td>:</td>
            <td>
                <input type="text"/>
60
            </td>
        </tr>
        <tr>
            <td>Ngày giao dịch</td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>
        <tr>
            <td> Mã công ty </td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>
        <tr>
            <td> Mã nhà môi giới </td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>
       
        <tr>
            <td> Mã khách hàng bán</td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>
        <tr>
            <td> Mã khách hàng mua </td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>
        <tr>
            <td> Số lượng </td>
            <td>:</td>
            <td>
                 <input type="text"/>
           </td>
        </tr>
            <tr>
                <td></td>
                <td></td>
                <td><input type="submit" value="Lưu lại" />
                    <input type="submit" value="Đóng"  />
            </td>
61
            </tr>
       
        </form>
        </table>
</CENTER>
</br>

</body>
5.3. Mã lệnh Web server control:
<div style="display: inline-block;
border: 1px solid blue;
padding: 15px">
<h2 style="text-align: center;">THÔNG TIN GIAO DỊCH</h2>
<form id=”formGiaodich” runat=”server”>
<table cellpadding=10 cellspacing=20>
<tr>
<th>Số thứ tự giao dịch</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtSttgiaodich"></td>
</tr>
<tr>
<th>Ngày giao dịch</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtNgaygd"></td>
</tr>
<tr>
<th>Mã công ty</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtCongty"></td>
</tr>
<tr>
<th>Mã nhà môi giơi</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtManhamoigioi"></td>
</tr>

62
<tr>
<th>Mã khách hàng bán</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtMakhban"></td>
</tr>
<tr>
<th>Mã khách hàng mua</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtMakhmua"></td>
</tr>
<tr>
<th>Số lượng </th>
<td>:</td>
<td><asp:TextBox type="text" name="txtSoluong"></td>
</tr>

</table>
<br>
<div style="text-align: center;">
<button type="">Đóng</button>&nbsp; &nbsp;
<button type="submit" runat=”server”>Lưu lại</button>
</div>
</form>
</div>

5.4.Mã lệnh Controller:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TIEULUAN36.Models;

namespace TIEULUAN36.Controllers
{
public class GIAODICHController : Controller
{

63
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities();
// GET: Default
public ActionResult Index()
{
var lstgd = from gd in db.GIAODICHes select gd;
return View(lstgd);
}
[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(GIAODICH gd)
{
db.GIAODICHes.Add(gd);
db.SaveChanges();
return RedirectToAction("Index");
}
public ActionResult Delete(String id)
{
GIAODICH gd = db.GIAODICHes.Find(id);
db.GIAODICHes.Remove(gd);
db.SaveChanges();
return RedirectToAction("Index");
}
[HttpGet]
public ActionResult Edit(String id)
{
var gd = db.GIAODICHes.Find(id);
return View(gd);
}
[HttpPost]
public ActionResult Edit(GIAODICH gd)
{
var updategd = db.GIAODICHes.Find(gd.STTGIAODICH);
updategd.STTGIAODICH = gd.STTGIAODICH;
updategd.NGAYGIAODICH = gd.NGAYGIAODICH;
updategd.MANHAMOIGIOI = gd.MANHAMOIGIOI;
updategd.MAKHMUA = gd.MAKHMUA;
updategd.MAKHBAN = gd.MAKHBAN;
updategd.SOLUONG = gd.SOLUONG;
updategd.MACONGTY = gd.MACONGTY;
db.SaveChanges();
return RedirectToAction("Index");
}

public ActionResult Details(String id)


{
var lstgd = db.GIAODICHes.Select(p => p).Where(p => p.STTGIAODICH
== id).FirstOrDefault();
64
return View(lstgd);
}
}
}

5.5.Chức năng hiển thị:


5.5.1.Giao diện chức năng hiển thị:

5.5.2.Mã lệnh Controller:


public class GIAODICHController : Controller
{
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities();
// GET: Default
public ActionResult Index()
{
var lstgd = from gd in db.GIAODICHes select gd;
return View(lstgd);
}
5.5.3.Mã lệnh Index chức năng hiển thị:
@model IEnumerable<TIEULUAN36.Models.GIAODICH>

@{
ViewBag.Title = "Index";
}

<h2>Danh sách giao dịch</h2>

<p>
@Html.ActionLink("Tạo mới", "Create")
</p>
<table class="table">
<tr>
<th>
Số thứ tự giao dịch
</th>
<th>
65
Ngày giao dịch
</th>
<th>
Mã nhà môi giới
</th>
<th>
Mã khách hàng mua
</th>
<th>
Mã khách hàng bán
</th>
<th>
Số lượng
</th>
<th>
Mã công ty
</th>
<th></th>
</tr>

@foreach (var item in Model) {


<tr>
<td>
@Html.DisplayFor(modelItem => item.STTGIAODICH)
</td>
<td>
@Html.DisplayFor(modelItem => item.NGAYGIAODICH)
</td>
<td>
@Html.DisplayFor(modelItem => item.MANHAMOIGIOI)
</td>
<td>
@Html.DisplayFor(modelItem => item.MAKHMUA)
</td>
<td>
@Html.DisplayFor(modelItem => item.MAKHBAN)
</td>
<td>
@Html.DisplayFor(modelItem => item.SOLUONG)
</td>
<td>
@Html.DisplayFor(modelItem => item.MACONGTY)
</td>
<td>
@Html.ActionLink("Chỉnh sửa", "Edit", new { id=item.STTGIAODICH })
|
@Html.ActionLink("Chi tiết ", "Details", new
{ id=item.STTGIAODICH }) |
@Html.ActionLink("Xóa ", "Delete", new { id=item.STTGIAODICH })
</td>
</tr>
}
66
</table>
5.6.Chức năng chỉnh sửa:
5.6.1.Giao diện chức năng chỉnh sửa:

5.6.2. Mã lệnh Controller chức năng chỉnh sửa:


[HttpGet]
public ActionResult Edit(String id)
{
var gd = db.GIAODICHes.Find(id);
return View(gd);
}
[HttpPost]
public ActionResult Edit(GIAODICH gd)
{
var updategd = db.GIAODICHes.Find(gd.STTGIAODICH);
updategd.STTGIAODICH = gd.STTGIAODICH;
updategd.NGAYGIAODICH = gd.NGAYGIAODICH;
updategd.MANHAMOIGIOI = gd.MANHAMOIGIOI;
updategd.MAKHMUA = gd.MAKHMUA;
updategd.MAKHBAN = gd.MAKHBAN;
updategd.SOLUONG = gd.SOLUONG;
updategd.MACONGTY = gd.MACONGTY;
db.SaveChanges();
67
return RedirectToAction("Index");
}
5.6.3 Mã lệnh Edit chức năng chỉnh sửa:
@model TIEULUAN36.Models.GIAODICH

@{
ViewBag.Title = "Edit";
}

<h2>Chỉnh sửa</h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Giao dịch</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.STTGIAODICH)

<div class="form-group">

<div class="col-md-10">
Số thứ tự giao dịch
@Html.EditorFor(model => model.STTGIAODICH, new
{ htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.STTGIAODICH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Ngày giao dịch
@Html.EditorFor(model => model.NGAYGIAODICH, new
{ htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NGAYGIAODICH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Mã nhà môi giới
@Html.EditorFor(model => model.MANHAMOIGIOI, new
{ htmlAttributes = new { @class = "form-control" } })

68
@Html.ValidationMessageFor(model => model.MANHAMOIGIOI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Mã khách hàng mua
@Html.EditorFor(model => model.MAKHMUA, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MAKHMUA, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Mã khách hàng bán
@Html.EditorFor(model => model.MAKHBAN, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MAKHBAN, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Số lượng
@Html.EditorFor(model => model.SOLUONG, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SOLUONG, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Mã công ty
@Html.EditorFor(model => model.MACONGTY, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MACONGTY, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Lưu" class="btn btn-default" />
69
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
5.7.Chức năng thêm:
5.7.1.Giao diện chức năng thêm:

5.7.2.Mã lệnh Controller chức năng thêm:


[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(GIAODICH gd)
{
db.GIAODICHes.Add(gd);
70
db.SaveChanges();
return RedirectToAction("Index");
}
5.7.3.Mã lệnh Create chức năng thêm:
@model TIEULUAN36.Models.GIAODICH

@{
ViewBag.Title = "Create";
}

<h2>Tạo mới </h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Giao dịch</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">

<div class="col-md-10">
Số thứ tự giao dịch
@Html.EditorFor(model => model.STTGIAODICH, new
{ htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.STTGIAODICH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Ngày giao dịch
@Html.EditorFor(model => model.NGAYGIAODICH, new
{ htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NGAYGIAODICH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Mã nhà môi giới
@Html.EditorFor(model => model.MANHAMOIGIOI, new
{ htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MANHAMOIGIOI, "", new
{ @class = "text-danger" })

71
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Mã khách hàng mua
@Html.EditorFor(model => model.MAKHMUA, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MAKHMUA, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Mã khách hàng bán
@Html.EditorFor(model => model.MAKHBAN, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MAKHBAN, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Số lượng
@Html.EditorFor(model => model.SOLUONG, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SOLUONG, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Mã công ty
@Html.EditorFor(model => model.MACONGTY, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MACONGTY, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Tạo mới" class="btn btn-default" />
</div>
</div>
72
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
5.8.Chức năng xóa:
5.8.1. Giao diện chức năng xóa:

5.8.2.Mã lệnh Controller chức năng xóa:


public ActionResult Delete(String id)
{
GIAODICH gd = db.GIAODICHes.Find(id);
db.GIAODICHes.Remove(gd);
db.SaveChanges();
return RedirectToAction("Index");
}

73
5.9.Chức năng hiển thị chi tiết:
5.9.1.Giao diện chức năng hiển thị chi tiết:

5.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:


public ActionResult Details(String id)
{
var lstgd = db.GIAODICHes.Select(p => p).Where(p => p.STTGIAODICH
== id).FirstOrDefault();
return View(lstgd);
}
5.9.3.Mã lệnh Details Chức năng hiển thị chị tiết:
@model TIEULUAN36.Models.GIAODICH

@{
ViewBag.Title = "Details";
}

<h2>Chi tiét</h2>

<div>
<h4>Giao dịch</h4>
<hr />
<dl class="dl-horizontal">
<dt>
Số thứ tự giao dịch
</dt>

<dd>
@Html.DisplayFor(model => model.STTGIAODICH)
</dd>
<dt>
Ngày giao dịch
</dt>

74
<dd>
@Html.DisplayFor(model => model.NGAYGIAODICH)
</dd>

<dt>
Mã nhà môi giới
</dt>

<dd>
@Html.DisplayFor(model => model.MANHAMOIGIOI)
</dd>

<dt>
Mã khách hàng mua
</dt>

<dd>
@Html.DisplayFor(model => model.MAKHMUA)
</dd>

<dt>
Mã khách hàng bán
</dt>

<dd>
@Html.DisplayFor(model => model.MAKHBAN)
</dd>

<dt>
Số lượng
</dt>

<dd>
@Html.DisplayFor(model => model.SOLUONG)
</dd>

<dt>
Mã công ty
</dt>

<dd>
@Html.DisplayFor(model => model.MACONGTY)
</dd>

</dl>
</div>
<p>
@Html.ActionLink("Chỉnh sửa", "Edit", new { id = Model.STTGIAODICH }) |
@Html.ActionLink("Back to List", "Index")
</p>

75
6. Bảng Khách hàng mua
6.1. Thiết kế form:

6.2. Mã lệnh theo HTML Server Control (Cách 1):


<!DOCTYPE html>

<html lang="en-US">
<head>
    <title>
        TIỂU LUẬN KẾT THÚC MÔN
    </title>
</head>
<body>
    <br>
<CENTER>
   
        <form >
         <table>
            <tr><th colspan="3">THÔNG TIN KHÁCH HÀNG</th></tr>

        <tr>
            <td>Mã khách hàng</td>
            <td>:</td>
            <td> <input type="text"/></td>
        </tr>
        <tr>
            <td>Tên khách hàng</td>
            <td>:</td>
            <td> <input type="text"/></td>
        </tr>
        <tr>
            <td>Địa chỉ </td>
            <td>:</td>
            <td> <input type="text"/></td>
        </tr>
        <tr>
            <td>Điện thoại </td>
            <td>:</td>
            <td> <input type="text"/></td>
76
        </tr>
        <tr>
            <td>Thu nhập </td>
            <td>:</td>
            <td> <input type="text"/></td>
        </tr>
       
            <tr>
                <td></td>
                <td></td>
                <td><input type="submit" value="Lưu lại" />
                    <input type="submit" value="Đóng" />
            </td>
            </tr>
         
        </table>
       
        </form>
       
</CENTER>
</br>

</body>

</html>

6.3. Mã lệnh Web server control:


<div style="display: inline-block;
border: 1px solid blue;
padding: 15px">
<h2 style="text-align: center;">THÔNG TIN KHÁCH HÀNG</h2>
<form id=”formKhachhang” runat=”server”>
<table cellpadding=10 cellspacing=20>
<tr>
<th>Mã khách hàng mua</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtMakh"></td>
</tr>
<tr>
<th>Tên khách hàng mua</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtTenkh"></td>
77
</tr>
<tr>
<th>Địa chỉ</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtDiaChi"></td>
</tr>
<tr>
<th>Điện thoại</th>
<td>:</td>
<td><asp:TextBox type="text" name="txtDienThoai"></td>
</tr>

</table>
<br>
<div style="text-align: center;">
<button type="">Đóng</button>&nbsp; &nbsp;
<button type="submit" runat=”server”>Lưu lại</button>
</div>
</form>
</div>

6.4.Mã lệnh Controller:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TIEULUAN36.Models;

namespace TIEULUAN36.Controllers
{
public class KHACHHANGMUAtController : Controller
{
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities ();
// GET: Default
public ActionResult Index()
{
var lstkhm = from khm in db.KHACHHANGMUAs select khm;
return View(lstkhm);

78
}
[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(KHACHHANGMUA khm)
{
db.KHACHHANGMUAs.Add(khm);
db.SaveChanges();
return RedirectToAction("Index");
}
public ActionResult Delete(String id)
{
KHACHHANGMUA khm = db.KHACHHANGMUAs.Find(id);
db.KHACHHANGMUAs.Remove(khm);
db.SaveChanges();
return RedirectToAction("Index");
}
[HttpGet]

public ActionResult Edit(String id)


{
var khm = db.KHACHHANGMUAs.Find(id);
return View(khm);
}

[HttpPost]
public ActionResult Edit(KHACHHANGMUA khm)
{
var updatekhm = db.KHACHHANGMUAs.Find(khm.MAKH);
updatekhm.MAKH = khm.MAKH;
updatekhm.TENKH = khm.TENKH;
updatekhm.DIACHI = khm.DIACHI;
updatekhm.DIENTHOAI = khm.DIENTHOAI;
updatekhm.THUNHAP= khm.THUNHAP;

db.SaveChanges();
return RedirectToAction("Index");
}

public ActionResult Details(String id)


{
var lstkhm = db.KHACHHANGMUAs.Select(p => p).Where(p => p.MAKH ==
id).FirstOrDefault();
return View(lstkhm);
}
}
}

79
6.5.Chức năng hiển thị:
6.5.1.Giao diện chức năng hiển thị:

6.5.2.Mã lệnh Controller:


public class KHACHHANGMUAtController : Controller
{
QUANLYTHITRUONGCHUNGKHOANEntities db = new
QUANLYTHITRUONGCHUNGKHOANEntities ();
// GET: Default
public ActionResult Index()
{
var lstkhm = from khm in db.KHACHHANGMUAs select khm;
return View(lstkhm);
}
6.5.3.Mã lệnh Index chức năng hiển thị:
@model IEnumerable<TIEULUAN36.Models.KHACHHANGMUA>

@{
ViewBag.Title = "Index";
}

<h2>Danh sách khách hàng mua</h2>

<p>
@Html.ActionLink("Tạo mới ", "Create")
</p>
<table class="table">
<tr>
<th>
Mã khách hàng mua
</th>
<th>
Tên khách hàng mua
</th>
<th>
Địa chỉ
80
</th>
<th>
Điện thoại
</th>
<th>
Thu nhập
</th>
<th></th>
</tr>

@foreach (var item in Model) {


<tr>
<td>
@Html.DisplayFor(modelItem => item.MAKH)
</td>
<td>
@Html.DisplayFor(modelItem => item.TENKH)
</td>
<td>
@Html.DisplayFor(modelItem => item.DIACHI)
</td>
<td>
@Html.DisplayFor(modelItem => item.DIENTHOAI)
</td>
<td>
@Html.DisplayFor(modelItem => item.THUNHAP)
</td>
<td>
@Html.ActionLink("Chỉnh sửa", "Edit", new { id=item.MAKH }) |
@Html.ActionLink("chi tiết", "Details", new { id=item.MAKH }) |
@Html.ActionLink("Xóa", "Delete", new { id=item.MAKH })
</td>
</tr>
}

</table>

81
2.6.Chức năng chỉnh sửa:
2.6.1.Giao diện chức năng chỉnh sửa:

2.6.2. Mã lệnh Controller chức năng chỉnh sửa:


public ActionResult Edit(String id)
{
var khm = db.KHACHHANGMUAs.Find(id);
return View(khm);
}

[HttpPost]
public ActionResult Edit(KHACHHANGMUA khm)
{
var updatekhm = db.KHACHHANGMUAs.Find(khm.MAKH);
updatekhm.MAKH = khm.MAKH;
updatekhm.TENKH = khm.TENKH;
updatekhm.DIACHI = khm.DIACHI;
updatekhm.DIENTHOAI = khm.DIENTHOAI;
updatekhm.THUNHAP= khm.THUNHAP;

db.SaveChanges();
return RedirectToAction("Index");
}
2.6.3 Mã lệnh Edit chức năng chỉnh sửa:
@model TIEULUAN36.Models.KHACHHANGMUA

@{
82
ViewBag.Title = "Edit";
}

<h2>Chỉnh sửa</h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Khách hàng mua</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.MAKH)

<div class="form-group">

<div class="col-md-10">
Mã Khách hàng mua
@Html.EditorFor(model => model.MAKH, new { htmlAttributes = new
{ @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MAKH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Tên khách hàng mua
@Html.EditorFor(model => model.TENKH, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TENKH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Địa chỉ
@Html.EditorFor(model => model.DIACHI, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIACHI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
83
Điện thoại
@Html.EditorFor(model => model.DIENTHOAI, new { htmlAttributes
= new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIENTHOAI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Thu nhập
@Html.EditorFor(model => model.THUNHAP, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.THUNHAP, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Lưu" class="btn btn-default" />
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

84
2.7.Chức năng thêm:
2.7.1.Giao diện chức năng thêm:

2.7.2.Mã lệnh Controller chức năng thêm:


[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(KHACHHANGMUA khm)
{
db.KHACHHANGMUAs.Add(khm);
db.SaveChanges();
return RedirectToAction("Index");
}
2.7.3.Mã lệnh Create chức năng thêm:
@model TIEULUAN36.Models.KHACHHANGMUA

@{
ViewBag.Title = "Create";
}

<h2>Tạo mới</h2>

85
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>Khách hàng mua</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">

<div class="col-md-10">
Mã khách hàng mua
@Html.EditorFor(model => model.MAKH, new { htmlAttributes = new
{ @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MAKH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Tên khách hàng mua
@Html.EditorFor(model => model.TENKH, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TENKH, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Địa chỉ
@Html.EditorFor(model => model.DIACHI, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIACHI, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">

<div class="col-md-10">
Điện thoại
@Html.EditorFor(model => model.DIENTHOAI, new { htmlAttributes
= new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DIENTHOAI, "", new
{ @class = "text-danger" })
</div>
</div>

86
<div class="form-group">

<div class="col-md-10">
Thu nhập
@Html.EditorFor(model => model.THUNHAP, new { htmlAttributes =
new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.THUNHAP, "", new
{ @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Tạo mới" class="btn btn-default" />
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
2.8.Chức năng xóa:
2.8.1. Giao diện chức năng xóa:

2.8.2.Mã lệnh Controller chức năng xóa:


public ActionResult Delete(String id)
{
KHACHHANGMUA khm = db.KHACHHANGMUAs.Find(id);
db.KHACHHANGMUAs.Remove(khm);
db.SaveChanges();
return RedirectToAction("Index");
}
87
2.9.Chức năng hiển thị chi tiết:
2.9.1.Giao diện chức năng hiển thị chi tiết:

2.9.2.Mã lệnh Controller chức năng hiển thị chi tiết:


public ActionResult Details(String id)
{
var lstkhm = db.KHACHHANGMUAs.Select(p => p).Where(p => p.MAKH ==
id).FirstOrDefault();
return View(lstkhm);
}
2.9.3.Mã lệnh Details Chức năng hiển thị chị tiết:
@model TIEULUAN36.Models.KHACHHANGMUA

@{
ViewBag.Title = "Details";
}

<h2>Chi tiết</h2>

<div>
<h4>Khách hàng mua</h4>
<hr />
<dl class="dl-horizontal">
<dt>
Mã khách hàng mua
</dt>

<dd>
@Html.DisplayFor(model => model.MAKH)
</dd>
<dt>
Tên khách hàng mua
</dt>

<dd>
88
@Html.DisplayFor(model => model.TENKH)
</dd>

<dt>
Địa chỉ
</dt>

<dd>
@Html.DisplayFor(model => model.DIACHI)
</dd>

<dt>
Điện thoại
</dt>

<dd>
@Html.DisplayFor(model => model.DIENTHOAI)
</dd>

<dt>
Thu nhập
</dt>

<dd>
@Html.DisplayFor(model => model.THUNHAP)
</dd>

</dl>
</div>
<p>
@Html.ActionLink("chỉnh sửa", "Edit", new { id = Model.MAKH }) |
@Html.ActionLink("Back to List", "Index")
</p>

89
90
91

You might also like