if(App.ActiveCellar == null) { MessageBox.Show("Aucune cave n'est ouverte"); return; } TableManager manager = new TableManager(App); manager.BeginUpdate(); DataTable table = new DataTable("AfficherPAEx"); table.DefaultView.AllowDelete = false; table.CaseSensitive = false; table.DefaultView.AllowEdit = false; table.DefaultView.AllowNew = false; // SysId DataColumn col = new DataColumn("SysId", typeof(string)); col.Caption = "SysId"; table.Columns.Add(col); // Année col = new DataColumn("Year", typeof(ushort)); col.Caption = "Année"; table.Columns.Add(col); // Nom col = new DataColumn("Name", typeof(string)); col.Caption = "Vin"; table.Columns.Add(col); // Région col = new DataColumn("Area", typeof(string)); col.Caption = "Région"; table.Columns.Add(col); // Appellation col = new DataColumn("Appellation", typeof(string)); col.Caption = "Appellation"; table.Columns.Add(col); // Prix col = new DataColumn("Price", typeof(float)); col.Caption = "Prix unitaire "; table.Columns.Add(col); // Achat col = new DataColumn("Buy", typeof(ushort)); col.Caption = "Achat "; table.Columns.Add(col); // Consommation col = new DataColumn("Consume", typeof(ushort)); col.Caption = "Consommation "; table.Columns.Add(col); // Date col = new DataColumn("Date", typeof(DateTime)); col.Caption = "Date "; table.Columns.Add(col); // Commentaire fiche col = new DataColumn("Comment", typeof(string)); col.Caption = "Commentaire fiche"; table.Columns.Add(col); table.BeginLoadData(); // Liste des vins ObjectCollection oc = manager.Application.ActiveCellar.GetCollection((ushort)ObjectType.Wine); for(int i = 0; i < oc.Count; i++) { Wine w = (Wine)oc[i]; // Fiches achats consos for (int j = 0; j < w.Purchases.Count; j++) { PurchaseSales ps = (PurchaseSales)w.Purchases[j]; DataRow r = table.NewRow(); r["Name"] = w.Name.Trim(); r["Area"] = w.Area.Name.Trim(); r["Appellation"] = w.Appellation.Name.Trim(); r["SysId"] = w.SystemUID; r["Comment"] = ps.Comment.Replace("\n", " "); r["Year"] = w.Year; r["Price"] = ps.Price; r["Buy"] = ps.PurchaseBottles; r["Date"] = ps.Date; r["Consume"] = ps.ConsumeBottles; table.Rows.Add(r); } } table.EndLoadData(); manager.DataSource = table; manager.EndUpdate(); ITableWindow tableWindow = (ITableWindow)App.GetWindow(WindowType.Table, manager); if(tableWindow == null) { return; } tableWindow.Show(); // Affectation d'un filtre sur l'année 2004 // L'affectation doit se faire apres l'ouverture de la fenetre IFilter filter = FilterFactory.Instance.Get(manager, manager.DataSource.Columns["Year"]); filter.Value = 2004; filter.FilterType = FilterType.Equals; manager.Filters.Add(filter);
Sorting sortByYear = new Sorting(manager, manager.DataSource.Columns["Year"]); sortByYear.SortingType = SortingType.Asc; // Croissant // sortByYear.SortingType = SortingType.Desc; // Décroissant manager.Sorts.Add(sortByYear);