public override void LoadData() { dataGridView.AutoGenerateColumns = false; DockAreas = WeifenLuo.WinFormsUI.Docking.DockAreas.Document; _installators = SoftInstallatorsDataModel.GetInstance(); //Ожидаем дозагрузки данных, если это необходимо _installators.Select(); _vInstallators = new BindingSource { DataMember = "SoftInstallators", DataSource = DataSetManager.DataSet }; //Инициируем колонки snapshot-модели for (var i = 0; i < _installators.Select().Columns.Count; i++) { _snapshotInstallators.Columns.Add(new DataColumn( _installators.Select().Columns[i].ColumnName, _installators.Select().Columns[i].DataType)); } //Загружаем данные snapshot-модели из original-view for (var i = 0; i < _vInstallators.Count; i++) { _snapshotInstallators.Rows.Add(DataRowViewToArray((DataRowView)_vInstallators[i])); } _vSnapshotInstallators = new BindingSource { DataSource = _snapshotInstallators }; _vSnapshotInstallators.CurrentItemChanged += v_snapshotInstallators_CurrentItemChanged; dataGridView.DataSource = _vSnapshotInstallators; idInstallator.DataPropertyName = "ID Installator"; fullName.DataPropertyName = "fullName"; profession.DataPropertyName = "profession"; inactive.DataPropertyName = "inactive"; dataGridView.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged; dataGridView.CellValidated += dataGridView_CellValidated; //События изменения данных для проверки соответствия реальным данным в модели dataGridView.CellValueChanged += dataGridView_CellValueChanged; //Синхронизация данных исходные->текущие _installators.Select().RowChanged += InstallatorsViewport_RowChanged; _installators.Select().RowDeleting += InstallatorsViewport_RowDeleting; _installators.Select().RowDeleted += InstallatorsViewport_RowDeleted; }
private void PreLoadData() { toolStripProgressBar.Maximum = 13; DepartmentsDataModel.GetInstance(toolStripProgressBar, 1); DevicesDataModel.GetInstance(toolStripProgressBar, 1); SoftwareDataModel.GetInstance(toolStripProgressBar, 1); SoftVersionsDataModel.GetInstance(toolStripProgressBar, 1); SoftInstallationsDataModel.GetInstance(toolStripProgressBar, 1); SoftInstallatorsDataModel.GetInstance(toolStripProgressBar, 1); SoftLicDocTypesDataModel.GetInstance(toolStripProgressBar, 1); SoftLicensesDataModel.GetInstance(toolStripProgressBar, 1); SoftLicKeysDataModel.GetInstance(toolStripProgressBar, 1); SoftLicTypesDataModel.GetInstance(toolStripProgressBar, 1); SoftMakersDataModel.GetInstance(toolStripProgressBar, 1); SoftSuppliersDataModel.GetInstance(toolStripProgressBar, 1); SoftTypesDataModel.GetInstance(toolStripProgressBar, 1); }
public SearchInstallationsForm() { InitializeComponent(); var softMakers = SoftMakersDataModel.GetInstance(); var softTypes = SoftTypesDataModel.GetInstance(); var softSuppliers = SoftSuppliersDataModel.GetInstance(); var softLicTypes = SoftLicTypesDataModel.GetInstance(); var softLicDocTypes = SoftLicDocTypesDataModel.GetInstance(); var departments = DepartmentsDataModel.GetInstance(); var softInstallators = SoftInstallatorsDataModel.GetInstance(); // Ожидаем дозагрузки, если это необходимо softMakers.Select(); softTypes.Select(); softSuppliers.Select(); softLicTypes.Select(); softLicDocTypes.Select(); departments.Select(); softInstallators.Select(); var vSoftMakers = new BindingSource { DataMember = "SoftMakers", DataSource = DataSetManager.DataSet }; var vSoftTypes = new BindingSource { DataMember = "SoftTypes", DataSource = DataSetManager.DataSet }; var vSoftSuppliers = new BindingSource { DataMember = "SoftSuppliers", DataSource = DataSetManager.DataSet }; var vSoftLicTypes = new BindingSource { DataMember = "SoftLicTypes", DataSource = DataSetManager.DataSet }; var vSoftLicDocTypes = new BindingSource { DataMember = "SoftLicDocTypes", DataSource = DataSetManager.DataSet }; _vDepartmentsInstall = new BindingSource { DataSource = departments.SelectVisibleDepartments() }; _vDepartmentsLic = new BindingSource { DataSource = departments.SelectVisibleDepartments() }; var vSoftInstallators = new BindingSource { DataMember = "SoftInstallators", DataSource = DataSetManager.DataSet }; comboBoxSoftwareMaker.DataSource = vSoftMakers; comboBoxSoftwareMaker.ValueMember = "ID SoftMaker"; comboBoxSoftwareMaker.DisplayMember = "SoftMaker"; comboBoxSupplierID.DataSource = vSoftSuppliers; comboBoxSupplierID.ValueMember = "ID Supplier"; comboBoxSupplierID.DisplayMember = "Supplier"; comboBoxSoftwareType.DataSource = vSoftTypes; comboBoxSoftwareType.ValueMember = "ID SoftType"; comboBoxSoftwareType.DisplayMember = "SoftType"; comboBoxLicType.DataSource = vSoftLicTypes; comboBoxLicType.ValueMember = "ID LicType"; comboBoxLicType.DisplayMember = "LicType"; comboBoxInstallator.DataSource = vSoftInstallators; comboBoxInstallator.ValueMember = "ID Installator"; comboBoxInstallator.DisplayMember = "FullName"; comboBoxLicDocType.DataSource = vSoftLicDocTypes; comboBoxLicDocType.ValueMember = "ID DocType"; comboBoxLicDocType.DisplayMember = "DocType"; comboBoxDepartmentLicID.DataSource = _vDepartmentsLic; comboBoxDepartmentLicID.ValueMember = "ID Department"; comboBoxDepartmentLicID.DisplayMember = "Department"; comboBoxDepartmentInstallID.DataSource = _vDepartmentsInstall; comboBoxDepartmentInstallID.ValueMember = "ID Department"; comboBoxDepartmentInstallID.DisplayMember = "Department"; comboBoxOpBuyLicenseDate.SelectedIndex = 0; comboBoxOpExpireLicenseDate.SelectedIndex = 0; comboBoxOpInstallDate.SelectedIndex = 0; foreach (Control control in Controls) { control.KeyDown += (sender, e) => { var comboBox = sender as ComboBox; if (comboBox != null && comboBox.DroppedDown) { return; } if (e.KeyCode == Keys.Enter) { vButtonSearch_Click(sender, e); } else if (e.KeyCode == Keys.Escape) { DialogResult = DialogResult.Cancel; } } } ; }
public override void SaveRecord() { dataGridView.EndEdit(); _syncViews = false; var list = InstallatorsFromViewport(); if (!ValidateViewportData(list)) { _syncViews = true; return; } for (var i = 0; i < list.Count; i++) { var row = _installators.Select().Rows.Find(list[i].IdInstallator ?? 0); if (row == null) { var idInstallator = SoftInstallatorsDataModel.Insert(list[i]); if (idInstallator == -1) { _syncViews = true; return; } ((DataRowView)_vSnapshotInstallators[i])["ID Installator"] = idInstallator; _installators.Select().Rows.Add(DataRowViewToArray((DataRowView)_vSnapshotInstallators[i])); } else { if (RowToInstallator(row) == list[i]) { continue; } if (SoftInstallatorsDataModel.Update(list[i]) == -1) { _syncViews = true; return; } row["FullName"] = list[i].FullName == null ? DBNull.Value : (object)list[i].FullName; row["Profession"] = list[i].Profession == null ? DBNull.Value : (object)list[i].Profession; row["Inactive"] = list[i].Inactive == null ? DBNull.Value : (object)list[i].Inactive; } } list = InstallatorsFromView(); 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["idInstallator"].Value != null) && !string.IsNullOrEmpty(dataGridView.Rows[j].Cells["idInstallator"].Value.ToString()) && ((int)dataGridView.Rows[j].Cells["idInstallator"].Value == list[i].IdInstallator)) { rowIndex = j; } } if (rowIndex != -1) { continue; } if (SoftInstallatorsDataModel.Delete(list[i].IdInstallator.Value) == -1) { _syncViews = true; return; } _installators.Select().Rows.Find(list[i].IdInstallator).Delete(); } _syncViews = true; MenuCallback.EditingStateUpdate(); }