📄 default.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//机器号码
this.txtJQHM.Text =Center.GMS.GSMModemGetSnInfoNew(txtCOM.Text, txtBTL.Text);
this.txtCOM.Text = Center.GMS.GSMModemGetDevice(); //COM1
this.txtBTL.Text = Center.GMS.GSMModemGetBaudrate(); //波特率
}
protected void Button1_Click(object sender, EventArgs e)
{
//连接设备
if (Center.GMS.GSMModemInitNew(txtCOM.Text, txtBTL.Text, null, null, false, txtPower.Text) == false)
{
this.Page.RegisterStartupScript("","<script>alert('连接失败!" + Center.GMS.GSMModemGetErrorMsg()+"')</script>");
return;
}
//接收短信
string content = Center.GMS.GSMModemSMSReadAll(0);
if (content == null)
{
this.getMessage();
return;
}
content = content.Replace("||", "|"); // 替换||为|
string[] str_sp = content.Split('|');// 进行分离
int k = 0;
string[,] str_Sp = new string[2, str_sp.Length / 2];
for (int i = 0; i < str_sp.Length / 2; i++)
{
for (int j = 0; j < 2; j++)
{
str_Sp[j, i] = str_sp[k];
if (k % 2 != 0)
this.InsertMessage("insert into RecivedBox (Mobile,Content)values('" + Convert.ToString(str_Sp[0, i]) + "','" + Convert.ToString(str_Sp[1, i]) + "') ");
k++;
}
}
this.getMessage();
}
private void getMessage()
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("message.mdb")+ ";Persist Security Info=False");
OleDbDataAdapter dap = new OleDbDataAdapter("select mobile as 手机号码,content as 短信息,SendTime as 日期 from SendedBox", con);
DataSet ds = new DataSet();
dap.Fill(ds,"cj");
this.GridView1.DataSource = ds.Tables["cj"].DefaultView;
GridView1.DataBind();
}
private void InsertMessage(string strSql)
{
//将短信息内容添加到数据库中
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("message.mdb") + ";Persist Security Info=False");
con.Open();
OleDbCommand cmd = new OleDbCommand(strSql, con);
cmd.ExecuteNonQuery();
con.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -