📄 gsmwizunit.~pas
字号:
FServer.GSMSets.OnGSMBeforeCheck := nil;
FServer.GSMSets.OnGSMAfterCheck := nil;
NotAllOK := false;
for i:= 0 to FServer.GSMSets.Count-1 do
begin
if FServer.GSMSets.GSMSet[i].state<>gsIdle then
begin
NotAllOK := true;
break;
end;
end;
if NotAllOK then
begin
TestSetAction.Enabled := true;
// SendAction.Enabled := false;
// FeeAction.Enabled := false;
// ReActiveAction.Enabled := false;
StatusBar1.Panels.Items[0].Text := '检测完成,部分设备有错误';
NotifyLabel.Caption := '检测完成,部分设备有错误,请重新检测!';
end
else
begin
ForceSendAction.Enabled := true;
TestSetAction.Enabled := false;
ForceFeeAction.Enabled := true;
ReActiveAction.Enabled := true;
if GlobNeedCheckFee then
FeeAction.Enabled := true
else
SendAction.Enabled := true;
StatusBar1.Panels.Items[0].Text := '测试完成,一切OK!';
NotifyLabel.Caption := '测试完成,一切OK!,可以进行下一步操作';
end;
StopAction.Enabled := false;
end;
procedure TMainForm.SendActionExecute(Sender: TObject);
var
i: Integer;
IniFile: TINIFile;
begin
PrepaireSending;
GlobSendMode := true;
NotifyLabel.Caption := '正在发送短信,按停止按钮停止操作...';
StatusBar1.Panels.Items[0].Text := '发送中...';
GlobStartTime := now;
GlobStartCount := INISendedCount;
TaskInfoEditor.Values['开始时间'] := DateTimeToStr(GlobStartTime);
IniFile := TIniFile.Create(LogINIFile);
IniFile.WriteDateTime('LOG','StartTime',now);
IniFile.Free;
for i:=0 to FServer.GSMSets.Count-1 do
begin
if (not FServer.GSMSets.GSMSet[i].InThread) and (FServer.GSMSets.GSMSet[i].FeeState<>gfTooLow) then
begin
FServer.GSMSets.GSMSet[i].Task := FTasks.Task[0];
FServer.GSMSets.GSMSet[i].DoActive;
if INIisCallPhoneTask then
SimpleWait(500);
end;
end;
StopAction.Enabled := true;
BatchTimer.Enabled := true;
FeeTimer.Enabled := true;
end;
procedure TMainForm.BatchTimerTimer(Sender: TObject);
var
StartIndex,EndIndex: Integer;
i: Integer;
ASMSMessageItem: TGSMMessageItem;
ADialItem: TGSMDialItem;
WaitSendCount: Integer;
IniFile: TINIFile;
StartMinutes: Integer;
FrequenceStr: String;
begin
Randomize;
SheduleTimer.Enabled := true;
if INIisCallPhoneTask then
begin
IniFile := TIniFile.Create(LogINIFile);
StatusBar1.Panels.Items[1].Text := DateTimeToStr(now);
StartMinutes := MinutesBetween(GlobStartTime,Now);
if StartMinutes>0 then
begin
FrequenceStr := '频率:'+FloatToStr((INISendedCount-GlobStartCount) / StartMinutes)+'次/分钟';
StatusBar1.Panels.Items[2].Text := FrequenceStr;
end;
if FTasks.Task[0].WaitSendCount<INIWaitMax then
begin
StartIndex := INIReadCount;
if (INIRepeatCount=-1) or (StartIndex + INIBatchCount<INIRepeatCount) then
EndIndex := StartIndex + INIBatchCount
else
EndIndex := INIRepeatCount;
for i :=StartIndex to EndIndex-1 do
begin
ADialItem := TGSMDialItem.Create;
ADialItem.MobileNo := INICallNo;
if INIDialRandom<>0 then
ADialItem.DialTime := ((INIDialTime+Random(INIDialRandom)) div 60000)*60000+10000
else
ADialItem.DialTime := INIDialTime;
FTasks.Task[0].WaitSendItems.AddFromSendItem(ADialItem);
if ((i mod ININotifyCount)=0) and (ININotifyMobileNo<>'') then
begin
ASMSMessageItem := TGSMMessageItem.Create;
ASMSMessageItem.SMSMessage := INITaskName + '读取了'+InttoStr(i)+ '条, 已经拨打 '+ IntToStr(INISendedCount)+'次,失败了'+IntToStr(IniFailedCount)+'次.'+FrequenceStr;
ASMSMessageItem.MobileNo := ININotifyMobileNo;
FTasks.Task[0].WaitSendItems.AddFromSendItem(ASMSMessageItem);
end;
if (INIRepeatCount<>-1) and (i =INIRepeatCount-1) and (ININotifyMobileNo<>'') then
begin
ASMSMessageItem := TGSMMessageItem.Create;
ASMSMessageItem.SMSMessage := INITaskName + ' 任务已经完成.已经发送了 '+ IntToStr(INISendedCount)+'条,失败了'+IntToStr(IniFailedCount)+'条.'+FrequenceStr;
ASMSMessageItem.MobileNo := ININotifyMobileNo;
FTasks.Task[0].WaitSendItems.AddFromSendItem(ASMSMessageItem);
end;
end;
StartIndex := EndIndex;
INIReadCount := EndIndex;
IniFile.WriteInteger('LOG','ReadCount',0);
end;
IniFile.WriteInteger('LOG','SendedCount',INISendedCount);
IniFile.WriteInteger('LOG','FailedCount',IniFailedCount);
WaitSendCount := FTasks.Task[0].WaitSendCount;
TaskInfoEditor.Values['等待发送队列'] := IntToStr(WaitSendCount);
if INIRepeatCount<>-1 then
TaskInfoEditor.Values['未发送'] := IntToStr(INIRepeatCount-INIReadCount);
if ((WaitSendCount = 0) and (INIRepeatCount<>-1) and (StartIndex>=INIRepeatCount-1)) then
begin
BatchTimer.Enabled := false;
StopActionExecute(sender);
StatusBar1.Panels.Items[0].Text := '发送完成';
StatusBar1.Panels.Items[1].Text := '完成时间 '+DateTimeToStr(now) ;
Caption := '发送完成';
StopAction.Enabled := false;
NotifyLabel.Caption := '所有内容已经发送完成!';
BackUPLog;
end;
IniFile.Free;
end
else
begin
IniFile := TIniFile.Create(LogINIFile);
StatusBar1.Panels.Items[1].Text := DateTimeToStr(now);
StartMinutes := MinutesBetween(GlobStartTime,Now);
if StartMinutes>0 then
begin
FrequenceStr := '频率:'+IntToStr(INISendedCount div StartMinutes)+'条/分钟';
StatusBar1.Panels.Items[2].Text := FrequenceStr;
end;
if FTasks.Task[0].WaitSendCount<INIWaitMax then
begin
StartIndex := INIReadCount;
if StartIndex + INIBatchCount<MobileList.Count then
EndIndex := StartIndex + INIBatchCount
else
EndIndex := MobileList.Count;
for i :=StartIndex to EndIndex-1 do
begin
ASMSMessageItem := TGSMMessageItem.Create;
ASMSMessageItem.MobileNo := MobileList[i];
ASMSMessageItem.SMSMessage := INISMSMessage;
FTasks.Task[0].WaitSendItems.AddFromSendItem(ASMSMessageItem);
if ((i mod ININotifyCount)=0) and (ININotifyMobileNo<>'') then
begin
ASMSMessageItem := TGSMMessageItem.Create;
ASMSMessageItem.SMSMessage := INITaskName +'读取了'+InttoStr(i)+ '条, 已经发送了 '+ IntToStr(INISendedCount)+'条,失败了'+IntToStr(IniFailedCount)+'条.'+FrequenceStr;
ASMSMessageItem.MobileNo := ININotifyMobileNo;
FTasks.Task[0].WaitSendItems.AddFromSendItem(ASMSMessageItem);
end;
if (i =MobileList.Count-1) and (ININotifyMobileNo<>'') then
begin
ASMSMessageItem := TGSMMessageItem.Create;
ASMSMessageItem.SMSMessage := INITaskName + ' 任务已经完成.已经发送了 '+ IntToStr(INISendedCount)+'条,失败了'+IntToStr(IniFailedCount)+'条.'+FrequenceStr;
ASMSMessageItem.MobileNo := ININotifyMobileNo;
FTasks.Task[0].WaitSendItems.AddFromSendItem(ASMSMessageItem);
end;
end;
StartIndex := EndIndex;
INIReadCount := EndIndex;
IniFile.WriteInteger('LOG','ReadCount',0);
end;
IniFile.WriteInteger('LOG','SendedCount',INISendedCount);
IniFile.WriteInteger('LOG','FailedCount',IniFailedCount);
WaitSendCount := FTasks.Task[0].WaitSendCount;
TaskInfoEditor.Values['等待发送队列'] := IntToStr(WaitSendCount);
TaskInfoEditor.Values['未发送'] := IntToStr(MobileList.Count-INIReadCount);
if ((WaitSendCount = 0) and (StartIndex>=MobileList.Count-1)) then
begin
StopActionExecute(sender);
StatusBar1.Panels.Items[0].Text := '发送完成';
StatusBar1.Panels.Items[1].Text := '完成时间 '+DateTimeToStr(now) ;
Caption := '发送完成';
StopAction.Enabled := false;
NotifyLabel.Caption := '所有内容已经发送完成!';
BackUPLog;
end;
IniFile.Free;
end;
end;
procedure TMainForm.WriteLog(Log: String);
var
TargetFile: string;
begin
if LogListBox.Items.Count>=1000 then
begin
TargetFile := ExtractFilePath(Application.ExeName)+'Log\'+Format('GSMLog%.4d.ini',[GlobLogCount mod 1000]);
LogListBox.Items.SaveToFile(TargetFile);
LogListBox.Items.Clear;
GlobLogCount := GlobLogCount + 1;
end;
LogListBox.Items.Add(DateTimeToStr(now)+' : '+Log);
end;
procedure TMainForm.WndProc(var Message: TMessage);
var
Count: Integer;
Index: Integer;
GetFee: Integer;
Fee: Currency;
AListItem: TListItem;
begin
if Message.Msg = WM_SENDSUCC then
begin
Count := Message.LParam;
Index := Message.WParam;
if GlobNeedCheckFee and ((Count<>0) and ((Count mod 10)=0)) then
begin
// AListItem := GComListView.Items.Item[Index];
// FServer.GSMSets.GSMSet[Index].fee := FServer.GSMSets.GSMSet[Index].fee - 0.1*10;
// AListItem.SubItems.Strings[5] := CurrToStr(FServer.GSMSets.GSMSet[Index].fee);
// if FServer.GSMSets.GSMSet[Index].fee<=0 then
// FServer.GSMSets.GSMSet[Index].DoTerminate;
end;
INISendedCount := INISendedCount + 1;
TaskInfoEditor.Values['已发送'] := IntToStr(INISendedCount);
end
else if Message.Msg = WM_SENDERROR then
begin
// Index := Message.WParam;
// Count := Message.LParam;
IniFailedCount := IniFailedCount + 1;
TaskInfoEditor.Values['失败'] := IntToStr(IniFailedCount);
end
else if Message.Msg = WM_STOPFEE then
begin
Index := Message.WParam;
GetFee := Message.LParam;
AListItem := GComListView.Items.Item[Index];
if AListItem<>nil then
begin
AListItem.SubItems.Strings[5] := CurrToStr(FServer.GSMSets.GSMSet[Index].fee);
if GetFee = 0 then
AListItem.SubItems.Strings[0] := '剩余话费完成'
else
AListItem.SubItems.Strings[0] := '剩余话费失败';
end;
end
else if Message.Msg = WM_TOOMANYERROR then
begin
Index := Message.WParam;
AListItem := GComListView.Items.Item[Index];
if AListItem<>nil then
AListItem.SubItems.Strings[0] := '出错次数过多';
FServer.GSMSets.GSMSet[Index].ReActive;
end
else
Inherited;
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
TheExitFom.Show;
StopActionExecute(sender);
if GlobAutoCheckFeeMode then
begin
Action := caNone;
ShowMessage('等待自动');
end
else
begin
Application.ProcessMessages;
StopActionExecute(sender);
FinalGSMWiz;
SetList.Free;
end;
TheExitFom.Hide;
end;
procedure TMainForm.StopActionExecute(Sender: TObject);
var
i: Integer;
NotStop: Boolean;
begin
GlobSendMode := false;
FeeTimer.Enabled := false;
BatchTimer.Enabled := false;
FeeNotifyLabel.Caption := '停止';
NotifyLabel.Caption := '停止所有设备中...';
StatusBar1.Panels.Items[0].Text := '停止所有设备中...';
for i:=0 to FServer.GSMSets.Count-1 do
begin
if FServer.GSMSets.GSMSet[i].InThread then
FServer.GSMSets.GSMSet[i].DoTerminate;
end;
repeat
SimpleWait(100);
NotStop := false;
for i:=0 to FServer.GSMSets.Count-1 do
if FServer.GSMSets.GSMSet[i].InThread then
begin
NotStop := true;
break;
end;
until not NotStop;
NotifyLabel.Caption := '所有设备停止';
StatusBar1.Panels.Items[0].Text := '所有设备停止';
SendAction.Enabled := true;
if GlobNeedCheckFee then
FeeAction.Enabled := true;
StopAction.Enabled := false;
end;
procedure TMainForm.ForceFeeActionExecute(Sender: TObject);
var
i: Integer;
INIFile: TINIfile;
SendAdress: String;
SENDMSG: String;
ReceiveAdress: String;
FeeTemplate: String;
NotStop: Boolean;
NotAllOK: Boolean;
begin
FeeTimer.Enabled := false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -