private void button1_Click(object sender, EventArgs e) { UpdatedV.Clear(); SqlError.Clear(); SqlDataReader dataReader; sql = $"SELECT * FROM [DC_PreProd_Box_Validation].[dbo].[tblBox] where BoxID = {TxtBoxID.Text} "; try { SqlConnection sqlConnection = new SqlConnection(connection); sqlConnection.Open(); command = new SqlCommand(sql, sqlConnection); dataReader = command.ExecuteReader(); while (dataReader.Read()) { if (TxtTarget.Text == LastTarget) { LastTarget = (string)dataReader.GetValue(5); TxtTarget.Text = (string)dataReader.GetValue(5); } else { var IsYes = MessageBox.Show($"Do you want to change the target to: {TxtTarget.Text} ?", "Changing target", MessageBoxButtons.YesNo); if (IsYes == DialogResult.Yes) { Update_Target(); LastTarget = TxtTarget.Text; } else { TxtTarget.Text = (string)dataReader.GetValue(5); } } } if (!dataReader.HasRows) { LastTarget = ""; TxtTarget.Clear(); SqlError.SetError(TxtBoxID, "Box not found"); } dataReader.Close(); command.Dispose(); sqlConnection.Close(); } catch (Exception ex) { SqlError.SetError(TxtBoxID, ex.Message); } }
private bool CheckValues() { if (string.IsNullOrEmpty(CboOperationType.Text)) { MessageBox.Show("请选择操作类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); CboOperationType.Focus(); return(false); } if (string.IsNullOrEmpty(TxtHandman.Text)) { MessageBox.Show("请输入经手人", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); TxtHandman.Focus(); return(false); } if (string.IsNullOrEmpty(TxtTarget.Text)) { MessageBox.Show("请输入目标人", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); TxtTarget.Focus(); return(false); } return(true); }