






















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
All subjects in the course of studying Information Technology
Typology: Study Guides, Projects, Research
1 / 62
This page cannot be seen from the preview
Don't miss anything!























































ASSIGNMENT 2 BRIEF
P3 Build an application derived from UML class diagrams.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication { public partial class dangnhap : Form { public dangnhap() { InitializeComponent(); } Themsuaxoa t = new Themsuaxoa(); string user = "admin"; string pass = "123"; private void button1_Click(object sender, EventArgs e) { if (taikhoan.Text == "") { MessageBox.Show("Bạn chưa nhập tài khoản"); taikhoan.Focus(); } else if (matkhau.Text == "") { MessageBox.Show("Bạn chưa nhập mật khẩu"); matkhau.Focus(); } else if (user.Equals(taikhoan.Text) && pass.Equals(matkhau.Text)) { MessageBox.Show("Đăng nhập thành công"); this.Hide(); Form f = new Formchinh(); f.Show();
} Themsuaxoa t = new Themsuaxoa(); private void loaddata() { DataTable dt = t.docdulieu("select * from sach"); if (dt != null) { luoi.DataSource = dt; } luoi.Columns[0].HeaderText = "Mã sách "; luoi.Columns[0].Width = 80; luoi.Columns[3].Width = 180; luoi.Columns[1].HeaderText = "Tên sách"; luoi.Columns[2].HeaderText = "Năm xuất bản"; luoi.Columns[3].HeaderText = "Mã nhà xuất bản"; luoi.Columns[4].HeaderText = "Mã thể loại"; luoi.Columns[5].HeaderText = "Mã tác giả"; //luoi.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells); xoa.Enabled = true; sua.Text = "Sửa"; them.Enabled = true; sua.Enabled = true; xoa.Enabled = true; luu.Enabled = false; luoi.Enabled = true; } private void loadcombo() { DataTable dt = t.docdulieu("select * from nhaxb"); DataTable dt1 = t.docdulieu("select * from theloai"); DataTable dt2 = t.docdulieu("select * from tacgia"); comnhaxb.DataSource = dt; comnhaxb.DisplayMember = "tennxb"; comnhaxb.ValueMember = "manxb"; //comnhaxb.DisplayMember = "tennxb"; //comnhaxb.ValueMember = "manxb"; comtheloai.DataSource = dt1; comtheloai.DisplayMember = "tentheloai"; comtheloai.ValueMember = "matheloai"; commatacgia.DataSource = dt2; commatacgia.DisplayMember = "tentacgia"; commatacgia.ValueMember = "matacgia"; } private void txttimkiem_TextChanged(object sender, EventArgs e) { }
private void Formcapnhatsach_Load(object sender, EventArgs e) { loaddata(); } private void luoi_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void luoi_SelectionChanged(object sender, EventArgs e) { txtmasach.Text = luoi.CurrentRow.Cells[0].Value.ToString(); txttensach.Text = luoi.CurrentRow.Cells[1].Value.ToString(); txtnamxb.Text = luoi.CurrentRow.Cells[2].Value.ToString(); comnhaxb.Text = luoi.CurrentRow.Cells[3].Value.ToString(); comtheloai.Text = luoi.CurrentRow.Cells[4].Value.ToString(); commatacgia.Text = luoi.CurrentRow.Cells[5].Value.ToString(); } private void them_Click(object sender, EventArgs e) { txtmasach.Text = ""; txttensach.Text = ""; luu.Enabled = true; xoa.Enabled = false; sua.Text = "hủy"; them.Enabled = false; luoi.Enabled = false; loadcombo(); } private void luu_Click(object sender, EventArgs e) { if (txtmasach.Text == "") { MessageBox.Show("Chưa nhập mã sách"); txtmasach.Focus(); } else if (txttensach.Text == "") { MessageBox.Show("Chưa nhập tên sách"); txttensach.Focus(); } else if (txtnamxb.Text == "") { MessageBox.Show("Chưa nhập năm xuất bản");
txtmasach.Enabled = false; if (txttensach.Text == "") { txttensach.Focus(); } else if (txtnamxb.Text == "") { MessageBox.Show("Chưa nhập địa chỉ"); txtnamxb.Focus(); // else if (t.thucthidulieu("update SACH set tensach=N'" + txttensach.Text + "', namxb=N'" + txtnamxb.Text + "', manxb='" + comnhaxb.Text + "', matheloai='" + comtheloai.SelectedValue.ToString() + "', matacgia='" + commatacgia.SelectedValue.ToString() + "'where masach=N'" + txtmasach.Text + "'") == true) } else if (t.thucthidulieu("update SACH set tensach=N'" + txttensach.Text + "', namxb=N'" + txtnamxb.Text + "', manxb='" + comnhaxb.Text + "', matheloai='" + comtheloai.Text + "', matacgia='" + commatacgia.Text + "'where masach=N'" + txtmasach.Text + "'") == true) { MessageBox.Show("Cập nhật dữ liệu thành công"); loaddata(); txtmasach.Enabled = true; } else MessageBox.Show("Không thể cập nhật dữ liệu"); } } private void xoa_Click(object sender, EventArgs e) { if (xoa.Text == "hủy") { luu.Enabled = false; sua.Enabled = true; xoa.Enabled = true; xoa.Text = "Xóa"; sua.Text = "Sửa"; them.Enabled = true; loaddata(); luoi.Enabled = true; } else {
DialogResult chon = MessageBox.Show("Bạn có muốn xóa sách có mã số " + txtmasach.Text + "", "thông báo", MessageBoxButtons.YesNo); if (chon == DialogResult.Yes) { try { t.thucthidulieu("delete from sach where masach='" + txtmasach.Text + "'"); MessageBox.Show("Xóa thành Công", "Thông báo"); loaddata(); } catch (Exception) { MessageBox.Show("Không thể xóa", "Thông báo"); throw; } } else loaddata(); } } private void thoat_Click(object sender, EventArgs e) { this.Hide(); Form f = new Formchinh(); f.Show(); } private void button2_Click(object sender, EventArgs e) { DataTable dt5 = t.docdulieu("select * from sach where masach like '%" + txttimkiem.Text + "%'"); DataTable dt6 = t.docdulieu("select * from sach where tensach like '%" + txttimkiem.Text + "%'"); if (ramasach.Checked == true) { luoi.DataSource = dt5; } else luoi.DataSource = dt6; } } }
{ luoi.DataSource = dt5; } else luoi.DataSource = dt6; } private void button1_Click(object sender, EventArgs e) { this.Hide(); Form f = new Formchinh(); f.Show(); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication { public partial class Formdocgia : Form { public Formdocgia() { InitializeComponent(); } Themsuaxoa t = new Themsuaxoa(); private void Formdocgia_Load(object sender, EventArgs e) { loaddata(); } private void thoat_Click(object sender, EventArgs e) { this.Hide(); Form f = new Formchinh(); f.Show(); } private void loaddata()
{ DataTable dt = t.docdulieu("Logged in successfully"); l.Text = dt.Rows.Count.ToString(); if (dt != null) { luoi.DataSource = dt; } luoi.Columns[0].HeaderText = "Mã độc giả"; luoi.Columns[1].HeaderText = "Họ và tên"; luoi.Columns[2].HeaderText = "Ngày sinh"; luoi.Columns[3].HeaderText = "Giới tính"; luoi.Columns[4].HeaderText = "Lớp"; luoi.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells); xoa.Enabled = true; sua.Text = "Sửa"; them.Enabled = true; sua.Enabled = true; xoa.Enabled = true; luu.Enabled = false; luoi.Enabled = true; } private void luoi_SelectionChanged(object sender, EventArgs e) { txtmadocgia.Text = luoi.CurrentRow.Cells[0].Value.ToString(); txttendocgia.Text = luoi.CurrentRow.Cells[1].Value.ToString(); ngaysinh.Text = luoi.CurrentRow.Cells[2].Value.ToString(); comgioitinh.Text = luoi.CurrentRow.Cells[3].Value.ToString(); txtlop.Text = luoi.CurrentRow.Cells[4].Value.ToString(); } private void them_Click(object sender, EventArgs e) { txtmadocgia.Text = ""; txttendocgia.Text = ""; luu.Enabled = true; //sua.Enabled = false; xoa.Enabled = false; sua.Text = "hủy"; them.Enabled = false; luoi.Enabled = false; } private void luu_Click(object sender, EventArgs e) { string ngayhh = ngaysinh.Value.ToString("yyyy/MM/dd"); if (txtmadocgia.Text == "")
} else { if (txttendocgia.Text == "") { txttendocgia.Focus(); } else if (txtlop.Text == "") { MessageBox.Show("Chưa nhập địa chỉ"); txtlop.Focus(); } else if (t.thucthidulieu("update docgia set hoten=N'" + txttendocgia.Text + "', ngaysinh=N'" + ngayhh + "', gioitinh=N'" + comgioitinh.Text + "', thongtin='" + txtlop.Text + "'where madocgia=N'" + txtmadocgia.Text + "'") == true) { MessageBox.Show("Cập nhật dữ liệu thành công"); loaddata(); } else MessageBox.Show("Không thể cập nhật dữ liệu"); } } private void xoa_Click(object sender, EventArgs e) { if (xoa.Text == "hủy") { luu.Enabled = false; sua.Enabled = true; xoa.Enabled = true; xoa.Text = "Xóa"; sua.Text = "Sửa"; them.Enabled = true; loaddata(); luoi.Enabled = true; } else { DialogResult chon = MessageBox.Show("Bạn có muốn xóa độc giả có mã số " + txtmadocgia.Text + "", "thông báo", MessageBoxButtons.YesNo); if (chon == DialogResult.Yes)
{ try { if (t.thucthidulieu("delete from docgia where madocgia='" + txtmadocgia.Text + "'") == true) MessageBox.Show("Xóa thành Công", "Thông báo"); else MessageBox.Show("Lỗi không thể xóa dữ liệu", "Thông báo"); loaddata(); } catch (Exception) { MessageBox.Show("Không thể xóa", "Thông báo"); throw; } } else loaddata(); } } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;