Commit 42f8e3e6 by Cam Hayes

Merge remote-tracking branch 'origin/mac3' into cam3

parents 284ccb7b facf79ff
...@@ -9,6 +9,7 @@ procedure ShowStatusMessage(const AMessage, AClass: string; const AElementId: st ...@@ -9,6 +9,7 @@ procedure ShowStatusMessage(const AMessage, AClass: string; const AElementId: st
procedure HideStatusMessage(const AElementId: string); procedure HideStatusMessage(const AElementId: string);
procedure ShowSpinner(SpinnerID: string); procedure ShowSpinner(SpinnerID: string);
procedure HideSpinner(SpinnerID: string); procedure HideSpinner(SpinnerID: string);
procedure ShowErrorModal(const msg: string);
function CalculateAge(DateOfBirth: TDateTime): Integer; function CalculateAge(DateOfBirth: TDateTime): Integer;
function FormatPhoneNumber(PhoneNumber: string): string; function FormatPhoneNumber(PhoneNumber: string): string;
procedure ApplyReportTitle(CurrentReportType: string); procedure ApplyReportTitle(CurrentReportType: string);
...@@ -82,6 +83,39 @@ begin ...@@ -82,6 +83,39 @@ begin
end; end;
end; end;
// The $IFNDEF WIN32 was recommended by Holger to deal with any modal issues
procedure ShowErrorModal(const msg: string);
begin
{$IFNDEF WIN32}
asm
var modal = document.getElementById('main_errormodal');
var label = document.getElementById('main_lblmodal_body');
var reloadBtn = document.getElementById('btn_modal_restart');
if (label) label.innerText = msg;
// Ensure modal is a direct child of <body>
if (modal && modal.parentNode !== document.body) {
document.body.appendChild(modal);
}
// Bind hard reload to button
if (reloadBtn) {
reloadBtn.onclick = function () {
window.location.reload(true); // hard reload, bypass cache
};
}
// Show the Bootstrap modal
var bsModal = new bootstrap.Modal(modal, { keyboard: false });
bsModal.show();
end;
{$ENDIF}
end;
function CalculateAge(DateOfBirth: TDateTime): Integer; function CalculateAge(DateOfBirth: TDateTime): Integer;
var var
......
...@@ -125,39 +125,32 @@ begin ...@@ -125,39 +125,32 @@ begin
if PageNumber > 0 then if PageNumber > 0 then
begin begin
Utils.ShowSpinner('spinner'); Utils.ShowSpinner('spinner');
try
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetCustomers', [searchOptions])); xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetCustomers', [searchOptions]));
customerList := TJSObject(xdcResponse.Result); customerList := TJSObject(xdcResponse.Result);
// Load data into the dataset
xdwdsCustomers.Close; xdwdsCustomers.Close;
xdwdsCustomers.SetJsonData(customerList['data']); xdwdsCustomers.SetJsonData(customerList['data']);
xdwdsCustomers.Open; xdwdsCustomers.Open;
Utils.HideSpinner('spinner');
customerListLength := integer(customerList['count']); customerListLength := integer(customerList['count']);
TotalPages := ( (customerListLength + PageSize - 1) div PageSize); TotalPages := ( (customerListLength + PageSize - 1) div PageSize);
if customerListLength = 0 then if customerListLength = 0 then
begin lblEntries.Caption := 'No entries found'
lblEntries.Caption := 'No entries found';
end
else if (PageNumber * PageSize) < customerListLength then else if (PageNumber * PageSize) < customerListLength then
// Currently these do the same thing. If you want to limit the number of entries
// You will need to edit the server side, and then change this if statement so the label
// Correctly displayes. I believe it is IntToStr(PageSize * PageNum)
begin
lblEntries.Caption := 'Showing entries ' + IntToStr((PageNumber - 1) * PageSize + 1) + lblEntries.Caption := 'Showing entries ' + IntToStr((PageNumber - 1) * PageSize + 1) +
' - ' + IntToStr(customerListLength) + ' - ' + IntToStr(customerListLength) +
' of ' + IntToStr(customerListLength); ' of ' + IntToStr(customerListLength)
end else
else if (PageNumber * PageSize) >= customerListLength then
begin
lblEntries.Caption := 'Showing entries ' + IntToStr((PageNumber - 1) * PageSize + 1) + lblEntries.Caption := 'Showing entries ' + IntToStr((PageNumber - 1) * PageSize + 1) +
' - ' + IntToStr(customerListLength) + ' - ' + IntToStr(customerListLength) +
' of ' + IntToStr(customerListLength); ' of ' + IntToStr(customerListLength);
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not retrieve customers: ' + E.ErrorResult.ErrorMessage);
end; end;
Utils.HideSpinner('spinner');
end; end;
end; end;
......
...@@ -103,7 +103,7 @@ begin ...@@ -103,7 +103,7 @@ begin
Utils.ShowSpinner('spinner'); Utils.ShowSpinner('spinner');
end; end;
function TFViewEditUser.AddUser(): string; function TFViewEditUser.AddUser: string;
// Sends UserInfo over to the server so it can be added to the database // Sends UserInfo over to the server so it can be added to the database
var var
userInfo: string; userInfo: string;
...@@ -120,12 +120,17 @@ begin ...@@ -120,12 +120,17 @@ begin
'&rights=' + edtRights.Text + '&rights=' + edtRights.Text +
'&QB=' + edtQB.Text; '&QB=' + edtQB.Text;
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddUser', try
[userInfo])); xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddUser', [userInfo]));
responseString := TJSObject(xdcResponse.Result); responseString := TJSObject(xdcResponse.Result);
Info := string(responseString['value']); Info := string(responseString['value']);
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not add user: ' + E.ErrorResult.ErrorMessage);
end;
end; end;
procedure TFViewEditUser.HideNotification; procedure TFViewEditUser.HideNotification;
begin begin
pnlMessage.ElementHandle.hidden := True; pnlMessage.ElementHandle.hidden := True;
......
...@@ -48,7 +48,6 @@ object FViewItems: TFViewItems ...@@ -48,7 +48,6 @@ object FViewItems: TFViewItems
Height = 25 Height = 25
Caption = 'Add' Caption = 'Add'
ChildOrder = 7 ChildOrder = 7
ElementClassName = 'btn btn-light'
ElementID = 'btnadd' ElementID = 'btnadd'
ElementFont = efCSS ElementFont = efCSS
HeightStyle = ssAuto HeightStyle = ssAuto
...@@ -110,6 +109,7 @@ object FViewItems: TFViewItems ...@@ -110,6 +109,7 @@ object FViewItems: TFViewItems
ElementPosition = epRelative ElementPosition = epRelative
Role = 'null' Role = 'null'
TabOrder = 5 TabOrder = 5
Visible = False
object lblMessage: TWebLabel object lblMessage: TWebLabel
Left = 28 Left = 28
Top = 9 Top = 9
...@@ -148,7 +148,6 @@ object FViewItems: TFViewItems ...@@ -148,7 +148,6 @@ object FViewItems: TFViewItems
Height = 25 Height = 25
Caption = 'Save' Caption = 'Save'
ChildOrder = 79 ChildOrder = 79
ElementClassName = 'btn btn-light'
ElementID = 'btnconfirm' ElementID = 'btnconfirm'
ElementFont = efCSS ElementFont = efCSS
ElementPosition = epRelative ElementPosition = epRelative
...@@ -160,12 +159,11 @@ object FViewItems: TFViewItems ...@@ -160,12 +159,11 @@ object FViewItems: TFViewItems
end end
object btnCancel: TWebButton object btnCancel: TWebButton
Left = 565 Left = 565
Top = 259 Top = 256
Width = 96 Width = 96
Height = 25 Height = 25
Caption = 'Cancel' Caption = 'Cancel'
ChildOrder = 79 ChildOrder = 79
ElementClassName = 'btn btn-light'
ElementID = 'btncancel' ElementID = 'btncancel'
ElementFont = efCSS ElementFont = efCSS
ElementPosition = epRelative ElementPosition = epRelative
...@@ -182,7 +180,6 @@ object FViewItems: TFViewItems ...@@ -182,7 +180,6 @@ object FViewItems: TFViewItems
Height = 25 Height = 25
Caption = 'Delete' Caption = 'Delete'
ChildOrder = 79 ChildOrder = 79
ElementClassName = 'btn btn-light'
ElementID = 'btndelete' ElementID = 'btndelete'
ElementFont = efCSS ElementFont = efCSS
HeightStyle = ssAuto HeightStyle = ssAuto
...@@ -197,7 +194,6 @@ object FViewItems: TFViewItems ...@@ -197,7 +194,6 @@ object FViewItems: TFViewItems
Height = 25 Height = 25
Caption = 'Edit' Caption = 'Edit'
ChildOrder = 83 ChildOrder = 83
ElementClassName = 'btn btn-light'
ElementID = 'btnedit' ElementID = 'btnedit'
ElementFont = efCSS ElementFont = efCSS
HeightStyle = ssAuto HeightStyle = ssAuto
......
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
</div> </div>
</form> </form>
<table class="table table-responsive table-striped table-bordered" id="tblPhoneGrid"> <table class="table table-responsive table-striped table-hover table-bordered" id="tblPhoneGrid">
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
<th scope="col">ID</th> <th scope="col">ID</th>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// to sort the entries, filter their search, and search for a specific person. // to sort the entries, filter their search, and search for a specific person.
// Authors: // Authors:
// Cameron Hayes // Cameron Hayes
// Mac ... // Mac Stephens
unit View.Items; unit View.Items;
...@@ -115,46 +115,74 @@ begin ...@@ -115,46 +115,74 @@ begin
cbStatus.enabled := true; cbStatus.enabled := true;
end; end;
procedure TFViewItems.AddRowToTable(ID, Name, Description, Status: string); procedure TFViewItems.AddRowToTable(ID, Name, Description, Status: string);
// Adds rows to the table // Adds one row to #tblPhoneGrid and lets Bootstrap 5.3 highlight the row
// ID: item ID // with its built-in `table-active` class when the user clicks it.
// Name: item name
// Description: item description
// Status: inactive or active
var var
NewRow, Cell, P, Button, Audio: TJSHTMLElement; NewRow, Cell: TJSHTMLElement;
begin begin
NewRow := TJSHTMLElement(document.createElement('tr')); NewRow := TJSHTMLElement(document.createElement('tr'));
// Item ID Cell // Row-select click handler
NewRow.addEventListener('click',
procedure(Event: TJSMouseEvent)
var
TBody : TJSHTMLElement;
Rows : TJSHTMLCollection;
I : Integer;
RowElem : TJSHTMLElement;
begin
// Grab the <tbody> once and cast it
TBody := TJSHTMLElement(
(document.getElementById('tblPhoneGrid') as TJSHTMLElement)
.getElementsByTagName('tbody')[0]
);
// Remove 'table-active' from every existing row
Rows := TBody.children;
for I := 0 to Rows.length - 1 do
begin
RowElem := TJSHTMLElement(Rows.item(I)); // ? cast Node ? HTMLElement
RowElem.classList.remove('table-primary');
end;
// Add highlight to the clicked row
TJSHTMLElement(Event.currentTarget).classList.add('table-primary');
end
);
Cell := TJSHTMLElement(document.createElement('td')); Cell := TJSHTMLElement(document.createElement('td'));
Cell.setAttribute('data-label', 'Item ID'); Cell.setAttribute('data-label', 'Item ID');
Cell.innerText := ID; Cell.innerText := ID;
NewRow.appendChild(Cell); NewRow.appendChild(Cell);
// Name Cell
Cell := TJSHTMLElement(document.createElement('td')); Cell := TJSHTMLElement(document.createElement('td'));
Cell.setAttribute('data-label', 'Name'); Cell.setAttribute('data-label', 'Name');
Cell.innerText := Name; Cell.innerText := Name;
NewRow.appendChild(Cell); NewRow.appendChild(Cell);
// Description Cell
Cell := TJSHTMLElement(document.createElement('td')); Cell := TJSHTMLElement(document.createElement('td'));
Cell.setAttribute('data-label', 'Description'); Cell.setAttribute('data-label', 'Description');
Cell.innerText := Description; Cell.innerText := Description;
NewRow.appendChild(Cell); NewRow.appendChild(Cell);
// Status Cell
Cell := TJSHTMLElement(document.createElement('td')); Cell := TJSHTMLElement(document.createElement('td'));
Cell.setAttribute('data-label', 'Status'); Cell.setAttribute('data-label', 'Status');
Cell.innerText := Status; Cell.innerText := Status;
NewRow.appendChild(Cell); NewRow.appendChild(Cell);
// Appends new rows to the table body TJSHTMLElement(
TJSHTMLElement(document.getElementById('tblPhoneGrid').getElementsByTagName('tbody')[0]).appendChild(NewRow); (document.getElementById('tblPhoneGrid') as TJSHTMLElement)
.getElementsByTagName('tbody')[0]
).appendChild(NewRow);
Utils.HideSpinner('spinner'); Utils.HideSpinner('spinner');
end; end;
procedure TFViewItems.GeneratePagination(TotalPages: Integer); procedure TFViewItems.GeneratePagination(TotalPages: Integer);
// Generates pagination for the table. // Generates pagination for the table.
// TotalPages: Total amount of pages generated by the search // TotalPages: Total amount of pages generated by the search
...@@ -339,13 +367,13 @@ begin ...@@ -339,13 +367,13 @@ begin
if PageNumber > 0 then if PageNumber > 0 then
begin begin
Utils.ShowSpinner('spinner'); Utils.ShowSpinner('spinner');
try
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetItems', xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetItems',
[searchOptions])); [searchOptions]));
itemList := TJSObject(xdcResponse.Result); itemList := TJSObject(xdcResponse.Result);
data := TJSArray(itemList['data']); data := TJSArray(itemList['data']);
itemListLength := integer(itemList['count']); itemListLength := integer(itemList['count']);
ClearTable(); ClearTable();
Utils.HideSpinner('Spinner');
for i := 0 to data.Length - 1 do for i := 0 to data.Length - 1 do
begin begin
item := TJSObject(data[i]); item := TJSObject(data[i]);
...@@ -366,6 +394,11 @@ begin ...@@ -366,6 +394,11 @@ begin
' of ' + IntToStr(itemListLength); ' of ' + IntToStr(itemListLength);
end; end;
GeneratePagination(TotalPages); GeneratePagination(TotalPages);
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not retrieve items: ' + E.ErrorResult.ErrorMessage);
end;
Utils.HideSpinner('spinner');
end; end;
end; end;
...@@ -466,11 +499,16 @@ procedure TFViewItems.AddItem(itemOptions: string); ...@@ -466,11 +499,16 @@ procedure TFViewItems.AddItem(itemOptions: string);
var var
xdcResponse: TXDataClientResponse; xdcResponse: TXDataClientResponse;
begin begin
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddItem', try
[itemOptions])); xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddItem', [itemOptions]));
getItems(GenerateSearchOptions()); getItems(GenerateSearchOptions());
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not add item: ' + E.ErrorResult.ErrorMessage);
end;
end; end;
procedure TFViewItems.wcbPageSizeChange(Sender: TObject); procedure TFViewItems.wcbPageSizeChange(Sender: TObject);
// gets a new amount of items based when the page size is changed // gets a new amount of items based when the page size is changed
begin begin
......
...@@ -69,6 +69,27 @@ ...@@ -69,6 +69,27 @@
</div> </div>
</div> </div>
<div class="modal fade" id="main_errormodal" tabindex="-1" aria-labelledby="main_lblmodal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content shadow-lg">
<div class="modal-header">
<h5 class="modal-title" id="main_lblmodal">Error</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body fs-6 fw-bold" id="main_lblmodal_body">
Please contact EMSystems to solve the issue.
</div>
<div class="modal-footer justify-content-center">
<button type="button" id="btn_modal_restart" class="btn btn-primary">Restart WebApp</button>
</div>
</div>
</div>
</div>
...@@ -315,4 +315,5 @@ begin ...@@ -315,4 +315,5 @@ begin
FChildForm := TFViewUsers.CreateForm(WebPanel1.ElementID, Info); FChildForm := TFViewUsers.CreateForm(WebPanel1.ElementID, Info);
end; end;
end. end.
...@@ -553,7 +553,7 @@ var ...@@ -553,7 +553,7 @@ var
searchOptions, pdfURL: string; searchOptions, pdfURL: string;
jsObject: TJSObject; jsObject: TJSObject;
begin begin
try
// Call the server method to generate the PDF // Call the server method to generate the PDF
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateOrderCorrugatedPDF', [orderID])); xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateOrderCorrugatedPDF', [orderID]));
jsObject := JS.TJSObject(xdcResponse.Result); jsObject := JS.TJSObject(xdcResponse.Result);
...@@ -562,8 +562,13 @@ begin ...@@ -562,8 +562,13 @@ begin
// Open the PDF in a new browser tab without needing a different form // Open the PDF in a new browser tab without needing a different form
// This method is much faster too, even for large datasets // This method is much faster too, even for large datasets
window.open(pdfURL, '_blank'); window.open(pdfURL, '_blank');
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not generate corrugated PDF: ' + E.ErrorResult.ErrorMessage);
end;
end; end;
procedure TFOrderEntryCorrugated.AddCorrugatedOrder(orderJSON: TJSONObject); procedure TFOrderEntryCorrugated.AddCorrugatedOrder(orderJSON: TJSONObject);
// sends the order JSON object to the server // sends the order JSON object to the server
var var
...@@ -585,10 +590,16 @@ procedure TFOrderEntryCorrugated.DelOrder(); ...@@ -585,10 +590,16 @@ procedure TFOrderEntryCorrugated.DelOrder();
var var
Response: TXDataClientResponse; Response: TXDataClientResponse;
begin begin
try
Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.DelOrder', Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.DelOrder',
[OrderID, 'corrugated', JS.toString(AuthService.TokenPayload.Properties['user_id'])])); [OrderID, 'corrugated', JS.toString(AuthService.TokenPayload.Properties['user_id'])]));
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not delete order: ' + E.ErrorResult.ErrorMessage);
end;
end; end;
class function TFOrderEntryCorrugated.CreateForm(AElementID, orderInfo, customerInfo, mode, info: string): TWebForm; class function TFOrderEntryCorrugated.CreateForm(AElementID, orderInfo, customerInfo, mode, info: string): TWebForm;
var var
localMode: string; localMode: string;
...@@ -606,7 +617,6 @@ begin ...@@ -606,7 +617,6 @@ begin
end; end;
end end
); );
end; end;
procedure TFOrderEntryCorrugated.addColorRow(num: string; Color: string; LPI: string; Size: string); procedure TFOrderEntryCorrugated.addColorRow(num: string; Color: string; LPI: string; Size: string);
...@@ -821,8 +831,8 @@ var ...@@ -821,8 +831,8 @@ var
colorListJSON: TJSONArray; colorListJSON: TJSONArray;
items: TJSObject; items: TJSObject;
begin begin
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetOrder', try
[Order_ID])); xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetOrder', [Order_ID]));
order := TJSObject(xdcResponse.Result); order := TJSObject(xdcResponse.Result);
data := TJSArray(order['data']); data := TJSArray(order['data']);
XDataWebDataSet1.Close; XDataWebDataSet1.Close;
...@@ -953,7 +963,10 @@ begin ...@@ -953,7 +963,10 @@ begin
items := TJSObject(order['ITEMS']); items := TJSObject(order['ITEMS']);
xdwdsQBItem.SetJsonData(items['data']); xdwdsQBItem.SetJsonData(items['data']);
xdwdsQBITEM.Open; xdwdsQBITEM.Open;
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not retrieve order: ' + E.ErrorResult.ErrorMessage);
end;
end; end;
procedure TFOrderEntryCorrugated.getCustomer(customerID: string); procedure TFOrderEntryCorrugated.getCustomer(customerID: string);
...@@ -964,8 +977,8 @@ var ...@@ -964,8 +977,8 @@ var
address: string; address: string;
items: TJSObject; items: TJSObject;
begin begin
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetCustomer', try
[customerID])); xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetCustomer', [customerID]));
customer := TJSObject(xdcResponse.Result); customer := TJSObject(xdcResponse.Result);
XDataWebDataSet1.Close; XDataWebDataSet1.Close;
XDataWebDataSet1.SetJsonData(customer); XDataWebDataSet1.SetJsonData(customer);
...@@ -989,6 +1002,10 @@ begin ...@@ -989,6 +1002,10 @@ begin
dtpMountDue.Date := 0; dtpMountDue.Date := 0;
dtpShipDate.Date := 0; dtpShipDate.Date := 0;
dtpApprovedDate.Date := 0; dtpApprovedDate.Date := 0;
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not retrieve customer: ' + E.ErrorResult.ErrorMessage);
end;
end; end;
procedure TFOrderEntryCorrugated.WebFormShow(Sender: TObject); procedure TFOrderEntryCorrugated.WebFormShow(Sender: TObject);
......
...@@ -394,7 +394,7 @@ var ...@@ -394,7 +394,7 @@ var
searchOptions, pdfURL: string; searchOptions, pdfURL: string;
jsObject: TJSObject; jsObject: TJSObject;
begin begin
try
// Call the server method to generate the PDF // Call the server method to generate the PDF
console.log(orderID); console.log(orderID);
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateOrderCuttingPDF', [orderID])); xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateOrderCuttingPDF', [orderID]));
...@@ -404,22 +404,33 @@ begin ...@@ -404,22 +404,33 @@ begin
// Open the PDF in a new browser tab without needing a different form // Open the PDF in a new browser tab without needing a different form
// This method is much faster too, even for large datasets // This method is much faster too, even for large datasets
window.open(pdfURL, '_blank'); window.open(pdfURL, '_blank');
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not generate cutting die PDF: ' + E.ErrorResult.ErrorMessage);
end;
end; end;
procedure TFOrderEntryCuttingDie.AddCuttingDieOrder(orderJSON: TJSONObject); procedure TFOrderEntryCuttingDie.AddCuttingDieOrder(orderJSON: TJSONObject);
// sends the order JSON object to the server // sends the order JSON object to the server
var var
Response: TXDataClientResponse; Response: TXDataClientResponse;
jsObj: TJSObject; jsObj: TJSObject;
begin begin
try
Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddCuttingDieOrder', Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddCuttingDieOrder',
[orderJSON.ToString])); [orderJSON.ToString]));
jsObj := JS.TJSObject(Response.Result); jsObj := JS.TJSObject(Response.Result);
if mode = 'ADD' then if mode = 'ADD' then
OrderID := String(jsObj.Properties['OrderID']); OrderID := String(jsObj.Properties['OrderID']);
mode := 'EDIT'; mode := 'EDIT';
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not save cutting die order: ' + E.ErrorResult.ErrorMessage);
end;
end; end;
class function TFOrderEntryCuttingDie.CreateForm(AElementID, orderInfo, customerInfo, mode, info: string): TWebForm; class function TFOrderEntryCuttingDie.CreateForm(AElementID, orderInfo, customerInfo, mode, info: string): TWebForm;
var var
localMode: string; localMode: string;
...@@ -438,7 +449,6 @@ begin ...@@ -438,7 +449,6 @@ begin
end; end;
end end
); );
end; end;
procedure TFOrderEntryCuttingDie.btnAddClick(Sender: TObject); procedure TFOrderEntryCuttingDie.btnAddClick(Sender: TObject);
...@@ -513,6 +523,8 @@ var ...@@ -513,6 +523,8 @@ var
data: TJSArray; data: TJSArray;
order, items: TJSObject; order, items: TJSObject;
begin begin
Utils.ShowSpinner('spinner');
try
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetCuttingDieOrder', xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetCuttingDieOrder',
[Order_ID])); [Order_ID]));
order := TJSObject(xdcResponse.Result); order := TJSObject(xdcResponse.Result);
...@@ -522,7 +534,6 @@ begin ...@@ -522,7 +534,6 @@ begin
XDataWebDataSet1.Open; XDataWebDataSet1.Open;
// Check boxes and dates need to be manually set // Check boxes and dates need to be manually set
if not (XDataWebDataSet1staff_fields_order_date.AsString = '') then if not (XDataWebDataSet1staff_fields_order_date.AsString = '') then
dtpOrderDate.Date := StrToDateTime(XDataWebDataSet1staff_fields_order_date.Value) dtpOrderDate.Date := StrToDateTime(XDataWebDataSet1staff_fields_order_date.Value)
else else
...@@ -555,8 +566,14 @@ begin ...@@ -555,8 +566,14 @@ begin
xdwdsQBItem.SetJsonData(items['data']); xdwdsQBItem.SetJsonData(items['data']);
xdwdsQBITEM.Open; xdwdsQBITEM.Open;
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not retrieve order: ' + E.ErrorResult.ErrorMessage);
end;
Utils.HideSpinner('spinner');
end; end;
procedure TFOrderEntryCuttingDie.getCustomer(customerID: string); procedure TFOrderEntryCuttingDie.getCustomer(customerID: string);
// gets a customer from the database then loads the appropiate fields // gets a customer from the database then loads the appropiate fields
var var
......
...@@ -593,7 +593,7 @@ var ...@@ -593,7 +593,7 @@ var
searchOptions, pdfURL: string; searchOptions, pdfURL: string;
jsObject: TJSObject; jsObject: TJSObject;
begin begin
try
// Call the server method to generate the PDF // Call the server method to generate the PDF
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateOrderWebPDF', [orderID])); xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GenerateOrderWebPDF', [orderID]));
jsObject := JS.TJSObject(xdcResponse.Result); jsObject := JS.TJSObject(xdcResponse.Result);
...@@ -602,23 +602,33 @@ begin ...@@ -602,23 +602,33 @@ begin
// Open the PDF in a new browser tab without needing a different form // Open the PDF in a new browser tab without needing a different form
// This method is much faster too, even for large datasets // This method is much faster too, even for large datasets
window.open(pdfURL, '_blank'); window.open(pdfURL, '_blank');
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not generate web order PDF: ' + E.ErrorResult.ErrorMessage);
end;
end; end;
procedure TFOrderEntryWeb.AddWebOrder(orderJSON: TJSONObject); procedure TFOrderEntryWeb.AddWebOrder(orderJSON: TJSONObject);
// sends the order JSON object to the server // sends the order JSON object to the server
var var
Response: TXDataClientResponse; Response: TXDataClientResponse;
jsObj: TJSObject; jsObj: TJSObject;
begin begin
Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddWebOrder', try
[orderJSON.ToString])); Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.AddWebOrder', [orderJSON.ToString]));
jsObj := JS.TJSObject(Response.Result); jsObj := JS.TJSObject(Response.Result);
if mode = 'ADD' then if mode = 'ADD' then
OrderID := String(jsObj.Properties['OrderID']); OrderID := String(jsObj.Properties['OrderID']);
console.log(OrderID); console.log(OrderID);
mode := 'EDIT'; mode := 'EDIT';
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not save web order: ' + E.ErrorResult.ErrorMessage);
end;
end; end;
class function TFOrderEntryWeb.CreateForm(AElementID, orderInfo, customerInfo, mode, info: string): TWebForm; class function TFOrderEntryWeb.CreateForm(AElementID, orderInfo, customerInfo, mode, info: string): TWebForm;
var var
localMode: string; localMode: string;
...@@ -784,6 +794,8 @@ var ...@@ -784,6 +794,8 @@ var
colorListJSON: TJSONArray; colorListJSON: TJSONArray;
items: TJSObject; items: TJSObject;
begin begin
Utils.ShowSpinner('spinner');
try
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetWebOrder', xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetWebOrder',
[Order_ID])); [Order_ID]));
order := TJSObject(xdcResponse.Result); order := TJSObject(xdcResponse.Result);
...@@ -791,6 +803,7 @@ begin ...@@ -791,6 +803,7 @@ begin
XDataWebDataSet1.Close; XDataWebDataSet1.Close;
XDataWebDataSet1.SetJsonData(order); XDataWebDataSet1.SetJsonData(order);
XDataWebDataSet1.Open; XDataWebDataSet1.Open;
if XDataWebDataSet1quantity_and_colors_qty_colors.Value <> '' then if XDataWebDataSet1quantity_and_colors_qty_colors.Value <> '' then
begin begin
colorObject := TJSObject(TJSJSON.parse(XDataWebDataSet1quantity_and_colors_qty_colors.Value)); colorObject := TJSObject(TJSJSON.parse(XDataWebDataSet1quantity_and_colors_qty_colors.Value));
...@@ -803,7 +816,6 @@ begin ...@@ -803,7 +816,6 @@ begin
end; end;
// Dates need to be manually set // Dates need to be manually set
if not (XDataWebDataSet1staff_fields_order_date.AsString = '') then if not (XDataWebDataSet1staff_fields_order_date.AsString = '') then
dtpOrderDate.Date := StrToDateTime(XDataWebDataSet1staff_fields_order_date.Value) dtpOrderDate.Date := StrToDateTime(XDataWebDataSet1staff_fields_order_date.Value)
else else
...@@ -829,12 +841,10 @@ begin ...@@ -829,12 +841,10 @@ begin
dtpPDFDate1.Date := StrToDateTime(XDataWebDataSet1proofing_pdf_date_1.Value) dtpPDFDate1.Date := StrToDateTime(XDataWebDataSet1proofing_pdf_date_1.Value)
else else
dtpPDFDate1.Date := 0; dtpPDFDate1.Date := 0;
if not (XDataWebDataSet1proofing_pdf_date_2.AsString = '') then if not (XDataWebDataSet1proofing_pdf_date_2.AsString = '') then
dtpPDFDate2.Date := StrToDateTime(XDataWebDataSet1proofing_pdf_date_2.Value) dtpPDFDate2.Date := StrToDateTime(XDataWebDataSet1proofing_pdf_date_2.Value)
else else
dtpPDFDate2.Date := 0; dtpPDFDate2.Date := 0;
if not (XDataWebDataSet1proofing_pdf_date_3.AsString = '') then if not (XDataWebDataSet1proofing_pdf_date_3.AsString = '') then
dtpPDFDate3.Date := StrToDateTime(XDataWebDataSet1proofing_pdf_date_3.Value) dtpPDFDate3.Date := StrToDateTime(XDataWebDataSet1proofing_pdf_date_3.Value)
else else
...@@ -844,12 +854,10 @@ begin ...@@ -844,12 +854,10 @@ begin
dtpInkJetDate1.Date := StrToDateTime(XDataWebDataSet1proofing_ink_jet_date_1.Value) dtpInkJetDate1.Date := StrToDateTime(XDataWebDataSet1proofing_ink_jet_date_1.Value)
else else
dtpInkJetDate1.Date := 0; dtpInkJetDate1.Date := 0;
if not (XDataWebDataSet1proofing_ink_jet_date_2.AsString = '') then if not (XDataWebDataSet1proofing_ink_jet_date_2.AsString = '') then
dtpInkJetDate2.Date := StrToDateTime(XDataWebDataSet1proofing_ink_jet_date_2.Value) dtpInkJetDate2.Date := StrToDateTime(XDataWebDataSet1proofing_ink_jet_date_2.Value)
else else
dtpInkJetDate2.Date := 0; dtpInkJetDate2.Date := 0;
if not (XDataWebDataSet1proofing_ink_jet_date_3.AsString = '') then if not (XDataWebDataSet1proofing_ink_jet_date_3.AsString = '') then
dtpInkJetDate3.Date := StrToDateTime(XDataWebDataSet1proofing_ink_jet_date_3.Value) dtpInkJetDate3.Date := StrToDateTime(XDataWebDataSet1proofing_ink_jet_date_3.Value)
else else
...@@ -859,18 +867,15 @@ begin ...@@ -859,18 +867,15 @@ begin
dtpColorContractDate1.Date := StrToDateTime(XDataWebDataSet1proofing_color_contrac_date_1.Value) dtpColorContractDate1.Date := StrToDateTime(XDataWebDataSet1proofing_color_contrac_date_1.Value)
else else
dtpColorContractDate1.Date := 0; dtpColorContractDate1.Date := 0;
if not (XDataWebDataSet1proofing_color_contrac_date_2.AsString = '') then if not (XDataWebDataSet1proofing_color_contrac_date_2.AsString = '') then
dtpColorContractDate2.Date := StrToDateTime(XDataWebDataSet1proofing_color_contrac_date_2.Value) dtpColorContractDate2.Date := StrToDateTime(XDataWebDataSet1proofing_color_contrac_date_2.Value)
else else
dtpColorContractDate2.Date := 0; dtpColorContractDate2.Date := 0;
if not (XDataWebDataSet1proofing_digital_color_date_1.AsString = '') then if not (XDataWebDataSet1proofing_digital_color_date_1.AsString = '') then
dtpDigitalColorDate.Date := StrToDateTime(XDataWebDataSet1proofing_digital_color_date_1.Value) dtpDigitalColorDate.Date := StrToDateTime(XDataWebDataSet1proofing_digital_color_date_1.Value)
else else
dtpDigitalColorDate.Date := 0; dtpDigitalColorDate.Date := 0;
if mode = 'EDIT' then if mode = 'EDIT' then
begin begin
CustomerID := XDataWebDataSet1COMPANY_ID.AsString; CustomerID := XDataWebDataSet1COMPANY_ID.AsString;
...@@ -883,9 +888,15 @@ begin ...@@ -883,9 +888,15 @@ begin
items := TJSObject(order['ITEMS']); items := TJSObject(order['ITEMS']);
xdwdsQBItem.SetJsonData(items['data']); xdwdsQBItem.SetJsonData(items['data']);
xdwdsQBITEM.Open; xdwdsQBITEM.Open;
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not retrieve order: ' + E.ErrorResult.ErrorMessage);
end;
Utils.HideSpinner('spinner');
end; end;
procedure TFOrderEntryWeb.getCustomer(customerID: string); procedure TFOrderEntryWeb.getCustomer(customerID: string);
// gets a customer from the database then loads the appropiate fields // gets a customer from the database then loads the appropiate fields
var var
......
object FViewOrders: TFViewOrders object FViewOrders: TFViewOrders
Width = 676 Width = 676
Height = 480 Height = 480
Caption = 'main.errorpanel'
CSSLibrary = cssBootstrap CSSLibrary = cssBootstrap
ElementFont = efCSS ElementFont = efCSS
Font.Charset = DEFAULT_CHARSET Font.Charset = DEFAULT_CHARSET
......
...@@ -13,7 +13,7 @@ uses ...@@ -13,7 +13,7 @@ uses
WEBLib.Forms, WEBLib.Dialogs, WEBLib.Menus, WEBLib.ExtCtrls, WEBLib.StdCtrls, WEBLib.Forms, WEBLib.Dialogs, WEBLib.Menus, WEBLib.ExtCtrls, WEBLib.StdCtrls,
WEBLib.JSON, Auth.Service, XData.Web.Client, WebLib.Storage, WEBLib.JSON, Auth.Service, XData.Web.Client, WebLib.Storage,
ConnectionModule, App.Types, Vcl.StdCtrls, Vcl.Controls, WEBLib.DBCtrls, ConnectionModule, App.Types, Vcl.StdCtrls, Vcl.Controls, WEBLib.DBCtrls,
XData.Web.JsonDataset, WEBLib.DB, Data.DB, XData.Web.Dataset, XData.Web.JsonDataset, WEBLib.DB, Data.DB, XData.Web.Dataset, XData.Web.DatasetCommon,
WEBLib.Grids; WEBLib.Grids;
type type
...@@ -156,6 +156,8 @@ var ...@@ -156,6 +156,8 @@ var
searchOptions, pdfURL: string; searchOptions, pdfURL: string;
jsObject: TJSObject; jsObject: TJSObject;
begin begin
Utils.ShowSpinner('spinner');
try
searchOptions := edtSearch.Text; searchOptions := edtSearch.Text;
// Call the server method to generate the PDF // Call the server method to generate the PDF
...@@ -163,16 +165,16 @@ begin ...@@ -163,16 +165,16 @@ begin
jsObject := JS.TJSObject(xdcResponse.Result); jsObject := JS.TJSObject(xdcResponse.Result);
pdfURL := JS.toString(jsObject.Properties['value']); pdfURL := JS.toString(jsObject.Properties['value']);
// Open the PDF in a new browser tab without needing a different form // Open the PDF in a new browser tab
// This method is much faster too, even for large datasets
window.open(pdfURL, '_blank'); window.open(pdfURL, '_blank');
begin except
Utils.HideSpinner('Spinner'); on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not generate report PDF: ' + E.ErrorResult.ErrorMessage);
end; end;
Utils.HideSpinner('spinner');
end; end;
procedure TFViewOrders.WebButton1Click(Sender: TObject); procedure TFViewOrders.WebButton1Click(Sender: TObject);
begin begin
if OrderID <> '' then if OrderID <> '' then
...@@ -651,57 +653,56 @@ begin ...@@ -651,57 +653,56 @@ begin
end); end);
PageItem.appendChild(PageLink); PageItem.appendChild(PageLink);
PaginationElement.appendChild(PageItem); PaginationElement.appendChild(PageItem);
end; end;
procedure TFViewOrders.GetOrders(searchOptions: string); procedure TFViewOrders.GetOrders(searchOptions: string);
// retrieves a list of orders that fit a given search criteria
// searchOptions: search info to be sent to the server
var var
xdcResponse: TXDataClientResponse; xdcResponse: TXDataClientResponse;
orderList: TJSObject; orderList: TJSObject;
orderListLength: integer; orderListLength, TotalPages: Integer;
TotalPages: integer;
begin begin
Utils.ShowSpinner('spinner'); Utils.ShowSpinner('spinner');
if PageNumber > 0 then try
try
xdcResponse := await(XDataWebClient1.RawInvokeAsync(
'ILookupService.GetOrders', [searchOptions]));
if Assigned(xdcResponse.Result) then
begin begin
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetOrders', [searchOptions]));
orderList := TJSObject(xdcResponse.Result); orderList := TJSObject(xdcResponse.Result);
// Load data into the dataset
xdwdsOrders.Close; xdwdsOrders.Close;
xdwdsOrders.SetJsonData(orderList['data']); xdwdsOrders.SetJsonData(orderList['data']);
xdwdsOrders.Open; xdwdsOrders.Open;
orderListLength := integer(orderList['count']); orderListLength := Integer(orderList['count']);
TotalPages := ( (orderListLength + PageSize - 1) div PageSize); TotalPages := (orderListLength + PageSize - 1) div PageSize;
GeneratePagination(TotalPages);
// Update label
if orderListLength = 0 then if orderListLength = 0 then
begin lblEntries.Caption := 'No entries found'
lblEntries.Caption := 'No entries found';
end
else if (PageNumber * PageSize) < orderListLength then else if (PageNumber * PageSize) < orderListLength then
begin lblEntries.Caption := Format('Showing entries %d - %d of %d',
lblEntries.Caption := 'Showing entries ' + IntToStr((PageNumber - 1) * PageSize + 1) + [(PageNumber - 1) * PageSize + 1, PageNumber * PageSize, orderListLength])
' - ' + IntToStr(PageNumber * PageSize) + else
' of ' + IntToStr(orderListLength); lblEntries.Caption := Format('Showing entries %d - %d of %d',
end [(PageNumber - 1) * PageSize + 1, orderListLength, orderListLength]);
else if (PageNumber * PageSize) >= orderListLength then
begin
lblEntries.Caption := 'Showing entries ' + IntToStr((PageNumber - 1) * PageSize + 1) +
' - ' + IntToStr(orderListLength) +
' of ' + IntToStr(orderListLength);
end; end;
// Optional: Continue using pagination if needed except
GeneratePagination(TotalPages); on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not retrieve orders: ' + E.ErrorResult.ErrorMessage);
end;
finally
Utils.HideSpinner('spinner'); Utils.HideSpinner('spinner');
end; end;
end; end;
procedure TFViewOrders.btnAddOrderClick(Sender: TObject); procedure TFViewOrders.btnAddOrderClick(Sender: TObject);
begin begin
ShowAddOrderForm(); ShowAddOrderForm();
......
...@@ -97,21 +97,26 @@ var ...@@ -97,21 +97,26 @@ var
customerList: TJSObject; customerList: TJSObject;
i: integer; i: integer;
begin begin
try
// Fetch data from XData service // Fetch data from XData service
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.getQBCustomers', [])); xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.getQBCustomers', []));
customerList := TJSObject(xdcResponse.Result); customerList := TJSObject(xdcResponse.Result);
// Load data into TXDataWebDataset // Load data into TXDataWebDataset
xdwdsCustomers.Close; xdwdsCustomers.Close;
xdwdsCustomers.SetJsonData(customerList); xdwdsCustomers.SetJsonData(customerList);
xdwdsCustomers.Open; xdwdsCustomers.Open;
// Manually populate the grid // Manually populate the grid
PopulateGridManually; PopulateGridManually;
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not retrieve QuickBooks customers: ' + E.ErrorResult.ErrorMessage);
end;
Utils.HideSpinner('spinner'); Utils.HideSpinner('spinner');
end; end;
procedure TFSelectCustomer.PopulateGridManually; procedure TFSelectCustomer.PopulateGridManually;
// populates the grid with customers manually. // populates the grid with customers manually.
var var
......
...@@ -6,7 +6,7 @@ uses ...@@ -6,7 +6,7 @@ uses
System.SysUtils, System.Classes, Web, WEBLib.Graphics, WEBLib.Forms, WEBLib.Dialogs, System.SysUtils, System.Classes, Web, WEBLib.Graphics, WEBLib.Forms, WEBLib.Dialogs,
Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls, WEBLib.Controls, WEBLib.Grids, WebLib.Lists, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls, WEBLib.Controls, WEBLib.Grids, WebLib.Lists,
XData.Web.Client, WEBLib.ExtCtrls, DB, XData.Web.JsonDataset, XData.Web.Client, WEBLib.ExtCtrls, DB, XData.Web.JsonDataset,
XData.Web.Dataset, XData.Web.Connection, Vcl.Forms, WEBLib.DBCtrls, JS; XData.Web.Dataset, XData.Web.Connection, Vcl.Forms, WEBLib.DBCtrls, JS, Utils;
type type
TFViewUsers = class(TWebForm) TFViewUsers = class(TWebForm)
...@@ -330,10 +330,11 @@ var ...@@ -330,10 +330,11 @@ var
data: TJSArray; data: TJSArray;
user: TJSObject; user: TJSObject;
userListLength: integer; userListLength: integer;
begin begin
if PageNumber > 0 then if PageNumber > 0 then
begin begin
Utils.ShowSpinner('spinner');
try
xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetUsers', xdcResponse := await(XDataWebClient1.RawInvokeAsync('ILookupService.GetUsers',
[searchOptions])); [searchOptions]));
...@@ -368,6 +369,11 @@ begin ...@@ -368,6 +369,11 @@ begin
' of ' + IntToStr(userListLength); ' of ' + IntToStr(userListLength);
end; end;
GeneratePagination(TotalPages); GeneratePagination(TotalPages);
except
on E: EXDataClientRequestException do
Utils.ShowErrorModal('Could not retrieve users: ' + E.ErrorResult.ErrorMessage);
end;
Utils.HideSpinner('spinner');
end; end;
end; end;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<FrameworkType>VCL</FrameworkType> <FrameworkType>VCL</FrameworkType>
<MainSource>webKGOrders.dpr</MainSource> <MainSource>webKGOrders.dpr</MainSource>
<Base>True</Base> <Base>True</Base>
<Config Condition="'$(Config)'==''">Release</Config> <Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform> <Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms> <TargetedPlatforms>1</TargetedPlatforms>
<AppType>Application</AppType> <AppType>Application</AppType>
...@@ -208,7 +208,6 @@ ...@@ -208,7 +208,6 @@
<DCCReference Include="Utils.pas"/> <DCCReference Include="Utils.pas"/>
<DCCReference Include="View.AddItem.pas"> <DCCReference Include="View.AddItem.pas">
<Form>fViewAddItem</Form> <Form>fViewAddItem</Form>
<FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass> <DesignClass>TWebForm</DesignClass>
</DCCReference> </DCCReference>
<None Include="index.html"/> <None Include="index.html"/>
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
MemoLogLevel=3 MemoLogLevel=3
FileLogLevel=5 FileLogLevel=5
webClientVersion=0.9.4 webClientVersion=0.9.4
LogFileNum=710 LogFileNum=721
[Database] [Database]
Server=192.168.159.131 --Server=192.168.159.131
--Server=192.168.102.130 Server=192.168.102.130
--Server=192.168.75.133 --Server=192.168.75.133
Database=kg_order_entry Database=kg_order_entry
Username=root Username=root
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment