protected void LoadProps(MainDataSet.DynamicColumnsRow dynamicColumnsRow)
        {
            try
            {
                var props = NumericColumnProperties.Load(dynamicColumnsRow);

                if (props.IsDecimal)
                {
                    rdbDecimal.Checked = true;
                }
                else
                {
                    rdbInteger.Checked = true;
                }

                txtMinimum.Value = props.Min;
                txtMaximum.Value = props.Max;

                txtDecimalPlaces.Value = props.DecimalPlaces;

                UpdateControls();
            }
            catch (Exception ex)
            {
                MainForm.ShowExceptionMessage(ex);
            }
        }
        public static NumericColumnProperties Load(MainDataSet.DynamicColumnsRow row)
        {
            NumericColumnProperties result = null;

            ///////////////////////////////////////////////////////////////////////////////

            if (row != null && !row.IsPropertiesNull())
            {
                var propsJson = row.Properties;
                if (!String.IsNullOrEmpty(propsJson))
                {
                    result = JsonConvert.DeserializeObject <NumericColumnProperties>(propsJson);
                }
            }

            ///////////////////////////////////////////////////////////////////////////////

            if (result == null)
            {
                result = new NumericColumnProperties
                {
                    IsDecimal     = false,
                    DecimalPlaces = 1
                };
            }

            return(result);
        }
        public FormEditColumnNumeric(NumericColumnProperties props)
        {
            InitializeComponent();

            _props = props;

            txtValue.Minimum = Decimal.MinValue;
            txtValue.Maximum = Decimal.MaxValue;

            this.BackColor = MainForm.ColorBackground;
        }
        public string SaveProps()
        {
            var props = new NumericColumnProperties();

            props.IsDecimal     = rdbDecimal.Checked;
            props.Min           = txtMinimum.Value;
            props.Max           = txtMaximum.Value;
            props.DecimalPlaces = (int)txtDecimalPlaces.Value;

            if (props.Max < props.Min)
            {
                props.Max = props.Min;
            }

            return(props.Save());
        }
Ejemplo n.º 5
0
        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);
        }