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; }
/// <summary> /// Получает список идентификаторов неиспользованных ключей. Для корпоративных и электронных лицензий возвращает все ключи, для локальных только неиспользованные /// </summary> /// <param name="idLicense">Идентификатор лицензии</param> /// <returns>Список идентификаторов ключей</returns> public static IEnumerable <int> LicKeyIdsNotUsed(int idLicense) { return(from licenseKeyRow in FilterRows(SoftLicKeysDataModel.GetInstance().Select()) join licenseRow in FilterRows(SoftLicensesDataModel.GetInstance().Select()) on licenseKeyRow.Field <int?>("ID License") equals licenseRow.Field <int?>("ID License") join licenseTypeRow in FilterRows(SoftLicTypesDataModel.GetInstance().Select()) on licenseRow.Field <int?>("ID LicType") equals licenseTypeRow.Field <int?>("ID LicType") join installationRow in FilterRows(SoftInstallationsDataModel.GetInstance().Select()) on licenseKeyRow.Field <int?>("ID LicenseKey") equals installationRow.Field <int?>("ID LicenseKey") into jg from jgRow in jg.DefaultIfEmpty() where licenseKeyRow.Field <int?>("ID License") == idLicense && (jgRow == null || licenseTypeRow.Field <bool?>("LicKeyDuplicateAllowed") == true) select licenseKeyRow.Field <int>("ID LicenseKey")); }
protected override void Calculate(object sender, System.ComponentModel.DoWorkEventArgs e) { DmLoadState = DataModelLoadState.Loading; if (e == null) { throw new DataModelException("Не передана ссылка на объект DoWorkEventArgs в классе CalcDataModelLicensesConcat"); } var config = (CalcAsyncConfig)e.Argument; // Фильтруем удаленные строки var licenses = DataModelHelper.FilterRows(SoftLicensesDataModel.GetInstance().Select(), config.Entity, config.IdObject); var licKeys = DataModelHelper.FilterRows(SoftLicKeysDataModel.GetInstance().Select(), config.Entity, config.IdObject); // Вычисляем агрегационную информацию var result = from licensesRow in licenses join licKeyRow in licKeys on licensesRow.Field <int>("ID License") equals licKeyRow.Field <int>("ID License") select new { id_lickey = licKeyRow.Field <int>("ID LicenseKey"), id_license = licensesRow.Field <int>("ID License"), lickey = string.Format("{0} (в/н лицензии: {1}; срок действия: №{2} от {3})", licKeyRow.Field <string>("LicKey"), licensesRow.Field <int>("ID License"), licensesRow.Field <string>("DocNumber") ?? "б/н", licensesRow.Field <DateTime>("BuyLicenseDate").ToString("dd.MM.yyyy", CultureInfo.InvariantCulture) + (licensesRow.Field <DateTime?>("ExpireLicenseDate") == null ? " (бессрочно)" : " по " + licensesRow.Field <DateTime>("ExpireLicenseDate").ToString("dd.MM.yyyy", CultureInfo.InvariantCulture)) ) }; // Заполняем таблицу изменений var table = InitializeTable(); table.BeginLoadData(); result.ToList().ForEach(x => { table.Rows.Add(x.id_lickey, x.id_license, x.lickey); }); table.EndLoadData(); if (!DataSetManager.DataSet.Tables.Contains(TableName)) { DataSetManager.AddTable(table); } else { DataSetManager.DataSet.Merge(table); } // Возвращаем результат e.Result = table; }
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 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(); }