⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cj_main.pas

📁 亚惠快餐管理信息系统 包括亚惠快餐管理的各项功能
💻 PAS
📖 第 1 页 / 共 4 页
字号:
  TextFileName := Copy(TextFileName, 1, Pos('bin', LowerCase(TextFileName)) - 1)
    + 'Data\' + Trim(DateToStr(now)) + '.dat';
  {循环读取文件并比较}
  for i := 1 to 3 do
  begin
    ReturnValue := ReadFromDll('SX0014', Pchar(TextFileName), 0, 0, Jqh, 14,
      -100, -100);
    if ReturnValue <> -1 then
    begin
      Screen.Cursor := crDefault;
      ShowMessage('读取收银机数据错误,系统无法继续工作!');
      Exit;
    end;
  end;
  if not FileExists(TextFileName) then
  begin
    Screen.Cursor := crDefault;
    ShowMessage('数据文件' + TextFileName + '不存在,系统无法继续工作!');
    Exit;
  end;
  AssignFile(ATextFile, TextFileName);
  try
    ReSet(ATextFile);
  except
    Screen.Cursor := crDefault;
    ShowMessage('数据文件' + TextFileName + '受到破坏,系统无法继续工作!');
    Exit;
  end;
  Result := True;
end;

{------------------调用dll文件,采集配置及流水信息-----------------------}

function TFrmCJ_Main.ReadFromDll(czlx: pchar; filename1: pchar;
  WBaud: integer; Wport: smallint; Wmc: smallint; Wtype: smallint;
  Wformx: smallint; Wformy: smallint): smallint;
type
  TDllFunc = function(Wcommand: pchar; Wfname: pchar; WBaud: integer; Wport:
    smallint;
    Wmc: smallint; Wtype: smallint; Wformx: smallint; Wformy: smallint):
    smallint; stdcall;
var
  alib: THandle;
  proc: TDllFunc;
  PathName: string;
begin
  PathName := ExtractFilePath(Application.ExeName) + 'xtinterface.dll';
  try
    alib := LoadLibrary(PChar(PathName));
    if alib = 0 then
    begin
      Screen.Cursor := crDefault;
      ShowMessage('无法打开访问收款机的函数');
      Exit;
    end;
    proc := TDllFunc(GetProcAddress(alib, PChar('XtRun')));
    if @proc = nil then
    begin
      Screen.Cursor := crDefault;
      ShowMessage('无法从收银机读取数据');
      Exit;
    end
    else
      Result := proc(czlx, filename1, WBaud, Wport, Wmc, Wtype, Wformx, Wformy);
    proc := nil;
    FreeLibrary(alib);
  finally
    proc := nil;
    FreeLibrary(alib);
  end;
end;

procedure TFrmCJ_Main.CollectDataFromText(jlh: integer; s: string; ItemValue:
  TStrings);
var
  aSpxx: TSpxx;
  aJyfs: TJyfsList;
  num1: integer;
begin
  {采集机器号}
  if LowerCase(Trim(copy(s, 1, 3))) = 'mac' then
  begin
    TScxx(RecordList.Objects[jlh]).jqh := StrToInt(Trim(Copy(s, Pos('=', s) + 1,
      2)));
    Exit;
  end;
  {采集收据号}
  if LowerCase(Trim(Copy(s, 1, 7))) = 'receipt' then
  begin
    TScxx(RecordList.Objects[jlh]).sjh := strtoint(trim(copy(s, pos('=', s) + 1,
      20)));
    Exit;
  end;
  {采集服务员}
  if (length(trim(copy(s, 1, pos(',', s) - 1))) = 4) and (trim(copy(trim(copy(s,
    1, pos(',', s) - 1)), 1, 2)) = '21') then
  begin
    TScxx(RecordList.Objects[jlh]).fwyh := strtoint(trim(copy(s, 1, pos(',', s)
      - 1)));
    TScxx(RecordList.Objects[jlh]).fwym :=
      GetName(TScxx(RecordList.Objects[jlh]).fwyh, 1);
    Exit;
  end;
  {采集收款员}
  if (length(trim(copy(s, 1, pos(',', s) - 1))) = 4) and (trim(copy(trim(copy(s,
    1, pos(',', s) - 1)), 1, 1)) = '3') then
  begin
    TScxx(RecordList.Objects[jlh]).skyh := strtoint(trim(copy(s, 1, pos(',', s)
      - 1)));
    TScxx(RecordList.Objects[jlh]).skym :=
      GetClerkName(GetName(TScxx(RecordList.Objects[jlh]).skyh, 2));
    Exit;
  end;
  {退货键处理}
  if trim(copy(trim(copy(s, 1, pos(',', s) - 1)), 1, 3)) = '303' then
  begin
    BackFlag := True;
    Exit;
  end;
  {分解商品信息}
  ItemValue.Clear;
  while Pos(',', s) > 0 do
  begin
    ItemValue.Add(Copy(s, 1, Pos(',', s) - 1));
    s := Trim(Copy(s, Pos(',', s) + 1, 10000000));
  end;
  {采集商品信息——商品代码、数量、价格、名称}
  if (length(Trim(ItemValue[0])) = 5) and (copy(Trim(ItemValue[0]), 1, 1) = '1')
    then
  begin
    aSpxx := TSpxx.Create;
    aSpxx.spdl := strtoint(Trim(ItemValue[0]));
    aSpxx.sl := strtofloat(Trim(ItemValue[1]));
    num1 := Round(aSpxx.sl);
    TScxx(RecordList.Objects[jlh]).spsl := TScxx(RecordList.Objects[jlh]).spsl +
      num1;
    aSpxx.je := strtofloat(Trim(ItemValue[2])) / 100;
    aSpxx.spmc := GetName(aSpxx.spdl, 3);
    aSpxx.thflag := False;
    if BackFlag then
    begin
      aSpxx.thflag := True;
      BackFlag := False;
    end;
    TScxx(RecordList.Objects[jlh]).Spxx.AddObject('', aSpxx);
    Exit;
  end;
  {采集商品信息——折扣标志}
  if (length(Trim(ItemValue[0])) = 3) and (copy(Trim(ItemValue[0]), 1, 1) = '5')
    then
  begin
    TScxx(RecordList.Objects[jlh]).zkflag := 1;
    Exit;
  end;
  {采集商品信息——交易方式号、总金额、交易方式名}
  if (length(Trim(ItemValue[0])) = 3) and (copy(Trim(ItemValue[0]), 1, 1) = '9')
    and (copy(Trim(ItemValue[0]), 1, 3) <> '900') then
  begin
    //TScxx(RecordList.Objects[jlh]).jyfs := strtoint(Trim(ItemValue[0]));
    //TScxx(RecordList.Objects[jlh]).zje:=strtoint(Trim(ItemValue[2]));
    //TScxx(RecordList.Objects[jlh]).jyfsm := GetName(TScxx(RecordList.Objects[jlh]).jyfs, 4);
    aJyfs := TJyfsList.Create;
    aJyfs.jymc := GetName(strtoint(Trim(ItemValue[0])), 4);
    aJyfs.jyje := strtofloat(Trim(ItemValue[2]));
    TScxx(RecordList.Objects[jlh]).JyfsList.AddObject('', aJyfs);
    Exit;
  end;
end;
{--------------------------从数据库中通过号获得名称---------------------------}

function TFrmCJ_Main.GetName(Bh, lx: integer): string;
var
  sqlstring: string;
begin
  Result := '';
  case lx of
    1: sqlstring := 'Select 服务员姓名 From PZXX_DFWY1 Where 服务员编码=' +
      IntToStr(Bh);
    2: sqlstring :=
      'Select Right(密码姓名,len(密码姓名)-4) From PZXX_DSKY1 Where 收款员号=' +
        IntToStr(Bh);
    3: sqlstring := 'Select 商品名称 From PZXX_DSPXX1 Where 商品号=' +
      IntToStr(Bh);
    4: sqlstring := 'Select 交易名称 From PZXX_DJYFS Where 交易号=' +
      IntToStr(Bh);
  end;
  with FrmCJ_DataModule.ADOQuery2 do
  begin
    Close;
    Sql.Clear;
    Sql.Add(sqlstring);
    try
      Open;
    except
      ShowMessage('无法打开记录集');
      Exit;
    end;
    if RecordCount = 0 then
      Exit;
    Result := Trim(Fields[0].AsString);
  end;
end;

function TFrmCJ_Main.GetClerkName(skyname: string): string;
var
  sqlstring: string;
begin
  Result := '';
  sqlstring := 'Select 职员姓名 From SYJSKYDZB Where 收款员姓名=''' +
    Trim(skyname) + '''';
  with FrmCJ_DataModule.ADOQuery2 do
  begin
    Close;
    Sql.Clear;
    Sql.Add(sqlstring);
    try
      Open;
    except
      ShowMessage('无法打开收款员对照表');
      Exit;
    end;
    if RecordCount = 0 then
      Exit;
    Result := Trim(Fields[0].AsString);
  end;
end;

function TFrmCJ_Main.InsertAllToDb(SelSum: TStrings; Date1, Date2: TDate):
  Boolean;
var
  i: integer;
begin
  Result := False;
  if not EmptyMachineRecord(TScxx(RecordList.Objects[0]).jqh, Date1, Date2) then
    Exit;
  if not EmptyTh(TScxx(RecordList.Objects[0]).jqh, Date1, Date2) then
    Exit;
  if not EmptyJyfs(TScxx(RecordList.Objects[0]).jqh, Date1, Date2) then
    Exit;
  for i := 0 to SelSum.Count - 1 do
  begin
    if not InsertRecord(StrToInt(SelSum[i])) then
      Exit;
    if not InsertJyRecord(StrToInt(SelSum[i])) then
      Exit;
  end;
  Result := True;
end;

function TFrmCJ_Main.InsertPartToDb(SelSum: TStrings; Date1, Date2: TDate):
  Boolean;
var
  i: integer;
begin
  Result := False;
  for i := 0 to SelSum.Count - 1 do
  begin
    if not
      EmptyCurrentRecord(TScxx(RecordList.Objects[StrToInt(SelSum[i])]).jqh,
      TScxx(RecordList.Objects[StrToInt(SelSum[i])]).sjh, Date1, Date2) then
      Exit;
    if not EmptyCurrentTh(TScxx(RecordList.Objects[StrToInt(SelSum[i])]).jqh,
      TScxx(RecordList.Objects[StrToInt(SelSum[i])]).sjh, Date1, Date2) then
      Exit;
    if not EmptyCurrentJyfs(TScxx(RecordList.Objects[StrToInt(SelSum[i])]).jqh,
      TScxx(RecordList.Objects[StrToInt(SelSum[i])]).sjh, Date1, Date2) then
      Exit;
    if not InsertRecord(StrToInt(SelSum[i])) then
      Exit;
    if not InsertJyRecord(StrToInt(SelSum[i])) then
      Exit;
  end;
  Result := True;
end;

{---------------------采集全部,删除此机器号的全部记录----------------}

function TFrmCJ_Main.EmptyMachineRecord(MachineNo: integer; Date1, Date2:
  TDate): Boolean;
begin
  Result := False;
  with FrmCJ_DataModule.ADOQuery2 do
  begin
    Close;
    Sql.Clear;
    Sql.Add('Delete');
    Sql.Add('From SCSJ_DSYJXSXX1');
    Sql.Add('Where 设备编码=' + IntToStr(MachineNo));
    Sql.Add('And Convert(char(10),日期,20)>=''' + DateToStr(Date1) + '''');
    Sql.Add('And Convert(char(10),日期,20)<=''' + DateToStr(Date2) + '''');
    try
      ExecSql;
    except
      Screen.Cursor := crDefault;
      ShowMessage('无法清空库内有关机器' + IntToStr(MachineNo) +
        '的数据,系统无法继续工作!');
      Exit;
    end;
  end;
  Result := True;
end;

{------------------删除采集退货表中此机器号的全部记录-------------------}

function TFrmCJ_Main.EmptyTh(MachineNo: integer; Date1, Date2: TDate): Boolean;
begin
  Result := False;
  with FrmCJ_DataModule.ADOQuery2 do
  begin
    Close;
    Sql.Clear;
    Sql.Add('Delete');
    Sql.Add('From SCSJ_DTH');
    Sql.Add('Where 设备编码=' + IntToStr(MachineNo));
    Sql.Add('And Convert(char(10),日期,20)>=''' + DateToStr(Date1) + '''');
    Sql.Add('And Convert(char(10),日期,20)<=''' + DateToStr(Date2) + '''');
    try
      ExecSql;
    except
      Screen.Cursor := crDefault;
      ShowMessage('无法清空退货表中有关机器' + IntToStr(MachineNo) +
        '的数据,系统无法继续工作!');
      Exit;
    end;
  end;
  Result := True;
end;

{------------------删除采集交易方式表中此机器号的全部记录----------------}

function TFrmCJ_Main.EmptyJyfs(MachineNo: integer; Date1, Date2: TDate):
  Boolean;
begin
  Result := False;
  with FrmCJ_DataModule.ADOQuery2 do
  begin
    Close;
    Sql.Clear;
    Sql.Add('Delete');
    Sql.Add('From SCSJ_DJYFS');
    Sql.Add('Where 设备编码=' + IntToStr(MachineNo));
    Sql.Add('And Convert(char(10),日期,20)>=''' + DateToStr(Date1) + '''');
    Sql.Add('And Convert(char(10),日期,20)<=''' + DateToStr(Date2) + '''');
    try
      ExecSql;
    except
      Screen.Cursor := crDefault;
      ShowMessage('无法清空交易方式表中有关机器' + IntToStr(MachineNo) +
        '的数据,系统无法继续工作!');
      Exit;
    end;
  end;
  Result := True;
end;
{------------------ 部分采集前删除当前机器号和收据号的全部记录------------------------}

function TFrmCJ_Main.EmptyCurrentRecord(MachineNo, SjNo: integer; Date1, Date2:
  TDate): Boolean;
begin
  Result := False;
  with FrmCJ_DataModule.ADOQuery2 do
  begin
    Close;
    Sql.Clear;
    Sql.Add('Delete');
    Sql.Add('From SCSJ_DSYJXSXX1');
    Sql.Add('Where 设备编码=' + IntToStr(MachineNo));
    Sql.Add('And 收据号=' + IntToStr(SjNo));
    Sql.Add('And Convert(char(10),日期,20)>=''' + DateToStr(Date1) + '''');
    Sql.Add('And Convert(char(10),日期,20)<=''' + DateToStr(Date2) + '''');
    try
      ExecSql;
    except
      Screen.Cursor := crDefault;
      ShowMessage('无法清空库内有关机器' + IntToStr(MachineNo) + '收据号' +
        IntToStr(SjNo) + '的数据,系统无法继续工作!');
      Exit;
    end;
  end;
  Result := True;
end;

{------------------------删除采集退货表中当前机器号和交易号的退货记录------------------------------------------------}

function TFrmCJ_Main.EmptyCurrentTh(MachineNo, SjNo: integer; Date1, Date2:
  TDate): Boolean;
begin
  Result := False;
  with FrmCJ_DataModule.ADOQuery2 do
  begin
    Close;
    Sql.Clear;
    Sql.Add('Delete');
    Sql.Add('From SCSJ_DTH');
    Sql.Add('Where 设备编码=' + IntToStr(MachineNo));
    Sql.Add('And 收据号=' + IntToStr(SjNo));
    Sql.Add('And Convert(char(10),日期,20)>=''' + DateToStr(Date1) + '''');
    Sql.Add('And Convert(char(10),日期,20)<=''' + DateToStr(Date2) + '''');
    try
      ExecSql;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -