Пример #1
0
        private void btnDOModifyOk_Click(object sender, EventArgs e)
        {
            //获取修改的数据
            String GroupName = dgvDOModify.Rows[0].Cells[0].Value.ToString();
            String Name      = dgvDOModify.Rows[0].Cells[1].Value.ToString();
            Int32  CardNum   = int.Parse(dgvDOModify.Rows[0].Cells[2].Value.ToString());
            Int32  IoID      = int.Parse(dgvDOModify.Rows[0].Cells[3].Value.ToString());
            String mIoType   = dgvDOModify.Rows[0].Cells[4].Value.ToString();
            Int32  IoType    = WUseToolClass.getIoType(dgvDOModify.Rows[0].Cells[4].Value.ToString());
            String mIoState  = dgvDOModify.Rows[0].Cells[5].Value.ToString();
            Int32  IoState   = WUseToolClass.getIoState(dgvDOModify.Rows[0].Cells[5].Value.ToString());
            Int32  ExtendNum = int.Parse(dgvDOModify.Rows[0].Cells[6].Value.ToString());

            try
            {
                int    isModifyNum = 0;
                int    mIndex      = dgvDO.CurrentRow.Index;
                String oldName     = dgvDO.Rows[mIndex].Cells[1].Value.ToString();
                if (Name != oldName)
                {
                    if (mWDataToolClass.SelectShowDOCheck(" Name=" + Name) == 1)
                    {
                        MessageBox.Show("端口名称已存在,请检查");
                        return;
                    }
                }
                else
                {
                    isModifyNum++;
                }

                if (IoType == 1023)
                {
                    if (CardNum == int.Parse(dgvDO.Rows[mIndex].Cells[2].Value.ToString()) &&
                        IoID == int.Parse(dgvDO.Rows[mIndex].Cells[3].Value.ToString()) &&
                        mIoType == dgvDO.Rows[mIndex].Cells[4].Value.ToString() &&
                        ExtendNum == int.Parse(dgvDO.Rows[mIndex].Cells[6].Value.ToString()))
                    {
                        isModifyNum++;
                    }
                    else
                    {
                        if (mWDataToolClass.SelectShowDOCheck(
                                " CardNum=" + CardNum.ToString() +
                                " and IoID=" + IoID.ToString() +
                                " and IoType=" + IoType.ToString() +
                                " and ExtendNum=" + ExtendNum.ToString()
                                ) == 1)
                        {
                            MessageBox.Show("卡号、端口号、端口类型和扩展卡号已存在,请检查");
                            return;
                        }
                    }
                }
                else
                {
                    if (CardNum == int.Parse(dgvDO.Rows[mIndex].Cells[2].Value.ToString()) &&
                        IoID == int.Parse(dgvDO.Rows[mIndex].Cells[3].Value.ToString()) &&
                        mIoType == dgvDO.Rows[mIndex].Cells[4].Value.ToString())
                    {
                        isModifyNum++;
                    }
                    else
                    {
                        if (mWDataToolClass.SelectShowDOCheck(
                                " CardNum=" + CardNum.ToString() +
                                " and IoID=" + IoID.ToString() +
                                " and IoType=" + IoType.ToString()
                                ) == 1)
                        {
                            MessageBox.Show("卡号、端口号和端口类型已存在,请检查");
                            return;
                        }
                    }
                }
                if (GroupName == dgvDO.Rows[mIndex].Cells[0].Value.ToString() &&
                    mIoState == dgvDO.Rows[mIndex].Cells[5].Value.ToString())
                {
                    isModifyNum++;
                }
                if (isModifyNum == 3)
                {
                    MessageBox.Show("当前数据未有改动");
                    return;
                }
                if (mWDataToolClass.UpdateDO(oldName, GroupName, Name, CardNum, IoID, IoType, IoState, ExtendNum) != 0)
                {
                    MessageBox.Show("轴数据修改失败");
                    return;
                }
                //刷新轴数据
                mWDataToolClass.SelectShowDO(ref dgvDO);
                dgvDOModify.Rows.Clear();
                closePanelUI();
                MessageBox.Show("轴数据修改成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }