예제 #1
0
 /// <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"));
 }
예제 #2
0
        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;
        }
예제 #3
0
 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);
 }
        private static bool EditingNewRecordModel(string table)
        {
            switch (table)
            {
            case "Software":
                return(SoftwareDataModel.GetInstance().EditingNewRecord);

            case "SoftLicenses":
                return(SoftLicensesDataModel.GetInstance().EditingNewRecord);

            case "SoftInstallations":
                return(SoftInstallationsDataModel.GetInstance().EditingNewRecord);

            default:
                return(false);
            }
        }
예제 #5
0
        public static IEnumerable <int> GetLicenseIDsByCondition(Func <DataRow, bool> condition, EntityType entity)
        {
            var software     = FilterRows(SoftwareDataModel.GetInstance().Select());
            var softVersions = FilterRows(SoftVersionsDataModel.GetInstance().Select());
            var departments  = from departmentsRow in FilterRows(DepartmentsDataModel.GetInstance().SelectVisibleDepartments())
                               where departmentsRow.Field <bool>("AllowSelect")
                               select departmentsRow.Field <int>("ID Department");

            var licenses = from licensesRow in FilterRows(SoftLicensesDataModel.GetInstance().Select())
                           where departments.Contains(licensesRow.Field <int>("ID Department"))
                           select licensesRow;
            var result = from softwareRow in software
                         join softVersionRow in softVersions
                         on softwareRow.Field <int>("ID Software") equals softVersionRow.Field <int>("ID Software")
                         join licensesRow in licenses
                         on softVersionRow.Field <int>("ID Version") equals licensesRow.Field <int>("ID Version")
                             where entity == EntityType.Software ? condition(softwareRow) :
                         entity == EntityType.SoftVersion ? condition(softVersionRow) :
                         entity == EntityType.License && condition(licensesRow)
                         select licensesRow.Field <int>("ID License");

            return(result);
        }
예제 #6
0
        internal override string GetFilter()
        {
            var        filter = "";
            List <int> includedSoftwareIds = null;

            if (checkBoxLicTypeEnable.Checked && (comboBoxLicType.SelectedValue != null))
            {
                if (!string.IsNullOrEmpty(filter.Trim()))
                {
                    filter += " AND ";
                }
                filter += string.Format(CultureInfo.InvariantCulture, "[ID LicType] = '{0}'", comboBoxLicType.SelectedValue);
            }
            if (checkBoxLicDocTypeEnable.Checked && (comboBoxLicDocType.SelectedValue != null))
            {
                if (!string.IsNullOrEmpty(filter.Trim()))
                {
                    filter += " AND ";
                }
                filter += string.Format(CultureInfo.InvariantCulture, "[ID DocType] = '{0}'", comboBoxLicDocType.SelectedValue);
            }
            if (checkBoxSupplierEnable.Checked && (comboBoxSupplierID.SelectedValue != null))
            {
                if (!string.IsNullOrEmpty(filter.Trim()))
                {
                    filter += " AND ";
                }
                filter += string.Format(CultureInfo.InvariantCulture, "[ID Supplier] = '{0}'", comboBoxSupplierID.SelectedValue);
            }
            if (checkBoxDepartmentEnable.Checked && (comboBoxDepartmentID.SelectedValue != null))
            {
                if (!string.IsNullOrEmpty(filter.Trim()))
                {
                    filter += " AND ";
                }
                var selectedDepartments = DataModelHelper.GetDepartmentSubunits((int)comboBoxDepartmentID.SelectedValue).
                                          Union(new List <int> {
                    (int)comboBoxDepartmentID.SelectedValue
                });
                var accessibleDepartments = from departmentsRow in DataModelHelper.
                                            FilterRows(DepartmentsDataModel.GetInstance().SelectVisibleDepartments())
                                            where departmentsRow.Field <bool>("AllowSelect")
                                            select departmentsRow.Field <int>("ID Department");

                var departments = selectedDepartments.Intersect(accessibleDepartments).ToList();
                if (!departments.Any())
                {
                    throw new ViewportException("Вы не состоите ни в одном из департаментов.");
                }
                filter += "[ID Department] IN (";
                foreach (var id in departments)
                {
                    filter += id.ToString(CultureInfo.InvariantCulture) + ",";
                }
                filter = filter.TrimEnd(',') + ")";
            }
            else
            {
                if (!string.IsNullOrEmpty(filter.Trim()))
                {
                    filter += " AND ";
                }
                var accessibleDepartments = (from departmentsRow in DataModelHelper.FilterRows(DepartmentsDataModel.GetInstance().SelectVisibleDepartments())
                                             where departmentsRow.Field <bool>("AllowSelect")
                                             select departmentsRow.Field <int>("ID Department")).ToList();
                if (!accessibleDepartments.Any())
                {
                    throw new ViewportException("Вы не состоите ни в одном из департаментов.");
                }
                filter += "[ID Department] IN (";
                foreach (var id in accessibleDepartments)
                {
                    filter += id.ToString(CultureInfo.InvariantCulture) + ",";
                }
                filter = filter.TrimEnd(',') + ")";
            }
            if (checkBoxDocNumberEnable.Checked)
            {
                if (!string.IsNullOrEmpty(filter.Trim()))
                {
                    filter += " AND ";
                }
                filter += string.Format(CultureInfo.InvariantCulture, "DocNumber LIKE'%{0}%'", textBoxDocNumber.Text.Trim().Replace("'", ""));
            }
            if (checkBoxSoftwareNameEnable.Checked && (comboBoxSoftwareName.SelectedValue != null))
            {
                if (!string.IsNullOrEmpty(filter.Trim()))
                {
                    filter += " AND ";
                }
                filter += string.Format(CultureInfo.InvariantCulture, "[ID Version] = '{0}'", comboBoxSoftwareName.SelectedValue);
            }
            if (checkBoxBuyLicenseDateEnable.Checked)
            {
                if (!string.IsNullOrEmpty(filter.Trim()))
                {
                    filter += " AND ";
                }
                filter += string.Format(CultureInfo.InvariantCulture, "BuyLicenseDate {0} #{1}#",
                                        ConvertDisplayEqExprToSql(
                                            comboBoxOpBuyLicenseDate.SelectedItem.ToString()),
                                        dateTimePickerBuyLicenseDate.Value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
            }
            if (checkBoxExpireLicenseDateEnable.Checked)
            {
                if (!string.IsNullOrEmpty(filter.Trim()))
                {
                    filter += " AND ";
                }
                filter += string.Format(CultureInfo.InvariantCulture, "ExpireLicenseDate {0} #{1}#",
                                        ConvertDisplayEqExprToSql(
                                            comboBoxOpExpireLicenseDate.SelectedItem.ToString()),
                                        dateTimePickerExpireLicenseDate.Value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
            }
            if (checkBoxSoftwareMakerEnable.Checked && (comboBoxSoftwareMaker.SelectedValue != null))
            {
                var ids = DataModelHelper.GetSoftwareIDsBySoftMaker((int)comboBoxSoftwareMaker.SelectedValue);
                includedSoftwareIds = DataModelHelper.Intersect(null, ids).ToList();
            }
            if (checkBoxSoftwareTypeEnable.Checked && (comboBoxSoftwareType.SelectedValue != null))
            {
                var ids = DataModelHelper.GetSoftwareIDsBySoftType((int)comboBoxSoftwareType.SelectedValue);
                includedSoftwareIds = DataModelHelper.Intersect(includedSoftwareIds, ids).ToList();
            }
            if (checkBoxLicKeyEnable.Checked && (comboBoxLicKey.SelectedValue != null))
            {
                if (!string.IsNullOrEmpty(filter.Trim()))
                {
                    filter += " AND ";
                }
                filter += string.Format(CultureInfo.InvariantCulture, "[ID License] = '{0}'", comboBoxLicKey.SelectedValue);
            }
            if (checkBoxOnlyAvailableInstallations.Checked)
            {
                var installationsCount =
                    from installRow in DataModelHelper.FilterRows(SoftInstallationsDataModel.GetInstance().Select())
                    group installRow by installRow.Field <int>("ID License")
                    into gs
                    select new
                {
                    idLicense         = gs.Key,
                    istallationsCount = gs.Count()
                };
                var notAvailableLicenses =
                    (from licensesRow in DataModelHelper.FilterRows(SoftLicensesDataModel.GetInstance().Select())
                     join installRow in installationsCount
                     on licensesRow.Field <int>("ID License") equals installRow.idLicense
                     where licensesRow.Field <int?>("InstallationsCount") != null &&
                     (licensesRow.Field <int>("InstallationsCount") - installRow.istallationsCount <= 0)
                     select licensesRow.Field <int>("ID License")).ToList();
                if (notAvailableLicenses.Any())
                {
                    if (!string.IsNullOrEmpty(filter.Trim()))
                    {
                        filter += " AND ";
                    }
                    filter += "[ID License] NOT IN (0";
                    foreach (var id in notAvailableLicenses)
                    {
                        filter += id.ToString(CultureInfo.InvariantCulture) + ",";
                    }
                    filter = filter.TrimEnd(',') + ")";
                }
            }
            if (includedSoftwareIds == null || !includedSoftwareIds.Any())
            {
                return(filter);
            }
            if (!string.IsNullOrEmpty(filter.Trim()))
            {
                filter += " AND ";
            }
            filter += "[ID Version] IN (0";
            foreach (var id in includedSoftwareIds)
            {
                filter += id.ToString(CultureInfo.InvariantCulture) + ",";
            }
            filter = filter.TrimEnd(',') + ")";
            return(filter);
        }