Exemple #1
0
        /// <summary>
        /// 开始编辑/保存通道名称
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolStripMenuItemEditSave_Click(object sender, EventArgs e)
        {
            DevNodeInfo nodeInfo = tvDevs.SelectedNode.Tag as DevNodeInfo;

            if (!isChannelNameEditting) //开始编辑
            {
                isChannelNameEditting = true;
                if (nodeInfo.Categoty == DevNodeCategory.DioModule)
                {
                    ucDioNames.BeginEdit();
                }
                else if (nodeInfo.Categoty == DevNodeCategory.MotionModule)
                {
                    ucAxisNames.BeginEdit();
                }
                else if (nodeInfo.Categoty == DevNodeCategory.CmpTrigModule)
                {
                    ucCmpTrigNames.BeginEdit();
                }
                else if (nodeInfo.Categoty == DevNodeCategory.AioModule)
                {
                    ucAioNames.BeginEdit();
                }
                else if (nodeInfo.Categoty == DevNodeCategory.TrigCtrlDev) //编辑触发控制器通道名称
                {
                    ucTrigCtrlNames.BeginEdit();
                }
                else if (nodeInfo.Categoty == DevNodeCategory.LightCtrlTDev)
                {
                    ucLightCtrlNames.BeginEdit();
                }
                ToolStripMenuItemEditSave.Text      = "保存名称";
                ToolStripMenuItemEditCancel.Enabled = true;
                tvDevs.Enabled = false;
            }
            else //尝试保存并结束编辑状态
            {
                JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr;
                string errInfo           = "";
                if (nodeInfo.Categoty == DevNodeCategory.DioModule)
                {
                    string[] diNames = ucDioNames.DiNames;
                    string[] doNames = ucDioNames.DoNames;
                    if (!mgr.SetDiNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucDioNames.DiNames, out errInfo))
                    {
                        MessageBox.Show("设置DI通道名称失败,错误信息:\n" + errInfo);
                        return;
                    }
                    if (!mgr.SetDoNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucDioNames.DoNames, out errInfo))
                    {
                        MessageBox.Show("设置DO通道名称失败,错误信息:\n" + errInfo);
                        return;
                    }
                    ucDioNames.EndEdit();
                    MessageBox.Show("设置DIO通道名称OK");
                }
                else if (nodeInfo.Categoty == DevNodeCategory.MotionModule)
                {
                    if (!mgr.SetAxisNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucAxisNames.AxisNames, out errInfo))
                    {
                        MessageBox.Show("设置轴通道名称失败,错误信息:\n" + errInfo);
                        return;
                    }
                    ucAxisNames.EndEdit();
                    MessageBox.Show("设置轴通道名称OK");
                }
                else if (nodeInfo.Categoty == DevNodeCategory.CmpTrigModule)
                {
                    if (!mgr.SetCmpTrigNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucCmpTrigNames.TrigNames, out errInfo))
                    {
                        MessageBox.Show("设置比较触发通道名称失败,错误信息:\n" + errInfo);
                        return;
                    }
                    ucCmpTrigNames.EndEdit();
                    MessageBox.Show("设置比较触发通道名称OK");
                }
                else if (nodeInfo.Categoty == DevNodeCategory.AioModule)
                {
                    if (!mgr.SetAiNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucAioNames.AiNames, out errInfo))
                    {
                        MessageBox.Show("设置AI通道名称失败,错误信息:\n" + errInfo);
                        return;
                    }
                    if (!mgr.SetAoNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucAioNames.AoNames, out errInfo))
                    {
                        MessageBox.Show("设置AO通道名称失败,错误信息:\n" + errInfo);
                        return;
                    }
                    ucAioNames.EndEdit();
                    MessageBox.Show("设置AIO通道名称OK");
                }
                else if (nodeInfo.Categoty == DevNodeCategory.TrigCtrlDev)
                {
                    //ucTrigCtrlNames.
                    if (!mgr.SetTrigCtrlChannelNames(nodeInfo.DevID, ucTrigCtrlNames.ChannelNames(), out errInfo))
                    {
                        MessageBox.Show("设置触发控制器通道名称失败,错误信息:\n" + errInfo);
                        ucTrigCtrlNames.UpdateChannelsInfo(nodeInfo.DevID);
                        return;
                    }
                    ucTrigCtrlNames.EndEdit();
                }
                else if (nodeInfo.Categoty == DevNodeCategory.LightCtrlTDev)
                {
                    if (!mgr.SetLightCtrlChannelNames(nodeInfo.DevID, ucLightCtrlNames.LightChannelNames(), out errInfo))
                    {
                        MessageBox.Show("设置触发控制器通道名称失败,错误信息:\n" + errInfo);
                        ucLightCtrlNames.UpdateChannelsInfo(nodeInfo.DevID);
                        return;
                    }
                    string[] trigChannelNames = ucLightCtrlNames.TrigChannelNames();
                    if (null == trigChannelNames || 0 == trigChannelNames.Length)
                    {
                        mgr.RemoveLightCtrlDev(nodeInfo.DevID);
                    }
                    else
                    {
                        if (!mgr.SetTrigCtrlChannelNames(nodeInfo.DevID, ucLightCtrlNames.TrigChannelNames(), out errInfo))
                        {
                            MessageBox.Show("设置触发控制器通道名称失败,错误信息:\n" + errInfo);
                            ucLightCtrlNames.UpdateChannelsInfo(nodeInfo.DevID);
                            return;
                        }
                    }

                    ucLightCtrlNames.EndEdit();
                    //if (!mgr.SetLightCtrlChannelNames(nodeInfo.DevID, ucTrigCtrlNames.ChannelNames(), out errInfo))
                    //{
                    //    MessageBox.Show("设置触发控制器通道名称失败,错误信息:\n" + errInfo);
                    //    ucTrigCtrlNames.UpdateChannelsInfo(nodeInfo.DevID);
                    //    return;
                    //}
                }
                ToolStripMenuItemEditSave.Text      = "编辑名称";
                ToolStripMenuItemEditCancel.Enabled = true;
                isChannelNameEditting = false;
                tvDevs.Enabled        = true;
            }
        }