Пример #1
0
        private void btnAxisModifyOk_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvAxisModify.Rows[0].Cells[0].Value == null)
                {
                    MessageBox.Show("组名不能为空");
                    return;
                }
                String GroupName = dgvAxisModify.Rows[0].Cells[0].Value.ToString();
                if (dgvAxisModify.Rows[0].Cells[1].Value == null)
                {
                    MessageBox.Show("轴名称不能为空");
                    return;
                }
                String Name    = dgvAxisModify.Rows[0].Cells[1].Value.ToString();
                Int32  CardNum = int.Parse(dgvAxisModify.Rows[0].Cells[2].Value.ToString());
                Int32  AxisNum = int.Parse(dgvAxisModify.Rows[0].Cells[3].Value.ToString());
                Int32  Pulse   = 0;
                if (dgvAxisModify.Rows[0].Cells[4].Value == null)
                {
                    Pulse = 1000;
                }
                else
                {
                    if (!int.TryParse(dgvAxisModify.Rows[0].Cells[4].Value.ToString(), out Pulse))
                    {
                        MessageBox.Show("脉冲当量不是整数类型,请检查");
                        return;
                    }
                }
                Int32 Acc = 0;
                if (dgvAxisModify.Rows[0].Cells[5].Value == null)
                {
                    Acc = 100;
                }
                else
                {
                    if (!int.TryParse(dgvAxisModify.Rows[0].Cells[5].Value.ToString(), out Acc))
                    {
                        MessageBox.Show("加速度不是整数类型,请检查");
                        return;
                    }
                }
                Int32 Speed = 0;
                if (dgvAxisModify.Rows[0].Cells[6].Value == null)
                {
                    Speed = 10;
                }
                else
                {
                    if (!int.TryParse(dgvAxisModify.Rows[0].Cells[6].Value.ToString(), out Speed))
                    {
                        MessageBox.Show("速度不是整数类型,请检查");
                        return;
                    }
                }
                Int32  ResetNum    = int.Parse(dgvAxisModify.Rows[0].Cells[7].Value.ToString());
                int    isModifyNum = 0;
                int    mIndex      = dgvAxis.CurrentRow.Index;
                String oldName     = dgvAxis.Rows[mIndex].Cells[1].Value.ToString();
                if (Name != oldName)
                {
                    if (mWDataToolClass.SelectShowAxisCheck(" Name='" + Name + "'") == 1)
                    {
                        MessageBox.Show("轴名称已存在,请检查");
                        return;
                    }
                }
                else
                {
                    isModifyNum++;
                }

                if (CardNum == int.Parse(dgvAxis.Rows[mIndex].Cells[2].Value.ToString()) &&
                    AxisNum == int.Parse(dgvAxis.Rows[mIndex].Cells[3].Value.ToString()))
                {
                    isModifyNum++;
                }
                else
                {
                    if (mWDataToolClass.SelectShowAxisCheck(" CardNum=" + CardNum + " And AxisNum=" + AxisNum) == 1)
                    {
                        MessageBox.Show("卡号和轴号已存在,请检查");
                        return;
                    }
                }
                if (Pulse == int.Parse(dgvAxis.Rows[mIndex].Cells[4].Value.ToString()) &&
                    GroupName == dgvAxis.Rows[0].Cells[0].Value.ToString() &&
                    Acc == int.Parse(dgvAxis.Rows[mIndex].Cells[5].Value.ToString()) &&
                    Speed == int.Parse(dgvAxis.Rows[mIndex].Cells[6].Value.ToString()) &&
                    ResetNum == int.Parse(dgvAxis.Rows[mIndex].Cells[7].Value.ToString()))
                {
                    isModifyNum++;
                }
                if (isModifyNum == 3)
                {
                    MessageBox.Show("当前数据未有改动");
                    return;
                }
                if (mWDataToolClass.UpdateAxis(oldName, GroupName, Name, CardNum, AxisNum, Pulse, Acc, Speed, ResetNum) != 0)
                {
                    MessageBox.Show("轴数据修改失败");
                    return;
                }
                //刷新轴数据
                mWDataToolClass.SelectShowAxis(ref dgvAxis);
            }
            catch (Exception ex)
            {
                MessageBox.Show("轴数据修改出异常" + ex.ToString());
            }
            dgvAxisModify.Rows.Clear();
            closePanelUI();
            MessageBox.Show("轴数据修改成功");
        }