コード例 #1
0
ファイル: frmDocGia.cs プロジェクト: MTA-TTNhom/QuanLiThuVien
        private void Luu_DG_Click(object sender, EventArgs e)
        {
            if (Them_bool == true && Sua_bool == false)
            {
                var entity = new docgia();

                entity.sothe      = Convert.ToInt32(sothetxt.Text);
                entity.hoten      = tendgtxt.Text;
                entity.ngaysinh   = ngaysinhdg.Value;
                entity.gioitinh   = gioitinhdgtxt.Text;
                entity.diachi     = diachidgtxt.Text;
                entity.email      = emaildgtxt.Text;
                entity.socmtnd    = socmtnddgtxt.Text;
                entity.ngaylamthe = ngaythedg.Value;
                entity.handungthe = hanthedg.Value;

                var dg = new DocGiaController();
                if (dg.Add(entity) > 0)
                {
                    HienThi_DG();
                }
                else
                {
                    MessageBox.Show("Thêm độc giả không thành công");
                }
            }
            if (Them_bool == false && Sua_bool == true)
            {
                var entity = new docgia();
                entity.sothe      = Convert.ToInt32(sothetxt.Text);
                entity.hoten      = tendgtxt.Text;
                entity.ngaysinh   = ngaysinhdg.Value;
                entity.gioitinh   = gioitinhdgtxt.Text;
                entity.diachi     = diachidgtxt.Text;
                entity.email      = emaildgtxt.Text;
                entity.socmtnd    = socmtnddgtxt.Text;
                entity.ngaylamthe = ngaythedg.Value;
                entity.handungthe = hanthedg.Value;

                var dg = new DocGiaController();
                if (dg.Edit(entity))
                {
                    HienThi_DG();
                }
                else
                {
                    MessageBox.Show("Sửa độc giả không thành công");
                }
            }
            btn_enable(false);
        }
コード例 #2
0
        private void _btnsave_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult re;

            re = MessageBox.Show("Bạn có muốn sửa không", "Lưu Sách", MessageBoxButton.YesNo, MessageBoxImage.Question);
            if (re == MessageBoxResult.Yes)
            {
                try
                {
                    if (_txtmadocgia.Text.Equals("") == false)
                    {
                        DocGia docgia = new DocGia();
                        docgia = docGiaControll.GetById((_txtmadocgia.Text));


                        try
                        {
                            docgia.DiaChi    = (_txtdiachi.Text);
                            docgia.TenDocGia = _txttendocgia.Text;

                            try
                            {
                                if (_datengaysinh.Text.Equals("") == false)
                                {
                                    try { docgia.NgaySinh = Convert.ToDateTime(_datengaysinh.Text); }
                                    catch { }
                                }
                                else
                                {
                                    docgia.NgaySinh = DateTime.Today;
                                }

                                if (_rdnam.IsChecked == true)
                                {
                                    docgia.GioiTinh = "Nam";
                                }
                                else
                                {
                                    docgia.GioiTinh = "Nữ";
                                }
                            }
                            catch { }
                            try { docgia.ImageDocGia = App.ConvertFileToByte(_imagedocgia.Source); } catch { docgia.ImageDocGia = null; }
                            if (_cbbkhoa.SelectedItem != null)
                            {
                                docgia.MaKhoa = (_cbbkhoa.SelectedItem as Khoa).MaKhoa;
                            }
                            if (_cbblop.SelectedItem != null)
                            {
                                docgia.MaLop = (_cbblop.SelectedItem as Lop).MaLop;
                            }
                        }
                        catch { }

                        string warning = "";

                        if (String.IsNullOrWhiteSpace(_cbblop.Text))
                        {
                            warning += "Chọn Tên Lớp" + '\n';
                        }
                        if (String.IsNullOrWhiteSpace(_cbbkhoa.Text))
                        {
                            warning += "Chọn Tên Khoa." + '\n';
                        }

                        if (!warning.Equals(""))
                        {
                            MessageBox.Show(
                                warning,
                                "Lưu Sách",
                                MessageBoxButton.OK,
                                MessageBoxImage.Warning);
                            return;
                        }
                        if (docGiaControll.Edit(docgia))
                        {
                            MessageBox.Show(
                                "Cập nhật thành công",
                                "Cập Nhật Sách",
                                MessageBoxButton.OK,
                                MessageBoxImage.Information);
                        }
                        else
                        {
                            MessageBox.Show(
                                "Cập Nhật thất bại",
                                "Cập Nhật Sách",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                        }

                        LoadDocGiaTable();
                    }
                }
                catch { }
            }
        }
コード例 #3
0
        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();
        }