private boolean clearStationInfo() { // 清空所有记录 SQLRequestMessage msg = new SQLRequestMessage(); msg.setCommandMode(Constants.MODE_CS_SYN_CLIENT); msg.setCommandType(Constants.TYPE_CLIENT_SQLBATCHDELETE); // 从一个表中进行删除操作 /* msg.setCommandType(Constants.TYPE_CLIENT_SQLDELETE); msg.setDataBean("District"); msg.setSql("delete from District"); */ String[] sqlArray = new String[6]; sqlArray[0] = "delete from Station"; sqlArray[1] = "delete from District"; sqlArray[2] = "delete from Train"; sqlArray[3] = "delete from StationDistrictRelation"; sqlArray[4] = "delete from TrainDistrictRelation"; sqlArray[5] = "delete from Plan"; String sqlStr = JsonUtil.array2json(sqlArray); msg.setSql(sqlStr); String paprams = "null"; msg.setParams(paprams); String list = synClientSupport.sqlMessageSend(msg); if (list == null) return false; else return true; }
// 从服务器获取信息. private void getStationInfo() { SQLRequestMessage msg = new SQLRequestMessage(); msg.setCommandMode(Constants.MODE_CS_SYN_CLIENT); msg.setCommandType(Constants.TYPE_CLIENT_SQLQUERY); msg.setDataBean("Station"); // 不带参数的sql语句的使用方法 msg.setSql("select * from Station order by Station_name "); // limit 16 String paprams = "null"; // msg.setParams(paprams); // 转换为json字符串进行传递 String listString = synClientSupport.sqlMessageSend(msg); // 同步通信 if (listString == null) { // 此情况不会出现 return; } else { List<Station> list = JsonUtil.getList4Json(listString, Station.class); if (list.size() <= 0) return; stationData.setData(list); } }
// 向服务器发送更新报文 public boolean updateStationInfo( int downAvailLaneNum, int upAvailLaneNum, String map, String stationName) { SQLRequestMessage msg = new SQLRequestMessage(); msg.setCommandMode(Constants.MODE_CS_SYN_CLIENT); msg.setCommandType(Constants.TYPE_CLIENT_SQLUPDATE); msg.setDataBean("Station"); msg.setSql( "update Station set Station_downnumber=? ," + "Station_upnumber=?,Station_graph=? where Station_name =?"); if (downAvailLaneNum == 0) downAvailLaneNum = 1; if (upAvailLaneNum == 0) upAvailLaneNum = 1; Object[] params = new Object[] {downAvailLaneNum, upAvailLaneNum, map, stationName}; String paprams = JsonUtil.array2json(params); msg.setParams(paprams); String list = synClientSupport.sqlMessageSend(msg); // 同步通信 if (list == null) { return false; } else { return true; } }
// 参数为车站ID // 所有相关的记录都将删除. ?????????????? public boolean deleteStationInfo(String stationName) { SQLRequestMessage msg = new SQLRequestMessage(); msg.setCommandMode(Constants.MODE_CS_SYN_CLIENT); // 从列车区段表District中获取车站ID等于stationID的所有区段的ID List<String> districtIDList = new ArrayList<String>(); msg.setCommandType(Constants.TYPE_CLIENT_SQLQUERY); msg.setDataBean("District"); String sqlStr = "select * from District where District_startstationname='" + stationName + "' or District_endstationname='" + stationName + "'"; msg.setSql(sqlStr); String paprams = "null"; msg.setParams(paprams); String listString = synClientSupport.sqlMessageSend(msg); if (listString == null) { // 此情况不会出现 districtIDList = null; } else { List<District> list = JsonUtil.getList4Json(listString, District.class); if (list.size() <= 0) districtIDList = null; else { for (int i = 0; i < list.size(); i++) { District data = (District) list.get(i); districtIDList.add(data.getDistrict_name()); } } } // 从列车表Train中获取车站ID等于stationID的所有车次的ID List<String> trainIDList = new ArrayList<String>(); msg.setDataBean("Train"); sqlStr = "select * from Train where Train_startstationname='" + stationName + "' or Train_endstationname='" + stationName + "'"; msg.setSql(sqlStr); paprams = "null"; msg.setParams(paprams); listString = synClientSupport.sqlMessageSend(msg); if (listString == null) { // 此情况不会出现 trainIDList = null; } else { List<Train> list = JsonUtil.getList4Json(listString, Train.class); if (list.size() <= 0) trainIDList = null; else { for (int i = 0; i < list.size(); i++) { Train data = (Train) list.get(i); trainIDList.add(data.getTrain_name()); } } } // 批量删除 // 涉及到的表:Station, District Train StationDistrictRelation TrainDistrictRelation int districtNumber = 0; int trainNumber = 0; if (districtIDList != null) districtNumber = districtIDList.size(); if (trainIDList != null) trainNumber = trainIDList.size(); String[] sqlArray = new String[5 + districtNumber * 2 + trainNumber]; int index = 0; sqlArray[index++] = "delete from Station where Station_name='" + stationName + "'"; // number 1 sqlArray[index++] = "delete from StationDistrictRelation where Station_name='" + stationName + "'"; // number 1 sqlArray[index++] = "delete from Plan where Station_name='" + stationName + "' or Prestation_name='" + stationName + "'"; // number 1 if (districtIDList != null) { sqlArray[index++] = "delete from District where District_startstationname='" + stationName + "' or District_endstationname='" + stationName + "'"; // number 1 for (int i = 0; i < districtNumber; i++) { // number districtNumber*2 sqlArray[index++] = "delete from StationDistrictRelation where District_name='" + districtIDList.get(i) + "'"; sqlArray[index++] = "delete from TrainDistrictRelation where District_name='" + districtIDList.get(i) + "'"; } } if (trainIDList != null) { sqlArray[index++] = "delete from Train where Train_startstationname='" + stationName + "' or Train_endstationname='" + stationName + "'"; // number 1 for (int i = 0; i < trainNumber; i++) { // number trainNumber sqlArray[index++] = "delete from TrainDistrictRelation where Train_name='" + trainIDList.get(i) + "'"; } } msg.setCommandType(Constants.TYPE_CLIENT_SQLBATCHDELETE); sqlStr = JsonUtil.array2json(sqlArray); msg.setSql(sqlStr); paprams = "null"; msg.setParams(paprams); listString = synClientSupport.sqlMessageSend(msg); // 同步通信 if (listString == null) { return false; } else { return true; } }