示例#1
0
        private void add()
        {
            TreeNode tn = m_PNavigator.cn_TreeView.SelectedNode;

            if (tn == null)
            {
                return;
            }
            IAction currAct = (IAction)m_PNavigator.cn_TreeView.SelectedNode.Tag;

            if (!currAct.CanCreateChild)
            {
                return;
            }
            if (currAct is SegmentsRowWrapper)
            {
                IAction newAct = currAct.CreateNewChildObject();
                AddInterfaceAndStation fm_AddInterface = new AddInterfaceAndStation(m_configDataBase, newAct);
                if (fm_AddInterface.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }
            }
            else
            {
#if UNDOREDO
                RTLib.DataBase.UndoRedo.UndoRedoMenager.BeginTransaction();
#endif
                try
                {
                    if (!m_configDataBase.EnforceConstraints)
                    {
                        MessageBox.Show(Resources.tx_configDataBaseEnforceConstraints_false, Resources.tx_configtreeview_error_messagebox_title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    m_configDataBase.AcceptChanges();
                    m_configDataBase.EnforceConstraints = false;
#if UNDOREDO
                    RTLib.DataBase.UndoRedo.UndoRedoMenager.BeginTransaction();
#endif
                    IAction             newAct    = currAct.CreateNewChildObject();
                    AddObject <IAction> fm_AddObj = new AddObject <IAction>
                    {
                        Text   = "Add new object for: " + currAct,
                        Object = newAct
                    };
                    bool ok;
                    do
                    {
                        ok = true;
                        if (fm_AddObj.ShowDialog(this) != DialogResult.OK)
                        {
                            //deleteLastTransaction();
                            newAct.AddUnfinishedCleanup();
                            break;
                        }
                        try { newAct.AddObjectToTable(); }
                        catch (Exception ex)
                        {
                            MessageBox.Show
                                ("I cannot add new object to the configuration because: " + ex.Message,
                                Resources.tx_configtreeview_error_messagebox_title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            ok = false;
                        }
                    }while (!ok);
#if UNDOREDO
                    RTLib.DataBase.UndoRedo.UndoRedoMenager.EndTransaction();
#endif
                    try { m_configDataBase.EnforceConstraints = true; }
                    catch (Exception ex)
                    {
                        MessageBox.Show
                            ("I cannot add new object to the configuration because: " + ex.Message,
                            Resources.tx_configtreeview_error_messagebox_title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        m_configDataBase.RejectChanges();
                        m_configDataBase.EnforceConstraints = true;
                    }
                }
                catch (CreateChildObjectException ex)
                {
                    MessageBox.Show(ex.Message, Resources.tx_configtreeview_error_messagebox_title, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("I cannot add new object to the configuration becase: " + ex.Message, Resources.tx_configtreeview_error_messagebox_title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
#if UNDOREDO
                    RTLib.DataBase.UndoRedo.UndoRedoMenager.EndTransaction();
#endif
                    m_configDataBase.EnforceConstraints = true;
                }
            }
            ((IAction)m_PNavigator.cn_TreeView.SelectedNode.Tag).CreateNodes();
            //m_PNavigator.cn_TreeView.SelectedNode =
            tn.Expand();
            UpdateTagNumberInfo();
        }
 public void Refresh(ComunicationNet myConfig)
 {
     myConfig.AcceptChanges();
     TreeBuilder.CreateTree(myConfig, cn_TreeView);
     base.Refresh();
 }