Exemplo n.º 1
0
        public virtual void DataSourceLoading(object sender, DataSourceEventArgs args)
        {
            var  dataSource = sender as Terrasoft.UI.WebControls.Controls.EntityDataSource;
            Guid duplicateStatusId;
            var  duplicateStatusEntity = UserConnection.EntitySchemaManager.FindInstanceByName("DuplicateStatus").CreateEntity(UserConnection);

            duplicateStatusEntity.FetchFromDB("Code", "Duplicate");
            duplicateStatusId = duplicateStatusEntity.GetTypedColumnValue <Guid>("Id");
            var select    = args.SelectQuery;
            var subSelect = new Select(UserConnection)
                            .From(DuplicatesTableName)
                            .Column("Entity1Id")
                            .Distinct()
                            .Where("StatusOfDuplicateId").IsEqual(Column.Const(duplicateStatusId)) as Select;
            var newCondition = new QueryCondition(select);

            newCondition.ConditionType = QueryConditionType.Block;
            var cond = select.Condition;

            newCondition.LeftExpression = new QueryColumnExpression(dataSource.Schema.Name, "Id");
            newCondition.In(subSelect);
            if (cond.Count > 0)
            {
                cond.ConditionType = QueryConditionType.Block;
                cond = cond.WrapBlock();
                newCondition.LogicalOperation = LogicalOperation.And;
            }
            cond.Add(newCondition);
            dataSource.Loading -= DataSourceLoading;
        }
        /// <summary>
        /// Calculate completeness value from detail.
        /// </summary>
        /// <param name="param">Completeness parameter for detail completeness.</param>
        /// <param name="recordId">Record id.</param>
        /// <returns>Completeness value.</returns>
        protected int GetCompletenessFromDetail(CompletenessParameter param, Guid recordId)
        {
            int    detailCompleteness = 0;
            Select entitiesSelect     =
                new Select(AppConnection.SystemUserConnection)
                .Column(Func.Count(param.DetailColumn))
                .From(param.DetailEntityName)
                .Where(param.DetailColumn).IsEqual(new QueryParameter(recordId)) as Select;

            if (!string.IsNullOrEmpty(param.TypeColumn) && !param.TypeValue.IsEmpty())
            {
                var typeCondition = new QueryCondition {
                    LeftExpression = new QueryColumnExpression(param.TypeColumn)
                };
                typeCondition.In(new QueryParameter(param.TypeValue));
                entitiesSelect.AddCondition(typeCondition, LogicalOperation.And);
            }
            entitiesSelect.SpecifyNoLockHints();
            using (DBExecutor dbExecutor = EnsureSystemUserDbConnection()) {
                using (IDataReader dataReader = entitiesSelect.ExecuteReader(dbExecutor)) {
                    while (dataReader.Read())
                    {
                        if (Convert.ToInt32(dataReader.GetValue(0)) > 0)
                        {
                            detailCompleteness = param.Percentage;
                        }
                    }
                }
            }
            return(detailCompleteness);
        }