// ownview.prg
//
//
#INCLUDE "FIVEWIN.CH"
//-------------------------------
FUNC _OwnView( cMode,oWndMain,oFontB )
LOCAL SAYING, oWndChild, oGrps, oRsOwn, cSQL, oERR, oIco
LOCAL cTITLE, oBTN1, oBTN2
Local lOk,lClosed,oBmp
Local oOwner,oAddress1,oAddress2,oCity,oState,oZip,oContact,oPhone,oDivision
Local cOwner,cAddress1,cAddress2,cCity,cState,cZip,cContact,cPhone,cDivision
Local oSay1,oSay2,oSay3,oSay4,oSay5,oSay6,oSay7,oSay8,oSay9,oSay10
Local cLast,oLast,oFein,cFein
lCLOSED := .F. // trap valid
IF xSUPER = 'Y' .or. xAdmin = "Y"
ELSE
Saying := "Sorry .. Supervisor Rights needed here"+chr(10)
Saying += "You have Insufficients Permissions"+chr(10)
MsgInfo( SAYING )
RETURN(.F.)
ENDIF
LightGreyGrad()
oRsOwn := TOleAuto():New( "ADODB.Recordset" )
oRsOwn:CursorType := 1 // opendkeyset
oRsOwn:CursorLocation := 3 // local cache
oRsOwn:LockType := 3 // lockoportunistic
cSQL := "SELECT * FROM Owner"
TRY
oRSOwn:Open( cSQL,xCONNECT )
CATCH oErr
MsgInfo( "ERROR Opening Owner Table " )
RETURN(.F.)
END TRY
If oRsOwn:Eof
Saying := "No Owners Information Exists"+chr(10)
Saying += "Would you like to CREATE a new Owner ?"+chr(10)
If MsgNoYes( saying )
cMode := "A"
Else
oRsOwn:CLose()
Return(.f.)
ENdif
ELse
cMode := "E"
ENdif
If cMODE = "A"
cOwner := space(35)
cDivision := space(35)
cAddress1 := space(25)
cAddress2 := space(25)
cCity := space(25)
cState := space(2)
cZip := space(10)
cContact := space(35)
cPhone := space(13)
cLast := 1000
cFein := space(10)
Else
cOwner := if(empty(oRsOwn:FIelds("Owner"):Value),space(35),;
substr(oRsOwn:FIelds("Owner"):Value+space(35),1,35))
cDivision := if(empty(oRsOwn:FIelds("Division"):Value),space(35),;
substr(oRsOwn:FIelds("Division"):Value+space(35),1,35))
cAddress1 := if(empty(oRsOwn:FIelds("Address1"):Value),space(25),;
substr(oRsOwn:FIelds("Address1"):Value+space(25),1,25))
cAddress2 := if(empty(oRsOwn:FIelds("Address2"):Value),space(25),;
substr(oRsOwn:FIelds("Address2"):Value+space(25),1,25))
cCity := if(empty(oRsOwn:FIelds("City"):Value),space(25),;
substr(oRsOwn:FIelds("City"):Value+space(25),1,25))
cState := if(empty(oRsOwn:FIelds("State"):Value),space(2),;
substr(oRsOwn:FIelds("State"):Value+space(2),1,2))
cZip := if(empty(oRsOwn:FIelds("Zip"):Value),space(10),;
substr(oRsOwn:FIelds("Zip"):Value+space(10),1,10))
cContact := if(empty(oRsOwn:Fields("Contact"):Value),space(35),;
substr(oRsOwn:FIelds("Contact"):Value+space(35),1,35))
cPhone := if(empty(oRsOwn:FIelds("Phone"):Value),space(13),;
substr(oRsOwn:FIelds("Phone"):Value+space(13),1,13))
cLast := if(empty(oRsOwn:FIelds("LastInvoice"):Value),space(10),;
substr(oRsOwn:FIelds("LastInvoice"):Value+space(10),1,10))
cFein := if(empty(oRsOwn:FIelds("Fein"):Value),space(10),;
substr(oRsOwn:FIelds("Fein"):Value+space(10),1,10))
ENDIF
DarkGreyGrad()
cTITLE := "Business or Owner Information "
DO CASE
CASE cMODE = "E"
cTITLE := "Business or Owner Information EDIT "
CASE cMODE = "A"
cTITLE := "Business or Owner Information ADD "
CASE cMODE = "V"
cTITLE := "Business or Owner Information VIEW "
ENDCASE
DEFINE ICON oICO RESOURCE "CONFIG"
DEFINE BITMAP oBmp RESOURCE "OWNVIEW"
DEFINE WINDOW oWndChild ;
MDICHILD ;
FROM 0,1 to 30,55 ;
NOMINIMIZE ;
ICON oIco ;
NOZOOM ;
OF oWndMain ;
TITLE cTITLE
DEFINE DIALOG oGRPS RESOURCE "OWNVIEW" ;
of oWndChild
REDEFINE SAY oSay1 ID 120 of oGrps UPDATE
oSay1:SetFont( oFontB )
REDEFINE SAY oSay2 ID 121 of oGrps UPDATE
oSay2:SetFont( oFontB )
REDEFINE SAY oSay3 ID 122 of oGrps UPDATE
oSay3:SetFont( oFontB )
REDEFINE SAY oSay4 ID 123 of oGrps UPDATE
oSay4:SetFont( oFontB )
REDEFINE SAY oSay5 ID 124 of oGrps UPDATE
oSay5:SetFont( oFontB )
REDEFINE SAY oSay6 ID 125 of oGrps UPDATE
oSay6:SetFont( oFontB )
REDEFINE SAY oSay7 ID 126 of oGrps UPDATE
oSay7:SetFont( oFontB )
REDEFINE SAY oSay8 ID 127 of oGrps UPDATE
oSay8:SetFont( oFontB )
REDEFINE SAY oSay9 ID 128 of oGrps UPDATE
oSay9:SetFont( oFontB )
REDEFINE SAY oSay10 ID 129 of oGrps UPDATE
oSay10:SetFont( oFontB )
IF cMODE = "A" .or. cMODE = "E"
REDEFINE GET oOWNER VAR cOWNER ID 220 of oGRPS UPDATE
REDEFINE GET oDivision VAR cDivision ID 225 of oGRPS UPDATE
REDEFINE GET oADDRESS1 VAR cADDRESS1 ID 230 of oGRPS UPDATE
REDEFINE GET oADDRESS2 VAR cADDRESS2 ID 240 of oGRPS UPDATE
REDEFINE GET oCITY VAR cCITY ID 250 of oGRPS UPDATE
REDEFINE GET oSTATE VAR cSTATE ID 260 of oGRPS PICTURE "@!" UPDATE
REDEFINE GET oZIP VAR cZIP ID 270 of oGRPS UPDATE
REDEFINE GET oLast VAR cLast ID 271 of oGRPS PICTURE( "9999999999" ) UPDATE
REDEFINE GET oCONTACT VAR cCONTACT ID 280 of oGRPS UPDATE
REDEFINE GET oPHONE VAR cPHONE ID 290 of oGRPS PICTURE "(999)999-9999" UPDATE
REDEFINE GET oFein VAR cFein ID 291 of oGRPS PICTURE "@!" UPDATE
ELSE // view
REDEFINE GET oOWNER VAR cOWNER ID 220 of oGRPS COLOR CLR_BLACK, 16053492 READONLY
REDEFINE GET oDivision VAR cDivision ID 225 of oGRPS COLOR CLR_BLACK, 16053492 READONLY
REDEFINE GET oADDRESS1 VAR cADDRESS1 ID 230 of oGRPS COLOR CLR_BLACK, 16053492 READONLY
REDEFINE GET oADDRESS2 VAR cADDRESS2 ID 240 of oGRPS COLOR CLR_BLACK, 16053492 READONLY
REDEFINE GET oCITY VAR cCITY ID 250 of oGRPS COLOR CLR_BLACK, 16053492 READONLY
REDEFINE GET oSTATE VAR cSTATE ID 260 of oGRPS COLOR CLR_BLACK, 16053492 READONLY
REDEFINE GET oZIP VAR cZIP ID 270 of oGRPS COLOR CLR_BLACK, 16053492 READONLY
REDEFINE GET oLast VAR cLast ID 271 of oGRPS COLOR CLR_BLACK, 16053492 READONLY
REDEFINE GET oCONTACT VAR cCONTACT ID 280 of oGRPS COLOR CLR_BLACK, 16053492 READONLY
REDEFINE GET oPHONE VAR cPHONE ID 290 of oGRPS COLOR CLR_BLACK, 16053492 READONLY
REDEFINE GET oFein VAR cFein ID 291 of oGRPS COLOR CLR_BLACK, 16053492 READONLY
ENDIF
REDEFINE BTNBMP oBtn1 ID 201 of oGrps ;
RESOURCE "OK" ;
PROMPT "Ok" LEFT 2007;
ACTION ( IF(cMODE = "V",lOK := .T. , lOK := _busrules(cMode,cOwner,oOwner ) ), ;
IF(cMODE = "V",lOK := .T. , if(lOK = .T., _doit( cMODE, oRsOwn,cOwner,cAddress1,cAddress2,;
cCity,cState,cZip,cContact,cPhone,cDivision,cLast,cFein ),)),;
IF(lOK = .T., oWndChild:END(), ) ,;
IF(lOK = .T., _cleanup(), ));
GRADIENT GreyButtonGrad()
REDEFINE BTNBMP oBtn2 ID 202 OF oGrps ;
RESOURCE "CANCEL" ;
PROMPT "Cancel" LEFT 2007;
ACTION ( lOK := .F., oWndChild:END() );
GRADIENT GreyButtonGrad()
ACTIVATE DIALOG oGrps NOWAIT ; // It has to be NonModal --> NOWAIT clause
ON INIT oGrps:Move(0,0);
ON PAINT (PalBmpDraw( hDC, 0, 0, oBmp:hBitmap ));
VALID (!GETKEYSTATE( 27 )) // do not allow esc key here
ACTIVATE WINDOW oWndChild ;
ON INIT ( ;
oWndChild:bResized := {|| oGrps:SetSize( oWndChild:nWidth, oWndChild:nHeight, .t. ) }, ;
oGrps:ReFresh());
VALID ( IIF( !lCLOSED, _ExitPgm(.T.,oRsOwn,@lClosed,oBmp ) , .F. ))
RETURN( lOK )
//---------------------------------
Static FUNC _Busrules(cMode,cOwner,oOwner)
LOCAL SAYING
IF cOWNER = " "
SAYING := "SORRY ... Business or Owners Name is a REQUIRED field"
MsgInfo( SAYING )
oOWNER:SetFocus()
RETURN(.F.)
ENDIF
RETURN(.T.)
//---------------------------------
Static FUNC _Doit( cMODE, oRsOwn,cOwner,cAddress1,cAddress2,;
cCity,cState,cZip,cContact,cPhone,cDivision,cLast,cFein )
Local cEid
IF cMODE = 'V'
RETURN(.T.)
ENDIF
IF cMODE = 'A'
cEid := _GenEID()
If cEid = "BOGUS"
Saying := "Error Creating Primaty Key"
Msginfo( Saying )
Return(.f.)
ENdif
oRsOwn:AddNew()
oRsOwn:Fields("OwnerEid"):Value := cEid
ENDIF
oRsOwn:FIelds("OWNER"):Value := cOWNER
oRsOwn:FIelds("Division"):Value := cDivision
oRsOwn:FIelds("ADDRESS1"):Value := cADDRESS1
oRsOwn:FIelds("ADDRESS2"):Value := cADDRESS2
oRsOwn:FIelds("CITY"):Value := cCITY
oRsOwn:FIelds("STATE"):Value := cSTATE
oRsOwn:FIelds("ZIP"):Value := cZIP
oRsOwn:Fields("contact"):Value := cCONTACT
oRsOwn:FIelds("PHONE"):Value := cPHONE
oRsOwn:Fields("LastInvoice"):Value := cLast
oRsOwn:Fields("FEIN"):Value := cFein
oRsOwn:Update()
RETURN(NIL)
//----------------------
Static FUNC _Cleanup()
RETURN(.T.)
//---------------------
Static Func _GenEid()
LOCAL nRAND, cRAND, oRs,oErr,cSql
oRs := TOleAuto():New( "ADODB.Recordset" )
oRs:CursorType := 1 // opendkeyset
oRs:CursorLocation := 3 // local cache
oRs:LockType := 3 // lockoportunistic
cSQL := "SELECT OwnerEid from Owner"
TRY
oRs:Open( cSQL,xCONNECT )
CATCH oErr
MsgInfo( "Error in Opening OWNER table" )
RETURN(.F.)
END TRY
IF oRs:Eof
oRs:Close()
cRAND := "10000000"
RETURN( cRAND )
ENDIF
cRAND := 'BOGUS'
DO WHILE .T.
nRAND := nRANDOM(10000000000000000)
// 1 is reserved and 0 is a null key //
IF nRAND = 1 .or. nRAND = 0 .or. nRAND = NIL
LOOP
ENDIF
cRAND := alltrim(STR(nRAND,15))
IF oRs:eof
ELSE
oRs:MoveFirst()
oRs:Find("OwnerEid = '"+cRAND+"'" )
ENDIF
IF oRs:eof
EXIT
ELSE
LOOP
ENDIF
EXIT
ENDDO
oRs:CLose()
oRs := nil
RETURN( cRAND )
//-----------------------
Static FUNCTION _ExitPgm( lCLEAN,oRsOwn,lClosed,oBmp,oWndMain )
IF lCLEAN = .T.
lCLOSED := .T.
oRsOwn:Close()
LightGreyGrad()
oRsOwn := NIL
oBmp:End()
_cleanup()
ENDIF
RETURN( lCLOSED )
//-- END