Permalink
Browse files

up

  • Loading branch information...
1 parent f7a32a0 commit e0e8b5cd22da2112fe69bb97d161c8180249537f @nlnbich committed Mar 26, 2012
@@ -30,21 +30,26 @@
- "CREATE TABLE BoMon(MaBM char(6) NOT NULL PRIMARY KEY, TenMH nvarchar(50) NOT NULL unique," +
+ "CREATE TABLE BoMon(MaBM char(6) NOT NULL PRIMARY KEY, TenBM nvarchar(50) NOT NULL unique," +
" LichSu nvarchar(200),NhanSu nvarchar(200), GiangDay nvarchar(200), NghienCuuPhatTrien nvarchar(200) ) ;" ,
- "CREATE TABLE QuaTrinhCongTac(MaQTCT int NOT NULL AUTO_INCREMENT PRIMARY KEY, HSLuong float NOT NULL, Bac int NOT NULL, NgayBD date NOT NULL) ;" ,
+
+ "CREATE TABLE GiangVien(MaGV char(6) NOT NULL PRIMARY KEY, HoTen nvarchar(50) NOT NULL, NgaySinh DateTime NOT NULL, " +
+ "GioiTinh nvarchar(3) NOT NULL, DiaChi nvarchar(50) NOT NULL, DienThoai nvarchar(12) NOT NULL, Email nvarchar(50), GhiChu nvarchar(500)"+
+ ");",
+
+ "CREATE TABLE QuaTrinhCongTac(MaQTCT int NOT NULL AUTO_INCREMENT PRIMARY KEY, MaGV char(6) NOT NULL, HSLuong float NOT NULL," +
+ " Bac int NOT NULL, NgayBD date NOT NULL," +
+ "Constraint QuaTrinhCT_GiangVien Foreign key (MaGV) References GiangVien(MaGV) ) ;" ,
+
+
- "CREATE TABLE NghienCuuKH(MaCTNC char(6) NOT NULL PRIMARY KEY, TenCTNC nvarchar(200) NOT NULL, LoaiCTNC nvarchar(100) not null, NoiDungTH nvarchar(200), NgayBT date not null, NgayKT date ) ;" ,
+ "CREATE TABLE NghienCuuKH(MaCTNC char(6) NOT NULL PRIMARY KEY, TenCTNC nvarchar(200) NOT NULL, " +
+ "LoaiCTNC nvarchar(100) not null, NoiDungTH nvarchar(200), NgayBT date not null, NgayKT date ) ;" ,
// "CREATE TABLE KhenThuong_KyLuat(MaKTKL int NOT NULL AUTO_INCREMENT primary key, TenKTKL nvarchar(100) NOT NULL, NoiDung nvarchar(200) NOT NULL) ;" ,
-
- "CREATE TABLE GiangVien(MaGV char(6) NOT NULL PRIMARY KEY, HoTen nvarchar(50) NOT NULL, NgaySinh DateTime NOT NULL, " +
- "GioiTinh nvarchar(3) NOT NULL, DiaChi nvarchar(50) NOT NULL, DienThoai nvarchar(12) NOT NULL, Email nvarchar(50), GhiChu nvarchar(500),"+
- "MaQTCT int NOT NULL,"+
- "Constraint QTCT_GiangVien Foreign key (MaQTCT) References QuaTrinhCongTac(MaQTCT)"+
- ");",
+
"CREATE TABLE GiangVien_HocHam ( MaGVHH int NOT NULL AUTO_INCREMENT primary key, MaGV char(6)NOT NULL, TenHocHam nvarchar(100) NOT NULL, TGDat Datetime NOT NULL,"+
"Constraint GiangVien_GiangVienHocHam Foreign key (MaGV) References GiangVien(MaGV)) ;" ,
@@ -75,14 +75,15 @@ public static String getMaGV() {
QlgiangvienApplication.DB_PASS);
stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("select max(MaGV) as max from GiangVien ;");
-
+ ResultSet rs = stmt
+ .executeQuery("select max(MaGV) as max from GiangVien ;");
+
String re = "";
-
if (rs.next()) {
s = rs.getString(1);
- if (s.equals("NULL")) s = "GV0000";
+ if (s.equals("NULL"))
+ s = "GV0000";
System.out.println(">>>>>>>>>>>>>>>>>>> " + s + "--"
+ increateID(s));
@@ -91,7 +92,7 @@ public static String getMaGV() {
rs.close();
stmt.close();
conn.close();
-
+
return increateID(s);
} catch (Exception ex) {
@@ -100,8 +101,7 @@ public static String getMaGV() {
return "GV0001";
}
}// end of getIDGiangVien
-
-
+
public static String getMaQTCT() {
Connection conn = null;
@@ -119,27 +119,29 @@ public static String getMaQTCT() {
QlgiangvienApplication.DB_PASS);
stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("select max(MaQTCT) as max from QuaTrinhCongTac ;");
-
+ ResultSet rs = stmt
+ .executeQuery("select max(MaQTCT) as max from QuaTrinhCongTac ;");
+
String re = "";
-
if (rs.next()) {
s = rs.getString(1);
- if (s.equals("NULL")) s = "0";
+ if (s.equals("NULL"))
+ s = "0";
}
rs.close();
stmt.close();
conn.close();
-
- return String.valueOf( (Integer.valueOf(s)+1) ) ;
+
+ return String.valueOf((Integer.valueOf(s) + 1));
} catch (Exception ex) {
System.out.println("UpdateDatabase >> getID: " + ex.getMessage());
return "1";
}
}// end of getIDGiangVien
+
public static String getMaCV() {
Connection conn = null;
@@ -157,27 +159,29 @@ public static String getMaCV() {
QlgiangvienApplication.DB_PASS);
stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("select max(MaCV) as max from GiangVien_BoMon ;");
-
+ ResultSet rs = stmt
+ .executeQuery("select max(MaCV) as max from GiangVien_BoMon ;");
+
String re = "";
-
if (rs.next()) {
s = rs.getString(1);
- if (s.equals("NULL")) s = "0";
+ if (s.equals("NULL"))
+ s = "0";
}
rs.close();
stmt.close();
conn.close();
-
- return String.valueOf( (Integer.valueOf(s)+1) ) ;
+
+ return String.valueOf((Integer.valueOf(s) + 1));
} catch (Exception ex) {
System.out.println("UpdateDatabase >> getID: " + ex.getMessage());
return "1";
}
}// end of getMaCV
+
public static String get() {
Connection conn = null;
@@ -195,27 +199,29 @@ public static String get() {
QlgiangvienApplication.DB_PASS);
stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("select max(MaCV) as max from GiangVien_BoMon ;");
-
+ ResultSet rs = stmt
+ .executeQuery("select max(MaCV) as max from GiangVien_BoMon ;");
+
String re = "";
-
if (rs.next()) {
s = rs.getString(1);
- if (s.equals("NULL")) s = "0";
+ if (s.equals("NULL"))
+ s = "0";
}
rs.close();
stmt.close();
conn.close();
-
- return String.valueOf( (Integer.valueOf(s)+1) ) ;
+
+ return String.valueOf((Integer.valueOf(s) + 1));
} catch (Exception ex) {
System.out.println("UpdateDatabase >> getID: " + ex.getMessage());
return "1";
}
}// end of getMaCV
+
public static String getMaGV_HV() {
Connection conn = null;
@@ -233,37 +239,29 @@ public static String getMaGV_HV() {
QlgiangvienApplication.DB_PASS);
stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("select max(MaGVHV) as max from GiangVien_HocVi ;");
-
+ ResultSet rs = stmt
+ .executeQuery("select max(MaGVHV) as max from GiangVien_HocVi ;");
+
String re = "";
-
if (rs.next()) {
s = rs.getString(1);
- if (s.equals("NULL")) s = "0";
+ if (s.equals("NULL"))
+ s = "0";
}
rs.close();
stmt.close();
conn.close();
-
- return String.valueOf( (Integer.valueOf(s)+1) ) ;
+
+ return String.valueOf((Integer.valueOf(s) + 1));
} catch (Exception ex) {
System.out.println("UpdateDatabase >> getID: " + ex.getMessage());
return "1";
}
}// end of getMaCV
-
-
-
-
-
-
-
-
-
-
+
static private String increateID(String id) {
String re = id.substring(0, 2);
@@ -276,11 +274,8 @@ static private String increateID(String id) {
return re;
}
-
-
-
-
-//===================================== for list
+
+ // ===================================== for list
static public SQLContainer getBoMon() {
try {
@@ -290,20 +285,19 @@ static public SQLContainer getBoMon() {
QlgiangvienApplication.DB_USER,
QlgiangvienApplication.DB_PASS);
- String st_query = "select MaBM, TenMH from BoMon ;";
+ String st_query = "select MaBM, TenBM from BoMon ;";
FreeformQuery query = new FreeformQuery(st_query, pool, "MaBM");
SQLContainer result = new SQLContainer(query);
- return result ;
-
+ return result;
+
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
- }//getBoMon
-
-
+ }// getBoMon
+
static public SQLContainer getDeTai() {
try {
@@ -317,14 +311,54 @@ static public SQLContainer getDeTai() {
FreeformQuery query = new FreeformQuery(st_query, pool, "MaCTNC");
SQLContainer result = new SQLContainer(query);
- return result ;
-
+ return result;
+
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
- }//getBoMon
-
+ }// getBoMon
-}
+ static public boolean insertGiangVien(String[] sql) {
+
+ Connection conn = null;
+ Statement stmt = null;
+ ResultSet rs = null;
+
+ try {
+ Class.forName("com.mysql.jdbc.Driver");
+ conn = DriverManager.getConnection(DB_URL
+ + QlgiangvienApplication.DB_DBNAME,
+ QlgiangvienApplication.DB_USER,
+ QlgiangvienApplication.DB_PASS);
+ // Setting auto commit false
+ conn.setAutoCommit(false);
+ System.out.println("Databese Connection Done........");
+ } catch (Exception e) {
+ System.out.println(e.toString());
+ System.out.println("Error In Connection");
+ return false;
+ }
+ try {
+ // Creating Statement
+ stmt = conn.createStatement();
+
+ for (int i = 0; i < sql.length; i++) {
+
+ stmt.executeUpdate(sql[1]);
+ }
+
+ conn.commit();
+ conn.close();
+ stmt.close();
+ rs.close();
+ System.out.println("Connection Closed..........");
+ return true;
+
+ } catch (Exception e) {
+ System.out.println("insertGiangVien" +e.toString());
+ return false;
+ }
+ }//end of insertGiangVien
+}
@@ -126,7 +126,7 @@ public void setUpdateValue(final Item item){
try {
System.out.println(item.toString()) ;
txtMaBM.setValue(item.getItemProperty("MaBM").getValue().toString()) ;
- txtTenMB.setValue(item.getItemProperty("TenMH").getValue().toString()) ;
+ txtTenMB.setValue(item.getItemProperty("TenBM").getValue().toString()) ;
txtLichsu.setValue(item.getItemProperty("LichSu").getValue().toString()) ;
txtNhansu.setValue(item.getItemProperty("NhanSu").getValue().toString()) ;
txtGiangday.setValue(item.getItemProperty("GiangDay").getValue().toString()) ;
Oops, something went wrong.

0 comments on commit e0e8b5c

Please sign in to comment.