📄 gsmwizunit.~pas
字号:
unit GSMWizUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ActnList, ComCtrls, ToolWin, ImgList, ExtCtrls, StdCtrls, Grids,
ValEdit, INIFiles, GSMCom, DateUtils, Menus;
type
TMainForm = class(TForm)
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ActionList1: TActionList;
TestSetAction: TAction;
ImageList1: TImageList;
StopAction: TAction;
SendAction: TAction;
ToolButton3: TToolButton;
Panel1: TPanel;
Shape1: TShape;
Shape2: TShape;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
StatusBar1: TStatusBar;
Panel2: TPanel;
GSMComCombo: TComboBox;
ErrorCheckBox: TCheckBox;
SuccessCheckBox: TCheckBox;
SetCheckBox: TCheckBox;
TaskInfoEditor: TValueListEditor;
Shape4: TShape;
LogListBox: TListBox;
GComListView: TListView;
BatchTimer: TTimer;
FeeAction: TAction;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ForceFeeAction: TAction;
NotifyLabel: TLabel;
ForceSendAction: TAction;
ToolButton7: TToolButton;
ReActiveAction: TAction;
TabSheet3: TTabSheet;
FeeLogListBox: TListBox;
Panel3: TPanel;
FeeNotifyLabel: TLabel;
Shape5: TShape;
SheduleTimer: TTimer;
ToolButton9: TToolButton;
ToolButton10: TToolButton;
AddMobileAction: TAction;
OpenDialog1: TOpenDialog;
FeeTimer: TTimer;
SetPopupMenu: TPopupMenu;
N1: TMenuItem;
S1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
ToolButton4: TToolButton;
ToolButton8: TToolButton;
LowSpeedAction: TAction;
procedure FormCreate(Sender: TObject);
procedure TestSetActionExecute(Sender: TObject);
procedure SendActionExecute(Sender: TObject);
procedure BatchTimerTimer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure StopActionExecute(Sender: TObject);
procedure ForceFeeActionExecute(Sender: TObject);
procedure ForceSendActionExecute(Sender: TObject);
procedure SheduleTimerTimer(Sender: TObject);
procedure AddMobileActionExecute(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FeeTimerTimer(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure S1Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure LowSpeedActionExecute(Sender: TObject);
private
{ Private declarations }
FServer: TGSMServer;
FTasks: TGSMTasks;
procedure InitGSMWiz;
procedure FinalGSMWiz;
procedure BuildThreadList;
procedure BackUPLog;
procedure WriteSystemLog;
procedure PrepaireSending;
protected
procedure GSMAfterCheck(Index: Integer; state: TGSMSetState);
procedure GSMBeforeCheck(Index: Integer);
procedure WndProc(var Message: TMessage); override;
public
{ Public declarations }
procedure WriteLog(Log: String);
procedure WriteFeeLog(FeeLog: String);
end;
var
MainForm: TMainForm;
INITaskName: String;
INISMSMessage: String;
INIMobileListName: String;
INISendedCount: Integer;
INIWaitMax: Integer;
INIBatchCount: Integer;
ININotifyCount: Integer;
ININotifyMobileNo: String;
IniFailedCount: Integer;
INIReadCount: Integer;
MobileList: TStringList;
GlobStartTime: TDateTime;
GlobAutoStopTime: TDateTime;
GlobAutoStartTime: TDateTime;
GlobAutoStop: Boolean;
GlobNeedCheckFee: Boolean;
GlobStartCount: Integer;
GlobSendMode: Boolean;
GlobAutoCheckFeeTime: Integer;
GlobAutoCheckFee: Boolean;
GlobAutoCheckFeeStartTime: TDateTime;
GlobAutoCheckFeeStopTime: TDateTime;
GlobAutoCheckFeeMode: Boolean;
INIisCallPhoneTask: Boolean;
INICallNo : String;
INIDialTime: Integer;
INIDialRandom: Integer;
INIRepeatCount: Integer;
INIStopFee: Currency;
WizINIFile: String;
FEEINIFile: String;
LogINIFile: String;
GlobLogCount: Integer;
SetList: TStringList;
implementation
uses ExitForm, Math;
{$R *.dfm}
{ TForm1 }
procedure TMainForm.BuildThreadList;
var
i: Integer;
AListItem: TListItem;
ComboIndex: Integer;
begin
GComListView.Clear;
GSMComCombo.Items.Clear;
ComboIndex := GSMComCombo.ItemIndex;
GSMComCombo.Items.Add('所有设备');
if ComboIndex =-1 then
ComboIndex := 0;
for i:=0 to FServer.GSMSets.Count-1 do
begin
AListItem := GComListView.Items.Add;
AListItem.ImageIndex := -1;
AListItem.Caption :=Format('GSM%.2d',[FServer.GSMSets.GSMSet[i].Port]);
AListItem.SubItems.Add('等待');
AListItem.SubItems.Add('');
AListItem.SubItems.Add('');
AListItem.SubItems.Add('');
AListItem.SubItems.Add('');
AListItem.SubItems.Add('');
GSMComCombo.Items.Add('设备['+AListItem.Caption+']');
end;
GSMComCombo.ItemIndex := ComboIndex;
end;
procedure TMainForm.InitGSMWiz;
var
INIFile: TIniFile;
i: Integer;
begin
GlobLogCount := 0;
GlobSendMode := false;
GlobAutoCheckFeeMode := false;
NotifyLabel.Caption := '';
FeeNotifyLabel.Caption := '';
FEEINIFile := ExtractFilePath(Application.ExeName)+'Fee.ini';
WizINIFile := ExtractFilePath(Application.ExeName)+'GSMWiz.ini';
LogINIFile := ExtractFilePath(Application.ExeName)+'Log.ini';
FServer := TGSMServer.Create;
FTasks := TGSMTasks.Create(FServer);
FTasks.AddTask;
MobileList := TStringList.Create;
INIFile := TIniFile.Create(WizINIFile);
GlobAutoCheckFee := INIFile.ReadBool('COMMON','AutoCheckFee',true);
GlobAutoCheckFeeStartTime := INIFile.ReadTime('COMMON','AutoCheckFeeStartTime',StrToTime('7:00:00'));
GlobAutoCheckFeeStopTime := INIFile.ReadTime('COMMON','AutoCheckFeeStopTime',StrToTime('21:00:00'));
GlobDialLowSpeed:=INIFile.ReadBool('COMMON','DialLowSpeed',true);
GlobDialDelayTime:=INIFile.ReadInteger('COMMON','DialDelayTime',360000);
LowSpeedAction.Checked := GlobDialLowSpeed;
FServer.GSMSets.ForceSetPort(INIFile.ReadString('COMMON','PortString','1;2'));
for i:=0 to FServer.GSMSets.Count-1 do
SetList.Add(IntToStr(i));
INIStopFee := INIFile.ReadFloat('COMMON','StopFee',-1);
for i:= 0 to FServer.GSMSets.Count-1 do
FServer.GSMSets.GSMSet[i].FeeLowLevel := INIStopFee;
INIisCallPhoneTask := INIFile.ReadBool('COMMON','isCallPhoneTask',false);
INICallNo := INIFile.ReadString('COMMON','CallNo','');
INIRepeatCount:=INIFile.ReadInteger('COMMON','RepeatCount',0);
INIDialTime := INIFile.ReadInteger('COMMON','DialTime',300000);
INIDialRandom := INIFile.ReadInteger('COMMON','DialRandom',0);
// if is Dial Task , Then No Need to Load The Mobiles List
if INIisCallPhoneTask then
begin
TaskInfoEditor.Strings.Strings[1] := '拨打号码=';
TaskInfoEditor.Strings.Strings[2] := '拨打次数=';
TaskInfoEditor.Values['拨打号码'] := INICallNo;
if INIRepeatCount=-1 then
TaskInfoEditor.Values['拨打次数'] := '无限次'
else
TaskInfoEditor.Values['拨打次数'] := IntToStr(INIRepeatCount);
end
else
begin
INIMobileListName := ExtractFilePath(Application.ExeName)+INIFile.ReadString('COMMON','MobileListName','');
if FileExists(INIMobileListName) then
begin
MobileList.LoadFromFile(INIMobileListName);
TaskInfoEditor.Values['手机列表文件'] := INIMobileListName;
end
else
TaskInfoEditor.Values['手机列表文件'] := INIMobileListName + '《----文件不存在!!!!';
INISMSMessage := INIFile.ReadString('COMMON','SMSMessage['+DateToStr(now)+']','');
TaskInfoEditor.Values['短信内容'] := INISMSMessage;
end;
INIWaitMax := INIFile.ReadInteger('COMMON','WaitMax',1000);
INITaskName := INIFile.ReadString('COMMON','TaskName','未命名');
INIBatchCount := INIFile.ReadInteger('COMMON','BatchCount',10);
ININotifyCount := INIFile.ReadInteger('COMMON','NotifyCount',5000);
ININotifyMobileNo := INIFile.ReadString('COMMON', 'NotifyMobileNo','');
GlobAutoCheckFeeTime := INIFile.ReadInteger('COMMON','AutoCheckFeeTime',3600000);
FeeTimer.Interval := 600000;
GlobAutoStop := INIFile.ReadBool('COMMON','AutoStop',false);
if GlobAutoStop then
begin
GlobAutoStopTime := INIFile.ReadTime('COMMON','AutoStopTime',StrToTime('21:00:00'));
GlobAutoStartTime := INIFile.ReadTime('COMMON','AutoStartTime',StrToTime('9:00:00'));
end;
INIFile.Free;
INIFile := TIniFile.Create(LogINIFile);
INISendedCount := INIFile.ReadInteger('LOG','SendedCount',0);
IniFailedCount := INIFile.ReadInteger('LOG','FailedCount',0);
INIReadCount := INISendedCount + IniFailedCount - ((INISendedCount + IniFailedCount) div ININotifyCount);
GlobStartCount := INIReadCount;
// INIReadCount := INIFile.ReadInteger('COMMON','ReadCount',0);
INIFile.Free;
TaskInfoEditor.Values['任务名称'] := INITaskName;
Application.Title := 'GSMWiz - '+INITaskName;
MainForm.Caption := Application.Title;
TaskInfoEditor.Values['已发送'] := IntToStr(INISendedCount);
if not INIisCallPhoneTask then
TaskInfoEditor.Values['未发送'] := IntToStr(MobileList.Count-INIReadCount)
else if INIRepeatCount=-1 then
TaskInfoEditor.Values['未发送'] := '无限次'
else
TaskInfoEditor.Values['未发送'] := IntToStr(INIRepeatCount-INIReadCount);
BuildThreadList;
INIFile := TIniFile.Create(FEEINIFile);
GlobNeedCheckFee := INIFile.ReadBool('Fee','NeedCheckFee',true);
INIFile.Free;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
try
SetList:= TStringList.Create;
InitGSMWiz;
except
end;
end;
procedure TMainForm.FinalGSMWiz;
var
IniFile: TIniFile;
begin
IniFile := TIniFile.Create(LogINIFile);
IniFile.WriteInteger('Log','SendedCount',INISendedCount);
IniFile.WriteInteger('Log','FailedCount',IniFailedCount);
IniFile.free;
MobileList.Free;
FTasks.Free;
FServer.Free;
end;
procedure TMainForm.GSMAfterCheck(Index: Integer; state: TGSMSetState);
begin
case state of
gsIdle:
GComListView.Items[Index].SubItems[0] := '正常';
gsInvalid:
GComListView.Items[Index].SubItems[0] := '无效';
gsBusy:
GComListView.Items[Index].SubItems[0] := '忙碌';
gsOutTime:
GComListView.Items[Index].SubItems[0] := '超时';
gsUnknown:
GComListView.Items[Index].SubItems[0] := '未知';
end;
end;
procedure TMainForm.GSMBeforeCheck(Index: Integer);
begin
GComListView.ItemIndex := Index;
GComListView.Selected := GComListView.Items.Item[Index];
GComListView.Items[Index].SubItems[0] := '检测中....';
end;
procedure TMainForm.TestSetActionExecute(Sender: TObject);
var
i: Integer;
NotAllOK: Boolean;
begin
NotifyLabel.Caption := '开始检测设备,请稍候...';
StopAction.Enabled := false;
TestSetAction.Enabled := false;
StatusBar1.Panels.Items[0].Text := '开始测试设备......';
FServer.GSMSets.OnGSMAfterCheck := GSMAfterCheck;
FServer.GSMSets.OnGSMBeforeCheck := GSMBeforeCheck;
PageControl1.ActivePageIndex := 0;
// GComListView.SetFocus;
FServer.GSMSets.TestDevice;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -