Esempio n. 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;
        }
Esempio n. 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;
        }
Esempio n. 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;
        }
Esempio n. 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;
 }
Esempio n. 5
0
        /// <summary>
        /// Новый список
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ElementsProject.Elements.Count == 0)
            {
                var saveFileDialog = new SaveFileDialog();
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    _fileName = saveFileDialog.FileName;
                    Text      = _fileName.Substring(_fileName.LastIndexOf("\\") + 1) + @" - SPO Laboratory Works";
                }
                else
                {
                    return;
                }
                return;
            }
            var resultNewElement = MessageBox.Show(@"Do you want to save this file?", @"New file",
                                                   MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            switch (resultNewElement)
            {
            case DialogResult.Yes:
            {
                ElementsProject.AngularFrequency = Convert.ToDouble(textBoxAngularFrequency.Text);
                ElementsProject.FileName         = _fileName;
                _serializeElement.Serilization(ElementsProject);
                ElementsProject.Elements.Clear();
                elementDataGridView.Rows.Clear();
                textBoxAngularFrequency.Text = "";
                _fileName = "C:\\Users\\User\\Documents\\New List";
                Text      = FileNameGenerate.GenerateFileName(_fileName);
                break;
            }

            case DialogResult.No:
            {
                ElementsProject.Elements.Clear();
                elementDataGridView.Rows.Clear();
                textBoxAngularFrequency.Text = "";
                _fileName = "C:\\Users\\User\\Documents\\New List";
                Text      = FileNameGenerate.GenerateFileName(_fileName);
                break;
            }

            case DialogResult.Abort:
            {
                break;
            }
            }
            _saveFile = false;
        }
Esempio n. 6
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;
                }
            }
        }
Esempio n. 7
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;
        }
Esempio n. 8
0
        /// <summary>
        /// Главная форма
        /// </summary>
        public ElementListForm(string[] args)
        {
            InitializeComponent();

            if (args.Length > 0)
            {
                using (var fs = new FileStream(args[0], FileMode.OpenOrCreate))
                {
                    var elementsProject = (ElementsProject)formatter.Deserialize(fs);

                    ElementsProject = elementsProject;

                    textBoxAngularFrequency.Text = ElementsProject.AngularFrequency.ToString();
                    _fileName = ElementsProject.FileName;
                    Text      = _fileName.Substring(_fileName.LastIndexOf("\\") + 1) + @" - SPO Laboratory Works";

                    for (int i = 0; i < ElementsProject.Elements.Count; i++)
                    {
                        elementDataGridView.Rows.Add(ElementsProject.Elements[i].Name, ElementsProject.Elements[i].Value,
                                                     ElementsProject.Elements[i].GetImpedance(Convert.ToDouble(textBoxAngularFrequency.Text)));
                    }
                }
            }


            Text      = _fileName;
            _elements = new List <IElement>();
#if !DEBUG
            buttonRandom.Visible = false;
#endif
            Text                             = FileNameGenerate.GenerateFileName(_fileName);
            ElementsProject                  = new ElementsProject();
            ElementsProject.Elements         = _elements;
            ElementsProject.AngularFrequency = Convert.ToDouble(textBoxAngularFrequency.Text);
            ElementsProject.FileName         = _fileName;
        }