ftp.nice.ch/Attic/openStep/developer/examples/DevelopingBusinessApps.m.NIS.bs.tgz#/DevelopingBusinessApps.m.NIS.bs/PayPerView-EOF/OrderController.m

This is OrderController.m in view mode; [Download] [Up]

#import "OrderController.h"


@implementation OrderController

- (void)prepareOrder:(id)sender
{
    int result;

    [buyerNameField setStringValue:@""];
    [creditCardField setStringValue:@""];

    result = [NSApp runModalForWindow:orderPanel];
    switch (result) {
        case NSRunStoppedResponse:
            [self confirmOrder];
            break;
        case NSRunAbortedResponse:
            [self cancelOrder];
            break;
    }
    return;
}


- (void)cancelClicked:(id)sender
{
    [orderPanel orderOut:nil];
    [NSApp abortModal];
    return;
}

- (void)okClicked:(id)sender
{
    if (![self verifyCreditCard]) return;
    [orderPanel orderOut:nil];
    [NSApp stopModal];
    return;
}

- (void)cancelOrder
{
    NSString *status = [NSString
        stringWithFormat:@"Order for %@ was cancelled\n",
        [orderTitleField stringValue]];

    NSRunAlertPanel(@"Order Canceled", status, nil, nil, nil);
    return;
}

- (void)confirmOrder
{
    NSString *status = [NSString
        stringWithFormat: @"%@ ordered %@ using card #%@\n",
        [buyerNameField stringValue],
        [orderTitleField stringValue],
        [creditCardField stringValue]];

    NSRunAlertPanel(@"Order Placed", status, nil, nil, nil);
    return;
}

- (BOOL)verifyCreditCard
{
    if ([[buyerNameField stringValue] isEqual:@""]) {
        NSRunAlertPanel(@"No Customer Name",
            @"You must enter a customer's name.",
            nil, nil, nil);
        return NO;
    }

    if ([[creditCardField stringValue] isEqual:@""]) {
        NSRunAlertPanel(@"Invalid Card",
            @"Invalid credit card number for %@.",
            nil, nil, nil, [buyerNameField stringValue]);
        return NO;
    }

    return YES;
}

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.