📄 client.~pas
字号:
Cigalistview.Update;
Cigalistview.Clear;
for c:=0 to Cigalist.Count -1 do
begin
with Cigalistview.Items.Add do
begin
caption:=Cigalist[c];
subitems.Add(myini.ReadString('烟类',Cigalist[c],''));
end;
end;
ClientForm.Show;
Cigalist.Free;
myini.Free;
end
else
begin
application.MessageBox('获取商品列表失败,请检查服务端是否运行!','错误',MB_ICONERROR);
application.Terminate;
end;
ClearMemory;
end;
procedure TClientForm.DrinkListviewClick(Sender: TObject);
begin
if DrinkListview.SelCount =1 then button1.Enabled:=True
else Button1.Enabled:=False;
end;
procedure TClientForm.FoodListviewClick(Sender: TObject);
begin
if FoodListview.SelCount =1 then button1.Enabled:=True
else Button1.Enabled:=False;
end;
procedure TClientForm.CigaListviewClick(Sender: TObject);
begin
if CigaListview.SelCount =1 then button1.Enabled:=True
else Button1.Enabled:=False;
end;
procedure TClientForm.Button1Click(Sender: TObject);
var d,f,c:integer;
begin
Timer3.Enabled:=True;
if SaleList.Items.Count >-1 then Button3.Enabled:=True
else Button3.Enabled:=False;
//饮料处理
case PageControl1.ActivePageIndex of
0:
begin
for d:=0 to SaleList.Items.Count -1 do
begin
if DrinkListview.Selected.Caption=SaleList.Items[d].Caption then
begin
if strtoint(SaleList.Items[d].SubItems[1])>8 then
begin
application.MessageBox('最大数量不能超过10,请检查!','警告',MB_ICONWARNING);
exit;
end;
SaleList.Items[d].SubItems[1]:=inttostr(strtoint(SaleList.Items[d].SubItems[1])+1);
exit;
end;
end;
with SaleList.Items.Add do
begin
Caption:=trim(DrinkListview.Selected.Caption);
subitems.Add(trim(DrinkListview.Selected.SubItems.Text));
subitems.Add('1');
end;
end;
//食品处理
1:
begin
for f:=0 to SaleList.Items.Count -1 do
begin
if FoodListview.Selected.Caption=SaleList.Items[f].Caption then
begin
if strtoint(SaleList.Items[f].SubItems[1])>8 then
begin
application.MessageBox('最大数量不能超过10,请检查!','警告',MB_ICONWARNING);
exit;
end;
SaleList.Items[f].SubItems[1]:=inttostr(strtoint(SaleList.Items[f].SubItems[1])+1);
exit;
end;
end;
with SaleList.Items.Add do
begin
Caption:=trim(FoodListview.Selected.Caption);
subitems.Add(trim(FoodListview.Selected.SubItems.Text));
subitems.Add('1');
end;
end;
2:
begin
for c:=0 to SaleList.Items.Count -1 do
begin
if CigaListview.Selected.Caption=SaleList.Items[c].Caption then
begin
if strtoint(SaleList.Items[c].SubItems[1])>8 then
begin
application.MessageBox('最大数量不能超过10,请检查!','警告',MB_ICONWARNING);
exit;
end;
SaleList.Items[c].SubItems[1]:=inttostr(strtoint(SaleList.Items[c].SubItems[1])+1);
exit;
end;
end;
with SaleList.Items.Add do
begin
Caption:=trim(CigaListview.Selected.Caption);
subitems.Add(trim(CigaListview.Selected.SubItems.Text));
subitems.Add('1');
end;
end;
end;
end;
procedure TClientForm.SaleListClick(Sender: TObject);
begin
if SaleList.SelCount =1 then button2.Enabled:=True
else Button2.Enabled:=False;
end;
procedure TClientForm.Button2Click(Sender: TObject);
begin
if SaleList.SelCount <1 then Button2.Enabled:=False
else
begin
if strtoint(SaleList.Selected.SubItems[1])=1 then
begin
SaleList.Selected.Delete;
Button2.Enabled:=False;
end
else
begin
SaleList.Selected.SubItems[1]:=inttostr(strtoint(SaleList.Selected.SubItems[1])-1);
end;
end;
end;
procedure TClientForm.Button3Click(Sender: TObject);
var i:integer;
cmd:string;
SendListview:string;
ComputerName:string;
begin
if SaleList.Items.Count >0 then
begin
IdTCPClient1.Port:=5209;
if IdTCPClient1.Connected then IdTCPClient1.Disconnect;
IdTCPClient1.Connect; //连接
try
SendListview:='|';
for i:=0 to SaleList.Items.Count -1 do
begin
SendListview:=SendListview+SaleList.Items[i].Caption+'='+SaleList.Items[i].SubItems[0]+'='+SaleList.Items[i].SubItems[1]+'|';
end;
Computername:=ClientName;
computername:='|'+computername;
if length(Computername)<10 then //如果定长为10
begin
for i:=1 to 10-Length(Computername) do
begin
Computername:=Computername+' ';
end;
end;
IdTCPClient1.WriteLn('SALE_SHOP_LIST'+Computername+SendListview);
PageControl1.Enabled:=False;
Button1.Enabled:=False;
Button2.Enabled:=False;
Button3.Enabled:=False;
Button4.Enabled:=False;
Button5.Enabled:=False;
Button6.Enabled:=False;
Combobox1.Enabled:=False;
SaleList.Enabled:=False;
not_allowed_close:=True;
IdTCPServer1.Active:=True;
Timer2.Enabled:=True;
WaitReceiveForm:=TWaitReceiveForm.Create(self);
WaitReceiveForm.ShowModal;
exit;
except
application.MessageBox('发错异常错误,请联系管理员!','错误',MB_ICONERROR);
application.Terminate;
end;
//IdTCPClient1.Disconnect;
end
else
begin
Button3.Enabled:=False;
end;
end;
procedure TClientForm.FormDestroy(Sender: TObject);
begin
IdTCPClient1.Disconnect;
IdTCPServer1.Free;
IdTCPClient1.Free;
end;
procedure TClientForm.Timer1Timer(Sender: TObject);
begin
ClearMemory;
end;
procedure TClientForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if not_allowed_close=True then
begin
Action:=canone;
end
else
Action:=caFree;
end;
procedure TClientForm.Button6Click(Sender: TObject);
var
i:integer;
Computername:string;
begin
sendcount:=sendcount+1;
if sendcount>9 then
begin
application.MessageBox('您发送的消息次数太多,请休息一下再发吧。','警告',MB_ICONWARNING);
Combobox1.Enabled:=False;
Button6.Enabled:=False;
exit;
end;
if trim(Combobox1.Text)<>'' then
begin
Computername:=ClientName;
computername:='|'+computername;
if length(Computername)<10 then //如果定长为10
begin
for i:=1 to 10-Length(Computername) do
begin
Computername:=Computername+' ';
end;
end;
IdTCPClient1.Port:=5209;
if IdTCPClient1.Connected then IdTCPClient1.Disconnect;
IdTCPClient1.Connect; //连接
try
IdTCPClient1.WriteLn('SEND_MESSAGE'+Computername+Combobox1.Text); //给服务端发送消息
except
exit;
end;
IdTCPClient1.Disconnect;
end
else
begin
application.MessageBox('发送的消息不能为空!','提示',MB_ICONINFORMATION);
Combobox1.SetFocus;
exit;
end;
end;
procedure TClientForm.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then Button6Click(Sender);
end;
procedure TClientForm.Timer2Timer(Sender: TObject);
var cmd:string;
begin
if not_allowed_close=False then
begin
Timer2.Enabled:=False;
Timer3.Enabled:=False;
WaitReceiveForm.RzLabel1.Blinking:=False;
WaitReceiveForm.RzLabel1.Font.Color:=clRed;
WaitReceiveForm.RzLabel1.BlinkColor:=clGreen;
WaitReceiveForm.RzLabel1.Blinking:=True;
WaitReceiveForm.RzLabel1.Caption:='您的请求已经被接受,请准备好现金!商品马上送到!';
WaitReceiveForm.Shape1.Visible:=True;
WaitReceiveForm.Label1.Visible:=True;
PageControl1.Enabled:=True;
Button1.Enabled:=True;
Button2.Enabled:=True;
Button3.Enabled:=False;
Button4.Enabled:=True;
Button5.Enabled:=True;
Button6.Enabled:=True;
Combobox1.Enabled:=True;
SaleList.Clear;
SaleList.Enabled:=True;
if FileExists(ExtractFilePath(paramstr(0))+'msg.wav') then
begin
sndPlaySound(PAnsiChar(ExtractFilePath(paramstr(0))+'msg.wav'),SND_ASYNC);
end;
end;
end;
procedure TClientForm.Timer3Timer(Sender: TObject);
var i:integer;
saleprice:real;
begin
saleprice:=0.00;
for i:=0 to SaleList.Items.Count -1 do
begin
saleprice:=saleprice+strtoFloat(SaleList.Items[i].SubItems[0])*strtoFloat(SaleList.Items[i].SubItems[1]);
end;
Label6.Caption:=Formatfloat('0.00',saleprice);
end;
procedure TClientForm.IdTCPServer1Execute(AThread: TIdPeerThread);
var cmd:string;
begin
cmd:=Athread.Connection.ReadLn;
if cmd='RECEIVED_SUCESS' then not_allowed_close:=False;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -