2016-01-13 105 views
1

我已成功編碼,一次向一個手機號碼發送短信,但我想將其作爲批量發送。如何使用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(); 
     } 
    } 
} 

回答

0

嗯,你是從文本框分割你的字符串,但你從來沒有使用它。我已經擴展你的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

相關問題