如何使用C调用USB调制解调器发送批量短信#

问题描述:

我已成功编码,一次向一个手机号码发送短信,但我想将其作为批量发送。如何使用C调用USB调制解调器发送批量短信#

我正在使用一个文本框来提供数字我想输入几个数字到文本框并发送到该文本框中的所有数字。

这里是表单代码:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.Runtime.Remoting.Channels; 
using System.Runtime.Remoting.Channels.Tcp; 
using GsmComm.PduConverter; 
using GsmComm.PduConverter.SmartMessaging; 
using GsmComm.GsmCommunication; 
using GsmComm.Interfaces; 
using GsmComm.Server; 
using System.Globalization; 
using System.Text.RegularExpressions; 
using MySql.Data.MySqlClient; 

namespace yahapalana_DB 
{ 
    public partial class sms : Form 
    { 
     public sms() 
     { 
      InitializeComponent(); 
     } 

     private GsmCommMain comm; 
     private delegate void SetTextCallback(string text); 
     private SmsServer smsServer; 

     TextBox txtmsg = new TextBox(); 
     TextBox txtno = new TextBox(); 


     private void button3_Click(object sender, EventArgs e) 
     { 
      if (comboBox1.Text == "") 
      { 
       MessageBox.Show("Invalied Port Name"); 
       return; 
      } 
      comm = new GsmCommMain(comboBox1.Text, 9600, 150); 
      Cursor.Current = Cursors.Default; 
      bool retry; 
      do 
      { 
       retry = false; 
       try 
       { 
        Cursor.Current = Cursors.WaitCursor; 
        comm.Open(); 
        Cursor.Current = Cursors.Default; 
        MessageBox.Show("Connect Successfully"); 
       } 
       catch (Exception) 
       { 
        Cursor.Current = Cursors.Default; 
        if (MessageBox.Show(this, "Modem not available", "Check", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) retry = true; 
        { return; } 
       } 
      } while (retry); 
     } 

     private void sms_Load(object sender, EventArgs e) 
     { 
      comboBox1.Items.Add("Com1"); 
      comboBox1.Items.Add("Com2"); 
      comboBox1.Items.Add("Com3"); 
      comboBox1.Items.Add("Com4"); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      try { 

       string[] slist = text.Split(':'); 
       SmsSubmitPdu pdu; 
       byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault; 
       pdu = new SmsSubmitPdu(textmsg.Text,mobno.Text,dcs); 
       int times = 1; 
       for (int i=0;i<times;i++) { 
        comm.SendMessage(pdu); 
       } 
       MessageBox.Show("Message sent sucessfully"); 
      } catch (Exception ex) { 
       MessageBox.Show("Modem not avaliable"); 
      } 
     } 

     private void button2_Click(object sender, EventArgs e) 
     { 

      add_number au = new add_number(); 
      au.ShowDialog(); 
     } 
    } 
} 

嗯,你是从文本框分割你的字符串,但你从来没有使用它。我已经扩展你的foreach,并用数字项目中的项目代替mobno.Text。

private void button1_Click(object sender, EventArgs e) 
    { 
     try { 

      string[] slist = text.Split(':'); 

      foreach (string mobno in slist) { 
       SmsSubmitPdu pdu; 
       byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault; 
       pdu = new SmsSubmitPdu(textmsg.Text,mobno,dcs); 
       int times = 1; 

       comm.SendMessage(pdu); 
      } 

      MessageBox.Show("Message sent sucessfully"); 
     } catch (Exception ex) { 
      MessageBox.Show("Modem not avaliable"); 
     } 
    } 
+0

此密码不起作用 – Tharu1515

+0

好的。你试过了什么?什么是错误信息?你是否试图调试,如果在任何地方的预期价值等? – STORM

+0

我有一个这样的概念:我会从MySQL数据库中加载数字,并从中选择数字,并将数字加载到mobno文本框中,并使用数组中的数组格式数字和数组中的数字并使用发送按钮将其发送到所有数组上的数字。我想知道如何做到这一点!感谢帮助appriciate它交配! – Tharu1515