// 根据区段获得属于区段内的所有计划车次信息
  public void getAllPlanTrainInfoByDistrict(String districtName) {

    // ORDER BY 记录将按照默认的升序进行排列(即:从1到9,从a到z)使用DESC 数据按照降序排列
    Plan tableName = new Plan(); // 设置要进行操作的数据库表名
    String sqlStr =
        "select * from plan where District_name = '"
            + districtName
            + "' ORDER BY Plan_arrivestationtime,Plan_leavestationtime";

    // 从plan表中获取区段内所有车次信息 已经按照到站和离站时间排好序
    List<Plan> planTrainList = databaseAccessHandler.sqlQuery(tableName, "Plan", sqlStr);

    //////////////////////////////////////////////////////////////////
    // 从TrainDistrictRelation表中获取区段内所有车次信息,仅有车次信息  原来的
    // List<TrainDistrictRelation> trainNameList =
    // getAllTrainDistrictRelationByDistrict(districtName);
    // 从Train表中获取区段内所有车次信息
    List<Train> trainNameList = getAllTrainsByDistrict(districtName);

    if (trainNameList == null || trainNameList.size() == 0) return;

    // 对trainNameList进行加工,方便getTrainDirectionByTrainName方法的执行,提高效率
    Iterator<Train> it = trainNameList.iterator();
    while (it.hasNext()) {
      Train data = (Train) it.next();
      trainNameDirectionMap.put(data.getTrain_name(), data.getTrain_direction());
    }
    baseParam.setTrainNameDirectionMap(trainNameDirectionMap);

    // 对每一个车站,获取经过的所有车次信息,并自动排序
    sortPlanTrainForStation(planTrainList);

    // 转换格式
    int len = trainNameList.size();
    // 每次执行,仅对一个车次的信息的进行操作
    for (int i = 0; i < len; i++) {
      String trainName = trainNameList.get(i).getTrain_name();

      // 依据车次trainName按照车站的先后顺序对本车次进行排序  首站->终点站
      List<Plan> sortPlanTrainList = sortPlanTrainList(planTrainList, trainName);

      // 依据车次trainName,对排好序的车次详细信息进行加工,使之用于屏幕绘图
      setTrainPlanFromatList(sortPlanTrainList, trainName);
    }

    // 将车次信息添加到tdcsDataset的TrainList中
    for (int i = 0; i < len; i++) {
      String trainName = trainNameList.get(i).getTrain_name();
      trainNameExist(trainName); // 判断trainName是否已经存在
    }
  }
  // 参数为车站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;
    }
  }