Browse Source

增加textbox默认文本

master
zhangqi7131 10 months ago
parent
commit
e5179e532f
  1. 6
      STS/Form2.Designer.cs
  2. 37
      STS/Form2.cs
  3. BIN
      TaskManagementDB.bak

6
STS/Form2.Designer.cs

@ -57,10 +57,16 @@
//
// barcode_tb
//
this.barcode_tb.ForeColor = System.Drawing.SystemColors.GrayText;
this.barcode_tb.Location = new System.Drawing.Point(124, 46);
this.barcode_tb.Name = "barcode_tb";
this.barcode_tb.Size = new System.Drawing.Size(234, 25);
this.barcode_tb.TabIndex = 0;
this.barcode_tb.Text = "T*****";
this.barcode_tb.Click += new System.EventHandler(this.barcode_tb_Click);
this.barcode_tb.HideSelectionChanged += new System.EventHandler(this.barcode_tb_HideSelectionChanged);
this.barcode_tb.TextChanged += new System.EventHandler(this.barcode_tb_TextChanged);
this.barcode_tb.MouseLeave += new System.EventHandler(this.barcode_tb_MouseLeave);
//
// STI_tb
//

37
STS/Form2.cs

@ -61,9 +61,19 @@ namespace STS
conn2.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn2;
//判断数据库中是否已经有该条码
cmd.CommandText = $"select * from STM where Barcode='{barcode_tb.Text}'";
cmd.ExecuteNonQuery();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
MessageBox.Show("该条码已存在!"); return;
}
reader.Close();
//没有则插入数据
cmd.CommandText = $"insert into STM values('{barcode_tb.Text}','{STI_tb.Text}','{RTI_tb.Text}','{taskType_tb.Text}'," +
$"'{jobType_cbb.Text}','{startPoint_tb.Text}','{startLocation_tb.Text}','{endPoint_tb.Text}'," +
$"'{endLocation_tb.Text}','{taskStatus_tb.Text}','{startTime_dtp.Text}','{errorInfor_tb.Text}')";
$"'{endLocation_tb.Text}','{taskStatus_tb.Text}','{startTime_dtp.Value.ToString("yyyy-MM-dd HH:mm:ss")}','{errorInfor_tb.Text}')";
Console.WriteLine(cmd.CommandText);
int count = cmd.ExecuteNonQuery();
if (count > 0)
@ -83,5 +93,30 @@ namespace STS
{
Form2Closed?.Invoke(this, EventArgs.Empty);
}
private void barcode_tb_Click(object sender, EventArgs e)
{
//如果是首次点击才执行以下代码
if (barcode_tb.Text.Equals("T*****"))
{
barcode_tb.Text = "";
barcode_tb.ForeColor = Color.Black;
}
}
private void barcode_tb_TextChanged(object sender, EventArgs e)
{
}
private void barcode_tb_MouseLeave(object sender, EventArgs e)
{
}
private void barcode_tb_HideSelectionChanged(object sender, EventArgs e)
{
}
}
}

BIN
TaskManagementDB.bak

Binary file not shown.
Loading…
Cancel
Save