PowerWeb app example - Order Reservation (Part 5)

This forum is for conversations about Internet development using CXP, WebSockets, HttpEndPoint, etc.
Post Reply
Message
Author
User avatar
SlavkoDam
Posts: 101
Joined: Wed Apr 27, 2022 10:12 am
Location: Negotin, Serbia
Contact:

PowerWeb app example - Order Reservation (Part 5)

#1 Post by SlavkoDam »

Application Order Reservation.

This is an application for browsing and editing customer reservations. It is an Alaska CXP 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 Res(oSrv)
**
LOCAL html,;
      aCCols := {{"customer_i","Customer",,60},;
                 {"LEFT(company_na,30)","Company",,200},;
                 {"LEFT(contact_na,25)","Contact",,160},;
                 {"TRIM(city) + ', ' + TRIM(country)","Location",,160},;
                 {"discount","Disc",,25,,"@Z"},;
                 {"res_count","Res",,25,,"@Z",,{clrDRed,clrBeige}}},;
      aRCols := {{,"Prod",,30,,,,,"R"},;
                 {,"Product name",,300},;
                 {,"Qunty",,30,,,,,"R"}}
**
HASSNSET(oSrv,"Path",HAPATH(oSrv) + "data\reser")
SET PATH TO (HASSNGET(oSrv,"Path"))
DBOPEN("FOXCDX",{{{"Customer"},{"Customer","customer_i"}}},,,.T.)
HASSNSET(oSrv,"Customer","")
HASSNSET(oSrv,"ResId","")
HASSNSET(oSrv,"Operator","John Doe")
**
html = HDOCBGN(,{"files/reser.js"},,,"Reservations - browse",,,,,,,HSETGUI(,.T.)) +;
       HDLGBGN(,{1200},"Order reservation",icoPower,{,{,clrHoneyDew}},;
               {,,,clrDefBG},{clrYellow,clrMBrown},,"C") +;
       ResHead(oSrv) +;
       HDIVBGN({,1,"R"},{1200,650}) +;
       HHEAD({30},,"Browse reservations",,{,{"mediumblue"}}) +;
       HPARAG({30,70},,"Click on a customer to display its reservations.",;
              {{,12,"B"},{"brown"}}) +;
       HSAY({760,50},{450},,{,12,"B"},{clrBlue},{"Cust"}) +;
       HPARAG({760,70},,"Click on a reservation to edit it.",{{,12,"B"},;
              {"brown"}}) +;
       HBRWPGN({30,110},{,500},"Customer",aCCols,{,,"CustPage"},20,,,,,;
               {"CustResDisp"}) +;
       HBRWGEN({760,110},{,310},{{"","",0}},aRCols,,,,"ResBrw",,,{"ResId"}) +;
       HTOOLBAR({760,450},,;
                {{"Add",bmpNewDoc,HTTPREDIR("ResAdd",,,"B"),,,{"AddBtn"},.T.},;
                 {"Edit",icoEditText,HTTPREDIR("ResEdit",,,"B"),,,{"EditBtn"},.T.},;
                 {"Delete",icoTrash,"ResDelClk()",,,{"DelBtn"},.T.}},;
                {{110,30},,{,,,clrDefBG}}) +;
       HDIVEND() + HDLGEND() + HDOCEND()
CLOSE ALL
RETURN html

*============================================================================*

FUNCTION ResAdd(oSrv)
**
HASSNSET(oSrv,"ResId","")
RETURN ResEdit(oSrv)

*============================================================================*

FUNCTION ResEdit(oSrv)
**
LOCAL aCat[0],aPrd[0],html,m_cat,m_prd,m_qty,m_pack,m_pri,m_det,;
      aPack := {{"Standard","standard"},{"Gift","gift"}},;
      cust := HASSNGET(oSrv,"Customer"), res_id := HASSNGET(oSrv,"ResId"),;
      is_new := .F.
**
SET PATH TO (HASSNGET(oSrv,"Path"))
DBOPEN("FOXCDX",{{{"Customer"},{"Customer","customer_i"}},;
                 {{"Category"},{"Category","category_i"}},;
                 {{"Product"},{"Product","product_id"}},;
                 {{"Reservation"},{"Reservation","id"}}},,,.T.)
**
SELECT Customer
IF !EMPTY(cust)
  SEEK cust
ELSE
  cust = customer_i
  HASSNSET(oSrv,"Customer",cust)
ENDIF
cust = "Customer:  " + TRIM(cust) + "  " + CHAR2UTF8(TRIM(company_na))
SELECT Category
DBEVAL({|| AADD(aCat,{TRIM(category_n),category_i})})
IF !EMPTY(res_id)
  SELECT Reservation
  SEEK res_id
  m_prd = product_id;  m_qty = quantity;  m_pack = packaging
  m_pri = IF(priority,"Y","N");  m_det = details
  SELECT Product
  SEEK m_prd
  m_cat = category_i
ELSE
  GO TOP
  m_cat = category_i
  SELECT Product
  is_new = .T.
ENDIF
ORDSETFOCUS("category_i")
GO TOP
SEEK m_cat
DO WHILE category_i = m_cat .AND. !EOF()
  AADD(aPrd,{CHAR2UTF8(product_na),product_id})
  SKIP
ENDDO
CLOSE ALL
**
html = HDOCBGN(,{"files/reser.js"},,,"Reservations - edit",,,,,,,HSETGUI(.T.,.T.)) +;
       HDLGBGN(,{1200,570},"Order reservation",icoPower,{,{,clrHoneyDew}},;
               {,,,clrDefBG},{clrYellow,clrMBrown},,"C") +;
       ResHead(oSrv) +;
       HHEAD({30,20,"M"},,"Edit reservation",,{,{"mediumblue"}}) +;
       HSAY({30,20,"R"},{600},cust,{,12,"B"},{clrBlue}) +;
       HFORMBGN({30,30,"R"},,,,,,,,,{"ResForm"}) +;
       HFORMTBL(,;
                {{35,"Category:",{140},"CB",m_cat,aCat,{,!is_new},;
                  {,"Category"},,,{,"SelFill('Product','Category','ResCatPrd')"}},;
                 {35,"Product:",{250},"CB",m_prd,aPrd,{,!is_new},{,"Product"}},;
                 {35,"Quantity:",{60},"SB",m_qty,{1,100},,{,"Quantity"}},;
                 {35,"Packaging:",,"RB",m_pack,aPack,,{,"Packaging"}},;
                 {35,"Priority:",,"RB",m_pri,{"No","Yes"},,{,"Priority"}},;
                 {120,"Notes:",{,,37,5},"ML",m_det,,,{,"Details"}}},;
                {90,300}) +;
       HFORMEND() +;
       HTOOLBAR({30,70,"R"},,;
                {{"Save",bmpSave,"ResSaveClk()"},;
                 {"Cancel",bmpDelete,HTTPREDIR("Res",,,"B")}},;
                {{110,30},,{,,,clrDefBG}},{{,,10}}) +;
       HDLGEND() + HDOCEND()
RETURN html

*============================================================================*

FUNCTION ResPrdStk(oSrv)
**
LOCAL html, aCat := {{"--- Select ---",""}},;
      aCols := {{,"Product name",,300},;
                {,"InStock",,40,,,,,"R"},;
                {,"OnOrder",,40,,,,,"R"},;
                {,"Capital",,60,,,,,"R"}}
**
SET PATH TO (HASSNGET(oSrv,"Path"))
DBOPEN("FOXCDX",{{{"Category"},{"Category","category_i"}}},,,.T.)
**
DBEVAL({|| AADD(aCat,{TRIM(category_n),category_i})})
CLOSE
**
HASSNSET(oSrv,"Img","")
html = HDOCBGN(,{"files/reser.js"},,,"Reservations - product stock",,,,,,,;
               HSETGUI(.T.,.T.)) +;
       HDLGBGN(,{1200},"Order reservation",icoPower,{,{,clrHoneyDew}},;
               {,,,clrDefBG},{clrYellow,clrMBrown},,"C") +;
       ResHead(oSrv) +;
       HDIVBGN({,1,"R"},{1200,880}) +;
       HHEAD({30},,"Product stock",,{,{"mediumblue"}}) +;
       HSAY({30,90},,"Category:") +;
       HGET({110,90},{140,,10},"LB",,aCat,,{"CatList"},,,{,"CatSelCng()"}) +;
       HBRWGEN({300,90},{,250},{{"",0,0,0}},aCols,,,,"PrdBrw") +;
       HGRAPHRM({30,370},{1100,400},,{,,{,clrBlue}},{"GrpImg"}) +;
       HTOOLBAR({30,810},,;
                {{"Print",bmpPrint,HTTPREDIR("GrpPrdPrn",,,"B")},;
                 {"Save",bmpSave,"GrpSaveClk()"}},;
                {{110,30},,{,,,clrDefBG}},{{,,10}}) +;
       HEDITDATA({{35,"File name:",{,,20,20},,,,,{"File","File"}}},;
                 {80,165},"Save file",,,{"SaveDlg"},"GrpSaveAct") +;
       HDIVEND() + HDLGEND() + HDOCEND()
RETURN html

*============================================================================*

FUNCTION GrpPrdPrn(oSrv)
**
LOCAL img := HASSNGET(oSrv,"Img")
**
RETURN IF(EMPTY(img),"",;
       HDOCBGN(,,,,,,,,,,,"window.print();") +;
       HHEAD(,,"Category " + HASSNGET(oSrv,"Category"),,{,{clrBlue},,,"C"}) +;
       HBREAK() +;
       HIMG(,{1100,400},img,"Graph",,{,,clrBlue},"C") +;
       HDOCEND())

*============================================================================*

FUNCTION ResHead(oSrv,aCaps)
**
RETURN HMENU({3,3,"R"},{450},;
             {{"Browse",bmpHome,"Res"},;
              {"Edit",icoEdit,"ResEdit",,{,,,,.T.}},;
              {"Product stock",icoChart,"ResPrdStk"},;
              {"Exit",bmpExit,"ResExit"}},;
             {,,,{,,,clrDefBG}})

*============================================================================*
Image
Image
Image
Best regards,

Slavoljub Damnjanovic
SD-SoftDesign, Alaska Software Technology Partner
https://www.sd-softdesign.com
https://www.sd-softdesign.rs

Post Reply