Exemple #1
0
 //检测短信
 private void sms_operation_thread()
 {
     //短信与短信之间用“|” 隔开,第一条为空  |1#04#18670068930#是#14-05-21 17:30:46|2#04#18670068930#连客科技#14-05-21 17:42:36
     //每一条短信之间的项目用“#”隔开,分别是短信编号(删除短信时用此编号)0,短信类型1,发送号码2,内容3,日期4
     // 8#04#18670068930#321#14-05-21 20:19:18
     while (true)
     {
         string sms_Type = "00";
         string smsText;                     //所有短信的内容
         var    rt = SmsClass.Sms_NewFlag(); //判断是否有新短信
         if (rt == 1)
         {
             SmsClass.Sms_Receive(sms_Type, out smsText);
             if (smsText != "" || smsText != null)
             {
                 string[] smsarray = smsText.Split('|');
                 string   lastSms  = smsarray[smsarray.Length - 1].Split('#')[3].ToLower(); //短信内容
                 string   smsIndex = smsarray[smsarray.Length - 1].Split('#')[0];           //短信的编号,用于删除短信
                 string   phoneNo  = smsarray[smsarray.Length - 1].Split('#')[2];           //发送短信的手机号码
                 DBhandler(smsIndex, lastSms, phoneNo);
             }
         }
         Thread.Sleep(1000);
     }
 }
Exemple #2
0
        //根椐短信内容对数据库进行操作,
        // 操作代码如下:
        // 100:清空所有数据表,清空前先备份到C:\下,以当天的日期时间命名,如20140522153226
        // 101:备份数据库
        // 其它:回复短信:设备工作正常
        private void DBhandler(string smsIndex, string str, string phoneNo)
        {
            SqlConnection con  = new SqlConnection(connectionString);
            string        name = DateTime.Now.ToString("yyyyMMddHHmmss"); //数据库备份的名字,以当天的日期为名字,没有后缀
            SqlCommand    cmd;

            try
            {
                con.Open();
                cmd            = new SqlCommand();
                cmd.Connection = con;
                switch (str.ToLower())
                {
                case "100":
                    if (m_thread_auto != null && m_thread_auto.IsAlive)
                    {
                        m_thread_auto.Abort();
                    }

                    if (m_thread_detect != null && m_thread_detect.IsAlive)
                    {
                        m_thread_detect.Abort();
                    }

                    m_uploadCloud.stop();

                    cmd.CommandText = @"backup database bathdb to disk='d:\" + name + "'";
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "exec sp_msforeachtable 'truncate table ?' ";
                    cmd.ExecuteNonQuery();
                    break;

                case "101":
                    cmd.CommandText = @"backup database bathdb to disk='d:\" + name + "'";
                    cmd.ExecuteNonQuery();
                    break;

                default:
                    SmsClass.Sms_Send(phoneNo, Constants.SMS_HINT_MSG);
                    break;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("数据库操作失败! " + ex.Message);
            }
            finally
            {
                con.Close();
                SmsClass.Sms_Delete(smsIndex);  //删除短信
                if (str == "100")
                {
                    Environment.Exit(0);
                }
            }
        }
Exemple #3
0
 //双击任务栏图标
 private void NotifyServer_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     NotifyServer.Visible = false;
     this.ShowInTaskbar   = true;
     this.WindowState     = FormWindowState.Normal;
     if (CheckSMS.Checked)
     {
         SmsClass.Sms_Disconnection();
     }
 }
Exemple #4
0
        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (CheckSMS.Checked)
            {
                SmsClass.Sms_Disconnection();
            }

            NotifyServer.Visible = false;
            this.ShowInTaskbar   = true;
            this.WindowState     = FormWindowState.Normal;
        }
Exemple #5
0
        private void BtnOk_Click(object sender, EventArgs e)
        {
            save_config();

            #region 检测是否需要启动检测手牌异常线程
            if (CheckDetect.Checked)
            {
                timeLimit = MConvert <int> .ToTypeOrDefault(TextTimeLimit.Text, -1);

                moneyLimit = MConvert <double> .ToTypeOrDefault(TextMoneyLimit.Text, -1);

                if (m_thread_detect == null)
                {
                    m_thread_detect = new Thread(new ThreadStart(detect_unnormal_seat_thread));
                    m_thread_detect.IsBackground = true;
                    m_thread_detect.Start();
                }
            }
            #endregion

            #region 检测是否需要启动自动滚消费线程
            if (CheckAuto.Checked)
            {
                if (m_thread_auto == null)
                {
                    m_thread_auto = new Thread(new ThreadStart(order_auto_add_thread));
                    m_thread_auto.IsBackground = true;
                    m_thread_auto.Start();
                }
            }
            #endregion

            #region 检测是否需要启动UDP服务器线程
            if (CheckServer.Checked)
            {
                if (udp_Server == null)
                {
                    try
                    {
                        udp_Server = new UdpListenerPlus(Constants.LocalUdpPort);
                        udp_Server.OnThreadTaskRequest += new UdpListenerPlus.ThreadTaskRequest(Handle_Udp_Msg);
                    }

                    catch (Exception)
                    {
                        if (udp_Server != null)
                        {
                            udp_Server.Stop();
                            udp_Server = null;
                        }
                        MessageBox.Show(this, "启动UDP服务器失败!", "信息");
                    }
                }
                else
                {
                    udp_Server.Stop();
                    udp_Server = null;
                }
            }
            #endregion

            #region 启动云服务器上传线程

            if (m_uploadCloud == null)
            {
                m_uploadCloud = new UploadCloud(connectionString);
                m_uploadCloud.start();
            }

            #endregion


            #region 检测是否启用短信操控
            if (CheckSMS.Checked)
            {
                BtnOk.Enabled = false;
                string port = IOUtil.get_config_by_key(ConfigKeys.KEY_SMSPORT);
                if (port != "")
                {
                    comport = MConvert <uint> .ToTypeOrDefault(port.Substring(3, port.Length - 3), 0);
                }
                string str_baudrate = IOUtil.get_config_by_key(ConfigKeys.KEY_SMSBAUD);
                baudrate = MConvert <uint> .ToTypeOrDefault(str_baudrate, 0);

                string mobileType     = "";
                string CopyRightToCOM = "";
                string CopyRight      = "//上海迅赛信息技术有限公司,网址www.xunsai.com//";
                if (SmsClass.Sms_Connection(CopyRight, comport, baudrate, out mobileType, out CopyRightToCOM) == 0)
                {
                    MessageBox.Show("短信猫打开失败,请重新配置!");
                    BtnOk.Enabled = true;
                    return;
                }
                m_thread_smsOpertion = new Thread(new ThreadStart(sms_operation_thread));
                m_thread_smsOpertion.IsBackground = true;
                m_thread_smsOpertion.Start();
            }


            #endregion


            this.WindowState = FormWindowState.Minimized;
            BtnOk.Enabled    = true;
        }