Exemple #1
0
 private void addOrEdit_Click(object sender, EventArgs e)
 {
     if (addOrEdit.Text == EDIT)
     {
         if (Mode == BALL_GAME)
         {
             if ((Double.TryParse(minTextBox.Text, out double min)) && (Double.TryParse(minTextBox.Text, out double max)))
             {
                 if ((min > 0) && (max > 0))
                 {
                     object requestedObject = null;
                     foreach (object o in KindsOfSport)
                     {
                         if ((o is BallGame) && ((o as BallGame).Name == SelectedName))
                         {
                             requestedObject = o;
                             break;
                         }
                     }
                     if ((Unique(namesTextBox.Text)) || (namesTextBox.Text == SelectedName))
                     {
                         BallGame ballGame = requestedObject as BallGame;
                         ballGame.Name          = namesTextBox.Text;
                         ballGame.MinDiameterCM = min;
                         ballGame.MaxDiameterCM = max;
                         ballGame.FaceToFace    = faceToFaceCheckBox.Checked;
                         CompetitionsEdit(ballGame);
                         NodesNameChange(treeOfSport.Nodes[0].Nodes[1].Nodes[0], SelectedName, namesTextBox.Text);
                         SelectedName = namesTextBox.Text;
                     }
                     else
                     {
                         MessageBox.Show(ERR_NOTATION, ERR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                 }
                 else
                 {
                     MessageBox.Show(ERR_NOTATION, ERR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else
             {
                 MessageBox.Show(ERR_NOTATION, ERR, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else if (Mode == MIND_SPORT)
         {
             object requestedObject = null;
             foreach (object o in KindsOfSport)
             {
                 if ((o is MindSport) && ((o as MindSport).Name == SelectedName))
                 {
                     requestedObject = o;
                     break;
                 }
             }
             if ((Unique(namesTextBox.Text)) || (namesTextBox.Text == SelectedName))
             {
                 MindSport mindSport = requestedObject as MindSport;
                 mindSport.Name       = namesTextBox.Text;
                 mindSport.FaceToFace = faceToFaceCheckBox.Checked;
                 CompetitionsEdit(mindSport);
                 treeOfSport.SelectedNode.Name = namesTextBox.Text;
                 NodesNameChange(treeOfSport.Nodes[0].Nodes[0], SelectedName, namesTextBox.Text);
                 SelectedName = namesTextBox.Text;
             }
             else
             {
                 MessageBox.Show(ERR_NOTATION, ERR, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else if (Mode == FIGHT)
         {
             object requestedObject = null;
             foreach (object o in KindsOfSport)
             {
                 if ((o is Fight) && ((o as Fight).Name == SelectedName))
                 {
                     requestedObject = o;
                     break;
                 }
             }
             if ((Unique(namesTextBox.Text)) || (namesTextBox.Text == SelectedName))
             {
                 Fight fight = requestedObject as Fight;
                 fight.Name       = namesTextBox.Text;
                 fight.FaceToFace = faceToFaceCheckBox.Checked;
                 fight.WithGloves = glovesCheckBox.Checked;
                 CompetitionsEdit(fight);
                 treeOfSport.SelectedNode.Name = namesTextBox.Text;
                 NodesNameChange(treeOfSport.Nodes[0].Nodes[1].Nodes[1], SelectedName, namesTextBox.Text);
                 SelectedName = namesTextBox.Text;
             }
             else
             {
                 MessageBox.Show(ERR_NOTATION, ERR, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             object requestedObject = null;
             foreach (object o in KindsOfSport)
             {
                 if ((o is OtherBodySport) && ((o as OtherBodySport).Name == SelectedName))
                 {
                     requestedObject = o;
                     break;
                 }
             }
             if ((Unique(namesTextBox.Text)) || (namesTextBox.Text == SelectedName))
             {
                 OtherBodySport otherBodySport = requestedObject as OtherBodySport;
                 otherBodySport.Name       = namesTextBox.Text;
                 otherBodySport.FaceToFace = faceToFaceCheckBox.Checked;
                 CompetitionsEdit(otherBodySport);
                 treeOfSport.SelectedNode.Name = namesTextBox.Text;
                 NodesNameChange(treeOfSport.Nodes[0].Nodes[1].Nodes[2], SelectedName, namesTextBox.Text);
                 SelectedName = namesTextBox.Text;
             }
             else
             {
                 MessageBox.Show(ERR_NOTATION, ERR, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
Exemple #2
0
        private void TreeOfSport_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode selectedNode = treeOfSport.SelectedNode;

            if ((selectedNode.Text == KIND_OF_SPORT) || (selectedNode.Text == BODY_SPORT))
            {
                ConstructorsСleaning();
                Mode = NOTHING;
            }
            else if (selectedNode.Text == BALL_GAME)
            {
                ConstructorsСleaning();
                namesLabel.Enabled          = true;
                namesTextBox.Enabled        = true;
                faceToFaceCheckBox.Enabled  = true;
                competitionsLabel.Enabled   = true;
                competitionsListBox.Enabled = true;
                min.Enabled        = true;
                minTextBox.Enabled = true;
                max.Enabled        = true;
                maxTextBox.Enabled = true;
                addOrEdit.Visible  = true;
                addOrEdit.Text     = ADD;
                Mode = BALL_GAME;
            }
            else if (selectedNode.Text == MIND_SPORT)
            {
                ConstructorsСleaning();
                namesTextBox.Enabled        = true;
                faceToFaceCheckBox.Enabled  = true;
                competitionsLabel.Enabled   = true;
                competitionsListBox.Enabled = true;
                glovesCheckBox.Enabled      = false;
                addOrEdit.Visible           = true;
                addOrEdit.Text = ADD;
                Mode           = MIND_SPORT;
            }
            else if (selectedNode.Text == FIGHT)
            {
                ConstructorsСleaning();
                namesLabel.Enabled          = true;
                namesTextBox.Enabled        = true;
                faceToFaceCheckBox.Enabled  = true;
                competitionsLabel.Enabled   = true;
                competitionsListBox.Enabled = true;
                glovesCheckBox.Enabled      = true;
                addOrEdit.Visible           = true;
                addOrEdit.Text = ADD;
                Mode           = FIGHT;
            }
            else if (selectedNode.Text == OTHER_BODY_SPORT)
            {
                ConstructorsСleaning();
                namesLabel.Enabled          = true;
                namesTextBox.Enabled        = true;
                faceToFaceCheckBox.Enabled  = true;
                competitionsLabel.Enabled   = true;
                competitionsListBox.Enabled = true;
                addOrEdit.Visible           = true;
                addOrEdit.Text = ADD;
                Mode           = OTHER_BODY_SPORT;
            }
            else
            {
                TreeNode prevNode = treeOfSport.SelectedNode.Parent;
                if (prevNode.Text == BALL_GAME)
                {
                    ConstructorsСleaning();
                    object requestedObject = null;
                    foreach (object o in KindsOfSport)
                    {
                        if ((o is BallGame) && ((o as BallGame).Name == selectedNode.Text))
                        {
                            requestedObject = o;
                            break;
                        }
                    }
                    BallGame ballGame = requestedObject as BallGame;
                    namesLabel.Enabled          = true;
                    namesTextBox.Enabled        = true;
                    namesTextBox.Text           = ballGame.Name;
                    faceToFaceCheckBox.Enabled  = true;
                    faceToFaceCheckBox.Checked  = ballGame.FaceToFace;
                    competitionsLabel.Enabled   = true;
                    competitionsListBox.Enabled = true;
                    min.Enabled        = true;
                    minTextBox.Enabled = true;
                    minTextBox.Text    = ballGame.MinDiameterCM.ToString();
                    max.Enabled        = true;
                    maxTextBox.Enabled = true;
                    maxTextBox.Text    = ballGame.MaxDiameterCM.ToString();
                    addOrEdit.Visible  = true;
                    addOrEdit.Text     = EDIT;
                    CompetitionsOutput(ballGame);
                    Mode         = BALL_GAME;
                    SelectedName = namesTextBox.Text;
                }
                else if (prevNode.Text == MIND_SPORT)
                {
                    ConstructorsСleaning();
                    object requestedObject = null;
                    foreach (var o in KindsOfSport)
                    {
                        if ((o is MindSport) && ((o as MindSport).Name == selectedNode.Text))
                        {
                            requestedObject = o;
                            break;
                        }
                    }
                    MindSport mindSport = requestedObject as MindSport;
                    namesLabel.Enabled          = true;
                    namesTextBox.Enabled        = true;
                    namesTextBox.Text           = mindSport.Name;
                    faceToFaceCheckBox.Enabled  = true;
                    faceToFaceCheckBox.Checked  = mindSport.FaceToFace;
                    competitionsLabel.Enabled   = true;
                    competitionsListBox.Enabled = true;
                    addOrEdit.Visible           = true;
                    addOrEdit.Text = EDIT;
                    CompetitionsOutput(mindSport);
                    Mode         = MIND_SPORT;
                    SelectedName = namesTextBox.Text;
                }
                else if (prevNode.Text == FIGHT)
                {
                    ConstructorsСleaning();
                    object requestedObject = null;
                    foreach (object o in KindsOfSport)
                    {
                        if ((o is Fight) && ((o as Fight).Name == selectedNode.Text))
                        {
                            requestedObject = o;
                            break;
                        }
                    }
                    Fight fight = requestedObject as Fight;
                    namesLabel.Enabled          = true;
                    namesTextBox.Enabled        = true;
                    namesTextBox.Text           = fight.Name;
                    faceToFaceCheckBox.Enabled  = true;
                    faceToFaceCheckBox.Checked  = fight.FaceToFace;
                    competitionsLabel.Enabled   = true;
                    competitionsListBox.Enabled = true;
                    glovesCheckBox.Enabled      = true;
                    glovesCheckBox.Checked      = fight.WithGloves;
                    addOrEdit.Visible           = true;
                    addOrEdit.Text = EDIT;
                    CompetitionsOutput(fight);
                    Mode         = FIGHT;
                    SelectedName = namesTextBox.Text;
                }
                else
                {
                    ConstructorsСleaning();
                    object requestedObject = null;
                    foreach (var o in KindsOfSport)
                    {
                        if ((o is OtherBodySport) && ((o as OtherBodySport).Name == selectedNode.Text))
                        {
                            requestedObject = o;
                            break;
                        }
                    }
                    OtherBodySport otherBodySport = requestedObject as OtherBodySport;
                    namesLabel.Enabled          = true;
                    namesTextBox.Enabled        = true;
                    namesTextBox.Text           = otherBodySport.Name;
                    faceToFaceCheckBox.Enabled  = true;
                    faceToFaceCheckBox.Checked  = otherBodySport.FaceToFace;
                    competitionsLabel.Enabled   = true;
                    competitionsListBox.Enabled = true;
                    addOrEdit.Visible           = true;
                    addOrEdit.Text = EDIT;
                    CompetitionsOutput(otherBodySport);
                    Mode         = OTHER_BODY_SPORT;
                    SelectedName = namesTextBox.Text;
                }
            }
        }