public void DateTime() { var f1 = new FieldDate("Min date", "Minimum date", System.DateTime.Now.Date, true); var f2 = new FieldDate("Max date", "Maximum date", System.DateTime.Now.AddMonths(1).Date, true); var f3 = new FieldTime("Min time", "Minimum time", new System.DateTime(1899, 12, 30), true); var f4 = new FieldTime("Max time", "Maximum time", new System.DateTime(1899, 12, 30).AddSeconds(86399), true); var f5 = new FieldCheckBox("Generate unique values", "", false, true); new InputBox(_excelapp, "Random date-time generation", f1, f2, f3, f4, f5, _fnb).Show(delegate { System.DateTime minDate = f1.Value, maxDate = f2.Value; System.DateTime minTime = f3.Value, maxTime = f4.Value; var maxDays = (int)(maxDate - minDate).TotalDays + 1; var maxSeconds = (int)(maxTime - minTime).TotalSeconds + 1; var random = new Random(); string format = _culture.DateTimeFormat.ShortDatePattern + " HH:mm"; var gen = new Generator(f5.Value, () => minDate.AddDays(random.Next(maxDays)).AddSeconds(random.Next(maxSeconds))); if (_singlesel) CellsOperator.AddDataToRange(_range, (int)_fnb.Value, format, (ref object value) => { value = gen.Next(); }); else new CellsOperator(_range, true).ForEachValue(format, (ref object value) => { value = gen.Next(); }); }); }
public void Date() { var f1 = new FieldDate("Min date", "Minimum date", System.DateTime.Now.Date, true); var f2 = new FieldDate("Max date", "Maximum date", System.DateTime.Now.AddYears(1).Date, true); var f3 = new FieldCheckBox("Generate unique values", "", false, true); new InputBox(_excelapp, "Random time generation", f1, f2, f3, _fnb).Show(delegate { var minDate = f1.Value; var maxDate = f2.Value; int maxDays = (int)(maxDate - minDate).TotalDays + 1; var unique = f3.Value; string format = "m/d/yyyy"; var random = new Random(); var gen = new Generator(f3.Value, () => minDate.AddDays(random.Next(maxDays))); if (_singlesel) CellsOperator.AddDataToRange(_range, (int)_fnb.Value, format, (ref object value) => { value = gen.Next(); }); else new CellsOperator(_range, true).ForEachValue(format, (ref object value) => { value = gen.Next(); }); }); }