Exemplo n.º 1
0
        public void ConInit(WDataToolClass mWDataToolClass, string GroupName = "")
        {
            this.mWDataToolClass = mWDataToolClass;

            int       rtn = 0;
            DataTable dt;

            rtn = mWDataToolClass.SelectShowDI(out dt, GroupName);
            if (rtn != 0)
            {
                MessageBox.Show("SelectShowModel");
            }
            string        mGroupName = "";
            ListViewGroup mHeader    = new ListViewGroup();
            ListViewItem  mLvi;

            lvDIView.SmallImageList = ilImageList;
            foreach (DataRow row in dt.Rows)
            {
                //创建列表组名并添加
                if (mGroupName != row[0].ToString())
                {
                    mGroupName              = row[0].ToString();
                    mHeader                 = new ListViewGroup();
                    mHeader.Header          = mGroupName;
                    mHeader.HeaderAlignment = HorizontalAlignment.Left;
                    lvDIView.Groups.Add(mHeader);
                    lvDIView.ShowGroups = true;
                }
                //添加数据
                mLvi            = new ListViewItem();
                mLvi.ImageIndex = 0;
                mLvi.Text       = row[1].ToString();
                mLvi.SubItems.Add(row[2].ToString());
                mLvi.SubItems.Add(row[3].ToString());
                mLvi.SubItems.Add(row[4].ToString());
                mLvi.SubItems.Add(row[5].ToString());
                mLvi.SubItems.Add(row[6].ToString());
                //添加到列表
                mHeader.Items.Add(mLvi);
                lvDIView.Items.Add(mLvi);
            }
            //启动信号刷新定时器
            tSignalRefresh.Enabled = true;
        }
Exemplo n.º 2
0
        public void ConInit(WDataToolClass mWDataToolClass)
        {
            this.mWDataToolClass = mWDataToolClass;

            int rtn = 0;

            rtn = mWDataToolClass.SelectShowAxis(ref dgvAxis);
            if (rtn != 0)
            {
                MessageBox.Show("SelectShowAxis");
            }
            rtn = mWDataToolClass.SelectShowDI(ref dgvDI);
            if (rtn != 0)
            {
                MessageBox.Show("SelectShowAxis");
            }
            rtn = mWDataToolClass.SelectShowDO(ref dgvDO);
            if (rtn != 0)
            {
                MessageBox.Show("SelectShowAxis");
            }
        }
Exemplo n.º 3
0
        private void btnDIAddOk_Click(object sender, EventArgs e)
        {
            String GroupName = "";
            String Name      = "";
            Int32  CardNum   = 0;
            Int32  IoID      = 0;
            String mIoType   = "";
            Int32  IoType    = 0;
            String mIoState  = "";
            Int32  IoState   = 0;
            Int32  ExtendNum = 0;

            try
            {
                if (dgvDIAdd.Rows.Count > 0)
                {
                    //检查数据
                    for (int i = 0; i < dgvDIAdd.Rows.Count - 1; i++)
                    {
                        //检查数据是否为空
                        if (dgvDIAdd.Rows[i].Cells[0].Value == null)
                        {
                            MessageBox.Show("第" + (i + 1).ToString() + "行的组名为空,请检查");
                            return;
                        }
                        if (dgvDIAdd.Rows[i].Cells[1].Value == null)
                        {
                            MessageBox.Show("第" + (i + 1).ToString() + "行的端口名称为空,请检查");
                            return;
                        }
                        if (dgvDIAdd.Rows[i].Cells[2].Value == null)
                        {
                            MessageBox.Show("第" + (i + 1).ToString() + "行的卡号未选择,请检查");
                            return;
                        }
                        if (dgvDIAdd.Rows[i].Cells[3].Value == null)
                        {
                            MessageBox.Show("第" + (i + 1).ToString() + "行的端口号未选择,请检查");
                            return;
                        }
                        if (dgvDIAdd.Rows[i].Cells[4].Value == null)
                        {
                            MessageBox.Show("第" + (i + 1).ToString() + "行的端口类型选择,请检查");
                            return;
                        }
                        if (dgvDIAdd.Rows[i].Cells[5].Value == null)
                        {
                            MessageBox.Show("第" + (i + 1).ToString() + "行的端口状态选择,请检查");
                            return;
                        }
                        if (dgvDIAdd.Rows[i].Cells[4].Value.ToString() == "扩展" &&
                            dgvDIAdd.Rows[i].Cells[6].Value == null)
                        {
                            MessageBox.Show("第" + (i + 1).ToString() + "行的扩展卡号选择,请检查");
                            return;
                        }
                        //检查是否已经存在重复数据
                        Name    = dgvDIAdd.Rows[i].Cells[1].Value.ToString();
                        CardNum = int.Parse(dgvDIAdd.Rows[i].Cells[2].Value.ToString());
                        IoID    = int.Parse(dgvDIAdd.Rows[i].Cells[3].Value.ToString());
                        mIoType = dgvDIAdd.Rows[i].Cells[4].Value.ToString();

                        if (dgvDIAdd.Rows[i].Cells[6].Value == null)
                        {
                            ExtendNum = 0;
                        }
                        else
                        {
                            ExtendNum = int.Parse(dgvDIAdd.Rows[i].Cells[6].Value.ToString());
                        }

                        if (mWDataToolClass.SelectShowDICheck(" Name='" + Name + "' ") == 1)
                        {
                            MessageBox.Show("第" + (i + 1).ToString() + "行的轴名称:" + Name + ";已存在,请检查");
                            return;
                        }
                        if (mIoType == "扩展")
                        {
                            IoType = WUseToolClass.getIoType(mIoType);

                            if (mWDataToolClass.SelectShowDICheck(
                                    " CardNum=" + CardNum.ToString() +
                                    " and IoID=" + IoID.ToString() +
                                    " and IoType=" + IoType.ToString() +
                                    " and ExtendNum=" + ExtendNum.ToString()
                                    ) == 1)
                            {
                                MessageBox.Show("第" + (i + 1).ToString() + "行的卡号、端口号、端口类型和扩展卡号已存在,请检查");
                                return;
                            }
                        }
                        else
                        {
                            IoType = WUseToolClass.getIoType(mIoType);

                            if (mWDataToolClass.SelectShowDICheck(
                                    " CardNum=" + CardNum.ToString() +
                                    " and IoID=" + IoID.ToString() +
                                    " and IoType=" + IoType.ToString()
                                    ) == 1)
                            {
                                MessageBox.Show("第" + (i + 1).ToString() + "行的卡号、端口号和端口类型已存在,请检查");
                                return;
                            }
                        }

                        //增加的数据判断
                        int numRepeatName = 0;
                        int numRepeatCA   = 0;
                        for (int j = 0; j < dgvDIAdd.Rows.Count - 1; j++)
                        {
                            if (i != j)
                            {
                                if (Name == dgvDIAdd.Rows[j].Cells[0].Value.ToString())
                                {
                                    numRepeatName++;
                                }
                                if (mIoType == "扩展")
                                {
                                    if (CardNum == int.Parse(dgvDIAdd.Rows[j].Cells[2].Value.ToString()) &&
                                        IoID == int.Parse(dgvDIAdd.Rows[j].Cells[3].Value.ToString()) &&
                                        IoType == int.Parse(dgvDIAdd.Rows[j].Cells[4].Value.ToString()) &&
                                        ExtendNum == int.Parse(dgvDIAdd.Rows[j].Cells[6].Value.ToString()))
                                    {
                                        numRepeatCA++;
                                    }
                                }
                                else
                                {
                                    if (CardNum == int.Parse(dgvDIAdd.Rows[j].Cells[2].Value.ToString()) &&
                                        IoID == int.Parse(dgvDIAdd.Rows[j].Cells[3].Value.ToString()) &&
                                        IoType == int.Parse(dgvDIAdd.Rows[j].Cells[4].Value.ToString()))
                                    {
                                        numRepeatCA++;
                                    }
                                }
                            }
                        }
                        if (numRepeatName > 0)
                        {
                            MessageBox.Show("第" + (i + 1).ToString() + "行的轴名称有重复,请检查");
                            return;
                        }
                        if (numRepeatCA > 0)
                        {
                            MessageBox.Show("第" + (i + 1).ToString() + "行的卡号、端口号和端口类型(扩展卡号)有重复,请检查");
                            return;
                        }
                    }
                    //把所有数据插入
                    for (int i = 0; i < dgvDIAdd.Rows.Count - 1; i++)
                    {
                        GroupName = dgvDIAdd.Rows[i].Cells[0].Value.ToString();
                        Name      = dgvDIAdd.Rows[i].Cells[1].Value.ToString();
                        CardNum   = int.Parse(dgvDIAdd.Rows[i].Cells[2].Value.ToString());
                        IoID      = int.Parse(dgvDIAdd.Rows[i].Cells[3].Value.ToString());
                        mIoType   = dgvDIAdd.Rows[i].Cells[4].Value.ToString();
                        mIoState  = dgvDIAdd.Rows[i].Cells[5].Value.ToString();
                        if (dgvDIAdd.Rows[i].Cells[6].Value == null)
                        {
                            ExtendNum = 0;
                        }
                        else
                        {
                            ExtendNum = int.Parse(dgvDIAdd.Rows[i].Cells[6].Value.ToString());
                        }

                        IoType  = WUseToolClass.getIoType(mIoType);
                        IoState = WUseToolClass.getIoState(mIoState);

                        if (mWDataToolClass.InsertDI(GroupName, Name, CardNum, IoID, IoType, IoState, ExtendNum) != 0)
                        {
                            MessageBox.Show("第" + (i + 1).ToString() + "行的数据添加失败");
                            return;
                        }
                    }
                    closePanelUI();
                    //刷新轴数据
                    mWDataToolClass.SelectShowDI(ref dgvDI);
                    dgvDIAdd.Rows.Clear();
                    MessageBox.Show("轴数据添加成功");
                }
                else
                {
                    MessageBox.Show("添加的数据为空");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }