/// <summary> /// Compares this item's column to another DataGridItem's column. /// </summary> /// <param name="row">DataGridItem object.</param> /// <param name="columnIndex">Column index.</param> /// <returns>Number indicating how it should be positioned.</returns> public int CompareTo(DataGridItem row, int columnIndex) { switch (DataType[columnIndex]) { case "System.Float": float _float = (float)Data[columnIndex] - (float)row.Data[columnIndex]; if (_float > 0) return 1; else if (_float < 0) return -1; else return 0; case "System.Int16": return (Int16)Data[columnIndex] - (Int16)row.Data[columnIndex]; case "System.Int32": return (Int32)Data[columnIndex] - (Int32)row.Data[columnIndex]; case "System.Int64": Int64 _int64 = (Int64)Data[columnIndex] - (Int64)row.Data[columnIndex]; if (_int64 > 0) return 1; else if (_int64 < 0) return -1; else return 0; case "System.String": return ((string)Data[columnIndex]).CompareTo((string)row.Data[columnIndex]); case "System.UInt16": return (UInt16)Data[columnIndex] - (UInt16)row.Data[columnIndex]; case "System.UInt32": UInt32 _uInt32 = (UInt32)Data[columnIndex] - (UInt32)row.Data[columnIndex]; if (_uInt32 > 0) return 1; else if (_uInt32 < 0) return -1; else return 0; case "System.UInt64": UInt64 _uInt64 = (UInt64)Data[columnIndex] - (UInt64)row.Data[columnIndex]; if (_uInt64 > 0) return 1; else if (_uInt64 < 0) return -1; else return 0; default: return 0; } }
public void ShowBooKForLoan() { Window window = (Window)windows[WindowsPosition.BOOK_LOAN]; DataGrid dataGrid = null; if (window == null) { window = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.book_loan_window)); windows.Add(WindowsPosition.BOOK_LOAN, window); Button borrowButton = (Button)window.GetChildByName("actionButton"); Button cancelButton = (Button)window.GetChildByName("cancelButton"); borrowButton.TapEvent += (o) => Controller.BorrowBook(); cancelButton.TapEvent += (o) => Controller.CancelLoanTransaction(); dataGrid = (DataGrid)window.GetChildByName("dataGrid"); DataGridColumn colLabels = new DataGridColumn("", 80); DataGridColumn colValue = new DataGridColumn("", 320 - colLabels.Width); DataGridItem titleItem = new DataGridItem(new string[] { "Title", null }); DataGridItem authorsItem = new DataGridItem(new string[] { "Authors", null }); DataGridItem publisherItem = new DataGridItem(new string[] { "Publisher", null }); DataGridItem ISBNItem = new DataGridItem(new string[] { "ISBN", null }); DataGridItem publicationDateItem = new DataGridItem(new string[] { "Published", null }); dataGrid.RowCount = 5; dataGrid.AddColumn(colLabels); dataGrid.AddColumn(colValue); dataGrid.AddItem(titleItem); dataGrid.AddItem(authorsItem); dataGrid.AddItem(publisherItem); dataGrid.AddItem(ISBNItem); dataGrid.AddItem(publicationDateItem); } BookCompositeType book = LibraryModelSingleton.Instance.Book; if (dataGrid == null) dataGrid = (DataGrid)window.GetChildByName("dataGrid"); dataGrid.SetCellData(1, 0, book.Title); dataGrid.SetCellData(1, 1, ConcatString(book.Authors.STRING)); dataGrid.SetCellData(1, 2, book.Publisher); dataGrid.SetCellData(1, 3, book.ISBN); dataGrid.SetCellData(1, 4, book.PublicationDate.ToString("yyyy")); Glide.MainWindow = window; }
/// <summary> /// Compares this item's column to another DataGridItem's column. /// </summary> /// <param name="row">DataGridItem object.</param> /// <param name="columnIndex">Column index.</param> /// <returns>Number indicating how it should be positioned.</returns> public int CompareTo(DataGridItem row, int columnIndex) { switch (DataType[columnIndex]) { case "System.Float": float _float = (float)Data[columnIndex] - (float)row.Data[columnIndex]; if (_float > 0) { return(1); } else if (_float < 0) { return(-1); } else { return(0); } case "System.Int16": return((Int16)Data[columnIndex] - (Int16)row.Data[columnIndex]); case "System.Int32": return((Int32)Data[columnIndex] - (Int32)row.Data[columnIndex]); case "System.Int64": Int64 _int64 = (Int64)Data[columnIndex] - (Int64)row.Data[columnIndex]; if (_int64 > 0) { return(1); } else if (_int64 < 0) { return(-1); } else { return(0); } case "System.String": return(((string)Data[columnIndex]).CompareTo((string)row.Data[columnIndex])); case "System.UInt16": return((UInt16)Data[columnIndex] - (UInt16)row.Data[columnIndex]); case "System.UInt32": UInt32 _uInt32 = (UInt32)Data[columnIndex] - (UInt32)row.Data[columnIndex]; if (_uInt32 > 0) { return(1); } else if (_uInt32 < 0) { return(-1); } else { return(0); } case "System.UInt64": UInt64 _uInt64 = (UInt64)Data[columnIndex] - (UInt64)row.Data[columnIndex]; if (_uInt64 > 0) { return(1); } else if (_uInt64 < 0) { return(-1); } else { return(0); } default: return(0); } }
/// <summary> /// Removes an item. /// </summary> /// <param name="dataGridItem">dataGridItem</param> public void RemoveItem(DataGridItem dataGridItem) { int index = _rows.IndexOf(dataGridItem); if (index > -1) RemoveItemAt(index); }
/// <summary> /// Adds an item at a specified index. /// </summary> /// <param name="index">index</param> /// <param name="dataGridItem">dataGridItem</param> public void AddItemAt(int index, DataGridItem dataGridItem) { if (dataGridItem.Data.Length != _columns.Count) throw new ArgumentException("The DataGridRow data length does not match the DataGrid's column count.", "dataGridRow"); if (_rows.Count == 0 || index == -1 || index > _rows.Count - 1) _rows.Add(dataGridItem); else _rows.Insert(index, dataGridItem); // A new row was added so we must re-render the items. _renderItems = true; // Calculate the max list Y position _listMaxY = _rows.Count * RowHeight; if (ShowHeaders) _listMaxY += RowHeight; _listMaxY -= Height; }
/// <summary> /// Adds an item. /// </summary> /// <param name="dataGridItem">dataGridItem</param> public void AddItem(DataGridItem dataGridItem) { AddItemAt(-1, dataGridItem); }
public void ShowBooKForReturning() { Window window = (Window)windows[WindowsPosition.BOOK_RET]; DataGrid dataGrid = null; if (window == null) { window = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.book_loan_window)); windows.Add(WindowsPosition.BOOK_RET, window); Button returnButton = (Button)window.GetChildByName("actionButton"); Button cancelButton = (Button)window.GetChildByName("cancelButton"); returnButton.Text = "Return"; returnButton.TapEvent += (o) => Controller.ReturnBook(); cancelButton.TapEvent += (o) => Controller.CancelReturnTransaction(); dataGrid = (DataGrid)window.GetChildByName("dataGrid"); DataGridColumn colLabels = new DataGridColumn("", 80); DataGridColumn colValue = new DataGridColumn("", 320 - colLabels.Width); DataGridItem titleItem = new DataGridItem(new string[] { "Title", null }); DataGridItem publisherItem = new DataGridItem(new string[] { "Publisher", null }); DataGridItem ISBNItem = new DataGridItem(new string[] { "ISBN", null }); DataGridItem startDateItem = new DataGridItem(new string[] { "Start date", null }); DataGridItem dueDateItem = new DataGridItem(new string[] { "Due date", null }); dataGrid.RowCount = 5; dataGrid.AddColumn(colLabels); dataGrid.AddColumn(colValue); dataGrid.AddItem(titleItem); dataGrid.AddItem(publisherItem); dataGrid.AddItem(ISBNItem); dataGrid.AddItem(startDateItem); dataGrid.AddItem(dueDateItem); } BookCompositeType book = LibraryModelSingleton.Instance.Book; if (dataGrid == null) dataGrid = (DataGrid)window.GetChildByName("dataGrid"); dataGrid.SetCellData(1, 0, book.Title); dataGrid.SetCellData(1, 1, book.Publisher); dataGrid.SetCellData(1, 2, book.ISBN); dataGrid.SetCellData(1, 3, LibraryModelSingleton.Instance.StartDate.ToString("dd/MM/yyyy")); dataGrid.SetCellData(1, 4, LibraryModelSingleton.Instance.DueDate.ToString("dd/MM/yyyy")); Glide.MainWindow = window; }