|
@@ -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);
|