日期:2014-05-17 浏览次数:20618 次
#region 接收函数
/// <summary>
/// 接收信息
/// </summary>
/// <param name="_clear">是否清除sim卡中的信息, 是=true(推荐) 否=false</param>
/// <returns>是否接收成功 是=true 否=false</returns>
public bool ReceiveMsgToDataBase(bool _clear)
{
string _returnMsg = "";//程序运行信息
try
{
CommonClass cmu = new CommonClass();
string SMS_String = "";//短信接收所有的字符串
//连接设备
try
{
cmu.InitDevice(out _returnMsg);
}
catch
{}
if (cmu.DeviceIsConn(out _returnMsg) == true)
{//如果设备连接成功
SMS_String = cmu.Read(_clear, out _returnMsg);
if (SMS_String != null && SMS_String != "")
{//如果有信息
SMS_String = SMS_String.Replace("||","■");
//替换非法字符
SMS_String.Replace("'","''");
//删掉最后一个■
SMS_String = SMS_String.Remove(SMS_String.Length -1,1);
//将所有的字符串按照信息,一条一条的拆分成字符串数组
string[] SMS_OneString = SMS_String.Split('■');
WriteLog("↓--------------------------------");
//循环信息字符串数组,再一点一点的拆分内部的具体信息
for (int i = 0 ; i <= SMS_OneString.Length - 1 ; i++)
{
try
{
string _temp = SMS_OneString[i].ToString();
string[] _tempDetail = _temp.Split('|');
string _SMS_TypeCode = _tempDetail[0].ToString();//短信编码
string _SMS_Storage = _tempDetail[1].ToString();//短信存储位置
string _SendTime = _tempDetail[2].ToString();//短信发送时间
string _Sender = _tempDetail[3].ToString();//短信发送人的号码
string _SMS_Code = _tempDetail[4].ToString();//短信编码
string _SMS_Len = _tempDetail[5].ToString();//短信长度
string _Content = _tempDetail[6].ToString();//短信内容
//需要对发送日期进行处理,因为短信的发送日期为 07/24/07 10:00:51 (+0800) 的形式
string _tempTime = _SendTime.Substring(0,17);
DateTime dt = new DateTime();
CultureInfo culture = new CultureInfo( "en-US" );
try
{
dt = Convert.ToDateTime( _tempTime, culture );
dt = Convert.ToDateTime(dt.ToString("{yyyy-MM-dd HH:mm:ss}"));
}
catch
{
WriteLog("写入数据:" + "\t" + " {