Example #1
0
 protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
 {
     if (SnapshotHasChanges())
     {
         var result = MessageBox.Show(@"Сохранить изменения в базу данных?", @"Внимание",
                                      MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
         if (result == DialogResult.Yes)
         {
             SaveRecord();
         }
         else
         if (result == DialogResult.No)
         {
             CancelRecord();
         }
         else
         {
             e.Cancel = true;
             return;
         }
     }
     _softLicTypes.Select().RowChanged  -= SoftLicTypesViewport_RowChanged;
     _softLicTypes.Select().RowDeleting -= SoftLicTypesViewport_RowDeleting;
     _softLicTypes.Select().RowDeleted  -= SoftLicTypesViewport_RowDeleted;
     base.OnClosing(e);
 }
Example #2
0
        public override void LoadData()
        {
            dataGridView.AutoGenerateColumns = false;
            DockAreas     = WeifenLuo.WinFormsUI.Docking.DockAreas.Document;
            _softLicTypes = SoftLicTypesDataModel.GetInstance();

            //Ожидаем дозагрузки данных, если это необходимо
            _softLicTypes.Select();

            _vSoftLicTypes = new BindingSource
            {
                DataMember = "SoftLicTypes",
                DataSource = DataSetManager.DataSet
            };

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

            dataGridView.DataSource        = _vSnapshotSoftLicTypes;
            idSoftLicType.DataPropertyName = "ID LicType";
            softLicType.DataPropertyName   = "LicType";
            softLicKeyDuplicateAllowed.DataPropertyName = "LicKeyDuplicateAllowed";

            dataGridView.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

            dataGridView.CellValidated += dataGridView_CellValidated;
            //События изменения данных для проверки соответствия реальным данным в модели
            dataGridView.CellValueChanged += dataGridView_CellValueChanged;
            //Синхронизация данных исходные->текущие
            _softLicTypes.Select().RowChanged  += SoftLicTypesViewport_RowChanged;
            _softLicTypes.Select().RowDeleting += SoftLicTypesViewport_RowDeleting;
            _softLicTypes.Select().RowDeleted  += SoftLicTypesViewport_RowDeleted;
        }