Exemplo n.º 1
0
 private static void add_newVote_Date_Option_MySQL(
     Vote_Date_Helper vote_date_helper, int vote_id) {
   String[] vote_date = new String[Table_Vote_Date.Size()];
   vote_date[Table_Vote_Date.Event_ID_num] = Event_Helper.details[Table_Events.Event_ID_num];
   vote_date[Table_Vote_Date.Vote_ID_num] = vote_id + "";
   vote_date[Table_Vote_Date.Start_Date_num] = vote_date_helper.getStart_Date();
   vote_date[Table_Vote_Date.End_Date_num] = vote_date_helper.getEnd_Date();
   vote_date[Table_Vote_Date.All_Day_Time_num] = vote_date_helper.getAll_Day();
   vote_date[Table_Vote_Date.Start_Time_num] = vote_date_helper.getStart_Time();
   vote_date[Table_Vote_Date.End_Time_num] = vote_date_helper.getEnd_Time();
   vote_date[Table_Vote_Date.User_ID_num] = Constants.UnCheck;
   sqlHelper.insert(Table_Vote_Date.Table_Name, vote_date);
 }
Exemplo n.º 2
0
  private static void Update_Event_ServerSQL(Context context, String Event_ID) {
    // Update event (delete and then insert).
    new Event_AsyncTask_update(context).execute(Event_Helper.details);
    // Update Friends list invention.
    Friend_Helper friend_helper;
    for (String User_ID : Event_Helper.friends_tmp.keySet()) {
      friend_helper = Event_Helper.friends_tmp.get(User_ID);
      if (Event_Helper.friends.get(User_ID) == null) { // Add new friends.
        new EventUser_AsyncTask_insert(context)
            .execute(
                Event_ID, User_ID, friend_helper.getAttending(), friend_helper.getPermission());
      } else { // Change permission.
        if (!friend_helper
            .getPermission()
            .equals(Event_Helper.friends.get(User_ID).getPermission())) {
          new EventUser_AsyncTask_UpdatePermission(context)
              .execute(Event_ID, User_ID, friend_helper.getPermission());
        }
      }
    }
    // Delete friends.
    for (String User_ID : Event_Helper.friends.keySet()) {
      if (Event_Helper.friends_tmp.get(User_ID) == null) {
        new EventUser_AsyncTask_delete(context).execute(Event_ID, User_ID);
      }
    }

    // Update Tasks.
    boolean new_task, new_subTask;
    Task_Helper task_helper;
    for (int task_id : Event_Helper.task_tmp.keySet()) {
      task_helper = Event_Helper.task_tmp.get(task_id);
      new_task = Event_Helper.task.get(task_id) == null;
      if (new_task) { // Add new tasks.
        new Task_AsyncTask_insert(context)
            .execute(
                Event_ID,
                task_id + "",
                0 + "",
                task_helper.getType(),
                task_helper.getDescription(),
                task_helper.getUser_ID());
      } else { // Update task description.
        if (!task_helper.getDescription().equals(Event_Helper.task.get(task_id).getDescription())) {
          new Task_AsyncTask_update(context)
              .execute(
                  Event_ID,
                  task_id + "",
                  0 + "",
                  task_helper.getType(),
                  task_helper.getDescription(),
                  task_helper.getUser_ID());
        }
      }
      for (int subTask_id : task_helper.getSubTasks().keySet()) {
        new_subTask =
            (new_task || Event_Helper.task.get(task_id).getSubTasks().get(subTask_id) == null);
        if (new_subTask) { // Add new subTasks.
          new Task_AsyncTask_insert(context)
              .execute(
                  Event_ID,
                  task_id + "",
                  subTask_id + "",
                  task_helper.getType(),
                  task_helper.getSubTasks().get(subTask_id)[0],
                  task_helper.getUser_ID());
        } else { // Update subTask description.
          if (!task_helper
              .getSubTasks()
              .get(subTask_id)[0]
              .equals(Event_Helper.task.get(task_id).getSubTasks().get(subTask_id)[0])) {
            new Task_AsyncTask_update(context)
                .execute(
                    Event_ID,
                    task_id + "",
                    subTask_id + "",
                    task_helper.getType(),
                    task_helper.getSubTasks().get(subTask_id)[0],
                    task_helper.getUser_ID());
          }
        }
      }
    }
    // Delete Tasks.
    for (int task_id : Event_Helper.task.keySet()) {
      task_helper = Event_Helper.task.get(task_id);
      if (Event_Helper.task_tmp.get(task_id) == null) {
        new Task_AsyncTask_delete_Task(context).execute(Event_ID, task_id + "");
      } else {
        for (int subTask_id : task_helper.getSubTasks().keySet()) {
          if (Event_Helper.task_tmp.get(task_id).getSubTasks().get(subTask_id) == null) {
            new Task_AsyncTask_delete_subTask(context)
                .execute(Event_ID, task_id + "", subTask_id + "");
          }
        }
      }
    }

    // Update Vote_date.
    // Update vote will reset the votes users.
    boolean new_vote_date;
    Vote_Date_Helper vote_date_helper_tmp;
    Vote_Date_Helper vote_date_helper;
    for (int vote_id : Event_Helper.vote_date_tmp.keySet()) {
      vote_date_helper_tmp = Event_Helper.vote_date_tmp.get(vote_id);
      vote_date_helper = Event_Helper.vote_date.get(vote_id);
      new_vote_date = vote_date_helper == null;
      String[] vote = new String[Table_Vote_Date.Size()];
      vote[Table_Vote_Date.Event_ID_num] = Event_ID;
      vote[Table_Vote_Date.Vote_ID_num] = vote_id + "";
      vote[Table_Vote_Date.Start_Date_num] = vote_date_helper_tmp.getStart_Date();
      vote[Table_Vote_Date.End_Date_num] = vote_date_helper_tmp.getEnd_Date();
      vote[Table_Vote_Date.All_Day_Time_num] = vote_date_helper_tmp.getAll_Day();
      vote[Table_Vote_Date.Start_Time_num] = vote_date_helper_tmp.getStart_Time();
      vote[Table_Vote_Date.End_Time_num] = vote_date_helper_tmp.getEnd_Time();
      vote[Table_Vote_Date.User_ID_num] = Constants.UnCheck;
      if (new_vote_date) { // Add new vote.
        new Vote_Date_AsyncTask_insert(context).execute(vote);
      } else { // Update vote date.
        if (!vote_date_helper_tmp.getStart_Date().equals(vote_date_helper.getStart_Date())
            || !vote_date_helper_tmp.getEnd_Date().equals(vote_date_helper.getEnd_Date())
            || !vote_date_helper_tmp.getAll_Day().equals(vote_date_helper.getAll_Day())
            || !vote_date_helper_tmp.getStart_Time().equals(vote_date_helper.getStart_Time())
            || !vote_date_helper_tmp.getEnd_Time().equals(vote_date_helper.getStart_Time())) {
          // reset the votes users.
          new Vote_Date_AsyncTask_deleteByVote_ID(context).execute(Event_ID, vote_id + "");
          new Vote_Date_AsyncTask_insert(context).execute(vote);
        }
      }
    }
    // Delete Vote_date.
    for (int vote_id : Event_Helper.vote_date.keySet()) {
      vote_date_helper = Event_Helper.vote_date.get(vote_id);
      if (Event_Helper.vote_date_tmp.get(vote_id) == null) {
        new Vote_Date_AsyncTask_deleteByVote_ID(context).execute(Event_ID, vote_id + "");
      }
    }

    // Update Vote_location.
    // Update vote will reset the votes users.
    boolean new_vote_location;
    Vote_Location_Helper vote_location_helper_tmp;
    Vote_Location_Helper vote_location_helper;
    for (int vote_id : Event_Helper.vote_location_tmp.keySet()) {
      vote_location_helper_tmp = Event_Helper.vote_location_tmp.get(vote_id);
      vote_location_helper = Event_Helper.vote_location.get(vote_id);
      new_vote_location = vote_location_helper == null;
      String[] vote = new String[Table_Vote_Location.Size()];
      vote[Table_Vote_Location.Event_ID_num] = Event_ID;
      vote[Table_Vote_Location.Vote_ID_num] = vote_id + "";
      vote[Table_Vote_Location.Description_num] = vote_location_helper_tmp.getDescription();
      vote[Table_Vote_Location.User_ID_num] = Constants.UnCheck;
      if (new_vote_location) { // Add new vote.
        new Vote_Location_AsyncTask_insert(context).execute(vote);
      } else { // Update vote date.
        if (!vote_location_helper_tmp
            .getDescription()
            .equals(vote_location_helper.getDescription())) {
          // reset the votes users.
          new Vote_Location_AsyncTask_deleteByVote_ID(context).execute(Event_ID, vote_id + "");
          new Vote_Location_AsyncTask_insert(context).execute(vote);
        }
      }
    }
    // Delete Vote_location.
    for (int vote_id : Event_Helper.vote_location.keySet()) {
      vote_location_helper = Event_Helper.vote_location.get(vote_id);
      if (Event_Helper.vote_location_tmp.get(vote_id) == null) {
        update_section[vote_location_num] = Constants.Yes;
        sqlHelper.delete(
            Table_Vote_Location.Table_Name,
            new String[] {Table_Vote_Location.Event_ID, Table_Vote_Location.Vote_ID},
            new String[] {Event_ID, vote_id + ""},
            null);
      }
    }
  }
Exemplo n.º 3
0
  // ----------------------------------------------Server SQL
  // Functions----------------------------------------------
  public static void Create_Event_ServerSQL(Context context) {
    // new Event_AsyncTask_insert(context).execute(Event_ID, Name, Location, Start_Date, Start_Time,
    // End_Date, End_Time, Description, ImagePath, Update_Time);

    // create event.
    new Event_AsyncTask_insert(context).execute(Event_Helper.details);
    // Add My user.
    new EventUser_AsyncTask_insert(context)
        .execute(
            Event_Helper.details[Table_Events.Event_ID_num],
            Constants.MY_User_ID,
            Constants.Yes,
            Constants.Owner);
    // Add all friends.
    for (String User_ID : Event_Helper.friends.keySet()) {
      Friend_Helper friend_helper = Event_Helper.friends.get(User_ID);
      new EventUser_AsyncTask_insert(context)
          .execute(
              Event_Helper.details[Table_Events.Event_ID_num],
              User_ID,
              friend_helper.getAttending(),
              friend_helper.getPermission());
    }
    // Add tasks
    for (int task_id : Event_Helper.task.keySet()) {
      Task_Helper task_helper = Event_Helper.task.get(task_id);
      new Task_AsyncTask_insert(context)
          .execute(
              Event_Helper.details[Table_Events.Event_ID_num],
              task_id + "",
              0 + "",
              task_helper.getType(),
              task_helper.getDescription(),
              task_helper.getUser_ID());
      // Add all subTasks.
      for (int subTask_id : task_helper.getSubTasks().keySet()) {
        new Task_AsyncTask_insert(context)
            .execute(
                Event_Helper.details[Table_Events.Event_ID_num],
                task_id + "",
                subTask_id + "",
                task_helper.getType(),
                task_helper.getSubTasks().get(subTask_id)[0],
                task_helper.getUser_ID());
      }
    }
    // Create Chat table.
    String Chat_ID =
        Table_Chat.Table_Name
            + Helper.Clean_Event_ID(Event_Helper.details[Table_Events.Event_ID_num]);
    new Chat_AsyncTask_CreateByEvent(context).execute(Chat_ID);
    // Add vote_dates.
    for (int vote_id : Event_Helper.vote_date.keySet()) {
      Vote_Date_Helper vote_date_helper = Event_Helper.vote_date.get(vote_id);
      new Vote_Date_AsyncTask_insert(context)
          .execute(
              Event_Helper.details[Table_Events.Event_ID_num],
              vote_id + "",
              vote_date_helper.getStart_Date(),
              vote_date_helper.getEnd_Date(),
              vote_date_helper.getAll_Day(),
              vote_date_helper.getStart_Time(),
              vote_date_helper.getEnd_Time(),
              Constants.UnCheck);
    }
    // Add vote_dates.
    for (int vote_id : Event_Helper.vote_location.keySet()) {
      Vote_Location_Helper vote_location_helper = Event_Helper.vote_location.get(vote_id);
      new Vote_Location_AsyncTask_insert(context)
          .execute(
              Event_Helper.details[Table_Events.Event_ID_num],
              vote_id + "",
              vote_location_helper.getDescription(),
              Constants.UnCheck);
    }
  }
Exemplo n.º 4
0
  private static void Update_Event_MySQL(String Event_ID) {
    Update_Users = new ArrayList<>();
    update_section =
        new String[] {Constants.Yes, Constants.No, Constants.No, Constants.No, Constants.No};
    // Update event (delete and then insert).
    sqlHelper.delete(
        Table_Events.Table_Name,
        new String[] {Table_Events.Event_ID},
        new String[] {Event_ID},
        new int[] {1});
    sqlHelper.insert(Table_Events.Table_Name, Event_Helper.details);
    // Update Friends list invention.
    Friend_Helper friend_helper;
    for (String User_ID : Event_Helper.friends_tmp.keySet()) {
      friend_helper = Event_Helper.friends_tmp.get(User_ID);
      if (Event_Helper.friends.get(User_ID) == null) { // Add new friends.
        update_section[users_num] = Constants.Yes;
        add_newFriend_MySQL(friend_helper, User_ID);
        Update_Users.add(new String[] {User_ID, Constants.New_Event});
      } else { // Change permission.
        if (!User_ID.equals(Constants.MY_User_ID)) // No need to send update message to myself.
        Update_Users.add(new String[] {User_ID, Constants.Update_Event});
        if (!friend_helper
            .getPermission()
            .equals(Event_Helper.friends.get(User_ID).getPermission())) {
          update_section[users_num] = Constants.Yes;
          sqlHelper.update(
              Table_Events_Users.Table_Name,
              new String[] {Table_Events_Users.Permission},
              new String[] {friend_helper.getPermission()},
              new String[] {Table_Events_Users.Event_ID, Table_Events_Users.User_ID},
              new String[] {Event_ID, User_ID});
        }
      }
    }
    // Delete friends.
    for (String User_ID : Event_Helper.friends.keySet()) {
      if (Event_Helper.friends_tmp.get(User_ID) == null) {
        update_section[users_num] = Constants.Yes;
        Update_Users.add(new String[] {User_ID, Constants.Delete_Event});
        sqlHelper.delete(
            Table_Events_Users.Table_Name,
            new String[] {Table_Events_Users.Event_ID, Table_Events_Users.User_ID},
            new String[] {Event_Helper.details[Table_Events.Event_ID_num], User_ID},
            new int[] {1});
      }
    }
    // Update Tasks.
    boolean new_task, new_subTask;
    Task_Helper task_helper;
    for (int task_id : Event_Helper.task_tmp.keySet()) {
      task_helper = Event_Helper.task_tmp.get(task_id);
      new_task = Event_Helper.task.get(task_id) == null;
      if (new_task) { // Add new tasks.
        update_section[tasks_num] = Constants.Yes;
        add_newTask_MySQL(task_helper, task_id, 0);
      } else { // Update task description.
        if (!task_helper.getDescription().equals(Event_Helper.task.get(task_id).getDescription())) {
          update_section[tasks_num] = Constants.Yes;
          sqlHelper.update(
              Table_Tasks.Table_Name,
              new String[] {Table_Tasks.Description},
              new String[] {task_helper.getDescription()},
              new String[] {
                Table_Tasks.Event_ID, Table_Tasks.Task_ID_Number, Table_Tasks.subTask_ID_Number
              },
              new String[] {Event_ID, task_id + "", 0 + ""});
        }
      }
      for (int subTask_id : task_helper.getSubTasks().keySet()) {
        new_subTask =
            (new_task || Event_Helper.task.get(task_id).getSubTasks().get(subTask_id) == null);
        if (new_subTask) { // Add new subTasks.
          update_section[tasks_num] = Constants.Yes;
          add_newTask_MySQL(task_helper, task_id, subTask_id);
        } else { // Update subTask description.
          if (!task_helper
              .getSubTasks()
              .get(subTask_id)[0]
              .equals(Event_Helper.task.get(task_id).getSubTasks().get(subTask_id)[0])) {
            update_section[tasks_num] = Constants.Yes;
            sqlHelper.update(
                Table_Tasks.Table_Name,
                new String[] {Table_Tasks.Description},
                new String[] {task_helper.getSubTasks().get(subTask_id)[0]},
                new String[] {
                  Table_Tasks.Event_ID, Table_Tasks.Task_ID_Number, Table_Tasks.subTask_ID_Number
                },
                new String[] {Event_ID, task_id + "", subTask_id + ""});
          }
        }
      }
    }
    // Delete Tasks.
    for (int task_id : Event_Helper.task.keySet()) {
      task_helper = Event_Helper.task.get(task_id);
      if (Event_Helper.task_tmp.get(task_id) == null) {
        update_section[tasks_num] = Constants.Yes;
        sqlHelper.delete(
            Table_Tasks.Table_Name,
            new String[] {Table_Tasks.Event_ID, Table_Tasks.Task_ID_Number},
            new String[] {Event_Helper.details[Table_Events.Event_ID_num], task_id + ""},
            null);
      } else {
        for (int subTask_id : task_helper.getSubTasks().keySet()) {
          if (Event_Helper.task_tmp.get(task_id).getSubTasks().get(subTask_id) == null) {
            update_section[tasks_num] = Constants.Yes;
            sqlHelper.delete(
                Table_Tasks.Table_Name,
                new String[] {
                  Table_Tasks.Event_ID, Table_Tasks.Task_ID_Number, Table_Tasks.subTask_ID_Number
                },
                new String[] {
                  Event_Helper.details[Table_Events.Event_ID_num], task_id + "", subTask_id + ""
                },
                null);
          }
        }
      }
    }
    // Update Vote_date.
    // Update vote will reset the votes users.
    boolean new_vote_date;
    Vote_Date_Helper vote_date_helper_tmp;
    Vote_Date_Helper vote_date_helper;
    for (int vote_id : Event_Helper.vote_date_tmp.keySet()) {
      vote_date_helper_tmp = Event_Helper.vote_date_tmp.get(vote_id);
      vote_date_helper = Event_Helper.vote_date.get(vote_id);
      new_vote_date = vote_date_helper == null;
      if (new_vote_date) { // Add new vote.
        update_section[vote_date_num] = Constants.Yes;
        add_newVote_Date_Option_MySQL(vote_date_helper_tmp, vote_id);
      } else { // Update vote date.
        if (!vote_date_helper_tmp.getStart_Date().equals(vote_date_helper.getStart_Date())
            || !vote_date_helper_tmp.getEnd_Date().equals(vote_date_helper.getEnd_Date())
            || !vote_date_helper_tmp.getAll_Day().equals(vote_date_helper.getAll_Day())
            || !vote_date_helper_tmp.getStart_Time().equals(vote_date_helper.getStart_Time())
            || !vote_date_helper_tmp.getEnd_Time().equals(vote_date_helper.getStart_Time())) {
          update_section[vote_date_num] = Constants.Yes;
          // reset the votes users.
          sqlHelper.delete(
              Table_Vote_Date.Table_Name,
              new String[] {Table_Vote_Date.Event_ID, Table_Vote_Date.Vote_ID},
              new String[] {Event_ID, vote_id + ""},
              null);
          add_newVote_Date_Option_MySQL(vote_date_helper_tmp, vote_id);
        }
      }
    }
    // Delete Vote_date.
    for (int vote_id : Event_Helper.vote_date.keySet()) {
      vote_date_helper = Event_Helper.vote_date.get(vote_id);
      if (Event_Helper.vote_date_tmp.get(vote_id) == null) {
        update_section[vote_date_num] = Constants.Yes;
        sqlHelper.delete(
            Table_Vote_Date.Table_Name,
            new String[] {Table_Vote_Date.Event_ID, Table_Vote_Date.Vote_ID},
            new String[] {Event_ID, vote_id + ""},
            null);
      }
    }

    // Update Vote_location.
    // Update vote will reset the votes users.
    boolean new_vote_location;
    Vote_Location_Helper vote_location_helper_tmp;
    Vote_Location_Helper vote_location_helper;
    for (int vote_id : Event_Helper.vote_location_tmp.keySet()) {
      vote_location_helper_tmp = Event_Helper.vote_location_tmp.get(vote_id);
      vote_location_helper = Event_Helper.vote_location.get(vote_id);
      new_vote_location = vote_location_helper == null;
      if (new_vote_location) { // Add new vote.
        update_section[vote_location_num] = Constants.Yes;
        add_newVote_Location_Option_MySQL(vote_location_helper_tmp, vote_id);
      } else { // Update vote date.
        if (!vote_location_helper_tmp
            .getDescription()
            .equals(vote_location_helper.getDescription())) {
          update_section[vote_location_num] = Constants.Yes;
          // reset the votes users.
          sqlHelper.delete(
              Table_Vote_Location.Table_Name,
              new String[] {Table_Vote_Location.Event_ID, Table_Vote_Location.Vote_ID},
              new String[] {Event_ID, vote_id + ""},
              null);
          add_newVote_Location_Option_MySQL(vote_location_helper_tmp, vote_id);
        }
      }
    }
    // Delete Vote_location.
    for (int vote_id : Event_Helper.vote_location.keySet()) {
      vote_location_helper = Event_Helper.vote_location.get(vote_id);
      if (Event_Helper.vote_location_tmp.get(vote_id) == null) {
        update_section[vote_location_num] = Constants.Yes;
        sqlHelper.delete(
            Table_Vote_Location.Table_Name,
            new String[] {Table_Vote_Location.Event_ID, Table_Vote_Location.Vote_ID},
            new String[] {Event_ID, vote_id + ""},
            null);
      }
    }
  }