PowerWeb app example - Computer Shop (Part 3)
Posted: Mon Mar 20, 2023 5:36 am
Application Computer Shop.
This is an application for purchasing computers. It is an Alaska WAA application example which is developed in the PowerWeb way.
Below is the code for creating pages in the application, which are displayed in the following screenshots. You can see in the code that each web UI component is created with a single-function call and its attributes are set in Xbase++ language and style without HTML/CSS. You can find the complete code in the attachment of the Part 1 post about the new PowerWeb library.
This is an application for purchasing computers. It is an Alaska WAA application example which is developed in the PowerWeb way.
Below is the code for creating pages in the application, which are displayed in the following screenshots. You can see in the code that each web UI component is created with a single-function call and its attributes are set in Xbase++ language and style without HTML/CSS. You can find the complete code in the attachment of the Part 1 post about the new PowerWeb library.
Code: Select all
FUNCTION Comp(oSrv)
**
LOCAL html,;
aCols := {{"partno","PartNo",,60},;
{"producer","Producer",,200},;
{"computer","Computer",,200},;
{"LTRIM(STR(cpucount)) + ' ' + TRIM(cputype)",;
"Processors",,250},;
{"price","Price",,70,,"999999.99"},;
{,"Order",,40,"G",,,,,{30,"2S"}},;
{,"Quantity",,60,"G",,,,,{40,"SB",{1,10}}},;
{"jpg_image","Image",,120,"I"}}
* {"'temp/Cp' + STRZERO(RECNO(),6) + '.jpg'","Image",,120,"I"}}
**
HASSNSET(oSrv,"Path",HAPATH(oSrv) + "data\comp")
SET PATH TO (HASSNGET(oSrv,"Path"))
DBOPEN("FOXCDX",{{{"Computer"},{"Computer"}}},,,.T.)
**
IF EMPTY(HAPARGET(oSrv,"sel"))
HASSNSET(oSrv,"aSel",{})
HASSNSET(oSrv,"bgets","")
ENDIF
**
html = HDOCBGN(,,,,"Computers - Shop") +;
HDLGBGN(,{1200},"Computer shop",icoPower,{,{,clrBeige}},{,,,clrDefBG},;
{clrOldLace,clrDGold},,"C") +;
CompHead(oSrv) +;
HHEAD({30,20,"M"},,"Super computers",,{,{"mediumblue"}}) +;
HSCRP("SetBGets('" + HASSNGET(oSrv,"bgets") + "');") +;
HBRWPGN({,40,"M"},{,600},,aCols,{,"CompGet","CompPage"},,,"Comp",,"C") +;
HBREAK(2) + HDLGEND() + HDOCEND()
CLOSE
RETURN html
*============================================================================*
FUNCTION CompOrd(oSrv)
**
LOCAL aData,aCols,html, aSel := HASSNGET(oSrv,"aSel")
**
IF !AEMPTY(aSel)
CompSel(oSrv,aSel,@aData,@aCols)
**
html = HDOCBGN(,,,,"Computers - Order",,,,,,,HSETGUI(.T.)) +;
HDLGBGN(,{1200},"Computer shop",icoPower,{,{,clrBeige}},{,,,clrDefBG},;
{clrOldLace,clrDGold},,"C") +;
CompHead(oSrv) +;
HHEAD({30,20,"M"},,"Order",,{,{"mediumblue"}}) +;
HTABLE({,40,"M"},aData,aCols,,,,"C") +;
HHLINE({,40,"M"},{1050},clrGray,"C") +;
HFORMBGN({,40,"M"},{690,160},,,,{,{clrDRed,clrLinen},,20},;
{3,"DB",clrDCyan,10},,"C",{"CustForm"}) +;
HFORMTBL(,;
{{40,"First name:",{,,30},,,,,{,"F_FNAME"}},;
{40,"Last name:",{,,30},,,,,{,"F_LNAME"}},;
{40,"EMail:",{,,30,40},,,,,{,"F_EMAIL"}},;
{40,"Phone:",{,,30},,,,,{,"F_PHONE"}}},;
{80,240}) +;
HFORMTBL({360,-160,"R","R"},;
{{40,"Street:",{,,30,40},,,,,{,"F_STREET"}},;
{40,"City:",{,,30},,,,,{,"F_CITY"}},;
{40,"State:",{,,30},,,,,{,"F_STATE"}},;
{40,"Info:",,"2S",,,,{,"F_INFO"}}},;
{80,240}) +;
HFORMEND() +;
HDIVBGN({,40,"M"},{1200},{,,60,,"C"}) +;
HLINK(,,"Go to shop",bmpHome,;
{{,12,"B"},{clrDViolet,clrLBlue},,{5,25}},{,,,clrDefBG},;
{2,,clrMRed,5},HTTPREDIR("Comp",{{"sel","true"}},,"L"),,,,,;
"text-decoration:none") +;
HLINK({20,,"M"},,"Commit order",icoOK,;
{{,12,"B"},{clrDViolet,clrLBlue},,{5,15}},{,{16,16},,clrDefBG},;
{2,,clrMRed,5},HTTPREDIR("CompCmt",,"FormPost('CustForm')","L"),;
,,,,"text-decoration:none") +;
HDIVEND() + HBREAK() + HDLGEND() + HDOCEND()
ELSE
HASSNSET(oSrv,"Msg","Your basket is empty.")
HASSNSET(oSrv,"Addr","Comp")
html = HTTPREDIR("CompMsg")
ENDIF
RETURN html
*============================================================================*
FUNCTION CompSel(oSrv,aSel,aData,aCols)
**
LOCAL amnt,I, len := LEN(aSel), tot := 0
**
SET PATH TO (HASSNGET(oSrv,"Path"))
DBOPEN("FOXCDX",{{{"Computer"},{"Computer"}}},,,.T.)
**
aCols = {{,"PartNo",,60},;
{,"Producer",,200},;
{,"Computer",,200},;
{,"Processors","Total",250},;
{,"Price",,70,,,,"R"},;
{,"Quantity",,60,,,,"R"},;
{,"Amount",,100,,,,"R"}}
aData = ARRAY(len)
FOR I=1 TO len
GO aSel[I,1]
amnt = price * aSel[I,2]
tot += amnt
aData[I] = {partno,producer,computer,LTRIM(STR(cpucount)) + " " +;
TRIM(cputype),price,aSel[I,2],amnt}
NEXT
aCols[7,3] = LTRIM(STR(tot))
CLOSE
RETURN .T.
*============================================================================*
FUNCTION CompHead(oSrv)
**
RETURN HMENU({3,3,"R"},{450},;
{{"Shop",bmpHome,"Comp?sel=true"},;
{"Basket",bmpBasket,"CompBask"},;
{"Order",bmpList,"CompOrd"},;
{"Exit",bmpExit,"CompExit"}},;
{,,,{,,,clrDefBG}})
*============================================================================*