Click here to Skip to main content
15,895,656 members
Home / Discussions / C#
   

C#

 
QuestionDatasets / SQL [modified] Pin
CrimeanTurtle200813-Jan-09 13:42
CrimeanTurtle200813-Jan-09 13:42 
AnswerRe: Datasets / SQL Pin
leckey13-Jan-09 14:36
leckey13-Jan-09 14:36 
QuestionAutoresize column width in owner drawn ListView [modified] Pin
CodeBerserker13-Jan-09 12:30
CodeBerserker13-Jan-09 12:30 
QuestionNumber Vaildation Pin
tswright104113-Jan-09 12:26
tswright104113-Jan-09 12:26 
AnswerRe: Number Vaildation Pin
EliottA13-Jan-09 12:38
EliottA13-Jan-09 12:38 
AnswerRe: Number Vaildation Pin
RyanEK13-Jan-09 14:03
RyanEK13-Jan-09 14:03 
AnswerRe: Number Vaildation Pin
PIEBALDconsult13-Jan-09 14:18
mvePIEBALDconsult13-Jan-09 14:18 
AnswerRe: Number Vaildation [modified] Pin
Jon Rista13-Jan-09 14:36
Jon Rista13-Jan-09 14:36 
Technically speaking, what your asking about is an algorithm. If you think about it purely analytically, you basically have these rules (I assume, I could have interperated your question incorrectly):

Available Rows: A - P
Available Seats: 1 - 18

Rule: Row between A and H, Seat geater than 15 = invalid
Rule: One assignment per Row/Seat combination

If your creating a booking system, the ultimate result of a booking is that you track which row/seat is assigned somewhere (in my example, a dictionary mapping a key(the row) to a list of ints (the seats):

class TheaterBooking
{
    const char MAX_ROW = 'P';
    const int MAX_SEAT = 18;

    IDictionary<char,IList<int>> m_bookedSeats;

    public TheaterBooking()
    {
        m_bookedSeats = new Dictionary<char,IList<int>>();
    }

    public bool IsValidNewBooking(char row, int seat)
    {
        if (row > MAX_ROW) throw new ArgumentException("Invalid row specified.", row);
        if (seat > MAX_SEAT) throw new ArgumentException("Invalid seat number specified.", seat);

        if (!IsValidSeat(row, seat))
            return false;

        if (IsAlreadyBooked(row, seat))
            return false;
        
        return true;  // The seat is valid for the row, and it is not already booked, so it is a valid new booking
    }

    private bool IsValidSeat(char row, int seat)
    {
        if (row <= 'H' && seat > 15)
            return false;
        return true;
    }

    private bool IsAlreadyBooked(char row, int seat)
    {
        IList<int> filledSeats;
        if (m_bookedSeats.TryGetValue(row, out filledSeats))
        {
            if (filledSeats.Contains(seat)) // This checks if row/seat is already booked
                return false;
        }

        return true;
    }
}


modified on Tuesday, January 13, 2009 8:44 PM

GeneralRe: Number Vaildation Pin
tswright104114-Jan-09 3:37
tswright104114-Jan-09 3:37 
GeneralRe: Number Vaildation Pin
Jon Rista14-Jan-09 12:05
Jon Rista14-Jan-09 12:05 
QuestionInternet Explorer running an application by file association Pin
bfrank197213-Jan-09 7:29
bfrank197213-Jan-09 7:29 
AnswerRe: Internet Explorer running an application by file association Pin
DaveyM6913-Jan-09 9:32
professionalDaveyM6913-Jan-09 9:32 
GeneralRe: Internet Explorer running an application by file association Pin
bfrank197213-Jan-09 13:58
bfrank197213-Jan-09 13:58 
QuestionReg: Pin
satsumatable13-Jan-09 7:01
satsumatable13-Jan-09 7:01 
AnswerRe: Reg: Pin
dan!sh 13-Jan-09 7:05
professional dan!sh 13-Jan-09 7:05 
GeneralRe: Reg: Pin
bfrank197213-Jan-09 14:00
bfrank197213-Jan-09 14:00 
AnswerRe: Reg: Pin
Verghese13-Jan-09 8:12
Verghese13-Jan-09 8:12 
GeneralRe: Reg: Pin
bfrank197213-Jan-09 14:03
bfrank197213-Jan-09 14:03 
QuestionDo not allow taskmanager to close my app Pin
spiritboy13-Jan-09 6:55
spiritboy13-Jan-09 6:55 
AnswerRe: Do not allow taskmanager to close my app Pin
EliottA13-Jan-09 6:58
EliottA13-Jan-09 6:58 
GeneralRe: Do not allow taskmanager to close my app Pin
spiritboy13-Jan-09 7:06
spiritboy13-Jan-09 7:06 
GeneralRe: Do not allow taskmanager to close my app Pin
Not Active13-Jan-09 7:08
mentorNot Active13-Jan-09 7:08 
GeneralRe: Do not allow taskmanager to close my app Pin
spiritboy13-Jan-09 7:13
spiritboy13-Jan-09 7:13 
GeneralRe: Do not allow taskmanager to close my app Pin
EliottA13-Jan-09 7:24
EliottA13-Jan-09 7:24 
GeneralRe: Do not allow taskmanager to close my app Pin
#realJSOP13-Jan-09 7:53
mve#realJSOP13-Jan-09 7:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.