private void FillDataSourceWithData(TestCrudDataSource dataSource, int numRecords) { var titles = new [] { "Mr", "Sir", "Dr", "Ms", "Mrs", "Miss" }; for (var i = 0; i < numRecords; i++) { var employee = new Employee { ID = i, Title = titles.Randomize().First(), FirstName = Tools.Text.GenerateRandomString(Tools.Maths.RandomNumberGenerator.Next(3, 12)), LastName = Tools.Text.GenerateRandomString(Tools.Maths.RandomNumberGenerator.Next(3, 12)), DateOfBirth = new DateTime(1900 + Tools.Maths.RandomNumberGenerator.Next(0, 100), Tools.Maths.RandomNumberGenerator.Next(1, 13), Tools.Maths.RandomNumberGenerator.Next(1, 29)), Salary = Tools.Maths.Gamble(0.1) ? null : (decimal?)Tools.Maths.RandomNumberGenerator.Next(20000, 200000), UIntField = (uint)Tools.Maths.RandomNumberGenerator.Next(0, 1000), Supervisor = Tools.Maths.Gamble(0.5) ? true : false, StartWorkTime = DateTime.Today.AddHours(Tools.Maths.RandomNumberGenerator.Next(10, 20)) }; if (Tools.Maths.Gamble(0.9)) { employee.Address = new Address { Street = string.Format("{0} {1} {2}", RandomStreetNumber(), RandomStreetName(), RandomStreetType()), City = RandomCity(), State = RandomState(), PostCode = RandomPostCode() }; } dataSource.Create(employee); foreach (var x in dataSource.AllEmployees) { x.Manager = dataSource.RandomEmployee(); } } }
public CrudTestForm() { InitializeComponent(); _textWriter = new TextBoxWriter(_outputTextBox); _flagsCheckedListBox.EnumType = typeof(CrudCapabilities); _flagsCheckedListBox.SelectedEnum = CrudCapabilities.Default; _gridBindings = new[] { new CrudGridColumn <Employee> { ColumnName = "ID", SortName = "ID", PropertyValue = e => e.ID, DataType = typeof(int), DisplayType = CrudCellDisplayType.Text, CanEditCell = false }, new CrudGridColumn <Employee> { ColumnName = "Name", SortName = "Name", DataType = typeof(string), PropertyValue = e => string.Format("{0} {1} {2}", e.Title ?? string.Empty, e.FirstName ?? string.Empty, e.LastName ?? string.Empty), DisplayType = CrudCellDisplayType.Text, ExpandsToFit = false, CanEditCell = false }, new CrudGridColumn <Employee> { ColumnName = "DOB", SortName = "DateOfBirth", DataType = typeof(DateTime), PropertyValue = e => e.DateOfBirth, DisplayType = CrudCellDisplayType.Date, DateTimeFormat = (x) => "dd/MM/yyyy", CanEditCell = true, SetPropertyValue = (e, o) => e.DateOfBirth = (DateTime)o }, new CrudGridColumn <Employee> { ColumnName = "Salary", SortName = "Salary", DataType = typeof(decimal), PropertyValue = e => e.Salary, DisplayType = CrudCellDisplayType.Currency, CanEditCell = true, SetPropertyValue = (e, o) => e.Salary = (decimal)o }, new CrudGridColumn <Employee> { ColumnName = "Unsigned Int Field", SortName = "UIntField", DataType = typeof(uint), PropertyValue = e => e.UIntField, DisplayType = CrudCellDisplayType.Numeric, CanEditCell = true, SetPropertyValue = (e, o) => e.UIntField = (uint)o }, new CrudGridColumn <Employee> { ColumnName = "Supervisor", SortName = "Supervisor", DataType = typeof(bool), PropertyValue = e => e.Supervisor, DisplayType = CrudCellDisplayType.Boolean, CanEditCell = true, SetPropertyValue = (e, o) => e.Supervisor = (bool)o }, new CrudGridColumn <Employee> { ColumnName = "StartWorkTime", SortName = "StartWorkTime", DataType = typeof(DateTime), PropertyValue = e => e.StartWorkTime, DisplayType = CrudCellDisplayType.Time, DateTimeFormat = (x) => "HH:mm:ss.fff", CanEditCell = true, SetPropertyValue = (e, o) => e.StartWorkTime = (DateTime)o }, new CrudGridColumn <Employee> { ColumnName = "Address", SortName = "Address", DataType = typeof(string), PropertyHasValue = e => e.Address != null, PropertyValue = e => string.Format("{0} {1} {2}, {3}", e.Address.Street, e.Address.City, e.Address.State, e.Address.PostCode), DisplayType = CrudCellDisplayType.Text, ExpandsToFit = true, CanEditCell = false }, new CrudGridColumn <Employee> { ColumnName = "Notes", SortName = "Notes", DataType = typeof(string), PropertyValue = e => e.Notes, DisplayType = CrudCellDisplayType.Text, ExpandsToFit = true, CanEditCell = true, SetPropertyValue = (e, o) => e.Notes = o as string }, new CrudGridColumn <Employee> { ColumnName = "Manager", SortName = "Manager", DataType = typeof(Employee), PropertyValue = e => e.Manager, DisplayType = CrudCellDisplayType.DropDownList, DropDownItems = (x) => _dataSource.RandomSet().Cast <object>(), DropDownItemDisplayMember = "FirstName", ExpandsToFit = true, CanEditCell = true, SetPropertyValue = (e, o) => e.Manager = (Employee)o }, new CrudGridColumn <Employee> { DisplayType = CrudCellDisplayType.EditCommand, } }; _crudGrid.GridBindings = _gridBindings; _crudGrid.Capabilities = (CrudCapabilities)_flagsCheckedListBox.SelectedEnum; _dataSource = new TestCrudDataSource(); FillDataSourceWithData(_dataSource, 1000); _crudGrid.SetDataSource(_dataSource); _crudComboBox.DisplayMember = (o) => ((Employee)o).FirstName; _crudComboBox.SetCrudParameters(_gridBindings, null, (CrudCapabilities)_flagsCheckedListBox.SelectedEnum, _dataSource, autoPageSize: _autoSizeCheckBox.Checked); }