Exemple #1
0
  public ArrayList<NhanVien> getTatCaNhanVien() {
    this.listNhanVien = new ArrayList<NhanVien>();

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlGetTatCaNhanVien);
      rs = pstmt.executeQuery();

      while (rs.next()) {
        this.nhanVien =
            new NhanVien(
                rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5));
        this.listNhanVien.add(this.nhanVien);
      }

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
      SQLConnection.closeResultSet(rs);
    }

    return this.listNhanVien;
  }
Exemple #2
0
  public NhanVien getNhanVienTheoTenDangNhapVaMatKhau(String tenDangNhap, String matKhau) {
    this.nhanVien = null;

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlGetNhanVienTheoTenDangNhapVaMatKhau);

      pstmt.setString(1, tenDangNhap);
      pstmt.setString(2, matKhau);

      rs = pstmt.executeQuery();

      if (rs.next()) {
        this.nhanVien =
            new NhanVien(
                rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5));
      }

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
      SQLConnection.closeResultSet(rs);
    }

    return this.nhanVien;
  }
Exemple #3
0
  public int deleteNhanVien(int maNhanVien) {
    int result = 0;

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlDeleteNhanVien);

      pstmt.setInt(1, maNhanVien);

      result = pstmt.executeUpdate();

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
    }

    return result;
  }
  public int addLoaiSanPham(LoaiSanPham lsp) {
    int result = 0;

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlAddLoaiSanPham);

      pstmt.setString(1, lsp.getTen());
      pstmt.setString(2, lsp.getMoTa());

      result = pstmt.executeUpdate();

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
    }

    return result;
  }
Exemple #5
0
  public int addNhanVien(NhanVien nv) {
    int result = 0;

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlAddNhanVien);

      pstmt.setString(1, nv.getTen());
      pstmt.setString(2, nv.getTenDangNhap());
      pstmt.setString(3, nv.getMatKhau());
      pstmt.setString(4, nv.getGhiChu());

      result = pstmt.executeUpdate();

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
    }

    return result;
  }
  public LoaiSanPham getLoaiSanPhamTheoMa(int maLoaiSanPham) {
    this.loaiSanPham = null;

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlGetLoaiSanPhamTheoMa);
      pstmt.setInt(1, maLoaiSanPham);
      rs = pstmt.executeQuery();

      if (rs.next()) {
        this.loaiSanPham = new LoaiSanPham(rs.getInt(1), rs.getString(2), rs.getString(3));
      }

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
      SQLConnection.closeResultSet(rs);
    }

    return this.loaiSanPham;
  }
  public ArrayList<LoaiSanPham> getTatCaLoaiSanPham() {
    this.listLoaiSanPham = new ArrayList<LoaiSanPham>();

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlGetTatCaLoaiSanPham);
      rs = pstmt.executeQuery();

      while (rs.next()) {
        this.loaiSanPham = new LoaiSanPham(rs.getInt(1), rs.getString(2), rs.getString(3));
        this.listLoaiSanPham.add(this.loaiSanPham);
      }

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
      SQLConnection.closeResultSet(rs);
    }

    return this.listLoaiSanPham;
  }