public IEnumerable <Protocol> GetProtocol(DateTime from_, DateTime to_, RezultTest typeRezult = RezultTest.All) { List <Protocol> prot = new List <Protocol>(); string command = ""; switch (typeRezult) { case RezultTest.All: command = string.Format("SELECT * FROM [View_Ticket] WHERE time>='{0}' AND time<'{1}'", from_.ToString("yyyy-MM-dd"), to_.ToString("yyyy-MM-dd")); break; case RezultTest.Good: command = string.Format("SELECT * FROM [View_Ticket] WHERE time>='{0}' AND time<'{1}' AND IsPassed='1'", from_.ToString("yyyy-MM-dd"), to_.ToString("yyyy-MM-dd")); break; case RezultTest.Bad: command = string.Format("SELECT * FROM [View_Ticket] WHERE time>='{0}' AND time<'{1}' AND IsPassed='0'", from_.ToString("yyyy-MM-dd"), to_.ToString("yyyy-MM-dd")); break; } SqlCommand cmd = new SqlCommand(command, connection); using (var reader = cmd.ExecuteReader()) while (reader.Read()) { prot.Add(new Protocol() { ticket = new Ticket() { ID = reader.GetInt32(0), level = reader.GetString(7), date = reader.GetDateTime(1), IsOffline = reader.IsDBNull(reader.GetOrdinal("IsPrint")) ? "так" : reader.GetBoolean(5) ? "ні" : "так", IsPassed = reader.IsDBNull(reader.GetOrdinal("IsPassed")) ? "--" : reader.GetBoolean(6) ? "так" : "ні", user = new UserInfo() { ID = reader.GetInt32(2), Lname = reader.GetString(3), Fname = reader.GetString(4) }, } }); } for (int i = 0; i < prot.Count(); i++) { command = string.Format("SELECT Count(*) FROM [View_Rezult] where ticket_id='{0}'", prot[i].ticket.ID);// [Exam].[dbo]. cmd = new SqlCommand(command, connection); prot[i].answers = (int)cmd.ExecuteScalar(); command = string.Format("SELECT Count(*) FROM [View_Rezult] where ticket_id='{0}' AND istrue='false' ", prot[i].ticket.ID);// [Exam].[dbo]. cmd = new SqlCommand(command, connection); prot[i].errors = (int)cmd.ExecuteScalar(); } return(prot); }
private void Search() { if (pick1.SelectedDate == null || pick2.SelectedDate == null) { MessageBox.Show("Вкажіть період !!!"); return; } progressbar.Visibility = Visibility.Visible; RezultTest RezTest = RezultTest.All; int count = VisualTreeHelper.GetChildrenCount(groupBox); for (int i = 0; i < count; i++) { Visual childVisual = (Visual)VisualTreeHelper.GetChild(groupBox, i); if (childVisual is RadioButton) { RadioButton rb = (RadioButton)childVisual; if ((bool)rb.IsChecked) { if (rb.Content.ToString() == "Успішні") { RezTest = RezultTest.Good; } else if (rb.Content.ToString() == "Провалені") { RezTest = RezultTest.Bad; } break; } } } object param_ = new { dateFrom = (DateTime)pick1.SelectedDate, dateTo = (DateTime)pick2.SelectedDate, rezTest = RezTest }; backWorker.RunWorkerAsync(param_); }