Esempio n. 1
0
        void LoadData()
        {
            List<TacGia> _tacGia = new List<TacGia>();
            TacGiaBUS _busTacGia = new TacGiaBUS();

            _tacGia = _busTacGia.GetList();

            dataGrid.Items.Clear();

            id = 1;
            foreach (TacGia i in _tacGia)
            {
                ThongTinTacGia _thongTinTacGia = new ThongTinTacGia();
                _thongTinTacGia.MaTacGia = i.MaTG;
                _thongTinTacGia.TenTacGia = i.TenTG;

                dataGrid.IsReadOnly = true;
                dataGrid.Items.Add(_thongTinTacGia);

                if (id < int.Parse(i.MaTG))
                {
                    id = int.Parse(i.MaTG);
                }
            }
        }
Esempio n. 2
0
        private void btThem_Click(object sender, RoutedEventArgs e)
        {
            TacGia tacGia = new TacGia() { MaTG = (++id).ToString(), TenTG = tbTenTacGia.Text };

            TacGiaBUS bus = new TacGiaBUS();

            try
            {
                bus.Insert(tacGia);

                MessageBox.Show("Thêm thành công !");
            }
            catch (Exception)
            {
                MessageBox.Show("Thêm thất bại !");
            }
            

            LoadData();
        }
        private void btTim_Click(object sender, RoutedEventArgs e)
        {
            List<Sach> _sach = new List<Sach>();
            SachBUS _busSach = new SachBUS();

            dataGrid.Items.Clear();

            _sach = _busSach.GetList();

            string _maTheLoai = "";
            foreach(TheLoai i in _theLoai)
            {
                if (i.TenTheLoai == cbbTheLoai.Text)
                {
                    _maTheLoai = i.MaTheLoai;
                    break;
                }
            }

            List<TacGia> _tacGia = new List<TacGia>();
            TacGiaBUS _busTacGia = new TacGiaBUS();
            _tacGia = _busTacGia.GetList();

            List<NhaXuatBan> _nhaXuatBan = new List<NhaXuatBan>();
            NhaXuatBanBUS _busNhaXuatBan = new NhaXuatBanBUS();
            _nhaXuatBan = _busNhaXuatBan.GetList();

            int stt = 1;

            if (tbTenSach.Text == "")
            {
                foreach (Sach i in _sach)
                {
                    if (i.TheLoai == _maTheLoai)
                    {
                        ThongTinSach _thongTinSach = new ThongTinSach();
                        _thongTinSach.Stt = stt++;
                        _thongTinSach.TenSach = i.TenSach;
                        _thongTinSach.TheLoai = cbbTheLoai.Text;
                        _thongTinSach.TacGia = LayTenTacGia(_tacGia, i.TacGia);
                        _thongTinSach.NhaXuatBan = LayTenNhaXuatBan(_nhaXuatBan, i.NhaXuatBan);
                        _thongTinSach.NamXuatBan = i.NamXuatBan;
                        _thongTinSach.GiaBan = i.GiaBan.ToString();
                        _thongTinSach.SoLuong = i.SoLuong;

                        dataGrid.Items.Add(_thongTinSach);
                    }
                }
            }
            else if (tbTenSach.Text != "" && cbbTheLoai.Text != "")
            {
                foreach (Sach i in _sach)
                {
                    if (String.Compare(i.TenSach, tbTenSach.Text, true) == 0 && i.TheLoai==_maTheLoai)
                    {
                        ThongTinSach _thongTinSach = new ThongTinSach();
                        _thongTinSach.Stt = stt++;
                        _thongTinSach.TenSach = i.TenSach;
                        _thongTinSach.TheLoai = cbbTheLoai.Text;
                        _thongTinSach.TacGia = LayTenTacGia(_tacGia, i.TacGia);
                        _thongTinSach.NhaXuatBan = LayTenNhaXuatBan(_nhaXuatBan, i.NhaXuatBan);
                        _thongTinSach.NamXuatBan = i.NamXuatBan;
                        _thongTinSach.GiaBan = i.GiaBan.ToString();
                        _thongTinSach.SoLuong = i.SoLuong;

                        dataGrid.Items.Add(_thongTinSach);
                    }
                }
            }
            else if(tbTenSach.Text!="")
            {
                foreach (Sach i in _sach)
                {
                    if (String.Compare(i.TenSach, tbTenSach.Text, true) == 0)
                    {
                        ThongTinSach _thongTinSach = new ThongTinSach();
                        _thongTinSach.Stt = stt++;
                        _thongTinSach.TenSach = i.TenSach;
                        _thongTinSach.TheLoai = LayTenTheLoai(_theLoai,i.TheLoai);
                        _thongTinSach.TacGia = LayTenTacGia(_tacGia, i.TacGia);
                        _thongTinSach.NhaXuatBan = LayTenNhaXuatBan(_nhaXuatBan, i.NhaXuatBan);
                        _thongTinSach.NamXuatBan = i.NamXuatBan;
                        _thongTinSach.GiaBan = i.GiaBan.ToString();
                        _thongTinSach.SoLuong = i.SoLuong;

                        dataGrid.Items.Add(_thongTinSach);
                    }
                }
            }
        }
Esempio n. 4
0
        private void btSua_Click(object sender, RoutedEventArgs e)
        {
            TacGia tacGia = new TacGia() { MaTG = tbMaTacGia.Text, TenTG = tbTenTacGia.Text };

            TacGiaBUS bus = new TacGiaBUS();

            try
            {
                bus.Update(tacGia);

                MessageBox.Show("Sửa thành công !");
            }
            catch (Exception)
            {
                MessageBox.Show("Sửa thất bại !");
            }
           

            LoadData();
        }
Esempio n. 5
0
        private void btXoa_Click(object sender, RoutedEventArgs e)
        {
            TacGiaBUS bus = new TacGiaBUS();

            try
            {
                bus.Delete(tbMaTacGia.Text);

                MessageBox.Show("Xóa thành công !");
            }
            catch (Exception)
            {
                MessageBox.Show("Xóa thất bại !");
            }
            

            LoadData();
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            List<Sach> _sach = new List<Sach>();
            SachBUS _busSach = new SachBUS();

            dataGrid.Items.Clear();

            _sach = _busSach.GetList();

            List<TacGia> _tacGia = new List<TacGia>();
            TacGiaBUS _busTacGia = new TacGiaBUS();
            _tacGia = _busTacGia.GetList();

            List<NhaXuatBan> _nhaXuatBan = new List<NhaXuatBan>();
            NhaXuatBanBUS _busNhaXuatBan = new NhaXuatBanBUS();
            _nhaXuatBan = _busNhaXuatBan.GetList();

            List<TheLoai> _theLoai = new List<TheLoai>();
            TheLoaiBUS _busTheLoai = new TheLoaiBUS();
            _theLoai = _busTheLoai.GetList();

            foreach (Sach i in _sach)
            {
                ThongTinSach _thongTinSach = new ThongTinSach();
                _thongTinSach.MaSach = i.MaSach;
                _thongTinSach.TenSach = i.TenSach;
                _thongTinSach.TheLoai = LayTenTheLoai(_theLoai, i.TheLoai);
                _thongTinSach.TacGia = LayTenTacGia(_tacGia, i.TacGia);
                _thongTinSach.NhaXuatBan = LayTenNhaXuatBan(_nhaXuatBan, i.NhaXuatBan);
                _thongTinSach.NamXuatBan = i.NamXuatBan;
                _thongTinSach.GiaBan = i.GiaBan.ToString();
                _thongTinSach.SoLuong = i.SoLuong;

                dataGrid.Items.Add(_thongTinSach);
            }
        }