void TxtDataLeave(object sender, EventArgs e) { var textBox = (TextBox)sender; UInt64 res; if (UInt64.TryParse(textBox.Text, out res)) { switch (textBox.Name) { case "textBoxStartAdress": if (res < 0 || res > 65535) { textBox.Text = _oldStartingAddress; MessageBox.Show("Start Address must be betweeon 0 to 65535."); return; } _oldStartingAddress = textBox.Text; formBaseDataTable.changeStartAddress(textBox.Text); break; case "textBoxTotalRegister": if ((res < 0 || res > 124) && (_functionCode.Equals("03") || _functionCode.Equals("04"))) { textBox.Text = _oldTotalRegister; MessageBox.Show("Total Register must be betweeon 1 to 123."); return; } else if ((res < 1 || res > 2000) && (_functionCode.Equals("01") || _functionCode.Equals("02"))) { textBox.Text = _oldTotalRegister; MessageBox.Show("Total Coils must be between 1 to 2000."); return; } _oldTotalRegister = textBox.Text; formBaseDataTable.changeTotalRegister(textBox.Text); break; case "textBoxMasterId": if (res < 0 || res > 256) { textBox.Text = _oldTotalRegister; MessageBox.Show("Slave Id must be betweeon 1 to 255."); return; } _oldMasterId = textBox.Text; break; case "textBoxRequestDelay": if (res < 500) { textBox.Text = _oldRequestDelay; MessageBox.Show("Delay must be more than 500 millis "); return; } _oldRequestDelay = textBox.Text; formBaseDataTable.changeRequestDelay(textBox.Text); break; case "textBoxReceiveDelay": checkReceiveDelay(textBox, res, sender); formBaseDataTable.changeReceiveDelay(textBox.Text); break; } } else { switch (textBox.Name) { case "textBoxStartAdress": textBox.Text = _oldStartingAddress; break; case "textBoxTotalRegister": textBox.Text = _oldTotalRegister; break; case "textBoxMasterId": textBox.Text = _oldMasterId; break; case "textBoxRequestDelay": textBox.Text = _oldRequestDelay; break; case "textBoxReceiveDelay": textBox.Text = _oldReceiveDelay; break; } } }