📄 main.pas
字号:
Form1.bookquery.SQL.Clear;
Form1.bookquery.SQL.Add('select * from yujing where Mphone = '+num);
Form1.bookquery.Open;
if Form1.bookquery.Eof then
result:=''
else
result:=Form1.bookquery.Fieldbyname('Pname').Value;
Form1.bookquery.Close;
end;
end;
procedure TForm1.InSMSFromSQL(str:string);
var
i:integer;
begin
bookquery.SQL.Clear;
bookquery.SQL.Add('select * from insms where (G_ATTRIBUTE = '+str+') order by G_TIME desc');
bookquery.Open;
if bookquery.RecordCount >0 then
begin
InSMSListView.Items.Clear;
bookquery.First;
for i:=0 to bookquery.RecordCount-1 do
begin
InSMSListView.Items.Add;
InSMSListView.Items.Item[InSMSListView.Items.Count-1].Caption:=
trim(ChangeSMS2(bookquery.Fieldbyname('G_content').Value));
InSMSListView.Items.Item[InSMSListView.Items.Count-1].SubItems.add
(trim(bookquery.Fieldbyname('G_NUMBER').Value));
InSMSListView.Items.Item[InSMSListView.Items.Count-1].SubItems.add
(trim(bookquery.Fieldbyname('G_TIME').Value));
{if (str='1') then
InSMSListView.Items.Item[InSMSListView.Items.Count-1].SubItems.add('未读')
else
InSMSListView.Items.Item[InSMSListView.Items.Count-1].SubItems.add('已读'); }
bookquery.Next;
end;
end else InSMSListView.Items.Clear;
bookquery.Close;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
RecNewMsg,SendFailedMsg:pchar;
s:string;
i,j:Integer;
begin
Timer1.Enabled:=false;
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GetMem(RecNewMsg,200);
GetMem(SendFailedMsg,200);
for i:=0 to Length(ModuleStatus)-1 do
begin
if ModuleStatus[i] and GetNewMsg(i+1, RecNewMsg) then //接收新信息
begin
for j:=0 to length(RecNewMsg)-1 do
begin
if (RecNewMsg[j]='|') then
begin
//======存储过程存储数据======================
with Form1.ADOCommand_SMS do
begin
try
Parameters.Clear;
Parameters.AddParameter.Name:='G_content';
Parameters.AddParameter.Name:='G_TIME';
Parameters.AddParameter.Name:='G_NUMBER';
Parameters.AddParameter.Name:='G_ATTRIBUTE';
CommandText:='exec p_insms @G_content=:G_content,@G_TIME=:G_TIME,@G_NUMBER=:G_NUMBER,@G_ATTRIBUTE=:G_ATTRIBUTE';
Parameters.ParamByName('G_content').Value:=ChangeSMS(copy(RecNewMsg,j+20,length(RecNewMsg)));
Parameters.ParamByName('G_TIME').Value:=copy(RecNewMsg,j+2,17);
Parameters.ParamByName('G_NUMBER').Value:=copy(RecNewMsg,0,j);
Parameters.ParamByName('G_ATTRIBUTE').Value:=1;
Execute;
except
end;
end;
InSMSFromSQL('1'); //读取新信息
break;
end;
end;
end else
if RecNewMsg='Module Error' then
begin
StatusBar1.Panels[0].Text:='出错提示:模块'+IntToStr(i+1)+'无响应';
ModuleStatus[i]:=False;
end;
if ModuleStatus[i] and GetFailedMsg(i+1,SendFailedMsg) then //提取发送失败的信息
begin
j:=pos('|',SendFailedMsg);
s:=copy(SendFailedMsg,j+1,160);
{//======存储过程存储数据======================
with Form1.ADOCommand_ADD do
begin
try
Parameters.Clear;
Parameters.AddParameter.Name:='G_content';
Parameters.AddParameter.Name:='G_TIME';
Parameters.AddParameter.Name:='G_NAME';
Parameters.AddParameter.Name:='G_NUMBER';
Parameters.AddParameter.Name:='G_ATTRIBUTE';
CommandText:='exec p_UNSENDsms @G_content=:G_content,@G_TIME=:G_TIME,@G_NAME=:NAME,@G_NUMBER=:G_NUMBER,@G_ATTRIBUTE=:G_ATTRIBUTE';
Parameters.ParamByName('G_content').Value:=copy(s,j+1,length(s));
Parameters.ParamByName('G_TIME').Value:=formatdatetime('yy-mm-dd hh:mm:ss',now);
Parameters.ParamByName('G_NAME').Value:=numbertoname(copy(s,1,j-1));
Parameters.ParamByName('G_NUMBER').Value:=copy(s,1,j-1);
Parameters.ParamByName('G_ATTRIBUTE').Value:='发送失败';
Execute;
except
end;
end;}
with UnSendSMSListView do
begin
j:=pos('|',s);
Items.Add;
Items.Item[Items.Count-1].Caption:=copy(s,j+1,length(s));
Items.Item[Items.Count-1].SubItems.Add(numbertoname(copy(s,1,j-1)));
Items.Item[Items.Count-1].SubItems.Add(copy(s,1,j-1));
Items.Item[Items.Count-1].SubItems.Add('发送失败');
Items.Item[Items.Count-1].SubItems.Add(formatdatetime('yy-mm-dd hh:mm:ss',now));
end;
end;
end;
UnSendSMSTab.Caption:='发送失败('+inttostr(UnSendSMSListView.Items.count)+')';
FreeMem(RecNewMsg);
FreeMem(SendFailedMsg);
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Timer1.Enabled:=true;
end;
function TForm1.ChangeSMS(Str:String):String;
var
i:integer;
begin
while pos(#13,str)<>0 do
begin
i:=pos(#13,str);
str:=copy(str,1,i-1)+'|'+copy(str,i+1,length(str));
end;
while pos(#10,str)<>0 do
begin
i:=pos(#10,str);
str:=copy(str,1,i-1)+copy(str,i+1,length(str));
end;
result:=trim(str);
end;
function TForm1.ChangeSMS2(Str:String):String;
var
i:integer;
begin
while pos('|',str)<>0 do
begin
i:=pos('|',str);
str:=copy(str,1,i-1)+chr(13)+chr(10)+copy(str,i+1,length(str));
end;
result:=trim(str);
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var
i:integer;
begin
//=====显示系统时间==============================
StatusBar1.Panels[2].Text:=' '+formatdatetime('yyyy-mm-dd hh:mm:ss',now);
//=====读数据库,是否有短信要发送======================
Timer2.Enabled:=False;
WaitSMSQuery.SQL.Clear;
WaitSMSQuery.SQL.Add('select * from waitsms');
WaitSMSQuery.Open;
if WaitSMSQuery.RecordCount >0 then
begin
WaitSMSQuery.First;
for i:=0 to WaitSMSQuery.RecordCount-1 do
begin
with form1.WaitSMSListView do
begin
Items.Add;
Items.Item[Items.Count-1].Caption:=trim(WaitSMSQuery.Fieldbyname('G_CONTENT').Value);
Items.Item[Items.Count-1].SubItems.Add('');
Items.Item[Items.Count-1].SubItems.Add(trim(WaitSMSQuery.Fieldbyname('G_NUMBER').Value));
Items.Item[Items.Count-1].SubItems.Add('');
WaitSMSQuery.Edit;
WaitSMSQuery.Delete;
WaitSMSQuery.Next;
end;
end;
SendSMS();
end;
WaitSMSQuery.Close;
Timer2.Enabled:=True;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Application.MessageBox('您真的决定退出程序?','提示',MB_OKCANCEL)=ID_CANCEL then
Action:=canone;
end;
//==========待发信息右键菜单===========================
procedure TForm1.WaitSMSListViewMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i:integer; mousepos:TPoint;
begin
for i:=0 to WaitSMSListView.Items.Count-1 do
begin
if WaitSMSListView.Items.Item[i].Selected and (Button=mbRight)then
begin
WaitId:=i;
GetCursorPos(mousepos); //获取鼠标位置
WaitPopupMenu.Popup(mousepos.X, mousepos.Y); // 弹出菜单;
break;
end;
end;
end;
//==========收件箱右键菜单===========================
procedure TForm1.InSMSListViewMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i:integer; mousepos:TPoint;
begin
for i:=0 to InSMSListView.Items.Count-1 do
begin
if InSMSListView.Items.Item[i].Selected and (Button=mbRight)then
begin
WaitId:=i;
GetCursorPos(mousepos); //获取鼠标位置
InPopupMenu.Popup(mousepos.X, mousepos.Y); // 弹出菜单;
break;
end;
end;
end;
//==========未发信息右键菜单===========================
procedure TForm1.UnSendSMSListViewMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i:integer; mousepos:TPoint;
begin
for i:=0 to UnSendSMSListView.Items.Count-1 do
begin
if UnSendSMSListView.Items.Item[i].Selected and (Button=mbRight)then
begin
WaitId:=i;
GetCursorPos(mousepos); //获取鼠标位置
UnPopupMenu.Popup(mousepos.X, mousepos.Y); // 弹出菜单;
break;
end;
end;
end;
//========按下发送键发送=====================================
procedure TForm1.BitBtn4Click(Sender: TObject);
begin
if not ModuleStatus[ComboBox1.ItemIndex] then
begin
StatusBar1.Panels[0].Text:='模块未打开';
end else
begin
if WaitSMSListView.Items.Count=0 then showmessage('没有可发送的信息!') else
begin
StatusBar1.Panels[3].Text:='';
SendSMS();
end;
end;
end;
//=========发送程序===========================================
procedure TForm1.SendSMS();
var
UnSendMsg:pchar;
ChOrEh:boolean;
begin
ProgressBar1.Max:=WaitSMSListView.Items.Count;
ProgressBar1.Step:=1;
ProgressBar1.Position:=0;
StopSend:=false;
BitBtn5.Enabled:=true;
BitBtn4.Enabled:=false;
Button1.Enabled:=false;
S2.Enabled:=false;
N2.Enabled:=false;
Timer1.Enabled:=false;
Timer2.Enabled:=false;
GetMem(UnSendMsg,200);
if SMSLength=70 then ChOrEh:=true
else ChOrEh:=false;
repeat
SendMsg(ComboBox1.ItemIndex+1,
Pchar(WaitSMSListView.Items.Item[WaitSMSListView.Items.Count-1].Caption),
Pchar(WaitSMSListView.Items.Item[WaitSMSListView.Items.Count-1].SubItems.Strings[1]),
1,ChOrEh);
repeat
Application.ProcessMessages;//中断响应
StatusBar1.Panels[1].Text:=' 正在发送...';
until not GetNextSendMsg(ComboBox1.ItemIndex+1,UnSendMsg,false);//重复执行,直到该语句为真
//=====进度条显示================================
ProgressBar1.StepIt;
StatusBar1.Panels[3].Text:=' 已完成'+FormatFloat('0',(ProgressBar1.Position/ProgressBar1.Max)*100)+'%';
WaitSMSListView.Items.Delete(WaitSMSListView.Items.Count-1);
until ((WaitSMSListView.Items.Count=0) or StopSend);//重复执行,直到该语句为真
if StopSend then
StatusBar1.Panels[1].Text:=' 发送停止'
else
StatusBar1.Panels[1].Text:=' 发送完毕';
FreeMem(UnSendMsg);
BitBtn5.Enabled:=false;
BitBtn4.Enabled:=true;
Button1.Enabled:=true;
N2.Enabled:=true;
S2.Enabled:=true;
Timer1.Enabled:=true;
Timer2.Enabled:=true;
end;
procedure TForm1.SendSMSOnce(Msg,MobileNo:string);
var
UnSendMsg:pchar;
ChOrEh:boolean;
begin
ProgressBar1.Max:=1;
ProgressBar1.Step:=1;
ProgressBar1.Position:=0;
StopSend:=false;
BitBtn5.Enabled:=true;
BitBtn4.Enabled:=false;
Button1.Enabled:=false;
N2.Enabled:=false;
S2.Enabled:=false;
Timer1.Enabled:=false;
Timer2.Enabled:=false;
GetMem(UnSendMsg,200);
if SMSLength=70 then ChOrEh:=true
else ChOrEh:=false;
SendMsg(ComboBox1.ItemIndex+1,Pchar(Msg),Pchar(MobileNo),1,ChOrEh);
repeat
Application.ProcessMessages;//中断响应
StatusBar1.Panels[1].Text:=' 正在发送...';
until not GetNextSendMsg(ComboBox1.ItemIndex+1,UnSendMsg,false);//重复执行,直到该语句为真
//=====进度条显示================================
ProgressBar1.StepIt;
StatusBar1.Panels[1].Text:=' 发送完毕';
StatusBar1.Panels[3].Text:=' 完成';
FreeMem(UnSendMsg);
BitBtn5.Enabled:=false;
BitBtn4.Enabled:=true;
Button1.Enabled:=true;
N2.Enabled:=true;
S2.Enabled:=true;
Timer1.Enabled:=true;
Timer2.Enabled:=true;
end;
//======停止键按下============================
procedure TForm1.BitBtn5Click(Sender: TObject);
begin
StopSend:=true;
BitBtn5.Enabled:=false;
StatusBar1.Panels[1].Text:=' 正在停止发送...';
end;
//========待发信息右键菜单发送===================
procedure TForm1.N2Click(Sender: TObject);
begin
if not ModuleStatus[ComboBox1.ItemIndex] then
begin
StatusBar1.Panels[0].Text:='模块未打开';
end else
begin
SendSMSOnce(WaitSMSListView.Items.Item[WaitId].Caption,
WaitSMSListView.Items.Item[WaitId].SubItems.Strings[1]);
WaitSMSListView.Items.Delete(WaitId);
end;
end;
//========待发信息右键菜单删除===================
procedure TForm1.N4Click(Sender: TObject);
begin
WaitSMSListView.Items.Delete(WaitId);
end;
//========待发信息右键菜单全部删除===================
procedure TForm1.N5Click(Sender: TObject);
begin
WaitSMSListView.Clear;
end;
//========未发信息右键菜单删除===================
procedure TForm1.D2Click(Sender: TObject);
begin
UnSendSMSListView.Items.Delete(WaitId);
end;
//========未发信息右键菜单全部删除===================
procedure TForm1.N12Click(Sender: TObject);
begin
UnSendSMSListView.Clear;
end;
//========未发信息右键菜单发送===================
procedure TForm1.S2Click(Sender: TObject);
begin
if not ModuleStatus[ComboBox1.ItemIndex] then
begin
StatusBar1.Panels[0].Text:='模块未打开';
end else
begin
SendSMSOnce(UnSendSMSListView.Items.Item[WaitId].Caption,
UnSendSMSListView.Items.Item[WaitId].SubItems.Strings[1]);
UnSendSMSListView.Items.Delete(WaitId);
end;
end;
procedure TForm1.N9Click(Sender: TObject);
begin
ADOTable_Edit.TableName:='insms';
ADOTable_Edit.Active:=true;
ADOTable_Edit.Locate('G_time',InSMSListView.Items.Item[WaitId].SubItems.Strings[1],[]);
ADOTable_Edit.Edit;
ADOTable_Edit.Delete;
ADOTable_Edit.Active:=false;
InSMSFromSQL('1'); //读取信息
end;
procedure TForm1.N10Click(Sender: TObject);
begin
with Form1.ADOCommand_ADD do
begin
try
Parameters.Clear;
CommandText:='delete from insms';
Execute;
except
end;
end;
InSMSFromSQL('1'); //读取信息
end;
procedure TForm1.TreeView1DblClick(Sender: TObject);
begin
sendcontent:='';
if treeview1.Selected.Level<>1 then exit;
sendcontent:=TreeView1.Selected.Text;
Form2.ShowModal;
end;
procedure TForm1.WMNID(var msg:TMessage);
begin
case msg.LParam of
WM_LBUTTONDBLCLK:
begin
Form1.Visible:=true;
//Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); // 显示主窗体后删除托盘区的图标
SetWindowPos(Application.Handle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW);
end;
//WM_RBUTTONUP: ShowMessage('您点击的是右键');
end;
End;
procedure TForm1.SysCommand(var SysMsg: TMessage);
begin
case SysMsg.WParam of
SC_MINIMIZE:
begin
Form1.Visible:=false;
SetWindowPos(Application.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_HIDEWINDOW);
Hide; // 在任务栏隐藏程序
end;
else
inherited;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@NotifyIcon);
end;
procedure TForm1.N7Click(Sender: TObject);
begin
if Application.MessageBox('您真的决定退出程序?','提示',MB_OKCANCEL)=ID_OK then
Application.Terminate;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form4.Show;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -