-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddComponentDialog.xaml.cs
More file actions
88 lines (74 loc) · 2.47 KB
/
Copy pathAddComponentDialog.xaml.cs
File metadata and controls
88 lines (74 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using CircuitPro.CircuitModel;
namespace CircuitPro
{
/// <summary>
/// Interaction logic for AddComponentDialog.xaml
/// </summary>
public partial class AddComponentDialog : Window
{
public AddComponentDialog()
{
InitializeComponent();
}
private void TipComponenCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (LabelValoare == null)
return;
switch(TipComponenCombo.SelectedIndex)
{
case 0:
LabelValoare.Text = "Rezistență";
UnitateMasura.Text = "Ω";
break;
case 1:
LabelValoare.Text = "Capacitate";
UnitateMasura.Text = "1/π F";
break;
case 2:
LabelValoare.Text = "Inductanță";
UnitateMasura.Text = "1/π H";
break;
}
}
private void OkButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
public TipComponent Tip => TipComponenCombo.SelectedIndex switch
{
0 => TipComponent.REZISTENTA,
1 => TipComponent.CONDENSATOR,
2 => TipComponent.BOBINA,
_ => TipComponent.REZISTENTA,
};
public string Nume => NumeComponentText.Text.Trim();
public double Valoare => ValoareComponentText.Text != "" ? double.Parse(ValoareComponentText.Text) : 0;
private void ValoareComponentText_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
Regex regex = new Regex("[^0-9.]+");
e.Handled = regex.IsMatch(e.Text);
}
private void NumeComponentText_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
Regex regex = new Regex(@"[^\w]+");
e.Handled = regex.IsMatch(e.Text);
}
private void TextInput_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space)
{
e.Handled = true;
}
base.OnPreviewKeyDown(e);
}
}
}