⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx.cs

📁 这是asp.net^和Visual C++Sharp编写的串并口通讯的书籍 源代码
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Text;
using System.Data.OleDb;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //机器号码
        
        this.txtJQHM.Text =smoking.GMS.GSMModemGetSnInfoNew(txtCOM.Text, txtBTL.Text);
        this.txtCOM.Text =smoking.GMS.GSMModemGetDevice();  //COM1
        this.txtBTL.Text =smoking.GMS.GSMModemGetBaudrate();  //波特率
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        if (txtSJHM.Text == "")
        {
            Page.RegisterStartupScript("", "<script>alert('手机号码不能为空!')</script>");
            txtSJHM.Focus();
            return;
        }
        if (txtContent.Text == "")
        {
            Page.RegisterStartupScript("", "<script>alert('短信内容不能为空!')</script>");
            txtContent.Focus();
            return;
        }
        //连接设备
        if (smoking.GMS.GSMModemInitNew(txtCOM.Text, txtBTL.Text, null, null, false, txtPower.Text) == false)
        {
            Page.RegisterStartupScript("", "<script>alert('设备连接失败!'" +smoking.GMS.GSMModemGetErrorMsg() + "')</script>");
            return;
        }
        // 发送短信
        if (smoking.GMS.GSMModemSMSsend(null, 8, txtContent.Text, Encoding.Default.GetByteCount(txtContent.Text), txtSJHM.Text, false) == true)
            Page.RegisterStartupScript("", "<script>alert('短信发送成功!')</script>");
        else
            Page.RegisterStartupScript("", "<script>alert('短信发送失败!'" +smoking.GMS.GSMModemGetErrorMsg() + "')</script>");
    }

    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();
    }
    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 短信息,reciveTime as 日期 from RecivedBox", con);
        DataSet ds = new DataSet();
        dap.Fill(ds,"note");
        this.GridView1.DataSource = ds.Tables["note"].DefaultView;
        GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //连接设备
        if (smoking.GMS.GSMModemInitNew(txtCOM.Text, txtBTL.Text, null, null, false, txtPower.Text) == false)
        {
            Page.RegisterStartupScript("", "<script>alert('连接失败!" +smoking.GMS.GSMModemGetErrorMsg() + "')</script>");
            return;
        }
        //接收短信
        string content =smoking.GMS.GSMModemSMSReadAll(0);
        if (content == null)
        {
            this.getMessage();
            return;
        }
        content = content.Replace("||", "|"); // 替换||为|
        string[] str_sp = content.Split('|');// 进行分离
        int k = 0;
        GridView1.Columns[0].HeaderText = "手机号码";
        GridView1.Columns[1].HeaderText = "短信息";
        for (int i = 0; i < str_sp.Length / 2; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                GridView1.Rows[i].Cells[j].Text = str_sp[k];
                if (k % 2 != 0)
                    this.InsertMessage("insert into RecivedBox (Mobile,Content,reciveTime)values('" + Convert.ToString(GridView1.Rows[i].Cells[0].Text) + "','" + Convert.ToString(GridView1.Rows[i].Cells[1].Text) + "','" + DateTime.Now.ToString() + "') ");
                k++;
            }
        }
        this.getMessage();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -