void InitQueryForUsageReportTable(string prefix, DbCommand cmd, string suffix) { List <QueryParameter> queryParams = new List <QueryParameter>(); string query = prefix; if (WebUserControl11.HasConstraints) { query += " where "; if (WebUserControl11.HasUserNameConstraint) { query += " s.UserID = ? and"; queryParams.Add(new QueryParameter("userid", WebUserControl11.TxtUserName.Text)); } if (WebUserControl11.HasOSNameConstraint) { query += " s.OS = ? and"; queryParams.Add(new QueryParameter("os", WebUserControl11.TxtOSName.Text)); } if (WebUserControl11.HasMemoryConstraint) { query += " s.SystemMemory " + WebUserControl11.CmbMmeoryOperator.SelectedValue + " ? and"; queryParams.Add(new QueryParameter("memory", WebUserControl11.TxtMemoryValue.Text)); } if (WebUserControl11.HasAppNameConstraint) { query += " s.AppName = ? and"; queryParams.Add(new QueryParameter("appname", WebUserControl11.TxtAppName.Text)); } if (WebUserControl11.HasAppVersionConstraint) { query += " s.AppVersion " + WebUserControl11.CmbAppVersionOperator.SelectedValue + " ? and"; queryParams.Add(new QueryParameter("appversion", float.Parse(WebUserControl11.TxtAppVersion.Text))); } if (WebUserControl11.HasDateFromConstraint) { query += " s.StartTime >= ? and"; queryParams.Add(new QueryParameter("starttime", WebUserControl11.DtFrom.SelectedDate)); } if (WebUserControl11.HasDateToConstraint) { query += " s.EndTime < ? and"; queryParams.Add(new QueryParameter("endtime", WebUserControl11.DtTo.SelectedDate.AddDays(1))); } if (WebUserControl11.HasLicenseIDConstraint) { query += " s.AssociatedLicenseID = ? and"; queryParams.Add(new QueryParameter("licenseid", WebUserControl11.TxtLicenseID.Text)); } if (WebUserControl11.HasRuntimeConstraint) { query += " s.CLRVersion " + WebUserControl11.CmbRuntime.SelectedValue + " ? and"; queryParams.Add(new QueryParameter("clrversion", float.Parse(WebUserControl11.TxtRuntime.Text))); } if (WebUserControl11.HasFeatureTableConstraints) { query += " s.ID in (select f.ReportID from " + svc.UsageReportFeatureTableName + " as f where f.ReportID=s.ID and "; if (WebUserControl11.HasFeatureNameConstraint) { query += "f.Name = ? and"; queryParams.Add(new QueryParameter("featurename", WebUserControl11.TxtFeatureName.Text)); } if (query.EndsWith("and")) { query = query.Remove(query.Length - 3); } query += ")"; } if (query.EndsWith("and")) { query = query.Remove(query.Length - 3); } } query += suffix; cmd.CommandText = query; foreach (QueryParameter qp in queryParams) { worker.AddInputParameter(cmd, qp.name, qp.value); } }