Exemple #1
0
        private void lvGatewayList_DoubleClick(object sender, EventArgs e)
        {
            string           strGatewayID;
            cls_Gateway_Info gwTemp = new cls_Gateway_Info();

            if (lvGatewayList.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select the gateway first!", "Error");
                return;
            }

            strGatewayID = lvGatewayList.SelectedItems[0].Text.Trim();

            int i = 0;

            foreach (cls_Gateway_Info gi in this.gm.gateway_list)
            {
                if (gi.gateway_id == strGatewayID)
                {
                    gwTemp = this.gm.gateway_list[i];
                    break;
                }
                i++;
            }

            var frm = new frmEditGateway(SetGatewayInfo, gwTemp);

            frm.Owner = this;
            frm.ShowDialog();

            gwTemp = null;

            RefreshGatewayList();
            lvGatewayList.Focus();
        }
Exemple #2
0
        private void btnAddGateway_Click(object sender, EventArgs e)
        {
            //var frm = new frmEditGateway();
            var frm = new frmEditGateway(SetGatewayInfo, CheckDuplicateGateway, false);

            frm.Owner = this;
            frm.ShowDialog();

            delgGWManager(gm);
            RefreshGatewayList();
        }
Exemple #3
0
        private void btnDeviceSave_Click(object sender, EventArgs e)
        {
            cls_Device_Info diTemp         = new cls_Device_Info();
            bool            duplicate_flag = false;

            if (txtDeviceID.Text.Trim() == "")
            {
                MessageBox.Show("Please enter Device ID!", "Error");
                return;
            }

            if (!this.isEdit)
            {
                duplicate_flag = (bool)IEW.Platform.Kernel.Platform.Instance.Invoke("GatewayService", "CheckDuplicateDeviceID", new object[] { txtDeviceID.Text.Trim() });
                if (duplicate_flag)
                {
                    MessageBox.Show("Device ID should be unique!!", "Error");
                    return;
                }
            }

            if (cmbType.Text.Trim() == "")
            {
                MessageBox.Show("Please select the device type!", "Error");
                return;
            }

            if (cmbType.Text == "PLC")
            {
                if (txtPLC_IP.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter the PLC ip!", "Error");
                    return;
                }
                else
                {
                    IPAddress ip;
                    bool      validate = IPAddress.TryParse(txtPLC_IP.Text.Trim(), out ip);
                    if (!validate)
                    {
                        MessageBox.Show("Please enter the  valid ip address!", "Error");
                        return;
                    }
                }

                if (txtPLC_Port.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter the port id!", "Error");
                    return;
                }
            }
            else if (cmbType.Text == "BLE")
            {
                if (txtBLE_Mac.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter the MAC address!", "Error");
                    return;
                }
                else
                {
                    Regex r = new Regex("^([0-9a-fA-F]{2}(?:(?:-[0-9a-fA-F]{2}){5}|(?::[0-9a-fA-F]{2}){5}|[0-9a-fA-F]{10}))$");
                    if (!r.IsMatch(txtBLE_Mac.Text.Trim()))
                    {
                        MessageBox.Show("Invalid MAC address!", "Error");
                        return;
                    }
                }

                if (txtBLE_Service_UUID.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter the BLE Service UUID!", "Error");
                    return;
                }
            }

            diTemp.device_name     = txtDeviceID.Text.Trim();
            diTemp.device_type     = cmbType.Text.Trim();
            diTemp.device_location = txtLocation.Text.Trim();
            diTemp.plc_ip_address  = txtPLC_IP.Text.Trim();
            diTemp.plc_port_id     = txtPLC_Port.Text.Trim();
            diTemp.ble_mac         = txtBLE_Mac.Text.Trim();
            if (txtBLE_Service_UUID.Text.Trim() == "")
            {
                diTemp.ble_service_uuid = null;
            }
            else
            {
                diTemp.ble_service_uuid.Add(txtBLE_Service_UUID.Text.Trim());
            }

            diTemp.tag_info      = taglist_data;
            diTemp.calc_tag_info = calc_taglist_data;

            this.device_data = diTemp;

            if (!isEmbedded)
            {
                frmEditGateway pgw = (frmEditGateway)this.Owner;

                if (!isEdit)
                {
                    //pgw.device_list.Add(diTemp);
                    pgw.gateway_Info.device_info.Add(diTemp);
                }
                else
                {
                    //pgw.device_list[iDeviceIndex] = diTemp;
                    pgw.gateway_Info.device_info[iDeviceIndex] = diTemp;
                }
            }
            else
            {
                Gateway p = (Gateway)this.Owner;
                p.SetDeviceInfo(gw_data, device_data, iDeviceIndex, this.isCopy);
                p.RefreshGatewayConfig(0);
            }

            this.Close();
        }