Commit 9bbaf56d by Cam Hayes

Finished Copy and delete in the ways discussed with dave.

Delete doesn't delete every relationship with the order in the database so there will still be clutter in the Status Tables.
parent 7bb7fd61
object FViewMain: TFViewMain
Width = 1322
Height = 764
CSSLibrary = cssBootstrap
Color = clWhite
ElementFont = efCSS
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
FormStyle = fsNormal
Height = 764
Left = 0
ParentFont = False
OnCreate = WebFormCreate
TabOrder = 0
Top = 0
Width = 1322
object lblUsername: TWebLabel
Left = 529
Top = 4
Width = 59
Height = 14
Caption = 'lblUsername'
ElementID = 'view.main.username'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 21
Left = 529
Top = 4
HeightPercent = 100.000000000000000000
Transparent = False
Width = 80
WidthPercent = 100.000000000000000000
end
object wllblUserProfile: TWebLinkLabel
Caption = ' User Profile'
ElementID = 'dropdown.menu.userprofile'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 0
Left = 529
OnClick = wllblUserProfileClick
Top = 21
Width = 0
Width = 59
Height = 14
ElementID = 'dropdown.menu.userprofile'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = wllblUserProfileClick
Caption = ' User Profile'
end
object wllblLogout: TWebLinkLabel
Caption = ' Logout'
ElementID = 'dropdown.menu.logout'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 0
Left = 551
OnClick = wllblLogoutClick
Top = 143
Width = 0
Width = 36
Height = 14
ElementID = 'dropdown.menu.logout'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = wllblLogoutClick
Caption = ' Logout'
end
object lblHome: TWebLinkLabel
Caption = 'Home'
ElementID = 'dropdown.menu.home'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 0
Left = 556
OnClick = lblHomeClick
Top = 38
Width = 0
Width = 27
Height = 14
ElementID = 'dropdown.menu.home'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = lblHomeClick
Caption = 'Home'
end
object lblAppTitle: TWebLabel
Left = 57
Top = 31
Width = 75
Height = 14
Caption = 'Koehler-Gibson'
ElementID = 'view.main.apptitle'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 40
Left = 57
Top = 31
HeightPercent = 100.000000000000000000
Transparent = False
Width = 202
WidthPercent = 100.000000000000000000
end
object lblItemsList: TWebLinkLabel
Caption = 'Items'
ElementFont = efCSS
ElementID = 'dropdown.menu.itemlist'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 32
Left = 560
OnClick = lblItemsListClick
Top = 85
Width = 95
Width = 25
Height = 14
ElementID = 'dropdown.menu.itemlist'
ElementFont = efCSS
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = lblItemsListClick
Caption = 'Items'
end
object lblUsers: TWebLinkLabel
Caption = 'Users'
ElementFont = efCSS
ElementID = 'dropdown.menu.users'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 0
Left = 561
OnClick = lblUsersClick
Top = 108
Width = 0
Width = 29
Height = 14
ElementID = 'dropdown.menu.users'
ElementFont = efCSS
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = lblUsersClick
Caption = 'Users'
end
object lblorders: TWebLabel
Left = 556
Top = 52
Width = 34
Height = 14
Caption = 'Orders'
ElementFont = efCSS
ElementID = 'lblorders'
ElementFont = efCSS
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 32
HeightStyle = ssAuto
Left = 556
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = lblordersClick
Top = 52
Width = 104
end
object lblCustomers: TWebLabel
Left = 540
Top = 69
Width = 52
Height = 14
Caption = 'Customers'
ElementFont = efCSS
ElementID = 'lblcustomers'
ElementFont = efCSS
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 32
HeightStyle = ssAuto
Left = 540
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = lblCustomersClick
Top = 69
Width = 131
end
object lblQuickbooks: TWebLabel
Left = 546
Top = 125
Width = 57
Height = 14
Caption = 'QuickBooks'
ElementFont = efCSS
ElementID = 'lblquickbooks'
ElementFont = efCSS
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 32
HeightStyle = ssAuto
Left = 546
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = lblQuickbooksClick
Top = 125
Width = 139
end
object WebPanel1: TWebPanel
ChildOrder = 3
Color = clBtnFace
object lblVersion: TWebLabel
Left = 358
Top = 209
Width = 47
Height = 14
Caption = 'lblVersion'
ElementID = 'view.main.version'
ElementFont = efCSS
ElementID = 'main.webpanel'
ElementPosition = epIgnore
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 0
ElementPosition = epRelative
HeightStyle = ssAuto
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
end
object WebPanel1: TWebPanel
Left = 77
Role = 'null'
TabOrder = 0
TabStop = False
Top = 112
Width = 1322
Height = 0
ElementID = 'main.webpanel'
HeightStyle = ssAuto
WidthStyle = ssAuto
ChildOrder = 3
ElementFont = efCSS
ElementPosition = epIgnore
Role = 'null'
TabOrder = 0
end
object WebMemo1: TWebMemo
AutoSize = False
Color = clWindow
Left = 77
Top = 479
Width = 471
Height = 83
ElementID = 'main.debugmemo'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 83
Left = 77
HeightPercent = 100.000000000000000000
Lines.Strings = (
'WebMemo1')
ReadOnly = False
Role = 'null'
SelLength = 0
SelStart = 0
ShowFocus = True
TabOrder = 0
Top = 479
Visible = False
Width = 471
end
object lblVersion: TWebLabel
Caption = 'lblVersion'
ElementFont = efCSS
ElementID = 'view.main.version'
ElementPosition = epRelative
Font.Charset = ANSI_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Arial'
Font.Size = 8
Font.Style = []
Height = 21
HeightStyle = ssAuto
Left = 358
Top = 209
Width = 60
WidthPercent = 100.000000000000000000
end
object WebMessageDlg1: TWebMessageDlg
Left = 47
Top = 232
Width = 24
Height = 24
Buttons = []
CustomButtons = <>
DialogText.Strings = (
'Warning'
......@@ -267,13 +201,7 @@ object FViewMain: TFViewMain
'No to all'
'Help'
'Close')
Height = 24
Left = 47
Opacity = 0.200000000000000000
Top = 232
Width = 24
Left = 47
Top = 232
end
object XDataWebClient: TXDataWebClient
Connection = DMConnection.ApiConnection
......
......@@ -57,6 +57,8 @@ type
procedure ViewOrderEntryCuttingDie(orderInfo, customerInfo, mode: string);
procedure ViewOrders(info: string);
procedure ShowUserForm(Info: string);
var
search: string;
end;
var
......
......@@ -247,7 +247,7 @@ object FOrderEntryCorrugated: TFOrderEntryCorrugated
Text = ''
end
object edtCompanyName: TWebDBEdit
Left = 24
Left = 18
Top = 92
Width = 300
Height = 22
......@@ -1159,6 +1159,7 @@ object FOrderEntryCorrugated: TFOrderEntryCorrugated
ElementID = 'btndelete'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnDeleteClick
end
object btnClose: TWebButton
Left = 1094
......
......@@ -209,6 +209,7 @@ type
procedure btnConfirmClick(Sender: TObject);
[async] procedure AddCorrugatedOrder(orderJSON: TJSONObject);
[async] procedure GenerateReportPDF;
[async] procedure DelOrder();
procedure btnCancelClick(Sender: TObject);
procedure btnPDFClick(Sender: TObject);
procedure btnCopyClick(Sender: TObject);
......@@ -216,6 +217,7 @@ type
procedure XDataWebDataSet1AfterEdit(DataSet: TDataSet);
procedure btnCloseClick(Sender: TObject);
procedure btnCloseNotificationClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
private
FAgencyCode: string;
FCurrentReportType: string;
......@@ -371,7 +373,7 @@ begin
orderJSON.AddPair('mode', mode);
if mode = 'EDIT' then
orderJSON.AddPair('ORDER_ID', orderID);
AddCorrugatedOrder(orderJSON);
if mode = 'ADD' then
ShowNotification('Success:Order Added Successfully!')
else
......@@ -382,15 +384,31 @@ end;
procedure TFOrderEntryCorrugated.btnConfirmClick(Sender: TObject);
// Converts all the information on the page into a JSON to then send to the server
begin
//When confirm is clicked should we then switch to edit mode with the ID? should the server send back an OrderID?
sendOrderToServer();
window.scrollTo(0, 0);
end;
procedure TFOrderEntryCorrugated.btnCopyClick(Sender: TObject);
begin
mode := 'ADD';
sendOrderToServer();
// Should we then open the "new" order.
//sendOrderToServer();
window.scrollTo(0, 0);
dtpOrderDate.Date := 0;
dtpProofDate.Date := 0;
dtpArtDue.Date := 0;
dtpPlateDue.Date := 0;
dtpMountDue.Date := 0;
dtpShipDate.Date := 0;
dtpApprovedDate.Date := 0;
ShowNotification('Success:Order Successfully Copied');
window.scrollTo(0, 0);
end;
procedure TFOrderEntryCorrugated.btnDeleteClick(Sender: TObject);
begin
//mode := 'DEL';
//sendOrderToServer();
DelOrder();
end;
procedure TFOrderEntryCorrugated.btnPDFClick(Sender: TObject);
......@@ -435,6 +453,14 @@ begin
console.log(OrderID);
end;
procedure TFOrderEntryCorrugated.DelOrder();
var
Response: TXDataClientResponse;
begin
Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.DelOrder',
[OrderID, 'corrugated', JS.toString(AuthService.TokenPayload.Properties['user_id'])]));
end;
class function TFOrderEntryCorrugated.CreateForm(AElementID, orderInfo, customerInfo, mode: string): TWebForm;
var
localMode: string;
......@@ -515,13 +541,15 @@ end;
procedure TFOrderEntryCorrugated.btnCancelClick(Sender: TObject);
begin
If mode = 'EDIT' then
// need to get this button working properly edit version does not work correctly
if mode = 'EDIT' then
begin
getOrder(OrderID);
ShowNotification('Failure:Changes Discarded');
end
else
FViewMain.ViewOrderEntryCorrugated('', CustomerID, 'ADD');
window.scrollTo(0, 0);
end;
procedure TFOrderEntryCorrugated.btnCloseClick(Sender: TObject);
......
object FOrderEntryWeb: TFOrderEntryWeb
Width = 1015
Width = 1261
Height = 628
OnShow = WebFormShow
object WebLabel2: TWebLabel
......@@ -1078,7 +1078,7 @@ object FOrderEntryWeb: TFOrderEntryWeb
Top = 568
Width = 96
Height = 25
Caption = 'Confirm'
Caption = 'Save'
ChildOrder = 79
ElementID = 'btnconfirm'
HeightPercent = 100.000000000000000000
......@@ -1086,7 +1086,7 @@ object FOrderEntryWeb: TFOrderEntryWeb
OnClick = btnConfirmClick
end
object btnPDF: TWebButton
Left = 867
Left = 963
Top = 568
Width = 96
Height = 25
......@@ -1098,7 +1098,7 @@ object FOrderEntryWeb: TFOrderEntryWeb
OnClick = btnPDFClick
end
object btnCancel: TWebButton
Left = 761
Left = 853
Top = 568
Width = 96
Height = 25
......@@ -1186,6 +1186,42 @@ object FOrderEntryWeb: TFOrderEntryWeb
DataField = 'print_orientation_print_orient'
DataSource = WebDataSource1
end
object btnCopy: TWebButton
Left = 751
Top = 568
Width = 96
Height = 25
Caption = 'Copy'
ChildOrder = 91
ElementID = 'btncopy'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnCopyClick
end
object btnDelete: TWebButton
Left = 1065
Top = 568
Width = 96
Height = 25
Caption = 'Delete'
ChildOrder = 79
ElementID = 'btndelete'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnDeleteClick
end
object btnClose: TWebButton
Left = 1063
Top = 523
Width = 96
Height = 25
Caption = 'Close'
ChildOrder = 80
ElementID = 'btnclose'
HeightPercent = 100.000000000000000000
WidthPercent = 100.000000000000000000
OnClick = btnCloseClick
end
object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 160
......
......@@ -357,13 +357,22 @@
</div>
<div class="row">
<div class="col-auto">
<button id="btnconfirm" class="btn btn-primary btn-sm float-end my-2">Confirm</button>
<button id="btnconfirm" class="btn btn-primary btn-sm float-end my-2">Save</button>
</div>
<div class="col-auto">
<button id="btncancel" class="btn btn-primary btn-sm float-end my-2">Cancel</button>
</div>
<div class="col-auto">
<button id="btncopy" class="btn btn-primary btn-sm float-end my-2">Copy</button>
</div>
<div class="col-auto">
<button id="btnpdf" class="btn btn-primary btn-sm float-end my-2">PDF</button>
</div>
<div class="col-auto">
<button id="btndelete" class="btn btn-primary btn-sm float-end my-2">Delete</button>
</div>
<div class="col-auto">
<button id="btnclose" class="btn btn-primary btn-sm float-end my-2">Close</button>
</div>
</div>
</div>
......@@ -198,6 +198,9 @@ type
WebDBComboBox3: TWebDBComboBox;
wcbPrint: TWebDBComboBox;
WebDBComboBox4: TWebDBComboBox;
btnCopy: TWebButton;
btnDelete: TWebButton;
btnClose: TWebButton;
procedure WebFormCreate(Sender: TObject);
procedure HideNotification();
procedure ShowNotification(Notification: string);
......@@ -212,6 +215,11 @@ type
procedure btnCancelClick(Sender: TObject);
procedure btnPDFClick(Sender: TObject);
[async] procedure GenerateReportPDF;
procedure SendOrderToServer;
procedure btnCopyClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
[async] procedure DelOrder;
private
FAgencyCode: string;
FCurrentReportType: string;
......@@ -235,6 +243,46 @@ uses
View.Home, View.Main;
procedure TFOrderEntryWeb.btnConfirmClick(Sender: TObject);
begin
SendOrderToServer();
window.scrollTo(0, 0);
end;
procedure TFOrderEntryWeb.btnCopyClick(Sender: TObject);
begin
mode := 'ADD';
dtpOrderDate.Date := 0;
dtpProofDate.Date := 0;
dtpArtDue.Date := 0;
dtpPlateDue.Date := 0;
dtpShipDate.Date := 0;
dtpPDFDate1.Date := 0;
dtpPDFDate2.Date := 0;
dtpPDFDate3.Date := 0;
dtpInkJetDate1.Date := 0;
dtpInkJetDate2.Date := 0;
dtpInkJetDate3.Date := 0;
dtpColorContractDate1.Date := 0;
dtpColorContractDate2.Date := 0;
dtpDigitalColorDate.Date := 0;
ShowNotification('Success:Order Successfully Copied');
window.scrollTo(0, 0);
end;
procedure TFOrderEntryWeb.btnDeleteClick(Sender: TObject);
begin
DelOrder();
end;
[async] procedure TFOrderEntryWeb.DelOrder();
var
Response: TXDataClientResponse;
begin
Response := await(XDataWebClient1.RawInvokeAsync('ILookupService.DelOrder',
[OrderID, 'web', JS.toString(AuthService.TokenPayload.Properties['user_id'])]));
end;
procedure TFOrderEntryWeb.SendOrderToServer();
// Converts all the information on the page into a JSON to then send to the server
var
colorList: TJSONArray;
......@@ -249,12 +297,10 @@ var
Field: TField;
Response: TXDataClientResponse;
begin
console.log('confirm');
orderJSON := TJSONObject.Create;
colorList := TJSONArray.Create;
container := document.getElementById('additionalFields');
colorCollection := container.children;
for I := 0 to colorCollection.length - 1 do
begin
colorJSON := TJSONObject.Create;
......@@ -323,8 +369,7 @@ begin
else
info := 'Success:Order Successfully Added';
AddWebOrder(orderJSON);
FViewMain.ViewOrders(info);
ShowNotification(info);
end;
procedure TFOrderEntryWeb.btnPDFClick(Sender: TObject);
......@@ -332,7 +377,7 @@ begin
GenerateReportPDF;
end;
[async] procedure TFOrderEntryWeb.GenerateReportPDF;
procedure TFOrderEntryWeb.GenerateReportPDF;
// sends the search to the server which then sends back a pdf of the results
var
xdcResponse: TXDataClientResponse;
......@@ -441,6 +486,11 @@ end;
procedure TFOrderEntryWeb.btnCancelClick(Sender: TObject);
begin
//FViewMain.ViewOrders('');
end;
procedure TFOrderEntryWeb.btnCloseClick(Sender: TObject);
begin
FViewMain.ViewOrders('');
end;
......@@ -619,10 +669,29 @@ begin
end;
procedure TFOrderEntryWeb.ShowNotification(Notification: string);
var
splitNotification: TArray<string>;
begin
if Notification <> '' then
begin
lblMessage.Caption := Notification;
splitNotification := Notification.Split([':']);
if(splitNotification[0] = 'Success') then
begin
asm
var messageDiv = document.getElementById('view.login.message');
messageDiv.classList.remove('alert-danger');
messageDiv.classList.add('alert-success');
end;
end
else
begin
asm
var messageDiv = document.getElementById('view.login.message');
messageDiv.classList.remove('alert-success');
messageDiv.classList.add('alert-danger');
end;
end;
lblMessage.Caption := splitNotification[1];
pnlMessage.ElementHandle.hidden := False;
end;
end;
......
......@@ -624,7 +624,7 @@ begin
xdwdsOrders.Close;
xdwdsOrders.SetJsonData(orderList['data']);
xdwdsOrders.Open;
wdbtcOrders.HideColumn(0);
//wdbtcOrders.HideColumn(0);
asm
endSpinner();
......
......@@ -251,7 +251,7 @@ object FSearch: TFSearch
Top = 579
Width = 96
Height = 25
Caption = 'Confirm'
Caption = 'Search'
ChildOrder = 7
ElementClassName = 'btn btn-secondary'
ElementFont = efCSS
......
......@@ -277,15 +277,11 @@ begin
// Set up column headers
TMSFNCGrid1.ColumnCount := 4;
TMSFNCGrid1.RowCount := 1;
TMSFNCGrid1.Cells[0, 0] := 'ID';
TMSFNCGrid1.Cells[1, 0] := 'Short Name';
TMSFNCGrid1.Cells[0, 0] := 'DBID';
TMSFNCGrid1.Cells[1, 0] := 'ID';
TMSFNCGrid1.Cells[2, 0] := 'Name';
TMSFNCGrid1.Cells[3, 0] := 'Address';
// TMSFNCGrid1.ColumnWidths[0] := 40;
// TMSFNCGrid1.ColumnWidths[1] := 80;
// TMSFNCGrid1.ColumnWidths[2] := 250;
// Populate the grid with data from the dataset
xdwdsCustomers.First;
RowIndex := 1;
......
......@@ -380,6 +380,7 @@ type
function AddUser(userInfo: string): string;
function AddItem(itemInfo: string): string;
function DelUser(username: string): string;
function DelOrder(orderID, orderType, UserID: string): TJSONObject;
function EditUser(const editOptions: string): string;
function AddCorrugatedOrder(orderInfo: string): TJSONObject;
function AddWebOrder(orderInfo: string): TJSONObject;
......
......@@ -19,7 +19,8 @@ uses
iexToolbars, iexUserInteractions, imageenio, imageenproc, QuickRpt, QRCtrls,
dbimageen, Vcl.ExtCtrls, ieview, imageenview, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdFTP,
iexProcEffects, frxDBSet, frxExportBaseDialog, frCoreClasses, rOrderList, rOrderCorrugated, Common.Logging;
iexProcEffects, frxDBSet, frxExportBaseDialog, frCoreClasses, rOrderList, rOrderCorrugated, Common.Logging,
DateUtils;
type
......@@ -50,6 +51,7 @@ type
function AddCorrugatedOrder(orderInfo: string): TJSONObject;
function AddWebOrder(orderInfo: string): TJSONObject;
function AddCuttingDieOrder(orderInfo: string): TJSONObject;
function delOrder(OrderID, OrderType, UserID: string): TJSONObject;
function GenerateSubQuery(currStatus: string): string;
......@@ -1420,7 +1422,6 @@ begin
result := 'success';
except
on E: Exception do
// This block will catch any exception derived from the Exception class
logger.Log(5, 'An error occurred when setting status: ' + E.Message);
end;
......@@ -1727,8 +1728,132 @@ begin
end;
end;
function TLookupService.delOrder(OrderID, orderType, UserID: string): TJSONObject;
var
table: string;
table2: string;
sql: string;
CorrugatedOrder: TFullOrder;
WebOrder: TWebOrder;
CuttingDieOrder: TCuttingDie;
DateFormat: TFormatSettings;
JSONData: TJSONObject;
JSONArray: TJSONArray;
Pair: TJSONPair;
Field: TField;
ORDER_ID: string;
mode: string;
stream: TStringStream;
RevisionID: integer;
JSONValue: TJSONValue;
JSONObject: TJSONObject;
DataObject: TJSONObject;
begin
if orderType = 'corrugated' then
begin
table := 'corrugated_plate_orders';
table2 := 'corrugated_plate_orders_revisions';
end
else if orderType = 'web' then
begin
table := 'web_plate_orders';
table2 := 'web_plate_orders_revisions';
end
else
begin
table := 'cutting_die_orders';
table2 := 'cutting_die_orders_revisions';
end;
stream := TStringStream.Create('', TEncoding.UTF8);
DateFormat := TFormatSettings.Create;
DateFormat.ShortDateFormat := 'yyyy-mm-dd';
DateFormat.DateSeparator := '-';
//Update RevisionID
SQL := 'UPDATE idfield set KEYVALUE = KEYVALUE + 1 WHERE KEYNAME = ' + quotedStr('GEN_ORDER_REVISION_ID');
OrdersDB.UniQuery1.SQL.Text := SQL;
OrdersDB.UniQuery1.ExecSQL;
//Retrieve updated RevisionID
SQL := 'select KEYVALUE from idfield where KEYNAME = ' + quotedStr('GEN_ORDER_REVISION_ID');
doQuery(OrdersDB.UniQuery1, SQL);
RevisionID := OrdersDB.UniQuery1.FieldByName('KEYVALUE').AsInteger;
// Convert Order into JSON
SQL := 'select * from ' + table + ' where ORDER_ID = ' + OrderID;
doQuery(ordersDB.UniQuery1, SQL);
ordersDB.UniQuery1.SaveToJSON(stream);
stream.Position := 0;
JSONValue := TJSONObject.ParseJSONValue(Stream.DataString);
if not Assigned(JSONValue) then
raise Exception.Create('Invalid JSON content');
try
if not (JSONValue is TJSONObject) then
raise Exception.Create('Expected JSON object');
JSONObject := TJSONObject(JSONValue);
// Get the "data" object
if not JSONObject.TryGetValue('data', DataObject) then
raise Exception.Create('Missing "data" object in JSON');
// Get the "rows" array
if not DataObject.TryGetValue('rows', JSONArray) then
raise Exception.Create('Missing "rows" array in JSON data');
JSONData := JSONArray.Items[0] as TJSONObject;
SQL := 'select * from ' + table2 + ' where ORDER_ID = 0 and ORDER_ID <> 0';
doQuery(ordersDB.UniQuery1, SQL);
try
ordersDB.UniQuery1.Insert;
for Pair in JSONData do
begin
Field := ordersDB.UniQuery1.FindField(Pair.JsonString.Value); // Checks if the field exists in the dataset
if Assigned(Field) then
begin
// handles any dates or datetimes
if (Field is TDateTimeField) and (Pair.JsonValue.Value <> '') then
TDateTimeField(Field).AsDateTime := ISO8601ToDate(Pair.JsonValue.Value, False)
else if Pair.JsonValue.Value <> '' then
Field.AsString := Pair.JsonValue.Value;
end;
end;
ordersDB.UniQuery1.FieldByName('ORDER_ID').AsString := OrderID;
ordersDB.UniQuery1.FieldByName('ORDER_STATUS').AsString := 'DELETED';
ordersDB.UniQuery1.FieldByName('REVISION_NUMBER').AsInteger := 1;
ordersDB.UniQuery1.FieldByName('ORDER_REVISION_ID').AsInteger := RevisionID;
ordersDB.UniQuery1.FieldByName('REVISION_USER_ID').AsString := UserID;
// Post the record to the database
ordersDB.UniQuery1.Post;
Result := TJSONObject.Create.AddPair('status', 'success');
Result.AddPair('OrderID', ORDER_ID);
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
except
on E: Exception do
begin
Result := TJSONObject.Create.AddPair('error', E.Message);
end
end;
finally
JSONData.Free;
end;
sql := 'delete from ' + table + ' where ORDER_ID = ' + OrderID;
OrdersDB.UniQuery1.SQL.Text := SQL;
OrdersDB.UniQuery1.ExecSQL;
sql := 'delete from orders where ORDER_ID = ' + OrderID;
OrdersDB.UniQuery1.SQL.Text := SQL;
OrdersDB.UniQuery1.ExecSQL;
end;
initialization
RegisterServiceType(TLookupService);
end.
......@@ -2,7 +2,7 @@
MemoLogLevel=3
FileLogLevel=5
webClientVersion=0.9.2
LogFileNum=366
LogFileNum=396
[Database]
Server=192.168.159.132
......
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