Example #1
0
        public TacGiaDTO LayTenTacGia(int maTG)
        {
            TacGiaDTO TACGIA = null;

            OleDbConnection connection = DataProvider.CreateConnection();
            string          cmdText    = "Select * from TACGIA where MaTG = ?";
            OleDbCommand    command    = new OleDbCommand(cmdText, connection);

            command.Parameters.Add("@MaTG", OleDbType.Integer);

            command.Parameters["@MaTG"].Value = maTG;
            OleDbDataReader reader = command.ExecuteReader();



            while (reader.Read())
            {
                TACGIA = new TacGiaDTO();

                TACGIA.MaTG  = (int)reader["MaTG"];
                TACGIA.TenTG = (string)reader["TenTG"];
            }
            reader.Close();
            connection.Close();
            return(TACGIA);
        }
        //public string ConnectionString { get => connectionString; set => connectionString = value; }

        public bool Them(TacGiaDTO add)
        {
            string query = string.Empty;

            query += "INSERT INTO TacGia ([Matacgia], [Tentacgia], [Quenquan])";
            query += "VALUES (@Matacgia,@Hoten,@Quenquan)";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@Matacgia", add.Matacgia);
                    cmd.Parameters.AddWithValue("@Hoten", add.Tentacgia);
                    cmd.Parameters.AddWithValue("@Quenquan", add.Quequan);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
 private void btnLuu_Click(object sender, EventArgs e)
 {
     try
     {
         TacGiaDTO tgDTO = new TacGiaDTO();
         tgDTO.MaTacGia = matacgia;
         tgDTO.HoTen    = txtHoTen.Text.Trim();
         tgDTO.NgaySinh = dtpNgaySinh.Value;
         tgDTO.GioiTinh = radNam.Checked ? true : false;
         tgDTO.GhiChu   = txtGhiChu.Text.Trim();
         TacGiaBUS tgBUS = new TacGiaBUS();
         if (tgBUS.Sua(tgDTO))
         {
             MessageBox.Show("Thành công!");
         }
         else
         {
             MessageBox.Show("Không thành công!");
         }
         this.Dispose();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void btnThem_Click(object sender, EventArgs e)
 {
     if (txtTenTG.Text != "")
     {
         TacGiaDTO TG = new TacGiaDTO();
         TG.MaTG   = txtMaTG.Text;
         TG.TenTG  = txtTenTG.Text;
         TG.DiaChi = txtDiaChi.Text;
         if (TacGiaBUS.ThemTG(TG) == true)
         {
             txtMaTG.Text = TacGiaBUS.GetIDTG();
             txtTenTG.ResetText();
             txtDiaChi.ResetText();
             LoadData();
         }
         else
         {
             MessageBox.Show("Thêm thất bại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show("Tên tác giả không được để trống.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public bool Xoa(TacGiaDTO del)
        {
            string query = string.Empty;

            query += "DELETE FROM TacGia WHERE [Matacgia] = @Matacgia";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@Matacgia", del.Matacgia);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
        public bool Sua(TacGiaDTO edit)
        {
            string query = string.Empty;

            query += "UPDATE TacGia SET [Tentacgia] = @Tentacgia, [Quequan] = @Quequan WHERE [Matacgia] = @Matacgia";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@Matacgia", edit.Matacgia);
                    cmd.Parameters.AddWithValue("@Tentacgia", edit.Tentacgia);
                    cmd.Parameters.AddWithValue("@Quequan", edit.Quequan);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #7
0
        public void SuaTacGia(TacGiaDTO tacGiaDto)
        {
            var tacGia = _tacGiaRepository.GetBy(tacGiaDto.MaTG);

            tacGiaDto.MappingTacGia(tacGia);

            _tacGiaRepository.Update(tacGia);
        }
 public static TacGia MappingTacGia(this TacGiaDTO tacGiaDto)
 {
     return(new TacGia
     {
         MaTG = tacGiaDto.MaTG,
         TenTG = tacGiaDto.TenTG
     });
 }
Example #9
0
        public TacGiaDTO LayTenTacGia(int maTG)
        {
            TacGiaDAO tgDAO = new TacGiaDAO();
            TacGiaDTO tgDTO = null;

            tgDTO = tgDAO.LayTenTacGia(maTG);
            return(tgDTO);
        }
Example #10
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            TacGiaDTO tacGia = new TacGiaDTO();

            tacGia.MaTG  = ((TacGiaDTO)cmbTacGia.SelectedItem).MaTG;
            tacGia.TenTG = txtTacGia.Text;
            TacGiaBUS tacgiaBUS = new TacGiaBUS();

            // TacGiaBUS.Modify(tacGia);
            QuanLyTacGia_Load(sender, e);
        }
Example #11
0
 public bool Sua(TacGiaDTO tgDTO)
 {
     if (tgDTO.HoTen == "")
     {
         throw new Exception("Chưa nhập tên tác giả!");
     }
     if (tgDTO.NgaySinh > DateTime.Now)
     {
         throw new Exception("Ngày sinh không hợp lệ!");
     }
     return(tgDAO.Sua(tgDTO));
 }
Example #12
0
        public bool Them(TacGiaDTO tgDTO)
        {
            conn.Open();
            string SQL = string.Format("INSERT INTO TACGIA (HOTEN,NGAYSINH,GIOITINH,GHICHU)" +
                                       " VALUES (N'{0}','{1}','{2}',N'{3}')", tgDTO.HoTen, tgDTO.NgaySinh.ToString("yyyy-MM-dd"), tgDTO.GioiTinh, tgDTO.GhiChu);
            SqlCommand com = new SqlCommand(SQL, conn);
            int        kq  = com.ExecuteNonQuery();

            conn.Close();
            if (kq > 0)
            {
                return(true);
            }
            return(false);
        }
Example #13
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     if (txtTenTacGia.Text.Length == 0)
     {
         MessageBox.Show("Bạn Chưa Nhập Tên Tác Giả!", "Cảnh báo!");
     }
     else
     {
         TacGiaDTO tacGia = new TacGiaDTO();
         tacGia.TenTG = txtTenTacGia.Text;
         TacGiaBUS.Insert(tacGia);
         MessageBox.Show("Thêm thành công!", "Thông báo!");
         this.Close();
     }
 }
Example #14
0
        public bool Sua(TacGiaDTO tgDTO)
        {
            conn.Open();
            string SQL = string.Format("UPDATE TACGIA SET HOTEN = N'{0}', NGAYSINH = '{1}', GIOITINH = '{2}', GHICHU = N'{3}' " +
                                       "WHERE MATACGIA = {4}", tgDTO.HoTen, tgDTO.NgaySinh.ToString("yyyy-MM-dd"), tgDTO.GioiTinh, tgDTO.GhiChu, tgDTO.MaTacGia);
            SqlCommand com = new SqlCommand(SQL, conn);
            int        kq  = com.ExecuteNonQuery();

            conn.Close();
            if (kq > 0)
            {
                return(true);
            }
            return(false);
        }
Example #15
0
        public static void Insert(TacGiaDTO TACGIA)
        {
            OleDbConnection connection = DataProvider.CreateConnection();
            string          cmdText    = "Insert into TACGIA(TenTG) values(?)";
            OleDbCommand    command    = new OleDbCommand(cmdText, connection);

            command.Parameters.Add("@TenTG", OleDbType.VarWChar);
            command.Parameters["@TenTG"].Value = TACGIA.TenTG;

            command.ExecuteNonQuery();

            command.CommandText = "select @@IDENTITY";
            TACGIA.MaTG         = (int)command.ExecuteScalar();

            connection.Close();
        }
        private void btnSua_Click(object sender, EventArgs e)
        {
            TacGiaDTO TG = new TacGiaDTO();

            TG.MaTG   = txtMaTG.Text;
            TG.TenTG  = txtTenTG.Text;
            TG.DiaChi = txtDiaChi.Text;
            if (TacGiaBUS.SuaTG(TG) == true)
            {
                LoadData();
            }
            else
            {
                MessageBox.Show("Cập nhật thất bại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public IActionResult Index(string sortOrder, string searchString, int pageIndex = 1)
        {
            int pageSize = 8;
            int count;
            var tacGias   = tacGiaService.GetTacGias(sortOrder, searchString, pageIndex, pageSize, out count);
            var tacGiaNew = new TacGiaDTO();

            var tacGiaVM = new TacGiaIndexVm()
            {
                TacGias      = new PaginatedList <TacGiaDTO>(tacGias, count, pageIndex, pageSize),
                SearchString = searchString,
                SortOrder    = sortOrder,
                tacGia       = tacGiaNew
            };

            return(View(tacGiaVM));
        }
        private void frmCapNhatTacGia_Load(object sender, EventArgs e)
        {
            TacGiaBUS tgBUS = new TacGiaBUS();
            TacGiaDTO tgDTO = tgBUS.LayTacGiaTheoMa(matacgia);

            txtMaTacGia.Text  = tgDTO.MaTacGia.ToString();
            txtHoTen.Text     = tgDTO.HoTen;
            dtpNgaySinh.Value = tgDTO.NgaySinh;
            if (tgDTO.GioiTinh)
            {
                radNam.Checked = true;
            }
            else
            {
                radNu.Checked = true;
            }
            txtGhiChu.Text = tgDTO.GhiChu;
        }
Example #19
0
 public static bool SuaTG(TacGiaDTO TG)
 {
     try
     {
         SqlConnection con = DataProvider.Connection();
         SqlCommand    cmd = new SqlCommand("sp_SuaTG", con);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add("@matg", SqlDbType.NChar);
         cmd.Parameters.Add("@tentg", SqlDbType.NVarChar);
         cmd.Parameters.Add("@diachi", SqlDbType.NVarChar);
         cmd.Parameters["@matg"].Value   = TG.MaTG;
         cmd.Parameters["@tentg"].Value  = TG.TenTG;
         cmd.Parameters["@diachi"].Value = TG.DiaChi;
         cmd.ExecuteNonQuery();
         con.Close();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #20
0
        public TacGiaDTO LayTacGiaTheoMa(int matacgia)
        {
            conn.Open();
            SqlCommand com = new SqlCommand();

            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = "SP_LayTacGiaTheoMa";
            com.Parameters.Add("matacgia", SqlDbType.Int).Value = matacgia;
            com.Connection = conn;
            SqlDataReader dr = com.ExecuteReader();
            TacGiaDTO     tg = new TacGiaDTO();

            if (dr.Read())
            {
                tg.MaTacGia = matacgia;
                tg.HoTen    = (string)dr["HoTen"];
                tg.NgaySinh = Convert.ToDateTime(dr["NgaySinh"]);
                tg.GioiTinh = (bool)dr["GioiTinh"];
                tg.GhiChu   = (string)dr["GhiChu"];
            }
            conn.Close();
            return(tg);
        }
Example #21
0
        public static bool Modify(TacGiaDTO tacGia)
        {
            bool result = false;

            OleDbConnection connection = DataProvider.CreateConnection();
            string          cmdText    = "Update TACGIA set TenTG = ? where MaTG = ?";
            OleDbCommand    command    = new OleDbCommand(cmdText, connection);

            command.Parameters.Add("@TenTG", OleDbType.VarWChar);
            command.Parameters.Add("@MaTG", OleDbType.Integer);

            command.Parameters["@TenTG"].Value = tacGia.TenTG;
            command.Parameters["@MaTG"].Value  = tacGia.MaTG;

            int row = command.ExecuteNonQuery();

            if (row > 0)
            {
                result = true;
            }

            return(result);
        }
Example #22
0
        public static IList GetList()
        {
            ArrayList arrList = new ArrayList();

            TacGiaDTO TACGIA = null;

            OleDbConnection connection = DataProvider.CreateConnection();
            string          cmdText    = "Select * from TACGIA";
            OleDbCommand    command    = new OleDbCommand(cmdText, connection);
            OleDbDataReader reader     = command.ExecuteReader();

            while (reader.Read())
            {
                TACGIA = new TacGiaDTO();

                TACGIA.MaTG  = (int)reader["MaTG"];
                TACGIA.TenTG = (string)reader["TenTG"];
                arrList.Add(TACGIA);
            }
            reader.Close();
            connection.Close();
            return(arrList);
        }
Example #23
0
 public static void Insert(TacGiaDTO tacGia)
 {
     TacGiaDAO.Insert(tacGia);
 }
        public bool Them(TacGiaDTO tg)
        {
            bool re = TgDAL.Them(tg);

            return(re);
        }
        public bool Xoa(TacGiaDTO kn)
        {
            bool re = TgDAL.Xoa(kn);

            return(re);
        }
        public bool Sua(TacGiaDTO kn)
        {
            bool re = TgDAL.Sua(kn);

            return(re);
        }
Example #27
0
 private void btnLuuTG_Click(object sender, EventArgs e)
 {
     if (isThemTG)
     {
         try
         {
             TacGiaDTO tgDTO = new TacGiaDTO();
             tgDTO.HoTen    = txtHoTenTG.Text.Trim();
             tgDTO.NgaySinh = dtpNgaySinhTG.Value;
             tgDTO.GioiTinh = radNamTG.Checked ? true : false;
             tgDTO.GhiChu   = txtGhiChuTG.Text.Trim();
             if (tgBUS.Them(tgDTO))
             {
                 MessageBox.Show("Thêm thành công!");
             }
             else
             {
                 MessageBox.Show("Thêm không thành công!");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             btnLuuTG.Visible          = false;
             pnlChucNangTacGia.Enabled = true;
             pnlControlTacGia.Enabled  = false;
             isThemTG = false;
             //resetControlTG();
             bdsTacGia.DataSource    = tgBUS.LayDanhSach();
             bdsCBOTacGia.DataSource = tgBUS.LayDanhSach();
         }
     }
     if (isSuaTG)
     {
         try
         {
             TacGiaDTO tgDTO = new TacGiaDTO();
             tgDTO.MaTacGia = Convert.ToInt32(txtMaTacGia.Text);
             tgDTO.HoTen    = txtHoTenTG.Text.Trim();
             tgDTO.NgaySinh = dtpNgaySinhTG.Value;
             tgDTO.GioiTinh = radNamTG.Checked ? true : false;
             tgDTO.GhiChu   = txtGhiChuTG.Text.Trim();
             if (tgBUS.Sua(tgDTO))
             {
                 MessageBox.Show("Sửa thành công!");
             }
             else
             {
                 MessageBox.Show("Sửa không thành công!");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             btnLuuTG.Visible          = false;
             pnlChucNangTacGia.Enabled = true;
             pnlControlTacGia.Enabled  = false;
             isSuaTG = false;
             //resetControlTG();
             bdsTacGia.DataSource    = tgBUS.LayDanhSach();
             bdsCBOTacGia.DataSource = tgBUS.LayDanhSach();
         }
     }
 }
Example #28
0
        private void frmCapNhatSach_Load(object sender, EventArgs e)
        {
            try
            {
                cmbTenTG.DataSource    = TacGiaBUS.GetList();
                cmbTenTG.DisplayMember = "TenTG";
                cmbTenTG.ValueMember   = "MaTG";

                cmbNhaXuatBan.DataSource    = NhaXuatBanBUS.GetList();
                cmbNhaXuatBan.DisplayMember = "TenNXB";
                cmbNhaXuatBan.ValueMember   = "MaNXB";

                cmbLoaiSach.DataSource    = TheLoaiBUS.GetList();
                cmbLoaiSach.DisplayMember = "TenTheLoai";
                cmbLoaiSach.ValueMember   = "MaLoai";

                cmbNgonNgu.DataSource    = NgonNguBUS.GetList();
                cmbNgonNgu.DisplayMember = "TenNgonNgu";
                cmbNgonNgu.ValueMember   = "MaNgonNgu";

                int     maSach  = TimKiemSach.MaSach;
                SachBUS sachBUS = new SachBUS();
                SachDTO sachDTO = null;
                sachDTO         = sachBUS.Search_MaSach(maSach);
                tbxTenSach.Text = sachDTO.TenSach;
                txtSoTrang.Text = sachDTO.SoTrang.ToString();

                TacGiaBUS tacgiaBUS = new TacGiaBUS();
                TacGiaDTO tacgiaDTO = null;
                tacgiaDTO     = tacgiaBUS.LayTenTacGia(sachDTO.MaTacGia);
                cmbTenTG.Text = tacgiaDTO.TenTG;

                NhaXuatBanBUS nxbBUS = new NhaXuatBanBUS();
                NhaXuatBanDTO nxbDTO = null;
                nxbDTO             = nxbBUS.LayTenNhaXuatBan(sachDTO.MaNXB);
                cmbNhaXuatBan.Text = nxbDTO.TenNXB;

                NgonNguBUS nnBUS = new NgonNguBUS();
                NgonNguDTO nnDTO = null;
                nnDTO           = nnBUS.LayTenNgonNgu(sachDTO.MaNgonNgu);
                cmbNgonNgu.Text = nnDTO.TenNgonNgu;

                TheLoaiBUS tlBUS = new TheLoaiBUS();
                TheLoaiDTO tlDTO = null;
                tlDTO            = tlBUS.LayTenTheLoai(sachDTO.MaTheLoai);
                cmbLoaiSach.Text = tlDTO.TenTheLoai;


                if (sachDTO.TrangThai == 0)
                {
                    cmbTinhTrang.Text = "Chưa mượn";
                }
                else
                {
                    cmbTinhTrang.Text = "Đã mượn";
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public static void MappingTacGia(this TacGiaDTO tacGiaDto, TacGia tacGia)
 {
     tacGia.MaTG  = tacGiaDto.MaTG;
     tacGia.TenTG = tacGiaDto.TenTG;
 }
Example #30
0
        public void ThemTacGia(TacGiaDTO tacGiaDto)
        {
            var tacGia = tacGiaDto.MappingTacGia();

            _tacGiaRepository.Add(tacGia);
        }