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

📄 main.~pas

📁 通过串口发送多条短信的群发软件
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
  except
    logForm.logMemo.Lines.Add('销毁端口对象出错!');
  end;

  try
    //销毁超时计数器对象
    timeoutTimer.Free;
  except
    logForm.logMemo.Lines.Add('销毁超时计数器出错!');
  end;

end;

procedure TmainForm.rwglSpeedButtonClick(Sender: TObject);
begin
  dataForm.Caption:='日常用语';
  dataForm.ReadyforShow;
  dataForm.ShowModal;
end;

procedure TmainForm.jhrwSpeedButtonClick(Sender: TObject);
begin
  taskForm.ReadyforShow;
  taskForm.ShowUnselectedusers('','','','','','');//显示未选客户
  taskForm.ShowModal;
end;

procedure TmainForm.fsdzSpeedButtonClick(Sender: TObject);
var
  TreeNode:TTreeNode;
begin
  //取得当前选中的节点
  TreeNode:=groupTreeView.Selected;
  if (TreeNode<>nil) and (TreeNode.Parent=nil) then
  begin
    taskForm.ReadyforShow;
    taskForm.groupname:=TreeNode.Text;//记录当前编辑的联系组名
    taskForm.ShowSelectedusers;//显示已选客户
    taskForm.ShowUnselectedusers('','','','','','');//显示未选客户
    taskForm.ShowModal;
  end;
end;

procedure TmainForm.deleteSpeedButtonClick(Sender: TObject);
begin
  // 有任务信息被选中且该任务不在运行状态
  if (tasklistview.SelCount=1) and (tasklistview.Selected.ImageIndex<>3) then
  begin
    //询问是否删除该任务
    if application.MessageBox('你确定要删除这个任务吗?','提示',MB_YESNO)=ID_NO then
      exit;

    try
      taskadoquery.RecNo:=tasklistview.Selected.Index+1;
      taskadoquery.Delete;
    except
      application.MessageBox('发生错误!','提示',MB_OK);
    end;
      
    // 删除列表中选中数据
    taskListView.DeleteSelected;
  end;
end;

procedure TmainForm.change_timeSpeedButtonClick(Sender: TObject);
begin
  // 有客户信息被选中
  if (tasklistview.SelCount=1) and (tasklistview.Selected.ImageIndex=2) then
  begin
    //取得选中任务的发送时间
    changetimeForm.DateTimePicker1.Date:=strtodatetime(tasklistview.Selected.SubItems.Strings[1]);
    changetimeForm.DateTimePicker2.time:=strtodatetime(tasklistview.Selected.SubItems.Strings[1]);
    changetimeForm.ShowModal;
  end;
end;

procedure TmainForm.jlljSpeedButtonClick(Sender: TObject);
var
  i:Integer;
begin
  //连接手机
  if jlljSpeedButton.Caption='建立连接' then
  begin
    if not smsApdComPort.Open then
      smsApdComPort.Open:=True;
    if smsApdComPort.Open then
    begin
      logForm.logMemo.Lines.Add('打开通讯端口COM'+
      IntToStr(smsApdComPort.ComNumber));

      jlljSpeedButton.Enabled:=False;
      ljszSpeedButton.Enabled:=False;

      //启动线程
      if sm_sending_receiving.Suspended then
        sm_sending_receiving.Resume;
    end
  end
  //中断连接手机
  else
  begin
    if smsApdComPort.Open then
    begin
      ljszSpeedButton.Enabled:=False;
      mainForm.jlljSpeedButton.Enabled:=False;

      //隐藏相关按钮
      if tasklistview.ItemIndex>=0 then
      begin
        i:=tasklistview.ItemIndex;
        tasklistview.ItemIndex:=-1;
        tasklistview.ItemIndex:=i;
      end;

      smsApdComPort.Open:=False;

      logForm.logMemo.Lines.Add('关闭通讯端口COM'+
      IntToStr(smsApdComPort.ComNumber));
    end;
  end;
end;

procedure TmainForm.ljszSpeedButtonClick(Sender: TObject);
begin
  if comport='COM1' then
    connectForm.comportComboBox.ItemIndex:=0
  else if comport='COM2' then
    connectForm.comportComboBox.ItemIndex:=1
  else if comport='COM3' then
    connectForm.comportComboBox.ItemIndex:=2
  else if comport='COM4' then
    connectForm.comportComboBox.ItemIndex:=3
  else if comport='COM5' then
    connectForm.comportComboBox.ItemIndex:=4
  else if comport='COM6' then
    connectForm.comportComboBox.ItemIndex:=5
  else if comport='COM7' then
    connectForm.comportComboBox.ItemIndex:=6
  else if comport='COM8' then
    connectForm.comportComboBox.ItemIndex:=7;

  if baud_speed='9600' then
    connectForm.baud_speedComboBox.ItemIndex:=0
  else if baud_speed='19200' then
    connectForm.baud_speedComboBox.ItemIndex:=1
  else if baud_speed='38400' then
    connectForm.baud_speedComboBox.ItemIndex:=2
  else if baud_speed='57600' then
    connectForm.baud_speedComboBox.ItemIndex:=3
  else if baud_speed='115200' then
    connectForm.baud_speedComboBox.ItemIndex:=4;

  connectForm.ShowModal;
end;

procedure TmainForm.runSpeedButtonClick(Sender: TObject);
var
  i:Integer;
begin
  // 有客户信息被选中
  if (serivce_tel<>'') and (tasklistview.SelCount=1) and
  (tasklistview.Selected.SubItems.Strings[0]='等待') then
  begin
    //设置发送图标
    tasklistview.Selected.ImageIndex:=3;
    //改变状态
    tasklistview.Selected.SubItems.Strings[0]:='发送';

    //显示和隐藏相关按钮
    if tasklistview.ItemIndex>=0 then
    begin
      i:=tasklistview.ItemIndex;
      tasklistview.ItemIndex:=-1;
      tasklistview.ItemIndex:=i;
    end;
  end;
end;

procedure TmainForm.stopSpeedButtonClick(Sender: TObject);
var
  i:Integer;
begin
  // 有客户信息被选中
  if (serivce_tel<>'') and (tasklistview.SelCount=1) and
  (tasklistview.Selected.SubItems.Strings[0]='发送') then
  begin
    //设置等待图标
    tasklistview.Selected.ImageIndex:=2;
    //改变状态
    tasklistview.Selected.SubItems.Strings[0]:='等待';

    //显示和隐藏相关按钮
    if tasklistview.ItemIndex>=0 then
    begin
      i:=tasklistview.ItemIndex;
      tasklistview.ItemIndex:=-1;
      tasklistview.ItemIndex:=i;
    end;
  end;
end;

procedure TmainForm.task_infoSpeedButtonClick(Sender: TObject);
var
    send_tel:string;//已发送的手机号码
    error_send_tel:string;//发送错误的手机号码
    not_send_tel:string;//未发送的手机号码
    current_tel:string;//当前要处理的手机号
    current_user:string;//当前要处理的手机号对应的用户
    taskinfoadoquery:TADOQuery;
    i:integer;
    listitem:TListItem;
begin
  // 有任务信息被选中且该任务不在运行状态
  if tasklistview.SelCount=1 then
  begin
    task_infoForm.Panel2.Visible:=true;
    task_infoForm.Panel3.Visible:=false;

    task_infoForm.mobile_tel_accountLabel.Caption:='共有'+
    tasklistview.Selected.SubItems.Strings[2]+'条信息需要发送';

    task_infoForm.send_account_blLabel.Caption:=
    inttostr(strtoint(tasklistview.Selected.SubItems.Strings[3])*100 div strtoint(tasklistview.Selected.SubItems.Strings[2]))+'%';
    task_infoForm.error_send_account_blLabel.Caption:=
    inttostr(strtoint(tasklistview.Selected.SubItems.Strings[4])*100 div strtoint(tasklistview.Selected.SubItems.Strings[2]))+'%';
    task_infoForm.not_send_account_blLabel.Caption:=
    inttostr(strtoint(tasklistview.Selected.SubItems.Strings[5])*100 div strtoint(tasklistview.Selected.SubItems.Strings[2]))+'%';

    task_infoForm.send_accountLabel.Caption:=tasklistview.Selected.SubItems.Strings[3];
    task_infoForm.error_send_accountLabel.Caption:=tasklistview.Selected.SubItems.Strings[4];
    task_infoForm.not_send_accountLabel.Caption:=tasklistview.Selected.SubItems.Strings[5];

    task_infoForm.smMemo.Text:=tasklistview.Selected.SubItems.Strings[6];

    task_infoForm.send_userListView.Clear;

    taskinfoadoquery:=TADOQuery.Create(self);
    taskinfoadoquery.ConnectionString:=adodbconnectionstring;

    taskinfoadoquery.SQL.Text:='select * from task where id='''+
    tasklistview.Selected.Caption+'''';

    try
      taskinfoadoquery.Open;
    except
      application.MessageBox('发生错误!','提示',MB_OK);
      taskinfoadoquery.Free;
      exit;
    end;

    if taskinfoadoquery.RecordCount=1 then
    begin
      send_tel:=taskinfoadoquery.Fields.Fields[8].AsString;
      error_send_tel:=taskinfoadoquery.Fields.Fields[9].AsString;
      not_send_tel:=taskinfoadoquery.Fields.Fields[10].AsString;

      taskinfoadoquery.Close;
      taskinfoadoquery.Free;

      //显示发送成功的用户信息
      // 从号码集中取得一个新的号码
      while send_tel<>'' do
      begin
        current_tel:=copy(send_tel,1,pos(';',send_tel)-1);
        //取得该手机号对应的用户名
        current_user:='';
        i:=0;
        while (mainForm.userListView.Items.Item[i].SubItems.Strings[1]<>current_tel) and
        (i<mainForm.userListView.Items.Count-1) do
           i:=i+1;

        //找到用户信息
        if i<mainForm.userListView.Items.Count-1 then
          current_user:=mainForm.userListView.Items.Item[i].Caption
        //未找到用户信息
        else if i=mainForm.userListView.Items.Count-1 then
          current_user:=current_tel;

        listitem:=task_infoForm.send_userListView.Items.Add;
        listitem.Caption:=current_user;
        listitem.SubItems.Add(current_tel);
        listitem.SubItems.Add('发送成功');

        // 从号码集中删除该号码
        delete(send_tel,1,pos(';',send_tel));
      end;

      //显示发送出错的用户信息
      // 从号码集中取得一个新的号码
      while error_send_tel<>'' do
      begin
        current_tel:=copy(error_send_tel,1,pos(';',error_send_tel)-1);
        //取得该手机号对应的用户名
        current_user:='';
        i:=0;
        while (mainForm.userListView.Items.Item[i].SubItems.Strings[1]<>current_tel) and
        (i<mainForm.userListView.Items.Count-1) do
           i:=i+1;

        //找到用户信息
        if i<mainForm.userListView.Items.Count-1 then
          current_user:=mainForm.userListView.Items.Item[i].Caption
        //未找到用户信息
        else if i=mainForm.userListView.Items.Count-1 then
          current_user:=current_tel;
           
        listitem:=task_infoForm.send_userListView.Items.Add;
        listitem.Caption:=current_user;
        listitem.SubItems.Add(current_tel);
        listitem.SubItems.Add('发送失败');

        // 从号码集中删除该号码
        delete(error_send_tel,1,pos(';',error_send_tel));
      end;

      //显示还未发送的用户信息
      // 从号码集中取得一个新的号码
      while not_send_tel<>'' do
      begin
        current_tel:=copy(not_send_tel,1,pos(';',not_send_tel)-1);
        //取得该手机号对应的用户名
        current_user:='';
        i:=0;
        while (mainForm.userListView.Items.Item[i].SubItems.Strings[1]<>current_tel) and
        (i<mainForm.userListView.Items.Count-1) do
           i:=i+1;

        //找到用户信息
        if i<mainForm.userListView.Items.Count-1 then
          current_user:=mainForm.userListView.Items.Item[i].Caption
        //未找到用户信息
        else if i=mainForm.userListView.Items.Count-1 then
          current_user:=current_tel;
           
        listitem:=task_infoForm.send_userListView.Items.Add;
        listitem.Caption:=current_user;
        listitem.SubItems.Add(current_tel);
        listitem.SubItems.Add('未发送');

        // 从号码集中删除该号码
        delete(not_send_tel,1,pos(';',not_send_tel));
      end;

    end;

    task_infoForm.ShowModal;
  end;

end;

procedure TmainForm.N11Click(Sender: TObject);
begin
  logForm.Show;
end;

procedure TmainForm.taskListViewSelectItem(Sender: TObject;
  Item: TListItem; Selected: Boolean);
begin

  //选中一个任务
  if Selected then
  begin
    //显示"运行"按钮
    if (serivce_tel<>'') and (Item.SubItems.Strings[0]='等待') then
      runSpeedButton.Visible:=True;
    //显示"停止"按钮
    if (serivce_tel<>'') and (Item.SubItems.Strings[0]='发送') then
      stopSpeedButton.Visible:=True;
    //显示"删除"按钮
    if Item.SubItems.Strings[0]<>'发送' then
      deleteSpeedButton.Visible:=True;
    //显示"任务信息"按钮
    task_infoSpeedButton.Visible:=True;
  end
  else
  begin
    runSpeedButton.Visible:=False;
    stopSpeedButton.Visible:=False;
    deleteSpeedButton.Visible:=False;
    task_infoSpeedButton.Visible:=False;
    change_timeSpeedButton.Visible:=False;
  end;
end;

procedure TmainForm.AppException(Sender: TObject; E: Exception);//捕获异常
begin
  logForm.logMemo.Lines.Add(E.Message);
end;

procedure TmainForm.N13Click(Sender: TObject);
begin
  aboutForm.ShowModal;
end;

procedure TmainForm.hzglSpeedButtonClick(Sender: TObject);
var
  i:Integer;
begin
  //判断是否连接到手机
  if serivce_tel='' then
  begin
    application.MessageBox('未连接到手机,无法查看收件记录!','提示',MB_OK);
    exit;
  end;

  //判断当前是否有任务在运行
  for i:=0 to tasklistview.Items.Count-1 do
    if tasklistview.Items.Item[i].SubItems.Strings[0]='发送' then
    begin
      application.MessageBox('正在发送短信,无法查看收件记录!','提示',MB_OK);
      exit;
    end;

  //删除收件记录
//  inboxForm.inboxListView.Clear;

  //显示收件记录
  inboxForm.ShowModal;
end;

end.

⌨️ 快捷键说明

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