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 { /// /// Interaction logic for UpdateNodeView.xaml /// 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"; } } /// /// Process when click button Save or Cancel /// /// /// 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; } /// /// Process update node /// 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); } } } }