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

📄 main.pas

📁 中国联通 CDMA点对点短信话单分析入库的程序
💻 PAS
字号:
unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, RzButton, RzTabs, RzPanel, DB, DBAccess, Ora,
  StdCtrls, RzEdit, Grids, DBGrids, RzRadChk,StrUtils, RzShellDialogs,
  MemDS, OraSmart,header, ComCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    RzPanel1: TRzPanel;
    RzPageControl1: TRzPageControl;
    TabSheet1: TRzTabSheet;
    TabSheet2: TRzTabSheet;
    RzButton1: TRzButton;
    RzButton2: TRzButton;
    Conn: TOraSession;
    RzMemo1: TRzMemo;
    RzGroupBox1: TRzGroupBox;
    Splitter1: TSplitter;
    DBGrid1: TDBGrid;
    RzCheckBox1: TRzCheckBox;
    LEdit1: TLabeledEdit;
    LEdit2: TLabeledEdit;
    CheckBox2: TCheckBox;
    CheckBox1: TCheckBox;
    RzSelectFolderDialog1: TRzSelectFolderDialog;
    Edit1: TEdit;
    Button1: TButton;
    RzButton3: TRzButton;
    Timer2: TTimer;
    LEdit3: TLabeledEdit;
    SQ1: TSmartQuery;
    ins_cdma: TOraSQL;
    DS_FILELOAD: TOraDataSource;
    t_c_fileload: TSmartQuery;
    t_c_fileloadFILENAME: TStringField;
    t_c_fileloadFILESIZE: TFloatField;
    t_c_fileloadDEALDATE: TDateTimeField;
    t_c_fileloadFILEID: TStringField;
    t_c_fileloadSMSCENTER: TStringField;
    t_c_fileloadLINENUM: TFloatField;
    t_c_fileloadFILEDATE: TStringField;
    ProgressBar1: TProgressBar;
    procedure RzButton1Click(Sender: TObject);
    procedure RzButton2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure RzButton3Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
  private
    { Private declarations }
    procedure LoadGSMReport;
    procedure LoadCDMACDR;
    procedure Display(logstr: string);
    function fileloaded(file_name:String ):Boolean;
    function loadfile(file_name:String):Boolean;
    procedure insert_cdma(rowcontent:CDMA_FILEBODY);
    procedure logfileload(v_file_name:String;v_count,v_count1:Integer;v_fileid,v_smscenter,v_filedate:String);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses IniFiles,FileCtrl;
{$R *.dfm}
procedure TForm1.RzButton1Click(Sender: TObject);
begin
 try
  Timer2.Interval:=StrToInt(LEdit2.Text)*1000;
  RzButton1.Enabled := false;
  if checkBox1.Checked then Timer1.Enabled := true;
  if checkBox2.Checked then Timer2.Enabled := true;
  RzButton2.Enabled := true;
 except
   on E: Exception do Display(E.Message);
 end;
end;

procedure TForm1.RzButton2Click(Sender: TObject);
begin
  Timer1.Enabled := false;
  Timer2.Enabled := false;
  RzButton2.Enabled := false;
  RzButton1.Enabled := true;
end;
procedure TForm1.Display(logstr: string);
begin
  RzMemo1.Lines.Add(FormatDateTime('YYYY-MM-DD hh:mm:ss', Now()) + ' ' + logstr)
end;
procedure TForm1.FormCreate(Sender: TObject);
var RunConfig: TIniFile;
begin
  RunConfig := TIniFile.Create(ExtractFileDir(Application.ExeName) + '\\Config.ini');
  with RunConfig do begin
  Conn.Server := ReadString('dbset', 'server', 'ucsys');
  Conn.Username := ReadString('dbset', 'user', 'ucsys');
  Conn.Password := ReadString('dbset', 'password', 'ucsys');
  if (ReadString('runparam', 'auto_start', '0') = '1') then RzCheckBox1.Checked := true;
  if ReadString('runparam','sync_gsm','0')='1' then CheckBox1.Checked := true;
  if ReadString('runparam','sync_cdma','0')='1' then CheckBox2.Checked := true;
  LEdit1.Text:=ReadString('runparam','gsm_start_time','01:00:00');
  LEdit2.Text:=ReadString('runparam','cdma_sync_interval','300');
  LEdit3.Text:=ReadString('runparam','file_ext','*.dat');
  Edit1.Text:=ReadString('runparam','cdma_cdr_path','c:\');
  Free;
  end;
  //if not ProcNameSel.Active then ProcNameSel.Open;
  //DispList;
  //if (RzCheckBox1.Checked) then RzButton1Click(Application);
  RzPageControl1.ActivePage:=TabSheet1;
  t_c_fileload.Open
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
LEdit1.Enabled:= CheckBox1.Checked;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
LEdit2.Enabled:= CheckBox2.Checked;
Edit1.Enabled:=CheckBox2.Checked
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
RzSelectFolderDialog1.Execute;
Edit1.Text:=RzSelectFolderDialog1.SelectedPathName;
end;

procedure TForm1.RzButton3Click(Sender: TObject);
var RunConfig: TIniFile;
begin
  RunConfig := TIniFile.Create(ExtractFileDir(Application.ExeName) + '\\Config.ini');
  with RunConfig do begin
  if (RzCheckBox1.Checked) then   WriteString('runparam','auto_start','1')
  else WriteString('runparam','auto_start','0');
  if CheckBox1.Checked then WriteString('runparam','sync_gsm','1')
  else WriteString('runparam','sync_gsm','0');
  if CheckBox2.Checked then WriteString('runparam','sync_cdma','1')
  else WriteString('runparam','sync_cdma','0');
  WriteString('runparam','gsm_start_time',LEdit1.Text);
  WriteString('runparam','cdma_sync_interval',LEdit2.Text);
  WriteString('runparam','file_ext',LEdit3.Text);
  WriteString('runparam','cdma_cdr_path',Edit1.Text);
  Free;
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var nowtime :String;
begin
 nowtime:=FormatDateTime('hh:nn', now());
 if nowtime=LeftStr(LEdit1.Text,5) then begin
   LoadGSMReport;
 end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
  LoadCDMACDR;
end;

procedure TForm1.LoadGSMReport;
begin

end;

procedure TForm1.LoadCDMACDR;
var Dir:TFileListBox;
i:Integer;
filename:String;
begin
//if fileloaded()
  Dir:=TFileListBox.Create(self);
  Dir.ParentWindow:=Application.Handle;
  with Dir do begin
   Mask:=LEdit3.Text;
   Directory:=Edit1.Text;
   for i:=0 to Items.Count-1 do begin
    filename:= Items.Strings[i];
    if not fileloaded(filename) then begin
      Display('正在导入文件:'+filename);
      if loadfile(filename) then begin
        Display('已将文件'+filename+'成功导入');
        t_c_fileload.Close;
        t_c_fileload.Open;
      end;
    end;
   end;
   Free;
  end;
end;
function TForm1.fileloaded(file_name:String):Boolean;
begin
  with SQ1 do begin
    SQL.Clear;
    SQL.Add('select * from t_c_fileload where filename='''+ExtractFileName(file_name)+'''');
    Open;
    Result:=not(Eof);
  end;
end;
function TForm1.loadfile(file_name:String):Boolean;
var Lines :TStringList;
i,Count,count1:Integer;
Row,smscenter,fileid,filedate:String;
file_end:Boolean;
filebody:CDMA_FILEBODY;
begin
  Result:=false;
  if FileExists(file_name) then begin
  Lines:=  TStringList.Create();
  try
    Lines.LoadFromFile(file_name);
    Count:=Lines.Count;
    if Count>0 then begin
    ProgressBar1.Min:=0;
    ProgressBar1.Max:=Count;
    Row:=Lines.Strings[0];//read head infomations
      if LeftStr(row,4)='HEAD' then begin
      smscenter:=MidStr(row,5,24);
      fileid:=MidStr(row,29,4);
      file_end:=false;
      i:=1;
      Conn.StartTransaction;
       try
        while not file_end do begin
          row:=Lines.Strings[i];
          if LeftStr(row,4)='TAIL' then begin
            file_end:=true;
            count1:=StrToInt(MidStr(row,5,8));
            filedate:=MidStr(row,13,14);
          end
          else begin
            with filebody do begin
              RecNo:=MidStr(row,1,15);
              CallType:=MidStr(row,16,2);
              CallingNumber :=MidStr(row,18,24);
              CalledNumber:=MidStr(row,42,24);
              RegisterTime:=MidStr(row,66,14);
              SendTime:=MidStr(row,80,14);
              TextLength:=StrToInt(MidStr(row,94,3));
              LastStatus:=StrToInt(MidStr(row,97,5));
              ServiceType:=StrToInt(MidStr(row,102,3));
              ServiceType_Ext:=StrToInt(MidStr(row,105,4));
              LangType:=StrToInt(MidStr(row,109,1));
              Priority:=StrToInt(MidStr(row,110,2));
              //ChargedParty:=StrToInt(MidStr(row,112,1));
              ChargedParty:=0;
            end;
            insert_cdma(filebody);
            ProgressBar1.Position:=i;
            inc(i);
          end;
        end;
        logfileload(ExtractFileName(file_name),i-1,count1,fileid,smscenter,filedate);
        Conn.Commit;
        Display('文件记录数:'+IntToStr(count1)+'实际导入记录数:'+IntToStr(i-1)+'文件生产日期:'+filedate);
       except
        on E: Exception do begin
          Display(E.Message);
          Conn.Rollback;
        end;
       end;
      end
      else Display('文件格式不正确');
    end
    else Display('文件无内容');
  finally
    Lines.Free;
  end;
  end
  else
  Display('文件'+file_name+'不存在');
end;
procedure TForm1.insert_cdma(rowcontent:CDMA_FILEBODY);
begin
  try
  with ins_cdma do begin
    Params.ParamByName('RecNo').Value:=rowcontent.RecNo;
    params.ParamByName('CallType').Value:=rowcontent.CallType;
    params.ParamByName('CallingNumber').Value:=rowcontent.CallingNumber;
    params.ParamByName('CalledNumber').Value:=rowcontent.CalledNumber;
    params.ParamByName('RegisterTime').Value:=rowcontent.RegisterTime;
    params.ParamByName('SendTime').Value:=rowcontent.SendTime;
    params.ParamByName('TextLength').Value:=rowcontent.TextLength;
    params.ParamByName('LastStatus').Value:=rowcontent.LastStatus;
    params.ParamByName('ServiceType').Value:=rowcontent.ServiceType;
    params.ParamByName('ServiceType_Ext').Value:=rowcontent.ServiceType_Ext;
    params.ParamByName('LangType').Value:=rowcontent.LangType;
    params.ParamByName('Priority').Value:=rowcontent.Priority;
    params.ParamByName('ChargedParty').Value:=rowcontent.ChargedParty;
    Execute;
  end;
  except
    on E: Exception do Display(E.Message);
  end;
end;
procedure TForm1.logfileload(v_file_name:String;v_count,v_count1:Integer;v_fileid,v_smscenter,v_filedate:String);
begin
  with SQ1 do begin
    SQL.Clear;
    SQL.Add('insert into t_c_fileload (FILENAME ,FILESIZE,DEALDATE,FILEID,SMSCENTER,LINENUM,FILEDATE)');
    SQL.Add(' values ('''+v_file_name+''','+IntToStr(v_count)+',sysdate,'''+v_fileid+''','''+v_smscenter+''','+IntToStr(v_count1)+','''+v_filedate+''')');
    ExecSQL;
  end;
end;
end.

⌨️ 快捷键说明

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