Example #1
0
        public static void saveBoard(BoardStruct board)
        {
            boards.Add(board);
            Stream stream = File.OpenWrite(BoardFilePath);

            stream.Position = stream.Length;
            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(stream, board);
            stream.Close();
        }
Example #2
0
        public static void saveBoard(BoardStruct board)
        {
            SQLiteCommand command = new SQLiteCommand();

            try
            {
                DAL.OpenConnect();
                command             = new SQLiteCommand(null, DAL.connection);
                command.CommandText = "INSERT INTO Boards(Bid, TotalLimit, Name)  " +
                                      " VALUES (@Board_id, @Board_TotalLimit, @Board_Name )";
                SQLiteParameter boardID    = new SQLiteParameter("@Board_id", board.Id);
                SQLiteParameter boardLimit = new SQLiteParameter("@Board_TotalLimit", board.totalLimit);
                SQLiteParameter boardName  = new SQLiteParameter("@Board_Name", board.ProjectName);
                command.Parameters.Add(boardID);
                command.Parameters.Add(boardLimit);
                command.Parameters.Add(boardName);
                command.Prepare();
                try
                {
                    int changes = command.ExecuteNonQuery();
                }
                catch (SQLiteException e)
                {
                    if (e.Message.Contains("database is locked"))
                    {
                        AlmogException unicorn = new AlmogException();

                        unicorn.Value = new List <String>()
                        {
                            "DB locked. please try again later"
                        };
                        throw unicorn;
                    }
                    else
                    {
                        throw e;
                    }
                }
                command.Dispose();
                DAL.CloseConnect();
                Logger.Log.Info("saved new board with id: " + board.Id + "; name: '" + board.ProjectName + "'; limit: " + board.totalLimit);
            }
            catch (SQLiteException e)
            {
                Logger.Log.Fatal("sql exception when saving new board with id: " + board.Id + "\n error: " + e.Message);
                command.Dispose();
                DAL.CloseConnect();
            }
        }
Example #3
0
        public static void load()
        {
            boards = new List <BoardStruct>();
            if (!File.Exists(BoardFilePath))
            {
                Stream s = File.Create(BoardFilePath);
                s.Close();
            }

            Stream          stream    = File.OpenRead(BoardFilePath);
            BinaryFormatter formatter = new BinaryFormatter();

            while (stream.Position < stream.Length)
            {
                BoardStruct currentBoard = (BoardStruct)formatter.Deserialize(stream);
                boards.Add(currentBoard);
            }
            stream.Close();
        }
Example #4
0
        public static void delete(int Id)
        {
            BoardStruct taskToRemove = new BoardStruct();

            foreach (var item in boards)
            {
                if (item.Id == Id)
                {
                    taskToRemove = item;
                }
            }
            boards.Remove(taskToRemove);
            Stream          stream    = File.Create(BoardFilePath);
            BinaryFormatter formatter = new BinaryFormatter();

            foreach (var item in boards)
            {
                formatter.Serialize(stream, item);
            }
            stream.Close();
        }
Example #5
0
        public static void updateBoard(BoardStruct board)
        {
            BoardStruct boardToUpdate = new BoardStruct();

            foreach (var item in boards)
            {
                if (item.Id == board.Id)
                {
                    boardToUpdate = item;
                }
            }
            boards.Remove(boardToUpdate);
            boards.Add(board);
            Stream          stream    = File.Create(BoardFilePath);
            BinaryFormatter formatter = new BinaryFormatter();

            foreach (var item in boards)
            {
                formatter.Serialize(stream, item);
            }
            stream.Close();
        }
Example #6
0
        public static BoardStruct getBoard(int id)
        {
            BoardStruct      ans     = new BoardStruct();
            SQLiteCommand    command = new SQLiteCommand();
            SQLiteDataReader reader  = null;

            try
            {
                List <ColumnStruct> list = ColumnDAL.getByBoard(id);
                DAL.OpenConnect();

                command             = new SQLiteCommand(null, DAL.connection);
                command.CommandText = "SELECT * FROM Boards WHERE Bid = " + id;
                command.Prepare();
                reader = command.ExecuteReader();
                //string ans = "";
                while (reader.Read())
                {
                    int limit = int.Parse("" + reader["TotalLimit"]);

                    ans = new BoardStruct(id, "" + reader["Name"], list, limit);
                    //ans += "id: " + reader["Bid"] + "; limit: " + reader["TotalLimit"] + "; name" + reader["Name"] + "/n";
                }
                command.Dispose();
                reader.Close();
                DAL.CloseConnect();
            }
            catch (SQLiteException e)
            {
                Logger.Log.Fatal("sql exception when retriving board with id: " + id + "\n error: " + e.Message);
                if (reader != null)
                {
                    reader.Close();
                }
                command.Dispose();
                DAL.CloseConnect();
            }
            return(ans);
        }