Beispiel #1
0
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "address")
            {
                DataGridViewCell        addressCell = dataGridView1.Rows[e.RowIndex].Cells["address"];
                wDataGridViewMonitorRow row         = (wDataGridViewMonitorRow)addressCell.OwningRow;

                if (addressCell.Value != null)
                {
                    String addressValue = addressCell.Value.ToString();

                    Match m = Regex.Match(addressValue, @"\b");
                    if (m.Success)
                    {
                        addressValue = addressValue.ToString().ToUpper();
                    }

                    m = Regex.Match(addressValue, @"^[I|Q|M]");
                    if (m.Success)
                    {
                        wAddressType addressType;
                        switch (m.Value)
                        {
                        case "I":
                        default:
                            addressType = wAddressType.I;
                            break;

                        case "Q":
                            addressType = wAddressType.Q;
                            break;

                        case "M":
                            addressType = wAddressType.M;
                            break;
                        }

                        string addressTypeValue = addressValue.Substring(1);
                        m = Regex.Match(addressTypeValue, @"^[B|W|D]");
                        if (m.Success)
                        {
                            wAddressLengthType addressLengthType;
                            switch (m.Value)
                            {
                            case "B":
                            default:
                                addressLengthType = wAddressLengthType.Byte;
                                row.setByteOptions();
                                break;

                            case "W":
                                addressLengthType = wAddressLengthType.Word;
                                break;

                            case "D":
                                addressLengthType = wAddressLengthType.Double;
                                break;
                            }

                            string addressOffset = addressTypeValue.Substring(1);
                            m = Regex.Match(addressOffset, @"^[0-9]+$");
                            if (m.Success)
                            {
                                int         address = Int16.Parse(addressOffset);
                                wPlcAddress a       = new wPlcAddress(addressType, addressLengthType, address);
                                row.address                 = a;
                                row.addressIsValid          = true;
                                addressCell.Style.BackColor = Color.White;
                            }
                            else
                            {
                                row.addressIsValid          = false;
                                addressCell.Style.BackColor = Color.IndianRed;
                            }
                        }
                        else
                        {
                            row.addressIsValid          = false;
                            addressCell.Style.BackColor = Color.IndianRed;
                        }
                    }
                    else
                    {
                        row.addressIsValid          = false;
                        addressCell.Style.BackColor = Color.IndianRed;
                    }

                    addressCell.Value = addressValue;
                }
            }
            if (dataGridView1.Columns[e.ColumnIndex].Name == "dataType")
            {
            }
        }
Beispiel #2
0
 public wDataGridMonitorView()
 {
     RowTemplate = new wDataGridViewMonitorRow();
 }
Beispiel #3
0
 public wDataGridMonitorView()
 {
     RowTemplate = new wDataGridViewMonitorRow();
 }