Ejemplo n.º 1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                ShowStatusBar(string.Empty, true);

                if (IsDeviceConnected)
                {
                    IsDeviceConnected = false;
                    this.Cursor       = Cursors.Default;

                    return;
                }

                string ipAddress = tbxDeviceIP.Text.Trim();
                string port      = tbxPort.Text.Trim();
                if (ipAddress == string.Empty || port == string.Empty)
                {
                    throw new Exception("The Device IP Address and Port is mandotory !!");
                }

                int portNumber = 4370;
                if (!int.TryParse(port, out portNumber))
                {
                    throw new Exception("Not a valid port number");
                }

                bool isValidIpA = CHBK2014_N9.ATT.Utilities.UniversalStatic.ValidateIP(ipAddress);
                if (!isValidIpA)
                {
                    throw new Exception("The Device IP is invalid !!");
                }

                isValidIpA = CHBK2014_N9.ATT.Utilities.UniversalStatic.PingTheDevice(ipAddress);
                if (!isValidIpA)
                {
                    throw new Exception("The device at " + ipAddress + ":" + port + " did not respond!!");
                }

                objZkeeper        = new CHBK2014_N9.ATT.Utilities.ZkemClient(RaiseDeviceEvent);
                IsDeviceConnected = objZkeeper.Connect_Net(ipAddress, portNumber);

                if (IsDeviceConnected)
                {
                    string deviceInfo = manipulator.FetchDeviceInfo(objZkeeper, int.Parse(tbxMachineNumber.Text.Trim()));
                    lblDeviceInfo.Text = deviceInfo;
                }
            }
            catch (Exception ex)
            {
                ShowStatusBar(ex.Message, false);
            }
            this.Cursor = Cursors.Default;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            this.DGVDuLieuVaoRa.Rows.Clear();

            if (this.comboBoxLuaChonTai.SelectedIndex == 0)
            {
                string str;
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    //   ShowStatusBar(string.Empty, true);

                    if (IsDeviceConnected)
                    {
                        IsDeviceConnected = false;
                        this.Cursor       = Cursors.Default;

                        return;
                    }

                    string ipAddress = tbxDeviceIP.Text.Trim();
                    string port      = tbxPort.Text.Trim();
                    if (ipAddress == string.Empty || port == string.Empty)
                    {
                        throw new Exception("The Device IP Address and Port is mandotory !!");
                    }

                    int portNumber = 4370;
                    if (!int.TryParse(port, out portNumber))
                    {
                        throw new Exception("Not a valid port number");
                    }

                    bool isValidIpA = CHBK2014_N9.ATT.Utilities.UniversalStatic.ValidateIP(ipAddress);
                    if (!isValidIpA)
                    {
                        throw new Exception("The Device IP is invalid !!");
                    }

                    isValidIpA = CHBK2014_N9.ATT.Utilities.UniversalStatic.PingTheDevice(ipAddress);
                    if (!isValidIpA)
                    {
                        throw new Exception("The device at " + ipAddress + ":" + port + " did not respond!!");
                    }

                    axCZKEM2 = new CHBK2014_N9.ATT.Utilities.ZkemClient(RaiseDeviceEvent);
                    //  IsDeviceConnected = objZkeeper.Connect_Net(ipAddress, portNumber);
                    IsDeviceConnected = axCZKEM1.Connect_Net(ipAddress, portNumber);



                    if (this.axCZKEM1.GetDeviceStatus(1, 6, ref this._value))
                    {
                        this.iSoDuLieu = this._value;
                    }
                    this.kiemTraLoaiMay();
                    this.taiDuLieuVaoRa();
                    this.Cursor = Cursors.Default;



                    if (this.comboBoxLuaChonTai.SelectedIndex == 1)
                    {
                        MessageBox.Show("Chọn ng\x00e0y");
                    }
                }
                catch (Exception ex)
                {
                }
                this.Cursor = Cursors.Default;
            }
        }