windows mobile 短信群发软件
2011-02-25 20:16 pxeric 阅读(595) 评论(2) 收藏 举报又是一个因为自己懒而开发的小软件,虽说手机上有群发的功能,但并不是很强大,我所想要的功能也没有。该软件所实现的功能主要有单号码发送、多号群发、分组发送、定时发送、短信模板。采用SQLite数据库存储定时发送的信息和短信的模板。
部份代码
View Code
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.WindowsMobile.PocketOutlook;
namespace Send
{
public partial class Form1 : NonFullscreenForm
{
private SizeF MyAutoScaleFactor;
private int second = 8;
private int MsgId;
private string _contact = string.Empty;
private string _content = string.Empty;
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
public Form1()
{
InitializeComponent();
MyAutoScaleFactor = new SizeF(this.AutoScaleDimensions.Width / 96F, this.AutoScaleDimensions.Height / 96F);
this.Height = (int)(MyAutoScaleFactor.Height * 100 - SystemInformation.MenuHeight);
AutoRun();
}
/// <summary>
/// 提前10秒自动运行任务并提示用户将发送短信,有10秒的等待时间
/// <remark>2011-02-25 9:59 By Eric </remark>
/// </summary>
public void AutoRun()
{
GetContact();
timer.Interval = 1000;
timer.Enabled = true;
timer.Tick += new EventHandler(timerWait_Tick);
}
/// <summary>
/// 获取联系人和短信内容
/// <remark>2011-02-25 10:07 By Eric </remark>
/// </summary>
public void GetContact()
{
DataSet ds = new SendMessage.Common().GetFirstData();
if (ds.Tables[0].Rows.Count > 0)
{
MsgId = Convert.ToInt32(ds.Tables[0].Rows[0]["Id"]);
_contact = ds.Tables[0].Rows[0]["Contact"].ToString();
_content = ds.Tables[0].Rows[0]["MsgContent"].ToString();
}
ds.Dispose();
}
/// <summary>
/// 发送短信
/// <remark>2011-02-24 20:30 By Eric </remark>
/// </summary>
public void SendMsg()
{
ShowSending();
if (string.IsNullOrEmpty(_contact) || string.IsNullOrEmpty(_content))
{
MessageBox.Show("收信人或短信内容不能为空!", "失败");
this.Close();
}
else
{
try
{
string invalid = string.Empty;
int count = 0;
foreach (string item in _contact.Split(';'))
{
string[] _temp = item.Split('-');
if (_temp.Length > 1)
{
_content = _content.Replace("[name]", _temp[1]);
}
if (!new SendMessage.Common().IsPhone(_temp[0]))
{
invalid += _temp[0] + ",";
continue;
}
else
{
SmsMessage message = new SmsMessage(_temp[0], _content);
message.RequestDeliveryReport = true;
message.Send();
count++;
}
}
if (count == 0)
{
MessageBox.Show(string.Format("发送失败,“{0}”不是有效的手机号", invalid.TrimEnd(',')), "失败");
this.Close();
}
else
{
ShowSended();
timer.Interval = 1000;
timer.Enabled = true;
timer.Tick += new EventHandler(timer_Tick);
}
}
catch (Exception ex)
{
MessageBox.Show("发送失败," + ex.Message, "失败");
this.Close();
}
}
}
/// <summary>
/// timer事件
/// <remark>2011/1/22 12:41 By Eric </remark>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
void timer_Tick(object sender, EventArgs e)
{
if (second > 0)
{
second--;
lblSecond.Text = second.ToString();
}
else
{
timer.Enabled = false;
this.Close();
}
}
/// <summary>
/// timerWait事件
/// <remark>2011/1/22 12:41 By Eric </remark>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
void timerWait_Tick(object sender, EventArgs e)
{
if (second > 0)
{
second--;
lblBeginSecond.Text = second.ToString();
}
else
{
timer.Enabled = false;
second = 5;
SendMsg();
}
}
/// <summary>
/// 窗体关闭时设置下一次的任务
/// <remark>2011-02-25 9:51 By Eric </remark>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param>
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
SetNextAndExit();
}
/// <summary>
/// 删除已执行的任务以及设置下一次任务并退出系统
/// <remark>2011-02-24 20:21 By Eric </remark>
/// </summary>
public void SetNextAndExit()
{
new SendMessage.Common().DeleteSended(MsgId);
}
/// <summary>
/// 取消当前发送
/// <remark>2011-02-25 9:58 By Eric </remark>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// 立即发送
/// <remark>2011-02-25 9:58 By Eric </remark>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void btnSend_Click(object sender, EventArgs e)
{
timer.Enabled = false;
SendMsg();
}
/// <summary>
/// 显示正在发送中的状态
/// <remark>2011-02-25 10:21 By Eric </remark>
/// </summary>
public void ShowSending()
{
lblSending.Visible = lblWait.Visible = true;
lblBeginSendMsg.Visible = lblBeginSend.Visible = lblBeginSecond.Visible = btnCancel.Visible = btnSend.Visible = false;
}
/// <summary>
/// 显示发送完后的状态
/// <remark>2011-02-25 10:22 By Eric </remark>
/// </summary>
private void ShowSended()
{
lblSended.Visible = lblExit.Visible = lblSecond.Visible = true;
lblSending.Visible = lblWait.Visible = lblBeginSendMsg.Visible = lblBeginSend.Visible = lblBeginSecond.Visible = false;
}
}
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.WindowsMobile.PocketOutlook;
namespace Send
{
public partial class Form1 : NonFullscreenForm
{
private SizeF MyAutoScaleFactor;
private int second = 8;
private int MsgId;
private string _contact = string.Empty;
private string _content = string.Empty;
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
public Form1()
{
InitializeComponent();
MyAutoScaleFactor = new SizeF(this.AutoScaleDimensions.Width / 96F, this.AutoScaleDimensions.Height / 96F);
this.Height = (int)(MyAutoScaleFactor.Height * 100 - SystemInformation.MenuHeight);
AutoRun();
}
/// <summary>
/// 提前10秒自动运行任务并提示用户将发送短信,有10秒的等待时间
/// <remark>2011-02-25 9:59 By Eric </remark>
/// </summary>
public void AutoRun()
{
GetContact();
timer.Interval = 1000;
timer.Enabled = true;
timer.Tick += new EventHandler(timerWait_Tick);
}
/// <summary>
/// 获取联系人和短信内容
/// <remark>2011-02-25 10:07 By Eric </remark>
/// </summary>
public void GetContact()
{
DataSet ds = new SendMessage.Common().GetFirstData();
if (ds.Tables[0].Rows.Count > 0)
{
MsgId = Convert.ToInt32(ds.Tables[0].Rows[0]["Id"]);
_contact = ds.Tables[0].Rows[0]["Contact"].ToString();
_content = ds.Tables[0].Rows[0]["MsgContent"].ToString();
}
ds.Dispose();
}
/// <summary>
/// 发送短信
/// <remark>2011-02-24 20:30 By Eric </remark>
/// </summary>
public void SendMsg()
{
ShowSending();
if (string.IsNullOrEmpty(_contact) || string.IsNullOrEmpty(_content))
{
MessageBox.Show("收信人或短信内容不能为空!", "失败");
this.Close();
}
else
{
try
{
string invalid = string.Empty;
int count = 0;
foreach (string item in _contact.Split(';'))
{
string[] _temp = item.Split('-');
if (_temp.Length > 1)
{
_content = _content.Replace("[name]", _temp[1]);
}
if (!new SendMessage.Common().IsPhone(_temp[0]))
{
invalid += _temp[0] + ",";
continue;
}
else
{
SmsMessage message = new SmsMessage(_temp[0], _content);
message.RequestDeliveryReport = true;
message.Send();
count++;
}
}
if (count == 0)
{
MessageBox.Show(string.Format("发送失败,“{0}”不是有效的手机号", invalid.TrimEnd(',')), "失败");
this.Close();
}
else
{
ShowSended();
timer.Interval = 1000;
timer.Enabled = true;
timer.Tick += new EventHandler(timer_Tick);
}
}
catch (Exception ex)
{
MessageBox.Show("发送失败," + ex.Message, "失败");
this.Close();
}
}
}
/// <summary>
/// timer事件
/// <remark>2011/1/22 12:41 By Eric </remark>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
void timer_Tick(object sender, EventArgs e)
{
if (second > 0)
{
second--;
lblSecond.Text = second.ToString();
}
else
{
timer.Enabled = false;
this.Close();
}
}
/// <summary>
/// timerWait事件
/// <remark>2011/1/22 12:41 By Eric </remark>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
void timerWait_Tick(object sender, EventArgs e)
{
if (second > 0)
{
second--;
lblBeginSecond.Text = second.ToString();
}
else
{
timer.Enabled = false;
second = 5;
SendMsg();
}
}
/// <summary>
/// 窗体关闭时设置下一次的任务
/// <remark>2011-02-25 9:51 By Eric </remark>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param>
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
SetNextAndExit();
}
/// <summary>
/// 删除已执行的任务以及设置下一次任务并退出系统
/// <remark>2011-02-24 20:21 By Eric </remark>
/// </summary>
public void SetNextAndExit()
{
new SendMessage.Common().DeleteSended(MsgId);
}
/// <summary>
/// 取消当前发送
/// <remark>2011-02-25 9:58 By Eric </remark>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// 立即发送
/// <remark>2011-02-25 9:58 By Eric </remark>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void btnSend_Click(object sender, EventArgs e)
{
timer.Enabled = false;
SendMsg();
}
/// <summary>
/// 显示正在发送中的状态
/// <remark>2011-02-25 10:21 By Eric </remark>
/// </summary>
public void ShowSending()
{
lblSending.Visible = lblWait.Visible = true;
lblBeginSendMsg.Visible = lblBeginSend.Visible = lblBeginSecond.Visible = btnCancel.Visible = btnSend.Visible = false;
}
/// <summary>
/// 显示发送完后的状态
/// <remark>2011-02-25 10:22 By Eric </remark>
/// </summary>
private void ShowSended()
{
lblSended.Visible = lblExit.Visible = lblSecond.Visible = true;
lblSending.Visible = lblWait.Visible = lblBeginSendMsg.Visible = lblBeginSend.Visible = lblBeginSecond.Visible = false;
}
}
软件运行的截图:





测试机型:多普达S910W
软件下载:/Files/pxeric/SendMsg.rar

浙公网安备 33010602011771号