📄 mc_dcfy_lr.~pas
字号:
unit MC_DCFY_LR;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGrids, StdCtrls, Mask, DBCtrls, ExtCtrls, ComCtrls, Buttons,
ImgList, DB, DBTables;
type
TDCFY_LR = class(TForm)
GroupBox1: TGroupBox;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
DBText2: TDBText;
DBText3: TDBText;
DBText4: TDBText;
DBText5: TDBText;
DBText6: TDBText;
DBText7: TDBText;
DBText8: TDBText;
Label12: TLabel;
DBText9: TDBText;
Bevel1: TBevel;
Panel1: TPanel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label13: TLabel;
Label1: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
ImageList1: TImageList;
Panel2: TPanel;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Panel3: TPanel;
Label19: TLabel;
Label20: TLabel;
DCGrid: TStringGrid;
ListBox2: TListBox;
BitBtn1: TBitBtn;
Query1: TQuery;
Query2: TQuery;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
Query3: TQuery;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure DCGridKeyPress(Sender: TObject; var Key: Char);
procedure ListBox2KeyPress(Sender: TObject; var Key: Char);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure DCGridKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DCGridKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
ktkey:integer;
{ Private declarations }
public
x,y:integer;
PJ:array[1..50] of integer;
{ Public declarations }
end;
var
DCFY_LR: TDCFY_LR;
implementation
uses MC_TLCYGLXT, MC_YGCX, MC_KTGL, MC_GD_InFor;
{$R *.DFM}
procedure TDCFY_LR.FormCreate(Sender: TObject);
begin
TLCYGLXT.CPFYXXB.Open; //打开菜谱费用信息表;
TLCYGLXT.SJFYXXB.Open; //打开水酒信息表
TLCYGLXT.CJFYXXB.Open; //打开餐具费用信息表;
end;
procedure TDCFY_LR.FormShow(Sender: TObject);
var a,b,c:integer;
begin
DCGrid.Cells[1,0]:='编号';
DCGrid.Cells[2,0]:='名称';
DCGrid.Cells[3,0]:='类型';
DCGrid.Cells[4,0]:='单位';
DCGrid.Cells[5,0]:='数量';
DCGrid.Cells[6,0]:='价格';
DCGrid.Cells[7,0]:='状态';
DCGrid.Cells[8,0]:='合计';
for a:=1 to DCGrid.RowCount-1 do
begin
DCGrid.Cells[0,a]:=intToStr(a);
end;
end;
procedure TDCFY_LR.BitBtn2Click(Sender: TObject); //开始点菜
begin
Query1.Open; //打开库存水酒记录
TLCYGLXT.KT_FJTHXXB.Edit;
TLCYGLXT.KT_FJTHXXB.FieldByName('状态').AsString:='开台';
TLCYGLXT.KT_FJTHXXB.Post;
DCGrid.Enabled:=True;
BitBtn4.Enabled:=True;
BitBtn5.Enabled:=True;
DCGrid.setFocus;
end;
procedure TDCFY_LR.DCGridKeyPress(Sender: TObject; var Key: Char); //处理表格中的键盘操作
var zjje:Real;
aa:integer;
begin
X:=DCGrid.Row;
Y:=DCGrid.Col;
if key=#13 then //回车
begin
If DCGrid.Col = 8 Then //当光标移到表格第八列时计算消费合计
begin
zjje:=0;
for aa:=1 to 51 do
begin
if Length(DCGrid.Cells[8,aa])<>0 then
begin
if DCGrid.Cells[7,aa]<>'赠单' then
begin
zjje:=StrToFloat(DCGrid.Cells[8,aa])+zjje; //计算总计消费
Label14.Caption:=FloatToStr(zjje);
End
Else
begin
Label14.Caption:=FloatToStr(zjje);
end;
End
Else
Break; //结束循环
end;
end;
If DCGrid.Col = 5 Then
begin
if Length(DCGrid.Cells[1,X])<>0 then
begin
if StrToInt(DCGrid.Cells[5,X])=0 then //输入数量为零
begin
ShowMessage('数量不正确');
Exit;
End
Else
begin
Try
DCGrid.Cells[8,X]:=IntToStr(Round(StrToint(DCGrid.Cells[5,X])*StrToFloat(DCGrid.Cells[6,X]))); //计算金额
Except
End;
DCGrid.Col:=7;
end;
end;
if Length(DCGrid.Cells[1,x])<>0 then
if StrToInt(Copy(DCGrid.Cells[1,x],0,1))=1 then
begin
if PJ[DCGrid.row]-StrToInt(DCGrid.Cells[5,x])<=0 then //超出库存
begin
ShowMessage('库存不足');
end;
end;
end;
If DCGrid.Col = 1 Then //光标在第一列时
if Length(DCGrid.Cells[1,x])<>0 then
begin
case StrToInt(Copy(DCGrid.Cells[1,x],0,1)) of //copy: 获取指定数量的字符串
1: begin //首字符为1 点酒水
if TLCYGLXT.SJFYXXB.Locate('编号',DCGrid.Cells[1,x],[locaseInsensitive]) then
begin
if query1.Locate('编号',TLCYGLXT.SJFYXXB.FieldByName('货存编号').AsInteger,[locaseInsensitive]) then //查找商品
begin
PJ[DCGrid.row]:=Query1.FieldByName('数量').AsInteger;
DCGrid.Cells[2,X]:=TLCYGLXT.SJFYXXB.FieldByName('酒水名称').AsString;
DCGrid.Cells[4,x]:=TLCYGLXT.SJFYXXB.FieldByName('单位').AsString;
DCGrid.Cells[3,x]:=TLCYGLXT.SJFYXXB.FieldByName('酒水类别').AsString;
DCGrid.Cells[6,x]:=TLCYGLXT.SJFYXXB.FieldByName('价格').AsString;
DCGrid.Cells[7,x]:='点单';
DCGrid.Cells[5,x]:='1';
DCGrid.Cells[8,x]:=TLCYGLXT.SJFYXXB.FieldByName('价格').AsString;
DCGrid.Col:=4;
End
Else
begin
ShowMessage('对不起,已没有库存.');
Abort;
end;
End
Else
begin
ShowMessage('没有此编号水酒信息');
Abort;
end;
end;
3: begin //首字符为3 点餐具
if TLCYGLXT.CJFYXXB.Locate('编号',DCGrid.Cells[1,X],[loCaseInsensitive]) then
begin
DCGrid.Cells[2,X]:=TLCYGLXT.CJFYXXB.FieldByName('餐具名称').AsString;
DCGrid.Cells[4,x]:=TLCYGLXT.CJFYXXB.FieldByName('单位').AsString;
DCGrid.Cells[3,x]:=TLCYGLXT.CJFYXXB.FieldByName('餐具类别').AsString;
DCGrid.Cells[6,x]:=TLCYGLXT.CJFYXXB.FieldByName('价格').AsString;
DCGrid.Cells[7,x]:='点单';
DCGrid.Cells[5,x]:='1';
DCGrid.Cells[8,x]:=TLCYGLXT.CJFYXXB.FieldByName('价格').AsString;
DCGrid.Col:=4;
End
Else
begin
ShowMessage('没有此编号餐具信息');
Abort;
end;
end;
Else //首字符为其他点菜
begin
if TLCYGLXT.CPFYXXB.Locate('编号',DCGrid.Cells[1,X],[loCaseInsensitive]) then
begin
DCGrid.Cells[2,X]:=TLCYGLXT.CPFYXXB.FieldByName('菜名').AsString;
DCGrid.Cells[4,x]:=TLCYGLXT.CPFYXXB.FieldByName('单位').AsString;
DCGrid.Cells[3,x]:=TLCYGLXT.CPFYXXB.FieldByName('菜系类别').AsString;
DCGrid.Cells[6,x]:=TLCYGLXT.CPFYXXB.FieldByName('价格').AsString;
DCGrid.Cells[7,x]:='点单';
DCGrid.Cells[5,x]:='1';
DCGrid.Cells[8,x]:=TLCYGLXT.CPFYXXB.FieldByName('价格').AsString;
DCGrid.Col:=4;
End
Else
begin
ShowMessage('没有此编号菜谱信息');
Abort;
end;
end;
end;
end;
if DCGrid.Col<8 then DCGrid.Col:=DCGrid.Col+1 //光标向后移动
Else
If DCGrid.Row <> 50 Then
begin
DCGrid.row:=DCGrid.row+1; //光标移到下一行
DCGrid.Col:=1;
end;
End
Else
If (DCGrid.Col = 1) Or (DCGrid.Col = 5) Then
begin
If DCGrid.Col = 5 Then
begin
if key=#8 then key:=#8 else //退格键
if (key<'0') or (Key>'9') then key:=#0; //如果输入大于0小于9,则输入空字符
if Length(DCGrid.Cells[2,x])=0 then
begin
Key:=#0; // 空字符
end;
end;
If DCGrid.Col = 1 Then
if Length(DCGrid.Cells[2,X-1])=0 then
begin
Key:=#0;
End
Else
begin
if key=#8 then key:=#8 else
if (key<'0') or (Key>'9') then key:=#0; //如果输入大于0小于9,则输入空字符
end;
End
Else
If DCGrid.Col = 7 Then //如果光标在第7列时
begin
if Length(DcGrid.Cells[1,x])=0 then key:=#0 //如果DcGrid.Cells[1,x]单元格无输入值,输入空字符
Else
begin
Listbox2.Visible:=True; //显示点单赠单列表
Listbox2.ItemIndex:=0; //移到点单
ListBox2.SetFocus;
end;
End
Else
if (DCGrid.Col=1) or (DCGrid.Col=2) or (DCGrid.Col=3) or (DCGrid.Col=4)
or (DCGrid.Col=6) or (DCGrid.Col=7) or (DCGrid.Col=8) then Key:=#0;
end;
procedure TDCFY_LR.ListBox2KeyPress(Sender: TObject; var Key: Char); //选择点单或赠单
begin
if key=#13 then //回车选择点单或赠单
begin
DCGrid.Cells[Y,X]:=ListBox2.items[ListBox2.ItemIndex];
ListBox2.Visible:=False;
DCGrid.col:=DCGrid.col+1; //移到下一行列
DCGrid.setfocus;
end;
end;
procedure TDCFY_LR.BitBtn1Click(Sender: TObject); //放弃开台
begin
TLCYGLXT.KT_FJTHXXB.Edit; //编辑房台
TLCYGLXT.KT_FJTHXXB.FieldByName('状态').AsString:='空闲'; //将房台改为空闲
TLCYGLXT.KT_FJTHXXB.Post; //保存编辑
TLCYGLXT.JZBH.Edit; //编辑结账编号
TLCYGLXT.JZBH.FieldByName('编号').AsInteger:=TLCYGLXT.JZBH.FieldByName('编号').AsInteger-1;
TLCYGLXT.JZBH.Post; //保存编辑
ktkey:=3; //放弃开台
Close;
end;
procedure TDCFY_LR.BitBtn3Click(Sender: TObject); //确定返回
begin
TLCYGLXT.JZBH.Edit; //编辑结账编号
TLCYGLXT.JZBH.FieldByName('编号').AsInteger:=TLCYGLXT.JZBH.FieldByName('编号').AsInteger+1;
TLCYGLXT.JZBH.Post; //保存编辑
ktKey:=2; //确定返回
close;
end;
procedure TDCFY_LR.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var a:integer;
b:integer;
begin
If ktKey = 3 Then //放弃开台
begin
End
Else
If ktKey = 2 Then //确定返回
begin
if Length(DCGrid.Cells[1,1])=0 then //如果首单元格为空
begin
ShowMessage('对不起,没有点菜是无法开台营业的.');
Abort;
End
Else
begin
for a:=1 to 51 do
begin
if Length(DCGrid.Cells[1,a])=0 then //如果该行首单元格为空
begin
b:=a;
Break; //结束循环
End
Else
begin
if Length(DCGrid.Cells[2,a])=0 then //如果该行第二单元格为空
begin
ShowMessage('数据有误,请修改.');
DCGrid.Col:=2;
DCGrid.Row:=a;
DCGrid.SetFocus; //光标移到该单元格
Abort;
end;
if Length(DCGrid.Cells[3,a])=0 then //如果该行第三单元格为空
begin
ShowMessage('数据有误,请修改.');
DCGrid.Col:=3;
DCGrid.Row:=a;
DCGrid.SetFocus; //光标移到该单元格
Abort;
end;
if Length(DCGrid.Cells[4,a])=0 then //如果该行第四单元格为空
begin
ShowMessage('数据有误,请修改.');
DCGrid.Col:=4;
DCGrid.Row:=a;
DCGrid.SetFocus; //光标移到该单元格
Abort;
end;
if Length(DCGrid.Cells[5,a])=0 then //如果该行第五单元格为空
begin
ShowMessage('数据有误,请修改.');
DCGrid.Col:=5;
DCGrid.Row:=a;
DCGrid.SetFocus; //光标移到该单元格
Abort;
end;
if Length(DCGrid.Cells[6,a])=0 then //如果该行第六单元格为空
begin
ShowMessage('数据有误,请修改.');
DCGrid.Col:=6;
DCGrid.Row:=a;
DCGrid.SetFocus; //光标移到该单元格
Abort;
end;
if Length(DCGrid.Cells[7,a])=0 then //如果该行第七单元格为空
begin
ShowMessage('数据有误,请修改.');
DCGrid.Col:=7;
DCGrid.Row:=a;
DCGrid.SetFocus; //光标移到该单元格
Abort;
end;
if Length(DCGrid.Cells[8,a])=0 then //如果该行第八单元格为空
begin
ShowMessage('数据有误,请修改.');
DCGrid.Col:=8;
DCGrid.Row:=a;
DCGrid.SetFocus; //光标移到该单元格
Abort;
end;
end;
end;
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Add('Insert 点菜临时表 (房间台号,编号,名称,类型,单位,数量,价格,合计,服务员编号,服务员姓名,状态,点单日期,结帐编号,是否结单)');
Query2.SQl.Add('Values(:房间台号,:编号,:名称,:类型,:单位,:数量,:价格,:合计,:服务员编号,:服务员名称,:状态,:点单日期,:结帐编号,:是否结单)');
For a:=1 to b-1 do
begin //将点菜信息保存到点菜临时表
Query2.Params[0].AsInteger:=StrToInt(TLCYGLXT.KT_FJTHXXB.FieldByName('编号').AsString);
Query2.Params[1].AsInteger:=StrToInt(DCGrid.Cells[1,a]);
Query2.Params[2].AsString:=DCGrid.Cells[2,a];
Query2.Params[3].AsString:=DCGrid.Cells[3,a];
Query2.Params[4].AsString:=DCGrid.Cells[4,a];
Query2.Params[5].AsInteger:=StrToInt(DCGrid.Cells[5,a]);
Query2.Params[6].AsFloat:=StrToFloat(DCGrid.Cells[6,a]);
Query2.Params[7].AsFloat:=StrToFloat(DCGrid.Cells[8,a]);
Query2.Params[8].AsInteger:=TLCYGLXT.YGXXB.FieldByName('员工编号').AsInteger;
Query2.Params[9].AsString:=TLCYGLXT.YGXXB.FieldByName('姓名').AsString;
Query2.Params[10].AsString:=DCGrid.Cells[7,a];
Query2.Params[11].AsDateTime:=StrToDateTime(Label17.Caption);
Query2.Params[12].AsInteger:=StrToInt(Label18.Caption);
Query2.Params[13].Asstring:='否';
Query2.ExecSQL;
end;
TLCYGLXT.KT_FJTHXXB.Edit; //编辑房台信息
TLCYGLXT.KT_FJTHXXB.FieldByName('状态').AsString:='营业';
TLCYGLXT.KT_FJTHXXB.Post; //保存该房台为营业
end; //结束判断点菜的信息是否为空.
End
Else
Abort;
end;
procedure TDCFY_LR.DCGridKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState); //在 DCGrid控件中的按键操作
begin
x:=DCGrid.Row;
Y:=DCGrid.Col;
end;
procedure TDCFY_LR.DCGridKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
If DCGrid.Col = 5 Then //当光标在第五列时
begin
if Length(DCGrid.Cells[1,X])<>0 then //当光标所在行的首单元格不为空
if Length(DCGrid.Cells[5,X])=0 then //当光标所在行的第五单元格为空
begin
Exit; //结束
End
Else
begin
Try
DCGrid.Cells[8,X]:=IntToStr(Round(StrToint(DCGrid.Cells[5,X])*StrToFloat(DCGrid.Cells[6,X]))); //计算合计金额
Except
End;
end;
end;
end;
procedure TDCFY_LR.FormClose(Sender: TObject; var Action: TCloseAction); //关闭窗体
begin
KTGL.Button1.Click;
TLCYGLXT.CPFYXXB.Close; //关闭菜谱费用信息表;
TLCYGLXT.CJFYXXB.Close; //关闭餐具费用信息表;
TLCYGLXT.SJFYXXB.CLose; //关闭水酒信息表
TLCYGLXT.KT_FJTHXXB.CLose;
TLCYGLXT.JZBH.Close;
Query2.Close;
QUery1.Close;
DCFY_LR.Release;
DCFY_LR:=nil;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -