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

📄 pfm_accept.pas

📁 主要是介绍DELPHI三层应用以及分布式数据库的应用
💻 PAS
📖 第 1 页 / 共 3 页
字号:
unit pfm_accept;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, Db, DBTables, CheckLst, ExtCtrls,DateUtils,StrUtils,
  ADODB, FileCtrl;

type
  Tfm_databack = class(TForm)
    GroupBox1: TGroupBox;
    Memo1: TMemo;
    Label1: TLabel;
    BatMove1: TBatchMove;
    table1: TQuery;
    Table2: TTable;
    Table3: TTable;
    OpenDialog1: TOpenDialog;
    Panel1: TPanel;
    RadioGroup1: TRadioGroup;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    GroupBox3: TGroupBox;
    Edit1: TEdit;
    Button2: TButton;
    BitBtn1: TBitBtn;
    GroupBox4: TGroupBox;
    CkLBox1: TCheckListBox;
    Panel2: TPanel;
    BBtnNoall: TBitBtn;
    BBtnSelall: TBitBtn;
    BitBtn2: TButton;
    Button1: TButton;
    query1: TQuery;
    ComboBox3: TComboBox;
    Label4: TLabel;
    RadioGroup2: TRadioGroup;
    procedure FormCreate(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BBtnSelallClick(Sender: TObject);
    procedure BBtnNoallClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure RadioGroup1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure RadioGroup2Click(Sender: TObject);


  private
    { Private declarations }
    function GetSql(i:integer):string;
    function IfGetBefore(tempName:string):boolean;
    procedure DeleteFormerRecord(tempName:string;i:integer);
    procedure WriteRecord(tableName:string);
    procedure ModifyRecord(tableName:string;i:integer);
    procedure OpenFile(tempFile:string);
    function Choosestyle():boolean;
    function DelDir(DriverPath:string):boolean;
    procedure AddBackUpFields(tablename:string);
    procedure DealPartInfo ();
  public
    datastyle:string;
    { Public declarations }
  end;

var
  fm_databack: Tfm_databack;


implementation

uses Unit_wxp, pfm_selectdir, wxp_dm;

{$R *.DFM}
var
AcceptTableName,stimename,stable,stabledes:TStringlist;
myFileName:TextFile;
backStyle:string;
backTime:string;
lastBackTime:string;
fileContent:string;
FromOffice:string;
FromUser:string;
fromtime:string;
TableCount:integer;
GetBefore:boolean;
FilePath:string;
HasTable :array[0..50] of integer;


procedure Tfm_databack.FormCreate(Sender: TObject);
var
i:integer;
begin
    //label1.Caption:='上次上报数据时间'+InitRead2('上报数据','时间','无');
     stable:=TStringlist.create;
     stimename:=tstringlist.Create ;
     stabledes:=Tstringlist.create;


     if (unit_wxp.datastyle ='up') and (unit_wxp.myOffice <>'总部') then
     begin
          stable.Add('partleft');
          stabledes.Add('配件库存上报');
          stimename.Add('日期');
     end;
     if  (unit_wxp.datastyle='up') and (unit_wxp.myOffice ='总部') then
     begin
          stable.Add('pub_z_part');
          stabledes.Add('配件基本信息');
          stimename.Add('日期');

          stable.Add('std_machine');
          stabledes.Add('机型标准表');
          stimename.Add('录入日期');
     end;

     if  (unit_wxp.datastyle='down') and (unit_wxp.myOffice ='总部') then
     begin
          stable.Add('partleft');
          stabledes.Add('配件库存接收');
          stimename.Add('日期');
     end;

     if  (unit_wxp.datastyle='down') and (unit_wxp.myOffice <>'总部') then
     begin
          stable.Add('pub_z_part');
          stabledes.Add('配件基本信息');
          stimename.Add('录入日期');

          stable.Add('std_machine');
          stabledes.Add('机型标准表');
          stimename.Add('录入日期');

     end;

     stable.Add('pub_z_partsell');
     stabledes.Add('配件回笼信息');
     stimename.Add('录入日期');
     stable.Add('pub_z_partorder');
     stabledes.Add('配件订单表');
     stimename.Add('录入日期');
     stable.Add('pub_z_partin');
     stabledes.Add('零件入库单信息');
     stimename.Add('录入日期');
     stable.Add('pub_z_partout');
     stabledes.Add('零件出库信息');
     stimename.Add('录入日期');
     stable.Add('pub_z_test');
     stabledes.Add('试机报告信息');
     stimename.Add('录入日期');
     stable.Add('pub_z_maintain');
     stabledes.Add('机器维修信息');
     stimename.Add('录入日期');

     stable.Add('pub_z_contract');
     stabledes.Add('合同主表');
     stimename.Add('录入时间'); 

     stable.Add('pub_z_contract_machine');
     stabledes.Add('机器销售表');
     stimename.Add('录入时间');

     stable.Add('pub_z_contract_project');
     stabledes.Add('特别工程款表');
     stimename.Add('录入时间');

     stable.Add('pub_z_contract_specialties');
     stabledes.Add('合同的其他特殊装置');
     stimename.Add('录入时间');


     stable.Add('pub_z_contract_payment_before');
     stabledes.Add('合同预期付款');
     stimename.Add('录入时间');


     stable.Add('pub_z_contract_payment_record');
     stabledes.Add('合同付款记录');
     stimename.Add('录入时间');


     stable.Add('pub_z_contract_machine_requisition');
     stabledes.Add('宁波震雄出机单');
     stimename.Add('录入时间');


     stable.Add('pub_z_contract_machine_requisition_ys');
     stabledes.Add('亚塑机械出机单');
     stimename.Add('录入时间');


     stable.Add('pub_z_machine_out');
     stabledes.Add('产品出库通知');
     stimename.Add('录入时间');


     stable.Add('pub_z_machine_in');
     stabledes.Add('产品入库通知');
     stimename.Add('录入时间');


     stable.Add('pub_z_machine_outpay');
     stabledes.Add('出机应付款汇总表');
     stimename.Add('录入时间');

     stable.Add('pub_z_hk_in');
     stabledes.Add('货款回收汇总表');
     stimename.Add('录入时间');

     stable.Add('pub_z_cjqk');
     stabledes.Add('出机情况汇总表');
     stimename.Add('录入时间');

     stable.Add('pub_z_thqk');
     stabledes.Add('退货情况汇总表');
     stimename.Add('录入时间');

     stable.Add('pub_z_client');
     stabledes.Add('客户登记表');
     stimename.Add('录入日期');

     stable.Add('pub_c_client_person');
     stabledes.Add('客户联系人 ');
     stimename.Add('录入日期');

     stable.Add('pub_z_visitold');
     stabledes.Add('客户回访表');
     stimename.Add('录入日期');

     stable.Add('pub_z_complaint');
     stabledes.Add('客户投诉表');
     stimename.Add('录入日期');

     backstyle:='日';
     backtime:=floattostr(yearof(today))+'-'+floattostr(monthof(today))+
     '-'+floattostr(dayof(today));

     if unit_wxp.datastyle ='up' then
     begin
          for i:=0 to stable.count-1 do
          begin
          cklbox1.Items.Add(stabledes.strings[i]);
          end;
     end;


end;

procedure Tfm_databack.BitBtn1Click(Sender: TObject);
var
i,j,cnt1:integer;
tempSql:string;
ifChoose:boolean;
begin


     if ChooseStyle=false then
     begin
        //showmessage('请正确选择上报方式');
        exit;
     end;


    for i:=0 to stable.count-1 do
    begin
        if  cklbox1.Checked[i]=true then
        begin
            ifChoose:=true;
            break;
        end;
    end;

    if not ifchoose then
    begin
         showmessage('请选择要上报的表');
         exit;
    end;

    if DelDir(edit1.Text )=false then
       exit;
    


    if application.MessageBox(pchar('上报数据将花费较长的时间,确定要上报当前所有数据'),
        pchar('注意'),MB_OKCANCEL)<>IDOK then
    begin
        exit;
    end;

     //创建文件

     AssignFile(myFileName,filepath+'zxjx.txt');
     rewrite(myFileName);
     fromtime:=datetimetostr(now);
     writeln(myFileName,'上报时间:'+fromtime);

     memo1.lines.add('上报时间:'+fromtime);
     writeln(myFileName,'办事处:'+unit_wxp.myoffice);
     memo1.lines.add('办事处:'+unit_wxp.myoffice);
     writeln(myFileName,'上报人:'+unit_wxp.username);
     memo1.lines.add('上报人:'+unit_wxp.username);
     cnt1:=0;
     table1.Databasename:='zxjx';
     batmove1.mode:=batcopy;
     batmove1.Source:=table1;
     batmove1.Destination:=table2;
     AcceptTableName:=tstringlist.Create;
     for i:=0 to stable.count-1 do
     begin
        if  cklbox1.Checked[i]=true then
        begin
            //在上报以前修改每张表的上报时间
            if (stable.Strings[i]<>'pub_z_part') or (stable.Strings[i]='partleft')  then
            MOdifyRecord(stable.Strings[i],i);
            
            
            //上报数据
            //AddBackUpFields(stable.Strings[i]);
            memo1.lines.add('正在上报【'+stabledes.strings[i]+'】......');
            table1.Close ;
            table1.SQL.Clear ;
            if  (stable.Strings[i]<>'partleft') and (stable.Strings[i]<>'pub_z_part')
            and (stable.Strings[i]<>'std_machine')
            then
                table1.SQL.Add('select * from '+ stable.Strings[i]+ getsql(i))
            else if (stable.Strings[i]='std_machine') then
                table1.SQL.Add('select * from std_machine')
            else
                table1.SQL.Add('select * from pub_z_part');
            table1.Active :=true;
            //table1.tablename:=stable.Strings[i];

            table2.tablename:=filepath +stable.Strings[i]+'.db';

            batmove1.Execute;
            cnt1:=cnt1+1;
            AcceptTableName.Add(stable.Strings[i]);
        end;
     end;
     writeln(myFileName,'上报表数:'+inttostr(cnt1));
     memo1.lines.add('上报表数:'+inttostr(cnt1));
     writeln(myFileName,'上报类型:'+backStyle);
     memo1.lines.add('上报类型:'+backStyle);
     writeln(myFileName,'上报内容:'+backTime);
     memo1.lines.add('上报内容:'+backTime);
     //写入文件中
     for i:=0 to AcceptTableName.Count -1 do
     begin
          writeln(myFileName,'表名:'+AcceptTableName.Strings[i]);
     end;

     if cnt1=0 then exit;
    memo1.lines.add('数据库上报成功!共有'+inttostr(cnt1)+'个数据库表上报');
    label1.caption:='上次上报数据时间'+datetimetostr(date());
    closeFile(myFileName);
    edit1.Text :='backdata';


end;

procedure Tfm_databack.BitBtn2Click(Sender: TObject);
var
i,cnt1,j:integer;


begin


     if application.MessageBox(pchar('此次接收数据的上报时间为'+
     fromtime+',接收数据会删除原来的数据,确定要接收数据嘛?'),
     pchar('注意'),MB_OKCANCEL)<>IDOK then
         exit;

     memo1.Lines.Add('现在开始恢复数据');


     cnt1:=0;
     table2.Databasename:='zxjx';
     batmove1.mode:=batappend;
     batmove1.Source:=table3;
     batmove1.Destination:=table2;


     for i:=0 to CkLBox1.Count -1 do
     begin
        if  cklbox1.Checked[i]=true then
        begin
        //删除原来记录
                      if  (stable.Strings[hastable[i]]<>'pub_z_part') then

                          DeleteFormerRecord (stable.Strings[hastable[i]],hastable[i]);


                      memo1.lines.add('正在恢复【'+stabledes.strings[hastable[i]]+'】......');

⌨️ 快捷键说明

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