Ejemplo n.º 1
0
        private void btn_DownLoad_Click(object sender, EventArgs e)
        {
            _currentNumber = 1;
            if (tb_ID.Text.Length != 0)
            {
                _currentNumber = Convert.ToInt32(tb_ID.Text);
                if (_currentNumber == 0)
                {
                    MessageBox.Show("ID 编号从1开始。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            if (_currentNumber > 99999999)
            {
                MessageBox.Show("ID 编号已经超出可写范围(0 - 99999999)", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (_currentNumber < _mNumber.Number)
            {
                if (MessageBox.Show(string.Format(" ID 编号:{0}已经在使用中,是否重新下载写入。(当前流水编号:{1})", _currentNumber, _mNumber.Number), @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes)
                {
                    return;
                }
            }
            btn_DownLoad.Image   = null;
            btn_DownLoad.Enabled = false;
            tb_ID.Enabled        = false;

            byte[] by = PortAgreement.SetModuleNumber(tb_ID.Text);
            _mPort.Write(by);

            if (_tOverTime == null)
            {
                _tOverTime           = new System.Timers.Timer(5000);
                _tOverTime.AutoReset = false;
                _tOverTime.Elapsed  += _tOverTime_Elapsed;
                _tOverTime.Start();
            }
        }