unit AddBound;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, 
  Buttons, ExtCtrls, Grids, ComCtrls, Dialogs, MyDates, Arrays;

type
  TAddBoundDlg = class(TForm)
    OKBtn: TButton;
    CancelBtn: TButton;
    BoundDate: TDateTimePicker;
    Label1: TLabel;
    StringGrid1: TStringGrid;
    procedure OKBtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    RowInfo : TStrings;
    BoundDates : TMyArrayOfLongint;

    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

var
  AddBoundDlg: TAddBoundDlg;

implementation

{$R *.DFM}
{$RANGECHECKS OFF}

//----------------------------------------------------
constructor TAddBoundDlg.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);
    with StringGrid1 do begin
      Cells[0,0] := 'Upper Soil';
      Cells[1,0] := 'Lower Soil';
      Cells[2,0] := 'Ground';
      Cells[3,0] := 'Surface';
      Cells[4,0] := 'Snowpack';
    end;
    BoundDates := TMyArrayOfLongint.Create;
    BoundDate.Date := Now();
end;

//----------------------------------------------------
destructor TAddBoundDlg.Destroy;
begin
   BoundDates.Free;
   inherited Destroy;
end;


//----------------------------------------------------
procedure TAddBoundDlg.OKBtnClick(Sender: TObject);
var
   J          : integer;
   Seq1, Seq2 : longint;
   SameDate   : boolean;
   Answer     : word;
begin
   //
   // Compute sequence number for the specified date
   //
   Seq1 := DelphiDateToMyDate(BoundDate.Date);

   //
   // Do we already have an entry for that date?
   //
   SameDate := FALSE;
   for J:=0 to BoundDates.GetSize-1 do begin
       Seq2 := BoundDates[J];
       if (Seq1 = Seq2) then begin
          SameDate := TRUE;
       end;
   end;

   if (not SameDate) then begin
      ModalResult := mrOk;
      exit;
   end;

   Answer := MessageDlg('Overwrite existing entry on that day?', mtConfirmation,
                        [mbYes, mbNo, mbCancel], 0);
   if (Answer = mrYes) then ModalResult := mrOk;
   if (Answer = mrCancel) then ModalResult := mrNo;
end;


end.
