private void CapNhatTheDocGia_Load(object sender, EventArgs e) { sach = Database.GetSach(masach); textBox_MaDocGia.Text = masach; var theloais = Database.GetAllTheLoai(); var tacgias = Database.GetAllTacGia(); foreach (var tl in theloais) { comboBox_theloai.Items.Add(tl.TenTheLoai); } comboBox_theloai.SelectedIndex = 0; foreach (var tg in tacgias) { comboBox_tacgia.Items.Add(tg.TenTacGia); } comboBox_tacgia.SelectedIndex = 0; textBox_tensach.Text = sach.TenSach; dateTimePicker_ngaynhap.Value = sach.NgayNhap; textBox_nxb.Text = sach.NXB; textBox_namxb.Text = sach.NamXB.ToString(); textBox_tinhtrang.Text = sach.TinhTrang; }
private void button_CapNhatThe_Click(object sender, EventArgs e) { if (CheckInfo()) { DataAccess.DataObject.Sach sach = new DataAccess.DataObject.Sach(); sach.MaSach = textBox_masach.Text; sach.TheLoai = new DataAccess.DataObject.TheLoai() { TenTheLoai = comboBox_theloai.SelectedText }; sach.TenSach = textBox_tensach.Text; sach.NgayNhap = dateTimePicker_ngaynhap.Value; sach.NamXB = int.Parse(textBox_namxb.Text); sach.NXB = textBox_nxb.Text; sach.TacGia = new DataAccess.DataObject.TacGia() { TenTacGia = comboBox_tacgia.SelectedText }; sach.TinhTrang = textBox_tinhtrang.Text; Database.AddSach(sach); MessageBox.Show("Đã thêm sách vào database"); Close(); } }