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

📄 unit1.pas

📁 PosEasy收银系统源码,Pos机前后台管理代码
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Db, DBTables,registry, ExtCtrls, OleCtrls, MSCommLib_TLB,Unit13;

type
  TForm1 = class(TForm)
    Query1: TQuery;
    Image1: TImage;
    User: TEdit;
    Password: TEdit;
    Querypriceserver: TQuery;
    Querypricepos: TQuery;
    Database2: TDatabase;
    database1: TDatabase;
    Qryserupload: TQuery;
    qryposupload: TQuery;
    Databasetest: TDatabase;
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    function goreg(var regname:string): boolean;
    procedure FormCreate(Sender: TObject);
    procedure MakeCursorHide;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  confirm:boolean;
  clerk:string;
  curstate:boolean;
implementation
uses
  unit2, Unit4, Unit6, Unit7,Unit8,Unit9, Waite, Unitface;
{$R *.DFM}

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
 tmpsql:string;
 sno:integer;
 i:integer;
begin
 if key=Vk_F1 then
  begin

   form1.Show;

  end;
 if key=Vk_F5 then
  begin
   formsetting.show;
   mainform.Hide;

  end;
 if key=Vk_F6 then
  begin

   application.CreateForm(Tformconfirm,formconfirm);
   formconfirm.showmodal;
   if confirm=true then
    begin
     confirm:=false;
     application.CreateForm(Tformcash,formcash);
     formcash.showmodal;
    end;
  end;

 if key=Vk_F10 then
  begin
   application.CreateForm(Tformconfirm,formconfirm);
   formconfirm.showmodal;
   if confirm=true then
    begin
      confirm:=false;
      //清除挂帐信息
       with qryposupload do
       begin
         tmpsql:='delete from tmptrade';
         close;
         sql.clear;
         sql.Add(tmpsql);
         prepare;
         try
          execsql;
         except
          messagebox(form1.handle,'数据库连接失败','错误',MB_OK);
          exit;
         end;
       end;
    //判断网络是否连通
     if database1.AliasName='guohua' then
     begin
      //把本地数据上传
      //读取最大的交易流水号
      with qryserupload do
      begin
        tmpsql:='select max(sno) as Msno from trade';// where clerk=''123''';
        close;
        sql.Clear;
        sql.Add(tmpsql);
        prepare;
        try
         open;
        except
         messagebox(form1.handle,'数据库连接失败','错误',MB_OK);
         exit;
        end;
      end;

       if qryserupload['msno']=null then
        sno:=0
       else
        sno:=qryserupload['msno'];

     with qryposupload do
      begin
       tmpsql:='select * from trade';
       close;
       sql.clear;
       sql.add(tmpsql);
       prepare;
       try
        open;
       except
        messagebox(form1.handle,'本地数据库连接失败,检查网络','警告',MB_OK+MB_ICONERROR);
        exit;
       end;
      end;

    form1.database1.StartTransaction;
    try
      i:=0;
      while not qryposupload.Eof do
       begin

          with qryserupload do
           begin
           if (i mod 2)=0 then
            sno:=sno+1;
            tmpsql:='Insert Into trade(op,ecr,clerk,tmpclerk,saler,saledate,saletime,sno,orgtotal,total,totaldis,totalsub,';
            tmpsql:=tmpsql+'pay1,pay2,pay3,pay4,pay5,pay6,change,dept,code,name,discount,num,price,amount,sub,imark)';
            tmpsql:=tmpsql+' values('''+qryposupload['op']+''','''+qryposupload['ecr']+''','''+qryposupload['clerk']+''','''+qryposupload['tmpclerk']+''','''+qryposupload['saler']+''','''+qryposupload['saledate']+''',';
            tmpsql:=tmpsql+''''+qryposupload['saletime']+''','''+inttostr(sno)+''','+floattostr(qryposupload['orgtotal'])+','+floattostr(qryposupload['total'])+','+floattostr(qryposupload['totaldis'])+','+floattostr(qryposupload['totalsub'])+','+floattostr(qryposupload['pay1'])+',';
            tmpsql:=tmpsql+''+floattostr(qryposupload['pay2'])+','+floattostr(qryposupload['pay3'])+','+floattostr(qryposupload['pay4'])+','+floattostr(qryposupload['pay5'])+','+floattostr(qryposupload['pay6'])+','+floattostr(qryposupload['change'])+',';
            tmpsql:=tmpsql+''''+qryposupload['dept']+''','''+qryposupload['code']+''','''+qryposupload['name']+''',';
            tmpsql:=tmpsql+''''+floattostr(qryposupload['discount'])+''','''+floattostr(qryposupload['num'])+''',';
            tmpsql:=tmpsql+':tmpdj,:tmpje,:tmpzr,''0'')';


            close;
            sql.clear;
            sql.add(tmpsql);
            parambyname('tmpdj').asfloat:=qryposupload['price'];
            parambyname('tmpje').asfloat:=qryposupload['amount'];
            parambyname('tmpzr').asfloat:=qryposupload['sub'];
            prepare;
            try
             execsql;

            except
              //messagebox(mainform.handle,'数据库连接失败','错误',MB_OK);
             exit;
            end;
           end;
           i:=i+1;
           qryposupload.Next;

      end;

      form1.database1.Commit;
     except
         form1.database1.Rollback;
         messagebox(form1.handle,'数据库连接失败,检查网络','警告',MB_OK+MB_ICONERROR);
         exit;
     end;
      //清除本地机信息
       with qryposupload do
         begin
            tmpsql:='delete from trade';
            close;
            sql.Clear;
            sql.add(tmpsql);
            prepare;
            try
             execsql;
            except
             messagebox(form1.handle,'本地数据库连接失败,检查网络','警告',MB_OK+MB_ICONERROR);
             exit;
            end;
         end;
   end;
     application.CreateForm(TformShutDown,formShutDown);
     formShutDown.showmodal;

 end;
end;

 if key=VK_RETURN then
  begin
    if (user.Text<>'') and (password.Text<>'') then
     begin
     //判断网络是否连通
      try
         databasetest.Connected:=false;
         databasetest.AliasName:='guohua';
         databasetest.Connected:=true;
         if database1.AliasName='curposdata' then
          begin
           database1.Connected:=false;
           database1.AliasName:='guohua';
           database1.Connected:=true;
           curstate:=true;
          end;
       except
         curstate:=false;
         database1.Connected:=false;
         database1.AliasName:='curposdata';
         database1.Connected:=true;
       end;
       with query1 do
       begin
        tmpsql:='select * from clerkbase where ccode='''+user.text+''' and cpass='''+password.Text+'''';
        close;
        sql.clear;
        sql.add(tmpsql);
        prepare;
        try
          open;
        except
          messagebox(form1.handle,'数据库连接失败','错误',MB_OK+MB_ICONERROR);
          exit;
        end;
       end;
       if not query1.Eof then
       begin
        mainform.show;
        form1.Hide;

       end;
     end
     else
     begin
      key:=0;
      postmessage(Handle,WM_NextDlgCTL,0,0);
     end;
  end;

end;

procedure TForm1.FormShow(Sender: TObject);
var
  tmpsql:string;
  i:integer;
begin
 //判断网络是否连通
      try
         databasetest.Connected:=false;
         databasetest.AliasName:='guohua';
         databasetest.Connected:=true;
         if database1.AliasName='curposdata' then
          begin
           database1.Connected:=false;
           database1.AliasName:='guohua';
           database1.Connected:=true;
           curstate:=true;
          end;
       except
         curstate:=false;
         database1.Connected:=false;
         database1.AliasName:='curposdata';
         database1.Connected:=true;
       end;

  if database1.AliasName='guohua' then
     begin
      //把本地数据上传
      //读取最大的交易流水号
      with qryserupload do
      begin
        tmpsql:='select max(sno) as Msno from trade';
        close;
        sql.Clear;
        sql.Add(tmpsql);
        prepare;
        try
         open;
        except
         messagebox(form1.handle,'流水号读取失败','错误',MB_OK);
         exit;
        end;
      end;

       if qryserupload['msno']=null then
        sno:=0
       else
        sno:=qryserupload['msno'];

     with qryposupload do
      begin
       tmpsql:='select * from trade';
       close;
       sql.clear;
       sql.add(tmpsql);
       prepare;
       try
        open;
       except
        messagebox(form1.handle,'本地数据库连接失败,检查网络','警告',MB_OK+MB_ICONERROR);
        exit;
       end;
      end;

    form1.database1.StartTransaction;
    try
      i:=0;
      while not qryposupload.Eof do
       begin

          with qryserupload do
           begin
           if (i mod 2)=0 then
            sno:=sno+1;
            tmpsql:='Insert Into trade(op,ecr,clerk,tmpclerk,saler,saledate,saletime,sno,orgtotal,total,totaldis,totalsub,';
            tmpsql:=tmpsql+'pay1,pay2,pay3,pay4,pay5,pay6,change,dept,code,name,discount,num,price,amount,sub,imark)';
            tmpsql:=tmpsql+' values('''+qryposupload['op']+''','''+qryposupload['ecr']+''','''+qryposupload['clerk']+''','''+qryposupload['tmpclerk']+''','''+qryposupload['saler']+''','''+qryposupload['saledate']+''',';
            tmpsql:=tmpsql+''''+qryposupload['saletime']+''','''+inttostr(sno)+''','+floattostr(qryposupload['orgtotal'])+','+floattostr(qryposupload['total'])+','+floattostr(qryposupload['totaldis'])+','+floattostr(qryposupload['totalsub'])+','+floattostr(qryposupload['pay1'])+',';
            tmpsql:=tmpsql+''+floattostr(qryposupload['pay2'])+','+floattostr(qryposupload['pay3'])+','+floattostr(qryposupload['pay4'])+','+floattostr(qryposupload['pay5'])+','+floattostr(qryposupload['pay6'])+','+floattostr(qryposupload['change'])+',';
            tmpsql:=tmpsql+''''+qryposupload['dept']+''','''+qryposupload['code']+''','''+qryposupload['name']+''',';
            tmpsql:=tmpsql+''''+floattostr(qryposupload['discount'])+''','''+floattostr(qryposupload['num'])+''',';
            tmpsql:=tmpsql+':tmpdj,:tmpje,:tmpzr,''0'')';


            close;
            sql.clear;
            sql.add(tmpsql);
            parambyname('tmpdj').asfloat:=qryposupload['price'];
            parambyname('tmpje').asfloat:=qryposupload['amount'];
            parambyname('tmpzr').asfloat:=qryposupload['sub'];
            prepare;
            try
             execsql;

            except
              //messagebox(mainform.handle,'数据库连接失败','错误',MB_OK);
             exit;
            end;
           end;
           i:=i+1;
           qryposupload.Next;

      end;

      form1.database1.Commit;
     except
         form1.database1.Rollback;
         messagebox(form1.handle,'数据库连接失败,检查网络','警告',MB_OK+MB_ICONERROR);
         exit;
     end;
      //清除本地机信息
       with qryposupload do
         begin
            tmpsql:='delete from trade';
            close;
            sql.Clear;
            sql.add(tmpsql);
            prepare;
            try
             execsql;
            except
             messagebox(form1.handle,'本地数据库连接失败,检查网络','警告',MB_OK+MB_ICONERROR);
             exit;
            end;
         end;
   end;
 //隐藏鼠标
 makeCursorHide;
 user.Text:='';
 password.Text:='';
 user.SetFocus;


 if mainform.IsShowed then
 begin
   //客显
   //使用 COM1。
   mainform.MSComm1.CommPort :=1;
   //9600 波特,无奇偶校验,8 位数据,一个停止位。
   mainform.MSComm1.Settings := '9600,N,8,1';
   //当输入占用时,
   //告诉控件读入整个缓冲区。
   mainform.MSComm1.InputLen := 0;
   //打开端口。
   mainform.MSComm1.PortOpen := True;
   //将 attention 命令送到调制解调器。
   mainform.MSComm1.Output := Chr($1B) + Chr($51) + Chr($41) + '    WELCOME '+ Chr(13); //确保 SWORDZJ
   //mainform.MSComm1.Output := Chr($21) + Chr($23) + Chr($34);
   mainform.MSComm1.Output := Chr($1B) + Chr($51) + Chr($42) + '    '+ Chr(13); //确保 SWORDZJ
   //关闭串行端口。
   mainform.MSComm1.PortOpen := False;
 end;


end;

function TForm1.goreg(var regname: string): boolean;
var
  MyReg:TRegistry;
begin
  MyReg:=TRegistry.Create ;
  MyReg.RootKey :=HKEY_LOCAL_MACHINE;
  try
    if not MyReg.OpenKey ('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',True)
    then ;
    begin
      MyReg.WriteString('POS',regname);
    end;
  finally
    MyReg.Free ;
  end;
  goreg:=true;
end;


procedure TForm1.FormCreate(Sender: TObject);
var
 myname:string;
begin


 try

   database1.Connected:=true;
   curstate:=true;
 except
   messagebox(form1.handle,'服务器数据库连接失败,转入单机模式','警告',MB_OK+MB_ICONERROR);
   curstate:=false;
   database1.Connected:=false;
   database1.AliasName:='curposdata';
   database1.Connected:=true;
   exit;
 end;
   application.ProcessMessages;
   frmFace.ProgressBar1.StepIt;
   frmFace.ProgressBar1.StepIt;
 try

   form1.database2.Connected:=true;
 except
   messagebox(form1.handle,'本地数据库连接失败','警告',MB_OK+MB_ICONERROR);
   exit;
 end;



 frmFace.ProgressBar1.StepIt;
 frmFace.ProgressBar1.Position:=frmFace.ProgressBar1.Max;

 //调用下载线程
 TloadThread.Create(false);



 //写注册表
 myname:=application.ExeName;

 //goreg(myname);
end;

procedure TForm1.MakeCursorHide;
begin
  SetCursorPos(0,0);
end;

end.

⌨️ 快捷键说明

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