TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ahmet Taha
NA
381
20.3k
sending sms to many numbers using gsm modem in c#
Jun 5 2021 1:13 AM
Hello Guyz, i would like to ask how can i send sms to all number attached here is my source code i can only sent a sms to one phone number but i want to send it to many phone number. thanks
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.Data.SqlClient;
//============
using
System.IO.Ports;
using
System.Threading;
namespace
StudentInformationSystem
{
public
partial
class
frmsendingsms : Form
{
SqlCommand cmd;
SqlConnection cn;
SqlDataAdapter da;
SqlDataReader dr;
string
_title =
"STUDENT INFORMATION SYSTEM"
;
public
frmsendingsms()
{
InitializeComponent();
academicyear();
}
public
void
academicyear()
{
cn = ClassDB.ConnectDB();
//cn.Open();
cmd =
new
SqlCommand(
"select academicyear from tblAY where status like 'OPEN'"
, cn);
cmd.Parameters.AddWithValue(
"@academicyear"
, txtacademicyear.Text);
dr = cmd.ExecuteReader();
dr.Read();
if
(dr.HasRows)
{
txtacademicyear.Text = dr[
"academicyear"
].ToString();
// txtacademicterm.Text = dr["term"].ToString();
//cbacademicterm.Text = dr["term"].ToString();
}
else
{
}
dr.Close();
cn.Close();
}
private
void
btnSend_Click(
object
sender, EventArgs e)
{
try
{
SerialPort sp =
new
SerialPort();
sp.PortName = cbportnumber.Text;
sp.Open();
sp.WriteLine(
"AT"
+ Environment.NewLine);
Thread.Sleep(100);
sp.WriteLine(
"AT+CMGF=1"
+ Environment.NewLine);
Thread.Sleep(100);
sp.WriteLine(
"AT+CMGS=\""
+ txtPhoneNumber.Text +
"\""
+ Environment.NewLine);
Thread.Sleep(100);
sp.WriteLine(txtMessage.Text + Environment.NewLine);
Thread.Sleep(100);
sp.Write(
new
byte
[] { 26 }, 0, 1);
Thread.Sleep(100);
var response = sp.ReadExisting();
if
(response.Contains(
"ERROR"
))
MessageBox.Show(
"Send failed!"
,
"Message"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show(
"Message has been sent"
,
"Message"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
sp.Close();
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message,
"Message"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private
void
txtyear1_TextChanged(
object
sender, EventArgs e)
{
try
{
txtyear2.Text = (
long
.Parse(txtyear1.Text) + 1).ToString();
}
catch
{
txtyear2.Clear();
}
txtacademicyear.Text = txtyear1.Text +
"-"
+ txtyear2.Text;
}
private
void
txtsearch_KeyUp(
object
sender, KeyEventArgs e)
{
cn = ClassDB.ConnectDB();
listBox1.Visible =
true
;
listBox1.Items.Clear();
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd =
new
SqlCommand(
"Select* from tblstudentregistration where lrn like'"
+ txtsearch.Text +
"%' or fullname Like '"
+ txtsearch.Text +
"%'"
, cn);
cmd.ExecuteNonQuery();
DataTable dt =
new
DataTable();
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
da.Fill(dt);
foreach
(DataRow dr
in
dt.Rows)
{
listBox1.Items.Clear();
listBox1.Items.Add(dr[
"lrn"
]).ToString();
// listBox1.Items.Clear();
listBox1.Items.Add(dr[
"fullname"
]).ToString();
}
}
private
void
txtsearch_KeyDown(
object
sender, KeyEventArgs e)
{
try
{
cn = ClassDB.ConnectDB();
if
(e.KeyCode == Keys.Down)
{
listBox1.Focus();
listBox1.SelectedIndex = 0;
}
}
catch
(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private
void
listBox1_KeyDown(
object
sender, KeyEventArgs e)
{
cn = ClassDB.ConnectDB();
if
(e.KeyCode == Keys.Down)
{
this
.listBox1.SelectedIndex =
this
.listBox1.SelectedIndex;
}
if
(e.KeyCode == Keys.Up)
{
this
.listBox1.SelectedIndex =
this
.listBox1.SelectedIndex;
}
if
(e.KeyCode == Keys.Enter)
{
//search();
txtsearch.Text = listBox1.SelectedItem.ToString();
displayresulttextboxs();
// displayresultontxtboxes();
listBox1.Visible =
false
;
}
}
private
void
displayresulttextboxs()
{
cn = ClassDB.ConnectDB();
// cmd = new SqlCommand("Select * from tblstudentregistration where lrn='" + txtsearchstudentlrn0rFullname.Text + "' and academicyear='" + txtacademicyear.Text + "' and academicterm='" + txtacademicterm.Text + "'", cn);
cmd =
new
SqlCommand(
"Select * from tblstudentregistration where lrn='"
+ txtsearch.Text +
"' and academicyear='"
+txtacademicyear.Text+
"' and academicterm ='"
+cbacademicterm.Text+
"'"
, cn);
dr = cmd.ExecuteReader();
if
(dr.Read())
{
txtsearch.Text = dr[1].ToString();
txtPhoneNumber.Text= dr[9].ToString();
}
else
{
cn = ClassDB.ConnectDB();
// cmd = new SqlCommand("Select * from tblstudentregistration where fullname='" + txtsearchstudentlrn0rFullname.Text + "' and academicyear='" + txtacademicyear.Text + "' and academicterm='" + txtacademicterm.Text + "'", cn);
cmd =
new
SqlCommand(
"Select * from tblstudentregistration where fullname='"
+ txtsearch.Text +
"' and academicyear='"
+ txtacademicyear.Text +
"' and academicterm ='"
+ cbacademicterm.Text +
"'"
, cn);
dr = cmd.ExecuteReader();
if
(dr.Read())
{
txtsearch.Text = dr[1].ToString();
txtPhoneNumber.Text = dr[9].ToString();
}
else
{
MessageBox.Show(
"There's no Record has been found"
, _title, MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
}
private
void
btnsearch_Click(
object
sender, EventArgs e)
{
}
}
}
Reply
Answers (
2
)
Email Address Validation @ is not working cshtml
how to change the css for Upload Control in asp.net?