AutoCompleteStringCollection LoadHeadings() { IDBColumnIndexer <SubHeading> ndxer = Program.TablesManager.GetSubHeadingIndexer(TablesID.SPOT_VALUE, TablesManager.ColumnID_t.SubHeading); string[] seq = (from sh in ndxer.Attributes select sh.ToString()).Distinct().ToArray(); var result = new AutoCompleteStringCollection(); result.AddRange(seq); return(result); }
void SearchAsyncSubHeading(SubHeading subHeading , DateTime date , Incoterm ict , Country origin) { IDisposable releaser = Log.LogEngin.PushMessage("Recherche en cours..."); m_tsbSearch.Enabled = false; Func<SpotValue , SpotValue , bool> isSameVC = (sv1 , sv2) => { if (sv1.ValueContextID == sv2.ValueContextID) return true; ValueContext vc1 = sv1.ValueContext, vc2 = sv2.ValueContext; return vc1.IncotermID == vc2.IncotermID && vc1.OriginID == vc2.OriginID; }; Func<SpotViewItem[]> search = () => { IDBColumnIndexer<SubHeading> ndxer = Program.TablesManager.GetSubHeadingIndexer(TablesID.SPOT_VALUE , TablesManager.ColumnID_t.SubHeading); IEnumerable<SpotValue> seq = from SpotValue sv in ndxer.Get(subHeading) select sv; var candidatesValue = new List<SpotValue>(); foreach (SpotValue sv in seq) { if (sv.SpotTime > date) continue; int ndx = candidatesValue.FindIndex(v => v.Product.ID == sv.Product.ID && isSameVC(v , sv)); if (ndx == -1) candidatesValue.Add(sv); else if (candidatesValue[ndx].SpotTime < sv.SpotTime) candidatesValue[ndx] = sv; } seq = candidatesValue; if (ict.ID != 0) seq = from SpotValue sv in seq where sv.ValueContext.IncotermID == ict.ID select sv; if (origin != null) seq = from SpotValue sv in seq where sv.ValueContext.OriginID == origin.ID select sv; IEnumerable<SpotViewItem> items = from SpotValue sv in seq select new SpotViewItem(sv); return items.ToArray(); }; Action<Task<SpotViewItem[]>> onSuccess = (t) => { EmptyMode = t.Result.Length == 0; if (!EmptyMode) { m_lvSearchResult.BeginUpdate(); m_lvSearchResult.Items.AddRange(t.Result); if (m_lvSearchResult.View == View.Details) m_lvSearchResult.AdjustColumnsSize(); m_lvSearchResult.EndUpdate(); } string txtLog = $"Module valeurs boursières: recherche de la SPT {subHeading}, date: {date.ToShortDateString()}, " + $"incoterm: {(ict.ID == 0 ? AppText.UNSPECIFIED : ict.Name)}, origine: {(origin == null ? AppText.UNSPECIFIED : origin.Name)}, " + $"Nbre d'enregistrements trouvés: {t.Result.Length}"; Program.DialogManager.PostLog(txtLog , false); m_tsbSearch.Enabled = true; releaser.Dispose(); Log.LogEngin.PushFlash($"{t.Result.Length} élément(s) trouvé(s)."); }; Action<Task> onErr = (t) => { m_tsbSearch.Enabled = true; Log.LogEngin.PushFlash(t.Exception.InnerException.Message); string errLog = "Module valeurs boursiére: Erreur lors de la recherche, " + t.Exception.InnerException.Message; Program.DialogManager.PostLog(errLog , true); }; var task = new Task<SpotViewItem[]>(search , TaskCreationOptions.LongRunning); task.OnSuccess(onSuccess); task.OnError(onErr); task.Start(); }