/// <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; } } }
/// <summary> /// Изменить элемент /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonEdit_Click(object sender, EventArgs e) { if (ElementsProject.Elements.Count == 0) { return; } int index = elementDataGridView.SelectedCells[0].RowIndex; var form = new ElementForm { Element = ElementsProject.Elements[index] }; form.ShowDialog(); var element = form.Element; ElementsProject.Elements.RemoveAt(index); ElementsProject.Elements.Insert(index, element); elementDataGridView.Rows.RemoveAt(index); if (element is Resistor) { elementDataGridView.Rows.Insert(index, element.Name, element.Value, element.GetImpedance(Convert.ToDouble(textBoxAngularFrequency.Text))); } if (element is Inductor) { elementDataGridView.Rows.Insert(index, element.Name, element.Value, element.GetImpedance(Convert.ToDouble(textBoxAngularFrequency.Text))); } if (element is Capacitor) { elementDataGridView.Rows.Insert(index, element.Name, element.Value, element.GetImpedance(Convert.ToDouble(textBoxAngularFrequency.Text))); } _saveFile = true; }