Esempio n. 1
0
        // Chuyển giá trị trong DataGridView thành TheLoaiSach
        public TheLoaiSach DataGridView_To_TheLoaiSach(int index)
        {
            try
            {
                TheLoaiSach result = new TheLoaiSach();


                var id = this.dgvData.Rows[index].Cells["id"].Value;
                if (id != null)
                {
                    result.id = int.Parse(id.ToString());
                }

                var id_tblSach = this.dgvData.Rows[index].Cells["id_tblSach"].Value;
                if (id_tblSach != null)
                {
                    result.id_tblSach = (id_tblSach == null ? null : (int?)int.Parse(id_tblSach.ToString()));
                }

                var id_tblLoaiSach = this.dgvData.Rows[index].Cells["id_tblLoaiSach"].Value;
                if (id_tblLoaiSach != null)
                {
                    result.id_tblLoaiSach = (id_tblLoaiSach == null ? null : (int?)int.Parse(id_tblLoaiSach.ToString()));
                }

                return(result);
            }
            catch (Exception ex) { ShowMessage(ex.Message, false); } // Không load được hoặc xảy ra lỗi
            return(null);
        }
Esempio n. 2
0
        public TheLoaiSach GetData(String ma)
        {
            TheLoaiSach tl = new TheLoaiSach();

            cmd.CommandText = String.Format("Select * from TheLoaiSach where MaTL = '{0}' ", ma);
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = con.Connection;
            try
            {
                con.OpenConn();
                SqlDataReader reader   = cmd.ExecuteReader();
                int           ordMaNV  = reader.GetOrdinal("MaTL");
                int           ordTenNV = reader.GetOrdinal("TenTL");
                while (reader.Read())
                {
                    tl.MaTL  = reader.GetString(ordMaNV);
                    tl.TenTL = reader.GetString(ordTenNV);
                }
                reader.Close();
                con.CloseConn();
            }
            catch (Exception ex)
            {
                string mex = ex.ToString();
                cmd.Dispose();
                con.CloseConn();
            }
            return(tl);
        }
        public List <TheLoaiSach> getTL()
        {
            string             sql = "SELECT * FROM TheLoai";
            string             maTL, tenTL;
            List <TheLoaiSach> list = new List <TheLoaiSach>();

            Connect();
            try
            {
                SqlDataReader dr = myExecuteReader(sql);
                while (dr.Read())
                {
                    maTL  = dr[0].ToString();
                    tenTL = dr[1].ToString();


                    TheLoaiSach tl = new TheLoaiSach(maTL, tenTL);
                    list.Add(tl);
                }
                dr.Close();
                return(list);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                Disconnect();
            }
        }
Esempio n. 4
0
        public TheLoaiSach GetRow(string maTheLoai)
        {
            try
            {
                TheLoaiSach theLoai = new TheLoaiSach();
                if (_connection.State != ConnectionState.Open)
                {
                    _connection.Open();
                }
                const string sql = "SELECT * FROM TheLoaiSach WHERE MaTheLoai = @matheloai";
                var          cmd = new SqlCommand(sql, _connection);
                cmd.Parameters.Add("@matheloai", SqlDbType.Char).Value = maTheLoai;
                var rd = cmd.ExecuteReader();
                if (rd.Read())
                {
                    theLoai.MaTheLoai  = rd["MaTheLoai"].ToString();
                    theLoai.TenTheLoai = rd["TenTheLoai"].ToString();
                    rd.Close();
                }

                //_connection.Close();
                return(theLoai);
            }
            catch (Exception ex)
            {
                _connection.Close();
                Console.WriteLine(ex.Message);
            }
            return(null);
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(int id, [Bind("TheLoaiSachID,TenTLSach")] TheLoaiSach theLoaiSach)
        {
            if (id != theLoaiSach.TheLoaiSachID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(theLoaiSach);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TheLoaiSachExists(theLoaiSach.TheLoaiSachID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(theLoaiSach));
        }
Esempio n. 6
0
 public void ReLoadForm()
 {
     cbTheLoai.DataSource       = TheLoaiSach.laydanhsachtheloai();
     dtgDanhSachSach.DataSource = sm.LayDanhSachSach();
     txtMaSach.Text             = sm.GetLastNode().ToString("MS000");
     cbNguoiTiepNhan.DataSource = nvm.LayNhanVienThuKho();
     cbNamXuatBan.DataSource    = DanhSachNamXuatban();
 }
Esempio n. 7
0
        public void AddRowTest()
        {
            TheLoaiSach theLoai = new TheLoaiSach()
            {
                MaTheLoai  = "TL02",
                TenTheLoai = "Sách Giáo Khoa",
            };

            Assert.IsTrue(theLoaiSachTable.AddRow(theLoai));
        }
 public bool UpdateTheLoai(TheLoaiSach tl)
 {
     if (objTheLoai.IsRowExists(tl.MaTheLoai))
     {
         return(objTheLoai.UpdateRow(tl));
     }
     else
     {
         return(false);
     }
 }
 public bool AddTheLoai(TheLoaiSach tl)
 {
     if (!objTheLoai.IsRowExists(tl.MaTheLoai))
     {
         return(objTheLoai.AddRow(tl));
     }
     else
     {
         return(false);
     }
 }
Esempio n. 10
0
 public int Add(TheLoaiSach theLoaiSach)
 {
     try
     {
         return(theLoaiSachDAO.Add(theLoaiSach));
     }
     catch (SqlException ex)
     {
         throw ex;
     }
 }
Esempio n. 11
0
        public static List <TheLoaiSach> LayDanhSachTheLoai()
        {
            List <TheLoaiSach> list  = new List <TheLoaiSach>();
            string             query = string.Format("Select * from THE_LOAI");
            DataTable          dt    = DataProvider.Instance.ExcuteQuery(query);

            foreach (DataRow item in dt.Rows)
            {
                TheLoaiSach theLoai = new TheLoaiSach(item);
                list.Add(theLoai);
            }
            return(list);
        }
Esempio n. 12
0
        // Chuyển giá trị trong Textbox thành TheLoaiSach
        public TheLoaiSach Textbox_To_TheLoaiSach()
        {
            try
            {
                TheLoaiSach result = new TheLoaiSach();


                result.id             = (int)this.numbid.Value;
                result.id_tblSach     = (int)this.numbid_tblSach.Value;
                result.id_tblLoaiSach = (int)this.numbid_tblLoaiSach.Value;

                return(result);
            }
            catch (Exception ex) { ShowMessage(ex.Message, false); } // Không load được hoặc xảy ra lỗi
            return(null);
        }
        public int Add(TheLoaiSach theLoaiSach)
        {
            string sql = "INSERT INTO TheLoai VALUES (@id,@name)";
            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@id", theLoaiSach.MaTheLoai));
            parameters.Add(new SqlParameter("@name", theLoaiSach.TenTheLoai));


            try
            {
                return(myExecuteNonQuery(sql, CommandType.Text, parameters));
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
Esempio n. 14
0
 public bool AddData(TheLoaiSach tl)
 {
     cmd.CommandText = String.Format("Insert into TheLoaiSach values('{0}', N'{1}') ", tl.MaTL, tl.TenTL);
     cmd.CommandType = CommandType.Text;
     cmd.Connection  = con.Connection;
     try
     {
         con.OpenConn();
         cmd.ExecuteNonQuery();
         return(true);
     }
     catch (Exception ex)
     {
         string mex = ex.ToString();
         cmd.Dispose();
         con.CloseConn();
     }
     return(false);
 }
Esempio n. 15
0
 public bool UpdateData(TheLoaiSach tl)
 {
     cmd.CommandText = String.Format("update TheLoaiSach set TenTL=N'{0}' where MaTL = '{1}'", tl.TenTL, tl.MaTL);
     cmd.CommandType = CommandType.Text;
     cmd.Connection  = con.Connection;
     try
     {
         con.OpenConn();
         cmd.ExecuteNonQuery();
         return(true);
     }
     catch (Exception ex)
     {
         string mex = ex.ToString();
         cmd.Dispose();
         con.CloseConn();
     }
     return(false);
 }
Esempio n. 16
0
        public async Task <IActionResult> Create(TheLoaiSach theLoaiSach)
        {
            int count = _context.TheLoaiSach.Count();

            if (ModelState.IsValid)
            {
                if (count >= 3)
                {
                    return(RedirectToAction("Create"));
                }
                else
                {
                    _context.Add(theLoaiSach);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(theLoaiSach));
        }
Esempio n. 17
0
 public bool UpdateRow(TheLoaiSach theLoai)
 {
     try
     {
         if (_connection.State != ConnectionState.Open)
         {
             _connection.Open();
         }
         const string cmdText = "UPDATE TheLoaiSach SET TenTheLoai = @TenTheLoai WHERE MaTheLoai = @MaTheLoai";
         var          command = new SqlCommand(cmdText, _connection);
         command.Parameters.Add("@MaTheLoai", SqlDbType.Char).Value      = theLoai.MaTheLoai;
         command.Parameters.Add("@TenTheLoai", SqlDbType.NVarChar).Value = theLoai.TenTheLoai;
         command.ExecuteNonQuery();
         _connection.Close();
         return(true);
     }
     catch (Exception ex)
     {
         _connection.Close();
         Console.WriteLine(ex.Message);
     }
     return(false);
 }