コード例 #1
0
 /// <summary>
 /// Открытие вспомогательной формы и связь по делегату
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AddElementButtonClick(object sender, EventArgs e)
 {
     if (FrequencyTextBox.Text == "" || FrequencyTextBox.Text[0].ToString() == ",")
     {
         var errors = "Frequency wasn't found";
         MessageBox.Show(errors, @"Error!",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     else
     {
         AddElement newForm = new AddElement();
         if (newForm.ShowDialog() == DialogResult.OK)
         {
             try {
                 var component = newForm.Component;
                 Components.Add(component);
                 ComponentsDataGrid.Rows.Add(component.GetImpedance(double.Parse(FrequencyTextBox.Text)));
                 ComponentsDataGrid.Rows[ComponentsDataGrid.Rows.Count - 2].Cells[1].Value = component.Nominal;
             }
             catch (ArgumentException)
             {
                 var errors = "Wrong value!";
                 MessageBox.Show(errors, @"Error!",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// Изменить номинал элемента
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ModifyButton_Click(object sender, EventArgs e)
 {
     if (ComponentsDataGrid.CurrentRow.Cells[0].Value == null)
     {
         var errors = "Nothing to modify";
         MessageBox.Show(errors, @"Error!",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     else
     {
         IComponent.IComponent component = Components[ComponentsDataGrid.CurrentRow.Index];
         AddElement            newForm   = new AddElement();
         newForm.ModifyValue = Convert.ToDouble(ComponentsDataGrid.CurrentRow.Cells[1].Value);
         if (component is Resistor)
         {
             newForm.ResistorModify();
         }
         else if (component is Inductor)
         {
             newForm.InductorModify();
         }
         else
         {
             newForm.CapacitorModify();
         }
         newForm.ShowDialog();
         if (newForm.DialogResult == DialogResult.OK)
         {
             try {
                 component = newForm.Component;
                 ComponentsDataGrid.Rows[ComponentsDataGrid.CurrentRow.Index].Cells[0].Value = component.GetImpedance(double.Parse(FrequencyTextBox.Text));
                 ComponentsDataGrid.Rows[ComponentsDataGrid.CurrentRow.Index].Cells[1].Value = component.Nominal;
             }
             catch (ArgumentException)
             {
                 var errors = "Wrong value!";
                 MessageBox.Show(errors, @"Error!",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
         }
         ;
     }
 }