public static DateTimeColumnProperties Load(MainDataSet.DynamicColumnsRow row) { DateTimeColumnProperties result = null; /////////////////////////////////////////////////////////////////////////////// if (row != null && !row.IsPropertiesNull()) { var propsJson = row.Properties; if (!String.IsNullOrEmpty(propsJson)) { result = JsonConvert.DeserializeObject <DateTimeColumnProperties>(propsJson); } } /////////////////////////////////////////////////////////////////////////////// if (result == null) { result = new DateTimeColumnProperties { Format = DateTimeColumnFormat.DateOnly, DateFormat = "MM/dd/yy", TimeFormat = "HH:mm:ss (24-hour clock)" }; } /////////////////////////////////////////////////////////////////////////////// return(result); }
public FormEditColumnDateTime(DateTimeColumnProperties props) { InitializeComponent(); _props = props; this.BackColor = MainForm.ColorBackground; }
public string SaveProps() { var props = new DateTimeColumnProperties(); if (rdbDateOnly.Checked) { props.Format = DateTimeColumnFormat.DateOnly; } else if (rdbTimeOnly.Checked) { props.Format = DateTimeColumnFormat.TimeOnly; } else { props.Format = DateTimeColumnFormat.DateTime; } props.DateFormat = cmbDateFormat.Text; props.TimeFormat = cmbTimeFormat.Text; return(props.Save()); }
protected void LoadProps(MainDataSet.DynamicColumnsRow dynamicColumnsRow) { try { var props = DateTimeColumnProperties.Load(dynamicColumnsRow); switch (props.Format) { case DateTimeColumnFormat.DateOnly: rdbDateOnly.Checked = true; break; case DateTimeColumnFormat.TimeOnly: rdbTimeOnly.Checked = true; break; case DateTimeColumnFormat.DateTime: rdbDateTime.Checked = true; break; } if (!String.IsNullOrEmpty(props.DateFormat)) { cmbDateFormat.Text = props.DateFormat; } if (!String.IsNullOrEmpty(props.TimeFormat)) { cmbTimeFormat.Text = props.TimeFormat; } } catch (Exception ex) { MainForm.ShowExceptionMessage(ex); } }
protected bool DoChangeColumnType(BackgroundWorker worker, object arg) { try { _views.MainForm.sourceDocuments.RaiseListChangedEvents = false; worker.ReportProgress(0); var sourceDynamicColumnRow = (MainDataSet.DynamicColumnsRow)arg; var sourceDynamicColumnID = sourceDynamicColumnRow.ID; var sourceColumnTitle = sourceDynamicColumnRow.Title; var sourceColumnType = (DynamicColumnType)sourceDynamicColumnRow.Type; var sourceColumnIndex = _views.MainForm.datasetMain.Documents.Columns[sourceDynamicColumnRow.Title].Ordinal; var tempColumnName = GetTempColumnName(sourceDynamicColumnRow.Title); var tempColumnInfo = _views.MainForm.adapterDocuments.AddDynamicColumn(tempColumnName, DynamicColumnType.FreeText, true); var tempColumnIndex = _views.MainForm.datasetMain.Documents.Columns[tempColumnName].Ordinal; var primaryKeyColumnIndex = _views.MainForm.datasetMain.Documents.Columns[_views.MainForm.adapterDocuments.PrimaryKeyColumnName].Ordinal; var numericFormat = String.Empty; var dateFormat = String.Empty; if (sourceColumnType == DynamicColumnType.Numeric) { var props = NumericColumnProperties.Load(sourceDynamicColumnRow); numericFormat = props.GetFormatString(); } else if (sourceColumnType == DynamicColumnType.DateTime) { var props = DateTimeColumnProperties.Load(sourceDynamicColumnRow); dateFormat = props.GetFormatString(); } var totalCount = (double)_views.MainForm.datasetMain.Documents.Count; var counter = 0; var documentsUpdated = false; foreach (var row in _views.MainForm.datasetMain.Documents) { if (!row.IsNull(sourceColumnIndex)) { var primaryKey = row[primaryKeyColumnIndex]; var formattedValue = String.Empty; if (sourceColumnType == DynamicColumnType.Numeric) { var value = row[sourceColumnIndex]; if (value is double) { formattedValue = ((double)value).ToString(numericFormat); } else if (value is decimal) { formattedValue = ((decimal)value).ToString(numericFormat); } else if (value is int) { formattedValue = ((int)value).ToString(numericFormat); } } else if (sourceColumnType == DynamicColumnType.DateTime) { var value = (DateTime)row[sourceColumnIndex]; formattedValue = value.ToString(dateFormat); } else { formattedValue = Convert.ToString(row[sourceColumnIndex]); } _views.MainForm.adapterDocuments.SqlSetColumnValueByPrimaryKey(tempColumnName, formattedValue, primaryKey); row[tempColumnIndex] = formattedValue; documentsUpdated = true; } counter++; if (counter % 50 == 0) { var progress = (int)((counter / totalCount) * 100d); worker.ReportProgress(progress); } } if (documentsUpdated) { _views.MainForm.datasetMain.Documents.AcceptChanges(); _needReloadDocuments = true; } /////////////////////////////////////////////////////////////////////////////// _views.MainForm.adapterDocuments.DeleteColumn(sourceColumnTitle, true); _views.MainForm.adapterDocuments.RenameDynamicColumn(tempColumnName, sourceColumnTitle, sourceDynamicColumnID, true); sourceDynamicColumnRow.Type = (int)DynamicColumnType.FreeText; sourceDynamicColumnRow.SetPropertiesNull(); _views.MainForm.adapterDynamicColumns.Update(sourceDynamicColumnRow); if (sourceColumnType == DynamicColumnType.Category) { _views.MainForm.datasetMain.DynamicColumnCategories.Where(x => x.DynamicColumnID == sourceDynamicColumnID).ToList().ForEach(x => x.Delete()); _views.MainForm.adapterDynamicColumnCategories.Update(_views.MainForm.datasetMain.DynamicColumnCategories); _views.MainForm.adapterDynamicColumnCategories.Fill(_views.MainForm.datasetMain.DynamicColumnCategories); } return(true); } catch (Exception ex) { MainForm.ShowExceptionMessage(ex); } finally { _views.MainForm.sourceDocuments.RaiseListChangedEvents = true; } return(false); }