//this function moves the colum one index forward
        public InfoObject moveColumn(int columnNumber, string email)
        {
            InfoObject info;

            if (columnNumber == getColumns().Count)
            {
                info = new InfoObject(false, "You can't move the last column");
                Log.Error("You can't move the last column");
            }
            else if (columnNumber > getColumns().Count)
            {
                info = new InfoObject(false, "You selected illegal column");
                Log.Error("You selected illegal column");
            }
            else
            {
                Column Forward = (Column)getColumns()[columnNumber];
                Forward.setLocation(Forward.getLocation() + 1);
                DataLayerColumn2.save(Forward.getName(), Forward.getColumnMaxTasks(), email, Forward.getLocation(), boardName);
                Column Backwards = (Column)getColumns()[columnNumber + 1];
                Backwards.setLocation(Backwards.getLocation() - 1);
                DataLayerColumn2.save(Backwards.getName(), Backwards.getColumnMaxTasks(), email, Backwards.getLocation(), boardName);
                Forward.updateTaskHash(columnNumber + 1);
                Backwards.updateTaskHash(columnNumber);
                getColumns().Remove(columnNumber);
                getColumns().Remove(columnNumber + 1);
                getColumns().Add(columnNumber, Backwards);
                getColumns().Add(columnNumber + 1, Forward);
                info = new InfoObject(true, "the column #" + columnNumber + " moved forward");
                Log.Info("Column #" + columnNumber + " moved forward");
            }
            return(info);
        }
        //this function removing a column from the board
        public InfoObject removeColumn(String email, String columnName)
        {
            InfoObject info;

            for (int i = 1; i <= columnsHashTable.Count; i = i + 1)
            {
                Column column = (Column)columnsHashTable[i];
                if (column.getName() == columnName)
                {
                    if (column.isPossibleToRemove().getIsSucceeded())
                    {
                        Log.Info("column #" + i + " has been removed");
                        info = new InfoObject(true, "column #" + i + " has been removed");
                        this.currColumnCount--;
                        getColumns().Remove(i);
                        updateColumnHash(i + 1, email);
                        DataLayerColumn2.deleteColumn(email, columnName, boardName);
                        return(info);
                    }
                    else
                    {
                        Log.Warn("column #" + i + " has not been removed");
                        info = new InfoObject(false, "column #" + i + " has not been removed");
                        return(info);
                    }
                }
            }
            Log.Warn("column " + columnName + " can't be found");
            info = new InfoObject(false, "column " + columnName + " can't be found");
            return(info);
        }
 public void updateColumnHash(int index, string email)
 {
     for (int i = index; i <= currColumnCount; i = i + 1)
     {
         Column column = (Column)columnsHashTable[i];
         if (column != null)
         {
             column.setLocation(column.getLocation() - 1);
             column.updateTaskHash();
             DataLayerColumn2.save(column.getName(), column.getColumnMaxTasks(), email, column.getLocation(), boardName);
             getColumns().Add(i - 1, column);
             getColumns().Remove(i);
         }
     }
     currColumnCount = currColumnCount - 1;
 }
        // this function collet all the tasks from data and forward to the specific column they belong to.
        public int open(string author)
        {
            int numberOfColumns = 1;

            columnsHashTable     = new Hashtable();
            this.currColumnCount = 0;
            //string columnID;
            //string[] splited = existingColumns.Split('+');
            //for (int i = 0; i < splited.Length; i = i + 1)
            //{
            //    if (!splited[i].Equals(""))
            //    {
            //        columnID = splited[i];
            LinkedList <ColumnD> ListcolumnD = DataLayerColumn2.Open(author, boardName);

            foreach (ColumnD columnD in ListcolumnD)
            {
                if (columnD != null)
                {
                    Column column = new Column(columnD.getName(), this.boardName);
                    column.setLocation(columnD.getLocation());
                    column.setMAX_TASKS(author, columnD.getMaxCapacity());
                    columnsHashTable.Add(numberOfColumns, column);
                    this.currColumnCount = this.currColumnCount + 1;
                    numberOfColumns      = numberOfColumns + 1;
                    Log.Info("Column " + column.getName() + " loaded successfully from the database.");
                }
            }
            //    }
            //}
            int numberOfTasksAdded       = 0;
            LinkedList <TaskD> listTaskD = DataLayerTask2.Open(author, boardName);

            foreach (TaskD taskD in listTaskD)
            //TaskD taskD = DataLayerTask2.Open(numberOfTasksAdded, author, boardName);
            //while (taskD != null)
            {
                Column column = (Column)columnsHashTable[taskD.getStatus()];
                column.addTask(taskD.getTitle(), taskD.getDescription(), taskD.getStatus(), taskD.getDueDate(), taskD.getCreationTime(), taskD.getAuthor(), taskD.getTaskUID());
                Log.Info("Task #" + numberOfTasksAdded + " loaded successfully from the database.");
                numberOfTasksAdded++;
                //taskD = DataLayerTask2.Open(numberOfTasksAdded, author, boardName);
            }
            return(numberOfTasksAdded);
        }
        // this function sets the MAX_TASKS field
        public InfoObject setMAX_TASKS(string author, int newMAX_TASKS)
        {
            InfoObject info;

            if (getCurrentTaskCount() > newMAX_TASKS)
            {
                Log.Warn("The capacity of column " + getName() + " cant be changed to: " + newMAX_TASKS + ", beacuse there are more tasks than the new capacity number");
                info = new InfoObject(false, "The capacity of column " + getName() + " cant be changed to: " + newMAX_TASKS + ", beacuse there are more tasks than the new capacity number");
                return(info);
            }
            else
            {
                this.MAX_TASKS = newMAX_TASKS;
                DataLayerColumn2.save(getName(), newMAX_TASKS, author, getLocation(), boardName);
                Log.Info("The capacity of column " + COLUMN_NAME + " changed to: " + newMAX_TASKS);
                info = new InfoObject(true, "The capacity of column " + COLUMN_NAME + " changed to: " + newMAX_TASKS);
                return(info);
            }
        }
        // this function create a new coulmn and adds it to the Hash table that containes all the columns.
        public InfoObject addColumn(string author, string name)
        {
            InfoObject info;

            if (name != null)
            {
                Column column = new Column(name, this.boardName);
                this.currColumnCount++;
                column.setLocation(getCurrColumnCount());
                columnsHashTable.Add(columnsHashTable.Count + 1, column);
                DataLayerColumn2.save(name, int.MaxValue, author, column.getLocation(), boardName);
                Log.Info("A new Column named " + name + " added. The new column saved as column #" + this.currColumnCount);
                info = new InfoObject(true, "A new Column named " + name + " added. The new column saved as column number #" + this.currColumnCount);
                return(info);
            }
            else
            {
                Log.Warn("The input name is null");
                info = new InfoObject(false, "The input name is null");
                return(info);
            }
        }
        // this function changes the maximum capacity of a coulmn by updatinig the Max_Tasks field in column class
        public InfoObject changeColumnCapacity(string author, int columnNumber, int capacity)
        {
            InfoObject info;

            if (columnNumber <= columnsHashTable.Count)
            {
                Column column = (Column)columnsHashTable[columnNumber];

                if (columnNumber != columnsHashTable.Count)
                {
                    string name = column.getName();
                    info = column.setMAX_TASKS(author, capacity);
                    if (info.getIsSucceeded())
                    {
                        DataLayerColumn2.save(name, capacity, author, column.getLocation(), boardName);
                        return(info);
                    }
                    else
                    {
                        return(info);
                    }
                }
                else
                {
                    Log.Warn("Cant change Capacity of the last coulmn");
                    info = new InfoObject(false, "Cant change the capacity of the last column");
                    return(info);
                }
            }
            else
            {
                Log.Error("You're trying to change the capacity of an illegal column.");
                info = new InfoObject(false, "You're trying to change the capacity of an illegal column.");
                return(info);
            }
        }