private void dgvGroupAddress_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                if (this.IsSelectAll)
                {
                    this.IsSelectAll = false;

                    this.dgvGroupAddress.CurrentCell = null;

                    for (int i = 0; i < this.dgvGroupAddress.RowCount; i++)
                    {
                        this.dgvGroupAddress.Rows[i].Cells["IsSelected"].Value = false;
                    }
                }
                else
                {
                    this.IsSelectAll = true;

                    this.dgvGroupAddress.CurrentCell = null;

                    for (int i = 0; i < this.dgvGroupAddress.RowCount; i++)
                    {
                        this.dgvGroupAddress.Rows[i].Cells["IsSelected"].Value = true;
                    }
                }
            }
            else
            {
                this.dgvGroupAddress.EndEdit();

                bool anySelected            = false;
                bool communicationIsChecked = false;
                bool readIsChecked          = false;
                bool writeIsChecked         = false;
                bool transmitIsChecked      = false;
                bool upgradeIsChecked       = false;
                foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                {
                    anySelected            = (bool)row.Cells["IsSelected"].Value;
                    communicationIsChecked = (bool)row.Cells["IsCommunication"].Value;
                    readIsChecked          = (bool)row.Cells["IsRead"].Value;
                    writeIsChecked         = (bool)row.Cells["IsWrite"].Value;
                    transmitIsChecked      = (bool)row.Cells["IsTransmit"].Value;
                    upgradeIsChecked       = (bool)row.Cells["IsUpgrade"].Value;
                    if (anySelected)
                    {
                        break;
                    }
                }

                if (anySelected)
                {
                    if (1 == e.ColumnIndex) // Id
                    {
                    }
                    else if (2 == e.ColumnIndex) // Name
                    {
                    }
                    else if (3 == e.ColumnIndex) // KnxAddress
                    {
                    }
                    else if (4 == e.ColumnIndex) // KnxMainNumber
                    {
                    }
                    else if (5 == e.ColumnIndex) // KnxSubNumber
                    {
                    }
                    else if (6 == e.ColumnIndex) // Type
                    {
                    }
                    else if (7 == e.ColumnIndex) // DPTName
                    {
                    }
                    else if (8 == e.ColumnIndex) // 是否通讯
                    {
                        foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                        {
                            bool isSelected = (bool)row.Cells[0].Value;
                            if (isSelected)
                            {
                                if (communicationIsChecked)
                                {
                                    row.Cells[e.ColumnIndex].Value = false;
                                }
                                else
                                {
                                    row.Cells[e.ColumnIndex].Value = true;
                                }
                            }
                        }

                        Changed = true;
                    }
                    else if (9 == e.ColumnIndex) // 是否读
                    {
                        foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                        {
                            bool isSelected = (bool)row.Cells[0].Value;
                            if (isSelected)
                            {
                                if (readIsChecked)
                                {
                                    row.Cells[e.ColumnIndex].Value = false;
                                }
                                else
                                {
                                    row.Cells[e.ColumnIndex].Value = true;
                                }
                            }
                        }

                        Changed = true;
                    }
                    else if (10 == e.ColumnIndex) // 是否写
                    {
                        foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                        {
                            bool isSelected = (bool)row.Cells[0].Value;
                            if (isSelected)
                            {
                                if (writeIsChecked)
                                {
                                    row.Cells[e.ColumnIndex].Value = false;
                                }
                                else
                                {
                                    row.Cells[e.ColumnIndex].Value = true;
                                }
                            }
                        }

                        Changed = true;
                    }
                    else if (11 == e.ColumnIndex) // 是否传输
                    {
                        foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                        {
                            bool isSelected = (bool)row.Cells[0].Value;
                            if (isSelected)
                            {
                                if (transmitIsChecked)
                                {
                                    row.Cells[e.ColumnIndex].Value = false;
                                }
                                else
                                {
                                    row.Cells[e.ColumnIndex].Value = true;
                                }
                            }
                        }

                        Changed = true;
                    }
                    else if (12 == e.ColumnIndex) // 是否更新
                    {
                        foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                        {
                            bool isSelected = (bool)row.Cells[0].Value;
                            if (isSelected)
                            {
                                if (upgradeIsChecked)
                                {
                                    row.Cells[e.ColumnIndex].Value = false;
                                }
                                else
                                {
                                    row.Cells[e.ColumnIndex].Value = true;
                                }
                            }
                        }

                        Changed = true;
                    }
                    else if (13 == e.ColumnIndex) // 优先级
                    {
                        var frm    = new FrmSetPriority();
                        var result = frm.ShowDialog();
                        if (DialogResult.OK == result)
                        {
                            KNXPriority priority = frm.priority;
                            foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                            {
                                bool isSelected = (bool)row.Cells[0].Value;
                                if (isSelected)
                                {
                                    row.Cells[e.ColumnIndex].Value = priority;
                                }
                            }

                            Changed = true;
                        }
                    }
                    else if (14 == e.ColumnIndex) // 默认值
                    {
                        var frm    = new FrmSetDefaultValue();
                        var result = frm.ShowDialog();
                        if (DialogResult.OK == result)
                        {
                            int value = frm.value;
                            foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                            {
                                bool isSelected = (bool)row.Cells[0].Value;
                                if (isSelected)
                                {
                                    row.Cells[e.ColumnIndex].Value = value;
                                }
                            }

                            Changed = true;
                        }
                    }
                    else if (15 == e.ColumnIndex) // Actions
                    {
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void dgvGroupAddress_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            Console.Write("\nrow index:" + e.RowIndex + "\tcolumn index:" + e.ColumnIndex);

            if (e.ColumnIndex == 0)
            {
                if (this.IsSelectAll)
                {
                    this.IsSelectAll = false;

                    this.dgvGroupAddress.CurrentCell = null;

                    for (int i = 0; i < this.dgvGroupAddress.RowCount; i++)
                    {
                        this.dgvGroupAddress.Rows[i].Cells["IsSelected"].Value = false;

                    }
                }
                else
                {
                    this.IsSelectAll = true;

                    this.dgvGroupAddress.CurrentCell = null;

                    for (int i = 0; i < this.dgvGroupAddress.RowCount; i++)
                    {
                        this.dgvGroupAddress.Rows[i].Cells["IsSelected"].Value = true;
                    }
                }
            }
            else
            {
                this.dgvGroupAddress.EndEdit();

                bool anySelected = false;
                bool communicationIsChecked = false;
                bool readIsChecked = false;
                bool writeIsChecked = false;
                bool transmitIsChecked = false;
                bool upgradeIsChecked = false;
                foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                {
                    anySelected = (bool)row.Cells["IsSelected"].Value;
                    communicationIsChecked = (bool)row.Cells["IsCommunication"].Value;
                    readIsChecked = (bool)row.Cells["IsRead"].Value;
                    writeIsChecked = (bool)row.Cells["IsWrite"].Value;
                    transmitIsChecked = (bool)row.Cells["IsTransmit"].Value;
                    upgradeIsChecked = (bool)row.Cells["IsUpgrade"].Value;
                    if (anySelected)
                    {
                        break;
                    }
                }

                if (anySelected)
                {
                    if (1 == e.ColumnIndex)
                    {

                    }
                    else if (2 == e.ColumnIndex) // 名称
                    {

                    }
                    else if (3 == e.ColumnIndex) // 地址
                    {

                    }
                    else if (4 == e.ColumnIndex)
                    {

                    }
                    else if (5 == e.ColumnIndex) // 是否通讯
                    {
                        foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                        {
                            bool isSelected = (bool)row.Cells[0].Value;
                            if (isSelected)
                            {
                                if (communicationIsChecked)
                                {
                                    row.Cells[e.ColumnIndex].Value = false;
                                }
                                else
                                {
                                    row.Cells[e.ColumnIndex].Value = true;
                                }
                            }
                        }

                        Changed = true;
                    }
                    else if (6 == e.ColumnIndex) // 是否读
                    {
                        foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                        {
                            bool isSelected = (bool)row.Cells[0].Value;
                            if (isSelected)
                            {
                                if (readIsChecked)
                                {
                                    row.Cells[e.ColumnIndex].Value = false;
                                }
                                else
                                {
                                    row.Cells[e.ColumnIndex].Value = true;
                                }
                            }
                        }

                        Changed = true;
                    }
                    else if (7 == e.ColumnIndex) // 是否写
                    {
                        foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                        {
                            bool isSelected = (bool)row.Cells[0].Value;
                            if (isSelected)
                            {
                                if (writeIsChecked)
                                {
                                    row.Cells[e.ColumnIndex].Value = false;
                                }
                                else
                                {
                                    row.Cells[e.ColumnIndex].Value = true;
                                }
                            }
                        }

                        Changed = true;
                    }
                    else if (8 == e.ColumnIndex) // 是否传输
                    {
                        foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                        {
                            bool isSelected = (bool)row.Cells[0].Value;
                            if (isSelected)
                            {
                                if (transmitIsChecked)
                                {
                                    row.Cells[e.ColumnIndex].Value = false;
                                }
                                else
                                {
                                    row.Cells[e.ColumnIndex].Value = true;
                                }
                            }
                        }

                        Changed = true;
                    }
                    else if (9 == e.ColumnIndex) // 是否更新
                    {
                        foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                        {
                            bool isSelected = (bool)row.Cells[0].Value;
                            if (isSelected)
                            {
                                if (upgradeIsChecked)
                                {
                                    row.Cells[e.ColumnIndex].Value = false;
                                }
                                else
                                {
                                    row.Cells[e.ColumnIndex].Value = true;
                                }
                            }
                        }

                        Changed = true;
                    }
                    else if (10 == e.ColumnIndex) // 优先级
                    {
                        var frm = new FrmSetPriority();
                        var result = frm.ShowDialog();
                        if (DialogResult.OK == result)
                        {
                            KNXPriority priority = frm.priority;
                            foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                            {
                                bool isSelected = (bool)row.Cells[0].Value;
                                if (isSelected)
                                {
                                    row.Cells[e.ColumnIndex].Value = priority;
                                }
                            }

                            Changed = true;
                        }
                    }
                    else if (11 == e.ColumnIndex) // 默认值
                    {
                        var frm = new FrmSetDefaultValue();
                        var result = frm.ShowDialog();
                        if (DialogResult.OK == result)
                        {
                            int value = frm.value;
                            foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                            {
                                bool isSelected = (bool)row.Cells[0].Value;
                                if (isSelected)
                                {
                                    row.Cells[e.ColumnIndex].Value = value;
                                }
                            }

                            Changed = true;
                        }
                    }
                    else if (12 == e.ColumnIndex) // 读取时间间隔
                    {
                        var frm = new FrmSetReadTimeSpan();
                        var result = frm.ShowDialog();
                        if (DialogResult.OK == result)
                        {
                            int value = frm.time;
                            foreach (DataGridViewRow row in this.dgvGroupAddress.Rows)
                            {
                                bool isSelected = (bool)row.Cells[0].Value;
                                if (isSelected)
                                {
                                    row.Cells[e.ColumnIndex].Value = value;
                                }
                            }

                            Changed = true;
                        }
                    }
                }
            }
        }