示例#1
0
 public bool InseartTheLoai(TheLoai_DTO tl)
 {
     try
     {
         _conn.Open();
         SqlCommand cmd = new SqlCommand();
         cmd.Connection  = _conn;
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = "INSERTTheLoai";
         cmd.Parameters.AddWithValue("MaTheLoai", tl.MaTheLoai);
         cmd.Parameters.AddWithValue("TenTheLoai", tl.TenTheLoai);
         if (cmd.ExecuteNonQuery() > 0)
         {
             return(true);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     finally
     {
         _conn.Close();
     }
     return(false);
 }
 // cập nhật lại danh sách thể loại
 void CapNhat()
 {
     if (txtTenTheLoai.Text == "")
     {
         MessageBox.Show("Không được bỏ trống tên thể loại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         txtTenTheLoai.Focus();
     }
     else
     {
         if (MessageBox.Show("Bạn thực sự muốn cập nhật thể loại này?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
         {
             TheLoai_DTO tl = new TheLoai_DTO();
             tl.TenTheLoai = txtTenTheLoai.Text;
             tl.MaTheLoai  = int.Parse(txtMaTheLoai.Text);
             string ketQua = TheLoai_BUS.SuaTheLoai(tl);
             if (ketQua != "Success")
             {
                 MessageBox.Show(ketQua, "Lỗi");
                 return;
             }
             MessageBox.Show("Cập nhật thành công");
             HienThiDanhSachTheLoai();
         }
     }
 }
 private void btnOkThem_Click(object sender, EventArgs e)
 {
     if ((txtMaTL.Text != "") && (txtTenTL.Text != ""))
     {
         try
         {
             TheLoai_DTO theLoai = new TheLoai_DTO(txtMaTL.Text, txtTenTL.Text);
             BUS_OBJ.themTL(theLoai);
             HienThiDuLieu();
         }
         catch (Exception)
         {
             MetroFramework.MetroMessageBox.Show(this, "Mã thể loại bị trùng. \nKhông thể thêm mới", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             //MessageBox.Show(ex.Message);
         }
         finally
         {
             btnCancel_Click(sender, e);
             //if (conn.State == ConnectionState.Open) conn.Close();
         }
     }
     else
     {
         MetroFramework.MetroMessageBox.Show(this, "Nhập thiếu dữ liệu.", "Lỗi.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         if (txtTenTL.Text == "")
         {
             txtTenTL.Focus();
         }
         if (txtMaTL.Text == "")
         {
             txtMaTL.Focus();
         }
     }
     //btnCancel_Click(sender, e);
 }
示例#4
0
 public bool KiemTra(TheLoai_DTO tl)
 {
     if (tl.TenTheLoai == "")
     {
         return(false);
     }
     return(true);
 }
示例#5
0
 //Kiểm tra trước khi lưu
 public bool KiemTraTruocKhiLuu(TheLoai_DTO tl)
 {
     if (tl.TenTL.Equals(""))
     {
         MessageBox.Show("Tên Thể Loại không hợp lệ ! ");
         return(false);
     }
     return(true);
 }
示例#6
0
        //Lấy Thông tin Thể loại
        private TheLoai_DTO LayTTTL()
        {
            TheLoai_DTO tl = new TheLoai_DTO();

            tl.MaTL   = txtMaTL.Text;
            tl.TenTL  = txtTenTL.Text;
            tl.GhiChu = txtGhiChu.Text;
            return(tl);
        }
示例#7
0
 public frm_TheLoai(int _SoTheLoai)
 {
     InitializeComponent();
     soTheLoai      = _SoTheLoai;
     theLoaiBUS     = new TheLoai_BUS();
     theLoaiDTO     = new TheLoai_DTO();
     listTheLoai    = new List <string>();
     kiemtra        = true;
     xacNhanCapNhap = false;
 }
示例#8
0
 //Thêm 1 thể loại vào bảng THELOAI
 public static string ThemTheLoai(TheLoai_DTO tl)
 {
     if (TheLoai_DAO.GetTheLoaiByName(tl.TenTheLoai) == null)
     {
         return(TheLoai_DAO.Insert(tl));
     }
     else
     {
         return("Thể loại này đã có trong cơ sở dữ liệu");
     }
 }
示例#9
0
        public static void suaTL(TheLoai_DTO theLoai)
        {
            SqlConnection conn = SQLConn.connect();
            SqlCommand    cmd  = new SqlCommand("sp_suatheloai", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@matheloai", SqlDbType.VarChar).Value   = theLoai.MaTheLoai;
            cmd.Parameters.Add("@tentheloai", SqlDbType.NVarChar).Value = theLoai.TenTheLoai;
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }
示例#10
0
        private void dgvDauSach_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int dong = e.RowIndex;

            txtMaDauSach.Text        = dgvDauSach.Rows[dong].Cells[0].Value.ToString();
            txtMaSachCT.Text         = dgvDauSach.Rows[dong].Cells[0].Value.ToString();
            txtTenDauSach.Text       = dgvDauSach.Rows[dong].Cells[1].Value.ToString();
            cboTheLoai.SelectedValue = (int)(dgvDauSach.Rows[dong].Cells[2].Value);
            TheLoai_DTO tl = TheLoai_BUS.GetTheLoaiByMa((int)(dgvDauSach.Rows[dong].Cells[2].Value));

            cboTheLoai.Text         = tl.TenTheLoai;
            dgvCT_TacGia.DataSource = DauSach_BUS.SelectCTTacGiaByMa(int.Parse(dgvDauSach.Rows[dong].Cells[0].Value.ToString()));
        }
示例#11
0
 //Sửa Thể Loại vào CSDL
 public bool SuaTL(TheLoai_DTO tl)
 {
     if (KiemTraTruocKhiLuu(tl))
     {
         string sql = string.Format("UPDATE THELOAI SET TenTL=N'{0}', GhiChu=N'{1}' WHERE MaTL='{2}'", tl.TenTL, tl.GhiChu, tl.MaTL);
         if (connData.ThucThiSQL(sql))
         {
             MessageBox.Show("Sửa Thể Loại thành công !", "Thông tin", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return(true);
         }
     }
     return(false);
 }
示例#12
0
        public List <TheLoai_DTO> TimKiemTheLoai(string param)
        {
            List <TheLoai_DTO> DanhSachTheLoai = new List <TheLoai_DTO>();
            string             query           = string.Format("select * from TheLoai where MaTheLoai like N'%{0}%' or TenTheLoai like N'%{0}%'", param);
            DataTable          data            = DataProvider.Instance.ExecuteQuery(query);

            foreach (DataRow item in data.Rows)
            {
                TheLoai_DTO TL = new TheLoai_DTO(item);
                DanhSachTheLoai.Add(TL);
            }
            return(DanhSachTheLoai);
        }
示例#13
0
        public List <TheLoai_DTO> LayTatCaTheLoai()
        {
            List <TheLoai_DTO> DanhSachTheLoai = new List <TheLoai_DTO>();

            DataTable data = DataProvider.Instance.ExecuteQuery("select * from TheLoai");

            foreach (DataRow item in data.Rows)
            {
                TheLoai_DTO TL = new TheLoai_DTO(item);
                DanhSachTheLoai.Add(TL);
            }
            return(DanhSachTheLoai);
        }
示例#14
0
 //Thêm Thể loại vào CSDL
 public bool ThemTL(TheLoai_DTO tl)
 {
     if (KiemTraTruocKhiLuu(tl))
     {
         string sql = string.Format("INSERT INTO THELOAI (MaTL, TenTL, GhiChu)"
                                    + " VALUES ('{0}', N'{1}', N'{2}')", tl.MaTL, tl.TenTL, tl.GhiChu);
         if (connData.ThucThiSQL(sql))
         {
             MessageBox.Show("Thêm Thể loại thành công", "Thông tin", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return(true);
         }
     }
     return(false);
 }
示例#15
0
        private void dgvSach_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int dong = e.RowIndex;

            txtMaSach.Text           = dgvSach.Rows[dong].Cells[0].Value.ToString();
            txtTenSach.Text          = dgvSach.Rows[dong].Cells[1].Value.ToString();
            cmbTheLoai.SelectedValue = (int)(dgvSach.Rows[dong].Cells[2].Value);
            TheLoai_DTO tl = TheLoai_BUS.GetTheLoaiByMa((int)(dgvSach.Rows[dong].Cells[2].Value));

            cmbTheLoai.Text    = tl.TenTheLoai;
            txtTacGia.Text     = dgvSach.Rows[dong].Cells[3].Value.ToString();
            txtDonBanSach.Text = dgvSach.Rows[dong].Cells[4].Value.ToString();
            txtSoLuongTon.Text = dgvSach.Rows[dong].Cells[5].Value.ToString();
        }
示例#16
0
 //Sửa 1 thể loại
 public static string SuaTheLoai(TheLoai_DTO tl)
 {
     if (TheLoai_DAO.GetTheLoaiByName(tl.TenTheLoai) != null)
     {
         return("Thể loại này đã có trong cơ sở dữ liệu");
     }
     if (TheLoai_DAO.GetTheLoaiByMa(tl.MaTheLoai) != null)
     {
         return(TheLoai_DAO.Update(tl));
     }
     else
     {
         return("Mã thể loại này không tồn tại trong CSDL");
     }
 }
示例#17
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            TheLoai_DTO tl = LayTTTL();

            if (update)
            {
                tlBUS.SuaTL(tl);
                ttTheLoai_Load_1(sender, e);
            }
            if (add)
            {
                tlBUS.ThemTL(tl);
                ttTheLoai_Load_1(sender, e);
            }
        }
示例#18
0
        //Lấy thể loại bằng Mã thể loại
        public static TheLoai_DTO GetTheLoaiByMa(int Ma)
        {
            string    sql = "select * from THELOAI where MaTheLoai=" + Ma + "";
            DataTable dt  = DataAccess.ThucThiQuery(sql);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }
            else
            {
                TheLoai_DTO tl = new TheLoai_DTO();
                tl.MaTheLoai = (int)dt.Rows[0].ItemArray[0];
                return(tl);
            }
        }
示例#19
0
        //Lấy ra 1 đối tượng TheLoai_DTO bằng tên
        public static TheLoai_DTO GetTheLoaiByName(string Name)
        {
            string    sql = "select * from THELOAI where TenTheLoai=N'" + Name + "'";
            DataTable dt  = DataAccess.ThucThiQuery(sql);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }
            else
            {
                TheLoai_DTO tl = new TheLoai_DTO();
                tl.MaTheLoai  = (int)dt.Rows[0].ItemArray[0];
                tl.TenTheLoai = dt.Rows[0].ItemArray[1].ToString();
                return(tl);
            }
        }
示例#20
0
        public static string Laytensach(int ma)
        {
            string    sql = "select * from SACH where MaSach=" + ma + "";
            DataTable dt  = DataAccess.ThucThiQuery(sql);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }
            else
            {
                TheLoai_DTO tl = new TheLoai_DTO();
                //tl.MaTheLoai = (int)dt.Rows[0].ItemArray[0];
                tl.TenTheLoai = dt.Rows[0].ItemArray[1].ToString();
                return(tl.TenTheLoai);
            }
        }
示例#21
0
        public bool ThemTheLoai(TheLoai_DTO theLoai_DTO)
        {
            try
            {
                TheLoai theLoai = new TheLoai();

                theLoai.MaTheLoai  = theLoai_DTO.MaTheLoai;
                theLoai.TenTheLoai = theLoai_DTO.TenTheLoai;
                theLoai.TrangThai  = true;

                data.TheLoais.Add(theLoai);
                data.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#22
0
 public bool Insert(TheLoai_DTO tl)
 {
     try
     {
         if (con.State == ConnectionState.Closed)
         {
             con.Open();
         }
         string     sqlQuery = @"Insert into THELOAISACH values(N'" + tl.TenTheLoai + "')";
         SqlCommand cmd      = new SqlCommand(sqlQuery, con);
         cmd.ExecuteNonQuery();
         con.Close();
         return(true);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
         return(false);
     }
 }
示例#23
0
        private void btnBook_NewCategory_Click(object sender, EventArgs e)
        {
            if (txtBook_CategoryName.Text.Length > 0)
            {
                TheLoai_DTO theLoai_DTO = new TheLoai_DTO();
                theLoai_DTO.MaTheLoai  = lblBook_CategoryID.Text;
                theLoai_DTO.TenTheLoai = txtBook_CategoryName.Text;
                theLoai_DTO.TrangThai  = true;

                if (theLoai_BUS.ThemTheLoai(theLoai_DTO) == true)
                {
                    MessageBox.Show("Add Successfully", "Nocie", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Add Failed", "Nocie", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#24
0
        public bool UpdateTheLoai(TheLoai_DTO tl)
        {
            try
            {
                _conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = _conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "UPDATETheLoai";
                cmd.Parameters.AddWithValue("MaTheLoai", tl.MaTheLoai);
                cmd.Parameters.AddWithValue("TenTheLoai", tl.TenTheLoai);

                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            finally
            {
                _conn.Close();
            }
            return(false);
        }
示例#25
0
 // thêm vào danh sách thể loại
 void Them()
 {
     if (txtTenTheLoai.Text == "")
     {
         MessageBox.Show("Không được bỏ trống tên thể loại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         txtTenTheLoai.Focus();
     }
     else
     {
         if (MessageBox.Show("Bạn thực sự muốn thêm thể loại này?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
         {
             TheLoai_DTO tl = new TheLoai_DTO();
             tl.TenTheLoai = txtTenTheLoai.Text;
             string ketQua = TheLoai_BUS.ThemTheLoai(tl);
             if (ketQua != "Success")
             {
                 MessageBox.Show(ketQua, "Lỗi");
                 return;
             }
             MessageBox.Show("Thêm thể loại thành công");
             HienThiDanhSachTheLoai();
         }
     }
 }
示例#26
0
        //Sửa 1 thể loại theo Mã thể loại
        public static string Update(TheLoai_DTO tl)
        {
            string sql = "Update  THELOAI set TenTheLoai =N'" + tl.TenTheLoai + "'where MaTheLoai=" + tl.MaTheLoai + "";

            return(DataAccess.ThucThiNonQuery(sql));
        }
示例#27
0
        //Xóa 1 thể loại theo Mã thể loai
        public static string Delete(TheLoai_DTO tl)
        {
            string sql = "delete from THELOAI where MaTheLoai=" + tl.MaTheLoai + "";

            return(DataAccess.ThucThiNonQuery(sql));
        }
示例#28
0
 public bool ThemTheLoai(TheLoai_DTO theLoai_DTO)
 {
     return(theLoai_DAO.ThemTheLoai(theLoai_DTO));
 }
示例#29
0
 public static void themTL(TheLoai_DTO theLoai)
 {
     Sach_DAO.themTL(theLoai);
 }
示例#30
0
 public static void suaTL(TheLoai_DTO theLoai)
 {
     Sach_DAO.suaTL(theLoai);
 }