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

📄 main.cs

📁 windowsmobile 短信接收
💻 CS
字号:
using System;
using System.Windows.Forms;
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
using System.Data.SQLite;
using NotifyClient;
namespace sms
{
    public partial class main : Form
    {
        MessageInterceptor mi = new MessageInterceptor(InterceptionAction.NotifyAndDelete, true);
        private NotifyIcon ico = new NotifyIcon();
        string id;
        public static string tb;
                public main()
        {
            InitializeComponent();
            ico.Click += new EventHandler(notifyIcon_Click);
        }
        private void m_Received(object sender, MessageInterceptorEventArgs e)
        {
            SmsMessage rsms = e.Message as SmsMessage;
            proc.conn.Open();
            string mobile = rsms.From.Address;
            if (rsms.From.Address.IndexOf("+86") > 0)
            {
                mobile = rsms.From.Address.Substring(rsms.From.Address.IndexOf("+86") + 3, 11);
            }
            int radd = Convert.ToInt32(new SQLiteCommand("SELECT COUNT(*) FROM tel WHERE mobile = '" + mobile + "'", proc.conn).ExecuteScalar());
            if (radd > 0)
            {
                proc.SetLedStatus(0, 1);
                id = "2";
            }
            else
            {
                int count = Convert.ToInt32(new SQLiteCommand("SELECT COUNT(*) FROM Filter", proc.conn).ExecuteScalar());
                if (count > 0)
                {
                    SQLiteDataReader mr = new SQLiteCommand("SELECT * FROM Filter", proc.conn).ExecuteReader();
                    while (mr.Read())
                    {
                        if (rsms.Body.IndexOf(Convert.ToString(mr["Filterlist"])) > 0)
                        {
                            id = "2";
                            proc.SetLedStatus(0, 1);
                            break;
                        }
                    }
                    if (rsms.Body.IndexOf(Convert.ToString(mr["Filterlist"])) <= 0)
                    {
                        id = "1";
                        proc.WCE_PlaySound(proc.SoundFile, IntPtr.Zero, 1 | 131072);
                    }
                }
                else
                {
                    id = "1";
                    proc.WCE_PlaySound(proc.SoundFile, IntPtr.Zero, 1 | 131072);
                }
            }

            string dt = rsms.LastModified.ToLocalTime().ToString("yyyy-MM-dd' 'HH:mm:ss");
            SQLiteCommand comm = new SQLiteCommand("INSERT INTO sms(name, mobile, send, text, ID, State) VALUES ('" + rsms.From.Name + "', '" + mobile + "', '" + dt + "', '" + rsms.Body + "', '" + id + "', '0')", proc.conn);
            comm.ExecuteNonQuery();
            proc.conn.Close();
            lbox();
        }
        private void lbox()
        {
            proc.conn.Open();
            listBox1.Items.Clear();
            int uID = 1;
            if (button1.Enabled)
            {
                uID = 2;
            }
            int count = Convert.ToInt32(new SQLiteCommand("SELECT count(*) FROM sms where ID='" + uID + "' and state='" + Convert.ToString(comboBox1.SelectedIndex) + "'", proc.conn).ExecuteScalar());
            if (count > 0)
            {
                SQLiteDataReader sms = new SQLiteCommand("SELECT * FROM sms where ID='" + uID + "' and state='" + Convert.ToString(comboBox1.SelectedIndex) + "'", proc.conn).ExecuteReader();
                string item;
                while (sms.Read())
                {
                    item = sms["name"] + " " + Convert.ToDateTime(sms["send"]).ToString("yyyy-MM-dd' 'HH:mm:ss") + " " + sms["text"];
                    listBox1.Items.Add(item);
                }
            }
            button1.Text = "短信" + count + "项";
            proc.conn.Close();
        }
        private void main_Load(object sender, EventArgs e)
        {
            mi.MessageReceived += new MessageInterceptorEventHandler(m_Received);
            ico.Add(proc.LoadIcon(proc.GetModuleHandle(null), "#32512"));
            comboBox1.Text = Convert.ToString(comboBox1.Items[0]);
            lbox();
        }

        private void main_Closed(object sender, EventArgs e)
        {
            ico.Remove();
        }

        private void notifyIcon_Click(object sender, EventArgs e)
        {
            this.Show();
            proc.SetLedStatus(0, 0);
            lbox();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {

        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            if (listBox1.Items.Count > 0 & listBox1.SelectedIndex >= 0)
            {
                proc.conn.Open();
                SQLiteCommand comm;
                if (comboBox1.SelectedIndex == 2)
                {
                    comm = new SQLiteCommand("delete from sms where send='" + Convert.ToString(listBox1.Items[listBox1.SelectedIndex]).Split(' ')[1] + "'", proc.conn);
                }
                else
                {
                    comm = new SQLiteCommand("update sms set state='2' where send='" + Convert.ToString(listBox1.Items[listBox1.SelectedIndex]).Split(' ')[1] + "'", proc.conn);
                }
                comm.ExecuteNonQuery();
                proc.conn.Close();
            }
            lbox();
        }

        private void menuItem4_Click(object sender, EventArgs e)
        {
            if (0 <= listBox1.SelectedIndex & listBox1.SelectedIndex < listBox1.Items.Count)
            {
                //send.textBox1.Text = Convert.ToString(listBox1.Items[listBox1.SelectedIndex]).Split(' ')[0];
                //this.Hide();
                //send.Show();
            }
        }

        private void menuItem5_Click(object sender, EventArgs e)
        {
            if (0 <= listBox1.SelectedIndex & listBox1.SelectedIndex < listBox1.Items.Count)
            {
                //send.TextBox2.Text = Convert.ToString(listBox1.Items[listBox1.SelectedIndex]).Split(' ')[2];
                //this.Hide();
                //send.Show();
            }
        }

        private void menuItem7_Click(object sender, EventArgs e)
        {
            this.Hide();
            //filter.Show();
        }

        private void menuItem11_Click(object sender, EventArgs e)
        {

        }

        private void menuItem8_Click(object sender, EventArgs e)
        {
            proc.ExitWindowsEx(2, 0); //重启操作系统
        }

        private void menuItem9_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void menuItem10_Click(object sender, EventArgs e)
        {
            switch (button1.Enabled)
            {
                case true:
                    button1.Enabled = false;
                    menuItem7.Enabled = false;
                    menuItem9.Enabled = false;
                    break;
                case false:
                    button1.Enabled = true;
                    menuItem7.Enabled = true;
                    menuItem9.Enabled = true;
                    break;
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (0 <= listBox1.SelectedIndex & listBox1.SelectedIndex < listBox1.Items.Count)
            {
                sms sms = new sms();
                tb =Convert.ToString(listBox1.Items[listBox1.SelectedIndex]);
                sms.Show();
                this.Hide();
            }
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            lbox();
        }

        private void menuItem9_Click_1(object sender, EventArgs e)
        {
            this.Close();
            Application.Exit();
        }
    }
}

⌨️ 快捷键说明

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