-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHBedView.pas
352 lines (324 loc) · 9.98 KB
/
HBedView.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
{*******************************************************}
{ }
{ HimsSoft }
{ }
{ 版权所有 (C) 2019 [email protected] }
{ }
{*******************************************************}
unit HBedView;
interface
uses Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Graphics, System.Classes, System.SysUtils,
Vcl.Forms, Winapi.Windows,Vcl.Controls, Data.DBXClassRegistry,
HDataNotify, HDataModel,HCustomer, HDataDetailView,
HDeviceDefine,HDeviceInfo,
HJason;
type
TBedView = class(TPanel)
private
FbedStatus: EmBedStatus;
procedure SetbedStatus(const Value: EmBedStatus);
private
FnotifyComponent: TComponent;
procedure SetnotifyComponent(const Value: TComponent);
private
Fcustomer: TCustomer;
procedure Setcustomer(const Value: TCustomer);
published
property notifyComponent :TComponent read FnotifyComponent write SetnotifyComponent;
property bedStatus: EmBedStatus read FbedStatus write SetbedStatus;
property customer:TCustomer read Fcustomer write Setcustomer;
private
FImage: TImage;
FLabel: TLabel;
FBedIdLabel :TLabel;
FTimer: TTimer;
FDataDetailView: TDataDetailView;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
protected
procedure onClick(Sender: TObject);
procedure onDblClick(Sender: TObject);
procedure timerOnTimer(Sender: TObject);
procedure resetData;
private
FDId:string;//H_Data_Main.DId (由custId加随机生成码)
fJason :TJason;
FRspData:TDataModel;
procedure ErrorBlock(Sender: TObject;error: TErrorMsg);
procedure successBlock(Sender: TObject;rspData:TDataModel);
end;
implementation
uses HDBManager,superobject,HLog,
HBellco,HToray,HBraun,HNikkiso,HGambro,HFresenius;
{ TBedView }
constructor TBedView.Create(AOwner: TComponent);
begin
inherited;
Color := clWhite;
FTimer := TTimer.Create(Self);
FTimer.Interval := 10000;
FTimer.OnTimer := timerOnTimer;
FTimer.Enabled := False;
FLabel := TLabel.Create(Self);
FLabel.Parent := Self;
FLabel.Left := 0;
FLabel.Top := 0;
FLabel.Width := 120;
FLabel.Height := 20;
FLabel.Align := alTop;
FLabel.Alignment := taCenter;
FLabel.Layout := tlCenter;
FLabel.Font.Color := clRed;
FLabel.Transparent := True;
FImage := TImage.Create(Self);
FImage.Parent := Self;
FImage.Stretch := True;
FImage.Left := 5;
FImage.Top := 20;
FImage.Width := 120;
FImage.Height := 75;
FImage.Stretch := True;
FImage.Align := alClient;
FImage.onClick := onClick;
FImage.onDblClick := onDblClick;
FBedIdLabel := TLabel.Create(Self);
FBedIdLabel.Caption := 'Bed - ';
FBedIdLabel.Align := alBottom;
FBedIdLabel.Alignment := taCenter;
FBedIdLabel.Left := FImage.Left;
FBedIdLabel.Top := FImage.Top + FImage.Height;
FBedIdLabel.Width := 120;
FBedIdLabel.Height := 10;
FBedIdLabel.Transparent := True;
FBedIdLabel.Parent := Self;
end;
destructor TBedView.Destroy;
begin
if Assigned(FJason) then
begin
FJason.close;
FJason.Free;
end;
if Assigned(FTimer) then
FTimer.Free;
if Assigned(FImage) then
FImage.Free;
if Assigned(FLabel) then
FLabel.Free;
inherited;
end;
procedure TBedView.onClick(Sender: TObject);
var
lDataNotify: IDataNotify;
begin
//todo
Exit;
if Assigned(FDataDetailView) and (FbedStatus = EmBedUsed) then
begin
lDataNotify := FDataDetailView;
lDataNotify.sendSingleData(FRspData);
end;
end;
procedure TBedView.onDblClick(Sender: TObject);
begin
if FbedStatus = EmBedUsed then
begin
case Application.MessageBox('是否停止采集数据?', '提示',
MB_OKCANCEL + MB_ICONQUESTION) of
IDOK:
begin
FTimer.Enabled := False;
if Assigned(fJason) then
fJason.close;
bedStatus := EmBedNormal;
end;
IDCANCEL:
begin
end;
end;
end
else if FbedStatus = EmBedAlarm then
begin
//TODO:
bedStatus := EmBedNormal;
end
else if FbedStatus = EmBedError then
begin
//TODO:
end
else
begin
case Application.MessageBox('是否开启采集数据?', '提示',
MB_OKCANCEL + MB_ICONQUESTION) of
IDOK:
begin
FTimer.Enabled := False;
FTimer.Enabled := True;
bedStatus := EmBedUsed;
if Assigned(fJason) then
begin
fJason.close;
fJason.init;
end;
end;
IDCANCEL:
begin
end;
end;
end;
end;
procedure TBedView.resetData;
begin
FLabel.Caption := '';
end;
procedure TBedView.SetbedStatus(const Value: EmBedStatus);
var
fileStr: string;
sql:string;
sqls:TStringList;
jsonData: ISuperObject;
begin
FbedStatus := Value;
sqls := TStringList.Create;
fileStr := ExtractFilePath(paramstr(0)) + 'res/';
sql := Format
('Select DId From H_Data_Main Where MCustId = %s And MCureDate = %s ORDER by createDate LIMIT 1',
[QuotedStr(Fcustomer.MCustId),
QuotedStr(FormatDateTime('yyyy-mm-dd', Now))]);
jsonData := TDBManager.Instance.getDataBySql(sql);
case FbedStatus of
EmBedNormal:
begin
// 停止
fileStr := fileStr + 'bed_1.png';
sql := Format
('Update H_Data_Main set endTime =%s where DId =%s And MCustId = %s And MCureDate = %s',
[QuotedStr(FormatDateTime('yyyy-mm-dd hh:mm:ss', Now)),
QuotedStr(FDId), QuotedStr(Fcustomer.MCustId),
QuotedStr(FormatDateTime('yyyy-mm-dd', Now))]);
sqls.Add(sql);
resetData;
end;
EmBedUsed:
begin
// 开启
fileStr := fileStr + 'bed_2.png';
if jsonData.I['rowCount'] = 0 then
begin
sql := Format
('Insert Into H_Data_Main (DId,MCustId,startTime,MCureDate)' +
'Values (%s,%s,%s,%s)',
[QuotedStr(FDId), QuotedStr(Fcustomer.MCustId),
QuotedStr(FormatDateTime('yyyy-mm-dd hh:mm:ss', Now)),
QuotedStr(FormatDateTime('yyyy-mm-dd', Now))]);
sqls.Add(sql);
end;
end;
EmBedAlarm:
begin
fileStr := fileStr + 'bed.png';
end;
EmBedError:
begin
fileStr := fileStr + 'bed.png';
end;
end;
TDBManager.Instance.execSql(sqls);
if FileExists(fileStr) then
begin
FImage.Picture.LoadFromFile(fileStr);
end;
end;
procedure TBedView.Setcustomer(const Value: TCustomer);
var
sql: string;
jsonData: ISuperObject;
subData: ISuperObject;
deviceInfo: TDeviceInfo;
classRegistry: TClassRegistry;
fDeviceClass: string;
begin
Fcustomer := Value;
deviceInfo := TDeviceInfo.Create;
deviceInfo.MLink := FCustomer.MLinkType;
deviceInfo.MBrand := Fcustomer.MBrand;//这个涉及到后面对应的类解析数据,目前是必填项
deviceInfo.MLink := Fcustomer.MLinkType;
deviceInfo.MName := Fcustomer.MAddress;
deviceInfo.MPort := StrToInt(Fcustomer.MPort);
fJason := nil;
fDeviceClass := 'T' + deviceInfo.MBrand;
classRegistry := TClassRegistry.GetClassRegistry;
if classRegistry.HasClass(fDeviceClass) then
begin
fJason := (classRegistry.CreateInstance(fDeviceClass) as TJason).Create(deviceInfo);
fJason.failCallBack := ErrorBlock;
fJason.successCallBack := successBlock;
bedStatus := EmBedNormal;
end
else
begin
TLog.Instance.DDLogError('Can not found ' + fDeviceClass + ' class');
bedStatus := EmBedError;
end;
FBedIdLabel.Caption := 'Bed - '+ Fcustomer.MBedId + ':' + Fcustomer.MCustName;
FDId := '';
sql := Format('Select DId From H_Data_Main Where MCustId = %s And MCureDate = %s ORDER by createDate LIMIT 1',
[QuotedStr(FCustomer.MCustId),QuotedStr(FormatDateTime('yyyy-mm-dd',Now))]);
jsonData := TDBManager.Instance.getDataBySql(sql);
if jsonData.I['rowCount'] > 0 then
begin
for subData in jsonData['data'] do
begin
FDId := subData.S['DId'];
end;
end
else
begin
FDId := Fcustomer.MCustId +'|'+ FormatDateTime('yyyymmddhhmmss',Now);
end;
end;
procedure TBedView.SetnotifyComponent(const Value: TComponent);
begin
FnotifyComponent := Value;
FDataDetailView := FnotifyComponent as TDataDetailView;
end;
procedure TBedView.successBlock(Sender: TObject;rspData:TDataModel);
var sql:string;
sqls:TStringList;
begin
FRspData := rspData;
FLabel.Caption := 'UMP :' + IntToStr(Random(100)) + '%';
sqls := TStringList.Create;
sql := Format('Update H_Data_Main set endTime = %s Where DId = %s And MCustId = %s And MCureDate = %s',
[QuotedStr(FormatDateTime('yyyy-mm-dd hh:mm:ss',Now)),QuotedStr(FDId),QuotedStr(FCustomer.MCustId),QuotedStr(FormatDateTime('yyyymmdd',Now))]);
sqls.Add(sql);
sql := Format('Insert Into H_Data_Detail (DId,VenousPressure,DialysisPressure,TMP,BloodFlow,UFFlow,BloodPressure,TotalBlood,Temperature)' +
'Values (%s,%s,%s,%s,%s,%s,%s,%s,%s)',
[QuotedStr(FDId),QuotedStr(FRspData.VenousPressure),QuotedStr(FRspData.DialysisPressure),
QuotedStr(FRspData.TMP),QuotedStr(FRspData.BloodFlow),QuotedStr(FRspData.UFFlow),
QuotedStr(FRspData.BloodPressure),QuotedStr(FRspData.TotalBlood),QuotedStr(FRspData.Temperature)]);
sqls.Add(sql);
TDBManager.Instance.execSql(sqls);
end;
procedure TBedView.ErrorBlock(Sender: TObject;error: TErrorMsg);
begin
FLabel.Caption := 'Error :' + error.mType + '--'+ error.mDesc;
if Assigned(FTimer) then
begin
bedStatus := EmBedError;
end;
end;
procedure TBedView.timerOnTimer(Sender: TObject);
begin
if Assigned(fJason) then
fJason.send;
end;
initialization
TClassRegistry.GetClassRegistry.RegisterClass(TBellco.ClassName, TBellco);
TClassRegistry.GetClassRegistry.RegisterClass(TToray.ClassName, TToray);
TClassRegistry.GetClassRegistry.RegisterClass(TBraun.ClassName, TBraun);
TClassRegistry.GetClassRegistry.RegisterClass(TNikkiso.ClassName, TNikkiso);
TClassRegistry.GetClassRegistry.RegisterClass(TGambro.ClassName, TGambro);
TClassRegistry.GetClassRegistry.RegisterClass(TFresenius.ClassName, TFresenius);
end.