|
本帖最后由 EnZo 于 2024-10-16 11:54 编辑
窗体页面中有两个TextBox,在第一个TextBox使用SubmitEditing事件,对另一个TextBox进行获取焦点。最后点击按钮执行数据提交操作。再之后,所有的Focus就全部失效,重新打开后依然只有第一次有效
private void txtLockerNo_SubmitEditing(object sender, EventArgs e)
{
if (txtLockerNo.Text == "") return;
txtLockerNo.ReadOnly = true;
txtBoxID.ReadOnly = false;
txtBoxID.Focus();
}
private void btnCommit_Press(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
try
{
int ret = 0;
conn.ConnectionString = constr;
conn.Open();
string storagePlaceStr = string.Join(",", dtBox.AsEnumerable().Select(x => x.Field<string>("盒号")).ToArray());
//常规写入数据库
SqlCommand cmd = new SqlCommand("P_CSPCK_PDA_InLocker", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter fSqlParameter = new SqlParameter();
cmd.Parameters.Add(new SqlParameter("@LockerNo", SqlDbType.NVarChar, 50));
cmd.Parameters["@LockerNo"].Value = txtLockerNo.Text;
cmd.Parameters.Add(new SqlParameter("@StoragePlaceNo", SqlDbType.Text, 5000));
cmd.Parameters["@StoragePlaceNo"].Value = storagePlaceStr;
cmd.Parameters.Add(new SqlParameter("@Results", SqlDbType.NVarChar, 50));
cmd.Parameters["@Results"].Direction = ParameterDirection.Output;
cmd.Parameters.Add(new SqlParameter("@Msg", SqlDbType.NVarChar, 255));
cmd.Parameters["@Msg"].Direction = ParameterDirection.Output;
ret = cmd.ExecuteNonQuery();
conn.Close();
if (cmd.Parameters["@Results"].Value.ToString() == "000")
{
MessageBox.Show(string.Format("数据提交成功!,本次入【{0}】袋", dtBox.Rows.Count));
dtBox.Clear();
tableView1.DataSource = dtBox;
tableView1.DataBind();
txtBoxID.Text = "";
txtBoxID.ReadOnly = true;
txtLockerNo.Text = "";
txtLockerNo.ReadOnly = false;
txtLockerNo.Focus();
}
else
{
MessageBox.Show("数据提交失败", "错误");
}
}
catch (DataException ex)
{
MessageBox.Show("提交失败,请确认无线网络已连接!!" + ex.ToString());
txtBoxID.Text = "";
txtBoxID.ReadOnly = false;
conn.Close();
conn.Dispose();
}
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|