大家好我是新來的c#和sql,我在c#中創建一個Windows應用程序,將允許用戶不要在每個班次的上午7點到晚上7點之間在數據庫中插入相同的信息,應用程序必須允許用戶在這個時間間隔和同一件事之間在晚上7點和上午之間不插入相同的信息....如果用戶試圖插入相同的數據在此間隔之間會彈出一條消息,說明「這種轉變已經存在信息」。允許用戶每個班次發送一次數據到數據庫(每天一次,每晚一次)
這裏是我到目前爲止的代碼爲SAVE按鈕,它可以插入到數據庫中,我需要有人誰可以幫助在哪?我怎麼可以添加此功能允許沒有用戶在每班數據庫中插入相同的信息早上7點到晚上7點之間,或者如果有另一種方式。有人能幫我嗎?
private void button1_Click(object sender, EventArgs e)
{
//................INSERT TO DATABASE...........................................................
if ((!string.IsNullOrWhiteSpace(comboBox1.Text)) & (!string.IsNullOrWhiteSpace(textBox10.Text)) & (!string.IsNullOrWhiteSpace(textBox9.Text))& (!string.IsNullOrWhiteSpace(textBox6.Text))& (!string.IsNullOrWhiteSpace(textBox8.Text))& (!string.IsNullOrWhiteSpace(textBox13.Text))& (!string.IsNullOrWhiteSpace(textBox7.Text))& (!string.IsNullOrWhiteSpace(textBox3.Text))& (!string.IsNullOrWhiteSpace(textBox2.Text)))
{
string buffer = textBox10.Text;
string buffer1 = textBox9.Text;
string buffer2 = textBox6.Text;
string buffer3 = textBox7.Text;
string buffer4 = textBox8.Text;
double val = Double.Parse(buffer, System.Globalization.CultureInfo.InvariantCulture);
double val1 = Double.Parse(buffer1, System.Globalization.CultureInfo.InvariantCulture);
double val2 = Double.Parse(buffer2, System.Globalization.CultureInfo.InvariantCulture);
double val3 = Double.Parse(buffer3, System.Globalization.CultureInfo.InvariantCulture);
double val4 = Double.Parse(buffer4, System.Globalization.CultureInfo.InvariantCulture);
if (val > 59 && val < 161 && val1 > 99 && val1 < 301 && val2>2&&val2<7 && val3>2 && val3<7 && val4>2 && val2<4)
{
float em1 = float.Parse(textBox6.Text, System.Globalization.CultureInfo.InvariantCulture);
float em2 = float.Parse(textBox7.Text, System.Globalization.CultureInfo.InvariantCulture);
float em3 = float.Parse(textBox8.Text, System.Globalization.CultureInfo.InvariantCulture);
float ava = float.Parse(textBox13.Text, System.Globalization.CultureInfo.InvariantCulture);
int bond = int.Parse(textBox9.Text, System.Globalization.CultureInfo.InvariantCulture);
int feed = int.Parse(textBox10.Text, System.Globalization.CultureInfo.InvariantCulture);
string Connection = @"Data Source=NZUZO\SQLEXPRESS;Initial Catalog=Checksheet;Integrated Security=True";
string query = "insert into SJB (Machine_Cleanliness,Safety_System,Single_Mode,SJB_Fixture,Feed_Pressure,Bond_Height,Line_NO,Machine_NO,Product,Suspension,Capilary_Lifetime,EM_Trial1,EM_Trial2,EM_Trial3,Avarage,EN,Shift) values(@Machine_C ,@Safety, @SingleMode,@SJB_Fixture,'" + feed + "','" + bond + "','" + this.textBox12.Text + "','" + this.textBox4.Text + "','" + this.textBox1.Text + "','" + this.textBox11.Text + "','" + this.textBox3.Text + "','" + em1 + "','" + em2 + "','" + em3 + "','" + ava + "','" + this.textBox2.Text + "','" + this.label5.Text + "')";
SqlConnection conn = new SqlConnection(Connection);
SqlCommand conn1 = new SqlCommand(query, conn);
//select getdate()");
conn1.Connection = conn;
//String selection = new string(MyChar, 1);
//conn1.Parameters.AddWithValue("@Safety", selection);
SqlDataReader myReader;
// conn1.CommandType = CommandType.StoredProcedure;
using (var command = new SqlCommand("Checksheet1", conn)
{
CommandType = CommandType.StoredProcedure
})
// recordCount > 0;
// radioButton6 = radioButton6.checked;
if (radioButton6.Checked)
{
// selection = "G";
conn1.Parameters.AddWithValue("@Safety", "G");
}
else if (radioButton5.Checked)
// selection = "N";
conn1.Parameters.AddWithValue("@Safety", "N");
if (radioButton11.Checked)
{
conn1.Parameters.AddWithValue("@Machine_C", "G");
}
else if (radioButton12.Checked)
conn1.Parameters.AddWithValue("@Machine_C", "N");
if (radioButton13.Checked)
{
conn1.Parameters.AddWithValue("@SingleMode", "G");
}
else if (radioButton14.Checked)
conn1.Parameters.AddWithValue("@SingleMode", "N");
if (radioButton1.Checked)
{
conn1.Parameters.AddWithValue("@SJB_Fixture", "G");
}
else if (radioButton2.Checked)
{
conn1.Parameters.AddWithValue("@SJB_Fixture", "N");
}
try
{
conn.Open();
// conn1.ExecuteNonQuery();
myReader = conn1.ExecuteReader();
MessageBox.Show("Machine Checked......");
this.Close();
while (myReader.Read())
{
// conn1.Parameters.AddWithValue("@Line_No",textBox12);
// bool test=false;
//int hour = DateTime.Now.Hour;
// test = (myReader !=null && myReader.HasRows);
}
conn.Close();
}
catch (Exception es)
{
MessageBox.Show(es.Message);
}
}
else
{
MessageBox.Show("Error.... Invalid Value in The check List.", "Check Sheet", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Cannot Submit Checklist...Please check for empty space", "Check Sheet", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
不要用你的TITLE拍攝我們。我們是好人。 –
首先,不要在標題中使用標籤,現在我的選擇。你可以做的是做一個布爾值並且調用這個轉換。然後制定日期時間並設定時間。然後,當用戶插入數據時,布爾值變爲false,然後用戶無法插入數據,直到您設置的時間 –
也請更改組件的名稱,這會使代碼非常不清晰。如果文本框必須有密碼,請將其稱爲passwordTextbox。它更容易這樣 –