private void gridDoGia_SelectedItemChanged(object sender, DevExpress.Xpf.Grid.SelectedItemChangedEventArgs e) { try { DocGiaModel select = gridDoGia.SelectedItem as DocGiaModel; DocGia docgia = docGiaControll.GetById(select.MaDocGia); _txtmadocgia.Text = docgia.MaDocGia.ToString(); _txttendocgia.Text = docgia.TenDocGia.ToString(); _txtdiachi.Text = docgia.DiaChi.ToString(); _datengaysinh.Text = docgia.NgaySinh.ToString("MM/dd/yyyy"); if (docgia.GioiTinh == "Nam") { _rdnam.IsChecked = true; _rdnu.IsChecked = false; } else { _rdnam.IsChecked = false; _rdnu.IsChecked = true; } _imagedocgia.Source = App.ConvertByteArrayToBitmapImage(docgia.ImageDocGia) != null?App.ConvertByteArrayToBitmapImage(docgia.ImageDocGia) : null; if (docgia.MaLop != null) { try { Lop selected = _cbblop.SelectedItem as Lop; List <Lop> cboxList = _cbblop.ItemsSource as List <Lop>; selected = cboxList.SingleOrDefault(m => m.MaLop == docgia.MaLop); _cbblop.SelectedItem = selected; } catch (Exception) { _cbblop.SelectedItem = null; } } else { _cbblop.SelectedItem = null; } if (docgia.MaKhoa != null) { try { Khoa selected = _cbbkhoa.SelectedItem as Khoa; List <Khoa> cboxList = _cbbkhoa.ItemsSource as List <Khoa>; selected = cboxList.SingleOrDefault(m => m.MaKhoa == docgia.MaKhoa); _cbbkhoa.SelectedItem = selected; } catch (Exception) { _cbbkhoa.SelectedItem = null; } } else { _cbbkhoa.SelectedItem = null; } gridSachMuon.ItemsSource = sachMuonControll.GetSachMuonTableByDocGia(docgia); gridSachMuon.RefreshData(); } catch { } }
private void _btnadd_Click(object sender, RoutedEventArgs e) { if (_btnadd.Content.Equals("Add new")) { _btnadd.Content = "Hoàn tất"; _btnadd_cancel.IsEnabled = true; _btnadd_cancel.Visibility = Visibility.Visible; _btnsave.IsEnabled = false; _btndelete.IsEnabled = false; _btndelete.IsEnabled = false; _btnload.IsEnabled = false; gridSachMuon.IsEnabled = false; _txtmamuon.Clear(); _txtsoluongmuon.Clear(); _txttiencoc.Clear(); _datemuon.Clear(); _datetra.Clear(); _checkdatra.IsChecked = false; _cbbtendocgia.SelectedItem = null; _cbbtensach.SelectedItem = null; return; } string warning = ""; if (String.IsNullOrWhiteSpace(_txtsoluongmuon.Text)) { warning += "Vui lòng nhập Số Lượng Sách Mượn." + '\n'; } if (String.IsNullOrWhiteSpace(_txttiencoc.Text)) { warning += "Vui lòng nhập tiền cọc." + '\n'; } if (String.IsNullOrWhiteSpace(_cbbtendocgia.Text)) { warning += "Vui lòng Chọn Độc Giả." + '\n'; } if (String.IsNullOrWhiteSpace(_cbbtensach.Text)) { warning += "Vui lòng Chọn Tên Sách." + '\n'; } if (!warning.Equals("")) { MessageBox.Show( warning, "Thêm mới Sách Mượn", MessageBoxButton.OK, MessageBoxImage.Warning); return; } MuonSach sach = new MuonSach(); try { sach.SoLuongMuon = Convert.ToInt16(_txtsoluongmuon.Text); sach.TienCoc = Convert.ToDecimal(_txttiencoc.Text); if (_checkdatra.IsChecked == true) { sach.DaTra = true; } else { sach.DaTra = false; } if (_datemuon.Text.Equals("") == false && _datetra.Text.Equals("") == false) { try { sach.NgayMuon = DateTime.Today; sach.NgayHen = Convert.ToDateTime(_datetra.Text); } catch { } } else { sach.NgayMuon = DateTime.Today; sach.NgayHen = DateTime.Today; } } catch { } if (_cbbtendocgia.SelectedItem != null) { sach.MaDocGia = (_cbbtendocgia.SelectedItem as View_Models.DocGia).MaDocGia; } if (_cbbtensach.SelectedItem != null) { sach.MaSach = (_cbbtensach.SelectedItem as View_Models.Sach).MaSach; } Sach temp = _cbbtensach.SelectedItem as Sach; int slcm = sachControll.CheckChoMuon(temp); if (slcm == 0) { warning += "Sách trong kho đã hết" + '\n'; } if (slcm < sach.SoLuongMuon) { warning += "Sách trong kho còn:" + slcm + '\n'; } if (!warning.Equals("")) { MessageBox.Show( warning, "Thêm mới Sách Mượn", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (sachMuonControll.Add(sach)) { Sach sachtemp = sachControll.GetById(sach.MaSach); sachtemp.LuongDaMuon = sachMuonControll.GetTongSachMuon(sachtemp) == null? 0: sachMuonControll.GetTongSachMuon(sachtemp).Value; sachControll.Edit(sachtemp); DocGia dgtemp = docGiaControll.GetById(sach.MaDocGia); dgtemp.TienKiGui = sachMuonControll.GetTongTienCoc(dgtemp) == null ? 0 : sachMuonControll.GetTongTienCoc(dgtemp).Value; docGiaControll.Edit(dgtemp); MessageBox.Show( "Thêm mới thành công", "Thêm mới Sách Muọn", MessageBoxButton.OK, MessageBoxImage.Information); MessageBoxResult re; re = MessageBox.Show("Bạn có muốn in phiếu không", "In Phiếu", MessageBoxButton.YesNo, MessageBoxImage.Question); if (re == MessageBoxResult.Yes) { BookLoanPhieuMuon report = new BookLoanPhieuMuon(sach.MaDocGia, sach.NgayMuon); report.FilterString = "[DaTra] = false"; DocumentPreviewWindow window = new DocumentPreviewWindow(); window.PreviewControl.DocumentSource = report; report.CreateDocument(true); window.ShowDialog(); } } else { MessageBox.Show( "Thêm mới thất bại", "Thêm mới Sách Mượn", MessageBoxButton.OK, MessageBoxImage.Error); } _btnadd.Content = "Add new"; _btnadd_cancel.IsEnabled = false; _btnadd_cancel.Visibility = Visibility.Hidden; _btnsave.IsEnabled = true; _btndelete.IsEnabled = true; _btnload.IsEnabled = true; gridSachMuon.IsEnabled = true; LoadSachMuonTable(); }