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

📄 main.~pas

📁 用delphi开发的短信息预警系统
💻 ~PAS
📖 第 1 页 / 共 3 页
字号:
     end;
 -11:begin
       StatusBar1.Panels[0].Text := '保存模块参数失败';
       ModuleStatus[ComboBox1.ItemIndex]:=false;
     end;
  end;
end;

//=====关闭串口==========================
procedure TForm1.Off_BtonClick(Sender: TObject);
begin
  if not ModuleStatus[ComboBox1.ItemIndex] then
  begin
    StatusBar1.Panels[0].Text:='模块未打开';
    Exit;
  end;
  case CloseComm(ComboBox1.ItemIndex+1) of
   0:begin
       StatusBar1.Panels[0].Text := '关闭模块成功';
       StatusBar1.Panels[1].Text := '';
       ModuleStatus[ComboBox1.ItemIndex]:=False;
     end;
  -1:begin
       StatusBar1.Panels[0].Text := '还有未发消息待发';
       if Application.MessageBox('关闭失败,还有未处理短信,是否强制关闭?','提示',MB_OKCANCEL)=ID_OK then
       begin
         case ForceCloseComm(ComboBox1.ItemIndex+1) of
          0:begin
              StatusBar1.Panels[0].Text:='模块已强制关闭';
              ModuleStatus[ComboBox1.ItemIndex]:=False;
            end;
         -7:  StatusBar1.Panels[0].Text:='强制关闭模块失败';
         -8:  StatusBar1.Panels[0].Text := '模块未打开';
         end;
       end;
     end;
  -7:begin
       StatusBar1.Panels[0].Text := '关闭COM口失败';
     end;
  -8:begin
       StatusBar1.Panels[0].Text := '模块未打开';
     end;
  end;
end;

//=====退出系统==========================
procedure TForm1.CloseBtonClick(Sender: TObject);
begin
if Application.MessageBox('可能还有未处理的短信,退出程序将丢失部分信息,您真的决定退出程序?','提示',MB_OKCANCEL)=ID_OK then
Application.Terminate;
end;

//=====号码簿显示&消隐==========================
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if checkbox1.Checked then
  begin
  groupbox1.Visible:=true;
  treeview1.FullExpand;
  end else
  begin
  groupbox1.Visible:=false;
  end;
end;

//=======打开群发设置对话框=======================
procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.showmodal;
end;

//=======打开群发设置对话框=======================
procedure TForm1.Q1Click(Sender: TObject);
begin
form2.showmodal;
end;

//=======打开串口=======================
procedure TForm1.O2Click(Sender: TObject);
begin
On_BtonClick(Sender);
end;

//=======关闭串口=======================
procedure TForm1.D1Click(Sender: TObject);
begin
Off_BtonClick(Sender);
end;

//=======添加号码=======================
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  Form3.AddBBtn.Visible:=true;
  Form3.ChangeBBtn.Visible:=false;
  Form3.Caption:='添加联系人';
  form3.ShowModal;
end;

function StrToID(str:string):string;
var
number:string;
begin
  number:=StrToNumber(str);
  Form1.bookquery.SQL.Clear;
  Form1.bookquery.SQL.Add('select * from yujing where Mphone = '+number);
  Form1.bookquery.Open;
  result:=Form1.bookquery.Fieldbyname('id').Value;
  Form1.bookquery.Close;
end;

//=======删除号码=======================
procedure TForm1.BitBtn2Click(Sender: TObject);
var
number:string;
begin
  if treeview1.Selected.Level<>1 then exit;
  if MessageBox(handle,'您确定要删除此联系人吗?',
                '是否删除?',MB_YESNO+MB_ICONQUESTION)=IDYES then
  begin
    number:=StrToNumber(treeview1.Selected.Text); 
    bookquery.SQL.Clear;
    bookquery.SQL.Add('select * from yujing where  Mphone = '+number);
    bookquery.Open;
    bookquery.Edit;
    bookquery.Delete;
    bookquery.Close;
    ListCreate();
  end;
end;

//=======修改号码=======================
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
  if treeview1.Selected.Level<>1 then exit;
  Form3.AddBBtn.Visible:=false;
  Form3.ChangeBBtn.Visible:=true;
  Form3.Caption:='修改联系人';
  Form3.ShowModal;
end;

function StrToName(str:string):string;
begin
  if pos('\',str)=0 then
  result:=''
  else
  result:=copy(str,1,pos('\',str)-1);
end;

function StrToNumber(str:string):string;
begin
  if pos('\',str)=0 then
  result:=''
  else
  result:=copy(str,pos('\',str)+1,length(str)-1);
end;

function NumberToName(num:string):string;
begin
  if trim(num)='' then result:=''
  else
  begin
  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

⌨️ 快捷键说明

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