Example #1
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);
        }
Example #2
0
        public static int deleteBoard(int boardId)
        {
            SQLiteCommand command = new SQLiteCommand();

            try
            {
                ColumnDAL.deleteColumnOfBoard(boardId);
                DAL.OpenConnect();
                command             = new SQLiteCommand(null, DAL.connection);
                command.CommandText = "DELETE FROM Boards " + " WHERE (Bid = @boardId) ";

                SQLiteParameter BID = new SQLiteParameter("@boardId", boardId);

                command.Parameters.Add(BID);
                command.Prepare();
                int changes = command.ExecuteNonQuery();
                command.Dispose();
                DAL.CloseConnect();
                if (changes == 0)
                {
                    Logger.Log.Error("faild to delete board with id: " + boardId + " since it does not exist");
                }
                else
                {
                    Logger.Log.Info("deleted board with id: " + boardId);
                }
                return(changes);
            }
            catch (SQLiteException e)
            {
                Logger.Log.Fatal("sql exception from deleting board with id: " + boardId + "/n" + e.Message);
                command.Dispose();
                DAL.CloseConnect();
                return(0);
            }
        }