Ejemplo n.º 1
0
        private static Cone CreateCone(ElementsCollections elementsCollections)
        {
            try
            {
                double radius  = 0;
                double hight   = 0;
                double density = 0;

                if (IsRightData(elementsCollections) != false)
                {
                    for (int i = 0; i < elementsCollections.TextBoxes.Capacity - 1; i++)
                    {
                        var textbox = (TextBox)elementsCollections.TextBoxes[i];
                        if (textbox.Name == "Radius")
                        {
                            radius = double.Parse(textbox.Text);
                        }
                        else if (textbox.Name == "Hight")
                        {
                            hight = double.Parse(textbox.Text);
                        }
                        else
                        {
                            density = double.Parse(textbox.Text);
                        }
                    }
                    return(new Cone(hight, radius, density));
                }
            }
            catch
            {
            }
            return(null);
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            ElementsCollections elementsCollection = new ElementsCollections(GridName.Children);

            AppLogic.AddEvent(elementsCollection);
        }
Ejemplo n.º 3
0
 public static void AddEvent(ElementsCollections elementsCollections)
 {
     for (int i = 0; i < elementsCollections.LogicElements.Capacity - 1; i++)
     {
         if (elementsCollections.LogicElements[i].GetType() == new Button().GetType())
         {
             var button = (Button)elementsCollections.LogicElements[i];
             button.Click += (somthing, args) => { ReturnResult(elementsCollections); };
             elementsCollections.LogicElements[i] = button;
         }
     }
 }
Ejemplo n.º 4
0
 private static bool IsRightData(ElementsCollections elementsCollections)
 {
     try
     {
         for (int i = 0; i < elementsCollections.TextBoxes.Capacity - 1;)
         {
             var textbox = (TextBox)elementsCollections.TextBoxes[i];
             if (textbox.Text != "")
             {
                 i++;
             }
             else
             {
                 throw new Exception();
             }
         }
     }
     catch
     {
         MessageBox.Show("Неккоректно введены данные");
     }
     return(true);
 }
Ejemplo n.º 5
0
        private static void ReturnResult(ElementsCollections elementsCollections)
        {
            var cone = CreateCone(elementsCollections);

            try
            {
                for (int i = 0; i < elementsCollections.LogicElements.Capacity - 1; i++)
                {
                    if (elementsCollections.LogicElements[i].GetType() == new CheckBox().GetType())
                    {
                        var checktbox = (CheckBox)elementsCollections.LogicElements[i];
                        if (checktbox.IsChecked != false)
                        {
                            if (checktbox.Name == "Mass" && cone != null)
                            {
                                MessageBox.Show(cone.GetMass().ToString());
                                break;
                            }
                            else if (checktbox.Name == "Volume" && cone != null)
                            {
                                MessageBox.Show(cone.GetVolume().ToString());
                                break;
                            }
                            else
                            {
                                throw new Exception("No data");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }