예제 #1
0
        private void btn控制功能_Click_1(object sender, EventArgs e)
        {
            string endTime = tbEndTime.Text;

            if (endTime.Length != 12)
            {
                MessageBox.Show("命令有效截止长度不足!");
                return;
            }

            //倒计时控制
            if (rbYutiaozha1.Checked || rbYutiaozha2.Checked)
            {
                string x = tbYutiaozhaTime.Text;
                x = (Convert.ToInt16(x, 16) * 5).ToString("X2");
                x = x.Substring(x.Length - 2, 2);
                timeCountDown_mm      = Convert.ToInt16(x, 16);
                lblTimeCountDown.Text = "倒计时:" + timeCountDown_mm.ToString("D4") + ":00";
                timeCountDown_mm--;
                timeCountDown_ss = 60;
                if (timerPCTime.Enabled)
                {
                    timerPCTime.Stop();
                }
                timerPCTime.Interval   = 1000;
                this.timerPCTime.Tick -= new EventHandler(TimeCountDown);
                this.timerPCTime.Tick += new EventHandler(TimeCountDown);
                timerPCTime.Start();
            }
            #region 控制
            string N1N2 = null;
            if (rbTiaozha.Checked)
            {
                N1N2 = "1A00";                   //跳闸
            }
            if (rbYunxuhezha.Checked)
            {
                N1N2 = "1B00";                      //允许合闸
            }
            if (rbZhijiehezha.Checked)
            {
                N1N2 = "1C00";                       //直接合闸
            }
            if (rbYutiaozha1.Checked)
            {
                string ss = tbYutiaozhaTime.Text.PadLeft(2, '0');
                N1N2 = "1D" + ss;
            }
            if (rbYutiaozha2.Checked)
            {
                string ss = tbYutiaozhaTime.Text.PadLeft(2, '0');
                N1N2 = "1E" + ss;
            }
            if (rbBaojing.Checked)
            {
                N1N2 = "2A00";
            }
            if (rbJiechubaojing.Checked)
            {
                N1N2 = "2B00";
            }
            if (rbBaodian.Checked)
            {
                N1N2 = "3A00";
            }
            if (rbJiechubaodian.Checked)
            {
                N1N2 = "3B00";
            }

            Protocol645 p645 = new Protocol645();
            //明文模式
            if (rbMingwen.Checked)
            {
                string putData = endTime + Transfer.ReverseString(N1N2);
                if (p645.FeikongControl(putData))
                {
                    MessageBox.Show("操控成功!");
                }
                else
                {
                    MessageBox.Show("操控失败!");
                }
            }
            //密文模式
            if (rbMiwen.Checked)
            {
                string orginalPsw = Protocol645.Psw;
                Esam645Service.EsamOptionClient ESAMproxy = new Esam645Service.EsamOptionClient();//要操作时才new
                try
                {
                    string putData = N1N2 + endTime;
                    string enData  = ESAMproxy.Meter_Formal_UserControl(0, tbRand2.Text, tbDiv.Text, tbEsamNo.Text, putData);

                    Protocol645.Psw = orginalPsw.Substring(0, 6) + "98";//临时改为98级密码
                    if (p645.FeikongControl(enData))
                    {
                        MessageBox.Show("操控成功!");
                    }
                    else
                    {
                        MessageBox.Show("操控失败!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
                finally
                {
                    ESAMproxy.Close();
                    Protocol645.Psw = orginalPsw;//用后要改回原界面密码,否则影响其他功能使用
                }
            }
            #endregion
        }