UpdateNodeView.xaml.cs
3.17 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using RoboforkApp.Entities;
using RoboforkApp.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace RoboforkApp.View
{
/// <summary>
/// Interaction logic for UpdateNodeView.xaml
/// </summary>
public partial class UpdateNodeView : Window
{
public Robofork15Demo _dataNode;
public UpdateNodeView()
{
InitializeComponent();
}
private void txtSpeed_LostFocus(object sender, RoutedEventArgs e)
{
if (txtSpeed.Text.Trim() == "")
{
txtSpeed.Text = "0";
}
}
private void txtAngle_LostFocus(object sender, RoutedEventArgs e)
{
if (txtAngle.Text.Trim() == "")
{
txtAngle.Text = "0";
}
}
private void txtHight_LostFocus(object sender, RoutedEventArgs e)
{
if (txtHight.Text.Trim() == "")
{
txtHight.Text = "0";
}
}
/// <summary>
/// Process when click button Save or Cancel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnEditNode_Click(object sender, RoutedEventArgs e)
{
string tag = ((Button)sender).Tag.ToString();
switch (tag)
{
case "Cancel":
this.Close();
break;
case "Save":
if (!checkFloat(txtSpeed.Text) || !checkFloat(txtAngle.Text) || !checkFloat(txtHight.Text))
{
MessageBox.Show("Please check input data!");
break;
}
ExecUpdateNode();
this.Close();
break;
default:
break;
}
}
//Check input string is Float format
public bool checkFloat(string st)
{
bool flg = false;
Regex regex = new Regex(@"^[0-9]*(?:\.[0-9]*)?$");
flg = regex.IsMatch(st);
return flg;
}
/// <summary>
/// Process update node
/// </summary>
private void ExecUpdateNode()
{
if (this._dataNode != null)
{
double temp = 0;
Double.TryParse(txtHight.Text, out temp);
this._dataNode.NodeLftHeight = temp;
Double.TryParse(txtSpeed.Text, out temp);
this._dataNode.NodeVehSpd = temp;
Double.TryParse(txtAngle.Text, out temp);
this._dataNode.NodeVehAng = temp;
Robofork15DemoService service = new Robofork15DemoService();
service.ModifyRobofork15Demo(this._dataNode);
}
}
}
}