Код:
procedure TClientThread.Execute;
begin
inherited;
with Form1 do
begin
if not IdTCPClient1.Connected then
exit;
repeat
cmd.text:= IdTCPClient1.ReadLn;
if trim(cmd.text) <> '' then
begin
if VerificaComando(cmd.text,'msg=',true) then
Synchronize(ShowReceiveMsg)
else if VerificaComando(cmd.text,'server_error=',true) then
Synchronize(ShowServerError)
else Synchronize(UnknowCmd);
end;
until not IdTCPClient1.Connected;
end;
{if not Terminated then
Terminate;}
end;
procedure TForm1.ShowReceiveMsg;
begin
memo1.lines.add(ReceiveMsg(cmd.text));
end;
procedure TForm1.UnknowCmd;
var str:string;
S, S1,d1: String;
s3:real;
a,b:integer;
i1,i2: Integer;
r,m : double;
i:integer;
JpegIm: TJpegImage;
bm: TBitMap;
d3,d2: TDateTime;
buf:string;
v:integer;
begin
str:=cmd.text;
if str<>'' then begin
Memo1.Lines.add(str);
buf:='';
for v:=1 to length(str) do
if str[v] in ['0'..'9', '.', ','] then buf:=buf+str[v];
s1:=buf;
s1:=StringReplace(s1, '.',',' , [rfReplaceAll]);
i1:=Pos(',',s1);
if i1>0 then begin
i2:=PosEx(',',s1,i1+1);
if i2>0 then s1:=Copy(s1,1,i2-1)+Copy(s1,i2+1,Length(s1)-i2);
end;
r:=RoundTo(StrToFloatDef(s1,0),-2);
Edit1.Text:=Floattostr(r);
if (r > 0) AND (r <> last_massa) then
begin
edtNotes1.Text:=edtNotes1.Text+Edit1.Text+#9+DateToStr(now) +#9+TimeToStr(now) +#13#10;
zQuery1.SQL.Clear;
zQuery1.SQL.Add ('INSERT INTO base_'+labelList1.Caption+' (Date_posting, Time_posting, num, Massa, Name, Image, Com, BaudRate, Organization, Location, IP, Note, Model, Equopment, Linkey, Stable_weight, Image_kamera)' );
zQuery1.SQL.Add(' Values (:date1, :date2, 1, :massa, :name,''image'', :port, :BaudRate, :Organization, :Location, :Ip, :Note, :Model, :Equopment, :Linkey, 0, :adress)');
d3:=Trunc(Date);
d2:=frac(time);
zQuery1.ParamByName('date1').Value:=d3;
zQuery1.ParamByName('date2').Value:=d2;
zQuery1.ParamByName('massa').Value:=Edit1.Text;
zQuery1.ParamByName('name').Value:=labelModel1.Caption+' '+LabelEquopment1.Caption;
zQuery1.ParamByName('port').Value:=labelPort1.Caption;
zQuery1.ParamByName('BaudRate').Value:=LabelBaudRate1.Caption;
zQuery1.ParamByName('Organization').Value:=LabelOrganization1.Caption;
zQuery1.ParamByName('Location').Value:=LabelLocation1.Caption;
zQuery1.ParamByName('Ip').Value:=LabelIp1.Caption;
zQuery1.ParamByName('Note').Value:=labelNote1.Caption;
zQuery1.ParamByName('Model').Value:=labelModel1.Caption;
zQuery1.ParamByName('Equopment').Value:=labelEquopment1.Caption;
zQuery1.ParamByName('Linkey').Value:=labelLinkey1.Caption;
zQuery1.ParamByName('adress').Value:='\NO.jpg';
zQuery1.ExecSQL;
last_massa := r;
end;
end
else
begin
//Стабильный вес
m:=StrToFloat(Edit1.Text);
if m>strtofloat(RzEdit1.Text) then
begin
if PovtorChisla<0 then
begin
PredChislo := m;
PovtorChisla := 1
end
else
if m = PredChislo then inc(PovtorChisla)
else
begin
PovtorChisla := 1;
PredChislo := m;
end;
if PovtorChisla = 2 then
begin
//не срабатывает
edtNotes1.SelAttributes.Style:=edtNotes1.SelAttributes.Style+[fsBold];
edtNotes1.Text:=edtNotes1.Text+Floattostr(m)+#9+DateToStr(now) +#9+TimeToStr(now)+' стабильно' +#13#10;
zQuery1.SQL.Clear;
zQuery1.SQL.Add ('INSERT INTO base_'+labelList1.Caption+' (Date_posting, Time_posting, num, Massa, Name, Image, Com, BaudRate, Organization, Location, IP, Note, Model, Equopment, Linkey, Stable_weight, Image_kamera)' );
zQuery1.SQL.Add(' Values (:date1, :date2, 1, :massa, :name,''image'', :port, :BaudRate, :Organization, :Location, :Ip, :Note, :Model, :Equopment, :Linkey, 1, :adress)');
d3:=Trunc(Date);
d2:=frac(time);
zQuery1.ParamByName('date1').Value:=d3;
zQuery1.ParamByName('date2').Value:=d2;
zQuery1.ParamByName('massa').Value:=Edit1.Text;
zQuery1.ParamByName('name').Value:=labelModel1.Caption+' '+LabelEquopment1.Caption;
zQuery1.ParamByName('port').Value:=labelPort1.Caption;
zQuery1.ParamByName('BaudRate').Value:=LabelBaudRate1.Caption;
zQuery1.ParamByName('Organization').Value:=LabelOrganization1.Caption;
zQuery1.ParamByName('Location').Value:=LabelLocation1.Caption;
zQuery1.ParamByName('Ip').Value:=LabelIp1.Caption;
zQuery1.ParamByName('Note').Value:=labelNote1.Caption;
zQuery1.ParamByName('Model').Value:=labelModel1.Caption;
zQuery1.ParamByName('Equopment').Value:=labelEquopment1.Caption;
zQuery1.ParamByName('Linkey').Value:=labelLinkey1.Caption;
zQuery1.ParamByName('adress').Value:='\NO.jpg';
zQuery1.ExecSQL;
PovtorChisla := 0;
end;
end;
end;
a:=memo1.Lines.Count;
if a>15 then
memo1.Clear;
b:=edtNotes1.Lines.Count;
if b>1000 then
edtNotes1.Clear;
end;
procedure TForm1.ShowServerError;
var msg: String;
begin
msg:= copy(cmd.text,14,length(cmd.text));
memo1.lines.Add('Ошибка на сервере: ' + msg);
end;