public override void LoadData()
        {
            dataGridView.AutoGenerateColumns = false;
            DockAreas    = WeifenLuo.WinFormsUI.Docking.DockAreas.Document;
            _softLicKeys = SoftLicKeysDataModel.GetInstance();
            // Дожидаемся дозагрузки данных, если это необходимо
            _softLicKeys.Select();

            _vSoftLicKeys = new BindingSource
            {
                DataMember = "SoftLicKeys",
                Filter     = StaticFilter
            };
            if (!string.IsNullOrEmpty(StaticFilter) && !String.IsNullOrEmpty(DynamicFilter))
            {
                _vSoftLicKeys.Filter += " AND ";
            }
            _vSoftLicKeys.Filter    += DynamicFilter;
            _vSoftLicKeys.DataSource = DataSetManager.DataSet;

            if (ParentRow != null && ParentType == ParentTypeEnum.License)
            {
                Text = string.Format(CultureInfo.InvariantCulture, "Лицензионные ключи лицензии №{0}", ParentRow["ID License"]);
            }
            else
            {
                throw new ViewportException("Неизвестный тип родительского объекта");
            }

            //Инициируем колонки snapshot-модели
            for (var i = 0; i < _softLicKeys.Select().Columns.Count; i++)
            {
                _snapshotsoftLicKeys.Columns.Add(new DataColumn(_softLicKeys.Select().Columns[i].ColumnName, _softLicKeys.Select().Columns[i].DataType));
            }
            //Загружаем данные snapshot-модели из original-view
            for (var i = 0; i < _vSoftLicKeys.Count; i++)
            {
                _snapshotsoftLicKeys.Rows.Add(DataRowViewToArray(((DataRowView)_vSoftLicKeys[i])));
            }
            _vSnapshotSoftLicKeys = new BindingSource {
                DataSource = _snapshotsoftLicKeys
            };
            _vSnapshotSoftLicKeys.CurrentItemChanged += v_snapshotLicKeys_CurrentItemChanged;

            dataGridView.DataSource       = _vSnapshotSoftLicKeys;
            idLicenseKey.DataPropertyName = "ID LicenseKey";
            idLicense.DataPropertyName    = "ID License";
            LicKey.DataPropertyName       = "LicKey";
            dataGridView.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
            dataGridView.CellValidated += dataGridView_CellValidated;
            //События изменения данных для проверки соответствия реальным данным в модели
            dataGridView.CellValueChanged += dataGridView_CellValueChanged;
            //Синхронизация данных исходные->текущие
            _softLicKeys.Select().RowChanged  += SoftLicKeysViewport_RowChanged;
            _softLicKeys.Select().RowDeleting += SoftLicKeysViewport_RowDeleting;
            _softLicKeys.Select().RowDeleted  += SoftLicKeysViewport_RowDeleted;
        }
        public override void SaveRecord()
        {
            dataGridView.EndEdit();
            _syncViews = false;
            var list = SoftLicKeysFromViewport();

            if (!ValidateSoftLicKeys(list))
            {
                _syncViews = true;
                return;
            }
            for (var i = 0; i < list.Count; i++)
            {
                var row = _softLicKeys.Select().Rows.Find(list[i].IdLicenseKey);
                if (row == null)
                {
                    var idLicKey = SoftLicKeysDataModel.Insert(list[i]);
                    if (idLicKey == -1)
                    {
                        _syncViews = true;
                        return;
                    }
                    ((DataRowView)_vSnapshotSoftLicKeys[i])["ID LicenseKey"] = idLicKey;
                    _softLicKeys.Select().Rows.Add(DataRowViewToArray((DataRowView)_vSnapshotSoftLicKeys[i]));
                }
                else
                {
                    var softLicKeyFromView = RowToSoftLicKey(row);
                    if (softLicKeyFromView == list[i])
                    {
                        continue;
                    }
                    if (SoftLicKeysDataModel.Update(list[i]) == -1)
                    {
                        _syncViews = true;
                        return;
                    }
                    row["ID License"] = list[i].IdLicense == null ? DBNull.Value : (object)list[i].IdLicense;
                    row["LicKey"]     = list[i].LicKey == null ? DBNull.Value : (object)list[i].LicKey;
                }
            }
            list = SoftLicKeysFromView();
            for (var i = 0; i < list.Count; i++)
            {
                var rowIndex = -1;
                for (var j = 0; j < dataGridView.Rows.Count; j++)
                {
                    if ((dataGridView.Rows[j].Cells["idLicenseKey"].Value != null) &&
                        !string.IsNullOrEmpty(dataGridView.Rows[j].Cells["idLicenseKey"].Value.ToString()) &&
                        ((int)dataGridView.Rows[j].Cells["idLicenseKey"].Value == list[i].IdLicenseKey))
                    {
                        rowIndex = j;
                    }
                }
                if (rowIndex != -1)
                {
                    continue;
                }
                if (SoftLicKeysDataModel.Delete(list[i].IdLicenseKey.Value) == -1)
                {
                    _syncViews = true;
                    return;
                }
                _softLicKeys.Select().Rows.Find(list[i].IdLicenseKey).Delete();
            }
            _syncViews = true;
            MenuCallback.EditingStateUpdate();
        }