using System; using System.Collections.Generic; using System.Linq; using System.Text; 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; using System.Text.RegularExpressions; using System.Globalization; namespace RoboforkApp { /// /// Interaction logic for EditNode.xaml /// public partial class EditNodeWindow : Window { public EditNodeWindow() { InitializeComponent(); } public string txtMode; public string _txtMode { get { return txtMode; } set { txtMode = value; } } public string txtMode1; public string _txtMode1 { get { return txtMode1; } } public string txtMode2; public string _txtMode2 { get { return txtMode2; } } public string txtMode3; public string _txtMode3 { get { return txtMode3; } } public bool ExitFlg = false; public bool _ExitFlg { get { return ExitFlg; } } public struct NodeInf { public string Mode; public double Speed; public double Angle; public double Height; } public List NodeInf_List { get { return NodeInf_Lst; } set { NodeInf_Lst = value; } } List NodeInf_Lst = new List(); private void btnEditNode_Click(object sender, RoutedEventArgs e) { string tag = ((Button)sender).Tag.ToString(); switch (tag) { case "ADDMODE": if (!checkFloat(txtSpeed.Text) || !checkFloat(txtAngle.Text) || !checkFloat(txtHight.Text)) { MessageBox.Show("Please Check Again!"); break; } NewDoBeginSave(); clearField(); break; case "No": ExitFlg = true; this.Close(); break; case "Save": if (!checkFloat(txtSpeed.Text) || !checkFloat(txtAngle.Text) || !checkFloat(txtHight.Text)) { MessageBox.Show("Please Check Again!"); break; } NewDoBeginSave(); MessageBox.Show("Data is saved"); this.Close(); break; default: break; } } public void NewDoBeginSave() { NodeInf ni = new NodeInf(); ni.Mode = cbMode.Text; if (txtSpeed.Text != "") { ni.Speed = double.Parse(txtSpeed.Text); } if (txtAngle.Text != "") { ni.Angle = double.Parse(txtAngle.Text); } if (txtHight.Text != "") { ni.Height = double.Parse(txtHight.Text); } NodeInf_Lst.Add(ni); } //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; } public void clearField() { cbMode.Text = ""; txtSpeed.Text = ""; txtAngle.Text = ""; txtHight.Text = ""; } } }