1. Trang chủ
  2. » Giáo án - Bài giảng

Thực hành lập trình trên môi trường windows

68 59 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Thực hành lập trình trên môi trường Windows
Trường học Hutech University
Chuyên ngành Information Technology
Thể loại Workbook
Năm xuất bản 2023
Thành phố Ho Chi Minh City
Định dạng
Số trang 68
Dung lượng 2,92 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Field private string studentID; private string fullName; private float averageScore; private string faculty; //2... //case 3- DS Sinh viên khoa CNTT static void DisplayStudentsByFac

Trang 1

Biên

www.hutech.edu.vn

Trang 2

*1.2023.CMP371*

tailieuhoctap@hutech.edu.vn

Trang 3

I II

1

1.1 1

1.2 2

10

2.1 10

2.2 11

2.3 17

25

3.1 25

3.2 25

33

4.1 33

4.2 33

48

5.1 48

5.2 48

59

Trang 7

- bool , decimal , double , float , int , string, DateTime , bool? , decimal?,

double? , float? , int? , long?, DateTime? , object, var,

Trang 11

Student: ck vào Lab01-02 Project

class Student

{

//1 Field

private string studentID;

private string fullName;

private float averageScore;

private string faculty;

//2 Property

public string StudentID { get => studentID; set => studentID = value; }

public string FullName { get => fullName; set => fullName = value; }

public float AverageScore { get => averageScore; set => averageScore = value; } public string Faculty { get => faculty; set => faculty = value; }

this.studentID = studentID;

this.fullName = fullName;

this.averageScore = averageScore;

this.faculty = faculty;

Trang 12

6 BÀI 1:

{

Console.WriteLine( , this.StudentID,

this.fullName, this.Faculty, this.AverageScore);

}

}

Main

List<Student> studentList = new List<Student>();

bool exit = false;

Trang 14

//case 3- DS Sinh viên khoa CNTT

static void DisplayStudentsByFaculty(List<Student> studentList, string faculty)

//case 6: DS sinh vien co DTB >=5 va thuoc khoa CNTT

static void DisplayStudentsByFacultyAndScore(List<Student> studentList, string

faculty, float minDTB)

Trang 15

-

1 Thêm sinh viên

2 Thêm giáo viên

Trang 17

2.2 H NG D N LÀM QUEN V I WINDOWS FORM

- New Project Language : Visual C#

Name: Tên Project

Hình 2.1

-

Trang 18

12 BÀI 2:

-

-

-

Trang 22

float number1 = float.Parse(txtNumber1.Text);

float number2 = float.Parse(txtNumber2.Text);

float result = number1 + number2;

Trang 23

float number1 = float.Parse(txtNumber1.Text);

float number2 = float.Parse(txtNumber2.Text);

float result = number1 + number2;

Trang 27

: Lab02-03 Lab02

- - -

này

n màu khác nhau

Trang 28

Button btn = sender as Button;

if (btn.BackColor == Color.White)

btn.BackColor = Color.Blue;

else if (btn.BackColor == Color.Blue)

btn.BackColor = Color.White;

else if (btn.BackColor == Color.Yellow)

MessageBox.Show("Gh c bán!!");

}

-

Trang 30

24 BÀI 2:

-

4.3

Trang 32

26 BÀI 3:

-

Trang 33

this.toolStripStatusLabel1.Text = string.Format("Hôm nay là ngày {0} - Bây gi là {1}",

DateTime.Now.ToString("dd/MM/yyyy"), DateTime.Now.ToString("hh:mm:ss tt"));

}

SubMenu Open // X lý menu Open S d ng OpenFileDialog

private void openToolStripMenuItem_Click(object sender, EventArgs e)

//hien thi openDialog

if (dlg.ShowDialog() == DialogResult.OK)

axWindowsMediaPlayer1.URL = dlg.FileName; //L y tên file c n m

}

Trang 34

this.toolStripStatusLabel1.Text = string.Format("Hôm nay là ngày {0} - Bây gi là {1}",

DateTime.Now.ToString("dd/MM/yyyy"), DateTime.Now.ToString("hh:mm:ss tt"));

}

SubMenu Open // X lý menu Open S d ng OpenFileDialog

private void openToolStripMenuItem_Click(object sender, EventArgs e)

//hien thi openDialog

if (dlg.ShowDialog() == DialogResult.OK)

axWindowsMediaPlayer1.URL = dlg.FileName; //L y tên file c n m

}

Trang 35

Thêm project Lab03-02 vào Solution có giao di

RichTextBox

S d ng công c MenuStrip t o H Th nh D ng

S d ng công c ToolStrip t o thanh công c ch

Trang 41

- Ki m tra mã s sinh viên ph i có 10 kí t N u không s xu t thông báo

Trang 43

Tìm

re-cá nhân)

Trang 44

38 BÀI 4:

Trang 45

Sau khi Finish,

-

-

- Cách

//luôn luôn s d làm vi c v i các class

StudentContextDB context = new StudentContextDB();

//1 l y t t c các sinh viên t b ng Student

List<Student> listStudent = context.Students.ToList();

Student db = context.Students.FirstOrDefault(p => p.StudentID == ID);

ng sinh viên s vào database

Student s = new Student() { StudentID = "99", FullName = "test insert", AverageScore =

100 };

context.Students.Add(s);

context.SaveChanges();

//4 Update sinh viên -> l y item ra và c n update thu c tính nào thì set thu

Student dbUpdate = context.Students.FirstOrDefault(p => p.StudentID == ID);

Trang 46

StudentContextDB context = new StudentContextDB();

List<Faculty> listFalcultys = context.Faculties.ToList(); //l y các khoa

List<Student> listStudent = context.Students.ToList(); //l y sinh viên

//Hàm binding list có tên hi n th là tên khoa, giá tr là Mã khoa

private void FillFalcultyCombobox(List<Faculty> listFalcultys)

{

this.cmbFaculty.DataSource = listFalcultys;

this.cmbFaculty.DisplayMember = "FacultyName";

this.cmbFaculty.ValueMember = "FacultyID";

}

//Hàm binding gridView t list sinh viên

private void BindGrid(List<Student> listStudent)

Trang 50

CREATE TABLE [dbo].[Invoice](

[InvoiceNo] [nvarchar](20) NOT NULL,

[OrderDate] [datetime] NOT NULL,

[DeliveryDate] [datetime] NOT NULL,

[Note] [nvarchar](255) NULL,

CONSTRAINT [PK_Invoice] PRIMARY KEY CLUSTERED

(

[InvoiceNo] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY OFF,

ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

CREATE TABLE [dbo].[Product](

[ProductID] [nvarchar](20) NOT NULL,

[ProductName] [nvarchar](100) NOT NULL,

[Unit] [nvarchar](20) NOT NULL,

[BuyPrice] [decimal](18, 0) NULL,

[SellPrice] [decimal](18, 0) NULL,

CONSTRAINT [PK_Product] PRIMARY KEY CLUSTERED

(

[ProductID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY OFF,

ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

Trang 51

GO

CREATE TABLE [dbo].[Order](

[InvoiceNo] [nvarchar](20) NOT NULL,

[No] [int] NOT NULL,

[ProductID] [nvarchar](20) NOT NULL,

[ProductName] [nvarchar](100) NULL,

[Unit] [nvarchar](20) NULL,

[Price] [decimal](18, 0) NOT NULL,

[Quantity] [int] NOT NULL,

CONSTRAINT [PK_Order] PRIMARY KEY CLUSTERED

(

[InvoiceNo] ASC,

[No] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY OFF,

ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

/****** Object: Table [dbo].[Invoice] Script Date: 07/04/2020 23:14:16 ******/

INSERT [dbo].[Invoice] [InvoiceNo], [OrderDate], [DeliveryDate], [Note]) VALUES (N'HDX001', CAST(0x0000AAD900000000 AS DateTime), CAST(0x0000AADA00000000 AS

INSERT [dbo].[Invoice] [InvoiceNo], [OrderDate], [DeliveryDate], [Note]) VALUES (N'HDX002', CAST(0x0000AADA00000000 AS DateTime), CAST(0x0000AADA00000000 AS

INSERT [dbo].[Invoice] [InvoiceNo], [OrderDate], [DeliveryDate], [Note]) VALUES (N'HDX003', CAST(0x0000AADA00000000 AS DateTime), CAST(0x0000AADC00000000 AS

DateTime), N'giao tu 1-3h')

/****** Object: Table [dbo].[Product] Script Date: 07/04/2020 23:14:16 ******/

INSERT [dbo].[Product] [ProductID], [ProductName], [Unit], [BuyPrice],

[SellPrice]) VALUES (N'Product1', N'S n ph m 1', N'Cái', CAST(100000 AS Decimal(18,

0)), CAST(120000 AS Decimal(18, 0)))

INSERT [dbo].[Product] [ProductID], [ProductName], [Unit], [BuyPrice],

[SellPrice]) VALUES (N'Product2', N'S n ph m 2', N'Cái', CAST(90000 AS Decimal(18,

Trang 52

46 BÀI 4:

0)), CAST(120000 AS Decimal(18, 0)))

INSERT [dbo].[Product] [ProductID], [ProductName], [Unit], [BuyPrice],

[SellPrice]) VALUES (N'Product3', N'S n ph m 3', N'Cái', CAST(40000 AS Decimal(18,

0)), CAST(70000 AS Decimal(18, 0)))

INSERT [dbo].[Product] [ProductID], [ProductName], [Unit], [BuyPrice],

[SellPrice]) VALUES (N'Product4', N'S n ph m 4', N'H p', CAST(200000 AS Decimal(18,

0)), CAST(300000 AS Decimal(18, 0)))

/****** Object: Table [dbo].[Order] Script Date: 07/04/2020 23:14:16 ******/

INSERT [dbo].[Order] [InvoiceNo], [No], [ProductID], [ProductName], [Unit],

[Price], [Quantity]) VALUES (N'HDX001', 1, N'Product1', N'S n ph m 1', N'Cái',

CAST(120000 AS Decimal(18, 0)), 20)

INSERT [dbo].[Order] [InvoiceNo], [No], [ProductID], [ProductName], [Unit],

[Price], [Quantity]) VALUES (N'HDX001', 2, N'Product2', N'S n ph m 2', N'Cái',

CAST(120000 AS Decimal(18, 0)), 4)

INSERT [dbo].[Order] [InvoiceNo], [No], [ProductID], [ProductName], [Unit],

[Price], [Quantity]) VALUES (N'HDX001', 3, N'Product4', N'S n ph m 4', N'H p',

CAST(300000 AS Decimal(18, 0)), 10)

INSERT [dbo].[Order] [InvoiceNo], [No], [ProductID], [ProductName], [Unit],

[Price], [Quantity]) VALUES (N'HDX002', 1, N'Product4', N'S n ph m 1', N'H p',

CAST(300000 AS Decimal(18, 0)), 10)

INSERT [dbo].[Order] [InvoiceNo], [No], [ProductID], [ProductName], [Unit],

[Price], [Quantity]) VALUES (N'HDX002', 2, N'Product2', N'S n ph m 3', N'Cái',

CAST(300000 AS Decimal(18, 0)), 12)

INSERT [dbo].[Order] [InvoiceNo], [No], [ProductID], [ProductName], [Unit],

[Price], [Quantity]) VALUES (N'HDX003', 1, N'Product1', N'S n ph m 1', N'Cái',

CAST(120000 AS Decimal(18, 0)), 40)

INSERT [dbo].[Order] ([InvoiceNo], [No], [ProductID], [ProductName], [Unit],

[Price], [Quantity]) VALUES (N'HDX003', 4, N'Product2', N'S n ph m 2', N'Cái',

CAST(120000 AS Decimal(18, 0)), 60)

Trang 53

Khi load Form

-

-

-

Trang 55

1

Trang 56

50 BÀI 5:

-

Checked = True:

-

2

Trang 57

ed)

Lab05.GUI: là project Windows Form App

Trang 58

52 BÀI 5:

:

(

- StudentService

Trang 59

- MajorService

- FacultyService:

Trang 60

54 BÀI 5:

-

public partial class frmStudent : Form

{

private readonly StudentService studentService = new StudentService();

private readonly FacultyService facultyService = new FacultyService();

var listFacultys = facultyService.GetAll();

var listStudents = studentService.GetAll();

listFacultys.Insert(0, new Faculty());

this.cmbFaculty.DataSource = listFacultys;

this.cmbFaculty.DisplayMember = "FacultyName";

this.cmbFaculty.ValueMember = "FacultyID";

}

private void BindGrid(List<Student> listStudent)

Trang 61

{

dgvStudent.Rows.Clear();

foreach (var item in listStudent)

{

int index = dgvStudent.Rows.Add();

dgvStudent.Rows[index].Cells[0].Value = item.StudentID;

dgvStudent.Rows[index].Cells[1].Value = item.FullName;

if(item.Faculty!= null)

dgvStudent.Rows[index].Cells[2].Value = item.Faculty.FacultyName;

dgvStudent.Rows[index].Cells[3].Value = item.AverageScore + ""; if (item.MajorID != null) dgvStudent.Rows[index].Cells[4].Value = item.Major.Name + ""; ShowAvatar(item.Avatar); }

}

private void ShowAvatar(string ImageName) {

if (string.IsNullOrEmpty(ImageName)) {

picAvatar.Image = null; }

else {

string parentDirectory = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName; string imagePath = Path.Combine(parentDirectory, "Images", ImageName); picAvatar.Image = Image.FromFile(imagePath); picAvatar.Refresh(); }

}

public void setGridViewStyle(DataGridView dgview) {

dgview.BorderStyle = BorderStyle.None; dgview.DefaultCellStyle.SelectionBackColor = Color.DarkTurquoise; dgview.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal; dgview.BackgroundColor = Color.White; dgview.SelectionMode = DataGridViewSelectionMode.FullRowSelect; }

- chkUnregisterMajor_CheckedChanged private void chkUnregisterMajor_CheckedChanged(object sender, EventArgs e) {

var listStudents = new List<Student>(); if (this.chkUnregisterMajor.Checked) listStudents = studentService.GetAllHasNoMajor(); else listStudents = studentService.GetAll(); BindGrid(listStudents); }

Trang 62

public frmRegister()

{

InitializeComponent();

}

Trang 63

private void frmRegister_Load(object sender, EventArgs e)

this.cmbFaculty.DataSource = listFacultys;

this.cmbFaculty.DisplayMember = "FacultyName";

this.cmbFaculty.ValueMember = "FacultyID";

}

}

- cmbFaculty_SelectedIndexChanged

Trang 64

58 BÀI 5:

viên

Trang 65

BÀI 6:

LoaiSach ( MaLoai INT, TenLoai nvarchar(50) )

Sach( MaSach char(6) , TenSach nvarchar(150), NamXB INT, MaLoai INT)

LoaiSach.MaLoai

Trang 68

62 BÀI 6:

Ngày đăng: 28/07/2023, 17:58

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w