Ejemplo n.º 1
0
        public DataTable GetRelations(CardRelationField relation)
        {
            var card       = relation.Card;
            var constraint = relation.Constraint;

            bool isCreate = false;

            //если режим создания объекта
            if (card.EntityInstance == null)
            {
                isCreate = true;
                FillEntityInstance(card, "");
            }
            else if (string.IsNullOrEmpty(card.EntityInstance.EntityInstanceID))
            {
                isCreate = true;
            }

            card.DependencyRelations = new DependencyRelations(constraint, card.EntityInstance);

            var tableTitleAttributes = new Dictionary <string, string>();

            tableTitleAttributes.Add(constraint.ConstraintName, relation.Value);
            card.DependencyRelations.RelationTableTitleAttributes = tableTitleAttributes;

            DataTable ReferenceTableDataSource = card.DependencyRelations.SetRelationColumnsValue_GetReferenceTable(true, isCreate);

            return(ReferenceTableDataSource);
        }
Ejemplo n.º 2
0
        public int GetInstanceID(CardRelationField filledRelation)
        {
            var card = filledRelation.Card;

            var constrant = card.EntityInstance.Constraints.First(con => con.ConstraintName == filledRelation.SystemName);

            var relationColValues = card.EntityInstance.RelationColumnsValue.Where(col => col.ConstraintName == constrant.ConstraintName);


            var colValList = new List <string>();

            foreach (var item in relationColValues)
            {
                if (item.Value != null && item.Value.ToString() != "")
                {
                    var colVal = string.Format("{0} = {1}", item.RefCol, item.Value);
                    colValList.Add(colVal);
                }
            }

            var columnsValue = string.Join(" and ", colValList);

            var query = new StringBuilder("SELECT [objID] FROM [").
                        Append(filledRelation.Entity.SystemName).Append("] WHERE ").Append(columnsValue);

            var table = Storage.GetDataTable(query.ToString());

            //if (table.Rows.Count == 1)
            return(Convert.ToInt32(table.Rows[0][0]));
            //else
            //    throw new NotImplementedException("Не знаю почему сработал метод OpenRelationHandler(object sender, EventArgs e), надо разобраться ");
        }
Ejemplo n.º 3
0
        private Button CreateRelationEditedButton(CardRelationField relation)
        {
            var b = new Button
            {
                Text            = "\u21D3",
                ToolTip         = "Выбрать значение",
                CommandArgument = relation.SystemName,
                CommandName     = relation.Card.Entity.ID.ToString()
            };


            b.ApplyStyle(OpenRelatedListButtonStyle);

            b.Click += new EventHandler(RelationEditedButton_Click);

            return(b);
        }
Ejemplo n.º 4
0
        public void FillEntityInstance(Card card, string entityInstanceID)
        {
            var entity = Storage.Select <Entity>(card.Entity.ID);

            EntityInstance entityInstance = new EntityInstance(entityInstanceID, entity.SystemName, true);

            entityInstance.Constraints = entity.Constraints;

            entityInstance.SetRelationColumnsValue();

            card.EntityInstance = entityInstance;

#if Viktor
            //заполнить констраинт, если создаем списковый объект из ссылочного объекта
            if (card.ConstraintID != null && card.InstanceID != null)
            {
                var constraint = entityInstance.Constraints.FirstOrDefault(con => con.ConstraintObjID == card.ConstraintID.ToString());

                if (constraint != null)
                {
                    CardRelationField relation = new CardRelationField(constraint, card);

                    var dt = GetRelations(relation);

                    var rows   = dt.Select(string.Format("objID = {0}", Convert.ToInt32(card.InstanceID)));
                    var row    = rows.First();
                    var titles = new StringBuilder();
                    for (int i = 1; i < row.ItemArray.Count(); i++)
                    {
                        var cell = row.ItemArray[i];
                        titles.Append(cell).Append(" ~ ");
                    }

                    card.DependencyRelations.RelationTableTitleAttributes[constraint.ConstraintName] = titles.ToString();

                    FillRelation(relation, card.InstanceID);
                }
            }
#endif
        }
Ejemplo n.º 5
0
        public void FillRelation(CardRelationField relation, int?instanceID)
        {
            var card = relation.Card;

            bool isCreate = false;

            if (string.IsNullOrEmpty(card.EntityInstance.EntityInstanceID))
            {
                isCreate = true;
            }

#if Viktor
            card.DependencyRelations.NewEntityInstanceID = instanceID.ToString();
#else
            if (instanceID == -1)
            {
                card.DependencyRelations.NewEntityInstanceID = "";
            }
            else
            {
                card.DependencyRelations.NewEntityInstanceID = instanceID.ToString();
            }
#endif



            card.DependencyRelations.SetRelationColumnsValue_GetReferenceTable(false, isCreate);



            foreach (var field in card.Fields.Where(f => f is CardRelationField).OfType <CardRelationField>())
            {
                var title = field.Card.EntityInstance.RelationColumnsValue.Where(columnVal => columnVal.ConstraintName == field.SystemName).FirstOrDefault().TitleAttribute;

                field.Value = title;
            }
        }
Ejemplo n.º 6
0
 public RelationClickedEventArgs(CardRelationField relation)
 {
     Relation = relation;
 }