📄 unitmainform.pas
字号:
except
Screen.Cursor := tc;
UpdateRunStopBtn(False);
raise Exception.Create('通讯设备异常');
end;
end;
procedure TMainForm.Action_StopExecute(Sender: TObject);
var
i: integer;
tc: TCursor;
begin
//停止
tc := Screen.Cursor;
Screen.Cursor := crSQLWait;
try
StopAllThread;
for i:=0 to FModemPool.ModemList.Count-1 do
UpdateListView_CommStat(FModemPool.ModemList.Strings[i], NO_NETSIGNAL, COMM_STOP_STATUS);
UpdateRunStopBtn(False);
Screen.Cursor := tc;
except
Screen.Cursor := tc;
UpdateRunStopBtn(True);
raise Exception.Create('通讯设备异常');
end;
end;
procedure TMainForm.Action_CommStatusExecute(Sender: TObject);
begin
//通讯状态
RzPageControl1.ActivePage := TabSheetComm;
end;
procedure TMainForm.Action_SendLogExecute(Sender: TObject);
begin
//发送短信显示
RzPageControl1.ActivePage := TabSheetSendSMS;
end;
procedure TMainForm.Action_ReceiveLogExecute(Sender: TObject);
begin
//接收短信显示
RzPageControl1.ActivePage := TabSheetRecieveSMS;
end;
procedure TMainForm.Action_DebugExecute(Sender: TObject);
begin
//调试窗口
RzPageControl1.ActivePage := TabSheetDebug;
end;
procedure TMainForm.Action_ClearLogExecute(Sender: TObject);
begin
//清除日志
ListViewSendLog.Items.Clear;
ListViewReceiveLog.Items.Clear;
end;
procedure TMainForm.Action_ExitExecute(Sender: TObject);
begin
//退出系统
Close;
end;
procedure TMainForm.Action_SendSMSExecute(Sender: TObject);
begin
//短信群发
with TSendSMSForm.Create(nil, '', '') do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TMainForm.Action_QuerySMSExecute(Sender: TObject);
begin
//查询统计
with TQueryCountForm.Create(nil) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TMainForm.Action_AutoReplyExecute(Sender: TObject);
begin
//自动回复设置
if BtnStop.Enabled then
begin
if Application.MessageBox('执行此功能必须先停止服务,是否自动停止服务?','提示',MB_OKCancel + MB_DEFBUTTON2 + MB_IconQuestion)<>ID_OK then Exit;
BtnStop.Click;
end;
with TAutoReplyForm.Create(nil) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TMainForm.Action_FeeSMSExecute(Sender: TObject);
begin
//费用控制
if BtnStop.Enabled then
begin
if Application.MessageBox('执行此功能必须先停止服务,是否自动停止服务?','提示',MB_OKCancel + MB_DEFBUTTON2 + MB_IconQuestion)<>ID_OK then Exit;
BtnStop.Click;
end;
with TFeeCtrlForm.Create(nil) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TMainForm.Action_AboutExecute(Sender: TObject);
begin
//关于
TSplashForm.Create(nil, 1).Show;
end;
procedure TMainForm.Action_ShowExecute(Sender: TObject);
begin
//显示主窗口
RzTrayIcon.RestoreApp;
end;
procedure TMainForm.ListViewCommStatCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
//重绘节点
if Item = nil then Exit;
if (Item.SubItems.Strings[2])=COMM_OPEN_STATUS then
ListViewCommStat.Canvas.Font.Color := clLime //打开状态变亮
else
ListViewCommStat.Canvas.Font.Color := clRed; //关闭状态变灰
end;
procedure TMainForm.BtnClearMsgClick(Sender: TObject);
begin
//清除调试窗口
MemoRequestMsg.Clear;
MemoResponseMsg.Clear;
end;
procedure TMainForm.UpdateListView_CommStat(com, net, status: string);
var
i: integer;
ListItem: TListItem;
begin
//刷新通讯设备显示状态
for i:=0 to ListViewCommStat.Items.Count-1 do
begin
ListItem := ListViewCommStat.Items[i];
if ListItem.SubItems.Strings[0]=com then //0-通讯端口名称
begin
ListItem.SubItems.Strings[2] := status; //2-状态
ListItem.SubItems.Strings[6] := net; //1-网络信号接收强度
break;
end;
end;
if ListViewCommStat.CanFocus then ListViewCommStat.SetFocus;
ListViewCommStat.Selected := nil;
ListItem.Selected := True;
ListItem.Focused := True;
end;
procedure TMainForm.AddListView_SendLog(s0,s1,s2,s3,s4: string);
var
ListItem: TListItem;
begin
if ListViewSendLog.Items.Count>LISTVIEW_SHOWLINE_MAXCOUNT then ListViewSendLog.Items.Clear;
ListItem := ListViewSendLog.Items.Add;
ListItem.SubItems.Add(s0); //端口号
ListItem.SubItems.Add(s1); //序号
ListItem.SubItems.Add(s2); //号码
ListItem.SubItems.Add(s3); //时间
ListItem.SubItems.Add(s4); //内容
if ListViewSendLog.CanFocus then ListViewSendLog.SetFocus;
ListViewSendLog.Selected := nil;
ListItem.Selected := True;
ListItem.Focused := True;
//更新状态条
if Trim(StatusPaneSendCount.Caption)='' then
StatusPaneSendCount.Caption := '1'
else
StatusPaneSendCount.Caption := IntToStr(StrToInt(StatusPaneSendCount.Caption) + 1);
end;
procedure TMainForm.AddListView_ReceiveLog(s0,s1,s2,s3,s4: string);
var
ListItem: TListItem;
begin
if ListViewReceiveLog.Items.Count>LISTVIEW_SHOWLINE_MAXCOUNT then ListViewReceiveLog.Items.Clear;
ListItem := ListViewReceiveLog.Items.Add;
ListItem.SubItems.Add(s0); //端口号
ListItem.SubItems.Add(s1); //序号
ListItem.SubItems.Add(s2); //号码
ListItem.SubItems.Add(s3); //时间
ListItem.SubItems.Add(s4); //内容
if ListViewReceiveLog.CanFocus then ListViewReceiveLog.SetFocus;
ListViewReceiveLog.Selected := nil;
ListItem.Selected := True;
ListItem.Focused := True;
//更新状态条
if Trim(StatusPaneReceiveCount.Caption)='' then
StatusPaneReceiveCount.Caption := '1'
else
StatusPaneReceiveCount.Caption := IntToStr(StrToInt(StatusPaneReceiveCount.Caption) + 1);
RzTrayIcon.Animate := True;//图标闪动
end;
procedure TMainForm.ThreadDoAfterProcessing(Sender: TObject; iDoType: integer; MsgList: TStrings);
var
i: integer;
s0, s1, s2, s3, s4: string;
begin
if not Assigned(MsgList) then Exit;
if MsgList.Count<=0 then Exit;
s0 := '';
s1 := '';
s2 := '';
s3 := '';
s4 := '';
if MsgList.Count>0 then s0 := MsgList.Strings[0];
if MsgList.Count>1 then s1 := MsgList.Strings[1];
if MsgList.Count>2 then s2 := MsgList.Strings[2];
if MsgList.Count>3 then s3 := MsgList.Strings[3];
if MsgList.Count>4 then s4 := MsgList.Strings[4];
case iDoType of
DOSCANMODEMSTATUS:
begin
for i:=0 to (MsgList.Count div 2)-1 do //每个设备一组显示参数包含2个字符
begin
if MsgList.Count>=(0+i*2) then s0 := MsgList.Strings[0+i*2];
if MsgList.Count>=(1+i*2) then s1 := MsgList.Strings[1+i*2];
UpdateListView_CommStat(s0, s1, COMM_OPEN_STATUS);
end;
end;
DORECIEVEMSG:
begin
AddListView_ReceiveLog(s0, s1, s2, s3, s4);
end;
DOSENDMSG:
begin
AddListView_SendLog(s0, s1, s2, s3, s4);
end;
end;
end;
procedure TMainForm.InitStringGridListAll;
begin
StringGridListAll.RowCount := 20;
StringGridListAll.Cells[0, 0] := '';
StringGridListAll.Cells[1, 0] := '设备';
StringGridListAll.Cells[2, 0] := '操作类型';
StringGridListAll.Cells[3, 0] := '消息';
FStringGridNowLine := 1;
end;
procedure TMainForm.AddStringGridListAll(s0, s1, s2, s3: string);
var
i: integer;
begin
if FStringGridNowLine>=20 then
begin
for i:=1 to StringGridListAll.RowCount-1 do
StringGridListAll.Rows[i].Clear;
FStringGridNowLine := 1;
end;
StringGridListAll.Row := FStringGridNowLine;
StringGridListAll.Cells[0, FStringGridNowLine] := s0;
StringGridListAll.Cells[1, FStringGridNowLine] := s1;
StringGridListAll.Cells[2, FStringGridNowLine] := s2;
StringGridListAll.Cells[3, FStringGridNowLine] := s3;
Inc(FStringGridNowLine);
end;
procedure TMainForm.ShowMsg(Sender: TObject; ErrorType, CommName, DoType,
Msg: string);
begin
AddStringGridListAll(ErrorType, CommName, DoType, Msg);
end;
procedure TMainForm.BtnStartDebugClick(Sender: TObject);
begin
FDebug := True;
BtnStartDebug.Enabled := False;
BtnStopDebug.Enabled := True;
end;
procedure TMainForm.BtnStopDebugClick(Sender: TObject);
begin
FDebug := False;
BtnStartDebug.Enabled := True;
BtnStopDebug.Enabled := False;
end;
procedure TMainForm.ShowDebug(Sender: TObject; com, request, response: string);
begin
if not FDebug then Exit;
if MemoRequestMsg.Lines.Count>LISTVIEW_SHOWLINE_MAXCOUNT then
begin
MemoRequestMsg.Lines.Clear;
MemoResponseMsg.Lines.Clear;
end;
MemoRequestMsg.Lines.Add('['+com+']:'+request);
MemoResponseMsg.Lines.Add('['+com+']:'+response);
end;
procedure TMainForm.StartAllThread;
begin
FScanModemStatusThread := TScanModemStatusThread.Create(FModemPool, True, 10000);//端口检测线程创建(优先级最低)
FScanModemStatusThread.Priority := tpLower;
FScanModemStatusThread.AfterProcessing := ThreadDoAfterProcessing;
FScanModemStatusThread.ShowMsg := ShowMsg;
if FScanModemStatusThread.Handle<=0 then
begin
raise Exception.Create('设备检测线程创建失败');
Exit;
end;
FSendMsgThread := TSendMsgThread.Create(FModemPool, True, PublicFun.FiSendIntervalTime);//发送短信线程创建
FSendMsgThread.Priority := tpNormal;
FSendMsgThread.AfterProcessing := ThreadDoAfterProcessing;
FSendMsgThread.ShowMsg := ShowMsg;
if FSendMsgThread.Handle<=0 then
begin
raise Exception.Create('发送短信线程创建失败');
Exit;
end;
FRecieveMsgThread := TRecieveMsgThread.Create(FModemPool, True, PublicFun.FiRecieveIntervalTime);//接收短信线程创建
FRecieveMsgThread.Priority := tpNormal;
FRecieveMsgThread.AfterProcessing := ThreadDoAfterProcessing;
FRecieveMsgThread.ShowMsg := ShowMsg;
if FRecieveMsgThread.Handle<=0 then
begin
raise Exception.Create('接收短信线程创建失败');
Exit;
end;
FSendMsgThread.Resume;
FRecieveMsgThread.Resume;
FScanModemStatusThread.Resume;
end;
procedure TMainForm.StopAllThread;
begin
if FScanModemStatusThread<>nil then
begin
FScanModemStatusThread.Terminate;
FScanModemStatusThread := nil;
end;
if FRecieveMsgThread<>nil then
begin
FRecieveMsgThread.Terminate;
FRecieveMsgThread := nil;
end;
if FSendMsgThread<>nil then
begin
FSendMsgThread.Terminate;
FSendMsgThread := nil;
end;
end;
procedure TMainForm.ListViewReceiveLogDblClick(Sender: TObject);
var
s1, s2: string;
ListItem: TListItem;
begin
//双击回复短信
ListItem := ListViewReceiveLog.Selected;
if ListItem<>nil then
begin
s1 := ListItem.SubItems.Strings[2];
s2 := ListItem.SubItems.Strings[4];
with TSendSMSForm.Create(nil, s1, s2) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
end;
procedure TMainForm.ListViewSendLogDblClick(Sender: TObject);
var
s1, s2: string;
ListItem: TListItem;
begin
//双击重发短信
ListItem := ListViewSendLog.Selected;
if ListItem<>nil then
begin
s1 := ListItem.SubItems.Strings[2];
s2 := ListItem.SubItems.Strings[4];
with TSendSMSForm.Create(nil, s1, s2) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -