예제 #1
0
        private void btnDeleteNode_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("This action will delete the table from the metadata and data. Are you sure? ", "Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                PxMenuSelection selectedMenu = (PxMenuSelection)tvMenuSelection.SelectedNode.Tag;
                int             levelNo;
                int.TryParse(selectedMenu.LevelNo, out levelNo);
                if (levelNo < 5)
                {
                    //check if node has a table
                    if (tvMenuSelection.SelectedNode.Nodes.Count > 0)
                    {
                        MessageBox.Show("Could not delete this node it has subnodes, delete those first!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        string msg = "";
                        if (VariableFacade.Delete(selectedMenu, ref msg))
                        {
                            MessageBox.Show("The node was deleted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                //the node is a table
                else
                {
                    string      msg  = "";
                    string      msg2 = "";
                    string      msg3 = "";
                    PxMainTable mt   = VariableFacade.GetMainTableById(selectedMenu.Menu);

                    if (VariableFacade.Delete(mt, ref msg))
                    {
                        if (VariableFacade.Delete(selectedMenu, ref msg2))
                        {
                            if (mt != null)
                            {
                                if (VariableFacade.DeleteDataTable(mt.TableId, ref msg3))
                                {
                                    MessageBox.Show("The table was deleted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    MessageBox.Show(msg3, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                if (VariableFacade.DeleteDataTable(selectedMenu.Menu, ref msg3))
                                {
                                    MessageBox.Show("The table was deleted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    MessageBox.Show(msg3, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show(msg2, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }

                    else
                    {
                        MessageBox.Show(msg + "\n\n" + msg2 + "\n\n" + msg3, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }