T Biên www.hutech.edu.vn *1.2023.CMP371* tailieuhoctap@hutech.edu.vn : I .I II 1.1 1.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 II W hành (LINQ, Entity framework có , sinh viên (SQL Server) HÀNH - C# viên - Bài - : Giúp - Bài : - Bài cung III - Bài 6: viên - BÀI 1: BÀI 1: 1.1 M C TIÊU - - Console Visual Studio NET 2022 - bool, decimal, double, float, int, string, DateTime, bool?, decimal?, double?, float?, int?, long?, DateTime?, object, var, - as,is n Convert for, foreach, while, while - break, continue, return Console Console.Write Console.WriteLine(); // Console.ReadLine(); // Console.ReadKey(); - // Coding Convention C#: quy cho BÀI 1: 1.2 BÀI T P - : : BÀI 1: targetNumber - targetString attempt guess feedback GetFeedback máy tính - Hàm GetFeedback targetString guess - -01, Visual Studio 2022 /2019 BÀI 1: Main, Program.cs 2A: Thêm sinh viên - Thoát - - 48 BÀI 5: BÀI 5: ENTITY FRAMEWORK 5.1 M C TIÊU - nh 3-layer -layer entity framework - Unit of work 5.2 BÀI T P ngành BÀI 5: 49 50 BÀI 5: - Checked = True: Images {studentID}.{typeFile} Images/1234567890.jpg 1234567891 Images/ 1234567891.png BÀI 5: ed) Lab05.GUI: project Windows Form App (.NET Framework) Lab05.BUS FrameWork) Lab05.DAL: FrameWork) - c - project Library (.NET 51 52 BÀI 5: : ( - StudentService BÀI 5: - MajorService - FacultyService: 53 54 BÀI 5: - public partial class frmStudent : Form { private readonly StudentService studentService = new StudentService(); private readonly FacultyService facultyService = new FacultyService(); public frmStudent() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { try { setGridViewStyle(dgvStudent); var listFacultys = facultyService.GetAll(); var listStudents = studentService.GetAll(); FillFalcultyCombobox(listFacultys); BindGrid(listStudents); } catch (Exception ex) { MessageBox.Show(ex.Message); } } Mã khoa private void FillFalcultyCombobox(List listFacultys) { listFacultys.Insert(0, new Faculty()); this.cmbFaculty.DataSource = listFacultys; this.cmbFaculty.DisplayMember = "FacultyName"; this.cmbFaculty.ValueMember = "FacultyID"; } private void BindGrid(List listStudent) BÀI 5: { 55 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(); if (this.chkUnregisterMajor.Checked) listStudents = studentService.GetAllHasNoMajor(); else listStudents = studentService.GetAll(); BindGrid(listStudents); } 56 BÀI 5: 4.2 ( MajorId = NULL Student) - - vào Khoa public partial class frmRegister : Form { private readonly StudentService studentService = new StudentService(); private readonly FacultyService facultyService = new FacultyService(); private readonly MajorService majorService = new MajorService(); public frmRegister() { InitializeComponent(); } BÀI 5: private void frmRegister_Load(object sender, EventArgs e) { try { var listFacultys = facultyService.GetAll(); FillFalcultyCombobox(listFacultys); } catch (Exception ex) { MessageBox.Show(ex.Message); } } Mã khoa private void FillFalcultyCombobox(List listFacultys) { this.cmbFaculty.DataSource = listFacultys; this.cmbFaculty.DisplayMember = "FacultyName"; this.cmbFaculty.ValueMember = "FacultyID"; } } - cmbFaculty_SelectedIndexChanged 57 58 BÀI 5: viên BÀI 6: BÀI 6: ng MS QLSach i2 sau: LoaiSach ( MaLoai INT, TenLoai nvarchar(50) ) Sach( MaSach char(6) , TenSach nvarchar(150), NamXB INT, MaLoai INT) LoaiSach.MaLoai 59 60 BÀI 6: 2.3 Khi Load Form (1.5 d) - LoaiSach TenLoai - 2.5 Khi Click vào nút xóa (1d) - 2.6 i/ - sách sách! (0.5d) - Mã sách (0.5d) - Thêm (1d) (0.5d) sách) BÀI 6: - 61 ReportViewer sau sách thông tin danh sách ReportViewer 62 BÀI 6: