Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void fillWorkerCombo()
- {
- numberCombo.Items.Clear();
- cnn = new SqlConnection(connectionString);
- using (cnn)
- {
- AutoCompleteStringCollection data = new AutoCompleteStringCollection();
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- SqlDataReader dr;
- try
- {
- string sortQuery;
- SqlCommand cmd;
- if (sorting)
- {
- sortQuery = "SELECT Worker_Number, Error_Short, Machine, Create_Record, Modify_Record FROM Report_tbl WHERE Machine = @machine AND Error_Short = @errorshort AND Modify_Record BETWEEN @start_date AND @end_date";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machine", machineCombo.Text);
- cmd.Parameters.AddWithValue("@errorshort", errorCombo.Text);
- cmd.Parameters.AddWithValue("@start_date", monthCalendar1.SelectionRange.Start);
- cmd.Parameters.AddWithValue("@end_date", monthCalendar1.SelectionRange.End.AddDays(1));
- }
- else
- {
- sortQuery = "SELECT Worker_Number, Error_Short, Machine, Create_Record, Modify_Record FROM Report_tbl WHERE Machine = @machine AND Error_Short = @errorshort";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machine", machineCombo.Text);
- cmd.Parameters.AddWithValue("@errorshort", errorCombo.Text);
- dr = cmd.ExecuteReader();
- int workerNumber = 0;
- while (dr.HasRows)
- {
- while (dr.Read())
- {
- int getIntFromDR = dr.GetInt32(0);
- if (!numberCombo.Items.Contains(getIntFromDR))
- {
- workerNumber = getIntFromDR;
- numberCombo.Text = workerNumber.ToString();
- numberCombo.Items.Add(workerNumber.ToString());
- numberCombo.AutoCompleteCustomSource = data;
- }
- }
- dr.NextResult();
- }
- dr.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("521Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- cnn.Close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement