Beispiel #1
0
        /// <summary>
        /// Set a string value to a cell in a row.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        /// <param name="cellValue"></param>
        /// <returns></returns>
        public bool SetCellValue(IGridRow row, IGridColumn column, string cellValue)
        {
            if (row == null || column == null || cellValue == null)
            {
                return(false);
            }

            // find the cell in the row, matching the column
            IGridCell cell = row.ListCell.Where(ce => ce.Column == column).FirstOrDefault();

            if (cell == null)
            {
                return(false);
            }

            // the cell must be string
            GridCellString cellValueString = cell as GridCellString;

            if (cellValueString == null)
            {
                return(false);
            }

            cellValueString.Content = cellValue;
            return(true);
        }
Beispiel #2
0
        private String GetValueFor(IGridRow row)
        {
            Object value;

            try
            {
                if (RenderValue != null)
                {
                    value = RenderValue(row.Model as T);
                }
                else
                {
                    value = ExpressionValue(row.Model as T);
                }
            }
            catch (NullReferenceException)
            {
                return(String.Empty);
            }

            if (value == null)
            {
                return(String.Empty);
            }

            if (Format == null)
            {
                return(value.ToString());
            }

            return(String.Format(Format, value));
        }
Beispiel #3
0
        /// <summary>
        /// Create a cell (for a row), depending on the column type.
        /// </summary>
        /// <param name="column"></param>
        /// <returns></returns>
        public IGridCell CreateCell(IDynDataGrid dataGrid, IGridColumn column, IGridRow row)
        {
            // create a cell matching the type of the column
            IGridColumnString colString = column as IGridColumnString;

            if (colString != null)
            {
                // set a default value
                return(new GridCellString(colString, row, "", dataGrid.GridCellChangedProvider));
            }

            //IGridColumnInt colInt = column as GridColumnInt;
            //if (colInt != null)
            //{
            //    // set a default value
            //    return new GridCellInt(colInt, 0);
            //}

            IGridColumnCheckBox colCheckBox = column as IGridColumnCheckBox;

            if (colCheckBox != null)
            {
                return(new GridCellCheckBox(colCheckBox, row, false, dataGrid.GridCellChangedProvider));
            }


            throw new Exception("Factory.CreateCell(): type not yet implemented.");
        }
Beispiel #4
0
        public override IHtmlContent ValueFor(IGridRow <object> row)
        {
            object value = GetValueFor(row);

            if (value == null)
            {
                return(HtmlString.Empty);
            }
            if (value is IHtmlContent)
            {
                return(value as IHtmlContent);
            }
            if (FormatExpression != null)
            {
                Format = FormatExpression.Invoke((T)row.Model);
            }
            if (RouteValues != null)
            {
                Format = $"<a href=\"{RouteValues.Invoke((T)row.Model)}\">{Format}</a>";
            }
            if (Format != null)
            {
                value = string.Format(Format, value);
            }
            if (IsEncoded)
            {
                return(new HtmlString(HtmlEncoder.Default.Encode(value.ToString())));
            }

            return(new HtmlString(value.ToString()));
        }
Beispiel #5
0
        public virtual IHtmlString ValueFor(IGridRow <Object> row)
        {
            Object value = GetValueFor(row);

            if (value == null)
            {
                return(MvcHtmlString.Empty);
            }

            if (value is IHtmlString content)
            {
                return(content);
            }

            if (Format != null)
            {
                value = String.Format(Format, value);
            }

            if (IsEncoded)
            {
                return(new HtmlString(WebUtility.HtmlEncode(value.ToString())));
            }

            return(new HtmlString(value.ToString()));
        }
Beispiel #6
0
        public virtual IHtmlContent ValueFor(IGridRow <Object> row)
        {
            Object?value = ColumnValueFor(row);

            if (value == null)
            {
                return(HtmlString.Empty);
            }

            if (value is IHtmlContent content)
            {
                return(content);
            }

            if (Format != null)
            {
                value = String.Format(Format, value);
            }

            if (IsEncoded)
            {
                return(new GridHtmlString(value.ToString()));
            }

            return(new HtmlString(value.ToString()));
        }
Beispiel #7
0
        /// <summary>
        /// Add a row data model to the grid UI, create a corresponding VM.
        /// The grid row must have cells.
        /// Use this method when you map your application dataGrid model to this component dataGrid model.
        /// </summary>
        /// <param name="gridRow"></param>
        /// <returns></returns>
        public IGridRowVM AddRow(IGridRow gridRow)
        {
            if (gridRow == null)
            {
                return(null);
            }

            // check the cells (basic check: just the number of cells)
            if (gridRow.ListCell.Count() != _collColumnGrid.Count)
            {
                return(null);
            }

            // the row should be present in the dataGrid model
            if (!_dynDataGrid.ListRow.Contains(gridRow))
            {
                return(null);
            }

            // add it to the view: create VM
            IGridRowVM rowVM = new GridRowVM(gridRow);

            _collDataRow.Add(rowVM);
            RaisePropertyChanged("CollDataRow");

            return(rowVM);
        }
Beispiel #8
0
        /// <summary>
        /// Set a bool value to a cell in a row.
        /// The cell can be a bool, a checkButton or a radioButton.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        /// <param name="cellValue"></param>
        /// <returns></returns>
        public bool SetCellValue(IGridRow row, IGridColumn column, bool cellValue)
        {
            if (row == null || column == null)
            {
                return(false);
            }

            // find the cell in the row, matching the column
            IGridCell cell = row.ListCell.Where(ce => ce.Column == column).FirstOrDefault();

            if (cell == null)
            {
                return(false);
            }

            // the cell must be a bool: can be checkbox, a radioButton
            GridCellCheckBox cellValueBool = cell as GridCellCheckBox;

            if (cellValueBool != null)
            {
                cellValueBool.Content = cellValue;
                return(true);
            }

            // TODO: others types: radioButton
            return(false);
        }
Beispiel #9
0
        private void CreateDataGrid(IDynDataGridFactory dynDataGridFactory)
        {
            DataGrid = new DynDataGrid();

            //----create columns
            IGridColumn columnKey;

            dynDataGridFactory.CreateColumn(DataGrid, GridColumnType.String, "Key", out columnKey);
            // this column cells are read-only
            columnKey.IsEditionReadOnly = true;

            IGridColumn columnValue;

            dynDataGridFactory.CreateColumn(DataGrid, GridColumnType.String, "Value", out columnValue);

            // col checkbox
            IGridColumn columnCheck;

            dynDataGridFactory.CreateColumn(DataGrid, GridColumnType.CheckBox, "Checked", out columnCheck);

            //----create a data row, with empty cells
            IGridRow row = DynDataGridFactory.CreateRowWithCells(DataGrid);

            //----create data cells
            DataGrid.SetCellValue(row, columnKey, "keyYes");
            DataGrid.SetCellValue(row, "Value", "Oui");
            // checked by default
            DataGrid.SetCellValue(row, "Checked", true);

            // test: search a column by the name
            //IGridColumn colFound = DataGrid.FindColumnByName("Key");
        }
Beispiel #10
0
        public bool AddRow(IGridRow row)
        {
            // check if the row columns match the datagrid columns
            // TODO:

            _listRow.Add(row);
            return(true);
        }
Beispiel #11
0
        public GridCellBase(IGridColumn column, IGridRow row, GridCellChangedProvider actionProvider)
        {
            Column = column;
            Row    = row;

            _gridCellChangedProvider = actionProvider;

            IsReadOnly = column.IsEditionReadOnly;
        }
Beispiel #12
0
        public override IHtmlString ValueFor(IGridRow row)
        {
            String value = GetValueFor(row);

            if (IsEncoded)
            {
                value = WebUtility.HtmlEncode(value);
            }

            return(new HtmlString(value));
        }
Beispiel #13
0
        /// <summary>
        /// Set a bool value to a cell in a row.
        /// The cell can be a bool, a checkButton or a radioButton.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="colName"></param>
        /// <param name="cellValue"></param>
        /// <returns></returns>
        public bool SetCellValue(IGridRow row, string colName, bool cellValue)
        {
            // find the column
            IGridColumn colum = _listColumn.Where(c => c.Name.Equals(colName)).FirstOrDefault();

            if (colum == null)
            {
                return(false);
            }

            return(SetCellValue(row, colum, cellValue));
        }
        /// <summary>
        /// A grid cell content has changed.
        /// </summary>
        /// <param name="cell"></param>
        private void GridCellChanged(IGridCell cell)
        {
            // coming here when a cell value is modified in the UI!
            // TODO:

            // get the row and the column where is placed the cell
            IGridRow    row    = cell.Row;
            IGridColumn column = cell.Column;

            // TODO: add your code here!!
            FootPageText = cell.Content.ToString();
            RaisePropertyChanged("FootPageText");
        }
Beispiel #15
0
        private Object GetValueFor(IGridRow <Object> row)
        {
            try
            {
                if (RenderValue != null)
                {
                    return(RenderValue(row.Model as T));
                }

                return(ExpressionValue(row.Model as T));
            }
            catch (NullReferenceException)
            {
                return(null);
            }
        }
Beispiel #16
0
        public override IHtmlContent ValueForKey(IGridRow <object> row)
        {
            object value = GetValueFor(row);

            if (value == null)
            {
                return(HtmlString.Empty);
            }
            if (value is IHtmlContent)
            {
                return(value as IHtmlContent);
            }
            if (IsEncoded)
            {
                return(new HtmlString(HtmlEncoder.Default.Encode(value.ToString())));
            }

            return(new HtmlString(value.ToString()));
        }
Beispiel #17
0
        private object GetValueFor(IGridRow <object> row)
        {
            try
            {
                if (RenderValue != null)
                {
                    return(RenderValue(row.Model as T));
                }
                if (ExpressionValue != null)
                {
                    return(ExpressionValue(row.Model as T));
                }

                return(row.Model.GetType().GetProperty(Name).GetValue(row.Model, null));
            }
            catch (NullReferenceException)
            {
                return(null);
            }
        }
Beispiel #18
0
        private Object GetValueFor(IGridRow <Object> row)
        {
            try
            {
                if (RenderValue != null)
                {
                    return(RenderValue(row.Model as T));
                }

                Type type = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue);
                if (type.GetTypeInfo().IsEnum)
                {
                    return(GetEnumValue(type, ExpressionValue(row.Model as T).ToString()));
                }

                return(ExpressionValue(row.Model as T));
            }
            catch (NullReferenceException)
            {
                return(null);
            }
        }
Beispiel #19
0
        private Object?ColumnValueFor(IGridRow <Object> row)
        {
            try
            {
                if (RenderValue != null)
                {
                    return(RenderValue((T)row.Model, row.Index));
                }

                Type type = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue);

                if (type.IsEnum)
                {
                    return(EnumValue(type, ExpressionValue((T)row.Model) !.ToString() !));
                }

                return(ExpressionValue((T)row.Model));
            }
            catch (NullReferenceException)
            {
                return(null);
            }
        }
Beispiel #20
0
 public abstract IHtmlString ValueFor(IGridRow <Object> row);
 /// <summary>
 /// Constructor.
 /// Provide the default (its a bool ).
 /// </summary>
 /// <param name="column"></param>
 /// <param name="value"></param>
 public GridCellCheckBox(IGridColumnCheckBox column, IGridRow row, bool value, GridCellChangedProvider actionProvider) : base(column, row, actionProvider)
 {
     Content = value;
 }
Beispiel #22
0
 public abstract IHtmlContent ValueForKey(IGridRow <object> row);
Beispiel #23
0
 public abstract IHtmlString ValueFor(IGridRow row);
Beispiel #24
0
 public abstract IHtmlContent ValueFor(IGridRow <Object> row);
Beispiel #25
0
 // remove the row from the datagrid
 public bool RemoveRow(IGridRow row)
 {
     _listRow.Remove(row);
     return(true);
 }
Beispiel #26
0
 public GridCellString(IGridColumnString column, IGridRow row, string value, GridCellChangedProvider actionProvider) : base(column, row, actionProvider)
 {
     Content = value;
 }
Beispiel #27
0
 public GridRowVM(IGridRow gridRow)
 {
     GridRow = gridRow;
 }