Przeglądaj źródła

PRS MOBILE - datagrid improvement, added EquipmentGrid

Nick 2 lat temu
rodzic
commit
ab73b6bfd2

+ 2 - 0
prs.mobile/comal.timesheets.Android/MainActivity.cs

@@ -91,6 +91,8 @@ namespace comal.timesheets.Droid
 
             Xamarin.Essentials.Platform.Init(this, savedInstanceState);
 
+            Syncfusion.XForms.Android.PopupLayout.SfPopupLayoutRenderer.Init();
+
             Xamarin.FormsMaps.Init(this, savedInstanceState);
 
             ZXing.Net.Mobile.Forms.Android.Platform.Init();

+ 3 - 1
prs.mobile/comal.timesheets/CustomControls/Pages/ListSelectionPage.xaml.cs

@@ -125,12 +125,14 @@ namespace comal.timesheets
         {
             ListSelectionViewItem item = listView.SelectedItem as ListSelectionViewItem;
 
+            Device.BeginInvokeOnMainThread(() => { Navigation.PopAsync(); });
+
             if (item.ID != Guid.Empty)
                 OnDictionaryItemTapped?.Invoke(item.ID, item.Value);
             else
                 OnSimpleListTapped?.Invoke(item.Value);
 
-            Navigation.PopAsync();
+                
         }
 
         static String UpperCaseFirst(string s)

+ 1 - 1
prs.mobile/comal.timesheets/DataGridHost.xaml.cs

@@ -28,7 +28,7 @@ namespace comal.timesheets
         {
             Device.BeginInvokeOnMainThread(() =>
             {
-                titleLbl.Text = title + "s";
+                titleLbl.Text = title + " List";
                 saveBtn.IsVisible = savetype == DataGridSaveType.None ? false : true;
             });
         }

+ 5 - 0
prs.mobile/comal.timesheets/DataGridSearchEntry.cs

@@ -20,6 +20,11 @@ namespace comal.timesheets
             ColumnName = colname;
             FontSize = 16;
             Margin = 1.5;
+            if (colname == "Image")
+            {
+                Placeholder = "";
+                IsEnabled = false;
+            }
         }
 
         private void DataGridSearchEntry_TextChanged(object sender, TextChangedEventArgs e)

+ 7 - 5
prs.mobile/comal.timesheets/Equipment/EquipmentModule.xaml.cs

@@ -27,11 +27,13 @@ namespace comal.timesheets
 
         private async void EquipmentList_Tapped(object sender, EventArgs e)
 		{
-            using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
-            {
-                var equipment = new EquipmentList();
-                Navigation.PushAsync(equipment);
-            }
+            //using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
+            //{
+            //    var equipment = new EquipmentList();
+            //    Navigation.PushAsync(equipment);
+            //}
+            var page = new DataGridHost(new EquipmentGrid());
+            Navigation.PushAsync(page);
         }
 
 		private async void LiveMaps_Tapped(object sender, EventArgs e)

+ 46 - 0
prs.mobile/comal.timesheets/EquipmentGrid.cs

@@ -0,0 +1,46 @@
+using Comal.Classes;
+using InABox.Clients;
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace comal.timesheets
+{
+    public class EquipmentGrid : MobileDataGrid
+    {
+        public EquipmentGrid(DataGridSaveType savetype = DataGridSaveType.None)
+        {
+            Task.Run(async () =>
+            {
+                CoreTable table = new Client<Equipment>().Query(null,
+                new Columns<Equipment>(
+                    x => x.ID,
+                    x => x.GroupLink.Description,
+                    x => x.Description,
+                    x => x.TrackerLink.BatteryLevel
+                    )
+                );
+                if (!table.Rows.Any())
+                    return;
+
+                List<DataGridViewModelItem> shells = new List<DataGridViewModelItem>();
+                foreach (CoreRow row in table.Rows)
+                {
+                    List<Tuple<string, string>> tuples = new List<Tuple<string, string>>();
+                    tuples.Add(new Tuple<string, string>("Name", row.Get<Equipment, string>(x => x.Description)));
+                    tuples.Add(new Tuple<string, string>("Group", row.Get<Equipment, string>(x => x.GroupLink.Description)));
+                    tuples.Add(new Tuple<string, string>("Battery", row.Get<Equipment, double>(x => x.TrackerLink.BatteryLevel).ToString()));
+                    shells.Add(new DataGridViewModelItem
+                                    (
+                                        id: row.Get<Equipment, Guid>(x => x.ID),
+                                        data: tuples
+                                    ));
+                }
+                Setup(shells, typeof(Equipment), savetype);
+            });
+        }
+    }
+}

+ 1 - 1
prs.mobile/comal.timesheets/Main/MainPage.xaml.cs

@@ -1586,8 +1586,8 @@ namespace comal.timesheets
                         //    ProductList products = new ProductList();
                         //    Navigation.PushAsync(products);
                         //}
-
                         var page = new DataGridHost(new ProductsGrid());
+
                         Navigation.PushAsync(page);
                     });
                     toolEntries.Add(Products);

+ 7 - 0
prs.mobile/comal.timesheets/MobileDataGrid.xaml

@@ -31,12 +31,19 @@
                                     <ColumnDefinition Width="{Binding ColWidth1}"/>
                                     <ColumnDefinition Width="{Binding ColWidth2}"/>
                                     <ColumnDefinition Width="{Binding ColWidth3}"/>
+                                    <ColumnDefinition Width="{Binding ImgColWidth}"/>
                                 </Grid.ColumnDefinitions>
 
                                 <Label Grid.Column="0" Text="{Binding Col0}" Margin="5, 0, 5, 0" FontSize="16"/>
                                 <Label Grid.Column="1" Text="{Binding Col1}" Margin="5, 0, 5, 0" FontSize="16"/>
                                 <Label Grid.Column="2" Text="{Binding Col2}" Margin="5, 0, 5, 0" FontSize="16"/>
                                 <Label Grid.Column="3" Text="{Binding Col3}" Margin="5, 0, 5, 0" FontSize="16"/>
+
+                                <Image Grid.Column="4" Source="{Binding Source}" HeightRequest="30" WidthRequest="30" IsVisible="{Binding ImageColVisible}">
+                                    <Image.GestureRecognizers>
+                                        <TapGestureRecognizer Tapped="Image_Tapped" CommandParameter="{Binding .}"/>
+                                    </Image.GestureRecognizers>
+                                </Image>
                             </Grid>
                         </ViewCell>
                     </DataTemplate>

+ 105 - 27
prs.mobile/comal.timesheets/MobileDataGrid.xaml.cs

@@ -1,7 +1,12 @@
 using comal.timesheets.Data_Classes;
+using comal.timesheets.Deliveries;
+using InABox.Clients;
+using InABox.Core;
+using Syncfusion.XForms.PopupLayout;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.IO;
 using System.Linq;
 using System.Reflection;
 using Xamarin.Forms;
@@ -15,35 +20,46 @@ namespace comal.timesheets
         Single,
         Multiple
     }
+
     public delegate void DataGridOptionsSet(string title, DataGridSaveType savetype = DataGridSaveType.None);
+    public delegate void DataGridItemSelected(DataGridViewModelItem item);
     [XamlCompilation(XamlCompilationOptions.Compile)]
     public partial class MobileDataGrid : ContentView
     {
+        public event DataGridOptionsSet OnOptionsSet;
+        public event DataGridItemSelected OnItemSelected;
+
         public List<DataGridViewModelItem> Items { get; set; }
         DataGridSaveType SaveType { get; set; }
-
-        public event DataGridOptionsSet OnOptionsSet;
+      
         bool bSearching = false;
         ObservableCollection<DataGridFilter> Filters = new ObservableCollection<DataGridFilter>();       
         List<DataGridViewModelItem> CurrentItems = new List<DataGridViewModelItem>();
         PropertyInfo[] info = typeof(DataGridViewModelItem).GetProperties();
         Dictionary<string, List<string>> FilterOptions = new Dictionary<string, List<string>>();
         Type Type;
-
+        SfPopupLayout popupLayout;
         public MobileDataGrid()
         {
             InitializeComponent();
             Items = new List<DataGridViewModelItem>();
             Filters.CollectionChanged += Filters_CollectionChanged;
+
+            popupLayout = new SfPopupLayout();
+            popupLayout.PopupView.WidthRequest = 600;
+            popupLayout.PopupView.HeightRequest = 600;
+            popupLayout.PopupView.HeaderTitle = "Image";
+            popupLayout.PopupView.AcceptButtonText = "Close";
         }
 
+        #region Grid Setup
         public void Setup(List<DataGridViewModelItem> items, Type type, DataGridSaveType savetype = DataGridSaveType.None)
         {
             Type = type;
             Items = items;
             Device.BeginInvokeOnMainThread(() =>
             {
-                SetupHeadersAndDataTemplate(items.First());
+                SetupHeaders(items.First());
                 Refresh(Items);
             });
             OnOptionsSet?.Invoke(type.Name, savetype);
@@ -81,12 +97,13 @@ namespace comal.timesheets
             }
         }
 
-        public void SetupHeadersAndDataTemplate(DataGridViewModelItem item)
+        public void SetupHeaders(DataGridViewModelItem item)
         {
-            GenerateHeaders(item);
+            var count = GenerateHeaders(item);
+            GenerateImageHeader(item, count);
         }
 
-        public void GenerateHeaders(DataGridViewModelItem item)
+        public int GenerateHeaders(DataGridViewModelItem item)
         {
             int count = 0;
             foreach (var tuple in item.Data)
@@ -95,23 +112,19 @@ namespace comal.timesheets
                 CreateFilterOption(count);
                 count++;
             }
+            return count;
         }
 
-        private void CreateFilterOption(int column)
+        private void GenerateImageHeader(DataGridViewModelItem item, int count)
         {
-            List<string> options = new List<string>();
-            foreach (var property in info)
+            if (item.Image != null)
             {
-                if (property.Name == "Col" + column)
-                    foreach (var item in Items)
-                    {
-                        string value = GetStringValue(property, item);
-                        if (!options.Contains(value) && !string.IsNullOrWhiteSpace(value))
-                            options.Add(value);
-                    }
+                headerGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
+                DataGridHeaderRow header = new DataGridHeaderRow { ColumnName = "Image", ColumnNumber = count };
+                header.Setup();
+                headerGrid.Children.Add(SetGridValues(header, 0, count));
+                CreateSearchEntry("Image", count);
             }
-            options.Sort();
-            FilterOptions.Add("Col" + column, options);
         }
 
         private void CreateNewHeader(string name, int count)
@@ -124,6 +137,22 @@ namespace comal.timesheets
             headerGrid.Children.Add(SetGridValues(header, 0, count));
             CreateSearchEntry(name, count);
         }
+        private void CreateFilterOption(int column)
+        {
+            List<string> options = new List<string>();
+            foreach (var property in info)
+            {
+                if (property.Name == "Col" + column)
+                    foreach (var item in Items)
+                    {
+                        string value = GetStringValue(property, item);
+                        if (!options.Contains(value) && !string.IsNullOrWhiteSpace(value))
+                            options.Add(value);
+                    }
+            }
+            options.Sort();
+            FilterOptions.Add("Col" + column, options);
+        }      
 
         private void CreateSearchEntry(string name, int count)
         {
@@ -139,12 +168,15 @@ namespace comal.timesheets
             view.SetValue(Grid.ColumnProperty, column);
             return view;
         }
+        #endregion
 
         #region Events
         private void Row_Tapped(object sender, EventArgs e)
         {
             var item = itemsListView.SelectedItem as DataGridViewModelItem;
-            if (item != null && SaveType != DataGridSaveType.None)
+            if (item == null)
+                return;
+            if (SaveType != DataGridSaveType.None)
             {
                 switch (SaveType)
                 {
@@ -155,12 +187,17 @@ namespace comal.timesheets
                     case DataGridSaveType.Multiple:
                         AddSelectionToLists(item);
                         break;
+
                 }
+                List<DataGridViewModelItem> list = new List<DataGridViewModelItem>();
+                foreach (var i in CurrentItems)
+                    list.Add(i);
+                Refresh(list);
             }
-            List<DataGridViewModelItem> list = new List<DataGridViewModelItem>();
-            foreach (var i in CurrentItems)
-                list.Add(i);
-            Refresh(list);
+            else if (SaveType == DataGridSaveType.None)
+            {
+                OnItemSelected?.Invoke(item);
+            }        
         }
 
         private void UnselectOthers(DataGridViewModelItem item)
@@ -169,6 +206,39 @@ namespace comal.timesheets
             UnselectItems(item, CurrentItems);
         }
 
+        private void Image_Tapped(object sender, EventArgs e)
+        {
+            var item = ((TappedEventArgs)e).Parameter as DataGridViewModelItem;
+            if (item == null)
+                return;
+
+            if (item.ImageID == Guid.Empty)
+                return;
+
+            CoreTable table = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(item.ImageID),
+            new Columns<Document>(x => x.Data));
+            CoreRow docrow = table.Rows.FirstOrDefault();
+            if (docrow != null)
+            {
+                byte[] data = docrow.Get<Document, byte[]>(x => x.Data);
+                ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
+                if (src != null)
+                {
+                    Image popupContent = new Image();
+                    popupContent.HorizontalOptions = LayoutOptions.FillAndExpand;
+                    popupContent.VerticalOptions = LayoutOptions.FillAndExpand;
+                    popupContent.Aspect = Aspect.AspectFit;
+                    popupContent.Source = src;
+                    popupLayout.PopupView.ContentTemplate = new DataTemplate(() =>
+                    {
+                        return popupContent;
+                    });
+                    Device.BeginInvokeOnMainThread(() => { popupLayout.Show(); });
+                   
+                }
+            }
+        }
+
         private void UnselectItems(DataGridViewModelItem item, List<DataGridViewModelItem> selectedlist)
         {
             var list = selectedlist.Where(x => x.IsSelected == true);
@@ -386,6 +456,8 @@ namespace comal.timesheets
             var newlist = Filters.Where(x => x.ColNumber == "Col" + columnnumber);
         }
         #endregion
+
+        #region Utils
         private IEnumerable<DataGridViewModelItem> RunSearch(IEnumerable<DataGridViewModelItem> list, string value, string propertyname)
         {
             var intermediatelist = new List<DataGridViewModelItem>();
@@ -446,7 +518,7 @@ namespace comal.timesheets
                     return FilterNumber.Zero;
             }
         }
-
+        #endregion
     }
 
     public enum FilterNumber
@@ -485,6 +557,7 @@ namespace comal.timesheets
     public class DataGridViewModelItem
     {
         public Guid ID { get; set; }
+        public Guid ImageID { get; set; }
 
         private bool isSelected;
         public bool IsSelected
@@ -511,23 +584,28 @@ namespace comal.timesheets
         {
             get
             {
-                return Image.Source;
+                return Image == null? null: Image.Source;
             }
         }
         public GridLength ColWidth0 { get; set; }
         public GridLength ColWidth1 { get; set; }
         public GridLength ColWidth2 { get; set; }
         public GridLength ColWidth3 { get; set; }
+        public GridLength ImageColWidth { get; set; }
+        public bool ImageColVisible { get; set; }
 
-        public DataGridViewModelItem(Guid id, List<Tuple<string, string>> data, Image image = null)
+        public DataGridViewModelItem(Guid id, List<Tuple<string, string>> data, Image image = null, Guid imageid = new Guid())
         {
             ID = id;
+            ImageID = imageid;
             Data = data;
             Image = image;
             Col0 = data.Count > 0 ? data[0].Item2 : "";
             Col1 = data.Count > 1 ? data[1].Item2 : "";
             Col2 = data.Count > 2 ? data[2].Item2 : "";
             Col3 = data.Count > 3 ? data[3].Item2 : "";
+            ImageColWidth = image != null ? new GridLength(0.5, GridUnitType.Star) : new GridLength(0, GridUnitType.Absolute);
+            ImageColVisible = image != null ? true : false;
             ColWidth0 = data.Count > 0 ? new GridLength(1, GridUnitType.Star) : new GridLength(0, GridUnitType.Absolute);
             ColWidth1 = data.Count > 1 ? new GridLength(1, GridUnitType.Star) : new GridLength(0, GridUnitType.Absolute);
             ColWidth2 = data.Count > 2 ? new GridLength(1, GridUnitType.Star) : new GridLength(0, GridUnitType.Absolute);

+ 60 - 10
prs.mobile/comal.timesheets/ProductsGrid.cs

@@ -1,4 +1,5 @@
-using Comal.Classes;
+using comal.timesheets.Products;
+using Comal.Classes;
 using InABox.Clients;
 using InABox.Core;
 using System;
@@ -11,11 +12,27 @@ using XF.Material.Forms.UI.Dialogs;
 
 namespace comal.timesheets
 {
+    public delegate void ProductsGridItemSelected(DataGridViewModelItem item);
+    public delegate Task<string> ProductsGridShowOptions();
     public class ProductsGrid : MobileDataGrid
     {
+        public event ProductsGridItemSelected ItemSelected;
+        public event ProductsGridShowOptions ShowOptions;
         public ProductsGrid(DataGridSaveType savetype = DataGridSaveType.None)
         {
-            Task.Run(async() => 
+            OnItemSelected += ProductsGrid_OnItemSelected;
+            LoadItems(savetype);
+        }
+
+        private void ProductsGrid_OnItemSelected(DataGridViewModelItem item)
+        {
+            ItemSelected?.Invoke(item);
+            DisplayOptions(item);
+        }
+
+        private void LoadItems(DataGridSaveType savetype = DataGridSaveType.None)
+        {
+            Task.Run(async () =>
             {
                 if (GlobalVariables.ProductsLoaded)
                 {
@@ -28,8 +45,10 @@ namespace comal.timesheets
                         tuples.Add(new Tuple<string, string>("Family", product.Group));
                         shells.Add(new DataGridViewModelItem
                         (
-                                product.ID,
-                                tuples
+                                id: product.ID,
+                                data: tuples,
+                                image: product.ImageID == Guid.Empty ? new Image() : new Image { Source = "productimage.png", HeightRequest = 30, WidthRequest = 30 },
+                                imageid: product.ImageID
                             ));
                     }
                     Setup(shells, typeof(Product), savetype);
@@ -58,16 +77,47 @@ namespace comal.timesheets
 
                             shells.Add(new DataGridViewModelItem
                                 (
-                                    row.Get<Product, Guid>(x => x.ID),
-                                    tuples,
-                                    row.Get<Product, Guid>(x => x.Image.ID) == Guid.Empty ? new Image() : new Image { Source = "productimage.png", HeightRequest = 30, WidthRequest = 30 }
+                                    id: row.Get<Product, Guid>(x => x.ID),
+                                    data: tuples,
+                                    image: row.Get<Product, Guid>(x => x.Image.ID) == Guid.Empty ? new Image() : new Image { Source = "productimage.png", HeightRequest = 30, WidthRequest = 30 },
+                                    imageid: row.Get<Product, Guid>(x => x.Image.ID)
                                 ));
                         }
-
-                        Setup(shells, typeof(Product), savetype); 
+                        Setup(shells, typeof(Product), savetype);
                     }
                 }
-            });           
+            });
+        }
+
+        public async void DisplayOptions(DataGridViewModelItem item)
+        {
+            ProductShell product = GlobalVariables.ProductShells.FirstOrDefault(x => x.ID == item.ID);
+            ListSelectionPage page = new ListSelectionPage(new List<String> { "View Holdings", "View Movements" });
+            page.OnSimpleListTapped += ((chosenOption) => 
+            {
+                Device.BeginInvokeOnMainThread(() => 
+                {
+                    switch (chosenOption)
+                    {
+                        case "Cancel":
+                            return;
+                        case "View Holdings":
+                            HoldingViewer holdingViewer = new HoldingViewer(product.ID, product.Name, product.ImageID);
+                            holdingViewer.OnExitSelected += () =>
+                            {
+                                Navigation.PopAsync();
+                            };
+                            Navigation.PushAsync(holdingViewer);
+                            break;
+                        case "View Movements":
+                            MovementViewer movementViewer = new MovementViewer(product.ID, product.Name);
+                            Navigation.PushAsync(movementViewer);
+                            break;
+                        default: break;
+                    }
+                });               
+            });
+            Navigation.PushAsync(page);
         }
     }
 }

+ 1 - 0
prs.mobile/comal.timesheets/comal.timesheets.projitems

@@ -217,6 +217,7 @@
       <DependentUpon>ListSelectionPage.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="$(MSBuildThisFileDirectory)EquipmentGrid.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Equipment\EquipmentDetailsDataModel.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Equipment\EquipmentDetailsPage.xaml.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Equipment\EquipmentList.xaml.cs" />