public class App : Application { SfDataGrid sfGrid; public static SampleDemoDatabase database;
public App() { // The root page of your application sfGrid = new SfDataGrid(); sfGrid.ItemsSource = Database.GetItems(); Grid mainLayout = new Grid() { VerticalOptions = LayoutOptions.FillAndExpand }; mainLayout.RowDefinitions.Add(new RowDefinition()); mainLayout.ColumnDefinitions.Add(new ColumnDefinition()); mainLayout.Children.Add(sfGrid, 0, 0);
MainPage = new ContentPage { Content = mainLayout };
}
public static SampleDemoDatabase Database { get { if (database == null) { database = new SampleDemoDatabase(); } return database; } } //OrderItem.cs
public class OrderItem {
public OrderItem() {
}
[PrimaryKey, AutoIncrement] public int ID { get; set; } public string Name { get; set; } public int TokenNo { get; set; } public string BillStatus { get; set; } } // SampleDemoDatabase.cs
public IEnumerable<OrderItem> GetItems () { lock (locker) { // Changing the database table items as ObservableCollection var table = (from i in database.Table<OrderItem>() select i); ObservableCollection<OrderItem> OrderList = new ObservableCollection<OrderItem>(); foreach (var order in table) { OrderList.Add(new OrderItem() { ID = order.ID, Name = order.Name, TokenNo = order.TokenNo, BillStatus = order.BillStatus }); } return OrderList; } } |
|