Beispiel #1
0
        /// <summary>
        /// Добавление случайного элемента
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonRandom_Click(object sender, EventArgs e)
        {
            try
            {
                var newRandomElements = RandomElementGenerate.CreateRandomElement();
                ElementsProject.Elements.Add(newRandomElements);

                if (newRandomElements is Resistor)
                {
                    newRandomElements.Name = ElementNameGenerate.GenerateNameResistor();
                    elementDataGridView.Rows.Add(newRandomElements.Name, newRandomElements.Value,
                                                 newRandomElements.GetImpedance(Convert.ToDouble(textBoxAngularFrequency.Text)));
                }
                if (newRandomElements is Inductor)
                {
                    newRandomElements.Name = ElementNameGenerate.GenerateNameInductor();
                    elementDataGridView.Rows.Add(newRandomElements.Name, newRandomElements.Value,
                                                 newRandomElements.GetImpedance(Convert.ToDouble(textBoxAngularFrequency.Text)));
                }
                if (newRandomElements is Capacitor)
                {
                    newRandomElements.Name = ElementNameGenerate.GenerateNameCapacitor();
                    elementDataGridView.Rows.Add(newRandomElements.Name, newRandomElements.Value,
                                                 newRandomElements.GetImpedance(Convert.ToDouble(textBoxAngularFrequency.Text)));
                }

                this.Text = FileNameGenerate.AsteriskChange(true, _fileName);
            }
            catch (FormatException)
            {
                MessageBox.Show(@"Angular frequency must be more than zero");
            }
            _saveFile = true;
        }
Beispiel #2
0
        /// <summary>
        /// Пересчитать угловую частоту
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonCalculate_Click(object sender, EventArgs e)
        {
            if (textBoxAngularFrequency.TextLength == 0)
            {
                MessageBox.Show(@"The angular frequency must not be empty");
                return;
            }

            try
            {
                double angular = Convert.ToDouble(textBoxAngularFrequency.Text);

                for (int i = 0; i < ElementsProject.Elements.Count; i++)
                {
                    elementDataGridView.Rows[i].Cells[2].Value =
                        ElementsProject.Elements[i].GetImpedance(Convert.ToDouble((angular)));
                }
                Text = FileNameGenerate.AsteriskChange(true, _fileName);
            }
            catch (FormatException)
            {
                MessageBox.Show(@"Wrong format frequency");
            }
            _saveFile = true;
        }
Beispiel #3
0
        /// <summary>
        /// Удалить элемент
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonRemove_Click(object sender, EventArgs e)
        {
            if (ElementsProject.Elements.Count == 0)
            {
                return;
            }
            var resultRemove = MessageBox.Show(@"Are you sure you want to delete this element?",
                                               @"Remove",
                                               MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            switch (resultRemove)
            {
            case DialogResult.Yes:
            {
                int index = elementDataGridView.SelectedCells[0].RowIndex;
                elementDataGridView.Rows.RemoveAt(index);
                ElementsProject.Elements.RemoveAt(index);
                break;
            }

            case DialogResult.No:
            {
                return;
            }
            }
            Text      = FileNameGenerate.AsteriskChange(true, _fileName);;
            _saveFile = true;
        }
Beispiel #4
0
 /// <summary>
 /// Сериализация
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     ElementsProject.FileName         = _fileName;
     ElementsProject.AngularFrequency = Convert.ToDouble(textBoxAngularFrequency.Text);
     _serializeElement.Serilization(ElementsProject);
     Text      = FileNameGenerate.AsteriskChange(false, _fileName);
     _saveFile = false;
 }
Beispiel #5
0
        /// <summary>
        /// Добавить элемент
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            if (textBoxAngularFrequency.TextLength == 0)
            {
                MessageBox.Show(@"The angular fequency must not be empty");
                return;
            }
            double angular = Convert.ToDouble(textBoxAngularFrequency.Text);

            if (angular != 0)
            {
                var form = new ElementForm();
                if (form.ShowDialog() == DialogResult.OK)
                {
                    var element = form.Element;
                    if (element == null)
                    {
                        return;
                    }
                    ElementsProject.Elements.Add(element);

                    if (element is Resistor)
                    {
                        elementDataGridView.Rows.Add(element.Name, element.Value,
                                                     element.GetImpedance(Convert.ToDouble(textBoxAngularFrequency.Text)));
                    }
                    if (element is Inductor)
                    {
                        elementDataGridView.Rows.Add(element.Name, element.Value,
                                                     element.GetImpedance(Convert.ToDouble(textBoxAngularFrequency.Text)));
                    }
                    if (element is Capacitor)
                    {
                        elementDataGridView.Rows.Add(element.Name, element.Value,
                                                     element.GetImpedance(Convert.ToDouble(textBoxAngularFrequency.Text)));
                    }
                    Text      = FileNameGenerate.AsteriskChange(true, _fileName);
                    _saveFile = true;
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Сохранить как
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = @"txt files (*.el)|*.el";
            saveFileDialog.RestoreDirectory = true;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                _fileName = saveFileDialog.FileName;
                Text      = _fileName.Substring(_fileName.LastIndexOf("\\") + 1) + @" - SPO Laboratory Works";
            }
            else
            {
                return;
            }
            ElementsProject.AngularFrequency = Convert.ToDouble(textBoxAngularFrequency.Text);
            ElementsProject.FileName         = _fileName;
            _serializeElement.Serilization(ElementsProject);
            Text      = FileNameGenerate.AsteriskChange(false, _fileName);
            _saveFile = false;
        }